From a0363ba99d1dc99a306becf0898e7361c76df844 Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 23 Jan 2023 11:14:51 +0300 Subject: [PATCH 1/2] ImageView big images fix --- libs/widgets/image_view.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/widgets/image_view.cpp b/libs/widgets/image_view.cpp index e3637aa..d227fdf 100644 --- a/libs/widgets/image_view.cpp +++ b/libs/widgets/image_view.cpp @@ -137,7 +137,7 @@ void ImageView::adjustView() { #if QT_VERSION_MAJOR >= 5 ws *= devicePixelRatio(); #endif - int nw = map.size().boundedTo(ws).width(); + int nw = map.size().width(); item->setScale(1.); if (nw > 0) { qreal mp = map.width() / nw; From 7d7ec8976d1aa7de80d92def9a5c40ef5feaf5c6 Mon Sep 17 00:00:00 2001 From: peri4 Date: Mon, 23 Jan 2023 11:22:46 +0300 Subject: [PATCH 2/2] ImageView big images property --- libs/widgets/image_view.cpp | 35 ++++++++++++++++++++++------------- libs/widgets/image_view.h | 6 +++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/libs/widgets/image_view.cpp b/libs/widgets/image_view.cpp index d227fdf..a231cd5 100644 --- a/libs/widgets/image_view.cpp +++ b/libs/widgets/image_view.cpp @@ -24,8 +24,8 @@ ImageView::ImageView(QWidget * parent): QGraphicsView(parent), item(new QGraphic scene()->addItem(item); viewport()->setAutoFillBackground(false); viewport()->installEventFilter(this); - autofit_ = true; - interactive_ = false; + autofit_ = smooth_big = true; + interactive_ = false; } @@ -87,6 +87,12 @@ void ImageView::clear() { } +void ImageView::setSmoothBigImages(bool yes) { + smooth_big = yes; + adjustView(); +} + + void ImageView::mouseDoubleClickEvent(QMouseEvent *) { autofit(); } @@ -133,18 +139,21 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) { void ImageView::adjustView() { - QSize ws = size(); -#if QT_VERSION_MAJOR >= 5 - ws *= devicePixelRatio(); -#endif - int nw = map.size().width(); item->setScale(1.); - if (nw > 0) { - qreal mp = map.width() / nw; - if (mp > 1.) { - QSize ss = map.size(); - item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation)); - item->setScale(double(ss.width()) / item->pixmap().width()); + if (smooth_big) { + QSize ws = size(); +#if QT_VERSION_MAJOR >= 5 + ws *= devicePixelRatio(); +#endif + int nw = map.size().boundedTo(ws).width(); + if (nw > 0) { + qreal mp = map.width() / nw; + if (mp > 1.) { + QSize ss = map.size(); + item->setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + item->setScale(double(ss.width()) / item->pixmap().width()); + } else + item->setPixmap(map); } else item->setPixmap(map); } else diff --git a/libs/widgets/image_view.h b/libs/widgets/image_view.h index 1c95fdf..49871eb 100644 --- a/libs/widgets/image_view.h +++ b/libs/widgets/image_view.h @@ -32,6 +32,7 @@ class QAD_WIDGETS_EXPORT ImageView: public QGraphicsView { Q_OBJECT Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap) Q_PROPERTY(bool viewInteractive READ viewInteractive WRITE setViewInteractive) + Q_PROPERTY(bool smoothBigImages READ isSmoothBigImages WRITE setSmoothBigImages) public: ImageView(QWidget * parent = nullptr); @@ -44,6 +45,9 @@ public: bool viewInteractive() const { return interactive_; } void clear(); + bool isSmoothBigImages() const { return smooth_big; } + void setSmoothBigImages(bool yes); + public slots: void autofit(); void setPixmap(QPixmap pixmap); @@ -62,7 +66,7 @@ private: QGraphicsPixmapItem * item; QByteArray im_data; QPoint prev_pos; - bool autofit_, interactive_; + bool autofit_, interactive_, smooth_big; QPixmap map; };