fix: use SmoothTransformation when scale factor less than 100%

This commit is contained in:
Gary Wang 2020-02-13 19:45:14 +08:00
parent 8fe860e4bf
commit f49ed645fc
4 changed files with 25 additions and 0 deletions

View File

@ -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());

View File

@ -15,6 +15,8 @@ public:
void showSvg(const QString &filepath);
void showGif(const QString &filepath);
bool trySetTransformationMode(Qt::TransformationMode mode);
QPixmap renderToPixmap();
private:

View File

@ -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();

View File

@ -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);