-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
78 lines (72 loc) · 1.49 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <mainwin.h>
void MLabel::mousePressEvent(QMouseEvent *ev) {
switch (ev->button()) {
case Qt::LeftButton:
posx = ev->x();
posy = ev->y();
break;
case Qt::RightButton:
dx = (dx | 7) - 7;
dy = (dy | 7) - 7;
emit mMove();
break;
case Qt::MiddleButton:
dx = (dx + 128) / magX - 128;
dy = (dy + 96) / magY - 96;
magX = magY = 1.0;
emit mZoom();
break;
default:
break;
}
}
void MLabel::shift(int sx, int sy) {
dx += sx;
dy += sy;
posx += sx;
posy += sy;
emit mMove();
}
void MLabel::mouseMoveEvent(QMouseEvent *ev) {
if (!(ev->buttons() & Qt::LeftButton)) return;
if (!(ev->modifiers() & Qt::ControlModifier))
dx -= (ev->x() - posx);
if (!(ev->modifiers() & Qt::ShiftModifier))
dy -= (ev->y() - posy);
posx = ev->x();
posy = ev->y();
emit mMove();
}
void MLabel::wheelEvent(QWheelEvent* ev) {
float oldMagX = magX;
float oldMagY = magY;
if (ev->delta() < 0) {
if ((magX > 0.1) && (magY > 0.1)) {
magX /= 1.1;
magY /= 1.1;
}
} else {
if ((magX < 4.0) && (magY < 16.0)) {
magX *= 1.1;
magY *= 1.1;
}
}
dx = (dx + 128) * magX / oldMagX - 128;
dy = (dy + 96) * magY / oldMagY - 96;
emit mZoom();
}
void MLabel::setMag(double xmag, double ymag) {
float oldMagX = magX;
float oldMagY = magY;
magX = xmag;
magY = ymag;
dx = (dx + 128) * magX / oldMagX - 128;
dy = (dy + 96) * magY / oldMagY - 96;
emit mZoom();
}
int main(int ac, char** av) {
QApplication app(ac,av);
MWin win(NULL);
win.show();
return app.exec();
}