本文整理汇总了C++中QPainter::setCompositionMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::setCompositionMode方法的具体用法?C++ QPainter::setCompositionMode怎么用?C++ QPainter::setCompositionMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::setCompositionMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: grabRect
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);
}
}
示例2: p
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;
}
示例3: p
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);
}
示例4: drawBase
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);
}
示例5: draw
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 );
}
}
示例6: generateIcon
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;
}
示例7: paint
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();
}
示例8: pen
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
}
示例9: back
// 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); }
}
示例10: virtualToWidget
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);
}
}
}
示例11: clearRect
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);
}
示例12: draw
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 );
}
示例13: zoomOut
/**
* @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();
}
示例14: resistorPixmap
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);
}
示例15: font
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);
}