diff options
author | Ken Moore <ken@ixsystems.com> | 2018-11-12 08:40:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-12 08:40:43 -0500 |
commit | 5bcc42fad54ed70469877b5a74becdf792ecdcea (patch) | |
tree | 4bded7bcc733abef2ec9eebd63e6fa965feac198 /src-qt5/desktop-utils/lumina-photo/PhotoView.cpp | |
parent | Merge pull request #634 from lbartoletti/new_folder (diff) | |
parent | q5sys review: (diff) | |
download | lumina-5bcc42fad54ed70469877b5a74becdf792ecdcea.tar.gz lumina-5bcc42fad54ed70469877b5a74becdf792ecdcea.tar.bz2 lumina-5bcc42fad54ed70469877b5a74becdf792ecdcea.zip |
Merge pull request #626 from lbartoletti/lumina-photo
New desktop utils: lumina-photo
Diffstat (limited to 'src-qt5/desktop-utils/lumina-photo/PhotoView.cpp')
-rw-r--r-- | src-qt5/desktop-utils/lumina-photo/PhotoView.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src-qt5/desktop-utils/lumina-photo/PhotoView.cpp b/src-qt5/desktop-utils/lumina-photo/PhotoView.cpp new file mode 100644 index 00000000..718edf99 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-photo/PhotoView.cpp @@ -0,0 +1,81 @@ + +#include "PhotoView.h" +#include <QDebug> +#include <QWheelEvent> + +PhotoView::PhotoView (QWidget *parent) : QGraphicsView (parent) +{ + setCacheMode (CacheBackground); + setViewportUpdateMode (BoundingRectViewportUpdate); + setRenderHint (QPainter::HighQualityAntialiasing); + setTransformationAnchor (AnchorUnderMouse); +} + +void PhotoView::zoomIn () +{ + scale (scaleFactor, scaleFactor); + isFit = false; +} + +void PhotoView::zoomOut () +{ + scale (invScaleFactor, invScaleFactor); + isFit = false; +} + +void PhotoView::zoomNormal () +{ + resetMatrix (); + isFit = false; +} + +void PhotoView::zoomFit () +{ + fitInView (sceneRect (), Qt::KeepAspectRatio); + isFit = true; +} + +bool PhotoView::eventFilter (QObject *, QEvent *event) +{ + if (event->type () == QEvent::Wheel) + { + QWheelEvent *wheel_event = static_cast<QWheelEvent *> (event); + if (wheel_event->delta () > 0) + { + if (wheel_event->modifiers () == Qt::ControlModifier) + { + emit nextImage (); + } + else + { + scale (scaleFactor, scaleFactor); + return true; + } + } + else if (wheel_event->delta () < 0) + { + if (wheel_event->modifiers () == Qt::ControlModifier) + { + emit prevImage (); + } + else + { + scale (invScaleFactor, invScaleFactor); + return true; + } + } + } + + return false; +} + +void PhotoView::mouseDoubleClickEvent (QMouseEvent *event) +{ + if (event->button () == Qt::LeftButton) + { + if (isFit) + zoomNormal (); + else + zoomFit (); + } +} |