diff options
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 (); + } +} |