blob: 718edf997b5de9141b1b1687c7a32030d6424ba6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 ();
}
}
|