void KisFreeTransformStrategy::Private::recalculateTransformations() { KisTransformUtils::MatricesPack m(currentArgs); QTransform sanityCheckMatrix = m.TS * m.SC * m.S * m.projectedP; /** * The center of the original image should still * stay the origin of CS */ KIS_ASSERT_RECOVER_NOOP(sanityCheckMatrix.map(currentArgs.originalCenter()).manhattanLength() < 1e-4); transform = m.finalTransform(); QTransform viewScaleTransform = converter->imageToDocumentTransform() * converter->documentToFlakeTransform(); handlesTransform = transform * viewScaleTransform; QTransform tl = QTransform::fromTranslate(transaction.originalTopLeft().x(), transaction.originalTopLeft().y()); paintingTransform = tl.inverted() * q->thumbToImageTransform() * tl * transform * viewScaleTransform; paintingOffset = transaction.originalTopLeft(); // check whether image is too big to be displayed or not imageTooBig = KisTransformUtils::checkImageTooBig(transaction.originalRect(), m); // recalculate cached handles position recalculateTransformedHandles(); emit q->requestShowImageTooBig(imageTooBig); }
QPoint KisCoordinatesConverter::mirror(QPointF center, bool mirrorXAxis, bool mirrorYAxis, bool keepOrientation) { bool doXMirroring = m_d->isXAxisMirrored ^ mirrorXAxis; bool doYMirroring = m_d->isYAxisMirrored ^ mirrorYAxis; qreal scaleX = doXMirroring ? -1.0 : 1.0; qreal scaleY = doYMirroring ? -1.0 : 1.0; QTransform mirror = QTransform::fromScale(scaleX, scaleY); QTransform rot; rot.rotate(m_d->rotationAngle); m_d->flakeToWidget *= QTransform::fromTranslate(-center.x(),-center.y()); if(keepOrientation) m_d->flakeToWidget *= rot.inverted(); m_d->flakeToWidget *= mirror; if(keepOrientation) m_d->flakeToWidget *= rot; m_d->flakeToWidget *= QTransform::fromTranslate(center.x(),center.y()); if(!keepOrientation && (doXMirroring ^ doYMirroring)) m_d->rotationAngle = -m_d->rotationAngle; m_d->isXAxisMirrored = mirrorXAxis; m_d->isYAxisMirrored = mirrorYAxis; correctOffsetToTransformation(); recalculateTransformations(); return m_d->documentOffset.toPoint(); }
void nodeDock::centreNode( AEntity *ent ) // places the node in the centre of the view { nodeEntity *node( ent->castTo<nodeEntity*>() ); if( node ) { connect( node, SIGNAL(requestNetworkRedraw()), mScene, SLOT(update()), Qt::UniqueConnection ); if( qFuzzyCompare( node->property("nodeEntity/pos")->toVector3D(), QVector3D( 0, 0, 0 ) ) ) { // set pos to centre of screen QPointF pos; pos.setX(mView->rect().width()/2); pos.setY(mView->rect().height()/2); // get transformation matrix and invert it (viewMatrix moves the scene, so invert to move to view) QTransform viewMatrix = mView->getTransform(); viewMatrix = viewMatrix.inverted(); // map point to matrix pos = viewMatrix.map(pos); // set position QVector3D vectPos; vectPos.setX(pos.x()); vectPos.setY(pos.y()); node->property("nodeEntity/pos") = vectPos; } //Rebuild gui from here, rather than direct signal so only rebuild on NODE added, not just any entity rebuildGui(); } }
void QgsLayoutItemEllipseShape::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * ) { QPainter *painter = context.painter(); painter->setPen( Qt::NoPen ); painter->setBrush( Qt::NoBrush ); double scale = context.convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters ); //shapes with curves must be enlarged before conversion to QPolygonF, or //the curves are approximated too much and appear jaggy QTransform t = QTransform::fromScale( 100, 100 ); //inverse transform used to scale created polygons back to expected size QTransform ti = t.inverted(); //create an ellipse QPainterPath ellipsePath; ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) ); QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t ); QPolygonF shapePolygon = ti.map( ellipsePoly ); QList<QPolygonF> rings; //empty list symbol()->startRender( context ); symbol()->renderPolygon( shapePolygon, &rings, nullptr, context ); symbol()->stopRender( context ); }
void QgsLayoutItemRectangularShape::draw( QgsRenderContext &context, const QStyleOptionGraphicsItem * ) { QPainter *painter = context.painter(); painter->setPen( Qt::NoPen ); painter->setBrush( Qt::NoBrush ); double scale = context.convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters ); QPolygonF shapePolygon; if ( mCornerRadius.length() > 0 ) { //shapes with curves must be enlarged before conversion to QPolygonF, or //the curves are approximated too much and appear jaggy QTransform t = QTransform::fromScale( 100, 100 ); //inverse transform used to scale created polygons back to expected size QTransform ti = t.inverted(); QPainterPath roundedRectPath; double radius = mLayout->convertToLayoutUnits( mCornerRadius ) * scale; roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ), radius, radius ); QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t ); shapePolygon = ti.map( roundedPoly ); } else { shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) ); } QList<QPolygonF> rings; //empty list symbol()->startRender( context ); symbol()->renderPolygon( shapePolygon, &rings, nullptr, context ); symbol()->stopRender( context ); }
void KisTransformProcessingVisitor::transformClones(KisLayer *layer, KisUndoAdapter *undoAdapter) { QList<KisCloneLayerWSP> clones = layer->registeredClones(); foreach(KisCloneLayerSP clone, clones) { // we have just casted an object from a weak pointer, // so check validity first if(!clone) continue; KisTransformWorker tw(clone->projection(), m_sx, m_sy, m_shearx, m_sheary, m_shearOrigin.x(), m_shearOrigin.y(), m_angle, m_tx, m_ty, 0, m_filter); QTransform trans = tw.transform(); QTransform offsetTrans = QTransform::fromTranslate(clone->x(), clone->y()); QTransform newTrans = trans.inverted() * offsetTrans * trans; QPoint oldPos(clone->x(), clone->y()); QPoint newPos(newTrans.dx(), newTrans.dy()); KUndo2Command *command = new KisNodeMoveCommand2(clone, oldPos, newPos, undoAdapter); undoAdapter->addCommand(command); } }
void SceneInspector::renderScene(const QTransform &transform, const QSize &size) { if (!Endpoint::isConnected()) { // only do something if we are connected to a remote client return; } QGraphicsScene *scene = m_sceneModel->scene(); if (!scene) { return; } // initialize transparent pixmap QPixmap view(size); view.fill(Qt::transparent); // setup painter and apply transformation of client view QPainter painter(&view); painter.setWorldTransform(transform); // the area we want to paint has the size of the client's viewport _after_ applying // the transformation. Thus first apply the inverse to yield the desired area afterwards QRectF area(QPointF(0, 0), size); area = transform.inverted().mapRect(area); scene->render(&painter, area, area, Qt::IgnoreAspectRatio); QGraphicsItem *currentItem = m_itemSelectionModel->currentIndex().data(SceneModel::SceneItemRole).value<QGraphicsItem*>(); if (currentItem) { paintItemDecoration(currentItem, transform, &painter); } emit sceneRendered(view); }
/*! \brief Convenience function. * */ void TrackSpiralArcSpiral::setLocalStartHeading(double startHeading) { while (startHeading <= -180.0) { startHeading += 360.0; } while (startHeading > 180.0) { startHeading -= 360.0; } // Local to internal (Parameters are given in internal coordinates) // // double deltaHeading(startHeading - heading()); QTransform trafo; trafo.rotate(deltaHeading); pa_->setEndHeadingDeg(pa_->getEndHeadingRad() * 360.0 / (2.0 * M_PI) - deltaHeading); pa_->setEndPoint(trafo.inverted().map(pa_->getEndPoint())); pa_->init(); applyParameters(); // Set local translation // // setLocalRotation(startHeading); }
void QgsLayoutItemShape::draw( QgsLayoutItemRenderContext &context ) { QPainter *painter = context.renderContext().painter(); painter->setPen( Qt::NoPen ); painter->setBrush( Qt::NoBrush ); double scale = context.renderContext().convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters ); QPolygonF shapePolygon; //shapes with curves must be enlarged before conversion to QPolygonF, or //the curves are approximated too much and appear jaggy QTransform t = QTransform::fromScale( 100, 100 ); //inverse transform used to scale created polygons back to expected size QTransform ti = t.inverted(); switch ( mShape ) { case Ellipse: { //create an ellipse QPainterPath ellipsePath; ellipsePath.addEllipse( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) ); QPolygonF ellipsePoly = ellipsePath.toFillPolygon( t ); shapePolygon = ti.map( ellipsePoly ); break; } case Rectangle: { //if corner radius set, then draw a rounded rectangle if ( mCornerRadius.length() > 0 ) { QPainterPath roundedRectPath; double radius = mLayout->convertToLayoutUnits( mCornerRadius ) * scale; roundedRectPath.addRoundedRect( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ), radius, radius ); QPolygonF roundedPoly = roundedRectPath.toFillPolygon( t ); shapePolygon = ti.map( roundedPoly ); } else { shapePolygon = QPolygonF( QRectF( 0, 0, rect().width() * scale, rect().height() * scale ) ); } break; } case Triangle: { shapePolygon << QPointF( 0, rect().height() * scale ); shapePolygon << QPointF( rect().width() * scale, rect().height() * scale ); shapePolygon << QPointF( rect().width() / 2.0 * scale, 0 ); shapePolygon << QPointF( 0, rect().height() * scale ); break; } } QList<QPolygonF> rings; //empty list symbol()->startRender( context.renderContext() ); symbol()->renderPolygon( shapePolygon, &rings, nullptr, context.renderContext() ); symbol()->stopRender( context.renderContext() ); }
void transform(QGraphicsItem *item, const CLTransformation2D* trans, const CLGroup* group) { if (trans != NULL && trans->isSetMatrix()) { QRectF pathRect = item->boundingRect(); QTransform transform( trans->getMatrix2D()[0], trans->getMatrix2D()[1], trans->getMatrix2D()[2], trans->getMatrix2D()[3], trans->getMatrix2D()[4], trans->getMatrix2D()[5] ); QTransform matrix; matrix = matrix.translate(pathRect.x(), pathRect.y()); matrix = matrix.inverted(); matrix = matrix * transform; QTransform translate; translate = translate.translate(pathRect.x(), pathRect.y()); matrix = matrix * translate; item->setTransform(matrix, true); } else if (group != NULL && group->isSetMatrix()) { QRectF pathRect = item->boundingRect(); QTransform transform( group->getMatrix2D()[0], group->getMatrix2D()[1], group->getMatrix2D()[2], group->getMatrix2D()[3], group->getMatrix2D()[4], group->getMatrix2D()[5] ); QTransform matrix; matrix = matrix.translate(pathRect.x(), pathRect.y()); matrix = matrix.inverted(); matrix = matrix * transform; QTransform translate; translate = translate.translate(pathRect.x(), pathRect.y()); matrix = matrix * translate; item->setTransform(matrix, true); } }
/*! \brief Render the plot to a given rectangle ( f.e QPrinter, QSvgRenderer ) \param plot Plot widget to be rendered \param painter Painter \param plotRect Bounding rectangle for the plot */ void QwtPolarRenderer::render( QwtPolarPlot *plot, QPainter *painter, const QRectF &plotRect ) const { if ( plot == NULL || painter == NULL || !painter->isActive() || !plotRect.isValid() || plot->size().isNull() ) { return; } d_data->plot = plot; /* The layout engine uses the same methods as they are used by the Qt layout system. Therefore we need to calculate the layout in screen coordinates and paint with a scaled painter. */ QTransform transform; transform.scale( double( painter->device()->logicalDpiX() ) / plot->logicalDpiX(), double( painter->device()->logicalDpiY() ) / plot->logicalDpiY() ); const QRectF layoutRect = transform.inverted().mapRect( plotRect ); QwtPolarLayout *layout = plot->plotLayout(); // All paint operations need to be scaled according to // the paint device metrics. QwtPolarLayout::Options layoutOptions = QwtPolarLayout::IgnoreScrollbars | QwtPolarLayout::IgnoreFrames; layout->activate( plot, layoutRect, layoutOptions ); painter->save(); painter->setWorldTransform( transform, true ); painter->save(); renderTitle( painter, layout->titleRect() ); painter->restore(); painter->save(); renderLegend( painter, layout->legendRect() ); painter->restore(); const QRectF &canvasRect = layout->canvasRect(); painter->save(); painter->setClipRect( canvasRect ); plot->drawCanvas( painter, canvasRect ); painter->restore(); painter->restore(); layout->invalidate(); d_data->plot = NULL; }
void KarbonBooleanCommand::redo() { if (! d->resultingPath) { // transform input pathes to global coordinates QPainterPath pa = d->pathA->absoluteTransformation(0).map(d->pathA->outline()); QPainterPath pb = d->pathB->absoluteTransformation(0).map(d->pathB->outline()); QPainterPath pr; switch (d->operation) { case Intersection: pr = pa.intersected(pb); break; case Subtraction: pr = pa.subtracted(pb); break; case Exclusion: pr = pa.subtracted(pb); pr.addPath(pb.subtracted(pa)); break; case Union: pr = pa.united(pb); break; } QTransform transformationA = d->pathA->absoluteTransformation(0); // transform resulting path to local coordinate system of input path A pr = transformationA.inverted().map(pr); // create a path shape from the resulting path in local coordinates d->resultingPath = KoPathShape::createShapeFromPainterPath(pr); d->resultingPath->setStroke(d->pathA->stroke()); d->resultingPath->setBackground(d->pathA->background()); d->resultingPath->setShapeId(d->pathA->shapeId()); // the created shape has a transformation applied so we have to // apply the original transformation instead of replacing with it d->resultingPath->applyAbsoluteTransformation(transformationA); d->resultingPath->setName(d->pathA->name()); d->resultingPath->setZIndex(d->pathA->zIndex()); d->resultingPath->setFillRule(d->pathA->fillRule()); KoShapeGroup * group = dynamic_cast<KoShapeGroup*>(d->pathA->parent()); if (group) { QList<KoShape*> children; d->resultParentCmd = new KoShapeGroupCommand(group, children << d->resultingPath, this); } } if (d->shapeBasedDocument) { if (d->resultParent) d->resultParent->addShape(d->resultingPath); d->shapeBasedDocument->addShape(d->resultingPath); } KUndo2Command::redo(); d->isExecuted = true; }
void AbstractContent::slotSaveAs() { // make up the default save path (stored as 'Fotowall/ExportDir') QSettings s; QString defaultSavePath = tr("Unnamed %1.png").arg(QDate::currentDate().toString()); if (s.contains("Fotowall/ExportDir")) defaultSavePath.prepend(s.value("Fotowall/ExportDir").toString() + QDir::separator()); // ask the file name, validate it, store back to settings QString imgFilePath = QFileDialog::getSaveFileName(0, tr("Choose the Image file"), defaultSavePath, tr("Images (*.jpeg *.jpg *.png *.bmp *.tif *.tiff)")); if (imgFilePath.isNull()) return; s.setValue("Fotowall/ExportDir", QFileInfo(imgFilePath).absolutePath()); if (QFileInfo(imgFilePath).suffix().isEmpty()) imgFilePath += ".png"; // find out the Transform chain to mirror a rotated item QRectF sceneRectF = mapToScene(boundingRect()).boundingRect(); QTransform tFromItem = transform() * QTransform(1, 0, 0, 1, pos().x(), pos().y()); QTransform tFromPixmap = QTransform(1, 0, 0, 1, sceneRectF.left(), sceneRectF.top()); QTransform tItemToPixmap = tFromItem * tFromPixmap.inverted(); // render on the image int iHeight = (int)sceneRectF.height(); if (m_mirrorItem) iHeight += (int)m_mirrorItem->boundingRect().height(); QImage image((int)sceneRectF.width(), iHeight, QImage::Format_ARGB32); image.fill(Qt::transparent); // enable hi-q rendering bool prevHQ = RenderOpts::HQRendering; RenderOpts::HQRendering = true; // draw the transformed item onto the pixmap QPainter p(&image); p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true); p.setTransform(tItemToPixmap); paint(&p, 0, 0); if (m_mirrorItem) { p.resetTransform(); p.translate(0, (qreal)((int)sceneRectF.height())); m_mirrorItem->paint(&p, 0, 0); } p.end(); RenderOpts::HQRendering = prevHQ; // save image and check errors if (!image.save(imgFilePath) || !QFile::exists(imgFilePath)) { QMessageBox::warning(0, tr("File Error"), tr("Error saving the Object to '%1'").arg(imgFilePath)); return; } }
void KarbonBooleanCommand::redo() { if (! d->resultingPath) { QPainterPath pa = d->pathA->absoluteTransformation(0).map(d->pathA->outline()); QPainterPath pb = d->pathB->absoluteTransformation(0).map(d->pathB->outline()); QPainterPath pr; switch (d->operation) { case Intersection: pr = pa.intersected(pb); break; case Subtraction: pr = pa.subtracted(pb); break; case Exclusion: pr = pa.subtracted(pb); pr.addPath(pb.subtracted(pa)); break; case Union: pr = pa.united(pb); break; } QTransform transformation = d->pathA->transformation(); pr = transformation.inverted().map(pr); d->resultingPath = KoPathShape::createShapeFromPainterPath(pr); d->resultingPath->setBorder(d->pathA->border()); d->resultingPath->setBackground(d->pathA->background()); d->resultingPath->setShapeId(d->pathA->shapeId()); d->resultingPath->setTransformation(transformation); d->resultingPath->setName(d->pathA->name()); d->resultingPath->setZIndex(d->pathA->zIndex()); d->resultingPath->setFillRule(d->pathA->fillRule()); KoShapeGroup * group = dynamic_cast<KoShapeGroup*>(d->pathA->parent()); if (group) { QList<KoShape*> children; d->resultParentCmd = new KoShapeGroupCommand(group, children << d->resultingPath, this); } } if (d->controller) { if (d->resultParent) d->resultParent->addShape(d->resultingPath); d->controller->addShape(d->resultingPath); } QUndoCommand::redo(); d->isExecuted = true; }
void MapView::updateSceneRect(const QRectF &sceneRect, const QTransform &transform) { // Calculate a scene rect that includes a margin on the edge of the map, // taking into account the scale const QSize maxSize = maximumViewportSize(); const qreal marginWidth = maxSize.width() * 0.9; const qreal marginHeight = maxSize.height() * 0.9; QRectF viewRect = transform.mapRect(sceneRect); viewRect.adjust(-marginWidth, -marginHeight, marginWidth, marginHeight); const QRectF expandedSceneRect = transform.inverted().mapRect(viewRect); setSceneRect(expandedSceneRect); }
KisPerspectiveTransformWorker::KisPerspectiveTransformWorker(KisPaintDeviceSP dev, QPointF center, double aX, double aY, double distance, KoUpdaterPtr progress) : m_dev(dev), m_progressUpdater(progress) { QMatrix4x4 m; m.rotate(180. * aX / M_PI, QVector3D(1, 0, 0)); m.rotate(180. * aY / M_PI, QVector3D(0, 1, 0)); QTransform project = m.toTransform(distance); QTransform t = QTransform::fromTranslate(center.x(), center.y()); QTransform forwardTransform = t.inverted() * project * t; init(forwardTransform); }
static bool intersect_rect(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode, const QTransform &deviceTransform, const void *intersectData) { const QRectF sceneRect = *static_cast<const QRectF *>(intersectData); QRectF brect = item->boundingRect(); _q_adjustRect(&brect); // ### Add test for this (without making things slower?) Q_UNUSED(exposeRect); bool keep = true; const QGraphicsItemPrivate *itemd = QGraphicsItemPrivate::get(item); if (itemd->itemIsUntransformable()) { // Untransformable items; map the scene rect to item coordinates. const QTransform transform = item->deviceTransform(deviceTransform); QRectF itemRect = (deviceTransform * transform.inverted()).mapRect(sceneRect); if (mode == Qt::ContainsItemShape || mode == Qt::ContainsItemBoundingRect) keep = itemRect.contains(brect) && itemRect != brect; else keep = itemRect.intersects(brect); if (keep && (mode == Qt::ContainsItemShape || mode == Qt::IntersectsItemShape)) { QPainterPath itemPath; itemPath.addRect(itemRect); keep = QGraphicsSceneIndexPrivate::itemCollidesWithPath(item, itemPath, mode); } } else { Q_ASSERT(!itemd->dirtySceneTransform); const QRectF itemSceneBoundingRect = itemd->sceneTransformTranslateOnly ? brect.translated(itemd->sceneTransform.dx(), itemd->sceneTransform.dy()) : itemd->sceneTransform.mapRect(brect); if (mode == Qt::ContainsItemShape || mode == Qt::ContainsItemBoundingRect) keep = sceneRect != brect && sceneRect.contains(itemSceneBoundingRect); else keep = sceneRect.intersects(itemSceneBoundingRect); if (keep && (mode == Qt::ContainsItemShape || mode == Qt::IntersectsItemShape)) { QPainterPath rectPath; rectPath.addRect(sceneRect); if (itemd->sceneTransformTranslateOnly) rectPath.translate(-itemd->sceneTransform.dx(), -itemd->sceneTransform.dy()); else rectPath = itemd->sceneTransform.inverted().map(rectPath); keep = QGraphicsSceneIndexPrivate::itemCollidesWithPath(item, rectPath, mode); } } return keep; }
void MirrorItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * /*widget*/) { // TODO: real HQ rendering, skipping the pixmap (better result)! // generate Reflection pixmap, if needed if (m_dirty || m_pixmap.isNull() || RenderOpts::HQRendering) { // change pixmap size to match the bounding rect if (m_pixmap.size() != m_boundingRect.size().toSize()) m_pixmap = QPixmap(m_boundingRect.width(), m_boundingRect.height()); // clear pixmap m_pixmap.fill(Qt::transparent); // find out the Transform chain to mirror a rotated item QRectF sceneRectF = m_source->mapToScene(m_source->boundingRect()).boundingRect(); QTransform tFromItem = m_source->transform() * QTransform(1, 0, 0, 1, m_source->pos().x(), m_source->pos().y()); QTransform tFromPixmap = QTransform(1, 0, 0, -1.0, sceneRectF.left(), sceneRectF.bottom()); QTransform tItemToPixmap = tFromItem * tFromPixmap.inverted(); // draw the transformed item onto the pixmap QPainter p(&m_pixmap); p.setRenderHint(QPainter::Antialiasing, true); p.setTransform(tItemToPixmap, true); m_source->paint(&p, 0, 0); p.end(); // add a linear alpha channel to the image QPixmap alphaPixmap(m_pixmap.size()); QPainter alphaPainter(&alphaPixmap); QLinearGradient alphaGradient(0, 0, 0, alphaPixmap.height()); alphaGradient.setColorAt(0.0 , QColor(128, 128, 128)); alphaGradient.setColorAt(0.50, QColor( 32, 32, 32)); alphaGradient.setColorAt(1.0 , QColor( 0, 0, 0)); alphaPainter.fillRect(alphaPixmap.rect(), alphaGradient); alphaPainter.end(); m_pixmap.setAlphaChannel(alphaPixmap); // reset dirty m_dirty = false; } // draw the reflection pixmap if (!option) painter->drawPixmap(0, 0, m_pixmap); else painter->drawPixmap(option->rect, m_pixmap, option->rect); }
QImage minigis::svgGenerator(QSvgRenderer &render, const QPointF &p, const qreal &ang, const QString &cls, const qreal &svgSize, const quint8 &anchorX, const quint8 &anchorY, QPointF *start) { QRectF rgn = svgRect(render, cls, p, svgSize); QPointF mid(rgn.left(), rgn.top()); if (anchorX != 0 || anchorY != 0) { QPointF anchor(rgn.width() * anchorX * 0.01, rgn.height() * anchorY * 0.01); rgn.moveTopLeft(rgn.topLeft() - anchor); mid = QPointF(rgn.left() + anchor.x(), rgn.top() + anchor.y()); } QTransform tr; tr.translate(mid.x(), mid.y()).rotate(ang).translate(-mid.x(), -mid.y()); return svgGenerator(render, cls, rgn, tr, tr.inverted(), start); }
/*! Draw a text document into a rectangle \param painter Painter \param rect Traget rectangle \param flags Alignments/Text flags, see QPainter::drawText() \param text Text document */ void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect, int flags, const QTextDocument &text ) { QTextDocument *txt = text.clone(); painter->save(); QRectF unscaledRect = rect; if ( painter->font().pixelSize() < 0 ) { const QSize res = qwtScreenResolution(); const QPaintDevice *pd = painter->device(); if ( pd->logicalDpiX() != res.width() || pd->logicalDpiY() != res.height() ) { QTransform transform; transform.scale( res.width() / double( pd->logicalDpiX() ), res.height() / double( pd->logicalDpiY() )); painter->setWorldTransform( transform, true ); unscaledRect = transform.inverted().mapRect(rect); } } txt->setDefaultFont( painter->font() ); txt->setPageSize( QSizeF( unscaledRect.width(), QWIDGETSIZE_MAX ) ); QAbstractTextDocumentLayout* layout = txt->documentLayout(); const double height = layout->documentSize().height(); double y = unscaledRect.y(); if ( flags & Qt::AlignBottom ) y += ( unscaledRect.height() - height ); else if ( flags & Qt::AlignVCenter ) y += ( unscaledRect.height() - height ) / 2; QAbstractTextDocumentLayout::PaintContext context; context.palette.setColor( QPalette::Text, painter->pen().color() ); painter->translate( unscaledRect.x(), y ); layout->draw( painter, context ); painter->restore(); delete txt; }
void AbstractContent::slotSaveAs() { QString fileName = QFileDialog::getSaveFileName(0, tr("Choose the Image file"), QString(), tr("Images (*.jpeg *.jpg *.png *.bmp *.tif *.tiff)")); if (fileName.isNull()) return; if (QFileInfo(fileName).suffix().isEmpty()) fileName += ".png"; // find out the Transform chain to mirror a rotated item QRectF sceneRectF = mapToScene(boundingRect()).boundingRect(); QTransform tFromItem = transform() * QTransform(1, 0, 0, 1, pos().x(), pos().y()); QTransform tFromPixmap = QTransform(1, 0, 0, 1, sceneRectF.left(), sceneRectF.top()); QTransform tItemToPixmap = tFromItem * tFromPixmap.inverted(); // render on the image int iHeight = (int)sceneRectF.height(); if (m_mirrorItem) iHeight += (int)m_mirrorItem->boundingRect().height(); QImage image((int)sceneRectF.width(), iHeight, QImage::Format_ARGB32); image.fill(Qt::transparent); // enable hi-q rendering bool prevHQ = RenderOpts::HQRendering; RenderOpts::HQRendering = true; // draw the transformed item onto the pixmap QPainter p(&image); p.setRenderHint(QPainter::Antialiasing, true); p.setRenderHint(QPainter::SmoothPixmapTransform, true); p.setTransform(tItemToPixmap); paint(&p, 0, 0); if (m_mirrorItem) { p.resetTransform(); p.translate(0, (qreal)((int)sceneRectF.height())); m_mirrorItem->paint(&p, 0, 0); } p.end(); RenderOpts::HQRendering = prevHQ; // save image and check errors if (!image.save(fileName) || !QFile::exists(fileName)) { QMessageBox::warning(0, tr("File Error"), tr("Error saving the Object to '%1'").arg(fileName)); return; } }
void KisPerspectiveTransformWorker::init(const QTransform &transform) { m_isIdentity = transform.isIdentity(); m_forwardTransform = transform; m_backwardTransform = transform.inverted(); if (m_dev) { m_srcRect = m_dev->exactBounds(); QPolygonF dstClipPolygonUnused; fillParams(m_srcRect, m_dev->defaultBounds()->bounds(), &m_dstRegion, &dstClipPolygonUnused); } }
void ImageView::paint(QPainter &p, const QSizeF& sz, double zoom, const QPointF& origin) { if (!imageSize().isEmpty()) { QTransform tr = viewTransform(sz, zoom, origin); QTransform invTr = tr.inverted(); QRectF wR = invTr.mapRect(QRectF(QPoint(0,0), sz)); QRectF R = wR.intersected(QRectF(QPoint(0,0), imageSize())); if (!R.isEmpty()) { p.save(); p.setTransform(tr, true); if (m_handler) { m_handler->draw(this, p, R, image()); } else { draw(p, R, image()); } p.restore(); } } }
void Node:: reactToPossibleConnection(PortType reactingPortType, NodePortType reactingDataType, QPointF const &scenePoint) { QTransform const t = _nodeGraphicsObject->sceneTransform(); QPointF p = t.inverted().map(scenePoint); _nodeGeometry.setDraggingPosition(p); _nodeGraphicsObject->update(); _nodeState.setReaction(NodeState::REACTING, reactingPortType, reactingDataType); }
/*! \brief Convenience function. * */ void TrackSpiralArcSpiral::setLocalPointAndHeading(const QPointF &point, double hdg, bool isStart) { while (hdg <= -180.0) { hdg += 360.0; } while (hdg > 180.0) { hdg -= 360.0; } if (isStart) { // Local to internal (Parameters are given in internal coordinates) // // QPointF deltaPos(getLocalTransform().inverted().map(point) /* - getPoint(getSStart())*/); // getPoint(s_) == 0 by definition double deltaHeading(hdg - heading()); QTransform trafo; trafo.rotate(deltaHeading); pa_->setEndHeadingDeg(pa_->getEndHeadingRad() * 360.0 / (2.0 * M_PI) - deltaHeading); pa_->setEndPoint(trafo.inverted().map(pa_->pEnd_ - deltaPos)); pa_->init(); applyParameters(); // Set local transform // // setLocalTransform(point, hdg); } else { // Local to internal (Parameters are given in internal coordinates) // // pa_->pEnd_ = getLocalTransform().inverted().map(point); pa_->headingEnd_ = (hdg - getLocalHeading(getSStart())) * 2.0 * M_PI / 360.0; pa_->init(); applyParameters(); } }
bool Object::exportX( int frameStart, int frameEnd, QTransform view, QSize exportSize, QString filePath, bool antialiasing ) { QSettings settings( "Pencil", "Pencil" ); int page; page = 0; for ( int j = frameStart; j <= frameEnd; j = j + 15 ) { QImage xImg( QSize( 2300, 3400 ), QImage::Format_ARGB32_Premultiplied ); QPainter xPainter( &xImg ); xPainter.fillRect( 0, 0, 2300, 3400, Qt::white ); int y = j - 1; for ( int i = j; i < 15 + page * 15 && i <= frameEnd; i++ ) { QRect source = QRect( QPoint( 0, 0 ), exportSize ); QRect target = QRect( QPoint( ( y % 3 ) * 800 + 30, ( y / 3 ) * 680 + 50 - page * 3400 ), QSize( 640, 480 ) ); QTransform thumbView = view * RectMapTransform( source, target ); xPainter.setWorldTransform( thumbView ); xPainter.setClipRegion( thumbView.inverted().map( QRegion( target ) ) ); paintImage( xPainter, i, false, antialiasing ); xPainter.resetMatrix(); xPainter.setClipping( false ); xPainter.setPen( Qt::black ); xPainter.setFont( QFont( "helvetica", 50 ) ); xPainter.drawRect( target ); xPainter.drawText( QPoint( ( y % 3 ) * 800 + 35, ( y / 3 ) * 680 + 65 - page * 3400 ), QString::number( i ) ); y++; } if ( filePath.endsWith( ".jpg", Qt::CaseInsensitive ) ) { filePath.chop( 4 ); } if ( !xImg.save( filePath + QString::number( page ) + ".jpg", "JPG", 60 ) ) { return false; } page++; } return true; }
static bool intersect_point(const QGraphicsItem *item, const QRectF &exposeRect, Qt::ItemSelectionMode mode, const QTransform &deviceTransform, const void *intersectData) { const QPointF scenePoint = *static_cast<const QPointF *>(intersectData); QRectF brect = item->boundingRect(); _q_adjustRect(&brect); // ### Add test for this (without making things slower?) Q_UNUSED(exposeRect); bool keep = false; const QGraphicsItemPrivate *itemd = QGraphicsItemPrivate::get(item); if (itemd->itemIsUntransformable()) { // Untransformable items; map the scene point to item coordinates. const QTransform transform = item->deviceTransform(deviceTransform); QPointF itemPoint = (deviceTransform * transform.inverted()).map(scenePoint); keep = brect.contains(itemPoint); if (keep && (mode == Qt::ContainsItemShape || mode == Qt::IntersectsItemShape)) { QPainterPath pointPath; pointPath.addRect(QRectF(itemPoint, QSizeF(1, 1))); keep = QGraphicsSceneIndexPrivate::itemCollidesWithPath(item, pointPath, mode); } } else { Q_ASSERT(!itemd->dirtySceneTransform); QRectF sceneBoundingRect = itemd->sceneTransformTranslateOnly ? brect.translated(itemd->sceneTransform.dx(), itemd->sceneTransform.dy()) : itemd->sceneTransform.mapRect(brect); keep = sceneBoundingRect.intersects(QRectF(scenePoint, QSizeF(1, 1))); if (keep && (mode == Qt::ContainsItemShape || mode == Qt::IntersectsItemShape)) { QPointF p = itemd->sceneTransformTranslateOnly ? QPointF(scenePoint.x() - itemd->sceneTransform.dx(), scenePoint.y() - itemd->sceneTransform.dy()) : itemd->sceneTransform.inverted().map(scenePoint); keep = item->contains(p); } } return keep; }
void HbInputVkbWidgetPrivate::captureScreenshot() { Q_Q(HbInputVkbWidget); if (!mScreenshotWidget) { mScreenshotWidget = new HbInputScreenshotWidget(); mScreenshotWidget->setZValue(q->zValue()); mScreenshotWidget->setGeometry(q->geometry()); q->mainWindow()->scene()->addItem(mScreenshotWidget); } QPointF position = q->pos(); QRectF rect = QRectF(position.x(), position.y() + mCloseHandleHeight, q->boundingRect().width(), q->boundingRect().height() - mCloseHandleHeight); QTransform rotateTrans; rotateTrans = q->mainWindow()->viewportTransform(); QRectF transRect = rotateTrans.mapRect(rect); QPixmap pixmap; pixmap = QPixmap::grabWidget(q->mainWindow(), (int)transRect.x(), (int)transRect.y(), (int)transRect.width(), (int)transRect.height()); pixmap = pixmap.transformed(rotateTrans.inverted()); mScreenshotWidget->setScreenshot(pixmap); }
void svg_renderer::update_cache_item (const renderable_item *item, const render_cache_id &cache_id, const QTransform &transform, renderer_config &cfg, int total_x, int total_y) { int block_size = rendered_items_cache::block_pixel_size (); SkBitmap bitmap; bitmap.setConfig (SkBitmap::kARGB_8888_Config, block_size * total_x, block_size * total_y); bitmap.allocPixels (); SkBitmapDevice device (bitmap); SkCanvas canvas (&device); canvas.drawColor (SK_ColorTRANSPARENT, SkXfermode::kSrc_Mode); QRectF local_rect = cache_id.pixel_rect (transform); QTransform last_inverted = transform.inverted (); QPointF last_pos_local = last_inverted.map (QPointF (0, 0)); QPointF cur_pos_local = last_inverted.map (QPointF (local_rect.x (), local_rect.y ())); QPointF diff = -cur_pos_local + last_pos_local; QTransform pixmap_transform = QTransform (transform).translate (diff.x (), diff.y ()); renderer_state state (QRect (0, 0, block_size * total_x, block_size * total_y), pixmap_transform); draw_item (item, canvas, state, cfg); if (m_queue->is_interrupted ()) return; if (total_x == total_y && total_x == 1) m_cache->add_bitmap (cache_id, bitmap, cfg.use_new_cache ()); else { for (int i = 0; i < total_x; i++) for (int j = 0; j < total_y; j++) { render_cache_id cur_id (cache_id.x () + i, cache_id.y () + j, cache_id.object_type ()); SkBitmap bitmap_part; DEBUG_ASSERT (bitmap.extractSubset (&bitmap_part, SkIRect::MakeXYWH (i * block_size, j * block_size, block_size, block_size))); m_cache->add_bitmap (cur_id, bitmap_part, cfg.use_new_cache ()); } } }
static QTransform preciselyInverted( const QTransform& transform ) { QTransform inverted; switch ( transform.type() ) { case QTransform::TxNone: break; case QTransform::TxTranslate: inverted.translate( -transform.dx(), -transform.dy() ); break; case QTransform::TxScale: inverted.scale( 1.0 / transform.m11(), 1.0 / transform.m22() ); inverted.translate( -transform.dx(), -transform.dy() ); break; default: inverted = transform.inverted(); } return inverted; }