diff --git a/src/widgets/dialogs/showimagewidget.h b/src/widgets/dialogs/showimagewidget.h --- a/src/widgets/dialogs/showimagewidget.h +++ b/src/widgets/dialogs/showimagewidget.h @@ -36,20 +36,15 @@ void setImage(const QPixmap &pix); - QSize sizeHint() const override; - Q_REQUIRED_RESULT bool isAnimatedPixmap() const; void setIsAnimatedPixmap(bool value); void setImagePath(const QString &imagePath); protected: - void showEvent(QShowEvent *event) override; - void resizeEvent(QResizeEvent *event) override; void wheelEvent(QWheelEvent *e) override; private: - void applyPixmap(); void setZoom(double scale); QPixmap mPixmap; diff --git a/src/widgets/dialogs/showimagewidget.cpp b/src/widgets/dialogs/showimagewidget.cpp --- a/src/widgets/dialogs/showimagewidget.cpp +++ b/src/widgets/dialogs/showimagewidget.cpp @@ -38,7 +38,6 @@ auto *scrollArea = new QScrollArea(this); scrollArea->setObjectName(QStringLiteral("scrollArea")); - scrollArea->setWidgetResizable(true); mainLayout->addWidget(scrollArea); mLabel = new QLabel(this); @@ -87,9 +86,10 @@ { if (!mIsAnimatedPixmap && !mIsUpdatingZoom) { QScopedValueRollback guard(mIsUpdatingZoom, true); - const QPixmap pm = mPixmap.scaled(mPixmap.width() * scale, mPixmap.height() * scale, - Qt::KeepAspectRatio, Qt::SmoothTransformation); + auto pm = mPixmap.scaled(mPixmap.width() * scale, mPixmap.height() * scale, + Qt::KeepAspectRatio, Qt::SmoothTransformation); mLabel->setPixmap(pm); + mLabel->resize(pm.size()); mSlider->setValue(static_cast(scale * 100)); mZoomSpin->setValue(scale); } @@ -114,44 +114,23 @@ { QMovie *movie = new QMovie(this); movie->setFileName(imagePath); + movie->start(); + const auto size = movie->currentPixmap().size(); + movie->stop(); mLabel->setMovie(movie); + mLabel->resize(size); movie->start(); } void ShowImageWidget::setImage(const QPixmap &pix) { mPixmap = pix; - applyPixmap(); + mPixmap.setDevicePixelRatio(devicePixelRatioF()); + mLabel->setPixmap(mPixmap); + mLabel->resize(mPixmap.size() / devicePixelRatioF()); updateGeometry(); // sizeHint changed } -QSize ShowImageWidget::sizeHint() const -{ - if (mIsAnimatedPixmap) { - return QWidget::sizeHint(); - } - return mPixmap.size().boundedTo(QSize(800, 800)); -} - -void ShowImageWidget::showEvent(QShowEvent *event) -{ - applyPixmap(); - QWidget::showEvent(event); -} - -void ShowImageWidget::resizeEvent(QResizeEvent *event) -{ - applyPixmap(); - QWidget::resizeEvent(event); -} - -void ShowImageWidget::applyPixmap() -{ - if (!mIsAnimatedPixmap) { - mLabel->setPixmap(mPixmap.scaled(mLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - } -} - void ShowImageWidget::wheelEvent(QWheelEvent *e) { if (!mIsAnimatedPixmap) { diff --git a/src/widgets/room/autotests/messagedelegatehelperimagetest.cpp b/src/widgets/room/autotests/messagedelegatehelperimagetest.cpp --- a/src/widgets/room/autotests/messagedelegatehelperimagetest.cpp +++ b/src/widgets/room/autotests/messagedelegatehelperimagetest.cpp @@ -56,5 +56,6 @@ QVERIFY(!layout.isAnimatedImage); QVERIFY(layout.imagePath.endsWith(QLatin1String("/testfile.png"))); QCOMPARE(layout.imageSize.height(), layout.imageSize.width() * 2); // aspect ratio is preserved - QVERIFY(layout.imageSize.height() < 500); + QCOMPARE(layout.pixmap.devicePixelRatioF(), fakeWidget.devicePixelRatioF()); + QVERIFY(layout.imageSize.height() < 500 * fakeWidget.devicePixelRatioF()); } diff --git a/src/widgets/room/delegate/messagedelegatehelperimage.cpp b/src/widgets/room/delegate/messagedelegatehelperimage.cpp --- a/src/widgets/room/delegate/messagedelegatehelperimage.cpp +++ b/src/widgets/room/delegate/messagedelegatehelperimage.cpp @@ -75,6 +75,7 @@ rai.movie->start(); scaledPixmap = rai.movie->currentPixmap(); } + scaledPixmap.setDevicePixelRatio(option.widget->devicePixelRatioF()); } else { scaledPixmap = layout.pixmap.scaled(layout.imageSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } @@ -167,6 +168,7 @@ if (url.isLocalFile()) { layout.imagePath = url.toLocalFile(); layout.pixmap = mPixmapCache.pixmapForLocalFile(layout.imagePath); + layout.pixmap.setDevicePixelRatio(option.widget->devicePixelRatioF()); //or we could do layout.attachment = msgAttach; if we need many fields from it layout.title = msgAttach.title(); layout.description = msgAttach.description(); @@ -184,7 +186,8 @@ if (!layout.description.isEmpty()) { imageMaxHeight -= layout.descriptionSize.height() + DelegatePaintUtil::margin(); } - layout.imageSize = layout.pixmap.size().scaled(attachmentsWidth, imageMaxHeight, Qt::KeepAspectRatio); + const auto dpr = layout.pixmap.devicePixelRatioF(); + layout.imageSize = layout.pixmap.size().scaled(attachmentsWidth * dpr, imageMaxHeight * dpr, Qt::KeepAspectRatio); } } return layout;