void StyleHelper::drawPixmapWithScreenScaleFactor(QPainter* p, const QRect& rcOrign, const QPixmap& pix) { if (pix.isNull()) return; #ifdef Q_OS_MAC float factor = qt_mac_get_scalefactor(0); QRect rcTarget(rcOrign); rcTarget.setWidth(rcTarget.width() * factor); rcTarget.setHeight(rcTarget.height() * factor); QTransform transRect; transRect.scale(factor, factor); QPoint leftTop = transRect.map(rcOrign.topLeft()); rcTarget.moveTopLeft(leftTop); // float rFactor = 1 / factor; QTransform transPainter; transPainter.scale(rFactor, rFactor); // p->save(); p->setWorldTransform(transPainter); p->drawPixmap(rcTarget, pix); p->restore(); #else p->drawPixmap(rcOrign, pix); #endif }
QTransform QgsTransformEffect::createTransform( const QgsRenderContext &context ) const { QTransform t; if ( !source() ) return t; int width = source()->boundingRect().width(); int height = source()->boundingRect().height(); int top = source()->boundingRect().top(); int left = source()->boundingRect().left(); //remember that the below operations are effectively performed in the opposite order //so, first the reflection applies, then scale, shear, rotate and lastly translation double translateX = context.convertToPainterUnits( mTranslateX, mTranslateUnit, mTranslateMapUnitScale ); double translateY = context.convertToPainterUnits( mTranslateY, mTranslateUnit, mTranslateMapUnitScale ); t.translate( translateX + left + width / 2.0, translateY + top + height / 2.0 ); t.rotate( mRotation ); t.shear( mShearX, mShearY ); t.scale( mScaleX, mScaleY ); if ( mReflectX || mReflectY ) { t.scale( mReflectX ? -1 : 1, mReflectY ? -1 : 1 ); } t.translate( -left - width / 2.0, -top - height / 2.0 ); return t; }
QPainterPath ShapeProcessor::getPuzzlePieceShape(int status) { _p->shapeRequests++; if (!_p->shapeCache.contains(status)) { foreach (int s, _p->shapeCache.keys()) { MatchMode m = match(s, status); if (m == NoMatch) continue; // Found a shape which matches, but needs transforming QTransform tr; if (m == HorizontalFlipMatch) tr = tr.scale(-1.0, 1.0).translate(-_p->unit.width() - _p->tabFull * 2, 0); else if (m == VerticalFlipMatch) tr = tr.scale(1.0, -1.0).translate(0, - _p->unit.height() - _p->tabFull * 2); else if (m == HorizontalAndVerticalFlipMatch) tr = tr.scale(-1.0, -1.0).translate(-_p->unit.width() - _p->tabFull * 2, - _p->unit.height() - _p->tabFull * 2); _p->shapeCacheHits++; return _p->shapeCache[status] = tr.map(_p->shapeCache[s]); } // No match in the cache, need to generate a new shape return _p->shapeCache[status] = createPuzzleShape( _p->unit, status, _p->tabFull, _p->tabSize, _p->tabOffset, _p->tabTolerance, _p->tabSize, _p->tabOffset); }
void Animator::SetDegree(const double& dg){ Degree=dg; double ScaleGrade; while(Degree>360.0) Degree-=360.0; while(Degree<0) Degree+=360.0; if(tipoAnimazione==RotateIn){ QTransform transform; ScaleGrade=-((Degree/360.0)-1.0); transform.scale(ScaleGrade,ScaleGrade); transform.shear(0, (Degree/180.0)*((double)WidImage->height())/((double)WidImage->width())); Immagine->setTransform(transform); if(baseParent==0) setGeometry(Posizione.x()+(QApplication::desktop()->width()*(1-ScaleGrade)),Posizione.y(),WidImage->width()*ScaleGrade,WidImage->height()); else setGeometry(Posizione.x()+(baseParent->width()*(1-ScaleGrade)),Posizione.y(),WidImage->width()*ScaleGrade,WidImage->height()); } if(tipoAnimazione==RotateOut){ QTransform transform; ScaleGrade=Degree/360.0; transform.scale(ScaleGrade,ScaleGrade); transform.shear(0, ((Degree/180.0)-2.0)*((double)WidImage->height())/((double)WidImage->width())); Immagine->setTransform(transform); setGeometry( Posizione.x()*ScaleGrade, Posizione.y()-(WidImage->height())*(ScaleGrade-1.0), WidImage->width()*ScaleGrade, WidImage->height()+(WidImage->height())*(ScaleGrade-1.0)); } }
QTransform MapObjectItem::tileCollisionObjectsTransform(const Tile &tile) const { const Tileset *tileset = tile.tileset(); QTransform tileTransform; tileTransform.scale(mObject->width() / tile.width(), mObject->height() / tile.height()); if (mMapDocument->map()->orientation() == Map::Isometric) tileTransform.translate(-tile.width() / 2, 0.0); tileTransform.translate(tileset->tileOffset().x(), tileset->tileOffset().y()); if (mObject->cell().flippedVertically()) { tileTransform.scale(1, -1); tileTransform.translate(0, tile.height()); } if (mObject->cell().flippedHorizontally()) { tileTransform.scale(-1, 1); tileTransform.translate(-tile.width(), 0); } if (tileset->orientation() == Tileset::Isometric) tileTransform.translate(0.0, -tile.tileset()->gridSize().height()); else tileTransform.translate(0.0, -tile.height()); return tileTransform; }
QPixmap ExifPixmap::createPixmap(QString path) { ExifData *exifData = exif_data_new_from_file(path.toStdString().c_str()); int orientation = 0; if(exifData) { ExifByteOrder byteOrder = exif_data_get_byte_order(exifData); ExifEntry *exifEntry = exif_data_get_entry(exifData, EXIF_TAG_ORIENTATION); if(exifEntry) { orientation = exif_get_short(exifEntry->data, byteOrder); } exif_data_free(exifData); } QPixmap pic(path); /* 0th Row 0th Column 1 top left side 2 top right side 3 bottom right side 4 bottom left side 5 left side top 6 right side top 7 right side bottom 8 left side bottom */ QTransform t; switch(orientation) { // TODO : test flips case 1: break; case 2: t.scale(-1,1); break; case 3: t.rotate(180); break; case 4: t.rotate(180); t.scale(-1,1); break; case 5: t.rotate(90); t.scale(-1,1); break; case 6: t.rotate(90); break; case 7: t.rotate(-90); t.scale(-1,1); break; case 8: t.rotate(-90); break; default: break; } return pic.transformed(t); }
void TscoreTie::updateLength() { QTransform t; if (firstNote()->staff() == secondNote()->staff()) t.scale((secondNote()->x() - firstNote()->x() - firstNote()->width() * 0.8) / m_tieItem->boundingRect().width(), firstNote()->note()->rtm.stemDown() ? -1.0 : 1.0); else t.scale(1.0, firstNote()->note()->rtm.stemDown() ? -1.0 : 1.0); m_tieItem->setTransform(t); m_tieItem->setPos(firstNote()->width(), firstNote()->notePos() + (firstNote()->note()->rtm.stemDown() ? 3.7 : - 1.8)); }
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); } }
void ScreenPainter::drawGlyphOutline(const GlyphLayout gl, bool fill) { if (fill) drawGlyph(gl); m_painter->save(); bool fr = m_painter->fillRule(); m_painter->setFillRule(false); setupState(false); m_painter->translate(0, -(fontSize() * gl.scaleV)); FPointArray outline = font().glyphOutline(gl.glyph); double scaleHv = gl.scaleH * fontSize() / 10.0; double scaleVv = gl.scaleV * fontSize() / 10.0; QTransform trans; trans.scale(scaleHv, scaleVv); outline.map(trans); m_painter->setupPolygon(&outline, true); if (outline.size() > 3) { m_painter->setLineWidth(strokeWidth()); m_painter->strokePath(); } m_painter->setFillRule(fr); m_painter->restore(); }
void poligono::on_pushButton_6_clicked() { QTransform reflect; reflect.scale(-1,1); transforms.push_back(reflect); update(); }
void poligono::on_pushButton_4_clicked() { QTransform zoomIn; zoomIn.scale(2,2); transforms.push_back(zoomIn); update(); }
// draw text void ScenePainter::drawText(const char * const *strs, double *x, double *y, int n, Qt::Alignment flags, double rot, double hcex, double vcex) { if (indexMode()) { QVector<QRectF> rects = textExtents(strs, n, flags); for (int i = 0; i < n; i++) { QString qstr = QString::fromLocal8Bit(strs[i]); QPointF center = rects[i].center(); double xi = x[i] + center.x(); double yi = y[i] + center.y(); drawPoints(&xi, &yi, 1); } return; } // FIXME: alignment is ignored -- translate to HTML? QTransform posTform = transform(); QTransform textTform; textTform.rotate(-rot); textTform.scale(hcex, vcex); for (int i = 0; i < n; i++) { QString qstr = QString::fromLocal8Bit(strs[i]); QGraphicsItem *item = STORE_INDEX(_scene->addText(qstr, _scene->font())); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); item->setPos(posTform.map(QPointF(x[i], y[i]))); item->setTransform(textTform); } }
void Heading_Widget::paintEvent(QPaintEvent * event) { (void)event; QPainter painter(this); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); float xScale = (float)this->width() / (float)backImage.width(); float yScale = (float)this->height() / (float)backImage.height(); painter.scale(xScale, yScale); painter.drawPixmap(0, 0, backImage); QTransform trans; trans.translate( width()/2, height()/2); trans.scale(xScale,yScale); trans.rotate( -headingAngle ); trans.translate( -137, -137 ); painter.setTransform(trans); painter.drawPixmap(0, 0, headingRing); painter.resetTransform(); painter.scale(xScale, yScale); painter.drawPixmap(70, 40, airplaneImage); }
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); } }
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()); } }
MainWindow::MainWindow(QWidget* parent) { ui.setupUi(this); ui.graphicsView->setScene(&_scene); _mapid.load("./MapID.mat"); cout << _mapid.n_cols << "," << _mapid.n_rows << endl; connect(ui.slider, SIGNAL(valueChanged(int)), SLOT(selectValue(int))); connect(ui.clearGraphButton, SIGNAL(pressed()), SLOT(clearGraphs())); connect(ui.loadSeries, SIGNAL(pressed()), SLOT(loadSeries())); _mapItem = new QFloatImageItem(); _mapItem->setImage(_imageBuffer.memptr(), _imageBuffer.n_rows, _imageBuffer.n_cols); _mapItem->setRange(ui.minValue->value(), ui.maxValue->value()); _mapItem->setInteraction(this); _scene.addItem(_mapItem); _traceItem = _scene.addPath(_tracePath); _traceItem->setPen(QPen(Qt::black)); QTransform matrix; matrix.scale(5, 5); ui.graphicsView->setTransform(matrix); ui.customPlot->setInteraction(QCustomPlot::iSelectLegend, true); ui.customPlot->setInteraction(QCustomPlot::iSelectPlottables, true); connect(ui.customPlot, SIGNAL(selectionChangedByUser()), SLOT(graphSelected())); _plotMarker = new QGraphicsEllipseItem(_mapItem); _plotMarker->setVisible(false); }
void TransformTest::testTransformCombined() { QFETCH(int, type); QFETCH(double, rotation); qint32 dx = -3000; qint32 dy = 16000; qreal scale_x = 4.5; qreal scale_y = 2.5; QTransform qt; // Template::applyTemplateTransform order: translate, rotate, scale qt.translate(dx / 1000.0, dy / 1000.0); qt.rotate(qreal(rotation)); qt.scale(scale_x, scale_y); QVERIFY(qt.isScaling()); QCOMPARE(int(qt.type()), type); auto t = TemplateTransform::fromQTransform(qt); QCOMPARE(t.template_x, dx); QCOMPARE(t.template_y, dy); QCOMPARE(t.template_scale_x, scale_x); QCOMPARE(t.template_scale_y, scale_y); if (rotation <= 180.0) QCOMPARE(t.template_rotation, -qDegreesToRadians(qreal(rotation))); else QCOMPARE(t.template_rotation, -qDegreesToRadians(qreal(rotation - 360.0))); }
void prismaTriangular::on_pushButton_7_clicked() { QTransform reflect; reflect.scale(1,-1); transforms.push_back(reflect); update(); }
void QMLProfile::paint(QPainter *painter) { if (m_diveId.toInt() < 1) return; struct dive *d; d = get_dive_by_uniq_id(m_diveId.toInt()); if (!d) return; profile = new ProfileWidget2(0); profile->setProfileState(); profile->setToolTipVisibile(false); int old_animation_speed = prefs.animation_speed; prefs.animation_speed = 0; // no animations while rendering the QGraphicsView profile->plotDive(d); QTransform profileTransform; profileTransform.scale(this->height() / 100, this->height() / 100); profile->setTransform(profileTransform); profile->render(painter); prefs.animation_speed = old_animation_speed; profile->deleteLater(); }
void MainWindow::changeBackground(){ if(scene){ QPixmap pixmap(Config.BackgroundBrush); QBrush brush(pixmap); if(pixmap.width() > 100 && pixmap.height() > 100){ qreal _width = width()/view->matrix().m11(); qreal _height= height()/view->matrix().m22(); qreal dx = -_width/2.0; qreal dy = -_height/2.0; qreal sx = _width / qreal(pixmap.width()); qreal sy = _height / qreal(pixmap.height()); QTransform transform; transform.translate(dx, dy); transform.scale(sx, sy); brush.setTransform(transform); } scene->setBackgroundBrush(brush); } if(scene->inherits("RoomScene")){ RoomScene *room_scene = qobject_cast<RoomScene *>(scene); room_scene->changeTextEditBackground(); }else if(scene->inherits("StartScene")){ StartScene *start_scene = qobject_cast<StartScene *>(scene); start_scene->setServerLogBackground(); } }
bool ReAnimEntityWidget::GetTransformAt( int _cursor, QTransform& _result, bool _allowExterpolate ) { bool isOk = false; QPointF translation; qreal rotation = 0.0f; QPointF scale; bool hasTranslation = GetTranslationAt( _cursor, translation, _allowExterpolate ); bool hasRotation = GetRotationAt( _cursor, rotation, _allowExterpolate ); bool hasScale = GetScaleAt( _cursor, scale, _allowExterpolate ); if( hasTranslation || hasRotation || hasScale ) { _result.reset(); if( hasScale ) _result.scale( scale.x(), scale.y() ); if( hasRotation ) _result.rotate( rotation ); if( hasTranslation ) _result.translate( translation.x(), translation.y() ); isOk = true; } return isOk; }
void UMLGeneralizationLine::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * parent ) { QPolygonF head; head.append( QPointF( 0.0, 0.0 ) ); head.append( QPointF( cos( PI / 6 ), -sin( PI / 6 ) ) ); head.append( QPointF( cos( -PI / 6 ), -sin( -PI / 6 ) ) ); QPainterPath path; path.addPolygon( head ); QTransform transform; transform.translate( this->line().p2().x(), this->line().p2().y() ); transform.scale( ARROW_HEAD_SIZE, ARROW_HEAD_SIZE ); transform.rotate( 180.0 - this->line().angle() ); QTransform backup( painter->transform() ); painter->setTransform( transform, true ); painter->fillPath( path, QColor( "blue" ) ); painter->setPen( this->pen() ); painter->drawPolygon( head ); painter->setTransform( backup ); qreal triangleHeight = ::sqrt( 3.0 ) / 2.0; QPointF realP2( transform.map( QLineF( QPointF( 0.0, 0.0 ), QPointF( triangleHeight, 0.0 ) ) ).p2() ); painter->drawLine( this->line().p1(), realP2 ); }
void cubo::on_pushButton_7_clicked() { QTransform zoomIn; zoomIn.scale(1,-1); transforms.push_back(zoomIn); update(); }
void PrismaTriangular::on_pushButton_5_clicked() { QTransform zoomOut; zoomOut.scale(0.7,0.7); transformations.push_back(zoomOut); update(); }
void TsimpleScore::resizeEvent(QResizeEvent* event) { int hh = height(), ww = width(); if (event) { hh = event->size().height(); ww = event->size().width(); } if (hh == 0) return; qreal staffOff = 1.0; if (staff()->isPianoStaff()) staffOff = 2.0; qreal factor = ((qreal)hh / (staff()->height()))/* / transform().m11()*/; qreal yy = 0.0; if ((staff()->width() + staffOff + 1.0) * factor > width()) { factor = width() / ((staff()->width() + staffOff + 1.0)); yy = 1.0; } QTransform matrix; matrix.scale(factor, factor); setTransform(matrix); if (width() > (staff()->width() + staffOff + 1.0) * transform().m11()) staffOff = ((ww / transform().m11() - (staff()->width())) / 2.0); scene()->setSceneRect(0.0, 0.0, ww / transform().m11(), hh / transform().m11()); if (yy) yy = (scene()->sceneRect().height() - staff()->height()) / 2.0; staff()->setPos(staffOff, yy); }
void MarkerMapObject::paint(QPainter &painter, QRect view, int scale) { // Save the painter state for this paint session // so that it can be restored after without influencing other objects painter.save(); { // Translate, scale, and rotate... QTransform t; t.scale(1.0/scale, 1.0/scale); t.translate(x - view.x()*scale, view.height()*scale - y + view.y()*scale); painter.setTransform(t); for(int index = 0; index < transformationCount; index++) { long arrowLength = 1000*scale; long ballSize = 20*scale; Vector2D a = transformation[index].trans(); Vector2D b = (transformation[index] * Trafo2D::trans(0, arrowLength)).trans(); painter.setPen(transformationColors[index]); QPen pen = painter.pen(); pen.setWidth(2*scale); painter.setPen(pen); painter.drawLine(a.x(), -a.y(), b.x(), -b.y()); painter.setBrush(QBrush(transformationColors[index])); painter.drawEllipse(a.x()-ballSize/2, -(a.y()+ballSize/2), ballSize, ballSize); } } painter.restore(); }
void TestShapeContainer::testScaling() { KoShape *shape1 = new MockShape(); KoShape *shape2 = new MockShape(); shape1->setSize(QSizeF(10., 10.)); shape1->setPosition(QPointF(20., 20.)); shape2->setSize(QSizeF(30., 10.)); shape2->setPosition(QPointF(10., 40.)); QList<KoShape*> groupedShapes; groupedShapes.append(shape1); groupedShapes.append(shape2); KoShapeGroup *group = new KoShapeGroup(); KoShapeGroupCommand* groupCommand = KoShapeGroupCommand::createCommand(group, groupedShapes); groupCommand->redo(); QList<KoShape*> transformShapes; transformShapes.append(groupedShapes); transformShapes.append(group); QTransform matrix; matrix.scale(0.5, 0.5); QList<QTransform> oldTransformations; QList<QTransform> newTransformations; foreach(const KoShape* shape, transformShapes) { QTransform oldTransform = shape->transformation(); oldTransformations.append(oldTransform); newTransformations.append(oldTransform*matrix); }
void Poligono::on_pushButton_5_clicked() { QTransform zoomOut; zoomOut.scale(0.7,0.7); transformations.push_back(zoomOut); update(); }
void ZoomTool::scaleView(const QPointF ¢erPos) { QTransform transform; transform.scale(m_currentScale, m_currentScale); view()->setTransform(transform); QPointF adjustedCenterPos = centerPos; QSize rectSize(view()->rect().width() / m_currentScale, view()->rect().height() / m_currentScale); QRectF sceneRect; if (qAbs(m_currentScale - 1.0f) < Constants::ZoomSnapDelta) { adjustedCenterPos.rx() = rectSize.width() / 2; adjustedCenterPos.ry() = rectSize.height() / 2; } if (m_currentScale < 1.0f) { adjustedCenterPos.rx() = rectSize.width() / 2; adjustedCenterPos.ry() = rectSize.height() / 2; sceneRect.setRect(view()->rect().width() / 2 -rectSize.width() / 2, view()->rect().height() / 2 -rectSize.height() / 2, rectSize.width(), rectSize.height()); } else { sceneRect.setRect(adjustedCenterPos.x() - rectSize.width() / 2, adjustedCenterPos.y() - rectSize.height() / 2, rectSize.width(), rectSize.height()); } view()->setSceneRect(sceneRect); }
void PrismaTriangular::on_pushButton_4_clicked() { QTransform zoomIn; zoomIn.scale(1.5,1.5); transformations.push_back(zoomIn); update(); }