本文整理汇总了C++中QPainterPath::addRegion方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::addRegion方法的具体用法?C++ QPainterPath::addRegion怎么用?C++ QPainterPath::addRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::addRegion方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateShapeCache
void TopologyNode::updateShapeCache()
{
QPainterPath shapePath;
QString imagePath;
#ifdef PLUGIN_TARGET
if(mNodeFlags & NF_ISCENTRALROUTER)
{
Q_ASSERT (m_paintStrategy);
imagePath = m_paintStrategy->getImageName();
}
else
#endif
{
#ifdef POWERLINE_REVISION
if(m_isPowerLine)
{
imagePath = GENIE2_RES("map/devices/PowerLineNormal.png");
}
else
#endif
{
imagePath = getDeviceTypeImagePath(m_deviceType,DTIR_NORMAL);
}
}
QPixmap pixDetecter(imagePath);
shapePath.addRegion(QRegion(pixDetecter.mask()));
shapePath.translate(-pixDetecter.width() / 2,-pixDetecter.height() / 2);
m_shapePath = shapePath;
}
示例2: shape
QPainterPath BubbleChatBox::shape() const
{
QRegion maskRegion(backgroundPixmap.mask().scaled(rect.size().toSize()));
QPainterPath path;
path.addRegion(maskRegion);
return path;
}
示例3: paintEvent
void GlPlottingCanvas::paintEvent(QPaintEvent *)
{
// QPainter painter(this);
// painter.setCompositionMode(QPainter::CompositionMode_Source);
// QPixmap& pix = PlottingThread::Instance()->GetCanvas();
//// qDebug() << ".... paint";
// painter.drawPixmap(0, 0, 800, 600, pix);
static double s_plottingX = 0;
double plottingY = 0;
QPainter painter(this);
QPen pen(Qt::green);
painter.setPen(pen);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(s_plottingX, 0, 10, 600, Qt::transparent);
QPainterPath path;
path.addRegion(m_popUpRegion);
painter.fillPath(path, Qt::transparent);
QRegion region(rect());
region -= m_popUpRegion;
painter.setClipRegion(region);
for(int i = 0; i < 60; i++)
{
plottingY = 10 + i * 10;
painter.drawLine(s_plottingX, plottingY, s_plottingX + 5, plottingY);
}
s_plottingX += 5;
if(s_plottingX > 800)
{
s_plottingX = 0;
}
}
示例4: loadSprites
/*!
\internal
A static function for reading the sprite files containing
pixmaps for displaying animated elements seen in the game.
*/
void KSprite::loadSprites()
{
QString sprites_prefix = IMG_BACKGROUND;
int sep = sprites_prefix.lastIndexOf("/");
sprites_prefix.truncate(sep);
int i = 0;
QString file_name;
QString base = sprites_prefix + '/';
while (animations_[i].id_) {
QList<QPixmap> p;
if (animations_[i].frames_) {
for (int j=0; j<animations_[i].frames_; ++j) {
QString s(animations_[i].path_);
file_name = base + s.arg(j,4,10,QLatin1Char('0'));
QPixmap pixmap(file_name);
p.insert(j,pixmap);
}
}
else {
file_name = base + QString(animations_[i].path_);
QPixmap pixmap(file_name);
p.insert(0,pixmap);
}
QList<Frame> frameshape;
for (int f = 0; f < p.size(); ++f) {
QPixmap pixmap = p.at(f);
Frame frame;
frame.pixmap = pixmap;
QPainterPath path;
QBitmap m = pixmap.mask();
if (m.width())
path.addRegion(QRegion(m));
else
path.addRegion(QRect(pixmap.rect()));
frame.shape = path;
frame.boundingRect = path.controlPointRect();
frameshape << frame;
}
shapemap_.insert(animations_[i].id_,frameshape);
i++;
}
spritesLoaded_ = true;
}
示例5: shape
QPainterPath AnimatedPixmapItem::shape() const
{
const Frame &f = frames.at(currentFrame);
if (f.shape.isEmpty()) {
QPainterPath path;
path.addRegion(f.pixmap.createHeuristicMask());
const_cast<Frame &>(f).shape = path;
}
return f.shape;
}
示例6: drawButton
void LaptopButton::drawButton(QPainter *p)
{
bool smallBtn = width() == btnWidth1;
if(btnPix1){
if(decoration()->isActive()){
if(isDown())
p->drawPixmap(0, 0, smallBtn ? *btnDownPix1 : *btnDownPix2);
else
p->drawPixmap(0, 0, smallBtn ? *btnPix1 : *btnPix2);
}
else{
if(isDown())
p->drawPixmap(0, 0, smallBtn ? *iBtnDownPix1 : *iBtnDownPix2);
else
p->drawPixmap(0, 0, smallBtn ? *iBtnPix1 : *iBtnPix2);
}
}
else{
QPalette g = options()->palette(KDecoration::ColorButtonBg, decoration()->isActive());
g.setCurrentColorGroup( QPalette::Active );
int w = width();
int h = height();
p->fillRect(1, 1, w-2, h-2, isDown() ? g.color(QPalette::Mid) : g.color(QPalette::Button) );
p->setPen(isDown() ? g.color( QPalette::Dark ) : g.color( QPalette::Light ));
p->drawLine(0, 0, w-1, 0);
p->drawLine(0, 0, 0, w-1);
p->setPen(isDown() ? g.color( QPalette::Light ) : g.color( QPalette::Dark ));
p->drawLine(w-1, 0, w-1, h-1);
p->drawLine(0, h-1, w-1, h-1);
}
QPainterPath path;
path.addRegion( deco );
QPoint offset( (width()-8)/2, (height()-8)/2 );
if( isDown() ) offset += QPoint( 1, 1 );
p->translate( offset );
p->setPen( Qt::NoPen );
p->setBrush( btnForeground );
p->drawPath( path );
}
示例7: clipRegionAddRect
void GraphQtInteractiveRenderer::clipRegionAddRect(Rectangle *rect)
{
GraphQtRenderer *renderer = m_data->renderer;
QRegion *clip = renderer->clipRegion();
QRect clipRect;
clipRect.setX(rect->x());
clipRect.setY(rect->y());
clipRect.setWidth(rect->width());
clipRect.setHeight(rect->height());
*clip = clip->united(clipRect);
QPainterPath path;
path.addRegion(*clip);
QPainter *painter = m_data->renderer->painter();
painter->setClipping(true);
painter->setClipPath(path);
}
示例8: translate
void tst_QPainterPath::translate()
{
QPainterPath path;
// Path with no elements.
QCOMPARE(path.currentPosition(), QPointF());
path.translate(50.5, 50.5);
QCOMPARE(path.currentPosition(), QPointF());
QCOMPARE(path.translated(50.5, 50.5).currentPosition(), QPointF());
// path.isEmpty(), but we have one MoveTo element that should be translated.
path.moveTo(50, 50);
QCOMPARE(path.currentPosition(), QPointF(50, 50));
path.translate(99.9, 99.9);
QCOMPARE(path.currentPosition(), QPointF(149.9, 149.9));
path.translate(-99.9, -99.9);
QCOMPARE(path.currentPosition(), QPointF(50, 50));
QCOMPARE(path.translated(-50, -50).currentPosition(), QPointF(0, 0));
// Complex path.
QRegion shape(100, 100, 300, 200, QRegion::Ellipse);
shape -= QRect(225, 175, 50, 50);
QPainterPath complexPath;
complexPath.addRegion(shape);
QVector<QPointF> untranslatedElements;
for (int i = 0; i < complexPath.elementCount(); ++i)
untranslatedElements.append(QPointF(complexPath.elementAt(i)));
const QPainterPath untranslatedComplexPath(complexPath);
const QPointF offset(100, 100);
complexPath.translate(offset);
for (int i = 0; i < complexPath.elementCount(); ++i)
QCOMPARE(QPointF(complexPath.elementAt(i)) - offset, untranslatedElements.at(i));
QCOMPARE(complexPath.translated(-offset), untranslatedComplexPath);
}
示例9: recreateTexture
//.........这里部分代码省略.........
quint64 timeEnd = App->getUsecSinceExec();
appLog() << "Simplify time = " << timeTotalSimplify << " usec";
appLog() << "Render time = " << timeTotalRender << " usec";
appLog() << "Full time = " << (timeEnd - timeStart) << " usec";
#elif STROKE_TECHNIQUE == 3
// Technique 3: Raster brute-force where for each destination pixel
// we measure the distance to the closest opaque source pixel
quint64 timeStart = App->getUsecSinceExec();
// Get bounding region based on text line bounding rects
QRegion region;
QTextBlock &block = m_document.firstBlock();
int numBlocks = m_document.blockCount();
for(int i = 0; i < numBlocks; i++) {
QTextLayout *layout = block.layout();
for(int j = 0; j < layout->lineCount(); j++) {
QTextLine &line = layout->lineAt(j);
const QString text = block.text().mid(
line.textStart(), line.textLength());
QRect rect = line.naturalTextRect()
.translated(layout->position()).toAlignedRect();
if(rect.isEmpty())
continue; // Don't add empty rectangles
rect.adjust(0, 0, 1, 0); // QTextLine is incorrect?
rect.adjust(
-m_strokeSize, -m_strokeSize,
m_strokeSize, m_strokeSize);
//appLog() << rect;
region += rect;
}
// Iterate
block = block.next();
}
quint64 timeRegion = App->getUsecSinceExec();
#if 0
// Debug bounding region
QPainterPath regionPath;
regionPath.addRegion(region);
regionPath.setFillRule(Qt::WindingFill);
p.fillPath(regionPath, QColor(255, 0, 0, 128));
#endif // 0
// We cannot read and write to the same image at the same time so
// create a second one. Note that this is not premultiplied.
QImage imgOut(size, QImage::Format_ARGB32);
imgOut.fill(Qt::transparent);
// Do distance calculation. We assume that non-fully transparent
// pixels are always next to a fully opaque one so if the closest
// "covered" pixel is not fully opaque then we can use that pixel's
// opacity to determine the distance to the shape's edge.
for(int y = 0; y < img.height(); y++) {
for(int x = 0; x < img.width(); x++) {
if(!region.contains(QPoint(x, y)))
continue;
float dist = getDistance(img, x, y, m_strokeSize);
// We fake antialiasing by blurring the edge by 1px
float outEdge = (float)m_strokeSize;
if(dist >= outEdge)
continue; // Outside stroke completely
float opacity = qMin(1.0f, outEdge - dist);
QColor col = m_strokeColor;
col.setAlphaF(col.alphaF() * opacity);
// Blend the stroke so that it appears under the existing
// pixel data
QRgb origRgb = img.pixel(x, y);
QColor origCol(origRgb);
origCol.setAlpha(qAlpha(origRgb));
col = blendColors(col, origCol, 1.0f);
imgOut.setPixel(x, y, col.rgba());
}
}
quint64 timeRender = App->getUsecSinceExec();
// Swap image data
p.end();
img = imgOut;
p.begin(&img);
quint64 timeEnd = App->getUsecSinceExec();
appLog() << "Region time = " << (timeRegion - timeStart) << " usec";
appLog() << "Render time = " << (timeRender - timeRegion) << " usec";
appLog() << "Swap time = " << (timeEnd - timeRender) << " usec";
appLog() << "Full time = " << (timeEnd - timeStart) << " usec";
#endif // STROKE_TECHNIQUE
}
// Render text
m_document.drawContents(&p);
// Convert the image to a GPU texture
m_texture = vidgfx_context_new_tex(gfx, img);
// Preview texture for debugging
//img.save(App->getDataDirectory().filePath("Preview.png"));
}
示例10: GetShape
QPainterPath CCJKShapeLinkNode::GetShape() const
{
QPainterPath path;
path.addRegion(QRegion(BoundingRect().toRect(), QRegion::Rectangle));
return path;
}