From f49ed645fc8e8d98b507e042e5f4bfed0a5d782b Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Thu, 13 Feb 2020 19:45:14 +0800 Subject: [PATCH] fix: use SmoothTransformation when scale factor less than 100% --- graphicsscene.cpp | 11 +++++++++++ graphicsscene.h | 2 ++ graphicsview.cpp | 11 +++++++++++ graphicsview.h | 1 + 4 files changed, 25 insertions(+) diff --git a/graphicsscene.cpp b/graphicsscene.cpp index c02cfff..2569b5c 100644 --- a/graphicsscene.cpp +++ b/graphicsscene.cpp @@ -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(m_theThing); + if (pixmapItem) { + pixmapItem->setTransformationMode(mode); + return true; + } + + return false; +} + QPixmap GraphicsScene::renderToPixmap() { QPixmap pixmap(sceneRect().toRect().size()); diff --git a/graphicsscene.h b/graphicsscene.h index facd045..3909449 100644 --- a/graphicsscene.h +++ b/graphicsscene.h @@ -15,6 +15,8 @@ public: void showSvg(const QString &filepath); void showGif(const QString &filepath); + bool trySetTransformationMode(Qt::TransformationMode mode); + QPixmap renderToPixmap(); private: diff --git a/graphicsview.cpp b/graphicsview.cpp index 0325a2b..65c477c 100644 --- a/graphicsview.cpp +++ b/graphicsview.cpp @@ -117,6 +117,7 @@ void GraphicsView::zoomView(qreal scaleFactor) { m_enableFitInView = false; scale(scaleFactor, scaleFactor); + applyTransformationModeByScaleFactor(); emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle); } @@ -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() @@ -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(); diff --git a/graphicsview.h b/graphicsview.h index 60ce62e..96a6046 100644 --- a/graphicsview.h +++ b/graphicsview.h @@ -54,6 +54,7 @@ private: bool isThingSmallerThanWindowWith(const QTransform &transform) const; bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const; void setCheckerboardEnabled(bool enabled); + void applyTransformationModeByScaleFactor(); void resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle);