comparison widgets/Panner.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents cb51d061cc25
children d39db4673676
comparison
equal deleted inserted replaced
1183:57d192e26331 1324:13d9b422f7fe
17 17
18 #include <QMouseEvent> 18 #include <QMouseEvent>
19 #include <QPaintEvent> 19 #include <QPaintEvent>
20 #include <QWheelEvent> 20 #include <QWheelEvent>
21 #include <QPainter> 21 #include <QPainter>
22
23 #include "WidgetScale.h"
22 24
23 #include <iostream> 25 #include <iostream>
24 #include <cmath> 26 #include <cmath>
25 27
26 Panner::Panner(QWidget *parent) : 28 Panner::Panner(QWidget *parent) :
60 } 62 }
61 63
62 void 64 void
63 Panner::scroll(bool up) 65 Panner::scroll(bool up)
64 { 66 {
67 scroll(up, 1);
68 }
69
70 void
71 Panner::scroll(bool up, int count)
72 {
65 float unit = m_scrollUnit; 73 float unit = m_scrollUnit;
66 if (unit == 0.f) { 74 if (unit == 0.f) {
67 unit = float(m_rectHeight) / (6 * float(height())); 75 unit = float(m_rectHeight) / (6 * float(height()));
68 if (unit < 0.01f) unit = 0.01f; 76 if (unit < 0.01f) unit = 0.01f;
69 } 77 }
70 78
71 if (!up) { 79 if (!up) {
72 m_rectY += unit; 80 m_rectY += unit * float(count);
73 } else { 81 } else {
74 m_rectY -= unit; 82 m_rectY -= unit * float(count);
75 } 83 }
76 84
77 normalise(); 85 normalise();
78 emitAndUpdate(); 86 emitAndUpdate();
79 } 87 }
130 } 138 }
131 139
132 void 140 void
133 Panner::wheelEvent(QWheelEvent *e) 141 Panner::wheelEvent(QWheelEvent *e)
134 { 142 {
135 scroll(e->delta() > 0); 143 int delta = m_wheelCounter.count(e);
144 scroll(delta > 0, abs(delta));
136 } 145 }
137 146
138 void 147 void
139 Panner::enterEvent(QEvent *) 148 Panner::enterEvent(QEvent *)
140 { 149 {
154 paint.setRenderHint(QPainter::Antialiasing, false); 163 paint.setRenderHint(QPainter::Antialiasing, false);
155 164
156 QColor bg(palette().background().color()); 165 QColor bg(palette().background().color());
157 bg.setAlpha(m_backgroundAlpha); 166 bg.setAlpha(m_backgroundAlpha);
158 167
159 paint.setPen(palette().dark().color()); 168 int penWidth = WidgetScale::scalePixelSize(1);
169 if (penWidth < 1) penWidth = 1;
170 paint.setPen(QPen(palette().dark().color(), penWidth));
171
160 paint.setBrush(bg); 172 paint.setBrush(bg);
161 paint.drawRect(0, 0, width()-1, height()-1); 173 paint.drawRect(penWidth/2, penWidth/2,
174 width()-penWidth/2-1, height()-penWidth/2-1);
162 175
163 QColor hl(m_thumbColour); 176 QColor hl(m_thumbColour);
164 hl.setAlpha(m_thumbAlpha); 177 hl.setAlpha(m_thumbAlpha);
165 178
166 paint.setBrush(hl); 179 paint.setBrush(hl);