From 05a1626c7e14978c55a9670f35ff72e2a3388096 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 17 Dec 2017 16:17:38 +0100 Subject: Implement different zoom levels for dive photos tab This implements different zoom levels for the dive photos tab as suggested by Stefan Fuchs in #898. The zoom level can be changed using a slider or CTRL+mousewheel. Zoom levels range from a third of the standard thumbnail size to thrice the standard thumbnail size. Thumbnails are cached in maximum resolution and scaled down on the fly. Because the profile widget took its pictures from the photo list model, an extra picture copy with a fixed size had to be introduced. The UI is still a bit crude. Reported-by: Stefan Fuchs Signed-off-by: Berthold Stoeger --- desktop-widgets/divepicturewidget.cpp | 14 +++++++++++ desktop-widgets/divepicturewidget.h | 2 ++ desktop-widgets/tab-widgets/TabDivePhotos.cpp | 9 +++++++ desktop-widgets/tab-widgets/TabDivePhotos.h | 1 + desktop-widgets/tab-widgets/TabDivePhotos.ui | 36 +++++++++++++++++++++++++++ 5 files changed, 62 insertions(+) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divepicturewidget.cpp b/desktop-widgets/divepicturewidget.cpp index a6864a5d9..46de16d09 100644 --- a/desktop-widgets/divepicturewidget.cpp +++ b/desktop-widgets/divepicturewidget.cpp @@ -59,3 +59,17 @@ void DivePictureWidget::mousePressEvent(QMouseEvent *event) QListView::mousePressEvent(event); } } + +void DivePictureWidget::wheelEvent(QWheelEvent *event) +{ + if (event->modifiers() == Qt::ControlModifier) { + // Angle delta is given in eighth parts of a degree. A classical mouse + // wheel click is 15 degrees. Each click should correspond to one zoom step. + // Therefore, divide by 15*8=120. To also support touch pads and finer-grained + // mouse wheels, take care to always round away from zero. + int delta = event->angleDelta().y(); + int carry = delta > 0 ? 119 : -119; + emit zoomLevelChanged((delta + carry) / 120); + } else + QListView::wheelEvent(event); +} diff --git a/desktop-widgets/divepicturewidget.h b/desktop-widgets/divepicturewidget.h index 09d4608c4..bf48a9d1b 100644 --- a/desktop-widgets/divepicturewidget.h +++ b/desktop-widgets/divepicturewidget.h @@ -14,9 +14,11 @@ public: protected: void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; signals: void photoDoubleClicked(const QString filePath); + void zoomLevelChanged(int delta); }; class DivePictureThumbnailThread : public QThread { diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.cpp b/desktop-widgets/tab-widgets/TabDivePhotos.cpp index 86749e770..571e0a3ac 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.cpp +++ b/desktop-widgets/tab-widgets/TabDivePhotos.cpp @@ -29,6 +29,10 @@ TabDivePhotos::TabDivePhotos(QWidget *parent) QDesktopServices::openUrl(QUrl::fromLocalFile(path)); } ); + connect(ui->photosView, &DivePictureWidget::zoomLevelChanged, + this, &TabDivePhotos::changeZoomLevel); + connect(ui->zoomSlider, &QAbstractSlider::valueChanged, + DivePictureModel::instance(), &DivePictureModel::setZoomLevel); } TabDivePhotos::~TabDivePhotos() @@ -98,3 +102,8 @@ void TabDivePhotos::updateData() divePictureModel->updateDivePictures(); } +void TabDivePhotos::changeZoomLevel(int delta) +{ + // We count on QSlider doing bound checks + ui->zoomSlider->setValue(ui->zoomSlider->value() + delta); +} diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.h b/desktop-widgets/tab-widgets/TabDivePhotos.h index 9b711595c..e2e7aa05c 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.h +++ b/desktop-widgets/tab-widgets/TabDivePhotos.h @@ -26,6 +26,7 @@ private slots: void addPhotosFromURL(); void removeAllPhotos(); void removeSelectedPhotos(); + void changeZoomLevel(int delta); private: Ui::TabDivePhotos *ui; diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.ui b/desktop-widgets/tab-widgets/TabDivePhotos.ui index 35cfd375a..21e4544e6 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.ui +++ b/desktop-widgets/tab-widgets/TabDivePhotos.ui @@ -21,6 +21,42 @@ + + + + + + Zoom level + + + + + + + -10 + + + 10 + + + 1 + + + 1 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 1 + + + + + -- cgit v1.2.3-70-g09d2