inline QRectF scaledBoundingRect( double sx, double sy, bool scalePens ) const { if ( sx == 1.0 && sy == 1.0 ) return d_boundingRect; QTransform transform; transform.scale( sx, sy ); QRectF rect; if ( scalePens && d_scalablePen ) { rect = transform.mapRect( d_boundingRect ); } else { rect = transform.mapRect( d_pointRect ); const double l = qAbs( d_pointRect.left() - d_boundingRect.left() ); const double r = qAbs( d_pointRect.right() - d_boundingRect.right() ); const double t = qAbs( d_pointRect.top() - d_boundingRect.top() ); const double b = qAbs( d_pointRect.bottom() - d_boundingRect.bottom() ); rect.adjust( -l, -t, r, b ); } return rect; }
void DisplayGroupController::scale(const QSizeF& factor) { const QTransform t = QTransform::fromScale(factor.width(), factor.height()); for (ContentWindowPtr window : _group.getContentWindows()) window->setCoordinates(t.mapRect(window->getCoordinates())); _group.setCoordinates(t.mapRect(_group.getCoordinates())); }
// draw shapes // NOTE: if drawing many shapes of same size, use drawGlyphs void ScenePainter::drawRectangles(double *x, double *y, double *w, double *h, int n) { QTransform tform = transform(); QPen pen = this->pen(); for (int i = 0; i < n; i++) { QPointF point = QPointF(x[i], y[i]); QRectF rect = tform.mapRect(QRectF(point, QSizeF(w[i], h[i]))); if (!tform.isRotating()) { STORE_INDEX(_scene->addRect(tform.mapRect(rect), pen)); } else STORE_INDEX(_scene->addPolygon(tform.map(QPolygonF(rect)))); } }
void CanvasMode_EditArc::mouseMoveEvent(QMouseEvent *m) { const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); m->accept(); double newX = mousePointDoc.x(); double newY = mousePointDoc.y(); if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed()) { PageItem *currItem = m_doc->m_Selection->itemAt(0); QTransform itemMatrix = currItem->getTransform(); QPointF sPoint = currItem->PoLine.pointQF(0); QPointF smPoint = itemMatrix.map(sPoint); QLineF stLinA = QLineF(smPoint, QPointF(m_Mxp, m_Myp)); QLineF stLinM = QLineF(smPoint, QPointF(newX, newY)); double deltaAngle = stLinM.angle() - stLinA.angle(); QPainterPath pp; if (m_arcPoint == useControlStart) m_startAngle += deltaAngle; else if (m_arcPoint == useControlSweep) m_endAngle += deltaAngle; else if (m_arcPoint == useControlHeight) m_heightPoint = QPointF(m_heightPoint.x(), m_heightPoint.y() + (newY - m_Myp)); else if (m_arcPoint == useControlWidth) m_widthPoint = QPointF(m_widthPoint.x() + (newX - m_Mxp), m_widthPoint.y()); double nSweep = m_endAngle - m_startAngle; if (nSweep < 0) nSweep += 360; double nWidth = sPoint.x() - m_widthPoint.x(); double nHeight = sPoint.y() - m_heightPoint.y(); if ((nWidth > 0) && (nHeight > 0)) { pp.moveTo(sPoint); pp.arcTo(QRectF(sPoint.x() - nWidth, sPoint.y() - nHeight, nWidth * 2, nHeight * 2), m_startAngle, nSweep); pp.closeSubpath(); FPointArray ar; ar.fromQPainterPath(pp); if (m_arcPoint == useControlStart) { m_startPoint = ar.pointQF(2); QLineF stLinA = QLineF(smPoint, itemMatrix.map(m_startPoint)); m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle()); } else if (m_arcPoint == useControlSweep) { m_endPoint = ar.pointQF(ar.size() - 4); QLineF stLinA = QLineF(smPoint, itemMatrix.map(m_endPoint)); m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle()); } QLineF res = QLineF(m_centerPoint, m_startPoint); QLineF swe = QLineF(m_centerPoint, m_endPoint); vectorDialog->setValues(res.angle(), swe.angle(), nHeight * 2, nWidth * 2); blockUpdateFromItem(true); currItem->update(); blockUpdateFromItem(false); m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-nWidth, -nHeight, nWidth, nHeight)); } } m_Mxp = newX; m_Myp = newY; }
/** * @brief cwCaptureViewport::updateBoundingBox * * This will update the bounding box for the viewport capture. * * This is useful for displaying annotation, and interactions ontop of the item * in qml. */ void cwCaptureViewport::updateBoundingBox() { QTransform transform = previewItem()->transform(); QRectF paperRect = previewItem()->boundingRect(); QRectF boundingBoxRect = transform.mapRect(paperRect); setBoundingBox(boundingBoxRect); }
void QgsComposerPicture::setPictureRotation( double r ) { double oldRotation = mPictureRotation; mPictureRotation = r; if ( mResizeMode == Zoom ) { //find largest scaling of picture with this rotation which fits in item QSizeF currentPictureSize = pictureSize(); QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), mPictureRotation ); mPictureWidth = rotatedImageRect.width(); mPictureHeight = rotatedImageRect.height(); update(); } else if ( mResizeMode == ZoomResizeFrame ) { QSizeF currentPictureSize = pictureSize(); QRectF oldRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() ); //calculate actual size of image inside frame QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), oldRotation ); //rotate image rect by new rotation and get bounding box QTransform tr; tr.rotate( mPictureRotation ); QRectF newRect = tr.mapRect( QRectF( 0, 0, rotatedImageRect.width(), rotatedImageRect.height() ) ); //keep the center in the same location newRect.moveCenter( oldRect.center() ); QgsComposerItem::setSceneRect( newRect ); emit itemChanged(); } emit pictureRotationChanged( mPictureRotation ); }
void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, const QRectF &sourceRect) { QRectF target = targetRect; if (target.isNull()) { QPaintDevice *dev = p->device(); QRectF deviceRect(0, 0, dev->width(), dev->height()); if (deviceRect.isNull()) { if (sourceRect.isNull()) target = QRectF(QPointF(0, 0), size()); else target = QRectF(QPointF(0, 0), sourceRect.size()); } else { target = deviceRect; } } QRectF source = sourceRect; if (source.isNull()) source = viewBox(); if (source != target && !source.isNull()) { QTransform transform; transform.scale(target.width() / source.width(), target.height() / source.height()); QRectF c2 = transform.mapRect(source); p->translate(target.x() - c2.x(), target.y() - c2.y()); p->scale(target.width() / source.width(), target.height() / source.height()); } }
void NodeGraph::wheelEventInternal(bool ctrlDown,double delta) { double scaleFactor = pow( NATRON_WHEEL_ZOOM_PER_DELTA, delta); QTransform transfo = transform(); double currentZoomFactor = transfo.mapRect( QRectF(0, 0, 1, 1) ).width(); double newZoomfactor = currentZoomFactor * scaleFactor; if ((newZoomfactor < 0.01 && scaleFactor < 1.) || (newZoomfactor > 50 && scaleFactor > 1.)) { return; } if (ctrlDown && _imp->_magnifiedNode) { if (!_imp->_magnifOn) { _imp->_magnifOn = true; _imp->_nodeSelectedScaleBeforeMagnif = _imp->_magnifiedNode->scale(); } _imp->_magnifiedNode->setScale_natron(_imp->_magnifiedNode->scale() * scaleFactor); } else { _imp->_accumDelta += delta; if (std::abs(_imp->_accumDelta) > 60) { scaleFactor = pow( NATRON_WHEEL_ZOOM_PER_DELTA, _imp->_accumDelta ); // setSceneRect(NATRON_SCENE_MIN,NATRON_SCENE_MIN,NATRON_SCENE_MAX,NATRON_SCENE_MAX); scale(scaleFactor,scaleFactor); _imp->_accumDelta = 0; } _imp->_refreshOverlays = true; } }
void GraphicsContext::beginTransparencyLayer(float opacity) { if (paintingDisabled()) return; int x, y, w, h; x = y = 0; QPainter *p = m_data->p(); const QPaintDevice *device = p->device(); w = device->width(); h = device->height(); QRectF clip = p->clipPath().boundingRect(); bool ok; QTransform transform = p->transform().inverted(&ok); if (ok) { QRectF deviceClip = transform.mapRect(clip); x = int(qBound(qreal(0), deviceClip.x(), (qreal)w)); y = int(qBound(qreal(0), deviceClip.y(), (qreal)h)); w = int(qBound(qreal(0), deviceClip.width(), (qreal)w) + 2); h = int(qBound(qreal(0), deviceClip.height(), (qreal)h) + 2); } TransparencyLayer * layer = new TransparencyLayer(m_data->p(), QRect(x, y, w, h)); layer->opacity = opacity; m_data->layers.push(layer); }
void KisShapeSelectionModel::add(KoShape *child) { if (!m_shapeSelection) return; if (m_shapeMap.contains(child)) return; child->setStroke(0); child->setBackground( QSharedPointer<KoShapeBackground>(0)); m_shapeMap.insert(child, child->boundingRect()); m_shapeSelection->shapeManager()->addShape(child); QRect updateRect = child->boundingRect().toAlignedRect(); if (m_image.isValid()) { QTransform matrix; matrix.scale(m_image->xRes(), m_image->yRes()); updateRect = matrix.mapRect(updateRect); } if (m_shapeMap.count() == 1) { // The shape is the first one, so the shape selection just got created // Pixel selection provides no longer the datamanager of the selection // so update the whole selection requestUpdate(QRect()); } else { requestUpdate(updateRect); } }
ITank::ITank(TankInfo tank_info, QString nick, int rank, ColorTeam color_team):QGraphicsObject() { _tank_info = tank_info; _nick = nick; _rank = rank; _color_team = color_team; _max_live = _current_live = tank_info._live; _max_mana = _current_mana = _tank_info._mana; _base_armor = _tank_info._armor; _base_speed = _tank_info._speed; _base_live_regeneration = _tank_info._live_regeneration; _base_mana_regeneration = tank_info._mana_regeneration; _dead_time = MECH_DEAD_TIME_FOR_LEVEL; _is_enemy = false; _level = 1; _updates_available = 1; _current_experience = 0; _next_level_experience = MECH_INIT_NEXT_LEVEL_EXPERIENCE; _counter_millisec = 0; _animation_dead = getListOfPixmapFromStripImage(":/gt/sprites/tank_explotion.png",160); _frame_animation_dead = 0; _animation_level_up = getListOfPixmapFromStripImage(":/gt/sprites/tank_level_up.png",100); _frame_animation_level_up = 39; QTransform transformation; transformation.translate(-80, -80); _default_rect = transformation.mapRect(QRect(0, 0, 160, 160)); _mini_map_tank = new QGraphicsPixmapItem(QPixmap(QString(":/gt/sprites/mini_map_tank_%1.png").arg(color_team))); _mini_map_tank->setTransformationMode(Qt::SmoothTransformation); _mini_map_tank->setTransformOriginPoint(_mini_map_tank->boundingRect().width()/2, _mini_map_tank->boundingRect().height()/2+2); _mini_map_tank->setZValue(20); _sound_explode = new SoundEngine(QUrl("qrc:/gt/sounds/explode.mp3"), MECH_MAX_DISTANCE_SOUND, this); _sound_level_up = new SoundEngine(QUrl("qrc:/gt/sounds/level_up.mp3"), MECH_MAX_DISTANCE_SOUND, this); //añade un efecto de sombra ligero al tanque // QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); // shadow->setColor(Qt::black); // shadow->setOffset(0); // shadow->setBlurRadius(5); // setGraphicsEffect(shadow); }
void CanvasMode_EditMeshGradient::mouseReleaseEvent(QMouseEvent *m) { m_canvas->m_viewMode.m_MouseButtonPressed = false; m_canvas->resetRenderMode(); m->accept(); PageItem *currItem = m_doc->m_Selection->itemAt(0); if (currItem->selectedMeshPointX >=0 && currItem->selectedMeshPointY >=0 && UndoManager::undoEnabled()) { ScItemState<QPair<meshPoint,meshPoint> > *ss = new ScItemState<QPair<meshPoint,meshPoint> >(Um::GradPos); ss->set("MOVE_MESH_PATCH"); ss->set("ARRAY",true); ss->set("X",currItem->selectedMeshPointX); ss->set("Y",currItem->selectedMeshPointY); if((*m_old_mesh) == currItem->meshGradientArray[currItem->selectedMeshPointX][currItem->selectedMeshPointY]) { delete ss; ss=NULL; } else ss->setItem(qMakePair(*m_old_mesh,currItem->meshGradientArray[currItem->selectedMeshPointX][currItem->selectedMeshPointY])); if(ss) undoManager->action(currItem,ss); } currItem->update(); QTransform itemMatrix = currItem->getTransform(); m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem->width(), currItem->height())); }
void MapObjectLabel::syncWithMapObject(MapRenderer *renderer) { const bool nameVisible = mObject->isVisible() && !mObject->name().isEmpty(); setVisible(nameVisible); if (!nameVisible) return; const QFontMetricsF metrics(QGuiApplication::font()); QRectF boundingRect = metrics.boundingRect(mObject->name()); boundingRect.translate(-boundingRect.width() / 2, -labelDistance); boundingRect.adjust(-labelMargin*2, -labelMargin, labelMargin*2, labelMargin); QPointF pixelPos = renderer->pixelToScreenCoords(mObject->position()); QRectF bounds = objectBounds(mObject, renderer); // Adjust the bounding box for object rotation QTransform transform; transform.translate(pixelPos.x(), pixelPos.y()); transform.rotate(mObject->rotation()); transform.translate(-pixelPos.x(), -pixelPos.y()); bounds = transform.mapRect(bounds); // Center the object name on the object bounding box QPointF pos((bounds.left() + bounds.right()) / 2, bounds.top()); setPos(pos + mObject->objectGroup()->offset()); if (mBoundingRect != boundingRect) { prepareGeometryChange(); mBoundingRect = boundingRect; } }
void KisCoordinatesConverterTest::testRotation() { KisImageSP image; KisCoordinatesConverter converter; initImage(&image, &converter); QSize widgetSize(1000,500); QRectF testRect(800, 100, 300, 300); converter.setImage(image); converter.setDocumentOffset(QPoint(0,0)); converter.setCanvasWidgetSize(widgetSize); converter.rotate(converter.widgetCenterPoint(), 30); converter.setZoom(1.); QTransform viewportToWidget = converter.viewportToWidgetTransform(); QRectF boundingRect = viewportToWidget.mapRect(testRect); QRectF directRect = converter.viewportToWidget(testRect); QCOMPARE(boundingRect, directRect); QRectF referenceRect(QPointF(742.82,53.5898), QSizeF(409.808,409.808)); #define FUZZY(a,b) ((a)-(b) < 0.01) QVERIFY(FUZZY(boundingRect.top(), referenceRect.top())); QVERIFY(FUZZY(boundingRect.left(), referenceRect.left())); QVERIFY(FUZZY(boundingRect.width(), referenceRect.width())); QVERIFY(FUZZY(boundingRect.height(), referenceRect.height())); }
QPainterPath KisDuplicateOpSettings::brushOutline(const QPointF& pos, KisPaintOpSettings::OutlineMode mode, qreal scale, qreal rotation) const { QPainterPath path; path = KisBrushBasedPaintOpSettings::brushOutline(QPointF(0.0,0.0),KisPaintOpSettings::CursorIsOutline, scale, rotation); QPainterPath copy(path); QRectF rect2 = copy.boundingRect(); if (m_isOffsetNotUptodate) { copy.translate(m_position - pos); } else { copy.translate(-m_offset); } path.addPath(copy); QTransform m; m.scale(0.5,0.5); rect2 = m.mapRect(rect2); path.moveTo(rect2.topLeft()); path.lineTo(rect2.bottomRight()); path.moveTo(rect2.topRight()); path.lineTo(rect2.bottomLeft()); if (mode == CursorIsOutline){ return path.translated(pos); } else { // workaround? //copy.addEllipse(QRectF(0,0,1,1)); return copy.translated(pos); } }
QSize StylePainterMobile::sizeForPainterScale(const QRect& rect) const { qreal scale = painterScale(painter); QTransform scaleTransform = QTransform::fromScale(scale, scale); return scaleTransform.mapRect(rect).size(); }
static inline void qwtDrawPixmapSymbols( QPainter *painter, const QPointF *points, int numPoints, const QwtSymbol &symbol ) { QSize size = symbol.size(); if ( size.isEmpty() ) size = symbol.pixmap().size(); const QTransform transform = painter->transform(); if ( transform.isScaling() ) { const QRect r( 0, 0, size.width(), size.height() ); size = transform.mapRect( r ).size(); } QPixmap pm = symbol.pixmap(); if ( pm.size() != size ) pm = pm.scaled( size ); QPointF pinPoint( 0.5 * size.width(), 0.5 * size.height() ); if ( symbol.isPinPointEnabled() ) pinPoint = symbol.pinPoint(); painter->resetTransform(); for ( int i = 0; i < numPoints; i++ ) { const QPointF pos = transform.map( points[i] ) - pinPoint; QwtPainter::drawPixmap( painter, QRect( pos.toPoint(), pm.size() ), pm ); } }
void CanvasMode_EditArc::applyValues(double start, double end, double height, double width) { PageItem *currItem = m_doc->m_Selection->itemAt(0); PageItem_Arc *item = currItem->asArc(); QPointF mPoint = item->PoLine.pointQF(0); QRectF upRect = QRectF(QPointF(0, 0), QPointF(currItem->width(), currItem->height())).normalized(); QRectF upRect2 = QRectF(mPoint.x() - item->arcWidth / 2.0, mPoint.y() - item->arcHeight / 2.0, item->arcWidth, item->arcHeight); upRect = upRect2.united(upRect); upRect.translate(currItem->xPos(), currItem->yPos()); QTransform bb; bb.scale(height / width, 1.0); QLineF inp = QLineF(QPointF(width / 2.0, height / 2.0), QPointF(width, height / 2.0)); inp.setAngle(start); QLineF res = bb.map(inp); inp.setAngle(end); QLineF ena = bb.map(inp); startAngle = res.angle(); endAngle = ena.angle(); double nSweep = endAngle - startAngle; if (nSweep < 0) nSweep += 360; QPainterPath pp; pp.moveTo(mPoint); pp.arcTo(QRectF(mPoint.x() - width / 2.0, mPoint.y() - height / 2.0, width, height), startAngle, nSweep); pp.closeSubpath(); currItem->PoLine.fromQPainterPath(pp); m_doc->AdjustItemSize(currItem); if(UndoManager::undoEnabled()) { ScItemState<QPair<FPointArray, FPointArray> > *ss = new ScItemState<QPair<FPointArray, FPointArray> >(Um::EditArc,"",Um::IPolygon); FPointArray old = item->PoLine; ss->set("ARC","arc"); ss->set("OLD_WIDTH",item->arcWidth); ss->set("NEW_WIDTH",width); ss->set("OLD_XPOS",item->xPos()); ss->set("OLD_YPOS",item->yPos()); ss->set("OLD_HEIGHT",item->arcHeight); ss->set("NEW_HEIGHT",height); ss->set("OLD_START",item->arcStartAngle); ss->set("NEW_START",startAngle); ss->set("OLD_SWEEP",item->arcSweepAngle); ss->set("NEW_SWEEP",nSweep); ss->setItem(qMakePair(old,item->PoLine)); ss->set("NEW_XPOS",item->xPos()); ss->set("NEW_YPOS",item->yPos()); undoManager->action(currItem,ss); } item->arcStartAngle = startAngle; item->arcSweepAngle = nSweep; item->arcWidth = width; item->arcHeight = height; startPoint = currItem->PoLine.pointQF(2); endPoint = currItem->PoLine.pointQF(currItem->PoLine.size() - 4); centerPoint = currItem->PoLine.pointQF(0); widthPoint = QPointF(centerPoint.x() - item->arcWidth / 2.0, centerPoint.y()); heightPoint = QPointF(centerPoint.x(), centerPoint.y() - item->arcHeight / 2.0); QTransform itemMatrix = currItem->getTransform(); m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem->width(), currItem->height())); }
void ThumbnailProtocol::drawPictureFrame(QPainter *painter, const QPoint ¢erPos, const QImage &image, int frameWidth, QSize imageTargetSize) const { // Scale the image down so it matches the aspect ratio float scaling = 1.0; if ((image.size().width() > imageTargetSize.width()) && (imageTargetSize.width() != 0)) { scaling = float(imageTargetSize.width()) / float(image.size().width()); } QImage frame(imageTargetSize + QSize(frameWidth * 2, frameWidth * 2), QImage::Format_ARGB32); frame.fill(0); float scaledFrameWidth = frameWidth / scaling; QTransform m; m.rotate(qrand() % 17 - 8); // Random rotation ±8° m.scale(scaling, scaling); QRectF frameRect(QPointF(0, 0), QPointF(image.width() + scaledFrameWidth*2, image.height() + scaledFrameWidth*2)); QRect r = m.mapRect(QRectF(frameRect)).toAlignedRect(); QImage transformed(r.size(), QImage::Format_ARGB32); transformed.fill(0); QPainter p(&transformed); p.setRenderHint(QPainter::SmoothPixmapTransform); p.setCompositionMode(QPainter::CompositionMode_Source); p.translate(-r.topLeft()); p.setWorldTransform(m, true); if (isOpaque(image)) { p.setRenderHint(QPainter::Antialiasing); p.setPen(Qt::NoPen); p.setBrush(Qt::white); p.drawRoundedRect(frameRect, scaledFrameWidth / 2, scaledFrameWidth / 2); } p.drawImage(scaledFrameWidth, scaledFrameWidth, image); p.end(); int radius = qMax(frameWidth, 1); QImage shadow(r.size() + QSize(radius * 2, radius * 2), QImage::Format_ARGB32); shadow.fill(0); p.begin(&shadow); p.setCompositionMode(QPainter::CompositionMode_Source); p.drawImage(radius, radius, transformed); p.end(); ImageFilter::shadowBlur(shadow, radius, QColor(0, 0, 0, 128)); r.moveCenter(centerPos); painter->drawImage(r.topLeft() - QPoint(radius / 2, radius / 2), shadow); painter->drawImage(r.topLeft(), transformed); }
void TextObjectEditorHelper::includeDirtyRect(QRectF& rect) { QTransform transform = object->calcTextToMapTransform(); QRectF selection_rect; int line = 0; while (getNextLinesSelectionRect(line, selection_rect)) rectIncludeSafe(rect, transform.mapRect(selection_rect)); }
void CanvasMode_EditSpiral::mouseMoveEvent(QMouseEvent *m) { const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); m->accept(); double newX = mousePointDoc.x(); double newY = mousePointDoc.y(); if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed() && (m_arcPoint != noPointDefined)) { PageItem *currItem = m_doc->m_Selection->itemAt(0); QTransform itemMatrix = currItem->getTransform(); PageItem_Spiral *item = currItem->asSpiral(); QPointF sPoint; if (m_arcPoint == useControlStart) sPoint = getSegment(m_startAngle); else if (m_arcPoint == useControlEnd) sPoint = getSegment(m_endAngle); QPointF smPoint = itemMatrix.map(sPoint); QLineF stLinA = QLineF(smPoint, QPointF(m_Mxp, m_Myp)); QLineF stLinM = QLineF(smPoint, QPointF(newX, newY)); double deltaAngle = stLinM.angle() - stLinA.angle(); if (deltaAngle < -180) deltaAngle = deltaAngle + 360; else if (deltaAngle > 180) deltaAngle = deltaAngle - 360; if (currItem->imageFlippedV()) deltaAngle *= -1.0; if (currItem->imageFlippedH()) deltaAngle *= -1.0; if (m_arcPoint == useControlStart) { if (m_startAngle + deltaAngle >= 0) { m_startAngle += deltaAngle; applyValues(m_startAngle,m_endAngle,item->spiralFactor); item->recalcPath(); m_startPoint = currItem->PoLine.pointQF(0); m_canvas->displayRealRotHUD(m->globalPos(), m_startAngle); } m_VectorDialog->setValues(computeRealAngle(m_startAngle, false), computeRealAngle(m_endAngle, false), item->spiralFactor); } else if (m_arcPoint == useControlEnd) { if (m_endAngle + deltaAngle > m_startAngle) { m_endAngle += deltaAngle; applyValues(m_startAngle,m_endAngle,item->spiralFactor); item->recalcPath(); m_endPoint = currItem->PoLine.pointQF(currItem->PoLine.size() - 2); m_canvas->displayRealRotHUD(m->globalPos(), m_endAngle); } m_VectorDialog->setValues(computeRealAngle(m_startAngle, false), computeRealAngle(m_endAngle, false), item->spiralFactor); } currItem->update(); m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-5, -5, 10, 10)); } m_Mxp = newX; m_Myp = newY; }
void TasQtTraverse::addWidgetCoordinates(TasObject* objectInfo, QWidget* widget, TasCommand* command) { objectInfo->addBooleanAttribute("isWindow", widget->isWindow()); QGraphicsProxyWidget* proxy = TestabilityUtils::parentProxy(widget); if (proxy) { //TasLogger::logger()->debug("TasQtTraverse::addWidgetCoordinates got proxy"); //print window coordinates QRectF sceneRect = proxy->sceneBoundingRect(); QGraphicsView* view = TestabilityUtils::getViewForItem(proxy); if(!view->viewportTransform().isIdentity()){ QTransform transform = view->viewportTransform(); sceneRect = transform.mapRect(sceneRect); } QPoint point = sceneRect.topLeft().toPoint(); //Print screen coordinates QPoint windowPoint = widget->mapTo(widget->window(),QPoint(0, 0)); windowPoint += point; objectInfo->addAttribute("x", windowPoint.x()); objectInfo->addAttribute("y", windowPoint.y()); objectInfo->addAttribute("x_absolute", windowPoint.x()); objectInfo->addAttribute("y_absolute", windowPoint.y()); } else { QPoint screenPoint; if (command && command->parameter("x_parent_absolute") != "" && command->parameter("y_parent_absolute") != "") { //TasLogger::logger()->debug("TasQtTraverse::addWidgetCoordinates moving point"); QPoint p(command->parameter("x_parent_absolute").toInt(), command->parameter("y_parent_absolute").toInt()); screenPoint = widget->mapToGlobal(p); objectInfo->addAttribute("x_absolute", screenPoint.x()); objectInfo->addAttribute("y_absolute", screenPoint.y()); } else { //TasLogger::logger()->debug("TasQtTraverse::addWidgetCoordinates using regular coords"); screenPoint = widget->mapToGlobal(QPoint(0, 0)); objectInfo->addAttribute("x_absolute", screenPoint.x()); objectInfo->addAttribute("y_absolute", screenPoint.y()); } //print window coordinates QPoint windowPoint = widget->window()->mapFromGlobal(screenPoint); objectInfo->addAttribute("x", windowPoint.x()); objectInfo->addAttribute("y", windowPoint.y()); } // Explicitly add width and height (property added changes name) objectInfo->addAttribute("width", widget->width()); objectInfo->addAttribute("height", widget->height()); }
TextRenderable::TextRenderable(const TextSymbol* symbol, const TextObject* text_object, const MapColor* color, double anchor_x, double anchor_y) : Renderable { color } , anchor_x { anchor_x } , anchor_y { anchor_y } , rotation { 0.0 } , scale_factor { symbol->getFontSize() / TextSymbol::internal_point_size } { path.setFillRule(Qt::WindingFill); // Otherwise, when text and an underline intersect, holes appear const QFont& font(symbol->getQFont()); const QFontMetricsF& metrics(symbol->getFontMetrics()); int num_lines = text_object->getNumLines(); for (int i=0; i < num_lines; i++) { const TextObjectLineInfo* line_info = text_object->getLineInfo(i); double line_y = line_info->line_y; double underline_x0 = 0.0; double underline_y0 = line_info->line_y + metrics.underlinePos(); double underline_y1 = underline_y0 + metrics.lineWidth(); auto num_parts = line_info->part_infos.size(); for (size_t j=0; j < num_parts; j++) { const TextObjectPartInfo& part(line_info->part_infos.at(j)); if (font.underline()) { if (j > 0) { // draw underline for gap between parts as rectangle // TODO: watch out for inconsistency between text and gap underline path.moveTo(underline_x0, underline_y0); path.lineTo(part.part_x, underline_y0); path.lineTo(part.part_x, underline_y1); path.lineTo(underline_x0, underline_y1); path.closeSubpath(); } underline_x0 = part.part_x; } path.addText(part.part_x, line_y, font, part.part_text); } } QTransform t { 1.0, 0.0, 0.0, 1.0, anchor_x, anchor_y }; t.scale(scale_factor, scale_factor); auto rotation_rad = text_object->getRotation(); if (!qIsNull(rotation_rad)) { rotation = -qRadiansToDegrees(rotation_rad); t.rotate(rotation); } extent = t.mapRect(path.controlPointRect()); }
QRectF QuickItemNodeInstance::contentItemBoundingBox() const { if (contentItem()) { QTransform contentItemTransform = DesignerSupport::parentTransform(contentItem()); return contentItemTransform.mapRect(contentItem()->boundingRect()); } return QRectF(); }
void BlurItem::reload(const QPixmap &pixmap) { const QRectF r = rect(); if (r.isNull() && !r.isValid()) return; QTransform t = sceneTransform(); t.translate(qAbs(scene()->sceneRect().left()), qAbs(scene()->sceneRect().top())); m_item->setPixmap(pixmap.copy(t.mapRect(r).toRect())); }
void PageItem_PathText::getVisualBoundingRect(double * x1, double * y1, double * x2, double * y2) const { PageItem::getVisualBoundingRect(x1, y1, x2, y2); QRectF totalRect(QPointF(*x1, *y1), QPointF(*x2, *y2)); QTransform clipTrans; clipTrans.translate(m_xPos, m_yPos); clipTrans.rotate(m_rotation); totalRect = totalRect.united(QRectF(clipTrans.mapRect(Clip.boundingRect()))); totalRect.getCoords(x1, y1, x2, y2); }
// NB: From QQuickWindow void TouchDispatcher::transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform) { QMatrix4x4 transformMatrix(transform); for (int i=0; i<touchPoints.count(); i++) { QTouchEvent::TouchPoint &touchPoint = touchPoints[i]; touchPoint.setRect(transform.mapRect(touchPoint.sceneRect())); touchPoint.setStartPos(transform.map(touchPoint.startScenePos())); touchPoint.setLastPos(transform.map(touchPoint.lastScenePos())); touchPoint.setVelocity(transformMatrix.mapVector(touchPoint.velocity()).toVector2D()); } }
void CanvasRect::paint(QPainter *painter, const QTransform &tran, const QRectF &limits) { QRectF plotRect = bounds(); // Let's not waste time here... if (!limits.intersects(plotRect)) return; // TODO: This boilerplate style stuff to a CanvasShape::applyStyle(QPainter*) func? QPen pen; LineSpec *ln = lineSpec(); pen.setColor(ln->color()); pen.setWidthF(ln->width()); QString style = ln->style(); if (style == ".") { pen.setStyle(Qt::SolidLine); } else { pen.setStyle( LineSpec::styleMap[style] ); } QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(fillSpec()->color()); painter->setRenderHint(QPainter::Antialiasing); // Only draw the part of the rect in the view QRectF rect = limits.intersected(plotRect); // Figure out which sides still need lines... QVector<QLineF> lines; if (rect.left() == plotRect.left()) lines << QLineF(rect.bottomLeft(), rect.topLeft()); if (rect.right() == plotRect.right()) lines << QLineF(rect.bottomRight(), rect.topRight()); if (rect.top() == plotRect.top()) lines << QLineF(rect.topLeft(), rect.topRight()); if (rect.bottom() == plotRect.bottom()) lines << QLineF(rect.bottomLeft(), rect.bottomRight()); // Map the fill and lines QRectF mappedRect = tran.mapRect(rect); for (int i=0; i<lines.length(); ++i) { lines[i] = tran.map(lines[i]); } // Draw the rect painter->setPen(Qt::NoPen); painter->setBrush(brush); painter->drawRect(mappedRect); // Draw the outline painter->setBrush(Qt::NoBrush); painter->setPen(pen); painter->drawLines(lines); }
int path_preview_handle::distance_to_mouse (QPoint screen_pos, QTransform transform) const { double max_distance = 20; QRectF bbox = transform.mapRect (m_item->bbox ()).adjusted (-max_distance, -max_distance, max_distance, max_distance); if (!bbox.contains (screen_pos)) return 1000; auto path_data = m_item->get_computed_attribute<svg_attribute_path_data> (); path_nearest_point nearest_calc; return nearest_calc.get_nearest_point (screen_pos, m_item->full_transform () * transform, path_data->path ()); }
void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) { if (!item) { qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add null item"); return; } if (item == this) { qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add a group to itself"); return; } // COMBINE bool ok; QTransform itemTransform = item->itemTransform(this, &ok); if (!ok) { qWarning("UBGraphicsGroupContainerItem::addToGroup: could not find a valid transformation from item to group coordinates"); return; } //setting item flags to given item item->setSelected(false); item->setFlag(QGraphicsItem::ItemIsSelectable, false); item->setFlag( QGraphicsItem::ItemIsMovable, false); item->setFlag(QGraphicsItem::ItemIsFocusable, true); QTransform newItemTransform(itemTransform); item->setPos(mapFromItem(item, 0, 0)); item->setParentItem(this); // removing position from translation component of the new transform if (!item->pos().isNull()) newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y()); // removing additional transformations properties applied with itemTransform() QPointF origin = item->transformOriginPoint(); QMatrix4x4 m; QList<QGraphicsTransform*> transformList = item->transformations(); for (int i = 0; i < transformList.size(); ++i) transformList.at(i)->applyTo(&m); newItemTransform *= m.toTransform().inverted(); newItemTransform.translate(origin.x(), origin.y()); newItemTransform.rotate(-item->rotation()); newItemTransform.scale(1/item->scale(), 1/item->scale()); newItemTransform.translate(-origin.x(), -origin.y()); // ### Expensive, we could maybe use dirtySceneTransform bit for optimization item->setTransform(newItemTransform); // item->d_func()->setIsMemberOfGroup(true); prepareGeometryChange(); itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect()); update(); }