Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@45
|
2
|
cannam@45
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
cannam@45
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@57
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@57
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@57
|
10
|
cannam@45
|
11 This program is free software; you can redistribute it and/or
|
cannam@45
|
12 modify it under the terms of the GNU General Public License as
|
cannam@45
|
13 published by the Free Software Foundation; either version 2 of the
|
cannam@45
|
14 License, or (at your option) any later version. See the file
|
cannam@45
|
15 COPYING included with this distribution for more information.
|
cannam@45
|
16 */
|
cannam@45
|
17
|
cannam@45
|
18 #include "panned.h"
|
cannam@45
|
19
|
cannam@45
|
20 #include <QScrollBar>
|
Chris@53
|
21 #include <QWheelEvent>
|
cannam@45
|
22
|
cannam@45
|
23 #include <iostream>
|
cannam@45
|
24
|
cannam@45
|
25 Panned::Panned()
|
cannam@45
|
26 {
|
Chris@56
|
27 setRenderHints(QPainter::Antialiasing |
|
Chris@56
|
28 QPainter::TextAntialiasing);
|
cannam@45
|
29 }
|
cannam@45
|
30
|
cannam@45
|
31 void
|
cannam@45
|
32 Panned::resizeEvent(QResizeEvent *ev)
|
cannam@45
|
33 {
|
Chris@60
|
34 QPointF nearpt = mapToScene(0, 0);
|
Chris@60
|
35 QPointF farpt = mapToScene(width(), height());
|
Chris@60
|
36 QSizeF sz(farpt.x()-nearpt.x(), farpt.y()-nearpt.y());
|
Chris@60
|
37 QRectF pr(nearpt, sz);
|
cannam@45
|
38
|
cannam@45
|
39 if (pr != m_pannedRect) {
|
cannam@45
|
40 m_pannedRect = pr;
|
cannam@45
|
41 emit pannedRectChanged(pr);
|
cannam@45
|
42 }
|
cannam@45
|
43
|
cannam@45
|
44 QGraphicsView::resizeEvent(ev);
|
cannam@45
|
45 }
|
cannam@45
|
46
|
cannam@45
|
47 void
|
cannam@45
|
48 Panned::paintEvent(QPaintEvent *e)
|
cannam@45
|
49 {
|
cannam@45
|
50 QGraphicsView::paintEvent(e);
|
cannam@45
|
51 }
|
cannam@45
|
52
|
cannam@45
|
53 void
|
cannam@45
|
54 Panned::drawForeground(QPainter *paint, const QRectF &)
|
cannam@45
|
55 {
|
Chris@60
|
56 QPointF nearpt = mapToScene(0, 0);
|
Chris@60
|
57 QPointF farpt = mapToScene(width(), height());
|
Chris@60
|
58 QSizeF sz(farpt.x()-nearpt.x(), farpt.y()-nearpt.y());
|
Chris@60
|
59 QRectF pr(nearpt, sz);
|
cannam@45
|
60
|
cannam@45
|
61 if (pr != m_pannedRect) {
|
cannam@45
|
62 if (pr.x() != m_pannedRect.x()) emit pannedContentsScrolled();
|
cannam@45
|
63 m_pannedRect = pr;
|
cannam@45
|
64 emit pannedRectChanged(pr);
|
cannam@45
|
65 }
|
cannam@45
|
66 }
|
cannam@45
|
67
|
cannam@45
|
68 void
|
Chris@53
|
69 Panned::zoomIn()
|
Chris@53
|
70 {
|
Chris@53
|
71 QMatrix m = matrix();
|
Chris@53
|
72 m.scale(1.0 / 1.1, 1.0 / 1.1);
|
Chris@53
|
73 setMatrix(m);
|
Chris@53
|
74 }
|
Chris@53
|
75
|
Chris@53
|
76 void
|
Chris@53
|
77 Panned::zoomOut()
|
Chris@53
|
78 {
|
Chris@53
|
79 QMatrix m = matrix();
|
Chris@53
|
80 m.scale(1.1, 1.1);
|
Chris@53
|
81 setMatrix(m);
|
Chris@53
|
82 }
|
Chris@53
|
83
|
Chris@53
|
84 void
|
cannam@45
|
85 Panned::slotSetPannedRect(QRectF pr)
|
cannam@45
|
86 {
|
cannam@45
|
87 centerOn(pr.center());
|
cannam@45
|
88 // setSceneRect(pr);
|
cannam@45
|
89 // m_pannedRect = pr;
|
cannam@45
|
90 }
|
cannam@45
|
91
|
cannam@45
|
92 void
|
cannam@45
|
93 Panned::wheelEvent(QWheelEvent *ev)
|
cannam@45
|
94 {
|
Chris@53
|
95 if (ev->modifiers() & Qt::ControlModifier) {
|
Chris@53
|
96 int d = ev->delta();
|
Chris@53
|
97 if (d > 0) {
|
Chris@53
|
98 while (d > 0) {
|
Chris@53
|
99 zoomOut();
|
Chris@53
|
100 d -= 120;
|
Chris@53
|
101 }
|
Chris@53
|
102 } else {
|
Chris@53
|
103 while (d < 0) {
|
Chris@53
|
104 zoomIn();
|
Chris@53
|
105 d += 120;
|
Chris@53
|
106 }
|
Chris@53
|
107 }
|
Chris@53
|
108 } else {
|
Chris@53
|
109 emit wheelEventReceived(ev);
|
Chris@53
|
110 QGraphicsView::wheelEvent(ev);
|
Chris@53
|
111 }
|
cannam@45
|
112 }
|
cannam@45
|
113
|
cannam@45
|
114 void
|
cannam@45
|
115 Panned::slotEmulateWheelEvent(QWheelEvent *ev)
|
cannam@45
|
116 {
|
cannam@45
|
117 QGraphicsView::wheelEvent(ev);
|
cannam@45
|
118 }
|
cannam@45
|
119
|
cannam@45
|
120 void
|
cannam@45
|
121 Panned::leaveEvent(QEvent *)
|
cannam@45
|
122 {
|
cannam@45
|
123 emit mouseLeaves();
|
cannam@45
|
124 }
|