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@17
|
32 m_navigating(false),
|
Chris@17
|
33 m_resizing(false),
|
Chris@0
|
34 m_centreLineVisible(true)
|
Chris@0
|
35 {
|
Chris@0
|
36 setObjectName("Pane");
|
Chris@0
|
37 setMouseTracking(true);
|
Chris@0
|
38 }
|
Chris@0
|
39
|
Chris@0
|
40 bool
|
Chris@0
|
41 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos)
|
Chris@0
|
42 {
|
Chris@0
|
43 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@0
|
44 --vi;
|
Chris@0
|
45 if (layer != *vi) return false;
|
Chris@0
|
46 pos = m_identifyPoint;
|
Chris@0
|
47 return m_identifyFeatures;
|
Chris@0
|
48 }
|
Chris@0
|
49
|
Chris@0
|
50 return false;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 void
|
Chris@0
|
54 Pane::setCentreLineVisible(bool visible)
|
Chris@0
|
55 {
|
Chris@0
|
56 m_centreLineVisible = visible;
|
Chris@0
|
57 update();
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 void
|
Chris@0
|
61 Pane::paintEvent(QPaintEvent *e)
|
Chris@0
|
62 {
|
Chris@0
|
63 QPainter paint;
|
Chris@0
|
64
|
Chris@0
|
65 QRect r(rect());
|
Chris@0
|
66
|
Chris@0
|
67 if (e) {
|
Chris@0
|
68 r = e->rect();
|
Chris@0
|
69 }
|
Chris@0
|
70 /*
|
Chris@0
|
71 paint.begin(this);
|
Chris@0
|
72 paint.setClipRect(r);
|
Chris@0
|
73
|
Chris@0
|
74 if (hasLightBackground()) {
|
Chris@0
|
75 paint.setPen(Qt::white);
|
Chris@0
|
76 paint.setBrush(Qt::white);
|
Chris@0
|
77 } else {
|
Chris@0
|
78 paint.setPen(Qt::black);
|
Chris@0
|
79 paint.setBrush(Qt::black);
|
Chris@0
|
80 }
|
Chris@0
|
81 paint.drawRect(r);
|
Chris@0
|
82
|
Chris@0
|
83 paint.end();
|
Chris@0
|
84 */
|
Chris@0
|
85 View::paintEvent(e);
|
Chris@0
|
86
|
Chris@0
|
87 paint.begin(this);
|
Chris@0
|
88
|
Chris@0
|
89 if (e) {
|
Chris@0
|
90 paint.setClipRect(r);
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@0
|
93 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@0
|
94 --vi;
|
Chris@0
|
95
|
Chris@0
|
96 int sw = (*vi)->getVerticalScaleWidth(paint);
|
Chris@0
|
97
|
Chris@0
|
98 if (sw > 0 && r.left() < sw) {
|
Chris@0
|
99
|
Chris@0
|
100 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
|
Chris@0
|
101
|
Chris@0
|
102 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
|
Chris@0
|
103 paint.save();
|
Chris@0
|
104
|
Chris@0
|
105 paint.setPen(Qt::black);
|
Chris@0
|
106 paint.setBrush(Qt::white);
|
Chris@0
|
107 paint.drawRect(0, 0, sw, height());
|
Chris@0
|
108
|
Chris@0
|
109 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
110 (*vi)->paintVerticalScale(paint, QRect(0, 0, sw, height()));
|
Chris@0
|
111
|
Chris@0
|
112 paint.restore();
|
Chris@0
|
113 }
|
Chris@0
|
114
|
Chris@0
|
115 if (m_identifyFeatures) {
|
Chris@0
|
116 QRect descRect = (*vi)->getFeatureDescriptionRect(paint,
|
Chris@0
|
117 m_identifyPoint);
|
Chris@0
|
118 if (descRect.width() > 0 && descRect.height() > 0 &&
|
Chris@0
|
119 r.left() + r.width() >= width() - descRect.width() &&
|
Chris@0
|
120 r.top() < descRect.height()) {
|
Chris@0
|
121
|
Chris@0
|
122 // Profiler profiler("Pane::paintEvent - painting local feature description", true);
|
Chris@0
|
123
|
Chris@0
|
124 // std::cerr << "Pane::paintEvent: calling paint.save() in feature description block" << std::endl;
|
Chris@0
|
125 paint.save();
|
Chris@0
|
126
|
Chris@0
|
127 paint.setPen(Qt::black);
|
Chris@0
|
128 paint.setBrush(Qt::white);
|
Chris@0
|
129
|
Chris@0
|
130 QRect rect(width() - descRect.width() - 1, 0,
|
Chris@0
|
131 descRect.width(), descRect.height());
|
Chris@0
|
132
|
Chris@0
|
133 paint.drawRect(rect);
|
Chris@0
|
134
|
Chris@0
|
135 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
136 (*vi)->paintLocalFeatureDescription(paint, rect, m_identifyPoint);
|
Chris@0
|
137
|
Chris@0
|
138 paint.restore();
|
Chris@0
|
139 }
|
Chris@0
|
140 }
|
Chris@0
|
141
|
Chris@0
|
142 break;
|
Chris@0
|
143 }
|
Chris@0
|
144
|
Chris@0
|
145 if (m_centreLineVisible) {
|
Chris@0
|
146
|
Chris@0
|
147 if (hasLightBackground()) {
|
Chris@0
|
148 paint.setPen(QColor(50, 50, 50));
|
Chris@0
|
149 } else {
|
Chris@0
|
150 paint.setPen(QColor(200, 200, 200));
|
Chris@0
|
151 }
|
Chris@0
|
152 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
153 paint.drawLine(width() / 2, 0, width() / 2, height() - 1);
|
Chris@0
|
154
|
Chris@0
|
155 // QFont font(paint.font());
|
Chris@0
|
156 // font.setBold(true);
|
Chris@0
|
157 // paint.setFont(font);
|
Chris@0
|
158
|
Chris@0
|
159 int sampleRate = getModelsSampleRate();
|
Chris@0
|
160 int y = height() - paint.fontMetrics().height()
|
Chris@0
|
161 + paint.fontMetrics().ascent() - 6;
|
Chris@0
|
162
|
Chris@0
|
163 LayerList::iterator vi = m_layers.end();
|
Chris@0
|
164
|
Chris@0
|
165 if (vi != m_layers.begin()) {
|
Chris@0
|
166
|
Chris@0
|
167 switch ((*--vi)->getPreferredFrameCountPosition()) {
|
Chris@0
|
168
|
Chris@0
|
169 case Layer::PositionTop:
|
Chris@0
|
170 y = paint.fontMetrics().ascent() + 6;
|
Chris@0
|
171 break;
|
Chris@0
|
172
|
Chris@0
|
173 case Layer::PositionMiddle:
|
Chris@0
|
174 y = (height() - paint.fontMetrics().height()) / 2
|
Chris@0
|
175 + paint.fontMetrics().ascent();
|
Chris@0
|
176 break;
|
Chris@0
|
177
|
Chris@0
|
178 case Layer::PositionBottom:
|
Chris@0
|
179 // y already set correctly
|
Chris@0
|
180 break;
|
Chris@0
|
181 }
|
Chris@0
|
182 }
|
Chris@0
|
183
|
Chris@0
|
184 if (sampleRate) {
|
Chris@0
|
185
|
Chris@0
|
186 QString text(QString::fromStdString
|
Chris@0
|
187 (RealTime::frame2RealTime
|
Chris@0
|
188 (m_centreFrame, sampleRate).toText(true)));
|
Chris@0
|
189
|
Chris@0
|
190 int tw = paint.fontMetrics().width(text);
|
Chris@0
|
191 int x = width()/2 - 4 - tw;
|
Chris@0
|
192
|
Chris@0
|
193 if (hasLightBackground()) {
|
Chris@0
|
194 paint.setPen(palette().background().color());
|
Chris@0
|
195 for (int dx = -1; dx <= 1; ++dx) {
|
Chris@0
|
196 for (int dy = -1; dy <= 1; ++dy) {
|
Chris@0
|
197 if ((dx && dy) || !(dx || dy)) continue;
|
Chris@0
|
198 paint.drawText(x + dx, y + dy, text);
|
Chris@0
|
199 }
|
Chris@0
|
200 }
|
Chris@0
|
201 paint.setPen(QColor(50, 50, 50));
|
Chris@0
|
202 } else {
|
Chris@0
|
203 paint.setPen(QColor(200, 200, 200));
|
Chris@0
|
204 }
|
Chris@0
|
205
|
Chris@0
|
206 paint.drawText(x, y, text);
|
Chris@0
|
207 }
|
Chris@0
|
208
|
Chris@0
|
209 QString text = QString("%1").arg(m_centreFrame);
|
Chris@0
|
210
|
Chris@0
|
211 int tw = paint.fontMetrics().width(text);
|
Chris@0
|
212 int x = width()/2 + 4;
|
Chris@0
|
213
|
Chris@0
|
214 if (hasLightBackground()) {
|
Chris@0
|
215 paint.setPen(palette().background().color());
|
Chris@0
|
216 for (int dx = -1; dx <= 1; ++dx) {
|
Chris@0
|
217 for (int dy = -1; dy <= 1; ++dy) {
|
Chris@0
|
218 if ((dx && dy) || !(dx || dy)) continue;
|
Chris@0
|
219 paint.drawText(x + dx, y + dy, text);
|
Chris@0
|
220 }
|
Chris@0
|
221 }
|
Chris@0
|
222 paint.setPen(QColor(50, 50, 50));
|
Chris@0
|
223 } else {
|
Chris@0
|
224 paint.setPen(QColor(200, 200, 200));
|
Chris@0
|
225 }
|
Chris@0
|
226 paint.drawText(x, y, text);
|
Chris@0
|
227 }
|
Chris@0
|
228
|
Chris@0
|
229 if (m_clickedInRange && m_shiftPressed) {
|
Chris@19
|
230 if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) {
|
Chris@19
|
231 //!!! be nice if this looked a bit more in keeping with the
|
Chris@19
|
232 //selection block
|
Chris@19
|
233 paint.setPen(Qt::blue);
|
Chris@19
|
234 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
|
Chris@19
|
235 m_mousePos.x() - m_clickPos.x(),
|
Chris@19
|
236 m_mousePos.y() - m_clickPos.y());
|
Chris@19
|
237 }
|
Chris@0
|
238 }
|
Chris@0
|
239
|
Chris@0
|
240 paint.end();
|
Chris@0
|
241 }
|
Chris@0
|
242
|
Chris@17
|
243 Selection
|
Chris@17
|
244 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge)
|
Chris@17
|
245 {
|
Chris@17
|
246 closeToLeftEdge = closeToRightEdge = false;
|
Chris@17
|
247
|
Chris@17
|
248 if (!m_manager) return Selection();
|
Chris@17
|
249
|
Chris@17
|
250 long testFrame = (x - 5) * m_zoomLevel + getStartFrame();
|
Chris@17
|
251 if (testFrame < 0) {
|
Chris@17
|
252 testFrame = x * m_zoomLevel + getStartFrame();
|
Chris@17
|
253 if (testFrame < 0) return Selection();
|
Chris@17
|
254 }
|
Chris@17
|
255
|
Chris@17
|
256 Selection selection = m_manager->getContainingSelection(testFrame, true);
|
Chris@17
|
257 if (selection.isEmpty()) return selection;
|
Chris@17
|
258
|
Chris@17
|
259 int lx = (int(selection.getStartFrame()) - getStartFrame()) / m_zoomLevel;
|
Chris@17
|
260 int rx = (int(selection.getEndFrame()) - getStartFrame()) / m_zoomLevel;
|
Chris@17
|
261
|
Chris@17
|
262 int fuzz = 2;
|
Chris@17
|
263 if (x < lx - fuzz || x > rx + fuzz) return Selection();
|
Chris@17
|
264
|
Chris@17
|
265 int width = rx - lx;
|
Chris@17
|
266 fuzz = 3;
|
Chris@17
|
267 if (width < 12) fuzz = width / 4;
|
Chris@17
|
268 if (fuzz < 1) fuzz = 1;
|
Chris@17
|
269
|
Chris@17
|
270 if (x < lx + fuzz) closeToLeftEdge = true;
|
Chris@17
|
271 if (x > rx - fuzz) closeToRightEdge = true;
|
Chris@17
|
272
|
Chris@17
|
273 return selection;
|
Chris@17
|
274 }
|
Chris@17
|
275
|
Chris@0
|
276 void
|
Chris@0
|
277 Pane::mousePressEvent(QMouseEvent *e)
|
Chris@0
|
278 {
|
Chris@0
|
279 m_clickPos = e->pos();
|
Chris@0
|
280 m_clickedInRange = true;
|
Chris@0
|
281 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@13
|
282 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@13
|
283
|
Chris@13
|
284 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
285 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
286
|
Chris@17
|
287 m_navigating = false;
|
Chris@13
|
288
|
Chris@17
|
289 if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)) {
|
Chris@17
|
290
|
Chris@17
|
291 if (mode != ViewManager::NavigateMode) {
|
Chris@17
|
292 setCursor(Qt::PointingHandCursor);
|
Chris@17
|
293 }
|
Chris@17
|
294
|
Chris@17
|
295 m_navigating = true;
|
Chris@13
|
296 m_dragCentreFrame = m_centreFrame;
|
Chris@13
|
297
|
Chris@13
|
298 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
299
|
Chris@17
|
300 bool closeToLeft = false, closeToRight = false;
|
Chris@17
|
301 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@17
|
302
|
Chris@17
|
303 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@17
|
304
|
Chris@17
|
305 m_manager->removeSelection(selection);
|
Chris@17
|
306
|
Chris@17
|
307 if (closeToLeft) {
|
Chris@17
|
308 m_selectionStartFrame = selection.getEndFrame();
|
Chris@17
|
309 } else {
|
Chris@17
|
310 m_selectionStartFrame = selection.getStartFrame();
|
Chris@17
|
311 }
|
Chris@17
|
312
|
Chris@17
|
313 m_manager->setInProgressSelection(selection, false);
|
Chris@17
|
314 m_resizing = true;
|
Chris@13
|
315
|
Chris@17
|
316 } else {
|
Chris@17
|
317
|
Chris@17
|
318 int mouseFrame = e->x() * m_zoomLevel + getStartFrame();
|
Chris@17
|
319 size_t resolution = 1;
|
Chris@17
|
320 int snapFrame = mouseFrame;
|
Chris@17
|
321
|
Chris@17
|
322 Layer *layer = getSelectedLayer();
|
Chris@17
|
323 if (layer) {
|
Chris@17
|
324 snapFrame = layer->getNearestFeatureFrame(mouseFrame, resolution,
|
Chris@17
|
325 false);
|
Chris@17
|
326 }
|
Chris@17
|
327
|
Chris@17
|
328 if (snapFrame < 0) snapFrame = 0;
|
Chris@17
|
329 m_selectionStartFrame = snapFrame;
|
Chris@17
|
330 if (m_manager) {
|
Chris@17
|
331 m_manager->setInProgressSelection(Selection(snapFrame,
|
Chris@17
|
332 snapFrame + resolution),
|
Chris@17
|
333 !m_ctrlPressed);
|
Chris@17
|
334 }
|
Chris@17
|
335
|
Chris@17
|
336 m_resizing = false;
|
Chris@17
|
337 }
|
Chris@17
|
338
|
Chris@17
|
339 update();
|
Chris@17
|
340
|
Chris@17
|
341 } else if (mode == ViewManager::DrawMode) {
|
Chris@17
|
342
|
Chris@13
|
343 Layer *layer = getSelectedLayer();
|
Chris@13
|
344 if (layer) {
|
Chris@17
|
345 layer->drawStart(e);
|
Chris@13
|
346 }
|
Chris@18
|
347
|
Chris@18
|
348 } else if (mode == ViewManager::EditMode) {
|
Chris@18
|
349
|
Chris@18
|
350 Layer *layer = getSelectedLayer();
|
Chris@18
|
351 if (layer) {
|
Chris@18
|
352 layer->editStart(e);
|
Chris@18
|
353 }
|
Chris@13
|
354 }
|
Chris@0
|
355
|
Chris@0
|
356 emit paneInteractedWith();
|
Chris@0
|
357 }
|
Chris@0
|
358
|
Chris@0
|
359 void
|
Chris@0
|
360 Pane::mouseReleaseEvent(QMouseEvent *e)
|
Chris@0
|
361 {
|
Chris@13
|
362 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
363 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
364
|
Chris@0
|
365 if (m_clickedInRange) {
|
Chris@0
|
366 mouseMoveEvent(e);
|
Chris@0
|
367 }
|
Chris@0
|
368
|
Chris@17
|
369 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@17
|
370
|
Chris@17
|
371 m_navigating = false;
|
Chris@17
|
372
|
Chris@17
|
373 if (mode != ViewManager::NavigateMode) {
|
Chris@17
|
374 // restore cursor
|
Chris@17
|
375 toolModeChanged();
|
Chris@17
|
376 }
|
Chris@0
|
377
|
Chris@13
|
378 if (m_shiftPressed) {
|
Chris@0
|
379
|
Chris@13
|
380 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
|
Chris@13
|
381 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
|
Chris@13
|
382 int w = x1 - x0;
|
Chris@13
|
383
|
Chris@13
|
384 long newStartFrame = getStartFrame() + m_zoomLevel * x0;
|
Chris@13
|
385
|
Chris@13
|
386 if (newStartFrame <= -long(width() * m_zoomLevel)) {
|
Chris@13
|
387 newStartFrame = -long(width() * m_zoomLevel) + 1;
|
Chris@13
|
388 }
|
Chris@13
|
389
|
Chris@13
|
390 if (newStartFrame >= long(getModelsEndFrame())) {
|
Chris@13
|
391 newStartFrame = getModelsEndFrame() - 1;
|
Chris@13
|
392 }
|
Chris@13
|
393
|
Chris@13
|
394 float ratio = float(w) / float(width());
|
Chris@13
|
395 // std::cerr << "ratio: " << ratio << std::endl;
|
Chris@13
|
396 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
|
Chris@13
|
397 if (newZoomLevel < 1) newZoomLevel = 1;
|
Chris@13
|
398
|
Chris@13
|
399 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
|
Chris@13
|
400 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
|
Chris@13
|
401 setStartFrame(newStartFrame);
|
Chris@13
|
402
|
Chris@13
|
403 //cerr << "mouseReleaseEvent: start frame now " << m_startFrame << endl;
|
Chris@13
|
404 // update();
|
Chris@0
|
405 }
|
Chris@0
|
406
|
Chris@13
|
407 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
408
|
Chris@13
|
409 if (m_manager && m_manager->haveInProgressSelection()) {
|
Chris@13
|
410
|
Chris@13
|
411 bool exclusive;
|
Chris@13
|
412 Selection selection = m_manager->getInProgressSelection(exclusive);
|
Chris@13
|
413
|
Chris@13
|
414 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
|
Chris@13
|
415 selection = Selection();
|
Chris@13
|
416 }
|
Chris@13
|
417
|
Chris@13
|
418 m_manager->clearInProgressSelection();
|
Chris@13
|
419
|
Chris@13
|
420 if (exclusive) {
|
Chris@13
|
421 m_manager->setSelection(selection);
|
Chris@13
|
422 } else {
|
Chris@13
|
423 m_manager->addSelection(selection);
|
Chris@13
|
424 }
|
Chris@0
|
425 }
|
Chris@13
|
426
|
Chris@13
|
427 update();
|
Chris@17
|
428
|
Chris@17
|
429 } else if (mode == ViewManager::DrawMode) {
|
Chris@17
|
430
|
Chris@17
|
431 Layer *layer = getSelectedLayer();
|
Chris@17
|
432 if (layer) {
|
Chris@17
|
433 layer->drawEnd(e);
|
Chris@17
|
434 update();
|
Chris@17
|
435 }
|
Chris@18
|
436
|
Chris@18
|
437 } else if (mode == ViewManager::EditMode) {
|
Chris@18
|
438
|
Chris@18
|
439 Layer *layer = getSelectedLayer();
|
Chris@18
|
440 if (layer) {
|
Chris@18
|
441 layer->editEnd(e);
|
Chris@18
|
442 update();
|
Chris@18
|
443 }
|
Chris@17
|
444 }
|
Chris@0
|
445
|
Chris@0
|
446 m_clickedInRange = false;
|
Chris@0
|
447
|
Chris@0
|
448 emit paneInteractedWith();
|
Chris@0
|
449 }
|
Chris@0
|
450
|
Chris@0
|
451 void
|
Chris@0
|
452 Pane::mouseMoveEvent(QMouseEvent *e)
|
Chris@0
|
453 {
|
Chris@13
|
454 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
455 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
456
|
Chris@0
|
457 if (!m_clickedInRange) {
|
Chris@0
|
458
|
Chris@17
|
459 if (mode == ViewManager::SelectMode) {
|
Chris@17
|
460 bool closeToLeft = false, closeToRight = false;
|
Chris@17
|
461 getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@17
|
462 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@17
|
463 setCursor(Qt::SizeHorCursor);
|
Chris@17
|
464 } else {
|
Chris@17
|
465 setCursor(Qt::ArrowCursor);
|
Chris@17
|
466 }
|
Chris@17
|
467 }
|
Chris@0
|
468
|
Chris@17
|
469 if (mode != ViewManager::DrawMode) {
|
Chris@0
|
470
|
Chris@17
|
471 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@17
|
472 QPoint prevPoint = m_identifyPoint;
|
Chris@0
|
473
|
Chris@17
|
474 m_identifyFeatures = true;
|
Chris@17
|
475 m_identifyPoint = e->pos();
|
Chris@17
|
476
|
Chris@17
|
477 if (m_identifyFeatures != previouslyIdentifying ||
|
Chris@17
|
478 m_identifyPoint != prevPoint) {
|
Chris@17
|
479 update();
|
Chris@17
|
480 }
|
Chris@0
|
481 }
|
Chris@0
|
482
|
Chris@13
|
483 return;
|
Chris@13
|
484 }
|
Chris@0
|
485
|
Chris@17
|
486 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@0
|
487
|
Chris@13
|
488 if (m_shiftPressed) {
|
Chris@0
|
489
|
Chris@13
|
490 m_mousePos = e->pos();
|
Chris@13
|
491 update();
|
Chris@0
|
492
|
Chris@0
|
493 } else {
|
Chris@13
|
494
|
Chris@13
|
495 long xoff = int(e->x()) - int(m_clickPos.x());
|
Chris@13
|
496 long frameOff = xoff * m_zoomLevel;
|
Chris@13
|
497
|
Chris@13
|
498 size_t newCentreFrame = m_dragCentreFrame;
|
Chris@13
|
499
|
Chris@13
|
500 if (frameOff < 0) {
|
Chris@13
|
501 newCentreFrame -= frameOff;
|
Chris@13
|
502 } else if (newCentreFrame >= size_t(frameOff)) {
|
Chris@13
|
503 newCentreFrame -= frameOff;
|
Chris@13
|
504 } else {
|
Chris@13
|
505 newCentreFrame = 0;
|
Chris@13
|
506 }
|
Chris@13
|
507
|
Chris@13
|
508 if (newCentreFrame >= getModelsEndFrame()) {
|
Chris@13
|
509 newCentreFrame = getModelsEndFrame();
|
Chris@13
|
510 if (newCentreFrame > 0) --newCentreFrame;
|
Chris@13
|
511 }
|
Chris@13
|
512
|
Chris@13
|
513 if (std::max(m_centreFrame, newCentreFrame) -
|
Chris@13
|
514 std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) {
|
Chris@13
|
515 setCentreFrame(newCentreFrame);
|
Chris@13
|
516 }
|
Chris@0
|
517 }
|
Chris@0
|
518
|
Chris@13
|
519 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
520
|
Chris@13
|
521 int mouseFrame = e->x() * m_zoomLevel + getStartFrame();
|
Chris@13
|
522 size_t resolution = 1;
|
Chris@13
|
523 int snapFrameLeft = mouseFrame;
|
Chris@13
|
524 int snapFrameRight = mouseFrame;
|
Chris@13
|
525
|
Chris@13
|
526 Layer *layer = getSelectedLayer();
|
Chris@13
|
527 if (layer) {
|
Chris@13
|
528 snapFrameLeft = layer->getNearestFeatureFrame(mouseFrame, resolution,
|
Chris@13
|
529 false);
|
Chris@13
|
530 snapFrameRight = layer->getNearestFeatureFrame(mouseFrame, resolution,
|
Chris@13
|
531 true);
|
Chris@13
|
532 }
|
Chris@13
|
533
|
Chris@13
|
534 if (snapFrameLeft < 0) snapFrameLeft = 0;
|
Chris@13
|
535 if (snapFrameRight < 0) snapFrameRight = 0;
|
Chris@13
|
536
|
Chris@13
|
537 size_t min, max;
|
Chris@13
|
538
|
Chris@13
|
539 if (m_selectionStartFrame > snapFrameLeft) {
|
Chris@13
|
540 min = snapFrameLeft;
|
Chris@13
|
541 max = m_selectionStartFrame;
|
Chris@13
|
542 } else if (snapFrameRight > m_selectionStartFrame) {
|
Chris@13
|
543 min = m_selectionStartFrame;
|
Chris@13
|
544 max = snapFrameRight;
|
Chris@13
|
545 } else {
|
Chris@13
|
546 min = snapFrameLeft;
|
Chris@13
|
547 max = snapFrameRight;
|
Chris@0
|
548 }
|
Chris@0
|
549
|
Chris@13
|
550 if (m_manager) {
|
Chris@13
|
551 m_manager->setInProgressSelection(Selection(min, max),
|
Chris@17
|
552 !m_resizing && !m_ctrlPressed);
|
Chris@0
|
553 }
|
Chris@15
|
554
|
Chris@15
|
555 bool doScroll = false;
|
Chris@15
|
556 if (!m_manager) doScroll = true;
|
Chris@15
|
557 if (!m_manager->isPlaying()) doScroll = true;
|
Chris@15
|
558 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
|
Chris@15
|
559
|
Chris@15
|
560 if (doScroll) {
|
Chris@13
|
561 int offset = mouseFrame - getStartFrame();
|
Chris@13
|
562 int available = getEndFrame() - getStartFrame();
|
Chris@15
|
563 if (offset >= available * 0.95) {
|
Chris@15
|
564 int move = int(offset - available * 0.95) + 1;
|
Chris@14
|
565 setCentreFrame(m_centreFrame + move);
|
Chris@15
|
566 } else if (offset <= available * 0.10) {
|
Chris@15
|
567 int move = int(available * 0.10 - offset) + 1;
|
Chris@14
|
568 if (m_centreFrame > move) {
|
Chris@14
|
569 setCentreFrame(m_centreFrame - move);
|
Chris@14
|
570 } else {
|
Chris@14
|
571 setCentreFrame(0);
|
Chris@14
|
572 }
|
Chris@13
|
573 }
|
Chris@13
|
574 }
|
Chris@13
|
575
|
Chris@13
|
576 update();
|
Chris@17
|
577
|
Chris@17
|
578 } else if (mode == ViewManager::DrawMode) {
|
Chris@17
|
579
|
Chris@17
|
580 Layer *layer = getSelectedLayer();
|
Chris@17
|
581 if (layer) {
|
Chris@17
|
582 layer->drawDrag(e);
|
Chris@19
|
583 update();
|
Chris@17
|
584 }
|
Chris@18
|
585
|
Chris@18
|
586 } else if (mode == ViewManager::EditMode) {
|
Chris@18
|
587
|
Chris@18
|
588 Layer *layer = getSelectedLayer();
|
Chris@18
|
589 if (layer) {
|
Chris@18
|
590 layer->editDrag(e);
|
Chris@19
|
591 update();
|
Chris@18
|
592 }
|
Chris@0
|
593 }
|
Chris@0
|
594 }
|
Chris@0
|
595
|
Chris@0
|
596 void
|
Chris@0
|
597 Pane::mouseDoubleClickEvent(QMouseEvent *e)
|
Chris@0
|
598 {
|
Chris@0
|
599 std::cerr << "mouseDoubleClickEvent" << std::endl;
|
Chris@0
|
600 }
|
Chris@0
|
601
|
Chris@0
|
602 void
|
Chris@0
|
603 Pane::leaveEvent(QEvent *)
|
Chris@0
|
604 {
|
Chris@0
|
605 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@0
|
606 m_identifyFeatures = false;
|
Chris@0
|
607 if (previouslyIdentifying) update();
|
Chris@0
|
608 }
|
Chris@0
|
609
|
Chris@0
|
610 void
|
Chris@0
|
611 Pane::wheelEvent(QWheelEvent *e)
|
Chris@0
|
612 {
|
Chris@0
|
613 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
|
Chris@0
|
614
|
Chris@0
|
615 int count = e->delta();
|
Chris@0
|
616
|
Chris@0
|
617 if (count > 0) {
|
Chris@0
|
618 if (count >= 120) count /= 120;
|
Chris@0
|
619 else count = 1;
|
Chris@0
|
620 }
|
Chris@0
|
621
|
Chris@0
|
622 if (count < 0) {
|
Chris@0
|
623 if (count <= -120) count /= 120;
|
Chris@0
|
624 else count = -1;
|
Chris@0
|
625 }
|
Chris@17
|
626
|
Chris@17
|
627 if (e->modifiers() & Qt::ControlModifier) {
|
Chris@17
|
628
|
Chris@17
|
629 if (getStartFrame() < 0 &&
|
Chris@17
|
630 getEndFrame() >= getModelsEndFrame()) return;
|
Chris@17
|
631
|
Chris@17
|
632 long delta = ((width() / 2) * count * m_zoomLevel);
|
Chris@17
|
633
|
Chris@17
|
634 if (int(m_centreFrame) < delta) {
|
Chris@17
|
635 setCentreFrame(0);
|
Chris@17
|
636 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
|
Chris@17
|
637 setCentreFrame(getModelsEndFrame());
|
Chris@17
|
638 } else {
|
Chris@17
|
639 setCentreFrame(m_centreFrame - delta);
|
Chris@17
|
640 }
|
Chris@17
|
641
|
Chris@17
|
642 } else {
|
Chris@17
|
643
|
Chris@17
|
644 int newZoomLevel = m_zoomLevel;
|
Chris@0
|
645
|
Chris@17
|
646 while (count > 0) {
|
Chris@17
|
647 if (newZoomLevel <= 2) {
|
Chris@17
|
648 newZoomLevel = 1;
|
Chris@17
|
649 break;
|
Chris@17
|
650 }
|
Chris@17
|
651 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
Chris@17
|
652 ZoomConstraint::RoundDown);
|
Chris@17
|
653 --count;
|
Chris@0
|
654 }
|
Chris@17
|
655
|
Chris@17
|
656 while (count < 0) {
|
Chris@17
|
657 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
Chris@17
|
658 ZoomConstraint::RoundUp);
|
Chris@17
|
659 ++count;
|
Chris@17
|
660 }
|
Chris@17
|
661
|
Chris@17
|
662 if (newZoomLevel != m_zoomLevel) {
|
Chris@17
|
663 setZoomLevel(newZoomLevel);
|
Chris@17
|
664 }
|
Chris@0
|
665 }
|
Chris@0
|
666
|
Chris@0
|
667 emit paneInteractedWith();
|
Chris@0
|
668 }
|
Chris@8
|
669
|
Chris@13
|
670 void
|
Chris@13
|
671 Pane::toolModeChanged()
|
Chris@13
|
672 {
|
Chris@13
|
673 ViewManager::ToolMode mode = m_manager->getToolMode();
|
Chris@13
|
674 std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
|
Chris@13
|
675
|
Chris@13
|
676 switch (mode) {
|
Chris@13
|
677
|
Chris@13
|
678 case ViewManager::NavigateMode:
|
Chris@13
|
679 setCursor(Qt::PointingHandCursor);
|
Chris@13
|
680 break;
|
Chris@13
|
681
|
Chris@13
|
682 case ViewManager::SelectMode:
|
Chris@13
|
683 setCursor(Qt::ArrowCursor);
|
Chris@13
|
684 break;
|
Chris@13
|
685
|
Chris@13
|
686 case ViewManager::EditMode:
|
Chris@19
|
687 setCursor(Qt::UpArrowCursor);
|
Chris@13
|
688 break;
|
Chris@13
|
689
|
Chris@13
|
690 case ViewManager::DrawMode:
|
Chris@13
|
691 setCursor(Qt::CrossCursor);
|
Chris@13
|
692 break;
|
Chris@13
|
693
|
Chris@13
|
694 case ViewManager::TextMode:
|
Chris@13
|
695 setCursor(Qt::IBeamCursor);
|
Chris@13
|
696 break;
|
Chris@13
|
697 }
|
Chris@13
|
698 }
|
Chris@13
|
699
|
Chris@8
|
700 QString
|
Chris@8
|
701 Pane::toXmlString(QString indent, QString extraAttributes) const
|
Chris@8
|
702 {
|
Chris@8
|
703 return View::toXmlString
|
Chris@8
|
704 (indent,
|
Chris@8
|
705 QString("type=\"pane\" centreLineVisible=\"%1\" %2")
|
Chris@8
|
706 .arg(m_centreLineVisible).arg(extraAttributes));
|
Chris@8
|
707 }
|
Chris@8
|
708
|
Chris@0
|
709
|
Chris@0
|
710 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
711 #include "Pane.moc.cpp"
|
Chris@0
|
712 #endif
|
Chris@0
|
713
|