-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImageViewer.cpp
63 lines (52 loc) · 1.32 KB
/
ImageViewer.cpp
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
#include "ImageViewer.h"
ImageViewer::ImageViewer(QWidget *parent):QGraphicsView(parent)
{
}
ImageViewer::~ImageViewer()
{
}
void ImageViewer::wheelEvent(QWheelEvent *event) {
if (event->orientation() == Qt::Vertical) {
double angleDeltaY = event->angleDelta().y();
double zoomFactor = qPow(1.0015, angleDeltaY);
scale(zoomFactor, zoomFactor);
if (angleDeltaY > 0) {
this->centerOn(sceneMousePos);
sceneMousePos = this->mapToScene(event->pos());
}
this->viewport()->update();
event->accept();
}
else {
event->ignore();
}
}
/*
void ImageViewer::mouseMoveEvent(QMouseEvent *event) {
if (moving) {
QPointF disPointF = event->pos() - previousPos;
previousPos = event->pos();
this->scene()->setSceneRect(this->scene()->sceneRect().x() - disPointF.x(),
this->scene()->sceneRect().y() - disPointF.y(),
this->scene()->sceneRect().width(),
this->scene()->sceneRect().height());
this->scene()->update();
}
QGraphicsView::mouseMoveEvent(event);
}
void ImageViewer::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::MiddleButton) {
previousPos = event->pos();
moving = true;
}
QGraphicsView::mousePressEvent(event);
}
void ImageViewer::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::MiddleButton) {
moving = false;
}
QGraphicsView::mouseReleaseEvent(event);
}
*/