本文整理汇总了C++中QPainterPath::boundingRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::boundingRect方法的具体用法?C++ QPainterPath::boundingRect怎么用?C++ QPainterPath::boundingRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::boundingRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toRect
QPainterPath TPathHelper::toRect(const QPainterPath &p, const QRect &rect, float offset)
{
QPainterPath path;
QRectF br = p.boundingRect();
QMatrix matrix;
float sx = 1, sy = 1;
if (rect.width() < br.width())
sx = static_cast<float>(rect.width()-offset) / static_cast<float>(br.width());
if (rect.height() < br.height())
sy = static_cast<float>(rect.height()-offset) / static_cast<float>(br.height());
float factor = qMin(sx, sy);
matrix.scale(factor, factor);
path = matrix.map(p);
matrix.reset();
QPointF pos = path.boundingRect().topLeft();
float tx = offset/2-pos.x(), ty = offset/2-pos.y();
matrix.translate(tx, ty);
return matrix.map(path);
}
示例2: brushOutlineImpl
QPainterPath KisBrushBasedPaintOpSettings::brushOutlineImpl(const KisPaintInformation &info,
OutlineMode mode,
qreal additionalScale,
bool forceOutline)
{
QPainterPath path;
if (forceOutline || mode == CursorIsOutline || mode == CursorIsCircleOutline || mode == CursorTiltOutline) {
KisBrushSP brush = this->brush();
if (!brush) return path;
qreal finalScale = brush->scale() * additionalScale;
QPainterPath realOutline = brush->outline();
if (mode == CursorIsCircleOutline || mode == CursorTiltOutline ||
(forceOutline && mode == CursorNoOutline)) {
QPainterPath ellipse;
ellipse.addEllipse(realOutline.boundingRect());
realOutline = ellipse;
}
path = outlineFetcher()->fetchOutline(info, this, realOutline, finalScale, brush->angle());
if (mode == CursorTiltOutline) {
QPainterPath tiltLine = makeTiltIndicator(info,
realOutline.boundingRect().center(),
realOutline.boundingRect().width() * 0.5,
3.0);
path.addPath(outlineFetcher()->fetchOutline(info, this, tiltLine, finalScale, 0.0, true, realOutline.boundingRect().center().x(), realOutline.boundingRect().center().y()));
}
}
return path;
}
示例3: UpdatePreView
void PolygonWidget::UpdatePreView()
{
double roundness = CurvatureSpin->value() / 100.0;
QPixmap pm = QPixmap(Preview->width() - 5, Preview->height() - 5);
pm.fill(Qt::white);
QPainter p;
p.begin(&pm);
p.setBrush(Qt::NoBrush);
p.setPen(Qt::black);
QPainterPath pp = RegularPolygon(Preview->width() - 6, Preview->height() - 6, Ecken->value(), Konvex->isChecked(), GetFaktor(), Slider2->value(), roundness);
QRectF br = pp.boundingRect();
if (br.x() < 0)
{
QMatrix m;
m.translate(-br.x(), 0);
pp = pp * m;
}
if (br.y() < 0)
{
QMatrix m;
m.translate(0, -br.y());
pp = pp * m;
}
br = pp.boundingRect();
if ((br.height() > Preview->height() - 6) || (br.width() > Preview->width() - 6))
{
QMatrix ma;
double sca = static_cast<double>(qMax(Preview->height() - 6, Preview->width() - 6)) / static_cast<double>(qMax(br.width(), br.height()));
ma.scale(sca, sca);
pp = pp * ma;
}
p.strokePath(pp, p.pen());
p.end();
Preview->setPixmap(pm);
}
示例4: drawPointLabel
void PrimitivePainter::drawPointLabel(QPointF C, QString str, QString strBg, QPainter* thePainter, qreal PixelPerM) const
{
LineParameters lp = labelBoundary();
qreal WW = PixelPerM*lp.Proportional+lp.Fixed;
if (WW < 10) return;
QFont font = getLabelFont();
font.setPixelSize(int(WW));
QFontMetrics metrics(font);
int modX = 0;
int modY = 0;
QPainterPath textPath;
QPainterPath bgPath;
if (!str.isEmpty()) {
modX = - (metrics.width(str)/2);
if (DrawIcon && !IconName.isEmpty() )
{
QImage pm(IconName);
modY = - pm.height();
if (DrawLabelBackground)
modY -= BG_SPACING;
}
textPath.addText(modX, modY, font, str);
thePainter->translate(C);
}
if (DrawLabelBackground && !strBg.isEmpty()) {
modX = - (metrics.width(strBg)/2);
if (DrawIcon && !IconName.isEmpty() )
{
QImage pm(IconName);
modY = - pm.height();
if (DrawLabelBackground)
modY -= BG_SPACING;
}
textPath.addText(modX, modY, font, strBg);
thePainter->translate(C);
bgPath.addRect(textPath.boundingRect().adjusted(-BG_SPACING, -BG_SPACING, BG_SPACING, BG_SPACING));
thePainter->setPen(QPen(LabelColor, BG_PEN_SZ));
thePainter->setBrush(LabelBackgroundColor);
thePainter->drawPath(bgPath);
}
if (getLabelHalo()) {
thePainter->setPen(QPen(Qt::white, font.pixelSize()/5));
thePainter->drawPath(textPath);
}
thePainter->setPen(Qt::NoPen);
thePainter->setBrush(LabelColor);
thePainter->drawPath(textPath);
if (DrawLabelBackground && !strBg.isEmpty()) {
QRegion rg = thePainter->clipRegion();
rg -= textPath.boundingRect().toRect().translated(C.toPoint());
thePainter->setClipRegion(rg);
}
}
示例5: paintEvent
void ToolButton::paintEvent(QPaintEvent *) {
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(Qt::black);
p.setBrush(_flashBackground != Qt::lightGray
? _flashBackground
: _mousePressPoint.isNull()
? (_mouseCurrentlyOver ? Qt::darkGray : Qt::lightGray)
: Qt::white);
p.drawRoundedRect(rect(), 20, 20, Qt::RelativeSize);
if (_tool) {
p.drawPixmap(2, 2, _tool->icon()
.pixmap(iconSize(), _currentlyTriggerable
? QIcon::Normal : QIcon::Disabled));
}
if (!_keyLabel.isNull()) {
QPainterPath pp;
QFont font = this->font();
//QFont font("Sans");
//font.setPointSize(10);
pp.addText(QPointF(0, 0), font, _keyLabel);
pp.translate(width()-2-pp.boundingRect().width()-pp.boundingRect().x(),
height()-2-pp.boundingRect().height()-pp.boundingRect().y());
p.setRenderHint(QPainter::Antialiasing);
// LATER parametrize outline and main letter colors
p.setBrush(Qt::white);
p.setPen(Qt::white);
p.drawPath(pp);
p.setBrush(Qt::darkBlue);
p.setPen(Qt::transparent);
p.drawPath(pp);
}
// LATER use icon rather than text as target indicator
QString targetIndicator("?");
switch (_targetType) {
case TargetManager::PrimaryTarget:
targetIndicator = QString();
break;
case TargetManager::PreviousPrimaryTarget:
targetIndicator = "p";
break;
case TargetManager::MouseOverTarget:
targetIndicator = "o";
break;
}
if (!targetIndicator.isEmpty()) {
QFont font = this->font();
//font.setPointSize(10);
p.setFont(font);
p.setPen(Qt::black);
QFontMetrics fm(font);
p.drawText(QRectF(2, height()-2-fm.height(), width()-4, fm.maxWidth()),
Qt::AlignLeft, targetIndicator);
}
p.end();
}
示例6: drawPath
void QPicturePaintEngine::drawPath(const QPainterPath &path)
{
Q_D(QPicturePaintEngine);
#ifdef QT_PICTURE_DEBUG
qDebug() << " -> drawPath():" << path.boundingRect();
#endif
int pos;
SERIALIZE_CMD(QPicturePrivate::PdcDrawPath);
d->s << path;
writeCmdLength(pos, path.boundingRect(), true);
}
示例7: paint
void KoPatternBackground::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const
{
Q_D(const KoPatternBackground);
if (! d->imageData)
return;
painter.save();
if (d->repeat == Tiled) {
// calculate scaling of pixmap
QSizeF targetSize = d->targetSize();
QSizeF imageSize = d->imageData->imageSize();
qreal scaleX = targetSize.width() / imageSize.width();
qreal scaleY = targetSize.height() / imageSize.height();
QRectF targetRect = fillPath.boundingRect();
// undo scaling on target rectangle
targetRect.setWidth(targetRect.width() / scaleX);
targetRect.setHeight(targetRect.height() / scaleY);
// determine pattern offset
QPointF offset = d->offsetFromRect(targetRect, imageSize);
// create matrix for pixmap scaling
QTransform matrix;
matrix.scale(scaleX, scaleY);
painter.setClipPath(fillPath);
painter.setWorldTransform(matrix, true);
painter.drawTiledPixmap(targetRect, d->imageData->pixmap(imageSize.toSize()), -offset);
} else if (d->repeat == Original) {
QRectF sourceRect(QPointF(0, 0), d->imageData->imageSize());
QRectF targetRect(QPoint(0, 0), d->targetSize());
targetRect.moveCenter(fillPath.boundingRect().center());
painter.setClipPath(fillPath);
painter.drawPixmap(targetRect, d->imageData->pixmap(sourceRect.size().toSize()), sourceRect);
} else if (d->repeat == Stretched) {
painter.setClipPath(fillPath);
// undo conversion of the scaling so that we can use a nicely scaled image of the correct size
qreal zoomX, zoomY;
converter.zoom(&zoomX, &zoomY);
zoomX = zoomX ? 1 / zoomX : zoomX;
zoomY = zoomY ? 1 / zoomY : zoomY;
painter.scale(zoomX, zoomY);
QRectF targetRect = converter.documentToView(fillPath.boundingRect());
painter.drawPixmap(targetRect.topLeft(), d->imageData->pixmap(targetRect.size().toSize()));
}
painter.restore();
}
示例8: drawPath
void QJsonPaintEngine::drawPath(const QPainterPath &path)
{
Q_D(QJsonPaintEngine);
#ifdef QT_PICTURE_DEBUG
qDebug() << " -> drawPath():" << path.boundingRect();
#endif
QString command;
d->s << QString("\t{\"p\": \r\n\t\t[\r\n");
for(int i=0; i< path.elementCount(); i++)
{
QPainterPath::Element e = path.elementAt(i);
switch (e.type)
{
case QPainterPath::MoveToElement:
command = QString("\t\t{\"m\": {\"x\": %1, \"y\":%2}},\r\n").arg(e.x).arg(e.y); break;
case QPainterPath::LineToElement:
command = QString("\t\t{\"l\": {\"x\": %1, \"y\":%2}},\r\n").arg(e.x).arg(e.y); break;
case QPainterPath::CurveToElement:
command = QString("\t\t{\"a\": (\"x1\": %1, \"y1\": %2, \"x2\": %3, \"y2\": %4}},\r\n").arg(d->pos.x()).arg(d->pos.y()).arg(e.x).arg(e.y); break;
case QPainterPath::CurveToDataElement:
command = QString("\t\t{\"ax\": (\"x1\": %1, \"y2\": %2, \"x2\": %3, \"y2\": %4}},\r\n").arg(d->pos.x()).arg(d->pos.y()).arg(e.x).arg(e.y); break;
default: break;
}
d->s << command;
d->pos.setX(e.x);
d->pos.setX(e.y);
}
d->s << QString("\t\t]\r\n\t},\r\n");
}
示例9: drawPath
/*!
Store a path command in the command list
\sa QPaintEngine::drawPath()
*/
void QwtGraphic::drawPath( const QPainterPath &path )
{
const QPainter *painter = paintEngine()->painter();
if ( painter == NULL )
return;
d_data->commands += QwtPainterCommand( path );
if ( !path.isEmpty() )
{
const QPainterPath scaledPath = painter->transform().map( path );
QRectF pointRect = scaledPath.boundingRect();
QRectF boundingRect = pointRect;
if ( painter->pen().style() != Qt::NoPen
&& painter->pen().brush().style() != Qt::NoBrush )
{
boundingRect = qwtStrokedPathRect( painter, path );
}
updateControlPointRect( pointRect );
updateBoundingRect( boundingRect );
d_data->pathInfos += PathInfo( pointRect,
boundingRect, qwtHasScalablePen( painter ) );
}
}
示例10: qwtStrokedPathRect
static QRectF qwtStrokedPathRect(
const QPainter *painter, const QPainterPath &path )
{
QPainterPathStroker stroker;
stroker.setWidth( painter->pen().widthF() );
stroker.setCapStyle( painter->pen().capStyle() );
stroker.setJoinStyle( painter->pen().joinStyle() );
stroker.setMiterLimit( painter->pen().miterLimit() );
QRectF rect;
if ( qwtHasScalablePen( painter ) )
{
QPainterPath stroke = stroker.createStroke(path);
rect = painter->transform().map(stroke).boundingRect();
}
else
{
QPainterPath mappedPath = painter->transform().map(path);
mappedPath = stroker.createStroke( mappedPath );
rect = mappedPath.boundingRect();
}
return rect;
}
示例11: updateTextPath
void ArcItem::updateTextPath() {
QPainterPath path;
if((_endItem && _startItem->collidesWithItem(_endItem)) ||
(!_endItem && _startItem->contains(_end)))
return;
QPointF start(0,0),
point = _end - pos();
//The arrow line and reverse liune
QLineF line(start, point);
QLineF revline(point, start);
//Make some text
if(this->weight() != 1){
QFont font;
font.setPointSizeF(6);
path.addText(QPointF(0,0), font, QString::number(this->weight()));
//Move it into some reasonable position
path.translate(-path.boundingRect().width()/2, -3);
QTransform rotation;
qreal angle = line.angle();
if(angle > 90 && angle < 270)
angle = 180 - angle;
else
angle = 360 - angle;
rotation.rotate(angle);
path = rotation.map(path);
path.translate(point/2);
}
_cachedTextPath = path;
}
示例12: paint
void UBEditableGraphicsRegularShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget)
Q_UNUSED(option)
setStyle(painter);
painter->fillPath(path(), painter->brush());
painter->drawPath(path());
if(mMultiClickState >= 1) {
painter->setBrush(QBrush());
QPen p;
p.setStyle(Qt::DashLine);
p.setColor(QColor(128,128,128));
p.setWidth(pen().width());
painter->setPen(p);
painter->drawEllipse(mCenter, mRadius, mRadius);
p.setColor(QColor(128, 128, 200));
painter->setPen(p);
QPainterPath ccircle;
ccircle.addEllipse(mCenter, mRadius, mRadius);
painter->drawRect(ccircle.boundingRect());
}
}
示例13: boundingRect
QRectF Arch::boundingRect() const
{
QPainterPath line;
QPainterPath path;
if (mRect.isNull())
return path.boundingRect();
if (mSpanAngle != 360 * 16) {
path.moveTo(mRect.center());
line.moveTo(mRect.center());
line.lineTo(x(), y());
path.arcTo(mRect, mStartAngle / 16.0, mSpanAngle / 16.0);
} else {
path.addEllipse(mRect);
}
return path.boundingRect();
}
示例14: lastPieceBoundingRect
const QRectF KarbonCalligraphicShape::lastPieceBoundingRect()
{
if (pointCount() < 6)
return QRectF();
int index = pointCount() / 2;
QPointF p1 = pointByIndex(KoPathPointIndex(0, index - 3))->point();
QPointF p2 = pointByIndex(KoPathPointIndex(0, index - 2))->point();
QPointF p3 = pointByIndex(KoPathPointIndex(0, index - 1))->point();
QPointF p4 = pointByIndex(KoPathPointIndex(0, index))->point();
QPointF p5 = pointByIndex(KoPathPointIndex(0, index + 1))->point();
QPointF p6 = pointByIndex(KoPathPointIndex(0, index + 2))->point();
// TODO: also take the control points into account
QPainterPath p;
p.moveTo(p1);
p.lineTo(p2);
p.lineTo(p3);
p.lineTo(p4);
p.lineTo(p5);
p.lineTo(p6);
return p.boundingRect().translated(position());
}
示例15:
GhostCard::GhostCard(const QPixmap& pixmap, const QPainterPath& path, const CardWindow::Position& pos)
: m_pixmap(pixmap)
, m_painterPath(path)
, m_boundingRect(path.boundingRect())
, m_position(pos)
{
}