Chris@0
|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 A waveform viewer and audio annotation editor.
|
Chris@5
|
5 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@0
|
6
|
Chris@0
|
7 This is experimental software. Not for distribution.
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 #include "widgets/Pane.h"
|
Chris@0
|
11 #include "base/Layer.h"
|
Chris@0
|
12 #include "base/Model.h"
|
Chris@0
|
13 #include "base/ZoomConstraint.h"
|
Chris@0
|
14 #include "base/RealTime.h"
|
Chris@0
|
15 #include "base/Profiler.h"
|
Chris@13
|
16 #include "base/ViewManager.h"
|
Chris@0
|
17
|
Chris@0
|
18 #include <QPaintEvent>
|
Chris@0
|
19 #include <QPainter>
|
Chris@0
|
20 #include <iostream>
|
Chris@0
|
21 #include <cmath>
|
Chris@0
|
22
|
Chris@0
|
23 using std::cerr;
|
Chris@0
|
24 using std::endl;
|
Chris@0
|
25
|
Chris@0
|
26 Pane::Pane(QWidget *w) :
|
Chris@0
|
27 View(w, true),
|
Chris@0
|
28 m_identifyFeatures(false),
|
Chris@0
|
29 m_clickedInRange(false),
|
Chris@0
|
30 m_shiftPressed(false),
|
Chris@13
|
31 m_ctrlPressed(false),
|
Chris@0
|
32 m_centreLineVisible(true)
|
Chris@0
|
33 {
|
Chris@0
|
34 setObjectName("Pane");
|
Chris@0
|
35 setMouseTracking(true);
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 bool
|
Chris@0
|
39 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos)
|
Chris@0
|
40 {
|
Chris@0
|
41 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@0
|
42 --vi;
|
Chris@0
|
43 if (layer != *vi) return false;
|
Chris@0
|
44 pos = m_identifyPoint;
|
Chris@0
|
45 return m_identifyFeatures;
|
Chris@0
|
46 }
|
Chris@0
|
47
|
Chris@0
|
48 return false;
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 void
|
Chris@0
|
52 Pane::setCentreLineVisible(bool visible)
|
Chris@0
|
53 {
|
Chris@0
|
54 m_centreLineVisible = visible;
|
Chris@0
|
55 update();
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 void
|
Chris@0
|
59 Pane::paintEvent(QPaintEvent *e)
|
Chris@0
|
60 {
|
Chris@0
|
61 QPainter paint;
|
Chris@0
|
62
|
Chris@0
|
63 QRect r(rect());
|
Chris@0
|
64
|
Chris@0
|
65 if (e) {
|
Chris@0
|
66 r = e->rect();
|
Chris@0
|
67 }
|
Chris@0
|
68 /*
|
Chris@0
|
69 paint.begin(this);
|
Chris@0
|
70 paint.setClipRect(r);
|
Chris@0
|
71
|
Chris@0
|
72 if (hasLightBackground()) {
|
Chris@0
|
73 paint.setPen(Qt::white);
|
Chris@0
|
74 paint.setBrush(Qt::white);
|
Chris@0
|
75 } else {
|
Chris@0
|
76 paint.setPen(Qt::black);
|
Chris@0
|
77 paint.setBrush(Qt::black);
|
Chris@0
|
78 }
|
Chris@0
|
79 paint.drawRect(r);
|
Chris@0
|
80
|
Chris@0
|
81 paint.end();
|
Chris@0
|
82 */
|
Chris@0
|
83 View::paintEvent(e);
|
Chris@0
|
84
|
Chris@0
|
85 paint.begin(this);
|
Chris@0
|
86
|
Chris@0
|
87 if (e) {
|
Chris@0
|
88 paint.setClipRect(r);
|
Chris@0
|
89 }
|
Chris@0
|
90
|
Chris@0
|
91 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@0
|
92 --vi;
|
Chris@0
|
93
|
Chris@0
|
94 int sw = (*vi)->getVerticalScaleWidth(paint);
|
Chris@0
|
95
|
Chris@0
|
96 if (sw > 0 && r.left() < sw) {
|
Chris@0
|
97
|
Chris@0
|
98 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
|
Chris@0
|
99
|
Chris@0
|
100 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
|
Chris@0
|
101 paint.save();
|
Chris@0
|
102
|
Chris@0
|
103 paint.setPen(Qt::black);
|
Chris@0
|
104 paint.setBrush(Qt::white);
|
Chris@0
|
105 paint.drawRect(0, 0, sw, height());
|
Chris@0
|
106
|
Chris@0
|
107 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
108 (*vi)->paintVerticalScale(paint, QRect(0, 0, sw, height()));
|
Chris@0
|
109
|
Chris@0
|
110 paint.restore();
|
Chris@0
|
111 }
|
Chris@0
|
112
|
Chris@0
|
113 if (m_identifyFeatures) {
|
Chris@0
|
114 QRect descRect = (*vi)->getFeatureDescriptionRect(paint,
|
Chris@0
|
115 m_identifyPoint);
|
Chris@0
|
116 if (descRect.width() > 0 && descRect.height() > 0 &&
|
Chris@0
|
117 r.left() + r.width() >= width() - descRect.width() &&
|
Chris@0
|
118 r.top() < descRect.height()) {
|
Chris@0
|
119
|
Chris@0
|
120 // Profiler profiler("Pane::paintEvent - painting local feature description", true);
|
Chris@0
|
121
|
Chris@0
|
122 // std::cerr << "Pane::paintEvent: calling paint.save() in feature description block" << std::endl;
|
Chris@0
|
123 paint.save();
|
Chris@0
|
124
|
Chris@0
|
125 paint.setPen(Qt::black);
|
Chris@0
|
126 paint.setBrush(Qt::white);
|
Chris@0
|
127
|
Chris@0
|
128 QRect rect(width() - descRect.width() - 1, 0,
|
Chris@0
|
129 descRect.width(), descRect.height());
|
Chris@0
|
130
|
Chris@0
|
131 paint.drawRect(rect);
|
Chris@0
|
132
|
Chris@0
|
133 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
134 (*vi)->paintLocalFeatureDescription(paint, rect, m_identifyPoint);
|
Chris@0
|
135
|
Chris@0
|
136 paint.restore();
|
Chris@0
|
137 }
|
Chris@0
|
138 }
|
Chris@0
|
139
|
Chris@0
|
140 break;
|
Chris@0
|
141 }
|
Chris@0
|
142
|
Chris@0
|
143 if (m_centreLineVisible) {
|
Chris@0
|
144
|
Chris@0
|
145 if (hasLightBackground()) {
|
Chris@0
|
146 paint.setPen(QColor(50, 50, 50));
|
Chris@0
|
147 } else {
|
Chris@0
|
148 paint.setPen(QColor(200, 200, 200));
|
Chris@0
|
149 }
|
Chris@0
|
150 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
151 paint.drawLine(width() / 2, 0, width() / 2, height() - 1);
|
Chris@0
|
152
|
Chris@0
|
153 // QFont font(paint.font());
|
Chris@0
|
154 // font.setBold(true);
|
Chris@0
|
155 // paint.setFont(font);
|
Chris@0
|
156
|
Chris@0
|
157 int sampleRate = getModelsSampleRate();
|
Chris@0
|
158 int y = height() - paint.fontMetrics().height()
|
Chris@0
|
159 + paint.fontMetrics().ascent() - 6;
|
Chris@0
|
160
|
Chris@0
|
161 LayerList::iterator vi = m_layers.end();
|
Chris@0
|
162
|
Chris@0
|
163 if (vi != m_layers.begin()) {
|
Chris@0
|
164
|
Chris@0
|
165 switch ((*--vi)->getPreferredFrameCountPosition()) {
|
Chris@0
|
166
|
Chris@0
|
167 case Layer::PositionTop:
|
Chris@0
|
168 y = paint.fontMetrics().ascent() + 6;
|
Chris@0
|
169 break;
|
Chris@0
|
170
|
Chris@0
|
171 case Layer::PositionMiddle:
|
Chris@0
|
172 y = (height() - paint.fontMetrics().height()) / 2
|
Chris@0
|
173 + paint.fontMetrics().ascent();
|
Chris@0
|
174 break;
|
Chris@0
|
175
|
Chris@0
|
176 case Layer::PositionBottom:
|
Chris@0
|
177 // y already set correctly
|
Chris@0
|
178 break;
|
Chris@0
|
179 }
|
Chris@0
|
180 }
|
Chris@0
|
181
|
Chris@0
|
182 if (sampleRate) {
|
Chris@0
|
183
|
Chris@0
|
184 QString text(QString::fromStdString
|
Chris@0
|
185 (RealTime::frame2RealTime
|
Chris@0
|
186 (m_centreFrame, sampleRate).toText(true)));
|
Chris@0
|
187
|
Chris@0
|
188 int tw = paint.fontMetrics().width(text);
|
Chris@0
|
189 int x = width()/2 - 4 - tw;
|
Chris@0
|
190
|
Chris@0
|
191 if (hasLightBackground()) {
|
Chris@0
|
192 paint.setPen(palette().background().color());
|
Chris@0
|
193 for (int dx = -1; dx <= 1; ++dx) {
|
Chris@0
|
194 for (int dy = -1; dy <= 1; ++dy) {
|
Chris@0
|
195 if ((dx && dy) || !(dx || dy)) continue;
|
Chris@0
|
196 paint.drawText(x + dx, y + dy, text);
|
Chris@0
|
197 }
|
Chris@0
|
198 }
|
Chris@0
|
199 paint.setPen(QColor(50, 50, 50));
|
Chris@0
|
200 } else {
|
Chris@0
|
201 paint.setPen(QColor(200, 200, 200));
|
Chris@0
|
202 }
|
Chris@0
|
203
|
Chris@0
|
204 paint.drawText(x, y, text);
|
Chris@0
|
205 }
|
Chris@0
|
206
|
Chris@0
|
207 QString text = QString("%1").arg(m_centreFrame);
|
Chris@0
|
208
|
Chris@0
|
209 int tw = paint.fontMetrics().width(text);
|
Chris@0
|
210 int x = width()/2 + 4;
|
Chris@0
|
211
|
Chris@0
|
212 if (hasLightBackground()) {
|
Chris@0
|
213 paint.setPen(palette().background().color());
|
Chris@0
|
214 for (int dx = -1; dx <= 1; ++dx) {
|
Chris@0
|
215 for (int dy = -1; dy <= 1; ++dy) {
|
Chris@0
|
216 if ((dx && dy) || !(dx || dy)) continue;
|
Chris@0
|
217 paint.drawText(x + dx, y + dy, text);
|
Chris@0
|
218 }
|
Chris@0
|
219 }
|
Chris@0
|
220 paint.setPen(QColor(50, 50, 50));
|
Chris@0
|
221 } else {
|
Chris@0
|
222 paint.setPen(QColor(200, 200, 200));
|
Chris@0
|
223 }
|
Chris@0
|
224 paint.drawText(x, y, text);
|
Chris@0
|
225 }
|
Chris@0
|
226
|
Chris@0
|
227 if (m_clickedInRange && m_shiftPressed) {
|
Chris@13
|
228 //!!! be nice if this looked a bit more in keeping with the
|
Chris@13
|
229 //selection block
|
Chris@0
|
230 paint.setPen(Qt::blue);
|
Chris@0
|
231 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
|
Chris@0
|
232 m_mousePos.x() - m_clickPos.x(),
|
Chris@0
|
233 m_mousePos.y() - m_clickPos.y());
|
Chris@0
|
234 }
|
Chris@0
|
235
|
Chris@0
|
236 paint.end();
|
Chris@0
|
237 }
|
Chris@0
|
238
|
Chris@0
|
239 void
|
Chris@0
|
240 Pane::mousePressEvent(QMouseEvent *e)
|
Chris@0
|
241 {
|
Chris@0
|
242 m_clickPos = e->pos();
|
Chris@0
|
243 m_clickedInRange = true;
|
Chris@0
|
244 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@13
|
245 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@13
|
246
|
Chris@13
|
247 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
248 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
249
|
Chris@13
|
250 if (mode == ViewManager::NavigateMode) {
|
Chris@13
|
251
|
Chris@13
|
252 m_dragCentreFrame = m_centreFrame;
|
Chris@13
|
253
|
Chris@13
|
254 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
255
|
Chris@13
|
256 int mouseFrame = e->x() * m_zoomLevel + getStartFrame();
|
Chris@13
|
257 size_t resolution = 1;
|
Chris@13
|
258 int snapFrame = mouseFrame;
|
Chris@13
|
259
|
Chris@13
|
260 Layer *layer = getSelectedLayer();
|
Chris@13
|
261 if (layer) {
|
Chris@13
|
262 snapFrame = layer->getNearestFeatureFrame(mouseFrame, resolution,
|
Chris@13
|
263 false);
|
Chris@13
|
264 }
|
Chris@13
|
265
|
Chris@13
|
266 if (snapFrame < 0) snapFrame = 0;
|
Chris@13
|
267 m_selectionStartFrame = snapFrame;
|
Chris@13
|
268 if (m_manager) {
|
Chris@13
|
269 m_manager->setInProgressSelection(Selection(snapFrame,
|
Chris@13
|
270 snapFrame + resolution),
|
Chris@13
|
271 !m_ctrlPressed);
|
Chris@13
|
272 }
|
Chris@13
|
273 update();
|
Chris@13
|
274 }
|
Chris@0
|
275
|
Chris@0
|
276 emit paneInteractedWith();
|
Chris@0
|
277 }
|
Chris@0
|
278
|
Chris@0
|
279 void
|
Chris@0
|
280 Pane::mouseReleaseEvent(QMouseEvent *e)
|
Chris@0
|
281 {
|
Chris@13
|
282 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
283 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
284
|
Chris@0
|
285 if (m_clickedInRange) {
|
Chris@0
|
286 mouseMoveEvent(e);
|
Chris@0
|
287 }
|
Chris@0
|
288
|
Chris@13
|
289 if (mode == ViewManager::NavigateMode) {
|
Chris@0
|
290
|
Chris@13
|
291 if (m_shiftPressed) {
|
Chris@0
|
292
|
Chris@13
|
293 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
|
Chris@13
|
294 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
|
Chris@13
|
295 int w = x1 - x0;
|
Chris@13
|
296
|
Chris@13
|
297 long newStartFrame = getStartFrame() + m_zoomLevel * x0;
|
Chris@13
|
298
|
Chris@13
|
299 if (newStartFrame <= -long(width() * m_zoomLevel)) {
|
Chris@13
|
300 newStartFrame = -long(width() * m_zoomLevel) + 1;
|
Chris@13
|
301 }
|
Chris@13
|
302
|
Chris@13
|
303 if (newStartFrame >= long(getModelsEndFrame())) {
|
Chris@13
|
304 newStartFrame = getModelsEndFrame() - 1;
|
Chris@13
|
305 }
|
Chris@13
|
306
|
Chris@13
|
307 float ratio = float(w) / float(width());
|
Chris@13
|
308 // std::cerr << "ratio: " << ratio << std::endl;
|
Chris@13
|
309 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
|
Chris@13
|
310 if (newZoomLevel < 1) newZoomLevel = 1;
|
Chris@13
|
311
|
Chris@13
|
312 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
|
Chris@13
|
313 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
|
Chris@13
|
314 setStartFrame(newStartFrame);
|
Chris@13
|
315
|
Chris@13
|
316 //cerr << "mouseReleaseEvent: start frame now " << m_startFrame << endl;
|
Chris@13
|
317 // update();
|
Chris@0
|
318 }
|
Chris@0
|
319
|
Chris@13
|
320 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
321
|
Chris@13
|
322 if (m_manager && m_manager->haveInProgressSelection()) {
|
Chris@13
|
323
|
Chris@13
|
324 bool exclusive;
|
Chris@13
|
325 Selection selection = m_manager->getInProgressSelection(exclusive);
|
Chris@13
|
326
|
Chris@13
|
327 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
|
Chris@13
|
328 selection = Selection();
|
Chris@13
|
329 }
|
Chris@13
|
330
|
Chris@13
|
331 m_manager->clearInProgressSelection();
|
Chris@13
|
332
|
Chris@13
|
333 if (exclusive) {
|
Chris@13
|
334 m_manager->setSelection(selection);
|
Chris@13
|
335 } else {
|
Chris@13
|
336 m_manager->addSelection(selection);
|
Chris@13
|
337 }
|
Chris@0
|
338 }
|
Chris@13
|
339
|
Chris@13
|
340 update();
|
Chris@13
|
341 }
|
Chris@0
|
342
|
Chris@0
|
343 m_clickedInRange = false;
|
Chris@0
|
344
|
Chris@0
|
345 emit paneInteractedWith();
|
Chris@0
|
346 }
|
Chris@0
|
347
|
Chris@0
|
348 void
|
Chris@0
|
349 Pane::mouseMoveEvent(QMouseEvent *e)
|
Chris@0
|
350 {
|
Chris@13
|
351 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
352 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
353
|
Chris@0
|
354 if (!m_clickedInRange) {
|
Chris@0
|
355
|
Chris@0
|
356 // std::cerr << "Pane: calling identifyLocalFeatures" << std::endl;
|
Chris@0
|
357
|
Chris@0
|
358 //!!! identifyLocalFeatures(true, e->x(), e->y());
|
Chris@0
|
359
|
Chris@0
|
360 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@0
|
361 QPoint prevPoint = m_identifyPoint;
|
Chris@0
|
362
|
Chris@0
|
363 m_identifyFeatures = true;
|
Chris@0
|
364 m_identifyPoint = e->pos();
|
Chris@0
|
365
|
Chris@0
|
366 if (m_identifyFeatures != previouslyIdentifying ||
|
Chris@0
|
367 m_identifyPoint != prevPoint) {
|
Chris@0
|
368 update();
|
Chris@0
|
369 }
|
Chris@0
|
370
|
Chris@13
|
371 return;
|
Chris@13
|
372
|
Chris@13
|
373 }
|
Chris@0
|
374
|
Chris@13
|
375 if (mode == ViewManager::NavigateMode) {
|
Chris@0
|
376
|
Chris@13
|
377 if (m_shiftPressed) {
|
Chris@0
|
378
|
Chris@13
|
379 m_mousePos = e->pos();
|
Chris@13
|
380 update();
|
Chris@0
|
381
|
Chris@0
|
382 } else {
|
Chris@13
|
383
|
Chris@13
|
384 long xoff = int(e->x()) - int(m_clickPos.x());
|
Chris@13
|
385 long frameOff = xoff * m_zoomLevel;
|
Chris@13
|
386
|
Chris@13
|
387 size_t newCentreFrame = m_dragCentreFrame;
|
Chris@13
|
388
|
Chris@13
|
389 if (frameOff < 0) {
|
Chris@13
|
390 newCentreFrame -= frameOff;
|
Chris@13
|
391 } else if (newCentreFrame >= size_t(frameOff)) {
|
Chris@13
|
392 newCentreFrame -= frameOff;
|
Chris@13
|
393 } else {
|
Chris@13
|
394 newCentreFrame = 0;
|
Chris@13
|
395 }
|
Chris@13
|
396
|
Chris@13
|
397 if (newCentreFrame >= getModelsEndFrame()) {
|
Chris@13
|
398 newCentreFrame = getModelsEndFrame();
|
Chris@13
|
399 if (newCentreFrame > 0) --newCentreFrame;
|
Chris@13
|
400 }
|
Chris@13
|
401
|
Chris@13
|
402 if (std::max(m_centreFrame, newCentreFrame) -
|
Chris@13
|
403 std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) {
|
Chris@13
|
404 setCentreFrame(newCentreFrame);
|
Chris@13
|
405 }
|
Chris@0
|
406 }
|
Chris@0
|
407
|
Chris@13
|
408 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
409
|
Chris@13
|
410 int mouseFrame = e->x() * m_zoomLevel + getStartFrame();
|
Chris@13
|
411 size_t resolution = 1;
|
Chris@13
|
412 int snapFrameLeft = mouseFrame;
|
Chris@13
|
413 int snapFrameRight = mouseFrame;
|
Chris@13
|
414
|
Chris@13
|
415 Layer *layer = getSelectedLayer();
|
Chris@13
|
416 if (layer) {
|
Chris@13
|
417 snapFrameLeft = layer->getNearestFeatureFrame(mouseFrame, resolution,
|
Chris@13
|
418 false);
|
Chris@13
|
419 snapFrameRight = layer->getNearestFeatureFrame(mouseFrame, resolution,
|
Chris@13
|
420 true);
|
Chris@13
|
421 }
|
Chris@13
|
422
|
Chris@13
|
423 if (snapFrameLeft < 0) snapFrameLeft = 0;
|
Chris@13
|
424 if (snapFrameRight < 0) snapFrameRight = 0;
|
Chris@13
|
425
|
Chris@13
|
426 size_t min, max;
|
Chris@13
|
427
|
Chris@13
|
428 if (m_selectionStartFrame > snapFrameLeft) {
|
Chris@13
|
429 min = snapFrameLeft;
|
Chris@13
|
430 max = m_selectionStartFrame;
|
Chris@13
|
431 } else if (snapFrameRight > m_selectionStartFrame) {
|
Chris@13
|
432 min = m_selectionStartFrame;
|
Chris@13
|
433 max = snapFrameRight;
|
Chris@13
|
434 } else {
|
Chris@13
|
435 min = snapFrameLeft;
|
Chris@13
|
436 max = snapFrameRight;
|
Chris@0
|
437 }
|
Chris@0
|
438
|
Chris@13
|
439 if (m_manager) {
|
Chris@13
|
440 m_manager->setInProgressSelection(Selection(min, max),
|
Chris@13
|
441 !m_ctrlPressed);
|
Chris@0
|
442 }
|
Chris@13
|
443
|
Chris@13
|
444 if (!m_manager || !m_manager->isPlaying()) {
|
Chris@13
|
445 int offset = mouseFrame - getStartFrame();
|
Chris@13
|
446 int available = getEndFrame() - getStartFrame();
|
Chris@13
|
447 if (offset >= available * 0.9) {
|
Chris@13
|
448 setCentreFrame(m_centreFrame + int(offset - available * 0.9) + 1);
|
Chris@13
|
449 } else if (offset <= available * 0.15) {
|
Chris@13
|
450 setCentreFrame(m_centreFrame - int(available * 0.15 - offset) - 1);
|
Chris@13
|
451 }
|
Chris@13
|
452 }
|
Chris@13
|
453
|
Chris@13
|
454 update();
|
Chris@0
|
455 }
|
Chris@0
|
456 }
|
Chris@0
|
457
|
Chris@0
|
458 void
|
Chris@0
|
459 Pane::mouseDoubleClickEvent(QMouseEvent *e)
|
Chris@0
|
460 {
|
Chris@0
|
461 std::cerr << "mouseDoubleClickEvent" << std::endl;
|
Chris@0
|
462 }
|
Chris@0
|
463
|
Chris@0
|
464 void
|
Chris@0
|
465 Pane::leaveEvent(QEvent *)
|
Chris@0
|
466 {
|
Chris@0
|
467 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@0
|
468 m_identifyFeatures = false;
|
Chris@0
|
469 if (previouslyIdentifying) update();
|
Chris@0
|
470 }
|
Chris@0
|
471
|
Chris@0
|
472 void
|
Chris@0
|
473 Pane::wheelEvent(QWheelEvent *e)
|
Chris@0
|
474 {
|
Chris@0
|
475 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
|
Chris@0
|
476
|
Chris@0
|
477 int newZoomLevel = m_zoomLevel;
|
Chris@0
|
478
|
Chris@0
|
479 int count = e->delta();
|
Chris@0
|
480
|
Chris@0
|
481 if (count > 0) {
|
Chris@0
|
482 if (count >= 120) count /= 120;
|
Chris@0
|
483 else count = 1;
|
Chris@0
|
484 }
|
Chris@0
|
485
|
Chris@0
|
486 if (count < 0) {
|
Chris@0
|
487 if (count <= -120) count /= 120;
|
Chris@0
|
488 else count = -1;
|
Chris@0
|
489 }
|
Chris@0
|
490
|
Chris@0
|
491 while (count > 0) {
|
Chris@0
|
492 if (newZoomLevel <= 2) {
|
Chris@0
|
493 newZoomLevel = 1;
|
Chris@0
|
494 break;
|
Chris@0
|
495 }
|
Chris@0
|
496 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
Chris@0
|
497 ZoomConstraint::RoundDown);
|
Chris@0
|
498 --count;
|
Chris@0
|
499 }
|
Chris@0
|
500
|
Chris@0
|
501 while (count < 0) {
|
Chris@0
|
502 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
Chris@0
|
503 ZoomConstraint::RoundUp);
|
Chris@0
|
504 ++count;
|
Chris@0
|
505 }
|
Chris@0
|
506
|
Chris@0
|
507 if (newZoomLevel != m_zoomLevel) {
|
Chris@0
|
508 setZoomLevel(newZoomLevel);
|
Chris@0
|
509 }
|
Chris@0
|
510
|
Chris@0
|
511 emit paneInteractedWith();
|
Chris@0
|
512 }
|
Chris@8
|
513
|
Chris@13
|
514 void
|
Chris@13
|
515 Pane::toolModeChanged()
|
Chris@13
|
516 {
|
Chris@13
|
517 ViewManager::ToolMode mode = m_manager->getToolMode();
|
Chris@13
|
518 std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
|
Chris@13
|
519
|
Chris@13
|
520 switch (mode) {
|
Chris@13
|
521
|
Chris@13
|
522 case ViewManager::NavigateMode:
|
Chris@13
|
523 setCursor(Qt::PointingHandCursor);
|
Chris@13
|
524 break;
|
Chris@13
|
525
|
Chris@13
|
526 case ViewManager::SelectMode:
|
Chris@13
|
527 setCursor(Qt::ArrowCursor);
|
Chris@13
|
528 break;
|
Chris@13
|
529
|
Chris@13
|
530 case ViewManager::EditMode:
|
Chris@13
|
531 setCursor(Qt::SizeAllCursor);
|
Chris@13
|
532 break;
|
Chris@13
|
533
|
Chris@13
|
534 case ViewManager::DrawMode:
|
Chris@13
|
535 setCursor(Qt::CrossCursor);
|
Chris@13
|
536 break;
|
Chris@13
|
537
|
Chris@13
|
538 case ViewManager::TextMode:
|
Chris@13
|
539 setCursor(Qt::IBeamCursor);
|
Chris@13
|
540 break;
|
Chris@13
|
541 }
|
Chris@13
|
542 }
|
Chris@13
|
543
|
Chris@8
|
544 QString
|
Chris@8
|
545 Pane::toXmlString(QString indent, QString extraAttributes) const
|
Chris@8
|
546 {
|
Chris@8
|
547 return View::toXmlString
|
Chris@8
|
548 (indent,
|
Chris@8
|
549 QString("type=\"pane\" centreLineVisible=\"%1\" %2")
|
Chris@8
|
550 .arg(m_centreLineVisible).arg(extraAttributes));
|
Chris@8
|
551 }
|
Chris@8
|
552
|
Chris@0
|
553
|
Chris@0
|
554 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
555 #include "Pane.moc.cpp"
|
Chris@0
|
556 #endif
|
Chris@0
|
557
|