void FreeRegionGrabber::grabRect() { QPolygon pol = selection; if ( !pol.isEmpty() ) { grabbing = true; int xOffset = pixmap.rect().x() - pol.boundingRect().x(); int yOffset = pixmap.rect().y() - pol.boundingRect().y(); QPolygon translatedPol = pol.translated(xOffset, yOffset); QPixmap pixmap2(pol.boundingRect().size()); pixmap2.fill(Qt::transparent); QPainter pt; pt.begin(&pixmap2); if (pt.paintEngine()->hasFeature(QPaintEngine::PorterDuff)) { pt.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform, true); pt.setBrush(Qt::black); pt.setPen(QPen(QBrush(Qt::black), 0.5)); pt.drawPolygon(translatedPol); pt.setCompositionMode(QPainter::CompositionMode_SourceIn); } else { pt.setClipRegion(QRegion(translatedPol)); pt.setCompositionMode(QPainter::CompositionMode_Source); } pt.drawPixmap(pixmap2.rect(), pixmap, pol.boundingRect()); pt.end(); emit freeRegionUpdated(pol); emit freeRegionGrabbed(pixmap2); } }
bool FX::blend(const QPixmap &upper, QPixmap &lower, double opacity, int x, int y) { if (opacity == 0.0) return false; // haha... { QPixmap tmp; if ( useRaster ) // raster engine is broken... :-( { tmp = QPixmap(upper.size()); tmp.fill(Qt::transparent); QPainter p(&tmp); p.drawPixmap(0,0, upper); p.end(); } else tmp = upper; QPainter p; if (opacity < 1.0) { p.begin(&tmp); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.fillRect(tmp.rect(), QColor(0,0,0, opacity*255.0)); p.end(); } p.begin(&lower); p.setCompositionMode(QPainter::CompositionMode_SourceOver); p.drawPixmap(x, y, tmp); p.end(); } return true; }
void KWD::Switcher::redrawPixmap () { QPainter p (&mPixmap); QPainter bp (&mBackgroundPixmap); const int contentWidth = mPixmap.width (); const int contentHeight = mPixmap.height (); mPixmap.fill (Qt::transparent); p.setCompositionMode (QPainter::CompositionMode_Source); p.setRenderHint (QPainter::SmoothPixmapTransform); mBackground->resizeFrame (QSizeF (contentWidth, contentHeight)); mBackground->paintFrame (&p, QRect (0, 0, contentWidth, contentHeight)); bp.setCompositionMode (QPainter::CompositionMode_Source); bp.drawPixmap (0, 0, mPixmap, mBorder.left, mBorder.top, mGeometry.width (), mGeometry.height ()); XSetWindowBackgroundPixmap (QX11Info::display (), mId, mX11BackgroundPixmap); XClearWindow (QX11Info::display (), mId); }
void CompositionRenderer::drawBase(QPainter &p) { p.setPen(Qt::NoPen); QLinearGradient rect_gradient(0, 0, 0, height()); rect_gradient.setColorAt(0, Qt::red); rect_gradient.setColorAt(.17, Qt::yellow); rect_gradient.setColorAt(.33, Qt::green); rect_gradient.setColorAt(.50, Qt::cyan); rect_gradient.setColorAt(.66, Qt::blue); rect_gradient.setColorAt(.81, Qt::magenta); rect_gradient.setColorAt(1, Qt::red); p.setBrush(rect_gradient); p.drawRect(width() / 2, 0, width() / 2, height()); QLinearGradient alpha_gradient(0, 0, width(), 0); alpha_gradient.setColorAt(0, Qt::white); alpha_gradient.setColorAt(0.2, Qt::white); alpha_gradient.setColorAt(0.5, Qt::transparent); alpha_gradient.setColorAt(0.8, Qt::white); alpha_gradient.setColorAt(1, Qt::white); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.setBrush(alpha_gradient); p.drawRect(0, 0, width(), height()); p.setCompositionMode(QPainter::CompositionMode_DestinationOver); p.setPen(Qt::NoPen); p.setRenderHint(QPainter::SmoothPixmapTransform); p.drawImage(rect(), m_image); }
void TouchUI::draw( QPainter & painter ) { _screen_width = painter.window().width(); _screen_height = painter.window().height(); limitScroll(); // draw background QRect rect(0,0,painter.window().width(),_height); painter.drawTiledPixmap( rect, _background ); // draw icons for ( int i = 0; i < _items.count(); i++ ) { UIItem * t = _items[i]; int posx = t->x1; int posy = t->y1; if ( posx < 0 ) posx = _screen_width+posx; QSvgRenderer * image = t->image; if ( t->highlighted ) painter.setCompositionMode( QPainter::CompositionMode_HardLight ); else painter.setCompositionMode( QPainter::CompositionMode_SourceOver ); if ( image == NULL ) continue; int h = image->defaultSize().height(); int w = image->defaultSize().width(); int img_width = g_config.ui_size; int img_height = g_config.ui_size; ImageLoadThread::fitImage( w,h, img_width, img_height, false ); QRectF r( posx+_xoffset, posy+_yoffset, w, h ); image->render( &painter, r ); } }
QIcon generateIcon(const char* iconPath) { QIcon icon; QString normalPath(iconPath); auto tokens = normalPath.split('.'); TF_ASSERT(tokens.length() == 2); QString off(tokens[0]); QString on(tokens[0] + stateOn); QString ext("." + tokens[1]); QString disabledPath(off + modeDisabled + ext); QString activePath(off + modeActive + ext); QString selectedPath(off + modeSelected + ext); QString normalOnPath(on + ext); QString disabledOnPath(on + modeDisabled + ext); QString activeOnPath(on + modeActive + ext); QString selectedOnPath(on + modeSelected + ext); auto offIcon = QPixmap(normalPath); icon.addPixmap(offIcon, QIcon::Normal, QIcon::Off); icon.addPixmap(QPixmap(disabledPath), QIcon::Disabled, QIcon::Off); icon.addPixmap(QPixmap(activePath), QIcon::Active, QIcon::Off); icon.addPixmap(QPixmap(selectedPath), QIcon::Selected, QIcon::Off); auto onIcon = QPixmap(normalOnPath); if (onIcon.isNull()) { QPainter p; auto img = offIcon.toImage().convertToFormat(QImage::Format_ARGB32); auto mask(img); auto width = mask.width(); auto height = mask.height(); auto outerRect = mask.rect(); auto innerRect = QRect(width / 16, height / 16, width - width / 8, height - height / 8); p.begin(&mask); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(outerRect, QApplication::palette().highlight()); p.fillRect(innerRect, Qt::transparent); p.end(); p.begin(&img); p.setCompositionMode(QPainter::CompositionMode_SourceOver); p.drawImage(0, 0, mask); p.end(); onIcon.convertFromImage(img); } icon.addPixmap(onIcon, QIcon::Normal, QIcon::On); icon.addPixmap(QPixmap(disabledOnPath), QIcon::Disabled, QIcon::On); icon.addPixmap(QPixmap(activeOnPath), QIcon::Active, QIcon::On); icon.addPixmap(QPixmap(selectedOnPath), QIcon::Selected, QIcon::On); return icon; }
void QSGPainterNode::paint() { QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect; QPainter painter; if (m_actualRenderTarget == QQuickPaintedItem::Image) { if (m_image.isNull()) return; painter.begin(&m_image); } else { if (!m_gl_device) { m_gl_device = new QOpenGLPaintDevice(m_fboSize); m_gl_device->setPaintFlipped(true); } if (m_multisampledFbo) m_multisampledFbo->bind(); else m_fbo->bind(); painter.begin(m_gl_device); } if (m_smoothPainting) { painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); } painter.scale(m_contentsScale, m_contentsScale); QRect sclip(qFloor(dirtyRect.x()/m_contentsScale), qFloor(dirtyRect.y()/m_contentsScale), qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)), qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale))); if (!m_dirtyRect.isNull()) painter.setClipRect(sclip); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(sclip, m_fillColor); painter.setCompositionMode(QPainter::CompositionMode_SourceOver); m_item->paint(&painter); painter.end(); if (m_actualRenderTarget == QQuickPaintedItem::Image) { m_texture->setImage(m_image); m_texture->setDirtyRect(dirtyRect); } else if (m_multisampledFbo) { QOpenGLFramebufferObject::blitFramebuffer(m_fbo, dirtyRect, m_multisampledFbo, dirtyRect); } if (m_multisampledFbo) m_multisampledFbo->release(); else if (m_fbo) m_fbo->release(); m_dirtyRect = QRect(); }
void drawCompositedPopup( QWidget* widget, const QPainterPath& outline, const QColor& lineColor, const QBrush& backgroundBrush, qreal opacity ) { bool compositingWorks = true; #if defined(Q_WS_WIN) //HACK: Windows refuses to perform compositing so we must fake it compositingWorks = false; #elif defined(Q_WS_X11) if ( !QX11Info::isCompositingManagerRunning() ) compositingWorks = false; #endif QPainter p; QImage result; if ( compositingWorks ) { p.begin( widget ); p.setRenderHint( QPainter::Antialiasing ); p.setBackgroundMode( Qt::TransparentMode ); } else { result = QImage( widget->rect().size(), QImage::Format_ARGB32_Premultiplied ); p.begin( &result ); p.setCompositionMode( QPainter::CompositionMode_Source ); p.fillRect( result.rect(), Qt::transparent ); p.setCompositionMode( QPainter::CompositionMode_SourceOver ); } QPen pen( lineColor ); pen.setWidth( 2 ); p.setPen( pen ); p.drawPath( outline ); p.setOpacity( opacity ); p.fillPath( outline, backgroundBrush ); p.end(); if ( !compositingWorks ) { QPainter finalPainter( widget ); finalPainter.setRenderHint( QPainter::Antialiasing ); finalPainter.setBackgroundMode( Qt::TransparentMode ); finalPainter.drawImage( 0, 0, result ); widget->setMask( QPixmap::fromImage( result ).mask() ); } #ifdef QT_MAC_USE_COCOA // Work around bug in Qt/Mac Cocoa where opening subsequent popups // would incorrectly calculate the background due to it not being // invalidated. SourceTreePopupHelper::clearBackground( widget ); #endif }
// QtPluginIconPalletTool Interface void dmz::QtPluginIconPalletTool::_add_type (const ObjectType &Type) { const String IconResource = config_to_string ( get_plugin_name () + ".resource", Type.get_config()); const String IconName = _rc.find_file (IconResource); if (IconName) { const String Name = Type.get_name (); if (Name) { QImage back ( (int)_iconExtent, (int)_iconExtent, QImage::Format_ARGB32_Premultiplied); QPainter painter (&back); painter.setCompositionMode (QPainter::CompositionMode_Source); painter.fillRect (back.rect (), Qt::transparent); painter.setCompositionMode (QPainter::CompositionMode_SourceOver); QSvgRenderer qsr (QString (IconName.get_buffer ())); QRectF size = qsr.viewBoxF (); qreal width = size.width (); qreal height = size.height (); qreal scale = (width > height) ? width : height; if (scale <= 0.0f) { scale = 1.0f; } scale = _iconExtent / scale; width *= scale; height *= scale; size.setWidth (width); size.setHeight (height); if (height < _iconExtent) { size.moveTop ((_iconExtent - height) * 0.5f); } if (width < _iconExtent) { size.moveLeft ((_iconExtent - width) * 0.5f); } qsr.render (&painter, size); painter.end (); QIcon icon; icon.addPixmap (QPixmap::fromImage (back)); QStandardItem *item = new QStandardItem (icon, Name.get_buffer ()); item->setEditable (false); _model.appendRow (item); } } else if (IconResource) { _log.error << "Unable to find icon resource: " << IconResource << " for object type: " << Type.get_name () << endl; } RuntimeIterator it; ObjectType next; while (Type.get_next_child (it, next)) { _add_type (next); } }
void PictureZoneEditor::paintOverPictureMask(QPainter& painter) { painter.setRenderHint(QPainter::Antialiasing); painter.setTransform(imageToVirtual() * virtualToWidget(), true); painter.setPen(Qt::NoPen); painter.setBrush(QColor(mask_color)); #ifndef Q_WS_X11 // That's how it's supposed to be. painter.setCompositionMode(QPainter::CompositionMode_Clear); #else // QPainter::CompositionMode_Clear doesn't work for arbitrarily shaped // objects on X11, as well as CompositionMode_Source with a transparent // brush. Fortunately, CompositionMode_DestinationOut with a non-transparent // brush does actually work. painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); #endif typedef PictureLayerProperty PLP; // First pass: ERASER1 BOOST_FOREACH(EditableZoneSet::Zone const& zone, m_zones) { if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER1) { painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill); } } painter.setCompositionMode(QPainter::CompositionMode_SourceOver); // Second pass: PAINTER2 BOOST_FOREACH (EditableZoneSet::Zone const& zone, m_zones) { if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::PAINTER2) { painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill); } } #ifndef Q_WS_X11 // That's how it's supposed to be. painter.setCompositionMode(QPainter::CompositionMode_Clear); #else // QPainter::CompositionMode_Clear doesn't work for arbitrarily shaped // objects on X11, as well as CompositionMode_Source with a transparent // brush. Fortunately, CompositionMode_DestinationOut with a non-transparent // brush does actually work. painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); #endif // Third pass: ERASER1 BOOST_FOREACH (EditableZoneSet::Zone const& zone, m_zones) { if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER3) { painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill); } } }
void GraphicsContext::clearRect(const FloatRect& rect) { if (paintingDisabled()) return; QPainter *p = m_data->p(); QPainter::CompositionMode currentCompositionMode = p->compositionMode(); p->setCompositionMode(QPainter::CompositionMode_Source); p->eraseRect(rect); p->setCompositionMode(currentCompositionMode); }
void PHISurfaceEffect::draw( QPainter *painter ) { /* QPoint offset; QPixmap pixmap; if ( sourceIsPixmap() ) { // No point in drawing in device coordinates (pixmap will be scaled anyways). pixmap=sourcePixmap( Qt::LogicalCoordinates, &offset ); } else { // Draw pixmap in device coordinates to avoid pixmap scaling; pixmap=sourcePixmap( Qt::DeviceCoordinates, &offset ); painter->setWorldTransform( QTransform() ); } QImage img=pixmap.toImage(); img=PHI::getSurfacedImage( img, _yOff, _size ); painter->drawImage( offset, img ); */ QRectF brect=sourceBoundingRect( Qt::LogicalCoordinates ); QImage img( static_cast<int>(brect.width()+1), static_cast<int>(brect.height()+_size+_yOff), QImage::Format_ARGB32_Premultiplied ); QPainter pixPainter; pixPainter.begin( &img ); pixPainter.setRenderHints( painter->renderHints() ); pixPainter.setCompositionMode( QPainter::CompositionMode_Clear ); pixPainter.fillRect( 0., 0., brect.width()+1., brect.height()+_size+_yOff+1, Qt::transparent ); pixPainter.setCompositionMode( QPainter::CompositionMode_SourceOver ); drawSource( &pixPainter ); QTransform t; t.rotate( 180., Qt::XAxis ); t.translate( 0., (-brect.height()*2.)-_yOff+1. ); pixPainter.setTransform( t ); drawSource( &pixPainter ); pixPainter.resetTransform(); pixPainter.translate( 0., brect.height()+_yOff ); QLinearGradient gradient( 0., 0., 0., 1.0 ); gradient.setColorAt( 0., QColor( 0, 0, 0, 220 ) ); gradient.setColorAt( 0.78, QColor( 0, 0, 0, 30 ) ); gradient.setColorAt( 1., Qt::transparent ); gradient.setCoordinateMode( QGradient::ObjectBoundingMode ); pixPainter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); pixPainter.fillRect( 0., 0., brect.width()+1, _size, gradient ); pixPainter.end(); painter->drawImage( 0, 0, img ); }
/** * @brief ImageDialog::ImageDialog * @param parent */ ImageDialog::ImageDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ImageDialog) { ui->setupUi(this); #ifdef Q_WS_MAC setWindowFlags((windowFlags() & ~Qt::WindowType_Mask) | Qt::Sheet); setStyleSheet(styleSheet() + " #ImageDialog { border: 1px solid rgba(0, 0, 0, 100); border-top: none; }"); #else setWindowFlags((windowFlags() & ~Qt::WindowType_Mask) | Qt::Dialog); #endif QSettings settings; resize(settings.value("ImageDialog/Size").toSize()); connect(ui->table, SIGNAL(cellClicked(int,int)), this, SLOT(imageClicked(int, int))); connect(ui->table, SIGNAL(sigDroppedImage(QUrl)), this, SLOT(onImageDropped(QUrl))); connect(ui->buttonClose, SIGNAL(clicked()), this, SLOT(reject())); connect(ui->buttonChoose, SIGNAL(clicked()), this, SLOT(chooseLocalImage())); connect(ui->previewSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(onPreviewSizeChange(int))); connect(ui->buttonZoomIn, SIGNAL(clicked()), this, SLOT(onZoomIn())); connect(ui->buttonZoomOut, SIGNAL(clicked()), this, SLOT(onZoomOut())); QMovie *movie = new QMovie(":/img/spinner.gif"); movie->start(); ui->labelSpinner->setMovie(movie); clear(); setImageType(TypePoster); m_currentDownloadReply = 0; QPixmap zoomOut(":/img/zoom_out.png"); QPixmap zoomIn(":/img/zoom_in.png"); QPainter p; p.begin(&zoomOut); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(zoomOut.rect(), QColor(0, 0, 0, 150)); p.end(); p.begin(&zoomIn); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(zoomIn.rect(), QColor(0, 0, 0, 150)); p.end(); ui->buttonZoomOut->setIcon(QIcon(zoomOut)); ui->buttonZoomIn->setIcon(QIcon(zoomIn)); m_noElementsLabel = new QLabel(tr("No images found"), ui->table); m_noElementsLabel->setMargin(10); m_noElementsLabel->hide(); }
To92::To92() { this->setFlag(QGraphicsItem::ItemIsMovable,true); int size = 3; int width = size*20; int height = 2*20; QPixmap resistorPixmap(width,height); resistorPixmap.fill(Qt::transparent); QPainter painter; painter.begin(&resistorPixmap); painter.setCompositionMode(QPainter::CompositionMode_Source); // lets draw the body // painter.drawRect(16,0,width-32,height,5,5); QRectF rect(8,0,width-16,height-1); painter.setBrush(Qt::gray); painter.setPen(Qt::black); painter.drawChord(rect,0*16,180*16); // lets draw the legs painter.drawRect(10,8,10,5);//,Qt::lightGray); painter.drawRect(width/2-2,8,5,5);//,Qt::lightGray); painter.drawRect(width-20,8,10,5);//,Qt::lightGray); painter.setPen(Qt::black); painter.drawText(10,10,10,10,0,"3"); painter.drawText(25,10,10,10,0,"2"); painter.drawText(40,10,10,10,0,"1"); this->setPixmap(resistorPixmap); }
void KWD::Switcher::update () { QFontMetrics fm = Plasma::Theme::defaultTheme ()->fontMetrics (); QFont font (Plasma::Theme::defaultTheme ()-> font (Plasma::Theme::DefaultFont)); QString name; QPainter p (&mPixmap); KWD::readWindowProperty (mId, Atoms::switchSelectWindow, (long *)&mSelected); name = KWindowSystem::windowInfo (mSelected, NET::WMVisibleName, 0).visibleName (); while (fm.width (name) > mGeometry.width ()) { name.truncate (name.length () - 6); name += "..."; } p.setCompositionMode (QPainter::CompositionMode_Source); mBackground->paintFrame (&p, QRect (mBorder.left, mBorder.top + mGeometry.height () + 5, mGeometry.width (), fm.height ())); p.setFont (font); p.setPen (Plasma::Theme::defaultTheme ()->color(Plasma::Theme::TextColor)); p.drawText ((mPixmap.width () - fm.width (name)) / 2, mBorder.top + mGeometry.height () + 5 + fm.ascent (), name); }
void Render::atualizaScreen(void) { QPainter p; if(screen != NULL) delete screen; screen = new QImage(screenW, screenH, QImage::Format_ARGB32_Premultiplied); p.begin(screen); p.setCompositionMode(QPainter::CompositionMode_Source); p.drawImage(0,0, buffer->copy(ponto->x(),ponto->y(),screenW, screenH)); p.setCompositionMode(QPainter::CompositionMode_SourceOver); p.drawImage(0,0, frontBuffer->copy(ponto->x(),ponto->y(),screenW, screenH)); p.end(); emit renderizado(*screen); }
void Render::reiniciaBuffers(int w, int h) { if(buffer != NULL) delete buffer; if(backBuffer != NULL) delete backBuffer; if(frontBuffer != NULL) delete frontBuffer; buffer = new QImage(w, h, QImage::Format_ARGB32_Premultiplied); backBuffer = new QImage(w, h, QImage::Format_ARGB32_Premultiplied); frontBuffer = new QImage(w, h, QImage::Format_ARGB32_Premultiplied); QPainter p; p.begin(buffer); p.fillRect(buffer->rect(), Qt::white); p.end(); p.begin(backBuffer); p.fillRect(backBuffer->rect(),Qt::white); p.end(); p.begin(frontBuffer); p.setCompositionMode(QPainter::CompositionMode_Source); p.fillRect(frontBuffer->rect(), Qt::transparent); p.end(); renderiza(); renderizaFront(); }
void PDIP::SetPDIPSize(int pdip_size) { this->pdip_size = pdip_size; int legsPerSide = (pdip_size/2); int height = legsPerSide*20; int width = 20*4; QPixmap pdipPixmap(width,height); pdipPixmap.fill(Qt::transparent); QPainter painter; painter.begin(&pdipPixmap); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.setBrush(Qt::gray); painter.setPen(Qt::black); // lets draw the body painter.drawRect(15,0,width-30,height);//,Qt::gray); // lets draw the arc marking for #1 pin QRectF pinOne(0,0,20,20); painter.drawEllipse(30,-10,20,20); // lets draw the legs for (int idx=0; idx<legsPerSide; idx++) { painter.drawRect(10,8+20*idx,5,5);//,Qt::lightGray); painter.drawRect(width-15,8+20*idx,5,5);//,Qt::lightGray); // lets draw the numbers for the pins int id = idx+1; painter.drawText(15,20*idx,20,20,0,QString("%0").arg(legsPerSide+(legsPerSide-(id-1)))); painter.drawText(width-30,20*idx,20,20,0,QString("%0").arg(id)); } painter.end(); this->setPixmap(pdipPixmap); }
ClosableImage::ClosableImage(QWidget *parent) : QLabel(parent) { setMouseTracking(true); m_showZoomAndResolution = true; m_scaleTo = Qt::Horizontal; m_fixedSize = 180; m_fixedHeight = 0; m_clickable = false; m_loading = false; m_font = QApplication::font(); #ifdef Q_OS_WIN32 m_font.setPointSize(m_font.pointSize()-1); #else m_font.setPointSize(m_font.pointSize()-2); #endif m_font.setFamily("Helvetica Neue"); m_loadingMovie = new QMovie(":/img/spinner.gif"); m_loadingMovie->start(); m_zoomIn = QPixmap(":/img/zoom_in.png"); Helper::instance()->setDevicePixelRatio(m_zoomIn, Helper::instance()->devicePixelRatio(this)); QPainter p; p.begin(&m_zoomIn); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(m_zoomIn.rect(), QColor(0, 0, 0, 150)); p.end(); m_zoomIn = m_zoomIn.scaledToWidth(16 * Helper::instance()->devicePixelRatio(this), Qt::SmoothTransformation); setAcceptDrops(true); }
void KviThemedLineEdit::paintEvent(QPaintEvent * event) { #ifdef COMPILE_PSEUDO_TRANSPARENCY QPainter * p = new QPainter(this); QPalette pal = palette(); // In Qt5 QStyle::drawPrimitive seems to always overwrite the background, no matter what. qDrawShadePanel(p, 0, 0, width(), height(), palette(), true, 1, nullptr); QRect r(1, 1, width() - 2, height() - 2); if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) { p->setCompositionMode(QPainter::CompositionMode_Source); QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade); col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100)); p->fillRect(r, col); p->restore(); } else if(g_pShadedChildGlobalDesktopBackground) { QPoint pnt; if(m_pKviWindow) pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, r.topLeft()) : mapTo(m_pKviWindow, r.topLeft()); else pnt = mapToGlobal(event->rect().topLeft()); p->drawTiledPixmap(r, *(g_pShadedChildGlobalDesktopBackground), pnt); } delete p; #endif QLineEdit::paintEvent(event); }
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) { QPixmap* framePixmap = nativeImageForCurrentFrame(); if (!framePixmap) // If it's too early we won't have an image yet. return; QPixmap pixmap = *framePixmap; QRect tr = QRectF(tileRect).toRect(); if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) pixmap = pixmap.copy(tr); QBrush b(pixmap); b.setTransform(patternTransform); ctxt->save(); ctxt->setCompositeOperation(op); QPainter* p = ctxt->platformContext(); if (!pixmap.hasAlpha() && p->compositionMode() == QPainter::CompositionMode_SourceOver) p->setCompositionMode(QPainter::CompositionMode_Source); p->setBrushOrigin(phase); p->fillRect(destRect, b); ctxt->restore(); if (imageObserver()) imageObserver()->didDraw(this); }
// ******************************************************** ImageBufferData::ImageBufferData(const IntSize& size, bool accelerated) { QPainter* painter = new QPainter; m_painter = adoptPtr(painter); #if ENABLE(ACCELERATED_2D_CANVAS) if (accelerated) { m_impl = adoptPtr(new ImageBufferDataPrivateAccelerated(size)); } else #endif m_impl = adoptPtr(new ImageBufferDataPrivateUnaccelerated(size)); if (!m_impl->paintDevice()) return; if (!painter->begin(m_impl->paintDevice())) return; painter->setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing); QPen pen = painter->pen(); pen.setColor(Qt::black); pen.setWidth(1); pen.setCapStyle(Qt::FlatCap); pen.setJoinStyle(Qt::SvgMiterJoin); pen.setMiterLimit(10); painter->setPen(pen); QBrush brush = painter->brush(); brush.setColor(Qt::black); painter->setBrush(brush); painter->setCompositionMode(QPainter::CompositionMode_SourceOver); }
void KviThemedLabel::paintEvent(QPaintEvent *e) { #ifdef COMPILE_PSEUDO_TRANSPARENCY QPainter *p = new QPainter(this); #if (QT_VERSION >= 0x050000) // In Qt5 QStyle::drawPrimitive seems to always overwrite the background, no matter what. qDrawShadePanel(p,0,0,width(),height(),palette(),true,1,NULL); QRect r(1,1,width()-1,height()-1); #else QStyleOptionFrameV2 option; option.initFrom(this); style()->drawPrimitive(QStyle::PE_FrameLineEdit, &option, p, this); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); #endif if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) { p->setCompositionMode(QPainter::CompositionMode_Source); QColor col=KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade); col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100)); p->fillRect(r, col); } else if(g_pShadedChildGlobalDesktopBackground) { QPoint pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, r.topLeft()) : mapTo(m_pKviWindow, r.topLeft()); p->drawTiledPixmap(r,*(g_pShadedChildGlobalDesktopBackground), pnt); } delete p; #endif QLabel::paintEvent(e); }
/**************************************************************************** Create a new sprite by cropping and taking only the given portion of the image. source gives the sprite that is to be cropped. x,y, width, height gives the rectangle to be cropped. The pixel at position of the source sprite will be at (0,0) in the new sprite, and the new sprite will have dimensions (width, height). mask gives an additional mask to be used for clipping the new sprite. Only the transparency value of the mask is used in crop_sprite. The formula is: dest_trans = src_trans * mask_trans. Note that because the transparency is expressed as an integer it is common to divide it by 256 afterwards. mask_offset_x, mask_offset_y is the offset of the mask relative to the origin of the source image. The pixel at (mask_offset_x,mask_offset_y) in the mask image will be used to clip pixel (0,0) in the source image which is pixel (-x,-y) in the new image. ****************************************************************************/ struct sprite *qtg_crop_sprite(struct sprite *source, int x, int y, int width, int height, struct sprite *mask, int mask_offset_x, int mask_offset_y) { if (!width || !height) { return NULL; } sprite *cropped = new sprite; cropped->pm = new QPixmap(width, height); cropped->pm->fill(Qt::transparent); QRectF source_rect(x,y,width, height); QRectF dest_rect(0,0,width, height); QPainter p; p.begin(cropped->pm); p.drawPixmap(dest_rect, *source->pm,source_rect); p.end(); if(mask) { p.begin(cropped->pm); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.drawPixmap(mask_offset_x-x,mask_offset_y-y,*mask->pm); p.end(); } return cropped; }
//takes inflates from the master job, OR's with the pixmap and recompresses to the master job. void SliceSet::AddSliceToJob(Slice* rasSlice, CrushedPrintJob* job) { B9LayoutProjectData* projectData = pInstance->pData->pMain->ProjectData(); unsigned int xres = projectData->GetResolution().x(); unsigned int yres = projectData->GetResolution().y(); QPainter painter; QImage img(xres,yres,QImage::Format_ARGB32_Premultiplied); img.fill(Qt::black); SubtractVoidFromFill(rasSlice->pImg); //we only need to inflate overlaying slices if there are multiple models if(!singleModelCompression) { job->inflateSlice(rasSlice->layerIndx, &img); if(img.size() == QSize(0,0)) { img = QImage(xres,yres,QImage::Format_ARGB32_Premultiplied); img.fill(Qt::black); } //or images together painter.begin(rasSlice->pImg); painter.setRenderHint(QPainter::Antialiasing,false); painter.setCompositionMode(QPainter::CompositionMode_Plus); painter.drawImage(0,0,img); painter.end(); } job->crushSlice(rasSlice->layerIndx, rasSlice->pImg); rasSlice->inProccessing = false; }
void QQuickContext2DTexture::paintWithoutTiles(QQuickContext2DCommandBuffer *ccb) { if (!ccb || ccb->isEmpty()) return; QPaintDevice* device = beginPainting(); if (!device) { endPainting(); return; } QPainter p; p.begin(device); if (m_antialiasing) p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, true); else p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, false); if (m_smooth) p.setRenderHint(QPainter::SmoothPixmapTransform, true); else p.setRenderHint(QPainter::SmoothPixmapTransform, false); p.setCompositionMode(QPainter::CompositionMode_SourceOver); ccb->replay(&p, m_state, scaleFactor()); endPainting(); markDirtyTexture(); }
void ShowFpsEffect::paintQPainter(int fps) { QPainter *painter = effects->scenePainter(); painter->save(); QColor color(255, 255, 255); color.setAlphaF(alpha); painter->setCompositionMode(QPainter::CompositionMode_SourceOver); painter->fillRect(x, y, 2 * NUM_PAINTS + FPS_WIDTH, MAX_TIME, color); color.setRed(0); color.setGreen(0); painter->fillRect(x, y + MAX_TIME - fps, FPS_WIDTH, fps, color); color.setBlue(0); for (int i = 10; i < MAX_TIME; i += 10) { painter->setPen(color); painter->drawLine(x, y + MAX_TIME - i, x + FPS_WIDTH, y + MAX_TIME - i); } // Paint FPS graph paintFPSGraph(x + FPS_WIDTH, y + MAX_TIME - 1); // Paint amount of rendered pixels graph paintDrawSizeGraph(x + FPS_WIDTH + NUM_PAINTS, y + MAX_TIME - 1); // Paint FPS numerical value painter->setPen(Qt::black); painter->drawText(fpsTextRect, textAlign, QString::number(fps)); painter->restore(); }
void UrlDialogTreeWidget::paintEvent(QPaintEvent * event) { QPainter * p = new QPainter(viewport()); QStyleOptionViewItem option = viewOptions(); QRect rect = event->rect(); #ifdef COMPILE_PSEUDO_TRANSPARENCY if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) { p->save(); p->setCompositionMode(QPainter::CompositionMode_Source); QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade); col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100)); p->fillRect(rect, col); p->restore(); } else if(g_pShadedChildGlobalDesktopBackground) { QPoint pnt = ((KviWindow *)parent())->isDocked() ? viewport()->mapTo(g_pMainWindow, rect.topLeft()) : viewport()->mapTo((KviWindow *)parent(), rect.topLeft()); p->drawTiledPixmap(rect, *(g_pShadedChildGlobalDesktopBackground), pnt); } else { #endif //FIXME this is not the treewindowlist p->fillRect(rect, KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground)); #ifdef COMPILE_PSEUDO_TRANSPARENCY } #endif delete p; //call paint on all children QTreeWidget::paintEvent(event); }
void ImageBufferDataPrivateAccelerated::platformTransformColorSpace(const Vector<int>& lookUpTable) { QPainter* painter = paintDevice()->paintEngine()->painter(); QImage image = toQImage().convertToFormat(QImage::Format_ARGB32); ASSERT(!image.isNull()); uchar* bits = image.bits(); const int bytesPerLine = image.bytesPerLine(); for (int y = 0; y < image.height(); ++y) { quint32* scanLine = reinterpret_cast_ptr<quint32*>(bits + y * bytesPerLine); for (int x = 0; x < image.width(); ++x) { QRgb& pixel = scanLine[x]; pixel = qRgba(lookUpTable[qRed(pixel)], lookUpTable[qGreen(pixel)], lookUpTable[qBlue(pixel)], qAlpha(pixel)); } } painter->save(); painter->resetTransform(); painter->setOpacity(1.0); painter->setClipping(false); painter->setCompositionMode(QPainter::CompositionMode_Source); // Should coordinates be flipped? painter->drawImage(QPoint(0,0), image); painter->restore(); }
ImageBufferData::ImageBufferData(const IntSize& size) : m_pixmap(size) { if (m_pixmap.isNull()) return; m_pixmap.fill(QColor(Qt::transparent)); QPainter* painter = new QPainter; m_painter = adoptPtr(painter); if (!painter->begin(&m_pixmap)) return; // Since ImageBuffer is used mainly for Canvas, explicitly initialize // its painter's pen and brush with the corresponding canvas defaults // NOTE: keep in sync with CanvasRenderingContext2D::State QPen pen = painter->pen(); pen.setColor(Qt::black); pen.setWidth(1); pen.setCapStyle(Qt::FlatCap); pen.setJoinStyle(Qt::SvgMiterJoin); pen.setMiterLimit(10); painter->setPen(pen); QBrush brush = painter->brush(); brush.setColor(Qt::black); painter->setBrush(brush); painter->setCompositionMode(QPainter::CompositionMode_SourceOver); m_image = StillImage::createForRendering(&m_pixmap); }