本文整理汇总了C++中QPainter::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::begin方法的具体用法?C++ QPainter::begin怎么用?C++ QPainter::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void ImageLoader::run()
{
QString fn = m_url.toLocalFile();
int pos = fn.lastIndexOf('.');
QString ext;
if (pos != -1)
ext = fn.mid(pos).toUpper();
if (ext.isEmpty() ||
!QImageReader::supportedImageFormats().contains(ext.toLocal8Bit()))
ext = QString();
QFile f(fn);
if (!f.open(QIODevice::ReadOnly))
{
qWarning("Could not read: %s", qPrintable(m_url.path()));
return;
}
QByteArray bytes;
while (!f.atEnd())
{
QThread::yieldCurrentThread();
bytes.append(f.read(1024));
}
QThread::yieldCurrentThread();
QImage im = ext.isEmpty() ? QImage::fromData(bytes)
: QImage::fromData(bytes, qPrintable(ext));
if (im.isNull())
return;
QString p = m_url.path();
p = p.section("/", -1);
int max = qMax(im.width(), im.height());
QImage frm;
if (max <= 64)
frm = QImage(QSize(64, 64), QImage::Format_ARGB32);
else if (max <= 128)
frm = QImage(QSize(128, 128), QImage::Format_ARGB32);
else if (max <= 256)
frm = QImage(QSize(256, 256), QImage::Format_ARGB32);
else if (max <= 512)
frm = QImage(QSize(512, 512), QImage::Format_ARGB32);
else
frm = QImage(QSize(1024, 1024), QImage::Format_ARGB32);
frm.fill(qRgba(0, 0, 0, 0));
QPainter ptr;
ptr.begin(&frm);
ptr.setBackgroundMode(Qt::TransparentMode);
QRect r;
if (max > 1024)
{
if (max == im.width())
{
float h = float(1024) * float(im.height()) / float(im.width());
r.setSize(QSize(1024, h));
}
else
{
float w = float(1024) * float(im.width()) / float(im.height());
r.setSize(QSize(w, 1024));
}
}
else
{
r.setSize(im.size());
}
int left = (frm.width() - r.width()) / 2;
int top = (frm.height() - r.height()) / 2;
r.moveTopLeft(QPoint(left, top));
QThread::yieldCurrentThread();
ptr.drawImage(r, im);
ptr.end();
emit imageLoaded(frm);
}
示例2: paint
bool setDegu::paint(QImage *image){
/*
int w = m_data->fgImage->width(), h = m_data->fgImage->height();
cv::Mat f(h, w, CV_8UC1);
uchar *fg_p = m_data->fgImage->bits();
int bl = m_data->fgImage->bytesPerLine();
memcpy(f.data, fg_p, h*bl);
cv::Mat border_aux(f.size(), CV_8UC1);
cv::Canny(f,border_aux, 50,100, 3);
std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
cv::Mat border_copy(border_aux.size(), CV_8UC1);
border_aux.copyTo(border_copy);
cv::findContours(border_copy, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0) );
std::vector<cv::Point> big_contour;
std::vector<cv::Point> hull;
if(contours.size() > 0) {
//Group found contours in one big contour
for(int i=0;i<contours.size(); i++) {
if(hierarchy[i][2] < 0) { // No parent, so it's parent
if(big_contour.empty())
big_contour = contours[i];
else
big_contour.insert( big_contour.end(), contours[i].begin(), contours[i].end());
}
}
//Get initial convex hull
cv::convexHull( big_contour, hull, false );
} else {
return true;
}
if(hull.size() == 0) {
return true;
}
//cv::erode(aux, aux, element);
//cv::dilate(aux, aux, element,cv::Point(-1,-1),2);
//cv::erode(aux, aux, element);
SpHullModel newHull(new HullModel());
newHull->local_hull = hull;
newHull->off_x = 0;
newHull->off_y = 0;
//newHull->off_x = j0;
//newHull->off_y = i0;
//newHull->id = (*it)->mobile_id;
newHull->id = NULL;
int w0 = m_data->fgImage->width(),
h0 = m_data->fgImage->height();
//Get principal/minor axis
std::vector<cv::Point2f> data_aux(h0*w0);
float mean_x = 0, mean_y = 0;
int count = 0;
for(int i=0; i<h0; i++)
for(int j=0; j<w0; j++)
if(cv::pointPolygonTest(hull, cv::Point2f(j, i), true) > - 1) {
data_aux[count++] = cv::Point2f(j, i);
mean_x += j;
mean_y += i;
}
//data_aux.resize(count);
//cv::Mat data(2, count, CV_32FC1, &data_aux.front());
cv::Mat data(2, count, CV_32FC1);
cv::Point2f x;
for(int i=0; i<count; i++) {
data.at<float>(0,i) = data_aux[i].x;
data.at<float>(1,i) = data_aux[i].y;
}
//cv::Mat data();
mean_x /= count;
mean_y /= count;
cv::Mat mean(2, 1, CV_32FC1);
mean.at<float>(0) = mean_x;
mean.at<float>(1) = mean_y;
//2. perform PCA
cv::PCA pca(data, mean, CV_PCA_DATA_AS_COL, 1);
//result is contained in pca.eigenvectors (as row vectors)
//std::cout << pca.eigenvectors << std::endl;
//3. get angle of principal axis
float dx = pca.eigenvectors.at<float>(0, 0),
//.........这里部分代码省略.........
示例3: paintEvent
void LightMaps::paintEvent(QPaintEvent *event)
{
QPainter p;
p.begin(this);
m_normalMap->render(&p, event->rect());
p.setPen(Qt::black);
#if defined(Q_OS_SYMBIAN)
QFont font = p.font();
font.setPixelSize(13);
p.setFont(font);
#endif
p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap,
"Map data CCBYSA 2009 OpenStreetMap.org contributors");
p.end();
if (zoomed) {
int dim = qMin(width(), height());
int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3);
int radius = magnifierSize / 2;
int ring = radius - 15;
QSize box = QSize(magnifierSize, magnifierSize);
// reupdate our mask
if (maskPixmap.size() != box) {
maskPixmap = QPixmap(box);
maskPixmap.fill(Qt::transparent);
QRadialGradient g;
g.setCenter(radius, radius);
g.setFocalPoint(radius, radius);
g.setRadius(radius);
g.setColorAt(1.0, QColor(255, 255, 255, 0));
g.setColorAt(0.5, QColor(128, 128, 128, 255));
QPainter mask(&maskPixmap);
mask.setRenderHint(QPainter::Antialiasing);
mask.setCompositionMode(QPainter::CompositionMode_Source);
mask.setBrush(g);
mask.setPen(Qt::NoPen);
mask.drawRect(maskPixmap.rect());
mask.setBrush(QColor(Qt::transparent));
mask.drawEllipse(g.center(), ring, ring);
mask.end();
}
QPoint center = dragPos - QPoint(0, radius);
center = center + QPoint(0, radius / 2);
QPoint corner = center - QPoint(radius, radius);
QPoint xy = center * 2 - QPoint(radius, radius);
// only set the dimension to the magnified portion
if (zoomPixmap.size() != box) {
zoomPixmap = QPixmap(box);
zoomPixmap.fill(Qt::lightGray);
}
if (true) {
QPainter p(&zoomPixmap);
p.translate(-xy);
m_largeMap->render(&p, QRect(xy, box));
p.end();
}
QPainterPath clipPath;
clipPath.addEllipse(center, ring, ring);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setClipPath(clipPath);
p.drawPixmap(corner, zoomPixmap);
p.setClipping(false);
p.drawPixmap(corner, maskPixmap);
p.setPen(Qt::gray);
p.drawPath(clipPath);
}
if (invert) {
QPainter p(this);
p.setCompositionMode(QPainter::CompositionMode_Difference);
p.fillRect(event->rect(), Qt::white);
p.end();
}
}
示例4: resizeEvent
/*
This regenrate optimize pixmap.
there is single squire image which is repeated n no. of times to genrate new pixmap
this new pixmap is translated to move horizontaly or verticaly depending on orientation.
*/
void HbRepeatIconItem::resizeEvent ( QGraphicsSceneResizeEvent * event )
{
Q_UNUSED(event);
mParentRect = parentItem()->boundingRect();
HbFrameDrawer drawer;
if(mOrientation == Qt::Horizontal){
drawer.setFrameGraphicsName("qtg_fr_progbar_h_mask");
drawer.setFrameType(HbFrameDrawer::ThreePiecesHorizontal);
setIconHeight(mParentRect.size().toSize().height());//set height of the image drawer
}
else{
drawer.setFrameGraphicsName("qtg_fr_progbar_v_mask");
drawer.setFrameType(HbFrameDrawer::ThreePiecesVertical);
setIconWidth(mParentRect.size().toSize().width());//set width of the image drawer
}
drawer.setFillWholeRect(true);
QPixmap track(mParentRect.size().toSize());
track.fill(Qt::white);
QPainter p;
p.begin(&track);
drawer.paint(&p, QRectF(QPointF(0,0),mParentRect.size() ));
p.end();
setGeometry(QRectF(QPointF(0,0),mParentRect.size() ));//set geometry of QGI
QImage i=track.toImage();
//i.invertPixels();
setMask(QPixmap::fromImage(i));
if(mRepeatPixmap){
delete mRepeatPixmap;
mRepeatPixmap = 0;
}
qreal rectWidth = mParentRect.size().width(); //newSize.width();
qreal iconWidth = mIcon.width();
qreal rectHeight = mParentRect.size().height();
qreal iconHeight = mIcon.height();
if(mOrientation == Qt::Horizontal){
mRepeatPixmap = new QPixmap(int(rectWidth + iconWidth), (int)iconHeight);
mRepeatPixmap->fill(Qt::white);
QPainter p2;
p2.begin(mRepeatPixmap);
if(iconWidth > 0){
for(qreal i = 0 ; i < (rectWidth + iconWidth) ; i += iconWidth) {
mIcon.paint(&p2, QRectF(i, 0, iconWidth, iconHeight), mMode);
}
}
p2.end();
}
else{
mRepeatPixmap = new QPixmap((int)iconWidth, int(rectHeight + iconHeight));
mRepeatPixmap->fill(Qt::white);
QPainter p2;
p2.begin(mRepeatPixmap);
if( iconHeight > 0 ){
for(qreal i = 0 ; i < (rectHeight + iconHeight) ; i += iconHeight) {
mIcon.paint(&p2, QRectF(0, i, iconWidth, iconHeight), mMode);
}
}
p2.end();
}
}
示例5: printTable
//.........这里部分代码省略.........
}
done = 10;
table.setModel(&model); // set model to table
// resize columns to percentages from page width
int accW = 0;
int cols = model.columns;
int tableW = table.width();
for (i = 0; i < model.columns; i++) {
int pw = qCeil((qreal)(tablePrintColumnWidths.at(i) * table.width()) / 100.0);
accW += pw;
if (i == cols - 1 && accW > tableW) /* adjust last column */
pw -= accW - tableW;
table.horizontalHeader()->resizeSection(i, pw);
}
// reset the model at this point
model.callReset();
// a list of vertical offsets where pages begin and some helpers
QList<unsigned int> pageIndexes;
pageIndexes.append(0);
/* the algorithm bellow processes the table rows in multiple passes,
* compensating for loss of space due to moving rows on a new page instead
* of truncating them.
* there is a 'passes' array defining how much percents of the total
* progress each will take. given, the first and last stage of this function
* use 10% each, then the sum of passes[] here should be 80%.
* two should be enough! */
const int passes[] = { 70, 10 };
int tableHeight = 0, lastAccIndex = 0, rowH, accH, headings, headingRowHeightD2, headingRowHeight;
bool newHeading = false;
for (unsigned int pass = 0; pass < sizeof(passes) / sizeof(passes[0]); pass++) {
progress = headings = accH = 0;
total = model.rows - lastAccIndex;
for (i = lastAccIndex; i < model.rows; i++) {
rowH = table.rowHeight(i);
if (i == 0) { // first row is always a heading. it's height is constant.
headingRowHeight = rowH;
headingRowHeightD2 = rowH / 2;
}
if (rowH > pageH - headingRowHeight) // skip huge rows. we don't support row spanning on multiple pages.
continue;
accH += rowH;
if (newHeading) {
headings += rowH;
newHeading = false;
}
if (accH > pageH) {
lastAccIndex = i;
pageIndexes.append(pageIndexes.last() + (accH - rowH));
addTablePrintHeadingRow(&model, i);
newHeading = true;
accH = 0;
i--;
}
tableHeight += table.rowHeight(i);
progress++;
emit signalProgress(done + (progress * passes[pass]) / total);
}
done += passes[pass];
}
done = 90;
pageIndexes.append(pageIndexes.last() + accH + headings);
table.resize(pageW, tableHeight);
/* attach a painter and render pages by using pageIndexes
* there is a weird QPicture dependency here; we need to offset a page
* by headingRowHeightD2, which is half the heading height. the same doesn't
* make sense if we are rendering the table widget directly to the printer-painter. */
QPainter painter(printer);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
total = pageIndexes.size() - 1;
progress = 0;
for (i = 0; i < total; i++) {
if (i > 0)
printer->newPage();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
(void)headingRowHeightD2;
QRegion region(0, pageIndexes.at(i) - 1,
table.width(),
pageIndexes.at(i + 1) - pageIndexes.at(i) + 1);
table.render(&painter, QPoint(0, 0), region);
#else
QRegion region(0, pageIndexes.at(i) + headingRowHeightD2 - 1,
table.width(),
pageIndexes.at(i + 1) - (pageIndexes.at(i) + headingRowHeightD2) + 1);
// vectorize the table first by using QPicture
QPicture pic;
QPainter picPainter;
picPainter.begin(&pic);
table.render(&picPainter, QPoint(0, 0), region);
picPainter.end();
painter.drawPicture(QPoint(0, headingRowHeightD2), pic);
#endif
progress++;
emit signalProgress(done + (progress * 10) / total);
}
}
示例6: r
bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f,
const QPointF& shift ) const
{
Q_UNUSED( layerName );
Q_UNUSED( shift ); //todo...
QSvgRenderer r( mPath );
if ( !r.isValid() )
{
return false;
}
QgsDxfPaintDevice pd( &e );
pd.setDrawingSize( QSizeF( r.defaultSize() ) );
//size
double size = mSize;
QgsExpression* sizeExpression = expression( "size" );
bool hasDataDefinedSize = context->renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;
if ( sizeExpression )
{
size = sizeExpression->evaluate( *f ).toDouble();
}
if ( mSizeUnit == QgsSymbolV2::MM )
{
size *= mmMapUnitScaleFactor;
}
if ( hasDataDefinedSize )
{
switch ( mScaleMethod )
{
case QgsSymbolV2::ScaleArea:
size = sqrt( size );
break;
case QgsSymbolV2::ScaleDiameter:
break;
}
}
double halfSize = size / 2.0;
//offset, angle
QPointF offset = mOffset;
QgsExpression* offsetExpression = expression( "offset" );
if ( offsetExpression )
{
QString offsetString = offsetExpression->evaluate( *f ).toString();
offset = QgsSymbolLayerV2Utils::decodePoint( offsetString );
}
double offsetX = offset.x();
double offsetY = offset.y();
if ( mSizeUnit == QgsSymbolV2::MM )
{
offsetX *= mmMapUnitScaleFactor;
offsetY *= mmMapUnitScaleFactor;
}
QPointF outputOffset( offsetX, offsetY );
double angle = mAngle;
QgsExpression* angleExpression = expression( "angle" );
if ( angleExpression )
{
angle = angleExpression->evaluate( *f ).toDouble();
}
//angle = -angle; //rotation in Qt is counterclockwise
if ( angle )
outputOffset = _rotatedOffset( outputOffset, angle );
QPainter p;
p.begin( &pd );
if ( !qgsDoubleNear( angle, 0.0 ) )
{
p.translate( r.defaultSize().width() / 2.0, r.defaultSize().height() / 2.0 );
p.rotate( angle );
p.translate( -r.defaultSize().width() / 2.0, -r.defaultSize().height() / 2.0 );
}
pd.setShift( shift );
pd.setOutputSize( QRectF( -halfSize, -halfSize, size, size ) );
pd.setLayer( layerName );
r.render( &p );
p.end();
return true;
}
示例7: QGraphicsView
Altimeter::Altimeter(QWidget *parent) :
QGraphicsView(parent),
feets(0)
{
QPolygon polygon; // helper
this->setGeometry(0,0, WIDGETSIZE, WIDGETSIZE);
// Style Setting
backgroundBrush = QBrush(Qt::black);//QBrush(QColor(0x53, 0x54, 0x48));
circlePen = QPen(Qt::white);
circlePen.setWidth(CIRCLEPENWIDTH);
graduationPen = QPen(Qt::white);
graduationPen.setWidth(2);
graduationFont = QFont("lucida");
graduationFont.setPointSize(12);
graduationFont.setBold(true);
handPenFront = QPen(Qt::black);
handPenFront.setWidth(2);
handPenBack = QPen(Qt::white);
handPenBack.setWidth(2);
handBrushBack = QBrush(Qt::black);
handBrushFront = QBrush(Qt::white);
// BACKGROUND PIXMAP
backgroundPixmap = QPixmap(WIDGETSIZE,WIDGETSIZE);
QPainter painter;
painter.begin(&(this->backgroundPixmap));
painter.setRenderHint(QPainter::Antialiasing);
// Background
painter.fillRect(QRect(0,0,WIDGETSIZE,WIDGETSIZE), backgroundBrush);
// Circle
painter.translate(WIDGETSIZE/2, WIDGETSIZE/2);
painter.setBrush(Qt::NoBrush);
painter.setPen(circlePen);
painter.drawEllipse(QPoint(0,0),
(WIDGETSIZE/2-CIRCLEPENWIDTH),
(WIDGETSIZE/2-CIRCLEPENWIDTH)
);
// Graduation
painter.save();
painter.setFont(graduationFont);
for(int i=0 ; i<10 ; ++i)
{
graduationPen.setWidth(2);
painter.setPen(graduationPen);
painter.drawLine(QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+5),
QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+13));
graduationPen.setWidth(1);
painter.setPen(graduationPen);
painter.drawText(
QPoint(-5, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+28),
QString::number(i));
for(int j=1 ; j<5 ; ++j)
{
painter.rotate(7.2);
painter.drawLine(QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+5),
QPoint(0, -(WIDGETSIZE/2-CIRCLEPENWIDTH)+10));
}
painter.rotate(7.2);
}
painter.restore();
painter.end();
// HAND, FEETS
feetsHand = QPixmap(HANDWIDTH, HANDHEIGHT);
painter.begin(&(this->feetsHand));
painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(feetsHand.rect(), backgroundBrush);
// Hand front
painter.setBrush(handBrushFront);
painter.setPen(handPenFront);
painter.drawRect(QRect(HANDCENTERX-2, CIRCLEPENWIDTH+5, 4, 16));
painter.drawRect(QRect(
QPoint(HANDCENTERX-3, CIRCLEPENWIDTH+5+15),
QPoint(HANDCENTERX+3, HANDCENTERY))
);
// Hand back
painter.setBrush(handBrushBack);
painter.setPen(handPenBack);
painter.drawRect(HANDCENTERX-3, HANDCENTERY, 6, 25);
painter.drawEllipse(QPoint(HANDCENTERX, HANDCENTERY+25), 6, 6);
painter.end();
// Mask
feetsHand.setMask(feetsHand.createMaskFromColor(
backgroundBrush.color(),
Qt::MaskInColor)
);
// HAND, TENTH of FEETS
tenthHand = QPixmap(HANDWIDTH, HANDHEIGHT);
painter.begin(&(this->tenthHand));
painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(tenthHand.rect(), backgroundBrush);
// Hand front
painter.setBrush(handBrushFront);
painter.setPen(handPenFront);
//.........这里部分代码省略.........
示例8: paintEvent
void OrbitsWidget::paintEvent(QPaintEvent*)
{
QPainter DC;
DC.begin(this);
DC.setRenderHint(QPainter::Antialiasing, true);
int min_size = qMin(width(), height());
int min_delta = min_size / 10;
const int num = numOfElectrons.count();
if (num == 0) {
DC.drawText(QPoint(width() / 3, height() / 3), i18n("Unknown Electron Distribution"));
return; // no orbits, do nothing
}
//make sure the biggest orbit fits in the widget
//diameter
int d = min_size - 2 * min_delta;
//the radius of the current orbit
int r = d / 2;
//the radius of an 'electron'
int r_electron = r / 20;
//difference to the previous circle
int ddx = r / num;
QList<int>::Iterator it = numOfElectrons.end();
--it;
for (int i = 0; i < num; ++i) {
int mx = min_delta + ddx * i; //the x-coordinate for the current circle
int my = min_delta + ddx * i; //the y-coordinate for the current circle
DC.setBrush(Qt::NoBrush);
DC.setPen(Qt::black);
//draw the big ellipses in concentric circles
DC.drawEllipse(mx, my, d, d);
DC.setPen(Qt::NoPen);
for (int e = 0; e < *it; ++e) {
int x = (int)translateToDX(d / 2.0, (double)e, *it);
int y = (int)translateToDY(d / 2.0, (double)e, *it);
//Creating a gradient for the current electron.
QRadialGradient grad(QPointF(x + mx + d / 2 - r_electron / 2, y + my + d / 2 - r_electron / 2), r_electron);
grad.setColorAt(0, Qt::white);
grad.setColorAt(0.2, Qt::yellow);
grad.setColorAt(1, QColor(Qt::yellow).darker());
DC.setBrush(QBrush(grad));
DC.drawEllipse(x + mx + d / 2 - r_electron,
y + my + d / 2 - r_electron,
2 * r_electron,
2 * r_electron);
}
--it;
d -= 2 * ddx;
}
}
示例9: if
// creates a polygon from a given vector RegularData1D * data
void RegularData2DWidget::createPlot()
{
// no data => no polygon
if (data_ == 0 ||
data_->size() == 0)
{
return;
}
// set up the ColorMap... TODO: This should be done by a dialog or something similar
ColorRGBA colorList[3];
ColorMap color_table_;
colorList[0] = ColorRGBA(1.,0.,0.,1.);
colorList[1] = ColorRGBA(0.,1.,0.,1.);
colorList[2] = ColorRGBA(0.,0.,1.,1.);
color_table_.setBaseColors(colorList, 3);
color_table_.setNumberOfColors(100);
// determine the minimal and maximal values in data_
float min = (*data_)[0];
float max = (*data_)[0];
for (Position i=1; i < (*data_).size(); i++)
{
if ((*data_)[i] < min) min = (*data_)[i];
else if ((*data_)[i] > max) max = (*data_)[i];
}
color_table_.setRange(min, max);
color_table_.createMap();
//maximal number of Lines and Columns
Size max_x = (*data_).getSize().x;
Size max_y = (*data_).getSize().y;
// Draw the points
QPixmap pixmap;
pixmap.resize(max_x, max_y);
pixmap.fill(); // delete the old picture
QPainter paint;
paint.begin(&pixmap); // set the Painter
try
{
QColor pCol;
for (Position y=0; y< max_y; y++)
{
for (Position x=0; x< max_x; x++)
{
ColorRGBA mapcolor = color_table_.map(data_->getData(x + y * max_x));
pCol = QColor(mapcolor.getRed(), mapcolor.getGreen(), mapcolor.getBlue());
paint.setPen(pCol);
paint.drawPoint(x, y);
}
}
}
catch(...)
{
setStatusbarText("Error: Point in dataset out of grid!");
Log.error() << "Error: Point in dataset out of grid!" << std::endl;
return;
}
paint.end();
//put the pixmapItem into objects
PixmapItem* pixItem = new PixmapItem(&canvas_, pixmap);
pixItem->show();
objects_.push_back(dynamic_cast<Q3CanvasItem*> (pixItem));
// resize the canvas to fit the data
canvas_.resize(max_x, max_y);
}
示例10: print
void SXBSchView::print(QPrinter* pPrinter)
{
m_pDoc->resetSelect();
updateViewBuffer(true);
QPainter paint;
if(paint.begin(pPrinter ) ) {
int dpi;
#ifdef Q_WS_MACX
int dpix,dpiy;;
dpix = pPrinter->logicalDpiX();
dpiy = pPrinter->logicalDpiY();
dpi=((dpix < dpiy) ? dpix : dpiy);
#else
dpi = pPrinter->resolution();
#endif
paint.setRenderHint(QPainter::Antialiasing, true);
// QRect rcPaper = pPrinter->paperRect();
// printf("paperRect %d,%d,%d,%d\n",rcPaper.left(),rcPaper.top(),rcPaper.width(),rcPaper.height());
QRect rcVp = paint.viewport();
QRect rcPg = pPrinter->pageRect();
// printf("pageRect %d,%d,%d,%d\n",rcPg.left(),rcPg.top(),rcPg.width(),rcPg.height());
// int orientation = pPrinter->orientation();
// printf("orientation %d\n",orientation);
int vpWidth, vpHeight;
int pgLeft, pgTop, pgWidth, pgHeight;
vpWidth =rcVp.width();
vpHeight = rcVp.height();
pgLeft =rcPg.left();
pgTop =rcPg.top();
pgWidth =rcPg.width();
pgHeight = rcPg.height();
//印刷時に印刷の向きを変えてもpageRect()の返す値が変わらないQtのバグ(?)の対策
if( (vpWidth > vpHeight && pgWidth < pgHeight)
|| (vpWidth < vpHeight && pgWidth > pgHeight) ) {
int swapn;
swapn = pgLeft;
pgLeft = pgTop;
pgTop = swapn;
swapn = pgWidth;
pgWidth = pgHeight;
pgHeight = swapn;
}
QSettings *settings = g_cfg.getSettings();
int leftMargin = 15;
int topMargin = 15;
int rightMargin = 15;
int bottomMargin = 15;
settings->beginGroup("PrintOption");
bool color = settings->value("Color",true).toBool();
settings->endGroup();
settings->beginGroup("PrintMargin");
topMargin = settings->value("Top",15).toInt();
bottomMargin = settings->value("Bottom",15).toInt();
leftMargin = settings->value("Left",15).toInt();
rightMargin = settings->value("Right",15).toInt();
settings->endGroup();
if (topMargin < 0) topMargin = 0;
else if (topMargin > 50) topMargin = 50;
if (bottomMargin < 0) bottomMargin = 0;
else if (bottomMargin > 50) bottomMargin = 50;
if (leftMargin < 0) leftMargin = 0;
else if (leftMargin > 50) leftMargin = 50;
if (rightMargin < 0) rightMargin = 0;
else if (rightMargin > 50) rightMargin = 50;
topMargin = dpi * 10 * topMargin / 254;
bottomMargin = dpi * 10 * bottomMargin / 254;
leftMargin = dpi * 10 * leftMargin / 254;
rightMargin = dpi * 10 * rightMargin / 254;
// printf("SXBSchView::print() dpi:%d\n",dpi);
paint.save();
paint.setViewTransformEnabled (true);
paint.resetMatrix();
SSize size = m_pDoc->SheetSize();
int w = size.w();
int h = size.h();
int dw = w*10;
//.........这里部分代码省略.........
示例11: richText
BalloonMsg::BalloonMsg(void *param, const QString &_text, QStringList &btn, QWidget *parent, const QRect *rcParent,
bool bModal, bool bAutoHide, unsigned bwidth, const QString &box_msg, bool *bChecked)
: QDialog(parent, "ballon", bModal,
(bAutoHide ? WType_Popup : WType_TopLevel | WStyle_StaysOnTop)
| WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool | WDestructiveClose | WX11BypassWM)
{
m_param = param;
m_parent = parent;
m_width = bwidth;
m_bAutoHide = bAutoHide;
m_bYes = false;
m_bChecked = bChecked;
bool bTailDown = true;
setPalette(QToolTip::palette());
text = _text;
QFrame *frm = new QFrame(this);
frm->setPalette(palette());
QVBoxLayout *vlay = new QVBoxLayout(frm);
vlay->setMargin(0);
m_check = NULL;
if (!box_msg.isEmpty()){
m_check = new QCheckBox(box_msg, frm);
vlay->addWidget(m_check);
if (m_bChecked)
m_check->setChecked(*m_bChecked);
}
QHBoxLayout *lay = new QHBoxLayout(vlay);
lay->setSpacing(5);
lay->addStretch();
unsigned id = 0;
bool bFirst = true;
for (QStringList::Iterator it = btn.begin(); it != btn.end(); ++it, id++){
BalloonButton *b = new BalloonButton(*it, frm, id);
connect(b, SIGNAL(action(int)), this, SLOT(action(int)));
lay->addWidget(b);
if (bFirst){
b->setDefault(true);
bFirst = false;
}
}
setButtonsPict(this);
lay->addStretch();
int wndWidth = frm->minimumSizeHint().width();
int hButton = frm->minimumSizeHint().height();
int txtWidth = bwidth;
QRect rc;
if (rcParent){
rc = *rcParent;
}else{
QPoint p = parent->mapToGlobal(parent->rect().topLeft());
rc = QRect(p.x(), p.y(), parent->width(), parent->height());
}
if (rc.width() > txtWidth) txtWidth = rc.width();
QSimpleRichText richText(_text, font(), "", QStyleSheet::defaultSheet(), QMimeSourceFactory::defaultFactory(), -1, Qt::blue, false);
richText.setWidth(wndWidth);
richText.adjustSize();
QSize s(richText.widthUsed(), richText.height());
QSize sMin = frm->minimumSizeHint();
if (s.width() < sMin.width())
s.setWidth(sMin.width());
int BALLOON_SHADOW = BALLOON_SHADOW_DEF;
#ifdef WIN32
/* FIXME */
/* if ((GetClassLong(winId(), GCL_STYLE) & CS_DROPSHADOW) && style().inherits("QWindowsXPStyle"))
BALLOON_SHADOW = 0; */
#endif
resize(s.width() + BALLOON_R * 2 + BALLOON_SHADOW,
s.height() + BALLOON_R * 2 + BALLOON_TAIL + BALLOON_SHADOW + hButton + BALLOON_MARGIN);
mask = QBitmap(width(), height());
int w = width() - BALLOON_SHADOW;
int tailX = w / 2;
int posX = rc.left() + rc.width() / 2 + BALLOON_TAIL_WIDTH - tailX;
if (posX <= 0) posX = 1;
QRect rcScreen = screenGeometry();
if (posX + width() >= rcScreen.width())
posX = rcScreen.width() - 1 - width();
int tx = posX + tailX - BALLOON_TAIL_WIDTH;
if (tx < rc.left()) tx = rc.left();
if (tx > rc.left() + rc.width()) tx = rc.left() + rc.width();
tailX = tx + BALLOON_TAIL_WIDTH - posX;
if (tailX < BALLOON_R) tailX = BALLOON_R;
if (tailX > width() - BALLOON_R - BALLOON_TAIL_WIDTH) tailX = width() - BALLOON_R - BALLOON_TAIL_WIDTH;
if (rc.top() <= height() + 2){
bTailDown = false;
move(posX, rc.top() + rc.height() + 1);
}else{
move(posX, rc.top() - height() - 1);
}
int pos = 0;
int h = height() - BALLOON_SHADOW - BALLOON_TAIL;
if (!bTailDown) pos += BALLOON_TAIL;
textRect.setRect(BALLOON_R, pos + BALLOON_R, w - BALLOON_R * 2, h);
frm->resize(s.width(), hButton);
frm->move(BALLOON_R, pos + h - BALLOON_R - hButton);
QPainter p;
p.begin(&mask);
#ifdef WIN32
QColor bg(255, 255, 255);
//.........这里部分代码省略.........
示例12: paintEvent
//________________________________________________
void TransitionWidget::paintEvent( QPaintEvent* event )
{
// fully transparent case
if( opacity() >= 1.0 && endPixmap().isNull() ) return;
if( !_paintEnabled ) return;
// get rect
QRect rect = event->rect();
if( !rect.isValid() ) rect = this->rect();
// local pixmap
const bool paintOnWidget( testFlag( PaintOnWidget ) && !testFlag( Transparent ) );
if( !paintOnWidget )
{
if( _currentPixmap.isNull() || _currentPixmap.size() != size() )
{ _currentPixmap = QPixmap( size() ); }
}
// fill
_currentPixmap.fill( Qt::transparent );
// copy local pixmap to current
{
QPainter p;
// draw end pixmap first, provided that opacity is small enough
if( opacity() >= 0.004 && !_endPixmap.isNull() )
{
// faded endPixmap if parent target is transparent and opacity is
if( opacity() <= 0.996 && testFlag( Transparent ) )
{
fade( _endPixmap, _currentPixmap, opacity(), rect );
p.begin( &_currentPixmap );
p.setClipRect( event->rect() );
} else {
if( paintOnWidget ) p.begin( this );
else p.begin( &_currentPixmap );
p.setClipRect( event->rect() );
p.drawPixmap( QPoint(), _endPixmap );
}
} else {
if( paintOnWidget ) p.begin( this );
else p.begin( &_currentPixmap );
p.setClipRect( event->rect() );
}
// draw fading start pixmap
if( opacity() <= 0.996 && !_startPixmap.isNull() )
{
if( opacity() >= 0.004 )
{
fade( _startPixmap, _localStartPixmap, 1.0-opacity(), rect );
p.drawPixmap( QPoint(), _localStartPixmap );
} else p.drawPixmap( QPoint(), _startPixmap );
}
p.end();
}
// copy current pixmap on widget
if( !paintOnWidget )
{
QPainter p( this );
p.setClipRect( event->rect() );
p.drawPixmap( QPoint(0,0), _currentPixmap );
p.end();
}
}
示例13: paintEvent
void SkyMapQDraw::paintEvent( QPaintEvent *event ) {
Q_UNUSED(event);
// This is machinery to prevent multiple concurrent paint events / recursive paint events
if( m_DrawLock ) {
kDebug() << "I just prevented a recursive / concurrent draw!";
return;
}
setDrawLock( true );
calculateFPS();
//If computeSkymap is false, then we just refresh the window using the stored sky pixmap
//and draw the "overlays" on top. This lets us update the overlay information rapidly
//without needing to recompute the entire skymap.
//use update() to trigger this "short" paint event; to force a full "recompute"
//of the skymap, use forceUpdate().
if (!m_SkyMap->computeSkymap)
{
QPainter p;
p.begin( this );
p.drawLine(0,0,1,1); // Dummy operation to circumvent bug. TODO: Add details
p.drawPixmap( 0, 0, *m_SkyPixmap );
drawOverlays(p);
p.end();
setDrawLock( false );
return ; // exit because the pixmap is repainted and that's all what we want
}
// FIXME: used to to notify infobox about possible change of object coordinates
// Not elegant at all. Should find better option
m_SkyMap->showFocusCoords();
m_SkyMap->setupProjector();
SkyQPainter psky(this, m_SkyPixmap);
//FIXME: we may want to move this into the components.
psky.begin();
//Draw all sky elements
psky.drawSkyBackground();
m_KStarsData->skyComposite()->draw( &psky );
//Finish up
psky.end();
QPainter psky2;
psky2.begin( this );
psky2.drawLine(0,0,1,1); // Dummy op.
psky2.drawPixmap( 0, 0, *m_SkyPixmap );
drawOverlays(psky2);
psky2.end();
if(m_SkyMap->m_previewLegend)
{
m_SkyMap->m_legend.paintLegend(m_SkyPixmap);
}
m_SkyMap->computeSkymap = false; // use forceUpdate() to compute new skymap else old pixmap will be shown
setDrawLock( false );
}
示例14: draw
/**
* @brief Axis::draw
*rysuje oś
* @return narysowaną właśnie oś
*/
QPixmap Axis::draw()
{
QFontMetrics fm(this->getFont());
const int tickCount = (this->max-this->min)/this->tick;
const QString unit = this->showUnit?" "+this->unit:"";
int textWidth = fm.width(QString::number(this->max)+unit);
int textHeight = fm.height();
QPixmap temp;
float space;
//najdluzszy tekst
for(int i=0; i<=tickCount; i++)
{
if(fm.width(QString::number(this->min+tick*i)+unit) > textWidth)
textWidth = fm.width(QString::number(this->min+tick*i)+unit);
}
if(position==left || position==right)
{
//this->setGeometry(Geometry(0,0,textWidth+6+this->tickSize, this->geometry.getHeight()));
int dodatek=0;
if(this->label.getGeometry().getWidth()>0)
dodatek = this->label.getGeometry().getWidth()+2;
temp = QPixmap(textWidth+6+this->tickSize+dodatek, this->geometry.getHeight());
space = (temp.height()-20)/(max-min)*tick;
if(position == left)
textWidth += dodatek;
}
else
{
//this->setGeometry(Geometry(0, 0, this->geometry.getWidth(), textHeight+6+tickSize));
temp = QPixmap(this->geometry.getWidth(), textHeight+6+this->tickSize);
space = (temp.width())/(max-min)*tick;
}
QPainter p;
p.begin(&temp);
p.fillRect(0, 0, temp.width(), temp.height(), Qt::white);
p.setFont(this->getFont());
if(position==left)
{
if(this->label.getGeometry().getWidth() > 0)
{
//textWidth += this->label.getGeometry().getWidth()+2;
p.drawPixmap(0, (temp.height()-this->label.getGeometry().getHeight())/2, this->label.draw());
}
if(tickDirection==inside)
p.drawLine(textWidth+5, 10, textWidth+5, temp.height()-10);
else if(tickDirection == middle)
p.drawLine(textWidth+5+tickSize/2, 10, textWidth+5+tickSize/2, temp.height()-10);
else
p.drawLine(textWidth+5+tickSize, 10, textWidth+5+tickSize, temp.height()-10);
for(int i=tickCount; i>=0; i--)
{
p.drawLine(textWidth+5, temp.height()-10-i*space, textWidth+5+tickSize, temp.height()-10-i*space);
p.drawText(0, temp.height()-10-i*space-textHeight/2, textWidth, textHeight, Qt::AlignRight, QString::number(min+tick*i)+unit);
}
p.drawLine(textWidth+5, 10, textWidth+5+tickSize, 10);
}
else if(position == right)
{
if(tickDirection==inside)
p.drawLine(1+tickSize, 10, 1+tickSize, temp.height()-10);
else if(tickDirection == middle)
p.drawLine(1+tickSize/2, 10, 1+tickSize/2, temp.height()-10);
else
p.drawLine(1, 10, 1, temp.height()-10);
for(int i=tickCount; i>=0; i--)
{
p.drawLine(1, temp.height()-10-i*space, 1+tickSize, temp.height()-10-i*space);
p.drawText(6+tickSize, temp.height()-10-i*space-textHeight/2, textWidth, textHeight, Qt::AlignLeft, QString::number(min+tick*i)+unit);
}
p.drawLine(1, 10, 1+tickSize, 10);
if(this->label.getGeometry().getWidth() > 0)
{
//textWidth += this->label.getGeometry().getWidth()+2;
p.drawPixmap(6+tickSize+textWidth+2, (temp.height()-this->label.getGeometry().getHeight())/2, this->label.draw());
}
}
else if(position == bottom)
{
if(tickDirection==outside)
p.drawLine(0, 1, temp.width(), 1);
else if(tickDirection == middle)
p.drawLine(0, 1+tickSize/2, temp.width(), 1+tickSize/2);
else
p.drawLine(0, 1+tickSize, temp.width(), 1+tickSize);
for(int i=tickCount; i>=0; i--)
{
//.........这里部分代码省略.........
示例15: printProfileDives
void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
{
int i, row = 0, col = 0, printed = 0, total = estimateTotalDives();
int animationOriginal = prefs.animation_speed;
struct dive *dive;
if (!total)
return;
// disable animations on the profile:
prefs.animation_speed = 0;
// setup a painter
QPainter painter;
painter.begin(printer);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
// setup the profile widget
QPointer<ProfileWidget2> profile = MainWindow::instance()->graphics();
const int profileFrameStyle = profile->frameStyle();
profile->setFrameStyle(QFrame::NoFrame);
profile->setPrintMode(true, !printOptions->color_selected);
profile->setFontPrintScale(divesPerRow * divesPerColumn > 3 ? 0.6 : 1.0);
QSize originalSize = profile->size();
// swap rows/col for landscape
if (printer->orientation() == QPrinter::Landscape) {
int swap = divesPerColumn;
divesPerColumn = divesPerRow;
divesPerRow = swap;
}
// padding in pixels between two dives. no padding if only one dive per page.
const int padDef = 20;
const int padW = (divesPerColumn < 2) ? 0 : padDef;
const int padH = (divesPerRow < 2) ? 0 : padDef;
// estimate dimensions for a single dive
const int scaledW = ESTIMATE_DIVE_DIM(pageW, divesPerColumn, padW);
const int scaledH = ESTIMATE_DIVE_DIM(pageH, divesPerRow, padH);
// padding in pixels between profile and table
const int padPT = 5;
// create a model and table
ProfilePrintModel model;
model.setFontsize(7); // if this is changed we also need to change 'const int sr' in the constructor
// if there is only one dive per page row we pass fitNotesToHeight to be almost half the page height
QPointer<QTableView> table(createProfileTable(&model, scaledW, (divesPerRow == 1) ? scaledH * 0.45 : 0.0));
// profilePrintTableMaxH updates after the table is created
const int tableH = profilePrintTableMaxH;
// resize the profile widget
profile->resize(scaledW, scaledH - tableH - padPT);
// offset table or profile on top
int yOffsetProfile = 0, yOffsetTable = 0;
if (printOptions->notes_up)
yOffsetProfile = tableH + padPT;
else
yOffsetTable = scaledH - tableH;
// plot the dives at specific rows and columns on the page
for_each_dive (i, dive) {
if (!dive->selected && printOptions->print_selected)
continue;
if (col == divesPerColumn) {
col = 0;
row++;
if (row == divesPerRow) {
row = 0;
printer->newPage();
}
}
// draw a profile
QTransform origTransform = painter.transform();
painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetProfile);
profile->plotDive(dive, true); // make sure the profile is actually redrawn
#ifdef Q_OS_LINUX // on Linux there is a vector line bug (big lines in PDF), which forces us to render to QImage
QImage image(scaledW, scaledH - tableH - padPT, QImage::Format_ARGB32);
QPainter imgPainter(&image);
imgPainter.setRenderHint(QPainter::Antialiasing);
imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
profile->render(&imgPainter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
imgPainter.end();
painter.drawImage(image.rect(),image);
#else // for other OS we can try rendering the profile as vector
profile->render(&painter, QRect(0, 0, scaledW, scaledH - tableH - padPT));
#endif
painter.setTransform(origTransform);
// draw a table
QPicture pic;
QPainter picPainter;
painter.translate((scaledW + padW) * col, (scaledH + padH) * row + yOffsetTable);
model.setDive(dive);
picPainter.begin(&pic);
table->render(&picPainter);
picPainter.end();
painter.drawPicture(QPoint(0,0), pic);
painter.setTransform(origTransform);
col++;
printed++;
emit signalProgress((printed * 100) / total);
}
//.........这里部分代码省略.........