void ColorWheel::drawPicker(QPainter &painter) { painter.save(); painter.setBrush(Qt::NoBrush); QPen pen; // region of the widget int w = qMin(width(), height()); qreal r = w/2-margin_; // radius of outer circle qreal ir = r-wheelWidth_; // radius of inner circle qreal m = w/2.0-ir/qSqrt(2); // left corner of square painter.translate(m-5, m-5); qreal SquareWidth = 2*ir/qSqrt(2); qreal S = currentColor_.saturationF()*SquareWidth; qreal V = currentColor_.valueF()*SquareWidth; if (currentColor_.saturation() > 30 || currentColor_.value() < 50) pen.setColor(Qt::white); pen.setWidth(2); pen.setCosmetic(true); painter.setPen(pen); painter.drawEllipse(S,V,10,10); painter.restore(); }
void KisAbstractCanvasWidget::drawDecorations(QPainter & gc, bool tools, const QPoint & documentOffset, const QRect & clipRect, KisCanvas2 * canvas) { // Setup the painter to take care of the offset; all that the // classes that do painting need to keep track of is resolution gc.setRenderHint(QPainter::Antialiasing); gc.setRenderHint(QPainter::TextAntialiasing); gc.setRenderHint(QPainter::HighQualityAntialiasing); gc.setRenderHint(QPainter::SmoothPixmapTransform); gc.translate(QPoint(-documentOffset.x(), -documentOffset.y())); // Paint the shapes (other than the layers) gc.save(); gc.setClipRect(clipRect); canvas->globalShapeManager()->paint(gc, *canvas->viewConverter(), false); gc.restore(); // ask the decorations to paint themselves foreach(KisCanvasDecoration* deco, m_decorations) { deco->paint(gc, documentOffset, clipRect, *canvas->viewConverter()); }
/* See task: 41469 Problem is that the state is not properly restored if the basestate of the painter is different when the picture data was created compared to the base state of the painter when it is played back. */ void tst_QPicture::save_restore() { QPicture pic; QPainter p; p.begin(&pic); paintStuff(&p); p.end(); QPixmap pix1(300, 300); pix1.fill(Qt::white); p.begin(&pix1); p.drawPicture(50, 50, pic); p.end(); QPixmap pix2(300, 300); pix2.fill(Qt::white); p.begin(&pix2); p.translate(50, 50); paintStuff(&p); p.end(); QVERIFY( pix1.toImage() == pix2.toImage() ); }
//графика____________________________________________________________________ void RectWgt::draw() { pPix=new QPixmap(230,230); QPainter painter; painter.begin(pPix); painter.setRenderHint(QPainter::Antialiasing,true); painter.setPen(QPen(Qt::black,2,Qt::SolidLine)); double scale=(pHL->text().toDouble()>pWL->text().toDouble())?(200/pHL->text().toDouble()):200/pWL->text().toDouble(); painter.translate((115.0-scale*(pWL->text().toDouble()/2)),(115.0-scale*(pHL->text().toDouble()/2))); painter.setClipRect(0.0,((pHL->text().toDouble()-phL->text().toDouble())*scale), scale*pWL->text().toDouble(),phL->text().toDouble()*scale); painter.save(); painter.setPen(Qt::NoPen); QLinearGradient gradient(scale*pWL->text().toDouble()/2,((pHL->text().toDouble()-phL->text().toDouble())*scale), scale*pWL->text().toDouble()/2,scale*pHL->text().toDouble()); gradient.setColorAt(0,Qt::blue); gradient.setColorAt(1,Qt::darkBlue); painter.setBrush(gradient); painter.drawRect(0,0,scale*pWL->text().toDouble(),scale*pHL->text().toDouble()); painter.setClipping(false); painter.restore(); QPointF points[4]= { QPointF(0.0,0.0), QPointF(0.0,scale*pHL->text().toDouble()), QPointF(scale*pWL->text().toDouble(),scale*pHL->text().toDouble()), QPointF(scale*pWL->text().toDouble(),0.0) }; painter.drawPolyline(points,4); painter.drawLine(0.0,((pHL->text().toDouble()-phL->text().toDouble())*scale), (scale*pWL->text().toDouble()),((pHL->text().toDouble()-phL->text().toDouble())*scale)); painter.end(); pPixLbl->setPixmap(*pPix); }
//バッファの再描画 //渡される無効エリアの座標はコンテンツ座標系 void SXBSchView::drawBuffer(int x,int y,int clipx,int clipy, int clipw, int cliph ) { // qDebug("SXBSchView::drawBuffer\n"); QPainter painter; QRect rcClip = QRect(clipx,clipy,clipw,cliph); QRect rcClipSheet = ContentsToSheet(rcClip); SRect srcClipSheet =SRect(rcClipSheet.left(),rcClipSheet.top(),rcClipSheet.width(),rcClipSheet.height()); //qDebug() << m_viewBuffer.size(); painter.begin(&m_viewBuffer); painter.setRenderHint(QPainter::TextAntialiasing); painter.translate(-x,-y); painter.eraseRect(clipx,clipy,clipw,cliph); // painter.setClipping(true); clipx -= x; clipy -= y; // painter.setClipRect(clipx,clipy,clipw,cliph); SSize size = m_pDoc->SheetSize(); g_drawFrame(&painter,size,rcClip,QColor("#7E2020"),m_viewScale,m_viewScaleMul); if(m_bDisplayGrid) { drawGrid(&painter,rcClipSheet,QColor("#FC4343")); } drawMainXBSchObj(&painter,DRAW_ON,&srcClipSheet,m_fEditHighLight, m_viewScale,m_viewScaleMul); if((m_moveOption == MOVE_OPTION_COMPONENT_NAME) || (m_moveOption == MOVE_OPTION_COMPONENT_NUM)) { int modeOption = 0; if(m_moveOption == MOVE_OPTION_COMPONENT_NAME) { modeOption = DRAW_INH_PARTNAME; } else { modeOption = DRAW_INH_PARTNUM; } drawTempXBSchObj(&painter,DRAW_TEMP|modeOption,&srcClipSheet); } painter.end(); }
void myscroll::timerEvent(QTimerEvent *) { QRegion exposed; p1->scroll(-1,0,p1->rect(), &exposed); QPainter painter; save.setX(save.x()-1); now.setY(qrand()%20+300); painter.begin(p1); painter.setPen(Qt::red); painter.drawLine(save,now); save = now; painter.drawLine(0,400,400,400); painter.drawLine(0,200,0,400); for(int i=0; i<200; i++) { if(!(i%10)) { painter.drawLine(0,400-i,3,400-i); } } // painter.drawPoint(299,310); if(!(i%50)) { painter.translate(400,400); painter.rotate(-15); painter.setRenderHint(QPainter::Antialiasing,true); painter.setPen(QPen(Qt::red, 2, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin)); painter.drawLine(0,0,0,5); str.setNum(i); painter.drawText(QRectF(-10,0,30,50),Qt::AlignCenter,str); } i++; update(); }
QIcon SCgAlphabet::createPairIcon(const QSize &size, QString type) { QIcon icon; SCgPair *pair = new SCgPair; pair->setTypeAlias(type); QVector<QPointF> points; points.push_back(QPointF(-size.width() / 2.f, 0.f)); points.push_back(QPointF(size.width() / 2.f, 0.f)); pair->setPoints(points); QPixmap pixmap(size); QPainter painter; pixmap.fill(Qt::transparent); painter.begin(&pixmap); painter.setRenderHint(QPainter::Antialiasing, true); pair->setColor(QColor(0, 0, 0, 255));//(state == QIcon::On) ? 255 : 128)); painter.translate(size.width() / 2.f, size.height() / 2.f); painter.scale(0.9f, 0.9f); paintPair(&painter, pair); painter.end(); for (int mode = QIcon::Normal; mode <= QIcon::Selected; mode++) for (int state = QIcon::On; state <= QIcon::Off; state++) icon.addPixmap(pixmap, (QIcon::Mode)mode, (QIcon::State)state); delete pair; return icon; }
void AccountsView::print( QPrinter &printer, QPrintDialog &printDialog ) { //kDebug(planDbg()); uint top, left, bottom, right; printer.margins( &top, &left, &bottom, &right ); //kDebug(planDbg())<<m.width()<<"x"<<m.height()<<" :"<<top<<","<<left<<","<<bottom<<","<<right<<" :"<<size(); QPainter p; p.begin( &printer ); p.setViewport( left, top, printer.width() - left - right, printer.height() - top - bottom ); p.setClipRect( left, top, printer.width() - left - right, printer.height() - top - bottom ); QRect preg = p.clipRegion().boundingRect(); //kDebug(planDbg())<<"p="<<preg; //p.drawRect(preg.x(), preg.y(), preg.width()-1, preg.height()-1); double scale = qMin( ( double ) preg.width() / ( double ) size().width(), ( double ) preg.height() / ( double ) ( size().height() ) ); //kDebug(planDbg())<<"scale="<<scale; if ( scale < 1.0 ) { p.scale( scale, scale ); } QPixmap labelPixmap = QPixmap::grabWidget( m_label ); p.drawPixmap( m_label->pos(), labelPixmap ); p.translate( 0, m_label->size().height() ); m_dlv->paintContents( &p ); p.end(); }
void RadialMap::Widget::paintEvent(QPaintEvent*) { QPainter paint; paint.begin(this); if (!m_map.isNull()) paint.drawPixmap(m_offset, m_map.pixmap()); else { paint.drawText(rect(), 0, i18nc("We messed up, the user needs to initiate a rescan.", "Internal representation is invalid,\nplease rescan.")); return; } //exploded labels if (!m_map.isNull() && !m_timer.isActive()) { if (Config::antialias) { paint.setRenderHint(QPainter::Antialiasing); //make lines appear on pixel boundaries paint.translate(0.5, 0.5); } paintExplodedLabels(paint); } }
void Font::drawComplexText(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to) const { if (to < 0) to = run.length(); QPainter *p = ctx->platformContext(); if (ctx->textDrawingMode() & cTextFill) { if (ctx->fillGradient()) { QBrush brush(*ctx->fillGradient()->platformGradient()); brush.setTransform(ctx->fillGradient()->gradientSpaceTransform()); p->setPen(QPen(brush, 0)); } else if (ctx->fillPattern()) { TransformationMatrix affine; p->setPen(QPen(QBrush(ctx->fillPattern()->createPlatformPattern(affine)), 0)); } else p->setPen(QColor(ctx->fillColor())); } if (ctx->textDrawingMode() & cTextStroke) { if (ctx->strokeGradient()) { QBrush brush(*ctx->strokeGradient()->platformGradient()); brush.setTransform(ctx->strokeGradient()->gradientSpaceTransform()); p->setPen(QPen(brush, ctx->strokeThickness())); } else if (ctx->strokePattern()) { TransformationMatrix affine; p->setPen(QPen(QBrush(ctx->strokePattern()->createPlatformPattern(affine)), ctx->strokeThickness())); } else p->setPen(QPen(QColor(ctx->strokeColor()), ctx->strokeThickness())); } const QString string = fixSpacing(qstring(run)); // text shadow IntSize shadowSize; int shadowBlur; Color shadowColor; bool hasShadow = ctx->textDrawingMode() == cTextFill && ctx->getShadow(shadowSize, shadowBlur, shadowColor); if (from > 0 || to < run.length()) { QTextLayout layout(string, font()); QTextLine line = setupLayout(&layout, run); float x1 = line.cursorToX(from); float x2 = line.cursorToX(to); if (x2 < x1) qSwap(x1, x2); QFontMetrics fm(font()); int ascent = fm.ascent(); QRectF clip(point.x() + x1, point.y() - ascent, x2 - x1, fm.height()); if (hasShadow) { // TODO: when blur support is added, the clip will need to account // for the blur radius qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0; if (shadowSize.width() > 0) dx2 = shadowSize.width(); else dx1 = -shadowSize.width(); if (shadowSize.height() > 0) dy2 = shadowSize.height(); else dy1 = -shadowSize.height(); // expand the clip rect to include the text shadow as well clip.adjust(dx1, dx2, dy1, dy2); } p->save(); p->setClipRect(clip.toRect()); QPointF pt(point.x(), point.y() - ascent); if (hasShadow) { p->save(); p->setPen(QColor(shadowColor)); p->translate(shadowSize.width(), shadowSize.height()); line.draw(p, pt); p->restore(); } line.draw(p, pt); p->restore(); return; } p->setFont(font()); QPointF pt(point.x(), point.y()); int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight; if (hasShadow) { // TODO: text shadow blur support p->save(); p->setPen(QColor(shadowColor)); p->translate(shadowSize.width(), shadowSize.height()); p->drawText(pt, string, flags, run.padding()); p->restore(); } if (ctx->textDrawingMode() & cTextStroke) { QPainterPath path; path.addText(pt, font(), string); p->strokePath(path, p->pen()); } if (ctx->textDrawingMode() & cTextFill) p->drawText(pt, string, flags, run.padding()); }
void LightMaps::paintEvent(QPaintEvent *event) { QPainter p; p.begin(this); m_normalMap->render(&p, event->rect()); p.setPen(Qt::black); 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(); } }
void RCDraw::paintEvent ( QPaintEvent * ) { QString s; QPainter painter ( this ); painter.setRenderHint(QPainter::HighQualityAntialiasing); if ( qimg != NULL ) { painter.drawImage ( QRectF(0., 0., imageScale*width, imageScale*height), *qimg, QRectF(0, 0, width, height) ); } painter.setWindow (effWin.toRect() ); if ( DRAW_PERIMETER ) { painter.setPen ( Qt::blue ); painter.drawRect ( 0,0,width-1,height-1 ); } if ( DRAW_AXIS ) { drawAxis(Qt::blue, 2); } //Draw lines while ( !lineQueue.isEmpty() ) { TLine l = lineQueue.dequeue(); if (invertedVerticalAxis) l.line = QLineF(l.line.x1()-visibleCenter(0), -l.line.y1()+visibleCenter(1), l.line.x2()-visibleCenter(0), -l.line.y2()+visibleCenter(1)); else l.line.translate(-visibleCenter(0), -visibleCenter(1)); painter.setPen ( QPen ( QBrush ( l.color ),l.width ) ); painter.drawLine ( l.line ); } //Draw gradient while ( !gradQueue.isEmpty() ) { TGrad g = gradQueue.dequeue(); if (invertedVerticalAxis) g.line = QLine(g.line.x1()-visibleCenter(0), -g.line.y1()+visibleCenter(1), g.line.x2()-visibleCenter(0), -g.line.y2()+visibleCenter(1)); else g.line.translate(-visibleCenter(0), -visibleCenter(1)); linGrad.setColorAt ( 0, g.color ); linGrad.setColorAt ( 1, g.color1 ); painter.setBrush ( linGrad ); painter.setPen ( QPen ( linGrad, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter.drawLine ( g.line ); } //Draw ellipses while ( !ellipseQueue.isEmpty() ) { TEllipse e = ellipseQueue.dequeue(); if (invertedVerticalAxis) e.center.setY(-(e.center.y()-visibleCenter(1))); else e.center = QPointF(e.center.x()-visibleCenter(0), e.center.y()-visibleCenter(1)); if ( e.fill == true ) painter.setBrush ( e.color ); else painter.setBrush ( Qt::transparent ); painter.setPen ( e.color ); if (fabs(e.ang) > 0.1) { painter.setPen ( e.color ); painter.translate( e.center ); painter.rotate( e.ang ); painter.drawEllipse ( QPointF(0,0), e.rx, e.ry ); painter.rotate( -e.ang ); painter.translate( -e.center ); } else painter.drawEllipse( e.center, e.rx, e.ry); } //Draw squares { QPen pen = painter.pen(); int penwidth = pen.width(); while ( !squareQueue.isEmpty() ) { TRect r = squareQueue.dequeue(); if (invertedVerticalAxis) r.rect = QRect(r.rect.x()-visibleCenter(0), -r.rect.y()+visibleCenter(1)-r.rect.height(), r.rect.width(), r.rect.height()); else r.rect.translate(-visibleCenter(0),-visibleCenter(1)); if ( r.fill == true ) painter.setBrush ( r.color ); else painter.setBrush ( Qt::transparent ); pen.setColor(r.color); pen.setWidth(r.width); painter.setPen(pen); if (fabs(r.ang) > 0.01 ) { QPointF center = r.rect.center(); painter.translate( center ); painter.rotate( r.ang ); painter.drawRect ( QRectF( r.rect.topLeft() - center, r.rect.size() )); painter.rotate( -r.ang ); painter.translate( -center ); } else painter.drawRect( r.rect ); } pen.setWidth(penwidth); painter.setPen(pen); } while ( !lineOnTopQueue.isEmpty() ) { TLine l = lineOnTopQueue.dequeue(); l.line.translate(-visibleCenter(0), -visibleCenter(1)); painter.setPen ( QPen ( QBrush ( l.color ),l.width ) ); painter.drawLine ( l.line ); } //Draw text while ( !textQueue.isEmpty() ) { TText t = textQueue.dequeue(); painter.setWindow ( effWin.normalized().toRect() ); QFont ant = painter.font(); QFont temp ( "Helvetica", t.size ); painter.setFont ( temp ); QRectF rect = painter.boundingRect(QRectF(t.pos.x(), t.pos.y(), 1, 1), Qt::AlignLeft, t.text); if (not t.centered) { painter.setPen(t.bgc); painter.setBrush(t.bgc); painter.drawRect(rect); painter.setBrush ( Qt::transparent ); painter.setPen ( t.color ); painter.drawText( QRectF(t.pos.x(), t.pos.y(), 0.82*t.text.size()*t.size, 1.2*t.size), Qt::AlignCenter, t.text); } else { rect.translate(-rect.width()/2., -rect.height()/2.); painter.setPen(t.bgc); painter.setBrush(t.bgc); painter.drawRect(rect); painter.setBrush ( Qt::transparent ); painter.setPen ( t.color ); painter.drawText(rect, Qt::AlignLeft, t.text); } painter.setFont ( ant ); painter.setWindow ( effWin.toRect() ); } }
void KDReports::ReportPrivate::paintPage( int pageNumber, QPainter& painter ) { ensureLayouted(); const int pageCount = m_layout->numberOfPages(); KDReports::Header* header = m_headers.headerForPage( pageNumber + 1, pageCount ); if ( header ) { header->preparePaintingPage( pageNumber + m_firstPageNumber - 1 ); } KDReports::Header* footer = m_footers.headerForPage( pageNumber + 1, pageCount ); if ( footer ) { footer->preparePaintingPage( pageNumber + m_firstPageNumber - 1 ); } const qreal textDocWidth = m_paperSize.width() - mmToPixels( m_marginLeft + m_marginRight ); const qreal textDocHeight = mainTextDocHeight(); const int left = qRound( mmToPixels( m_marginLeft ) ); const int top = qRound( mmToPixels( m_marginTop ) ); //const int right = qRound( mmToPixels( m_marginRight ) ); const int bottom = qRound( mmToPixels( m_marginBottom ) ); const bool skipHeadersFooters = this->skipHeadersFooters(); const int headerHeightWithSpacing = qRound( ( skipHeadersFooters ? 0 : m_headers.height() ) + mmToPixels( m_headerBodySpacing ) ); const int footerHeight = skipHeadersFooters ? 0 : qRound( m_footers.height() ); //const int footerHeightWithspacing = qRound( m_footers.height() + mmToPixels( m_footerBodySpacing ) ); //const QRect paperRect( 0, 0, qRound( m_paperSize.width() ), qRound( m_paperSize.height() ) ); //const QRect textDocRect = paperRect.adjusted( left, top + headerHeightWithSpacing, // -right, - bottom - footerHeightWithspacing); const QRect textDocRect( left, top + headerHeightWithSpacing, textDocWidth, textDocHeight ); /*qDebug() << "paintPage: in pixels: top=" << top << " headerHeight=" << headerHeightWithSpacing << " textDoc size:" << textDocRect.size() << " bottom=" << bottom << " footerHeight=" << footerHeight;*/ if( !m_watermarkText.isEmpty() ) { painter.save(); painter.translate( textDocRect.center() ); painter.rotate( m_watermarkRotation ); painter.setFont( m_watermarkFont ); painter.setPen( m_watermarkColor ); const QSize textSize( painter.fontMetrics().size( Qt::TextSingleLine, m_watermarkText ) ); const QRect textRect( -textSize.width() / 2, -textSize.height()/2, textSize.width(), textSize.height() ); painter.drawText( textRect, Qt::AlignCenter, m_watermarkText ); painter.restore(); } if( !m_watermarkImage.isNull() ) { // We paint it without scaling it, for better quality. // But this means the actual size depends on the zoom level or printer resolution... // // It also means the image could end up being bigger than the page, and we don't want that. // So we scale down if necessary. But never up. QImage img = m_watermarkImage; if ( m_watermarkImage.width() > textDocRect.width() || m_watermarkImage.height() > textDocRect.height() ) { // should probably be cached? img = m_watermarkImage.scaled( textDocRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); } const QRect imageRect = QStyle::alignedRect( Qt::LeftToRight, Qt::AlignCenter, img.size(), textDocRect ); //qDebug() << "textDocRect=" << textDocRect << "size=" << img.size() << "-> imageRect=" << imageRect; painter.drawImage( imageRect.topLeft(), img ); } painter.save(); //painter.setClipRect( textDocRect, Qt::IntersectClip ); // triggers a Qt-Windows bug when printing painter.setClipRect( textDocRect ); painter.translate( left, top + headerHeightWithSpacing ); m_layout->paintPageContent( pageNumber, painter ); painter.restore(); QAbstractTextDocumentLayout::PaintContext ctx; ctx.palette.setColor(QPalette::Text, Qt::black); if ( header && !skipHeadersFooters ) { painter.save(); painter.translate( left, top ); ctx.clip = painter.clipRegion().boundingRect(); header->doc().contentDocument().documentLayout()->draw(&painter, ctx); painter.restore(); } if ( footer && !skipHeadersFooters ) { painter.save(); painter.translate( left, m_paperSize.height() - bottom - footerHeight ); ctx.clip = painter.clipRegion().boundingRect(); footer->doc().contentDocument().documentLayout()->draw(&painter, ctx); painter.restore(); } }
void GraphicsWidget::paintEvent(QPaintEvent *event) { Q_UNUSED(event) //set up painting with antialiasing etc QPainter painter; painter.begin(&elements); painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.setRenderHint(QPainter::SmoothPixmapTransform); //transform coordinates to fit everything neatly on the screen painter.save(); painter.setWorldTransform(getCurrentTransform()); if (grid != nullptr) { //loop through and draw each entry for (const auto& cell: grid->getCells()) { GridEntry &entry = grid->getEntry(cell); if (entry.modified) { entry.modified = false; painter.save(); painter.translate(cell.x(), cell.y()); QPen pen(Qt::black); pen.setWidthF(0); painter.setPen(pen); if (entry.type == GridEntry::Wall) painter.setBrush(Qt::darkBlue); else if (entry.type == GridEntry::Start) painter.setBrush(Qt::yellow); else if (entry.type == GridEntry::End) painter.setBrush(Qt::red); else if (entry.path) painter.setBrush(Qt::white); else if (entry.searched) painter.setBrush(Qt::cyan); else painter.setBrush(Qt::darkGreen); painter.drawConvexPolygon(DISPLAY_HEXAGON); painter.restore(); } } } painter.restore(); painter.setPen(Qt::white); QPainter screenPainter(this); screenPainter.fillRect(rect(), QBrush(Qt::black)); screenPainter.drawImage(0, 0, elements); }
void MainWindow::on_pushButton_clicked() { QFileDialog::Options options; options |= QFileDialog::DontUseNativeDialog; QString selectedFilter; QString fileName = QFileDialog::getSaveFileName(this, tr("set the PDF name"), "", tr("PDF Files (*.pdf)"), &selectedFilter, options); fileName.append(".pdf"); printer.setOutputFileName(fileName); QPainter painter; if (! painter.begin(&printer)) { // failed to open file qWarning("failed to open file, is it writable?"); return ; } painter.save(); //fist, draw a rounded rect for header & graphic area; painter.drawRoundedRect(header_area,15,15); painter.drawRoundedRect(curve_area.x(),curve_area.y(),curve_area.width(),table_area.y()+table_area.height(),15,15); painter.drawRoundedRect(curve_area,15,15); painter.setPen(Qt::SolidLine); QPen nom_line_pen(Qt::black, 2, Qt::SolidLine); QPen act_line_pen(Qt::blue, 2 ,Qt::SolidLine); //move the painter to the left mid position painter.translate(curve_area.x(),curve_area.center().y()); //draw coordinate axis QPen axis_pen(Qt::blue,1,Qt::SolidLine); painter.setPen(axis_pen); painter.drawLine(0,0,curve_area.width(),0); painter.drawLine(curve_area.width()/2,curve_area.height()/2,curve_area.width()/2,-curve_area.height()/2); //draw nominal und actual curves painter.setPen(nom_line_pen); painter.drawPath(*nom_path); painter.setPen(act_line_pen); painter.drawPath(*act_path); //painter.drawPoints(nom_points,data->size()); //draw nominal points as single points for(int i=0;i<size;++i) { painter.drawEllipse(nom_points[i],1.2,1.2); } //draw data tables painter.restore(); painter.save(); painter.translate(table_area.x(),table_area.y()); painter.setFont(QFont("Times New Roman",10)); for (int i=0;i<14;++i) //just for test, offical release need auto adjust { painter.drawText(10+i*60,10,50,150,Qt::AlignCenter, QString("%1\n%2\n%3\n%4") .arg(i+1) .arg(nom_data->at(i).x) .arg(nom_data->at(i).y) .arg( QString::number(act_data->at(i).y,'f',4))); } painter.translate(0,90); for (int i=14;i<28;++i) //just for test, offical release need auto adjust { painter.drawText(10+(i-14)*60,10,50,150,Qt::AlignCenter, QString("%1\n%2\n%3\n%4") .arg(i+1) .arg(nom_data->at(i).x) .arg(nom_data->at(i).y) .arg( QString::number(act_data->at(i).y,'f',4))); } //draw a header and LOGO painter.restore(); painter.drawPixmap(header_area.x()+20,header_area.y()+1,header_area.height()-2,header_area.height()-2,*logo); painter.translate(header_area.center().x()-150,header_area.y()); //just for test QFont header_font("Blackadder ITC",20); painter.setFont(header_font); painter.drawText(0,0,300,header_area.height(),Qt::AlignCenter,QString("Just test, Curve Report by Sean")); }
void OCDial::drawShape(QPainter& p) { if (vnew != vcur) { vnew = vnew < vmin ? vmin : vnew > vmax ? vmax : vnew; writeValue(vnew); vcur = vnew; } QRect br = boundingRect(); double w = br.width(); double h = br.height(); double xc = w / 2; double yc = h / 2; double rw = w * .45; double rh = h * .45; double ptr_w = rw * .2; double ptr_h = rh * .2; double increment = M_PI * 100 / (rw * rh); double inc = vmax > vmin ? vmax - vmin : vmin - vmax; while (inc > 0 && inc < 100) inc *= 10.; while (inc >= 1000) inc /= 10.; p.drawPixmap(br, face); p.save(); p.translate(x(), y()); QColor ctick1("#99ff99"); QColor ctick2("#99cc99"); QColor cpointer("#ffcc33"); QColor ccontour("#660000"); QPen pen(QColor("#000000"), 2, SolidLine, RoundCap, BevelJoin); double last = -1; for (int i = 0; i <= inc; i++) { double theta = i * M_PI / (18. * inc / 24.) - M_PI/6.; if (theta - last < increment) continue; last = theta; double tick_w = ptr_w; double tick_h = ptr_h; if (inc >= 10 && (i % int(inc / 10)) == 0) { pen.setColor(ctick1); } else { tick_w /= 2; tick_h /= 2; pen.setColor(ctick2); } p.setPen(pen); double s = sin(theta); double c = cos(theta); p.drawLine( int(xc + c*(rw - tick_w)), int(yc - s*(rh - tick_h)), int(xc + c*rw), int(yc - s*rh)); } if (vmax == vmin) angle = 2.e9; else angle = (M_PI*7./6.) - (vcur - vmin) * (M_PI*4./3.) / (vmax - vmin); double c, s; if (fabs(angle) < 1.e9) { s = sin(angle); c = cos(angle); } else { c = s = angle = 0; } p.translate(xc, yc); QPointArray points(5); points.setPoint(0, int(s*ptr_w/2), int(c*ptr_w/2)); points.setPoint(1, int(c*rw), int(-s*rh)); points.setPoint(2, int(-s*ptr_w/2), int(-c*ptr_h/2)); points.setPoint(3, int(-c*rw/10), int(s*rh/10)); points.setPoint(4, int(s*ptr_w/2), int(c*ptr_h/2)); p.setBrush(cpointer); p.drawPolygon(points); pen.setColor(ccontour); p.setPen(pen); p.drawPolyline(points); p.restore(); }
void plotPathsToPainter(QPainter& painter, QPainterPath& path, const Numpy1DObj& x, const Numpy1DObj& y, const Numpy1DObj* scaling, const QRectF* clip, const QImage* colorimg, bool scaleline) { QRectF cliprect( QPointF(-32767,-32767), QPointF(32767,32767) ); if( clip != 0 ) { qreal x1, y1, x2, y2; clip->getCoords(&x1, &y1, &x2, &y2); cliprect.setCoords(x1, y1, x2, y2); } QRectF pathbox = path.boundingRect(); cliprect.adjust(pathbox.left(), pathbox.top(), pathbox.bottom(), pathbox.right()); // keep track of duplicate points QPointF lastpt(-1e6, -1e6); // keep original transformation for restoration after each iteration QTransform origtrans(painter.worldTransform()); // number of iterations int size = min(x.dim, y.dim); // if few color points, trim down number of paths if( colorimg != 0 ) size = min(size, colorimg->width()); // too few scaling points if( scaling != 0 ) size = min(size, scaling->dim); // draw each path for(int i = 0; i < size; ++i) { const QPointF pt(x(i), y(i)); if( cliprect.contains(pt) && ! smallDelta(lastpt, pt) ) { painter.translate(pt); if( colorimg != 0 ) { // get color from pixel and create a new brush QBrush b( QColor::fromRgba(colorimg->pixel(i, 0)) ); painter.setBrush(b); } if( scaling == 0 ) { painter.drawPath(path); } else { // scale point if requested const qreal s = (*scaling)(i); if( scaleline ) { painter.scale(s, s); painter.drawPath(path); } else { QPainterPath scaled; scalePath(path, s, scaled); painter.drawPath(scaled); } } painter.setWorldTransform(origtrans); lastpt = pt; } } }
QSizeF QgsSymbolV2LegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const { QgsSymbolV2* s = mItem.symbol(); if ( !s ) { return QSizeF(); } // setup temporary render context QgsRenderContext context; context.setScaleFactor( settings.dpi() / 25.4 ); context.setRendererScale( settings.mapScale() ); context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) ); context.setForceVectorOutput( true ); context.setPainter( ctx ? ctx->painter : 0 ); //Consider symbol size for point markers double height = settings.symbolSize().height(); double width = settings.symbolSize().width(); double size = 0; //Center small marker symbols double widthOffset = 0; double heightOffset = 0; if ( QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( s ) ) { // allow marker symbol to occupy bigger area if necessary size = markerSymbol->size() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context, s->outputUnit(), s->mapUnitScale() ) / context.scaleFactor(); height = size; width = size; if ( width < settings.symbolSize().width() ) { widthOffset = ( settings.symbolSize().width() - width ) / 2.0; } if ( height < settings.symbolSize().height() ) { heightOffset = ( settings.symbolSize().height() - height ) / 2.0; } } if ( ctx ) { double currentXPosition = ctx->point.x(); double currentYCoord = ctx->point.y() + ( itemHeight - settings.symbolSize().height() ) / 2; QPainter* p = ctx->painter; //setup painter scaling to dots so that raster symbology is drawn to scale double dotsPerMM = context.scaleFactor(); int opacity = 255; if ( QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( layerNode()->layer() ) ) opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 ); p->save(); p->setRenderHint( QPainter::Antialiasing ); p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset ); p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM ); if ( opacity != 255 && settings.useAdvancedEffects() ) { //semi transparent layer, so need to draw symbol to an image (to flatten it first) //create image which is same size as legend rect, in case symbol bleeds outside its alloted space QSize tempImageSize( width * dotsPerMM, height * dotsPerMM ); QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 ); tempImage.fill( Qt::transparent ); QPainter imagePainter( &tempImage ); context.setPainter( &imagePainter ); s->drawPreviewIcon( &imagePainter, tempImageSize, &context ); context.setPainter( ctx->painter ); //reduce opacity of image imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) ); imagePainter.end(); //draw rendered symbol image p->drawImage( 0, 0, tempImage ); } else { s->drawPreviewIcon( p, QSize( width * dotsPerMM, height * dotsPerMM ), &context ); } p->restore(); } return QSizeF( qMax( width + 2 * widthOffset, ( double ) settings.symbolSize().width() ), qMax( height + 2 * heightOffset, ( double ) settings.symbolSize().height() ) ); }
void ContinuousPanel::paint(const QRect&, QPainter& painter) { qreal _offsetPanel = 0; qreal _y = 0; qreal _oldWidth = 0; // The last final panel width qreal _newWidth = 0; // New panel width qreal _height = 0; qreal _leftMarginTotal = 0; // Sum of all elments left margin qreal _panelRightPadding = 5; // Extra space for the panel after last element Measure* measure = _score->firstMeasure(); if (!_active || !measure) { _visible = false; return; } if (measure->mmRest()) { measure = measure->mmRest(); } System* system = measure->system(); if (system == 0) { _visible = false; return; } Segment* s = measure->first(); double _spatium = _score->spatium(); if (_width <= 0) _width = s->x(); // // Set panel height for whole system // _height = 6 * _spatium; _y = system->staffYpage(0) + system->page()->pos().y(); double y2 = 0.0; for (int i = 0; i < _score->nstaves(); ++i) { SysStaff* ss = system->staff(i); if (!ss->show() || !_score->staff(i)->show()) continue; y2 = ss->y() + ss->bbox().height(); } _height += y2 + 6*_spatium; _y -= 6 * _spatium; // // Check elements at current panel position // _offsetPanel = -(_sv->xoffset()) / _sv->mag(); _rect = QRect(_offsetPanel + _width, _y, 1, _height); Page* page = _score->pages().front(); QList<Element*> el = page->items(_rect); if (el.empty()) { _visible = false; return; } qStableSort(el.begin(), el.end(), elementLessThan); const Measure*_currentMeasure = 0; for (const Element* e : el) { e->itemDiscovered = 0; if (!e->visible() && !_score->showInvisible()) continue; if (e->isMeasure()) { _currentMeasure = toMeasure(e); break; } } if (!_currentMeasure) return; // Don't show panel if staff names are visible if (_currentMeasure == _score->firstMeasure() && _sv->toPhysical(_currentMeasure->canvasPos()).x() > 0) { _visible = false; return; } qreal _xPosMeasure = _currentMeasure->canvasX(); qreal _measureWidth = _currentMeasure->width(); int tick = _currentMeasure->tick(); Fraction _currentTimeSig = _currentMeasure->timesig(); //qDebug() << "_sv->xoffset()=" <<_sv->xoffset() << " _sv->mag()="<< _sv->mag() <<" s->x=" << s->x() << " width=" << _width << " currentMeasure=" << _currentMeasure->x() << " _xPosMeasure=" << _xPosMeasure; //--------------------------------------------------------- // findElementWidths // determines the max width for each element types //--------------------------------------------------------- // The first pass serves to get the maximum width for each elements qreal lineWidthName = 0; qreal _widthClef = 0; qreal _widthKeySig = 0; qreal _widthTimeSig = 0; qreal _xPosTimeSig = 0; for (const Element* e : el) { e->itemDiscovered = 0; if (!e->visible() && !_score->showInvisible()) continue; if (e->isRest() && toRest(e)->isGap()) continue; if (e->isStaffLines()) { Staff* currentStaff = _score->staff(e->staffIdx()); Segment* parent = _score->tick2segment(tick); // Find maximum width for the staff name QList<StaffName>& staffNamesLong = currentStaff->part()->instrument()->longNames(); QString staffName = staffNamesLong.isEmpty() ? " " : staffNamesLong[0].name(); if (staffName == "") { QList<StaffName>& staffNamesShort = currentStaff->part()->instrument()->shortNames(); staffName = staffNamesShort.isEmpty() ? "" : staffNamesShort[0].name(); } Text* newName = new Text(_score); newName->setXmlText(staffName); newName->setParent(parent); newName->setTrack(e->track()); newName->textStyle().setFamily("FreeSans"); newName->textStyle().setSizeIsSpatiumDependent(true); newName->layout(); newName->setPlainText(newName->plainText()); newName->layout(); // Find maximum width for the current Clef Clef* newClef = new Clef(_score); ClefType currentClef = currentStaff->clef(tick); newClef->setClefType(currentClef); newClef->setParent(parent); newClef->setTrack(e->track()); newClef->layout(); if (newClef->width() > _widthClef) _widthClef = newClef->width(); // Find maximum width for the current KeySignature KeySig* newKs = new KeySig(_score); KeySigEvent currentKeySigEvent = currentStaff->keySigEvent(tick); newKs->setKeySigEvent(currentKeySigEvent); // The Parent and the Track must be set to have the key signature layout adjusted to different clefs // This also adds naturals to the key signature (if set in the score style) newKs->setParent(parent); newKs->setTrack(e->track()); newKs->setHideNaturals(true); newKs->layout(); if (newKs->width() > _widthKeySig) _widthKeySig = newKs->width(); // Find maximum width for the current TimeSignature TimeSig* newTs = new TimeSig(_score); // Try to get local time signature, if not, get the current measure one TimeSig* currentTimeSig = currentStaff->timeSig(tick); if (currentTimeSig) newTs->setFrom(currentTimeSig); else newTs->setSig(Fraction(_currentTimeSig.numerator(), _currentTimeSig.denominator()), TimeSigType::NORMAL); newTs->setParent(parent); newTs->setTrack(e->track()); newTs->layout(); if ((newName->width() > lineWidthName) && (newName->xmlText() != "")) lineWidthName = newName->width(); if (newTs->width() > _widthTimeSig) _widthTimeSig = newTs->width(); delete newClef; delete newName; delete newKs; delete newTs; } } _leftMarginTotal = _score->styleP(StyleIdx::clefLeftMargin); _leftMarginTotal += _score->styleP(StyleIdx::keysigLeftMargin); _leftMarginTotal += _score->styleP(StyleIdx::timesigLeftMargin); _newWidth = _widthClef + _widthKeySig + _widthTimeSig + _leftMarginTotal + _panelRightPadding; _xPosMeasure -= _offsetPanel; lineWidthName += _score->spatium() + _score->styleP(StyleIdx::clefLeftMargin) + _widthClef; if (_newWidth < lineWidthName) { _newWidth = lineWidthName; _oldWidth = 0; } if (_oldWidth == 0) { _oldWidth = _newWidth; _width = _newWidth; } else if (_newWidth > 0) { if (_newWidth == _width) { _oldWidth = _width; _width = _newWidth; } else if (((_xPosMeasure <= _newWidth) && (_xPosMeasure >= _oldWidth)) || ((_xPosMeasure >= _newWidth) && (_xPosMeasure <= _oldWidth))) _width = _xPosMeasure; else if (((_xPosMeasure+_measureWidth <= _newWidth) && (_xPosMeasure+_measureWidth >= _oldWidth)) || ((_xPosMeasure+_measureWidth >= _newWidth) && (_xPosMeasure+_measureWidth <= _oldWidth))) _width = _xPosMeasure+_measureWidth; else { _oldWidth = _width; _width = _newWidth; } } _rect = QRect(0, _y, _width, _height); //==================== painter.save(); // Draw colored rectangle painter.setClipping(false); QPointF pos(_offsetPanel, 0); painter.translate(pos); QPen pen; pen.setWidthF(0.0); pen.setStyle(Qt::NoPen); painter.setPen(pen); painter.setBrush(preferences.fgColor); QRectF bg(_rect); bg.setWidth(_widthClef + _widthKeySig + _widthTimeSig + _leftMarginTotal + _panelRightPadding); QPixmap* fgPixmap = _sv->fgPixmap(); if (fgPixmap == 0 || fgPixmap->isNull()) painter.fillRect(bg, preferences.fgColor); else { painter.setMatrixEnabled(false); painter.drawTiledPixmap(bg, *fgPixmap, bg.topLeft() - QPoint(lrint(_sv->matrix().dx()), lrint(_sv->matrix().dy()))); painter.setMatrixEnabled(true); } painter.setClipRect(_rect); painter.setClipping(true); QColor color(MScore::layoutBreakColor); // Draw measure text number QString text = QString("#%1").arg(_currentMeasure->no()+1); Text* newElement = new Text(_score); newElement->setTextStyleType(TextStyleType::DEFAULT); newElement->setFlag(ElementFlag::MOVABLE, false); newElement->setXmlText(text); newElement->textStyle().setFamily("FreeSans"); newElement->textStyle().setSizeIsSpatiumDependent(true); newElement->setColor(color); newElement->sameLayout(); pos = QPointF(_score->styleP(StyleIdx::clefLeftMargin) + _widthClef, _y + newElement->height()); painter.translate(pos); newElement->draw(&painter); pos += QPointF(_offsetPanel, 0); painter.translate(-pos); delete newElement; // This second pass draws the elements spaced evently using the width of the largest element for (const Element* e : el) { if (!e->visible() && !_score->showInvisible()) continue; if (e->isRest() && toRest(e)->isGap()) continue; if (e->isStaffLines()) { painter.save(); Staff* currentStaff = _score->staff(e->staffIdx()); Segment* parent = _score->tick2segmentMM(tick); pos = QPointF (_offsetPanel, e->pagePos().y()); painter.translate(pos); // Draw staff lines StaffLines newStaffLines(*toStaffLines(e)); newStaffLines.setParent(parent); newStaffLines.setTrack(e->track()); newStaffLines.layout(); newStaffLines.setColor(color); newStaffLines.setWidth(bg.width()); newStaffLines.draw(&painter); // Draw barline BarLine barLine(_score); barLine.setBarLineType(BarLineType::NORMAL); barLine.setParent(parent); barLine.setTrack(e->track()); barLine.setSpan(currentStaff->barLineSpan()); barLine.setSpanFrom(currentStaff->barLineFrom()); barLine.setSpanTo(currentStaff->barLineTo()); barLine.layout(); barLine.setColor(color); barLine.draw(&painter); // Draw the current staff name QList<StaffName>& staffNamesLong = currentStaff->part()->instrument()->longNames(); QString staffName = staffNamesLong.isEmpty() ? " " : staffNamesLong[0].name(); if (staffName == "") { QList<StaffName>& staffNamesShort = currentStaff->part()->instrument()->shortNames(); staffName = staffNamesShort.isEmpty() ? "" : staffNamesShort[0].name(); } Text* newName = new Text(_score); newName->setXmlText(staffName); newName->setParent(parent); newName->setTrack(e->track()); newName->setColor(color); newName->textStyle().setFamily("FreeSans"); newName->textStyle().setSizeIsSpatiumDependent(true); newName->layout(); newName->setPlainText(newName->plainText()); newName->layout(); if (currentStaff->part()->staff(0) == currentStaff) { double _spatium = _score->spatium(); pos = QPointF (_score->styleP(StyleIdx::clefLeftMargin) + _widthClef, -_spatium * 2); painter.translate(pos); newName->draw(&painter); painter.translate(-pos); } delete newName; qreal posX = 0.0; // Draw the current Clef Clef clef(_score); clef.setClefType(currentStaff->clef(tick)); clef.setParent(parent); clef.setTrack(e->track()); clef.setColor(color); clef.layout(); posX += _score->styleP(StyleIdx::clefLeftMargin); clef.drawAt(&painter, QPointF(posX, clef.pos().y())); posX += _widthClef; // Draw the current KeySignature KeySig newKs(_score); newKs.setKeySigEvent(currentStaff->keySigEvent(tick)); // The Parent and the track must be set to have the key signature layout adjusted to different clefs // This also adds naturals to the key signature (if set in the score style) newKs.setParent(parent); newKs.setTrack(e->track()); newKs.setColor(color); newKs.setHideNaturals(true); newKs.layout(); posX += _score->styleP(StyleIdx::keysigLeftMargin); newKs.drawAt(&painter, QPointF(posX, 0.0)); posX += _widthKeySig + _xPosTimeSig; // Draw the current TimeSignature TimeSig newTs(_score); // Try to get local time signature, if not, get the current measure one TimeSig* currentTimeSig = currentStaff->timeSig(tick); if (currentTimeSig) { newTs.setFrom(currentTimeSig); newTs.setParent(parent); newTs.setTrack(e->track()); newTs.setColor(color); newTs.layout(); posX += _score->styleP(StyleIdx::timesigLeftMargin); newTs.drawAt(&painter, QPointF(posX, 0.0)); } painter.restore(); } } painter.restore(); _visible = true; }
// protected virtual [base QWidget] void kpDualColorButton::paintEvent (QPaintEvent *e) { #if DEBUG_KP_DUAL_COLOR_BUTTON && 1 qCDebug(kpLogWidgets) << "kpDualColorButton::draw() rect=" << rect () << " contentsRect=" << contentsRect () << endl; #endif // Draw frame first. QFrame::paintEvent (e); QPainter painter (this); // Fill with background. if (isEnabled ()) { kpView::drawTransparentBackground (&painter, contentsRect ().topLeft ()/*checkerboard top-left*/, contentsRect (), true/*preview*/); } else { // Use default widget background. } painter.translate (contentsRect ().x (), contentsRect ().y ()); // Draw "Swap Colours" button (top-right). QPixmap swapPixmap = UserIcon ("colorbutton_swap_16x16"); if (!isEnabled ()) { // Don't let the fill() touch the mask. QBitmap swapBitmapMask = swapPixmap.mask (); swapPixmap.setMask (QBitmap ()); // Grey out the opaque parts of "swapPixmap". swapPixmap.fill (palette ().color (QPalette::Dark)); swapPixmap.setMask (swapBitmapMask); } painter.drawPixmap (swapPixmapRect ().topLeft (), swapPixmap); // Draw background colour patch. QRect bgRect = backgroundRect (); QRect bgRectInside = QRect (bgRect.x () + 2, bgRect.y () + 2, bgRect.width () - 4, bgRect.height () - 4); if (isEnabled ()) { #if DEBUG_KP_DUAL_COLOR_BUTTON && 1 qCDebug(kpLogWidgets) << "\tbackgroundColor=" << (int *) m_color [1].toQRgb () << endl; #endif if (m_color [1].isTransparent ()) // only if fully transparent painter.drawPixmap (bgRectInside, UserIcon ("color_transparent_26x26")); else painter.fillRect (bgRectInside, m_color [1].toQColor ()); } else painter.fillRect (bgRectInside, palette().color (QPalette::Button)); qDrawShadePanel (&painter, bgRect, palette(), false/*not sunken*/, 2/*lineWidth*/, 0/*never fill*/); // Draw foreground colour patch. // Must be drawn after background patch since we're on top. QRect fgRect = foregroundRect (); QRect fgRectInside = QRect (fgRect.x () + 2, fgRect.y () + 2, fgRect.width () - 4, fgRect.height () - 4); if (isEnabled ()) { #if DEBUG_KP_DUAL_COLOR_BUTTON && 1 qCDebug(kpLogWidgets) << "\tforegroundColor=" << (int *) m_color [0].toQRgb () << endl; #endif if (m_color [0].isTransparent ()) // only if fully transparent painter.drawPixmap (fgRectInside, UserIcon ("color_transparent_26x26")); else painter.fillRect (fgRectInside, m_color [0].toQColor ()); } else painter.fillRect (fgRectInside, palette ().color (QPalette::Button)); qDrawShadePanel (&painter, fgRect, palette (), false/*not sunken*/, 2/*lineWidth*/, 0/*never fill*/); }
void QgsDecorationNorthArrowDialog::drawNorthArrow() { int rotation = spinAngle->value(); double maxLength = 64; QSvgRenderer svg; const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( mDeco.svgPath(), maxLength, pbnChangeColor->color(), pbnChangeOutlineColor->color(), 1.0, 1.0 ); svg.load( svgContent ); if ( svg.isValid() ) { QSize size( maxLength, maxLength ); QRectF viewBox = svg.viewBoxF(); if ( viewBox.height() > viewBox.width() ) { size.setWidth( maxLength * viewBox.width() / viewBox.height() ); } else { size.setHeight( maxLength * viewBox.height() / viewBox.width() ); } QPixmap myPainterPixmap( maxLength, maxLength ); myPainterPixmap.fill(); QPainter myQPainter; myQPainter.begin( &myPainterPixmap ); myQPainter.setRenderHint( QPainter::SmoothPixmapTransform ); double centerXDouble = size.width() / 2.0; double centerYDouble = size.height() / 2.0; //save the current canvas rotation myQPainter.save(); myQPainter.translate( ( maxLength - size.width() ) / 2, ( maxLength - size.height() ) / 2 ); //rotate the canvas myQPainter.rotate( rotation ); //work out how to shift the image so that it appears in the center of the canvas //(x cos a + y sin a - x, -x sin a + y cos a - y) double myRadiansDouble = ( M_PI / 180 ) * rotation; int xShift = static_cast<int>( ( ( centerXDouble * std::cos( myRadiansDouble ) ) + ( centerYDouble * std::sin( myRadiansDouble ) ) ) - centerXDouble ); int yShift = static_cast<int>( ( ( -centerXDouble * std::sin( myRadiansDouble ) ) + ( centerYDouble * std::cos( myRadiansDouble ) ) ) - centerYDouble ); //draw the pixmap in the proper position myQPainter.translate( xShift, yShift ); svg.render( &myQPainter, QRectF( 0, 0, size.width(), size.height() ) ); //unrotate the canvas again myQPainter.restore(); myQPainter.end(); pixmapLabel->setPixmap( myPainterPixmap ); } else { QPixmap myPainterPixmap( 200, 200 ); myPainterPixmap.fill(); QPainter myQPainter; myQPainter.begin( &myPainterPixmap ); QFont myQFont( QStringLiteral( "time" ), 12, QFont::Bold ); myQPainter.setFont( myQFont ); myQPainter.setPen( Qt::red ); myQPainter.drawText( 10, 20, tr( "Pixmap not found" ) ); myQPainter.end(); pixmapLabel->setPixmap( myPainterPixmap ); } }
void RulerT::paintEvent(QPaintEvent *) { double xl; QPainter p; p.begin(this); p.drawLine(0, 24, width(), 24); p.translate(-offset, 0); p.setBrush(Qt::black); p.setFont(font()); p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); for (xl = 0; xl < width()+offset; xl += iter) { if (xl < offset) continue; p.drawLine(qRound(xl), 18, qRound(xl), 24); } for (xl = 0; xl < width()+(iter2/2)+offset; xl += iter2) { if (xl < offset) continue; p.drawLine(qRound(xl), 11, qRound(xl), 24); switch (unitIndex) { case 2: { QString tx = ""; int num1 = static_cast<int>(xl / iter2); if (num1 != 0) tx = QString::number(num1); double frac = (xl / iter2) - num1; if ((frac > 0.24) && (frac < 0.26)) tx += QChar(0xBC); if ((frac > 0.49) && (frac < 0.51)) tx += QChar(0xBD); if ((frac > 0.74) && (frac < 0.76)) tx += QChar(0xBE); p.drawText(qRound(xl+2), 17, tx); break; } case 3: p.drawText(qRound(xl+2), 17, QString::number(xl / iter)); break; default: p.drawText(qRound(xl+2), 17, QString::number(xl / iter * 10)); break; } } if (tabValues.count() != 0) { for (int yg = 0; yg < static_cast<int>(tabValues.count()); yg++) { if (yg == actTab) p.setPen(QPen(Qt::red, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); else p.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); switch (static_cast<int>(tabValues[yg].tabType)) { case 0: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition+8), 23); break; case 1: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition), 23, qRound(tabValues[yg].tabPosition-8), 23); break; case 2: case 3: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23); p.drawLine(qRound(tabValues[yg].tabPosition+3), 20, qRound(tabValues[yg].tabPosition+2), 20); break; case 4: p.drawLine(qRound(tabValues[yg].tabPosition), 15, qRound(tabValues[yg].tabPosition), 23); p.drawLine(qRound(tabValues[yg].tabPosition-4), 23, qRound(tabValues[yg].tabPosition+4), 23); break; default: break; } } } if (haveInd) { p.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p.setBrush(Qt::blue); QPolygon cr; cr.setPoints(3, qRound(firstLine+leftIndent), 12, qRound(firstLine+leftIndent-4), 0, qRound(firstLine+leftIndent+4), 0); p.drawPolygon(cr); QPolygon cr2; cr2.setPoints(3, qRound(leftIndent), 12, qRound(leftIndent+4), 24, qRound(leftIndent-4), 24); p.drawPolygon(cr2); } p.end(); }
QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight ) const { QgsSymbol *s = mItem.symbol(); if ( !s ) { return QSizeF(); } // setup temporary render context QgsRenderContext context; context.setScaleFactor( settings.dpi() / 25.4 ); context.setRendererScale( settings.mapScale() ); context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) ); context.setForceVectorOutput( true ); context.setPainter( ctx ? ctx->painter : nullptr ); if ( ctx && ctx->context ) { context.setExpressionContext( ctx->context->expressionContext() ); } else { // setup a minimal expression context QgsExpressionContext expContext; expContext.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( nullptr ) ); context.setExpressionContext( expContext ); } //Consider symbol size for point markers double height = settings.symbolSize().height(); double width = settings.symbolSize().width(); //Center small marker symbols double widthOffset = 0; double heightOffset = 0; if ( QgsMarkerSymbol *markerSymbol = dynamic_cast<QgsMarkerSymbol *>( s ) ) { // allow marker symbol to occupy bigger area if necessary double size = markerSymbol->size( context ) / context.scaleFactor(); height = size; width = size; if ( width < settings.symbolSize().width() ) { widthOffset = ( settings.symbolSize().width() - width ) / 2.0; } if ( height < settings.symbolSize().height() ) { heightOffset = ( settings.symbolSize().height() - height ) / 2.0; } } if ( ctx && ctx->painter ) { double currentXPosition = ctx->point.x(); double currentYCoord = ctx->point.y() + ( itemHeight - settings.symbolSize().height() ) / 2; QPainter *p = ctx->painter; //setup painter scaling to dots so that raster symbology is drawn to scale double dotsPerMM = context.scaleFactor(); int opacity = 255; if ( QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layerNode()->layer() ) ) opacity = ( 255 * vectorLayer->opacity() ); p->save(); p->setRenderHint( QPainter::Antialiasing ); p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset ); p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM ); if ( opacity != 255 && settings.useAdvancedEffects() ) { //semi transparent layer, so need to draw symbol to an image (to flatten it first) //create image which is same size as legend rect, in case symbol bleeds outside its alloted space QSize tempImageSize( width * dotsPerMM, height * dotsPerMM ); QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 ); tempImage.fill( Qt::transparent ); QPainter imagePainter( &tempImage ); context.setPainter( &imagePainter ); s->drawPreviewIcon( &imagePainter, tempImageSize, &context ); context.setPainter( ctx->painter ); //reduce opacity of image imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) ); imagePainter.end(); //draw rendered symbol image p->drawImage( 0, 0, tempImage ); } else { s->drawPreviewIcon( p, QSize( width * dotsPerMM, height * dotsPerMM ), &context ); } if ( !mTextOnSymbolLabel.isEmpty() ) { QFontMetricsF fm( mTextOnSymbolTextFormat.scaledFont( context ) ); qreal yBaselineVCenter = ( height * dotsPerMM + fm.ascent() - fm.descent() ) / 2; QgsTextRenderer::drawText( QPointF( width * dotsPerMM / 2, yBaselineVCenter ), 0, QgsTextRenderer::AlignCenter, QStringList() << mTextOnSymbolLabel, context, mTextOnSymbolTextFormat ); } p->restore(); } return QSizeF( std::max( width + 2 * widthOffset, static_cast< double >( settings.symbolSize().width() ) ), std::max( height + 2 * heightOffset, static_cast< double >( settings.symbolSize().height() ) ) ); }
void QZint::render(QPainter & painter, const QRectF & paintRect, AspectRatioMode mode) { encode(); bool textdone; int comp_offset = 0, xoffset = m_whitespace, j, main_width = 0, addon_text_height = 0; int yoffset = 0; QString caption = QString::fromUtf8((const char *)m_zintSymbol->text, -1); QFont fontSmall(fontstyle); fontSmall.setPixelSize(fontPixelSizeSmall); QFont fontLarge(fontstyle); fontLarge.setPixelSize(fontPixelSizeLarge); if (m_lastError.length()) { painter.setFont(fontLarge); painter.drawText(paintRect,Qt::AlignCenter,m_lastError); return; } painter.save(); painter.setClipRect(paintRect,Qt::IntersectClip); qreal xtr=paintRect.x(); qreal ytr=paintRect.y(); int zrow_height=m_zintSymbol->height; int zrows=0; for (int i=0;i<m_zintSymbol->rows;i++) { zrow_height-=m_zintSymbol->row_height[i]; if (!m_zintSymbol->row_height[i]) zrows++; } if (zrows) { zrow_height/=zrows; for (int i=0;i<m_zintSymbol->rows;i++) if (!m_zintSymbol->row_height[i]) m_zintSymbol->row_height[i]=zrow_height; } else m_zintSymbol->height-=zrow_height; qreal gwidth=m_zintSymbol->width; qreal gheight=m_zintSymbol->height; if (m_zintSymbol->symbology == BARCODE_MAXICODE) { gheight*=(maxi_width); gwidth*=(maxi_width+1); } qreal xsf=1; qreal ysf=1; qreal textoffset = 0; gwidth+=((m_border==BOX)?m_borderWidth*2:0); gheight+=((m_border!=NO_BORDER)?m_borderWidth*2:0); if(QString((const char*)m_zintSymbol->text).isEmpty() == false) { textoffset = 9; gheight += textoffset; } else { textoffset = 0; } gwidth+=m_zintSymbol->whitespace_width*2; switch(mode) { case IgnoreAspectRatio: xsf=(qreal)paintRect.width()/gwidth; ysf=(qreal)paintRect.height()/gheight; break; case KeepAspectRatio: if (paintRect.width()/gwidth<paintRect.height()/gheight) { ysf=xsf=(qreal)paintRect.width()/gwidth; ytr+=(qreal)(paintRect.height()-gheight*ysf)/2; } else { ysf=xsf=(qreal)paintRect.height()/gheight; xtr+=(qreal)(paintRect.width()-gwidth*xsf)/2; } break; case CenterBarCode: xtr+=((qreal)paintRect.width()-gwidth*xsf)/2; ytr+=((qreal)paintRect.height()-gheight*ysf)/2; break; } painter.setBackground(QBrush(m_bgColor)); painter.fillRect(paintRect,QBrush(m_bgColor)); painter.translate(xtr,ytr); painter.scale(xsf,ysf); QPen p; p.setColor(m_fgColor); p.setWidth(m_borderWidth); painter.setPen(p); QPainterPath pt; if(m_zintSymbol->symbology != BARCODE_MAXICODE) { /* Draw boundary bars or boxes around the symbol */ switch(m_border) { case BOX: painter.fillRect(0,m_borderWidth,m_borderWidth,m_zintSymbol->height,QBrush(m_fgColor)); painter.fillRect(m_zintSymbol->width + xoffset + xoffset + m_borderWidth,m_borderWidth,m_borderWidth,m_zintSymbol->height,QBrush(m_fgColor)); painter.fillRect(0,0,m_zintSymbol->width + xoffset + xoffset + m_borderWidth + m_borderWidth,m_borderWidth,QBrush(m_fgColor)); painter.fillRect(0,m_zintSymbol->height + m_borderWidth,m_zintSymbol->width + xoffset + xoffset + m_borderWidth + m_borderWidth, m_borderWidth,QBrush(m_fgColor)); painter.translate(m_borderWidth+m_zintSymbol->whitespace_width,m_borderWidth); yoffset = m_borderWidth; break; case BIND: painter.fillRect(0,0,m_zintSymbol->width + xoffset + xoffset,m_borderWidth,QBrush(m_fgColor)); painter.fillRect(0,m_zintSymbol->height + m_borderWidth,m_zintSymbol->width + xoffset + xoffset, m_borderWidth,QBrush(m_fgColor)); painter.translate(m_zintSymbol->whitespace_width,m_borderWidth); yoffset = m_borderWidth; break; default: painter.translate(m_zintSymbol->whitespace_width,0); break;; } } while(!(module_set(m_zintSymbol->rows - 1, comp_offset))) { comp_offset++; } xoffset = comp_offset; /* Set up some values for displaying EAN and UPC symbols correctly */ main_width = m_zintSymbol->width; if ((((m_zintSymbol->symbology == BARCODE_EANX) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_EANX_CC)) || (m_zintSymbol->symbology == BARCODE_ISBNX)) { switch(caption.size()) { case 13: /* EAN 13 */ case 16: case 19: if(m_zintSymbol->whitespace_width == 0) { m_zintSymbol->whitespace_width = 10; } main_width = 96 + comp_offset; break; default: main_width = 68 + comp_offset; break; } } if (((m_zintSymbol->symbology == BARCODE_UPCA) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_UPCA_CC)) { if(m_zintSymbol->whitespace_width == 0) { m_zintSymbol->whitespace_width = 10; } main_width = 96 + comp_offset; } if (((m_zintSymbol->symbology == BARCODE_UPCE) && (m_zintSymbol->rows == 1)) || (m_zintSymbol->symbology == BARCODE_UPCE_CC)) { if(m_zintSymbol->whitespace_width == 0) { m_zintSymbol->whitespace_width = 10; } main_width = 51 + comp_offset; } p.setWidth(1); painter.setPen(p); if (m_zintSymbol->symbology == BARCODE_MAXICODE) { /* Draw Maxicode with hexagons */ painter.save(); painter.setRenderHint(QPainter::Antialiasing); for (int r=0;r<m_zintSymbol->rows;r++) { for (int c=0;c<m_zintSymbol->width;c++) { if (module_set(r, c)) { qreal col=(qreal)c*(maxi_width+1)+(r%2)*((maxi_width+1)/2); qreal row=(qreal)r*(maxi_width+1)*0.868; QPainterPath pt; pt.moveTo(col+maxi_width/2, row); pt.lineTo(col+maxi_width, row+maxi_diagonal/4); pt.lineTo(col+maxi_width, row+(maxi_diagonal-maxi_diagonal/4)); pt.lineTo(col+maxi_width/2, row+maxi_diagonal); pt.lineTo(col, row+(maxi_diagonal-maxi_diagonal/4)); pt.lineTo(col, row+maxi_diagonal/4); pt.lineTo(col+maxi_width/2, row); painter.fillPath(pt,QBrush(m_fgColor)); } } } p.setWidth(maxi_width); painter.setPen(p); const qreal w=maxi_width+1; painter.drawEllipse(QPointF(14.5*w,16.5*w*0.868),w,w); painter.drawEllipse(QPointF(14.5*w,16.5*w*0.868),w+w*1.5,w+w*1.5); painter.drawEllipse(QPointF(14.5*w,16.5*w*0.868),w+w*3,w+w*3); painter.restore(); } else { /* Draw all other symbols with rectangles */ int y=0; for (int row=0;row<m_zintSymbol->rows;row++) { for (int i=0;i<m_zintSymbol->width;i++) { if (module_set(row, i)) { int ed = module_set(row, i); int linewidth=0; for (int j=i;j<m_zintSymbol->width;j++,linewidth++) if (ed != module_set(row, j)) break; QColor color; color=m_fgColor; if(!((i > main_width) && (row == m_zintSymbol->rows - 1))) { painter.fillRect(i,y,linewidth,m_zintSymbol->row_height[row],QBrush(color)); } else { painter.fillRect(i,y + 8,linewidth,m_zintSymbol->row_height[row] - 3,QBrush(color)); addon_text_height = y; } } } /* Add row binding */ if(((m_zintSymbol->symbology == BARCODE_CODE16K) || (m_zintSymbol->symbology == BARCODE_CODE49)) && (row != 0)) { painter.fillRect(0,y - 1,m_zintSymbol->width,2,QBrush(m_fgColor)); } y+=m_zintSymbol->row_height[row]; } } textdone = false; if(m_hidetext == false) { painter.setFont(fontSmall); if(((m_zintSymbol->symbology == BARCODE_EANX) || (m_zintSymbol->symbology == BARCODE_EANX_CC)) || (m_zintSymbol->symbology == BARCODE_ISBNX)) { /* Add bridge and format text for EAN */ switch(caption.size()) { case 8: case 11: case 14: painter.fillRect(0 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(2 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(32 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(34 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(64 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(66 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.setFont(fontLarge); painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 29, 9,Qt::AlignCenter, caption.mid(0,4)); painter.drawText(35 + xoffset, m_zintSymbol->height + yoffset, 29, 9,Qt::AlignCenter, caption.mid(4,4)); if(caption.size() == 11) { /* EAN-2 */ painter.drawText(76 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(9,2)); }; if(caption.size() == 14) { /* EAN-5 */ painter.drawText(76 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); }; painter.setFont(fontSmall); textdone = true; break; case 13: case 16: case 19: painter.fillRect(0 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(2 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(46 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(48 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(92 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(94 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.setFont(fontLarge); painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset, 7, 9,Qt::AlignCenter, caption.mid(0,1)); painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 43, 9,Qt::AlignCenter, caption.mid(1,6)); painter.drawText(49 + xoffset, m_zintSymbol->height + yoffset, 43, 9,Qt::AlignCenter, caption.mid(7,6)); if(caption.size() == 16) { /* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(14,2)); }; if(caption.size() == 19) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(14,5)); }; painter.setFont(fontSmall); textdone = true; break; } if(textdone == false) { painter.setFont(fontLarge); painter.drawText(0, m_zintSymbol->height, m_zintSymbol->width, 9,Qt::AlignCenter, caption); painter.setFont(fontSmall); textdone = true; } } if((m_zintSymbol->symbology == BARCODE_UPCA) || (m_zintSymbol->symbology == BARCODE_UPCA_CC)) { /* Add bridge and format text for UPC-A */ int block_width; bool latch = true; j = 0 + comp_offset; do { block_width = 0; do { block_width++; } while (module_set(m_zintSymbol->rows - 1, j + block_width) == module_set(m_zintSymbol->rows - 1, j)); if(latch == true) { /* a bar */ painter.fillRect(j + xoffset - comp_offset,m_zintSymbol->height,block_width,5,QBrush(m_fgColor)); latch = false; } else { /* a space */ latch = true; } j += block_width; } while (j < 11 + comp_offset); painter.fillRect(46 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(48 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); latch = true; j = 85 + comp_offset; do { block_width = 0; do { block_width++; } while (module_set(m_zintSymbol->rows - 1, j + block_width) == module_set(m_zintSymbol->rows - 1, j)); if(latch == true) { /* a bar */ painter.fillRect(j + xoffset - comp_offset,m_zintSymbol->height,block_width,5,QBrush(m_fgColor)); latch = false; } else { /* a space */ latch = true; } j += block_width; } while (j < 96 + comp_offset); painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(0,1)); painter.drawText(96 + xoffset, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(11,1)); painter.setFont(fontLarge); painter.drawText(11 + xoffset, m_zintSymbol->height + yoffset, 35, 9,Qt::AlignCenter, caption.mid(1,5)); painter.drawText(49 + xoffset, m_zintSymbol->height + yoffset, 35, 9,Qt::AlignCenter, caption.mid(6,5)); if(caption.size() == 15) { /* EAN-2 */ painter.drawText(104 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(13,2)); }; if(caption.size() == 18) { /* EAN-5 */ painter.drawText(104 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(13,5)); }; painter.setFont(fontSmall); textdone = true; } if((m_zintSymbol->symbology == BARCODE_UPCE) || (m_zintSymbol->symbology == BARCODE_UPCE_CC)) { /* Add bridge and format text for UPC-E */ painter.fillRect(0 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(2 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(46 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(48 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.fillRect(50 + xoffset,m_zintSymbol->height,1,5,QBrush(m_fgColor)); painter.drawText(xoffset - 7, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(0,1)); painter.drawText(51 + xoffset, m_zintSymbol->height + yoffset + 2, 7, 7,Qt::AlignCenter, caption.mid(7,1)); painter.setFont(fontLarge); painter.drawText(3 + xoffset, m_zintSymbol->height + yoffset, 43, 9,Qt::AlignCenter, caption.mid(1,6)); if(caption.size() == 11) { /* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 20, 9,Qt::AlignCenter, caption.mid(9,2)); }; if(caption.size() == 14) { /* EAN-2 */ painter.drawText(60 + xoffset, addon_text_height, 47, 9,Qt::AlignCenter, caption.mid(9,5)); }; painter.setFont(fontSmall); textdone = true; } } /* if (m_hidetext == false) */ if((m_hidetext == false) && (textdone == false)) { /* Add text to any other symbol */ painter.drawText(0, m_zintSymbol->height + yoffset, m_zintSymbol->width, 7, Qt::AlignCenter, caption); } painter.restore(); }
void TurnAndBank::createFrame(void){ QImage _frameImage = QImage(QSize(600,600), QImage::Format_ARGB32); _frameImage.fill(0x00ff0000); int outerR = _frameImage.width()/2; const int innerR = _frameImage.width()/2-60; QPainter p; p.setRenderHint(QPainter::Antialiasing, true); p.setRenderHint(QPainter::SmoothPixmapTransform, true); p.begin(&_frameImage); p.translate(300, 300); p.setPen(Qt::NoPen); p.setBrush(Qt::SolidPattern); p.setBrush(QColor(225,225,225)); QRadialGradient gradient(0, 0, outerR, 0, 0); gradient.setSpread(QGradient::ReflectSpread); gradient.setColorAt(0, Qt::white); gradient.setColorAt(1, Qt::black); QBrush gbrush(gradient); p.setBrush(gbrush); p.drawChord(-outerR, -outerR, 2*outerR, 2*outerR, 0, 360*16); //Ring outside of intstrument with white line: if (0){ p.setPen(QPen(QColor(225,225,225), 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); p.setBrush(Qt::NoBrush); p.drawChord(-outerR, -outerR, 2*outerR, 2*outerR, 0, 360*16); } // Create black inner core: p.setBrush(Qt::black); p.setPen(Qt::NoPen); p.drawChord(-innerR, -innerR, 2*innerR, 2*innerR, 0, 360*16); // Put horizontal and 2minute lines on outside: p.setPen(QPen(Qt::white, 7, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); const float angle = 15.; outerR = outerR-20; p.drawLine(innerR*cos(angle/180*M_PI), innerR*sin(angle/180*M_PI), outerR*cos(angle/180*M_PI), outerR*sin(angle/180*M_PI)); p.drawLine(-innerR*cos(angle/180*M_PI), innerR*sin(angle/180*M_PI), -outerR*cos(angle/180*M_PI), outerR*sin(angle/180*M_PI)); p.drawLine(innerR, 0, outerR, 0); p.drawLine(-innerR, 0, -outerR, 0); // Little vacuum text line p.setPen(QColor(200,200,200)); QFont topLabelFont = defaultFont; topLabelFont.setBold(true); p.setFont(topLabelFont); QString legend = "NO PITCH"; int width = p.fontMetrics().width(legend); int height = p.fontMetrics().height(); p.drawText(0-width/2,245,width, height, Qt::AlignCenter, legend); legend = "INFORMATION"; width = p.fontMetrics().width(legend); p.drawText(0-width/2,267,width, height, Qt::AlignCenter, legend); legend = "D. C. ELEC."; width = p.fontMetrics().width(legend); height =p.fontMetrics().height(); p.drawText(0-width/2,-275,width, height, Qt::AlignCenter, legend); legend = "2 MIN"; width = p.fontMetrics().width(legend); height =p.fontMetrics().height(); p.drawText(0-width/2,205,width, height, Qt::AlignCenter, legend); legend = "TURN COORDINATOR"; width = p.fontMetrics().width(legend); height =p.fontMetrics().height(); p.drawText(0-width/2,-150,width, height, Qt::AlignCenter, legend); QFont lrFont = defaultFont; lrFont.setPointSizeF(defaultFont.pointSizeF() * 2); lrFont.setBold(true); p.setFont(lrFont); legend = "L"; width = p.fontMetrics().width(legend); height = p.fontMetrics().height(); p.drawText(-265*cos(18./180.*M_PI)-width/2+5, 265*sin(18./180.*M_PI), width, height, Qt::AlignCenter, legend); legend = "R"; width = p.fontMetrics().width(legend); height = p.fontMetrics().height(); p.drawText(265*cos(18./180.*M_PI)-width/2-5, 265*sin(18./180.*M_PI), width, height, Qt::AlignCenter, legend); p.end(); _frame = QPixmap::fromImage(_frameImage, Qt::AutoColor); }
void WindowServerLuna::generateWallpaperImages() { qreal hScale, vScale, wallpaperScale, wallpaperScaleRot = 0.0; int screenWidth = SystemUiController::instance()->currentUiWidth(); int screenHeight = SystemUiController::instance()->currentUiHeight(); QPixmap image = QPixmap(m_wallpaperFileName); if (image.isNull()) return; bool desktop(false); #ifdef TARGET_DESKTOP desktop = true; #endif if(((image.width() < screenWidth) || (image.height() < screenHeight)) && ((image.height() < screenWidth) || (image.width() < screenHeight)) && !desktop) { // image is not large enough to fill the screen in any orientation, so do not scale it and // draw it centered on the screen m_normalWallpaperImage = QPixmap(image.width(), image.height()); m_rotatedWallpaperImage = QPixmap(); wallpaperScale = 1; m_wallpaperFullScreen = false; if (m_normalWallpaperImage.isNull()) return; } else { // image can fill the screen in some orientations, so scale it to always fill the entire screen m_normalWallpaperImage = QPixmap(m_screenWidth, m_screenHeight); m_rotatedWallpaperImage = QPixmap(m_screenWidth, m_screenHeight); hScale = (qreal)m_screenWidth / image.width(); vScale = (qreal)m_screenHeight / image.height(); if(hScale >= vScale) wallpaperScale = hScale; else wallpaperScale = vScale; vScale = (qreal)m_screenHeight / image.width(); hScale = (qreal)m_screenWidth / image.height(); if(hScale >= vScale) wallpaperScaleRot = hScale; else wallpaperScaleRot = vScale; m_wallpaperFullScreen = true; if (m_normalWallpaperImage.isNull()) return; if (m_rotatedWallpaperImage.isNull()) return; } QRect target; QPainter painter; painter.begin(&m_normalWallpaperImage); target = QRect((-image.rect().width()/2), (-image.rect().height()/2), image.rect().width(), image.rect().height()); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); painter.translate(m_normalWallpaperImage.width()/2, m_normalWallpaperImage.height()/2); painter.scale(wallpaperScale,wallpaperScale); painter.drawPixmap(target, image); painter.end(); if(m_wallpaperFullScreen) {// also generate the cropped and rotated version painter.begin(&m_rotatedWallpaperImage); target = QRect((-image.rect().width()/2), (-image.rect().height()/2), image.rect().width(), image.rect().height()); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); painter.translate(m_rotatedWallpaperImage.width()/2, m_rotatedWallpaperImage.height()/2); painter.rotate(90); painter.scale(wallpaperScaleRot,wallpaperScaleRot); painter.drawPixmap(target, image); painter.end(); } if(Settings::LunaSettings()->displayUiRotates) { updateWallpaperForRotation(m_currentUiOrientation); } else { m_currWallpaperImg = &m_normalWallpaperImage; Q_EMIT signalWallpaperImageChanged(m_currWallpaperImg, m_wallpaperFullScreen, 0); } }
//___________________________________________________ void Button::paint( QPainter& painter ) { QPalette palette( _client.palette() ); palette.setCurrentColorGroup( isActive() ? QPalette::Active : QPalette::Inactive); if( _client.compositingActive() && !( _client.isMaximized() || _type == ButtonItemClose || _type == ButtonItemMenu ) ) { painter.translate( 0, -1 ); } // translate buttons down if window maximized if( _client.isMaximized() ) painter.translate( 0, 1 ); // base button color QColor base; if( _type == ButtonItemClose && _forceInactive ) base = _client.backgroundPalette( this, palette ).window().color(); else if( _type == ButtonItemClose ) base = palette.window().color(); else base = palette.button().color(); // text color QColor color = (_type == ButtonItemClose && _forceInactive ) ? buttonDetailColor( _client.backgroundPalette( this, palette ) ): buttonDetailColor( palette ); // decide decoration color QColor glow; if( isAnimated() || (_status&Hovered) ) { glow = isCloseButton() ? _helper.viewNegativeTextBrush().brush(palette).color(): _helper.viewHoverBrush().brush(palette).color(); if( isAnimated() ) { color = KColorUtils::mix( color, glow, glowIntensity() ); glow = _helper.alphaColor( glow, glowIntensity() ); } else if( _status&Hovered ) color = glow; } if( hasDecoration() ) { // scale qreal scale( (21.0*_client.buttonSize())/22.0 ); // pressed state const bool pressed( (_status&Pressed) || ( _type == ButtonSticky && _client.isOnAllDesktops() ) || ( _type == ButtonAbove && _client.keepAbove() ) || ( _type == ButtonBelow && _client.keepBelow() ) ); // draw button shape painter.drawPixmap(0, 0, _helper.windecoButton( base, glow, pressed, scale ) ); } // Icon // for menu button the application icon is used if( isMenuButton() ) { int iconScale( 0 ); switch( _client.buttonSize() ) { case Configuration::ButtonSmall: iconScale = 13; break; default: case Configuration::ButtonDefault: iconScale = 16; break; case Configuration::ButtonLarge: iconScale = 20; break; case Configuration::ButtonVeryLarge: iconScale = 24; break; case Configuration::ButtonHuge: iconScale = 35; break; } const QPixmap& pixmap( _client.icon().pixmap( iconScale ) ); const double offset = 0.5*(width()-pixmap.width() ); painter.drawPixmap(offset, offset-1, pixmap ); } else { painter.setRenderHints(QPainter::Antialiasing); qreal width( 1.2 ); // contrast painter.setBrush(Qt::NoBrush); painter.setPen(QPen( _helper.calcLightColor( base ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); drawIcon(&painter); // main painter.translate(0,-1.5); painter.setBrush(Qt::NoBrush); painter.setPen(QPen(color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); drawIcon(&painter); } }
void TimeRuler::initUI() { int width = m_widthMonth + (m_lstDates.numYears() * 12 ) * m_widthMonth + m_widthMonth; m_pixmap = QPixmap(width, m_height); m_pixmap.fill(backgroundColor()); QPainter p (&m_pixmap); p.save(); p.setPen(Qt::gray); p.setBrush(Qt::white); QStyle& style = KApplication::kApplication()->style(); //draw a frame QColorGroup cg = colorGroup(); cg.setColor(QColorGroup::Background, Qt::white); style.drawPrimitive(QStyle::PE_ButtonBevel, &p, QRect(m_widthMonth, 3, width - 2 * m_widthMonth, m_yBase - 3), cg); p.restore(); //first create the month counter on a temporaroy pixmap QPixmap tp(12 * m_widthMonth, 20); tp.fill(backgroundColor()); QPainter tpp (&tp); tpp.translate(0,20); tpp.rotate(-90); QFont f(p.font()); f.setPixelSize(10); f.setBold(false); tpp.setFont(f); for (int i = 0; i <12; ++i) { tpp.drawText(0, i * m_widthMonth, 20, m_widthMonth, Qt::AlignRight | Qt::AlignVCenter, QString::number(i+1)); } tpp.end(); int over = -2; int x = 0; //reset the counting mechanism... m_lstDates.count(-1); for (int y = m_lstDates.firstYear(); y <= m_lstDates.lastYear(); ++ y) { for (int m = 1; m <= 12 ; ++m) { x = m_widthMonth + ((y - m_lstDates.firstYear())*12 + m -1 ) * m_widthMonth; if (m == 1) { bitBlt(&m_pixmap, x, m_yBase + 3, &tp, 0, 0, tp.width(), tp.height()); //draw the year numbers f.setPixelSize(16); f.setBold(true); p.setFont(f); p.drawText(x, m_yBase, 12 * m_widthMonth, m_height-m_yBase, Qt::AlignHCenter | Qt::AlignBottom, QString::number(y)); //draw the bold year lines p.setPen(QPen(Qt::gray, 3)); p.drawLine(x, m_yBase+over, x, m_yBase+22); p.setPen(QPen(Qt::black, 1)); p.drawLine(x, m_yBase+over, x, m_yBase+22); } else if (m == 7) { //draw the semi big half year marks p.setPen(QPen(Qt::gray, 3)); p.drawLine(x, m_yBase+over, x, m_yBase+8); p.setPen(QPen(Qt::black, 1)); p.drawLine(x, m_yBase+over, x, m_yBase+8); } else { //draw the thin month marks p.setPen(QPen(Qt::black, 1)); p.drawLine(x, m_yBase+over, x, m_yBase+8); } drawBeam(&p, m_lstDates.count(y,m, -1, true) * 100 / m_lstDates.maxMonth(), y, m); } } //draw the final year bar thats missing from the loop x += m_widthMonth; p.setPen(QPen(Qt::gray, 3)); p.drawLine(x, m_yBase+over, x, m_yBase+22); p.setPen(QPen(Qt::black, 1)); p.drawLine(x, m_yBase+over, x, m_yBase+22); //now draw the base line p.setPen(QPen(Qt::black, 1)); p.drawLine(10, m_yBase, width - 10 , m_yBase); //done p.end(); }
void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags, QPainter * destPainter, const QRect & limits, int width, int height ) { QPixmap * pixmap = 0; // if a pixmap is present for given id, use it if ( page->m_pixmaps.contains( id ) ) pixmap = page->m_pixmaps[ id ]; // else find the closest match using pixmaps of other IDs (great optim!) else if ( !page->m_pixmaps.isEmpty() && width != -1 ) { int minDistance = -1; QMap< int,QPixmap * >::const_iterator it = page->m_pixmaps.begin(), end = page->m_pixmaps.end(); for ( ; it != end; ++it ) { int pixWidth = (*it)->width(), distance = pixWidth > width ? pixWidth - width : width - pixWidth; if ( minDistance == -1 || distance < minDistance ) { pixmap = *it; minDistance = distance; } } } // if have no pixmap, draw blank page with gray cross and exit if ( !pixmap ) { QColor color = Qt::white; if ( KpdfSettings::changeColors() ) { switch ( KpdfSettings::renderMode() ) { case KpdfSettings::EnumRenderMode::Inverted: color = Qt::black; break; case KpdfSettings::EnumRenderMode::Paper: color = KpdfSettings::paperColor(); break; case KpdfSettings::EnumRenderMode::Recolor: color = KpdfSettings::recolorBackground(); break; default: ; } } destPainter->fillRect( limits, color ); // draw a cross (to that the pixmap as not yet been loaded) // helps a lot on pages that take much to render destPainter->setPen( Qt::gray ); destPainter->drawLine( 0, 0, width-1, height-1 ); destPainter->drawLine( 0, height-1, width-1, 0 ); // idea here: draw a hourglass (or kpdf icon :-) on top-left corner return; } // find out what to paint over the pixmap (manipulations / overlays) bool paintAccessibility = (flags & Accessibility) && KpdfSettings::changeColors() && (KpdfSettings::renderMode() != KpdfSettings::EnumRenderMode::Paper); bool paintHighlights = (flags & Highlights) && !page->m_highlights.isEmpty(); bool enhanceLinks = (flags & EnhanceLinks) && KpdfSettings::highlightLinks(); bool enhanceImages = (flags & EnhanceImages) && KpdfSettings::highlightImages(); // check if there are really some highlightRects to paint if ( paintHighlights ) { // precalc normalized 'limits rect' for intersection double nXMin = (double)limits.left() / (double)width, nXMax = (double)limits.right() / (double)width, nYMin = (double)limits.top() / (double)height, nYMax = (double)limits.bottom() / (double)height; // if no rect intersects limits, disable paintHighlights paintHighlights = false; QValueList< HighlightRect * >::const_iterator hIt = page->m_highlights.begin(), hEnd = page->m_highlights.end(); for ( ; hIt != hEnd; ++hIt ) { if ( (*hIt)->intersects( nXMin, nYMin, nXMax, nYMax ) ) { paintHighlights = true; break; } } } // use backBuffer if 'pixmap direct manipulation' is needed bool backBuffer = paintAccessibility || paintHighlights; QPixmap * backPixmap = 0; QPainter * p = destPainter; if ( backBuffer ) { // let's paint using a buffered painter backPixmap = new QPixmap( limits.width(), limits.height() ); p = new QPainter( backPixmap ); p->translate( -limits.left(), -limits.top() ); } // 1. fast blit the pixmap if it has the right size.. if ( pixmap->width() == width && pixmap->height() == height ) p->drawPixmap( limits.topLeft(), *pixmap, limits ); // ..else set a scale matrix to the painter and paint a quick 'zoomed' pixmap else { p->save(); // TODO paint only the needed part (note: hope that Qt4 transforms are faster) p->scale( width / (double)pixmap->width(), height / (double)pixmap->height() ); p->drawPixmap( 0,0, *pixmap, 0,0, pixmap->width(), pixmap->height() ); p->restore(); } // 2. mangle pixmap: convert it to 32-bit qimage and perform pixel-level manipulations if ( backBuffer ) { QImage backImage = backPixmap->convertToImage(); // 2.1. modify pixmap following accessibility settings if ( paintAccessibility ) { switch ( KpdfSettings::renderMode() ) { case KpdfSettings::EnumRenderMode::Inverted: // Invert image pixels using QImage internal function backImage.invertPixels(false); break; case KpdfSettings::EnumRenderMode::Recolor: // Recolor image using KImageEffect::flatten with dither:0 KImageEffect::flatten( backImage, KpdfSettings::recolorForeground(), KpdfSettings::recolorBackground() ); break; case KpdfSettings::EnumRenderMode::BlackWhite: // Manual Gray and Contrast unsigned int * data = (unsigned int *)backImage.bits(); int val, pixels = backImage.width() * backImage.height(), con = KpdfSettings::bWContrast(), thr = 255 - KpdfSettings::bWThreshold(); for( int i = 0; i < pixels; ++i ) { val = qGray( data[i] ); if ( val > thr ) val = 128 + (127 * (val - thr)) / (255 - thr); else if ( val < thr ) val = (128 * val) / thr; if ( con > 2 ) { val = con * ( val - thr ) / 2 + thr; if ( val > 255 ) val = 255; else if ( val < 0 ) val = 0; } data[i] = qRgba( val, val, val, 255 ); } break; } } // 2.2. highlight rects in page if ( paintHighlights ) { // draw highlights that are inside the 'limits' paint region QValueList< HighlightRect * >::const_iterator hIt = page->m_highlights.begin(), hEnd = page->m_highlights.end(); for ( ; hIt != hEnd; ++hIt ) { HighlightRect * r = *hIt; QRect highlightRect = r->geometry( width, height ); if ( highlightRect.isValid() && highlightRect.intersects( limits ) ) { // find out the rect to highlight on pixmap highlightRect = highlightRect.intersect( limits ); highlightRect.moveBy( -limits.left(), -limits.top() ); // highlight composition (product: highlight color * destcolor) unsigned int * data = (unsigned int *)backImage.bits(); int val, newR, newG, newB, rh = r->color.red(), gh = r->color.green(), bh = r->color.blue(), offset = highlightRect.top() * backImage.width(); for( int y = highlightRect.top(); y <= highlightRect.bottom(); ++y ) { for( int x = highlightRect.left(); x <= highlightRect.right(); ++x ) { val = data[ x + offset ]; newR = (qRed(val) * rh) / 255; newG = (qGreen(val) * gh) / 255; newB = (qBlue(val) * bh) / 255; data[ x + offset ] = qRgba( newR, newG, newB, 255 ); } offset += backImage.width(); } } } } backPixmap->convertFromImage( backImage ); } // 3. visually enchance links and images if requested if ( enhanceLinks || enhanceImages ) { QColor normalColor = QApplication::palette().active().highlight(); QColor lightColor = normalColor.light( 140 ); // enlarging limits for intersection is like growing the 'rectGeometry' below QRect limitsEnlarged = limits; limitsEnlarged.addCoords( -2, -2, 2, 2 ); // draw rects that are inside the 'limits' paint region as opaque rects QValueList< ObjectRect * >::const_iterator lIt = page->m_rects.begin(), lEnd = page->m_rects.end(); for ( ; lIt != lEnd; ++lIt ) { ObjectRect * rect = *lIt; if ( (enhanceLinks && rect->objectType() == ObjectRect::Link) || (enhanceImages && rect->objectType() == ObjectRect::Image) ) { QRect rectGeometry = rect->geometry( width, height ); if ( rectGeometry.intersects( limitsEnlarged ) ) { // expand rect and draw inner border rectGeometry.addCoords( -1,-1,1,1 ); p->setPen( lightColor ); p->drawRect( rectGeometry ); // expand rect to draw outer border rectGeometry.addCoords( -1,-1,1,1 ); p->setPen( normalColor ); p->drawRect( rectGeometry ); } } } } // 4. if was backbuffering, copy the backPixmap to destination if ( backBuffer ) { delete p; destPainter->drawPixmap( limits.left(), limits.top(), *backPixmap ); delete backPixmap; } }
void PlayField::mouseMoveEvent(QMouseEvent *e) { lastMouseXPos_ = e->x(); lastMouseYPos_ = e->y(); if (!dragInProgress_) return highlight(); int old_x = dragX_, old_y = dragY_; dragX_ = lastMouseXPos_ - mousePosX_; dragY_ = lastMouseYPos_ - mousePosY_; { int x = pixel2x(dragX_ + size_/2); int y = pixel2y(dragY_ + size_/2); if (x >= 0 && x < levelMap_->width() && y >= 0 && y < levelMap_->height() && pathFinder_.canDragTo(x, y)) { x = x2pixel(x); y = y2pixel(y); if (dragX_ >= x - size_/4 && dragX_ < x + size_/4 && dragY_ >= y - size_/4 && dragY_ < y + size_/4) { dragX_ = x; dragY_ = y; } } } if (dragX_ == old_x && dragY_ == old_y) return; QRect rect(dragX_, dragY_, size_, size_); dragXpm_= QPixmap(size_, size_); QPainter paint; paint.begin(&dragXpm_); paint.setBackground(palette().color(backgroundRole())); paint.setBrushOrigin(- dragX_, - dragY_); paint.translate((double) (- dragX_), (double) (- dragY_)); paintPainter(paint, rect); paint.end(); dragImage_ = dragXpm_.toImage(); for (int yy=0; yy<size_; yy++) { for (int xx=0; xx<size_; xx++) { QRgb rgb1 = imageData_->objectImg().pixel(xx, yy); int r1 = qRed(rgb1); int g1 = qGreen(rgb1); int b1 = qBlue(rgb1); if (r1 != g1 || r1 != b1 || r1 == 255) { QRgb rgb2 = dragImage_.pixel(xx, yy); int r2 = qRed(rgb2); int g2 = qGreen(rgb2); int b2 = qBlue(rgb2); r2 = (int) (0.75 * r1 + 0.25 * r2 + 0.5); g2 = (int) (0.75 * g1 + 0.25 * g2 + 0.5); b2 = (int) (0.75 * b1 + 0.25 * b2 + 0.5); dragImage_.setPixel(xx, yy, qRgb(r2, g2, b2)); } } } paint.begin(this); // the following line is a workaround for a bug in Qt 2.0.1 // (and possibly earlier versions) paint.setBrushOrigin(0, 0); dragXpm_ = QPixmap::fromImage(dragImage_, Qt::OrderedDither|Qt::OrderedAlphaDither| Qt::ColorOnly|Qt::AvoidDither); paint.drawPixmap(dragX_, dragY_, dragXpm_); { int dx = dragX_ - old_x; int dy = dragY_ - old_y; int y2 = old_y; if (dy > 0) { paintPainterClip(paint, old_x, old_y, size_, dy); // NOTE: clipping is now activated in the QPainter paint y2 += dy; } else if (dy < 0) { paintPainterClip(paint, old_x, old_y+size_+dy, size_, -dy); // NOTE: clipping is now activated in the QPainter paint dy = -dy; } if (dx > 0) { paintPainterClip(paint, old_x, y2, dx, size_-dy); // NOTE: clipping is now activated in the QPainter paint } else if (dx < 0) { paintPainterClip(paint, old_x+size_+dx, y2, -dx, size_-dy); // NOTE: clipping is now activated in the QPainter paint } } paint.end(); }