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); }
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; }
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); }
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); } }
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(); }
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); }
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(); }
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"); }
/*! 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 ) ); } }
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; }
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; }
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()); } }
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(); }
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()); }
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) { }
static inline QRectF boundsOnStroke(const QPainterPath &path, qreal width) { QPainterPathStroker stroker; stroker.setWidth(width); QPainterPath stroke = stroker.createStroke(path); return stroke.boundingRect(); }
QPainterPath TextSymbol::painterPath(void) { QPainterPath path; path.setFillRule(Qt::WindingFill); QString filename = ctx.loader->absPath("fonts/" + m_font); FontDataStore* ds = CachedFontParser::parse(filename); QMatrix mat(m_xsize / ds->xsize(), 0, 0, m_ysize / ds->ysize(), 0, 0); for (int i = 0; i < m_text.length(); ++i) { CharRecord* rec = ds->charRecord(m_text[i].toAscii()); if (rec) { QPainterPath p = mat.map(rec->painterPath(m_width_factor)); path.addPath(p); } mat.translate(ds->xsize() + ds->offset(), 0); } QRectF b = path.boundingRect(); QMatrix mat2; mat2.translate(-b.x(), -(b.y() + b.height())); path = mat2.map(path); return path; }
QRegion KRITAIMAGE_EXPORT splitPath(const QPainterPath &path) { QRect totalRect = path.boundingRect().toAlignedRect(); // adjust the rect for antialiasing to work totalRect.adjusted(-1,-1,1,1); const int step = 64; const int right = totalRect.x() + totalRect.width(); const int bottom = totalRect.y() + totalRect.height(); QRegion dirtyRegion; for (int y = totalRect.y(); y < bottom;) { int nextY = qMin((y + step) & ~(step-1), bottom); for (int x = totalRect.x(); x < right;) { int nextX = qMin((x + step) & ~(step-1), right); QRect rect(x, y, nextX - x, nextY - y); if(path.intersects(rect)) { dirtyRegion |= rect; } x = nextX; } y = nextY; } return dirtyRegion; }
void paintAreas( AbstractDiagram::Private* diagramPrivate, PaintContext* ctx, const QModelIndex& index, const QList< QPolygonF >& areas, uint opacity ) { AbstractDiagram* diagram = diagramPrivate->diagram; QPainterPath path; for ( int i = 0; i < areas.count(); ++i ) { const QPolygonF& p = areas[ i ]; path.addPolygon( p ); diagramPrivate->reverseMapper.addPolygon( index.row(), index.column(), p ); path.closeSubpath(); } ThreeDLineAttributes threeDAttrs = threeDLineAttributes( diagram, index ); QBrush trans = diagram->brush( index ); if ( threeDAttrs.isEnabled() ) { trans = threeDAttrs.threeDBrush( trans, path.boundingRect() ); } QColor transColor = trans.color(); transColor.setAlpha( opacity ); trans.setColor(transColor); QPen indexPen = diagram->pen(index); indexPen.setBrush( trans ); const PainterSaver painterSaver( ctx->painter() ); ctx->painter()->setRenderHint( QPainter::Antialiasing, diagram->antiAliasing() ); ctx->painter()->setPen( PrintingParameters::scalePen( indexPen ) ); ctx->painter()->setBrush( trans ); ctx->painter()->drawPath( path ); }
Image BrushStrokerCustomBrush::drawDabImage(const TabletInputData &data, QRect *rect) { Q_ASSERT(data.pressure > 0); Vec2D radiusVec; radiusVec.rx() = radiusBase() * data.pressure; radiusVec.ry() = radiusVec.x() * (1.0 - _setting.flattening); _lastMinorRadius = radiusVec.y(); //qDebug() << "radius" << radiusVec.x << radiusVec.y; QPainterPath ellipse; ellipse.addEllipse(data.pos, radiusVec.x(), radiusVec.y()); QRect dabRect; if (_setting.rotation) { QTransform rotation; rotation.rotate(_setting.rotation); ellipse = rotation.map(ellipse); dabRect = ellipse.boundingRect().toAlignedRect(); } else { dabRect = QRectF(QPointF(data.pos - radiusVec), QSizeF(2.0 * radiusVec)).toAlignedRect(); } Image dabImage(dabRect.size()); dabImage.clear(); Painter dabPainter(&dabImage); dabPainter.translateShape(-dabRect.topLeft()); if (_setting.tableWidth == 1 && _setting.tableHeight == 1) { // no gradient dabPainter.setPixel(pixel()); } else { ArgbGradient gradient; gradient.addStop(0, pixel()); gradient.addStop(_setting.tableWidth, pixel() * _setting.tableHeight); gradient.addStop(1, Pixel(0)); dabPainter.setBrush(Malachite::Brush::fromRadialGradient(gradient, data.pos, radiusVec)); } dabPainter.drawPath(ellipse); dabPainter.end(); *rect = dabRect; return dabImage; }
void UBEditableGraphicsRegularShapeItem::onActivateEditionMode() { QPainterPath circle; circle.addEllipse(mCenter, mRadius, mRadius); mHandles.at(0)->setPos(circle.boundingRect().bottomRight()); }
void plotPathsToPainter(QPainter& painter, QPainterPath& path, const Numpy1DObj& x, const Numpy1DObj& y, const Numpy1DObj* scaling, const QRectF* clip, const QImage* colorimg) { 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( scaling != 0 ) { // scale point if requested const qreal s = (*scaling)(i); painter.scale(s, s); } if( colorimg != 0 ) { // get color from pixel and create a new brush QBrush b( QColor::fromRgba(colorimg->pixel(i, 0)) ); painter.setBrush(b); } painter.drawPath(path); painter.setWorldTransform(origtrans); lastpt = pt; } } }
void QJsonPaintEngine::updateClipPath(const QPainterPath &path, Qt::ClipOperation op) { Q_D(QJsonPaintEngine); #ifdef QT_PICTURE_DEBUG qDebug() << " -> updateClipPath(): op:" << op << "bounding rect:" << path.boundingRect(); #endif d->s << QString("\t{\"cp\": {\"x\": \"notimplemented\"}},\r\n"); }
QRectF BlipItem::boundingRect() const { QPainterPath shape = generateGustStyleMarker(); QRectF box = shape.boundingRect(); qreal dp = pen().widthF()/2; return box.adjusted(-dp,-dp,dp,dp); }
void PathDeformRenderer::setText(const QString &text) { m_text = text; QFont f("times new roman,utopia"); f.setStyleStrategy(QFont::ForceOutline); f.setPointSize(m_fontSize); f.setStyleHint(QFont::Times); QFontMetrics fm(f); m_paths.clear(); m_pathBounds = QRect(); QPointF advance(0, 0); bool do_quick = true; for (int i=0; i<text.size(); ++i) { if (text.at(i).unicode() >= 0x4ff && text.at(i).unicode() <= 0x1e00) { do_quick = false; break; } } if (do_quick) { for (int i=0; i<text.size(); ++i) { QPainterPath path; path.addText(advance, f, text.mid(i, 1)); m_pathBounds |= path.boundingRect(); m_paths << path; advance += QPointF(fm.width(text.mid(i, 1)), 0); } } else { QPainterPath path; path.addText(advance, f, text); m_pathBounds |= path.boundingRect(); m_paths << path; } for (int i=0; i<m_paths.size(); ++i) m_paths[i] = m_paths[i] * QMatrix(1, 0, 0, 1, -m_pathBounds.x(), -m_pathBounds.y()); update(); }
void TestSnapStrategy::testNodeDecoration() { //Tests so the decoration returns a rect which is inside the "standard outer rect" NodeSnapStrategy toTest; KoViewConverter irrelevantParameter; QRectF originalRect = QRectF(-5.5, -5.5, 11, 11); QPainterPath resultingDecoration = toTest.decoration(irrelevantParameter); QRectF rectInsidePath = resultingDecoration.boundingRect(); QVERIFY(originalRect==rectInsidePath); }
void TestSnapStrategy::testIntersectionDecoration() { //Tests the decoration by making sure that the returned rect is within the "standard outer rect" IntersectionSnapStrategy toTest; KoViewConverter irrelevantParameter; QRectF originalRect = QRectF(-5.5,-5.5,11,11); //std outer rect QPainterPath resultingDecoration = toTest.decoration(irrelevantParameter); QRectF rectInsidePath = resultingDecoration.boundingRect(); QVERIFY(originalRect==rectInsidePath); }
void CanvasMode_EditPolygon::mouseReleaseEvent(QMouseEvent *m) { const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); m_canvas->m_viewMode.m_MouseButtonPressed = false; m_canvas->resetRenderMode(); m->accept(); PageItem *currItem = m_doc->m_Selection->itemAt(0); PageItem_RegularPolygon* item = currItem->asRegularPolygon(); QTransform itemMatrix = currItem->getTransform(); if ((m_polygonPoint == useControlInner) || (m_polygonPoint == useControlOuter) || (m_polygonPoint == useControlInnerCurve) || (m_polygonPoint == useControlOuterCurve)) { double newX = mousePointDoc.x(); double newY = mousePointDoc.y(); QPointF cPoint = itemMatrix.map(centerPoint); QLineF stLinA = QLineF(cPoint, QPointF(newX, newY)); uint cx = polyUseFactor ? polyCorners * 2 : polyCorners; double seg = 360.0 / cx; double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (currItem->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (currItem->height() / 2.0) + (currItem->height()/2.0) - currItem->height(), 2)); if (m_polygonPoint == useControlInner) { polyInnerRot = stLinA.angle() - 90 - polyRotation - seg; polyFactor = stLinA.length() / sqrt(pow(sin(stLinA.angle() * M_PI / 180.0) * currItem->height() / 2.0, 2) + pow(cos(stLinA.angle() * M_PI / 180.0) * currItem->width() / 2.0, 2)); } if (m_polygonPoint == useControlOuter) polyRotation = stLinA.angle() - 90; if (m_polygonPoint == useControlInnerCurve) { QPointF ePoint = itemMatrix.map(endPoint); QLineF stLinC = QLineF(ePoint, QPointF(newX, newY)); polyCurvature = stLinC.length() / trueLength; } if (m_polygonPoint == useControlOuterCurve) { QPointF sPoint = itemMatrix.map(startPoint); QPointF sPoint2 = itemMatrix.map(currItem->PoLine.pointQF(6)); QLineF stLinCo = QLineF(sPoint, QPointF(newX, newY)); QLineF stLinCo2 = QLineF(sPoint, sPoint2); polyOuterCurvature = stLinCo.length() / stLinCo2.length(); } item->polyFactor = polyFactor; item->polyRotation = polyRotation; item->polyCurvature = polyCurvature; item->polyInnerRot = polyInnerRot; item->polyOuterCurvature = polyOuterCurvature; item->recalcPath(); VectorDialog->setValues(polyCorners, polyFactor, polyUseFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature); if (m_transaction) { m_transaction.commit(); m_transaction.reset(); } } QPainterPath path = itemMatrix.map(RegularPolygonPath(item->width(), item->height(), polyCorners, polyUseFactor, polyFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature)); m_doc->regionsChanged()->update(path.boundingRect().adjusted(-5, -5, 10, 10)); }
QT_END_NAMESPACE #endif void tst_QRegion::regionToPath() { #ifdef QT_BUILD_INTERNAL QFETCH(QPainterPath, path); for (int i = 0; i < 360; i += 10) { QTransform transform; transform.scale(5, 5); transform.rotate(i); QPainterPath mapped = transform.map(path); QRegion region(mapped.toFillPolygon().toPolygon()); QPainterPath a; a.addRegion(region); QPainterPath b = qt_regionToPath(region); QRect r = a.boundingRect().toAlignedRect(); QImage ia(r.size(), QImage::Format_RGB32); ia.fill(0xffffffff); QImage ib = ia; QPainter p(&ia); p.translate(-r.x(), -r.y()); p.fillPath(a, Qt::red); p.end(); p.begin(&ib); p.translate(-r.x(), -r.y()); p.fillPath(b, Qt::red); p.end(); QCOMPARE(ia, ib); QCOMPARE(a.boundingRect(), b.boundingRect()); } #endif }
void RotationWidgetItem::initRotation(const QPainterPath & path, const QPointF & rotationPoint) { d->rotated_shape = path; QRectF boundingRect = path.boundingRect(); this->setPos(boundingRect.center()); d->rotated_shape.translate(-boundingRect.center()); d->handler_pos = QPointF(100,0); d->rotation_point = rotationPoint; d->rotation_angle = 0; d->rotation_point_offset = QPointF(); }