Skip to content

Commit

Permalink
fix: use SmoothTransformation when scale factor less than 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
BLumia committed Feb 13, 2020
1 parent 8fe860e commit f49ed64
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions graphicsscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ void GraphicsScene::showGif(const QString &filepath)
this->setSceneRect(m_theThing->boundingRect());
}

bool GraphicsScene::trySetTransformationMode(Qt::TransformationMode mode)
{
QGraphicsPixmapItem * pixmapItem = qgraphicsitem_cast<QGraphicsPixmapItem *>(m_theThing);
if (pixmapItem) {
pixmapItem->setTransformationMode(mode);
return true;
}

return false;
}

QPixmap GraphicsScene::renderToPixmap()
{
QPixmap pixmap(sceneRect().toRect().size());
Expand Down
2 changes: 2 additions & 0 deletions graphicsscene.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class GraphicsScene : public QGraphicsScene
void showSvg(const QString &filepath);
void showGif(const QString &filepath);

bool trySetTransformationMode(Qt::TransformationMode mode);

QPixmap renderToPixmap();

private:
Expand Down
11 changes: 11 additions & 0 deletions graphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void GraphicsView::zoomView(qreal scaleFactor)
{
m_enableFitInView = false;
scale(scaleFactor, scaleFactor);
applyTransformationModeByScaleFactor();
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle);
}

Expand All @@ -136,6 +137,7 @@ void GraphicsView::rotateView(qreal rotateAngel)
void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode)
{
QGraphicsView::fitInView(rect, aspectRadioMode);
applyTransformationModeByScaleFactor();
}

void GraphicsView::checkAndDoFitInView()
Expand Down Expand Up @@ -298,6 +300,15 @@ void GraphicsView::setCheckerboardEnabled(bool enabled)
}
}

void GraphicsView::applyTransformationModeByScaleFactor()
{
if (this->scaleFactor() < 1) {
scene()->trySetTransformationMode(Qt::SmoothTransformation);
} else {
scene()->trySetTransformationMode(Qt::FastTransformation);
}
}

void GraphicsView::resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle)
{
QGraphicsView::resetTransform();
Expand Down
1 change: 1 addition & 0 deletions graphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public slots:
bool isThingSmallerThanWindowWith(const QTransform &transform) const;
bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const;
void setCheckerboardEnabled(bool enabled);
void applyTransformationModeByScaleFactor();

void resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle);

Expand Down

0 comments on commit f49ed64

Please sign in to comment.