Chris@127
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@127
|
2
|
Chris@127
|
3 /*
|
Chris@127
|
4 Sonic Visualiser
|
Chris@127
|
5 An audio file viewer and annotation editor.
|
Chris@127
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@264
|
7 This file copyright 2006-2007 Chris Cannam and QMUL.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@128
|
16 #include "Pane.h"
|
Chris@128
|
17 #include "layer/Layer.h"
|
Chris@128
|
18 #include "data/model/Model.h"
|
Chris@127
|
19 #include "base/ZoomConstraint.h"
|
Chris@127
|
20 #include "base/RealTime.h"
|
Chris@127
|
21 #include "base/Profiler.h"
|
Chris@128
|
22 #include "ViewManager.h"
|
Chris@376
|
23 #include "widgets/CommandHistory.h"
|
Chris@376
|
24 #include "widgets/TextAbbrev.h"
|
Chris@338
|
25 #include "base/Preferences.h"
|
Chris@127
|
26 #include "layer/WaveformLayer.h"
|
Chris@127
|
27
|
gyorgyf@646
|
28 // GF: added so we can propagate the mouse move event to the note layer for context handling.
|
gyorgyf@646
|
29 #include "layer/LayerFactory.h"
|
gyorgyf@646
|
30 #include "layer/FlexiNoteLayer.h"
|
gyorgyf@646
|
31
|
gyorgyf@646
|
32
|
Chris@326
|
33 //!!! ugh
|
Chris@326
|
34 #include "data/model/WaveFileModel.h"
|
Chris@326
|
35
|
Chris@127
|
36 #include <QPaintEvent>
|
Chris@127
|
37 #include <QPainter>
|
Chris@257
|
38 #include <QBitmap>
|
Chris@312
|
39 #include <QDragEnterEvent>
|
Chris@312
|
40 #include <QDropEvent>
|
Chris@257
|
41 #include <QCursor>
|
Chris@316
|
42 #include <QTextStream>
|
Chris@616
|
43 #include <QMimeData>
|
Chris@802
|
44 #include <QApplication>
|
Chris@316
|
45
|
Chris@127
|
46 #include <iostream>
|
Chris@127
|
47 #include <cmath>
|
Chris@127
|
48
|
Chris@133
|
49 //!!! for HUD -- pull out into a separate class
|
Chris@133
|
50 #include <QFrame>
|
Chris@133
|
51 #include <QGridLayout>
|
Chris@133
|
52 #include <QPushButton>
|
Chris@133
|
53 #include "widgets/Thumbwheel.h"
|
Chris@172
|
54 #include "widgets/Panner.h"
|
Chris@188
|
55 #include "widgets/RangeInputDialog.h"
|
Chris@189
|
56 #include "widgets/NotifyingPushButton.h"
|
Chris@133
|
57
|
Chris@282
|
58 #include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget
|
Chris@282
|
59
|
Chris@363
|
60 //#define DEBUG_PANE
|
Chris@363
|
61
|
Chris@682
|
62
|
Chris@682
|
63
|
Chris@127
|
64
|
Chris@267
|
65 QCursor *Pane::m_measureCursor1 = 0;
|
Chris@267
|
66 QCursor *Pane::m_measureCursor2 = 0;
|
Chris@262
|
67
|
Chris@127
|
68 Pane::Pane(QWidget *w) :
|
Chris@127
|
69 View(w, true),
|
Chris@127
|
70 m_identifyFeatures(false),
|
Chris@127
|
71 m_clickedInRange(false),
|
Chris@127
|
72 m_shiftPressed(false),
|
Chris@127
|
73 m_ctrlPressed(false),
|
Chris@510
|
74 m_altPressed(false),
|
Chris@127
|
75 m_navigating(false),
|
Chris@127
|
76 m_resizing(false),
|
Chris@343
|
77 m_editing(false),
|
Chris@343
|
78 m_releasing(false),
|
Chris@133
|
79 m_centreLineVisible(true),
|
Chris@222
|
80 m_scaleWidth(0),
|
Chris@237
|
81 m_headsUpDisplay(0),
|
Chris@237
|
82 m_vpan(0),
|
Chris@237
|
83 m_hthumb(0),
|
Chris@237
|
84 m_vthumb(0),
|
Chris@290
|
85 m_reset(0),
|
Chris@802
|
86 m_mouseInWidget(false),
|
Chris@802
|
87 m_playbackFrameMoveScheduled(false),
|
Chris@802
|
88 m_playbackFrameMoveTo(0)
|
Chris@127
|
89 {
|
Chris@127
|
90 setObjectName("Pane");
|
Chris@127
|
91 setMouseTracking(true);
|
Chris@312
|
92 setAcceptDrops(true);
|
Chris@133
|
93
|
Chris@133
|
94 updateHeadsUpDisplay();
|
Chris@456
|
95
|
Chris@730
|
96 connect(this, SIGNAL(regionOutlined(QRect)),
|
Chris@730
|
97 this, SLOT(zoomToRegion(QRect)));
|
Chris@730
|
98
|
Chris@728
|
99 cerr << "Pane::Pane(" << this << ") returning" << endl;
|
Chris@133
|
100 }
|
Chris@133
|
101
|
Chris@133
|
102 void
|
Chris@133
|
103 Pane::updateHeadsUpDisplay()
|
Chris@133
|
104 {
|
Chris@382
|
105 Profiler profiler("Pane::updateHeadsUpDisplay");
|
Chris@187
|
106
|
Chris@192
|
107 if (!isVisible()) return;
|
Chris@192
|
108
|
Chris@132
|
109 /*
|
Chris@132
|
110 int count = 0;
|
Chris@132
|
111 int currentLevel = 1;
|
Chris@132
|
112 int level = 1;
|
Chris@132
|
113 while (true) {
|
Chris@132
|
114 if (getZoomLevel() == level) currentLevel = count;
|
Chris@132
|
115 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@132
|
116 ZoomConstraint::RoundUp);
|
Chris@132
|
117 if (newLevel == level) break;
|
Chris@132
|
118 if (newLevel == 131072) break; //!!! just because
|
Chris@132
|
119 level = newLevel;
|
Chris@132
|
120 ++count;
|
Chris@132
|
121 }
|
Chris@132
|
122
|
Chris@682
|
123 cerr << "Have " << count+1 << " zoom levels" << endl;
|
Chris@132
|
124 */
|
Chris@133
|
125
|
Chris@188
|
126 Layer *layer = 0;
|
Chris@188
|
127 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@188
|
128
|
Chris@133
|
129 if (!m_headsUpDisplay) {
|
Chris@133
|
130
|
Chris@133
|
131 m_headsUpDisplay = new QFrame(this);
|
Chris@133
|
132
|
Chris@133
|
133 QGridLayout *layout = new QGridLayout;
|
Chris@133
|
134 layout->setMargin(0);
|
Chris@133
|
135 layout->setSpacing(0);
|
Chris@133
|
136 m_headsUpDisplay->setLayout(layout);
|
Chris@133
|
137
|
Chris@133
|
138 m_hthumb = new Thumbwheel(Qt::Horizontal);
|
Chris@187
|
139 m_hthumb->setObjectName(tr("Horizontal Zoom"));
|
Chris@260
|
140 m_hthumb->setCursor(Qt::ArrowCursor);
|
Chris@173
|
141 layout->addWidget(m_hthumb, 1, 0, 1, 2);
|
Chris@133
|
142 m_hthumb->setFixedWidth(70);
|
Chris@133
|
143 m_hthumb->setFixedHeight(16);
|
Chris@133
|
144 m_hthumb->setDefaultValue(0);
|
Chris@165
|
145 m_hthumb->setSpeed(0.6);
|
Chris@133
|
146 connect(m_hthumb, SIGNAL(valueChanged(int)), this,
|
Chris@133
|
147 SLOT(horizontalThumbwheelMoved(int)));
|
Chris@189
|
148 connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
149 connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@172
|
150
|
Chris@172
|
151 m_vpan = new Panner;
|
Chris@260
|
152 m_vpan->setCursor(Qt::ArrowCursor);
|
Chris@172
|
153 layout->addWidget(m_vpan, 0, 1);
|
Chris@173
|
154 m_vpan->setFixedWidth(12);
|
Chris@172
|
155 m_vpan->setFixedHeight(70);
|
Chris@174
|
156 m_vpan->setAlpha(80, 130);
|
Chris@174
|
157 connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)),
|
Chris@174
|
158 this, SLOT(verticalPannerMoved(float, float, float, float)));
|
Chris@188
|
159 connect(m_vpan, SIGNAL(doubleClicked()),
|
Chris@188
|
160 this, SLOT(editVerticalPannerExtents()));
|
Chris@189
|
161 connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
162 connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@172
|
163
|
Chris@133
|
164 m_vthumb = new Thumbwheel(Qt::Vertical);
|
Chris@187
|
165 m_vthumb->setObjectName(tr("Vertical Zoom"));
|
Chris@260
|
166 m_vthumb->setCursor(Qt::ArrowCursor);
|
Chris@172
|
167 layout->addWidget(m_vthumb, 0, 2);
|
Chris@133
|
168 m_vthumb->setFixedWidth(16);
|
Chris@133
|
169 m_vthumb->setFixedHeight(70);
|
Chris@133
|
170 connect(m_vthumb, SIGNAL(valueChanged(int)), this,
|
Chris@133
|
171 SLOT(verticalThumbwheelMoved(int)));
|
Chris@189
|
172 connect(m_vthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
173 connect(m_vthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@133
|
174
|
Chris@188
|
175 if (layer) {
|
Chris@188
|
176 RangeMapper *rm = layer->getNewVerticalZoomRangeMapper();
|
Chris@188
|
177 if (rm) m_vthumb->setRangeMapper(rm);
|
Chris@188
|
178 }
|
Chris@188
|
179
|
Chris@189
|
180 m_reset = new NotifyingPushButton;
|
Chris@713
|
181 m_reset->setFlat(true);
|
Chris@260
|
182 m_reset->setCursor(Qt::ArrowCursor);
|
Chris@189
|
183 m_reset->setFixedHeight(16);
|
Chris@189
|
184 m_reset->setFixedWidth(16);
|
Chris@499
|
185 m_reset->setIcon(QPixmap(":/icons/zoom-reset.png"));
|
Chris@501
|
186 m_reset->setToolTip(tr("Reset zoom to default"));
|
Chris@189
|
187 layout->addWidget(m_reset, 1, 2);
|
Chris@492
|
188
|
Chris@492
|
189 layout->setColumnStretch(0, 20);
|
Chris@492
|
190
|
Chris@189
|
191 connect(m_reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault()));
|
Chris@189
|
192 connect(m_reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault()));
|
Chris@189
|
193 connect(m_reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault()));
|
Chris@189
|
194 connect(m_reset, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
195 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@133
|
196 }
|
Chris@133
|
197
|
Chris@133
|
198 int count = 0;
|
Chris@133
|
199 int current = 0;
|
Chris@133
|
200 int level = 1;
|
Chris@133
|
201
|
Chris@137
|
202 //!!! pull out into function (presumably in View)
|
Chris@137
|
203 bool haveConstraint = false;
|
Chris@137
|
204 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
|
Chris@137
|
205 ++i) {
|
Chris@137
|
206 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
|
Chris@137
|
207 haveConstraint = true;
|
Chris@137
|
208 break;
|
Chris@137
|
209 }
|
Chris@137
|
210 }
|
Chris@137
|
211
|
Chris@137
|
212 if (haveConstraint) {
|
Chris@137
|
213 while (true) {
|
Chris@137
|
214 if (getZoomLevel() == level) current = count;
|
Chris@137
|
215 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@137
|
216 ZoomConstraint::RoundUp);
|
Chris@137
|
217 if (newLevel == level) break;
|
Chris@137
|
218 level = newLevel;
|
Chris@137
|
219 if (++count == 50) break;
|
Chris@137
|
220 }
|
Chris@137
|
221 } else {
|
Chris@137
|
222 // if we have no particular constraints, we can really spread out
|
Chris@137
|
223 while (true) {
|
Chris@137
|
224 if (getZoomLevel() >= level) current = count;
|
Chris@137
|
225 int step = level / 10;
|
Chris@137
|
226 int pwr = 0;
|
Chris@137
|
227 while (step > 0) {
|
Chris@137
|
228 ++pwr;
|
Chris@137
|
229 step /= 2;
|
Chris@137
|
230 }
|
Chris@137
|
231 step = 1;
|
Chris@137
|
232 while (pwr > 0) {
|
Chris@137
|
233 step *= 2;
|
Chris@137
|
234 --pwr;
|
Chris@137
|
235 }
|
Chris@682
|
236 // cerr << level << endl;
|
Chris@137
|
237 level += step;
|
Chris@137
|
238 if (++count == 100 || level > 262144) break;
|
Chris@137
|
239 }
|
Chris@133
|
240 }
|
Chris@133
|
241
|
Chris@682
|
242 // cerr << "Have " << count << " zoom levels" << endl;
|
Chris@133
|
243
|
Chris@133
|
244 m_hthumb->setMinimumValue(0);
|
Chris@133
|
245 m_hthumb->setMaximumValue(count);
|
Chris@133
|
246 m_hthumb->setValue(count - current);
|
Chris@133
|
247
|
Chris@682
|
248 // cerr << "set value to " << count-current << endl;
|
Chris@682
|
249
|
Chris@682
|
250 // cerr << "default value is " << m_hthumb->getDefaultValue() << endl;
|
Chris@133
|
251
|
Chris@133
|
252 if (count != 50 && m_hthumb->getDefaultValue() == 0) {
|
Chris@133
|
253 m_hthumb->setDefaultValue(count - current);
|
Chris@682
|
254 // cerr << "set default value to " << m_hthumb->getDefaultValue() << endl;
|
Chris@133
|
255 }
|
Chris@133
|
256
|
Chris@204
|
257 bool haveVThumb = false;
|
Chris@204
|
258
|
Chris@133
|
259 if (layer) {
|
Chris@133
|
260 int defaultStep = 0;
|
Chris@133
|
261 int max = layer->getVerticalZoomSteps(defaultStep);
|
Chris@133
|
262 if (max == 0) {
|
Chris@133
|
263 m_vthumb->hide();
|
Chris@133
|
264 } else {
|
Chris@204
|
265 haveVThumb = true;
|
Chris@133
|
266 m_vthumb->show();
|
Chris@187
|
267 m_vthumb->blockSignals(true);
|
Chris@133
|
268 m_vthumb->setMinimumValue(0);
|
Chris@133
|
269 m_vthumb->setMaximumValue(max);
|
Chris@133
|
270 m_vthumb->setDefaultValue(defaultStep);
|
Chris@133
|
271 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
|
Chris@187
|
272 m_vthumb->blockSignals(false);
|
Chris@135
|
273
|
Chris@682
|
274 // cerr << "Vertical thumbwheel: min 0, max " << max
|
Chris@205
|
275 // << ", default " << defaultStep << ", value "
|
Chris@682
|
276 // << m_vthumb->getValue() << endl;
|
Chris@135
|
277
|
Chris@133
|
278 }
|
Chris@133
|
279 }
|
Chris@133
|
280
|
Chris@174
|
281 updateVerticalPanner();
|
Chris@174
|
282
|
Chris@133
|
283 if (m_manager && m_manager->getZoomWheelsEnabled() &&
|
Chris@133
|
284 width() > 120 && height() > 100) {
|
Chris@165
|
285 if (!m_headsUpDisplay->isVisible()) {
|
Chris@165
|
286 m_headsUpDisplay->show();
|
Chris@165
|
287 }
|
Chris@204
|
288 if (haveVThumb) {
|
Chris@204
|
289 m_headsUpDisplay->setFixedHeight(m_vthumb->height() + m_hthumb->height());
|
Chris@133
|
290 m_headsUpDisplay->move(width() - 86, height() - 86);
|
Chris@133
|
291 } else {
|
Chris@204
|
292 m_headsUpDisplay->setFixedHeight(m_hthumb->height());
|
Chris@204
|
293 m_headsUpDisplay->move(width() - 86, height() - 16);
|
Chris@133
|
294 }
|
Chris@133
|
295 } else {
|
Chris@133
|
296 m_headsUpDisplay->hide();
|
Chris@133
|
297 }
|
Chris@127
|
298 }
|
Chris@127
|
299
|
Chris@174
|
300 void
|
Chris@174
|
301 Pane::updateVerticalPanner()
|
Chris@174
|
302 {
|
Chris@174
|
303 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
|
Chris@174
|
304
|
Chris@208
|
305 // In principle we should show or hide the panner on the basis of
|
Chris@208
|
306 // whether the top layer has adjustable display extents, and we do
|
Chris@208
|
307 // that below. However, we have no basis for layout of the panner
|
Chris@208
|
308 // if the vertical scroll wheel is not also present. So if we
|
Chris@208
|
309 // have no vertical scroll wheel, we should remove the panner as
|
Chris@208
|
310 // well. Ideally any layer that implements display extents should
|
Chris@208
|
311 // implement vertical zoom steps as well, but they don't all at
|
Chris@208
|
312 // the moment.
|
Chris@208
|
313
|
Chris@208
|
314 Layer *layer = 0;
|
Chris@208
|
315 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@208
|
316 int discard;
|
Chris@208
|
317 if (layer && layer->getVerticalZoomSteps(discard) == 0) {
|
Chris@208
|
318 m_vpan->hide();
|
Chris@208
|
319 return;
|
Chris@208
|
320 }
|
Chris@208
|
321
|
Chris@174
|
322 float vmin, vmax, dmin, dmax;
|
Chris@174
|
323 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) {
|
Chris@174
|
324 float y0 = (dmin - vmin) / (vmax - vmin);
|
Chris@174
|
325 float y1 = (dmax - vmin) / (vmax - vmin);
|
Chris@174
|
326 m_vpan->blockSignals(true);
|
Chris@174
|
327 m_vpan->setRectExtents(0, 1.0 - y1, 1, y1 - y0);
|
Chris@174
|
328 m_vpan->blockSignals(false);
|
Chris@174
|
329 m_vpan->show();
|
Chris@174
|
330 } else {
|
Chris@174
|
331 m_vpan->hide();
|
Chris@174
|
332 }
|
Chris@174
|
333 }
|
Chris@174
|
334
|
Chris@127
|
335 bool
|
Chris@127
|
336 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
|
Chris@127
|
337 {
|
Chris@127
|
338 QPoint discard;
|
Chris@127
|
339 bool b0, b1;
|
Chris@127
|
340
|
Chris@711
|
341 if (m_manager && m_manager->getToolModeFor(this) == ViewManager::MeasureMode) {
|
Chris@262
|
342 return false;
|
Chris@262
|
343 }
|
matthiasm@651
|
344
|
Chris@326
|
345 if (m_manager && !m_manager->shouldIlluminateLocalFeatures()) {
|
Chris@326
|
346 return false;
|
Chris@326
|
347 }
|
Chris@326
|
348
|
Chris@127
|
349 if (layer == getSelectedLayer() &&
|
Chris@753
|
350 !shouldIlluminateLocalSelection(discard, b0, b1)) {
|
Chris@753
|
351
|
Chris@753
|
352 pos = m_identifyPoint;
|
Chris@753
|
353 return m_identifyFeatures;
|
Chris@127
|
354 }
|
Chris@127
|
355
|
Chris@127
|
356 return false;
|
Chris@127
|
357 }
|
Chris@127
|
358
|
Chris@127
|
359 bool
|
Chris@127
|
360 Pane::shouldIlluminateLocalSelection(QPoint &pos,
|
gyorgyf@645
|
361 bool &closeToLeft,
|
gyorgyf@645
|
362 bool &closeToRight) const
|
Chris@127
|
363 {
|
Chris@127
|
364 if (m_identifyFeatures &&
|
Chris@731
|
365 m_manager &&
|
Chris@731
|
366 m_manager->getToolModeFor(this) == ViewManager::EditMode &&
|
Chris@731
|
367 !m_manager->getSelections().empty() &&
|
Chris@731
|
368 !selectionIsBeingEdited()) {
|
gyorgyf@645
|
369
|
Chris@753
|
370 Selection s(getSelectionAt(m_identifyPoint.x(),
|
Chris@753
|
371 closeToLeft, closeToRight));
|
Chris@753
|
372
|
Chris@753
|
373 if (!s.isEmpty()) {
|
Chris@753
|
374 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
|
Chris@753
|
375
|
Chris@753
|
376 pos = m_identifyPoint;
|
Chris@753
|
377 return true;
|
Chris@753
|
378 }
|
gyorgyf@645
|
379 }
|
gyorgyf@645
|
380 }
|
Chris@127
|
381
|
Chris@127
|
382 return false;
|
Chris@127
|
383 }
|
Chris@127
|
384
|
Chris@127
|
385 bool
|
Chris@127
|
386 Pane::selectionIsBeingEdited() const
|
Chris@127
|
387 {
|
Chris@127
|
388 if (!m_editingSelection.isEmpty()) {
|
gyorgyf@645
|
389 if (m_mousePos != m_clickPos &&
|
gyorgyf@645
|
390 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) {
|
gyorgyf@645
|
391 return true;
|
gyorgyf@645
|
392 }
|
Chris@127
|
393 }
|
Chris@127
|
394 return false;
|
Chris@127
|
395 }
|
Chris@127
|
396
|
Chris@127
|
397 void
|
Chris@127
|
398 Pane::setCentreLineVisible(bool visible)
|
Chris@127
|
399 {
|
Chris@127
|
400 m_centreLineVisible = visible;
|
Chris@127
|
401 update();
|
Chris@127
|
402 }
|
Chris@127
|
403
|
Chris@127
|
404 void
|
Chris@127
|
405 Pane::paintEvent(QPaintEvent *e)
|
Chris@127
|
406 {
|
Chris@127
|
407 // Profiler profiler("Pane::paintEvent", true);
|
Chris@127
|
408
|
Chris@127
|
409 QPainter paint;
|
Chris@127
|
410
|
Chris@127
|
411 QRect r(rect());
|
Chris@261
|
412 if (e) r = e->rect();
|
Chris@127
|
413
|
Chris@127
|
414 View::paintEvent(e);
|
Chris@127
|
415
|
Chris@127
|
416 paint.begin(this);
|
Chris@339
|
417 setPaintFont(paint);
|
Chris@338
|
418
|
Chris@261
|
419 if (e) paint.setClipRect(r);
|
Chris@127
|
420
|
Chris@711
|
421 ViewManager::ToolMode toolMode = m_manager->getToolModeFor(this);
|
Chris@259
|
422
|
Chris@127
|
423 if (m_manager &&
|
Chris@290
|
424 // !m_manager->isPlaying() &&
|
Chris@290
|
425 m_mouseInWidget &&
|
Chris@259
|
426 toolMode == ViewManager::MeasureMode) {
|
Chris@127
|
427
|
Chris@127
|
428 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@127
|
429 --vi;
|
Chris@127
|
430
|
Chris@127
|
431 std::vector<QRect> crosshairExtents;
|
Chris@127
|
432
|
Chris@127
|
433 if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint,
|
Chris@127
|
434 crosshairExtents)) {
|
Chris@127
|
435 (*vi)->paintCrosshairs(this, paint, m_identifyPoint);
|
Chris@127
|
436 break;
|
Chris@127
|
437 } else if ((*vi)->isLayerOpaque()) {
|
Chris@127
|
438 break;
|
Chris@127
|
439 }
|
Chris@127
|
440 }
|
Chris@127
|
441 }
|
Chris@127
|
442
|
Chris@268
|
443 Layer *topLayer = getTopLayer();
|
Chris@277
|
444 bool haveSomeTimeXAxis = false;
|
Chris@268
|
445
|
Chris@258
|
446 const Model *waveformModel = 0; // just for reporting purposes
|
Chris@326
|
447 const Model *workModel = 0;
|
Chris@326
|
448
|
Chris@127
|
449 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@127
|
450 --vi;
|
Chris@277
|
451 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) {
|
Chris@277
|
452 haveSomeTimeXAxis = true;
|
Chris@277
|
453 }
|
Chris@127
|
454 if (dynamic_cast<WaveformLayer *>(*vi)) {
|
Chris@127
|
455 waveformModel = (*vi)->getModel();
|
Chris@326
|
456 workModel = waveformModel;
|
Chris@326
|
457 } else {
|
Chris@326
|
458 Model *m = (*vi)->getModel();
|
Chris@326
|
459 if (dynamic_cast<WaveFileModel *>(m)) {
|
Chris@326
|
460 workModel = m;
|
Chris@326
|
461 } else if (m && dynamic_cast<WaveFileModel *>(m->getSourceModel())) {
|
Chris@326
|
462 workModel = m->getSourceModel();
|
Chris@326
|
463 }
|
Chris@127
|
464 }
|
Chris@326
|
465
|
Chris@326
|
466 if (waveformModel && workModel && haveSomeTimeXAxis) break;
|
Chris@258
|
467 }
|
Chris@127
|
468
|
Chris@261
|
469 m_scaleWidth = 0;
|
Chris@261
|
470
|
Chris@759
|
471 if (workModel) {
|
Chris@759
|
472 drawModelTimeExtents(r, paint, workModel);
|
Chris@759
|
473 }
|
Chris@759
|
474
|
Chris@261
|
475 if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) {
|
Chris@261
|
476 drawVerticalScale(r, topLayer, paint);
|
Chris@261
|
477 }
|
Chris@261
|
478
|
Chris@326
|
479 if (m_identifyFeatures &&
|
Chris@326
|
480 m_manager && m_manager->shouldIlluminateLocalFeatures() &&
|
Chris@326
|
481 topLayer) {
|
Chris@261
|
482 drawFeatureDescription(topLayer, paint);
|
Chris@261
|
483 }
|
Chris@261
|
484
|
Chris@261
|
485 int sampleRate = getModelsSampleRate();
|
Chris@261
|
486 paint.setBrush(Qt::NoBrush);
|
Chris@261
|
487
|
Chris@261
|
488 if (m_centreLineVisible &&
|
Chris@261
|
489 m_manager &&
|
Chris@261
|
490 m_manager->shouldShowCentreLine()) {
|
Chris@277
|
491 drawCentreLine(sampleRate, paint, !haveSomeTimeXAxis);
|
Chris@261
|
492 }
|
Chris@261
|
493
|
Chris@261
|
494 paint.setPen(QColor(50, 50, 50));
|
Chris@261
|
495
|
Chris@261
|
496 if (waveformModel &&
|
Chris@261
|
497 m_manager &&
|
Chris@261
|
498 m_manager->shouldShowDuration()) {
|
Chris@261
|
499 drawDurationAndRate(r, waveformModel, sampleRate, paint);
|
Chris@261
|
500 }
|
Chris@261
|
501
|
Chris@326
|
502 bool haveWorkTitle = false;
|
Chris@326
|
503
|
Chris@326
|
504 if (workModel &&
|
Chris@326
|
505 m_manager &&
|
Chris@326
|
506 m_manager->shouldShowWorkTitle()) {
|
Chris@326
|
507 drawWorkTitle(r, paint, workModel);
|
Chris@326
|
508 haveWorkTitle = true;
|
Chris@326
|
509 }
|
Chris@326
|
510
|
Chris@326
|
511 if (workModel &&
|
Chris@320
|
512 m_manager &&
|
Chris@320
|
513 m_manager->getAlignMode()) {
|
Chris@326
|
514 drawAlignmentStatus(r, paint, workModel, haveWorkTitle);
|
Chris@320
|
515 }
|
Chris@320
|
516
|
Chris@261
|
517 if (m_manager &&
|
Chris@261
|
518 m_manager->shouldShowLayerNames()) {
|
Chris@261
|
519 drawLayerNames(r, paint);
|
Chris@261
|
520 }
|
Chris@261
|
521
|
Chris@262
|
522 if (m_shiftPressed && m_clickedInRange &&
|
Chris@283
|
523 (toolMode == ViewManager::NavigateMode || m_navigating)) {
|
Chris@261
|
524
|
Chris@261
|
525 //!!! be nice if this looked a bit more in keeping with the
|
Chris@261
|
526 //selection block
|
Chris@262
|
527
|
Chris@262
|
528 paint.setPen(Qt::blue);
|
Chris@262
|
529 //!!! shouldn't use clickPos -- needs to use a clicked frame
|
Chris@262
|
530 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
|
Chris@262
|
531 m_mousePos.x() - m_clickPos.x(),
|
Chris@262
|
532 m_mousePos.y() - m_clickPos.y());
|
Chris@261
|
533
|
Chris@262
|
534 }
|
Chris@261
|
535
|
Chris@266
|
536 if (toolMode == ViewManager::MeasureMode && topLayer) {
|
Chris@272
|
537 bool showFocus = false;
|
Chris@272
|
538 if (!m_manager || !m_manager->isPlaying()) showFocus = true;
|
Chris@272
|
539 topLayer->paintMeasurementRects(this, paint, showFocus, m_identifyPoint);
|
Chris@261
|
540 }
|
Chris@261
|
541
|
Chris@261
|
542 if (selectionIsBeingEdited()) {
|
Chris@261
|
543 drawEditingSelection(paint);
|
Chris@261
|
544 }
|
Chris@261
|
545
|
Chris@261
|
546 paint.end();
|
Chris@261
|
547 }
|
Chris@261
|
548
|
Chris@276
|
549 size_t
|
Chris@276
|
550 Pane::getVerticalScaleWidth() const
|
Chris@276
|
551 {
|
Chris@276
|
552 if (m_scaleWidth > 0) return m_scaleWidth;
|
Chris@276
|
553 else return 0;
|
Chris@276
|
554 }
|
Chris@276
|
555
|
Chris@261
|
556 void
|
Chris@261
|
557 Pane::drawVerticalScale(QRect r, Layer *topLayer, QPainter &paint)
|
Chris@261
|
558 {
|
Chris@258
|
559 Layer *scaleLayer = 0;
|
Chris@258
|
560
|
Chris@261
|
561 float min, max;
|
Chris@261
|
562 bool log;
|
Chris@261
|
563 QString unit;
|
Chris@258
|
564
|
Chris@261
|
565 // If the top layer has no scale and reports no display
|
Chris@261
|
566 // extents, but does report a unit, then the scale should be
|
Chris@261
|
567 // drawn from any underlying layer with a scale and that unit.
|
Chris@261
|
568 // If the top layer has no scale and no value extents at all,
|
Chris@261
|
569 // then the scale should be drawn from any underlying layer
|
Chris@261
|
570 // with a scale regardless of unit.
|
Chris@258
|
571
|
Chris@607
|
572 int sw = topLayer->getVerticalScaleWidth
|
Chris@607
|
573 (this, m_manager->shouldShowVerticalColourScale(), paint);
|
Chris@258
|
574
|
Chris@261
|
575 if (sw > 0) {
|
Chris@261
|
576 scaleLayer = topLayer;
|
Chris@261
|
577 m_scaleWidth = sw;
|
Chris@258
|
578
|
Chris@261
|
579 } else {
|
Chris@258
|
580
|
Chris@261
|
581 bool hasDisplayExtents = topLayer->getDisplayExtents(min, max);
|
Chris@261
|
582 bool hasValueExtents = topLayer->getValueExtents(min, max, log, unit);
|
Chris@261
|
583
|
Chris@261
|
584 if (!hasDisplayExtents) {
|
Chris@258
|
585
|
Chris@261
|
586 if (!hasValueExtents) {
|
Chris@258
|
587
|
Chris@261
|
588 for (LayerList::iterator vi = m_layers.end();
|
Chris@261
|
589 vi != m_layers.begin(); ) {
|
Chris@261
|
590
|
Chris@261
|
591 --vi;
|
Chris@261
|
592
|
Chris@261
|
593 if ((*vi) == topLayer) continue;
|
Chris@261
|
594
|
Chris@607
|
595 sw = (*vi)->getVerticalScaleWidth
|
Chris@607
|
596 (this, m_manager->shouldShowVerticalColourScale(), paint);
|
Chris@261
|
597
|
Chris@261
|
598 if (sw > 0) {
|
Chris@261
|
599 scaleLayer = *vi;
|
Chris@261
|
600 m_scaleWidth = sw;
|
Chris@261
|
601 break;
|
Chris@261
|
602 }
|
Chris@261
|
603 }
|
Chris@261
|
604 } else if (unit != "") { // && hasValueExtents && !hasDisplayExtents
|
Chris@258
|
605
|
Chris@261
|
606 QString requireUnit = unit;
|
Chris@261
|
607
|
Chris@261
|
608 for (LayerList::iterator vi = m_layers.end();
|
Chris@261
|
609 vi != m_layers.begin(); ) {
|
Chris@258
|
610
|
Chris@261
|
611 --vi;
|
Chris@258
|
612
|
Chris@261
|
613 if ((*vi) == topLayer) continue;
|
Chris@258
|
614
|
Chris@261
|
615 if ((*vi)->getDisplayExtents(min, max)) {
|
Chris@261
|
616
|
Chris@261
|
617 // search no further than this: if the
|
Chris@261
|
618 // scale from this layer isn't suitable,
|
Chris@261
|
619 // we'll have to draw no scale (else we'd
|
Chris@261
|
620 // risk ending up with the wrong scale)
|
Chris@261
|
621
|
Chris@261
|
622 if ((*vi)->getValueExtents(min, max, log, unit) &&
|
Chris@261
|
623 unit == requireUnit) {
|
Chris@261
|
624
|
Chris@607
|
625 sw = (*vi)->getVerticalScaleWidth
|
Chris@607
|
626 (this, m_manager->shouldShowVerticalColourScale(), paint);
|
Chris@261
|
627 if (sw > 0) {
|
Chris@261
|
628 scaleLayer = *vi;
|
Chris@261
|
629 m_scaleWidth = sw;
|
Chris@261
|
630 }
|
Chris@258
|
631 }
|
Chris@261
|
632 break;
|
Chris@258
|
633 }
|
Chris@258
|
634 }
|
Chris@258
|
635 }
|
Chris@127
|
636 }
|
Chris@258
|
637 }
|
Chris@127
|
638
|
Chris@258
|
639 if (!scaleLayer) m_scaleWidth = 0;
|
Chris@258
|
640
|
Chris@258
|
641 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) {
|
Chris@127
|
642
|
gyorgyf@645
|
643 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
|
gyorgyf@645
|
644
|
gyorgyf@645
|
645 // SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl;
|
Chris@258
|
646 paint.save();
|
Chris@258
|
647
|
Chris@287
|
648 paint.setPen(getForeground());
|
Chris@287
|
649 paint.setBrush(getBackground());
|
Chris@258
|
650 paint.drawRect(0, -1, m_scaleWidth, height()+1);
|
Chris@258
|
651
|
Chris@258
|
652 paint.setBrush(Qt::NoBrush);
|
Chris@258
|
653 scaleLayer->paintVerticalScale
|
Chris@607
|
654 (this, m_manager->shouldShowVerticalColourScale(),
|
Chris@607
|
655 paint, QRect(0, 0, m_scaleWidth, height()));
|
Chris@258
|
656
|
Chris@258
|
657 paint.restore();
|
Chris@258
|
658 }
|
Chris@261
|
659 }
|
Chris@261
|
660
|
Chris@261
|
661 void
|
Chris@261
|
662 Pane::drawFeatureDescription(Layer *topLayer, QPainter &paint)
|
Chris@261
|
663 {
|
Chris@261
|
664 QPoint pos = m_identifyPoint;
|
Chris@261
|
665 QString desc = topLayer->getFeatureDescription(this, pos);
|
gyorgyf@645
|
666
|
Chris@261
|
667 if (desc != "") {
|
Chris@261
|
668
|
Chris@261
|
669 paint.save();
|
Chris@261
|
670
|
Chris@261
|
671 int tabStop =
|
Chris@261
|
672 paint.fontMetrics().width(tr("Some lengthy prefix:"));
|
Chris@261
|
673
|
Chris@261
|
674 QRect boundingRect =
|
Chris@261
|
675 paint.fontMetrics().boundingRect
|
Chris@261
|
676 (rect(),
|
Chris@261
|
677 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
|
Chris@261
|
678 desc, tabStop);
|
Chris@261
|
679
|
Chris@261
|
680 if (hasLightBackground()) {
|
Chris@261
|
681 paint.setPen(Qt::NoPen);
|
Chris@261
|
682 paint.setBrush(QColor(250, 250, 250, 200));
|
Chris@261
|
683 } else {
|
Chris@261
|
684 paint.setPen(Qt::NoPen);
|
Chris@261
|
685 paint.setBrush(QColor(50, 50, 50, 200));
|
Chris@261
|
686 }
|
Chris@261
|
687
|
Chris@261
|
688 int extra = paint.fontMetrics().descent();
|
Chris@261
|
689 paint.drawRect(width() - boundingRect.width() - 10 - extra,
|
Chris@261
|
690 10 - extra,
|
Chris@261
|
691 boundingRect.width() + 2 * extra,
|
Chris@261
|
692 boundingRect.height() + extra);
|
Chris@261
|
693
|
Chris@261
|
694 if (hasLightBackground()) {
|
Chris@261
|
695 paint.setPen(QColor(150, 20, 0));
|
Chris@261
|
696 } else {
|
Chris@261
|
697 paint.setPen(QColor(255, 150, 100));
|
Chris@261
|
698 }
|
Chris@261
|
699
|
Chris@261
|
700 QTextOption option;
|
Chris@261
|
701 option.setWrapMode(QTextOption::NoWrap);
|
Chris@261
|
702 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
|
Chris@261
|
703 option.setTabStop(tabStop);
|
Chris@261
|
704 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
|
Chris@261
|
705 boundingRect.width(),
|
Chris@261
|
706 boundingRect.height()),
|
Chris@261
|
707 desc,
|
Chris@261
|
708 option);
|
Chris@261
|
709
|
Chris@261
|
710 paint.restore();
|
Chris@261
|
711 }
|
Chris@261
|
712 }
|
Chris@258
|
713
|
Chris@261
|
714 void
|
Chris@277
|
715 Pane::drawCentreLine(int sampleRate, QPainter &paint, bool omitLine)
|
Chris@261
|
716 {
|
Chris@261
|
717 int fontHeight = paint.fontMetrics().height();
|
Chris@261
|
718 int fontAscent = paint.fontMetrics().ascent();
|
Chris@261
|
719
|
Chris@261
|
720 QColor c = QColor(0, 0, 0);
|
Chris@261
|
721 if (!hasLightBackground()) {
|
Chris@261
|
722 c = QColor(240, 240, 240);
|
Chris@261
|
723 }
|
Chris@277
|
724
|
Chris@261
|
725 paint.setPen(c);
|
Chris@274
|
726 int x = width() / 2;
|
Chris@277
|
727
|
Chris@277
|
728 if (!omitLine) {
|
Chris@277
|
729 paint.drawLine(x, 0, x, height() - 1);
|
Chris@277
|
730 paint.drawLine(x-1, 1, x+1, 1);
|
Chris@277
|
731 paint.drawLine(x-2, 0, x+2, 0);
|
Chris@277
|
732 paint.drawLine(x-1, height() - 2, x+1, height() - 2);
|
Chris@277
|
733 paint.drawLine(x-2, height() - 1, x+2, height() - 1);
|
Chris@277
|
734 }
|
Chris@261
|
735
|
Chris@261
|
736 paint.setPen(QColor(50, 50, 50));
|
Chris@261
|
737
|
Chris@261
|
738 int y = height() - fontHeight + fontAscent - 6;
|
Chris@261
|
739
|
Chris@261
|
740 LayerList::iterator vi = m_layers.end();
|
Chris@261
|
741
|
Chris@261
|
742 if (vi != m_layers.begin()) {
|
gyorgyf@645
|
743
|
Chris@261
|
744 switch ((*--vi)->getPreferredFrameCountPosition()) {
|
Chris@258
|
745
|
Chris@261
|
746 case Layer::PositionTop:
|
Chris@261
|
747 y = fontAscent + 6;
|
Chris@261
|
748 break;
|
Chris@258
|
749
|
Chris@261
|
750 case Layer::PositionMiddle:
|
Chris@261
|
751 y = (height() - fontHeight) / 2
|
Chris@261
|
752 + fontAscent;
|
Chris@261
|
753 break;
|
Chris@127
|
754
|
Chris@261
|
755 case Layer::PositionBottom:
|
Chris@261
|
756 // y already set correctly
|
Chris@261
|
757 break;
|
Chris@127
|
758 }
|
Chris@127
|
759 }
|
Chris@127
|
760
|
Chris@261
|
761 if (m_manager && m_manager->shouldShowFrameCount()) {
|
Chris@261
|
762
|
Chris@261
|
763 if (sampleRate) {
|
Chris@127
|
764
|
Chris@261
|
765 QString text(QString::fromStdString
|
Chris@261
|
766 (RealTime::frame2RealTime
|
Chris@549
|
767 (m_centreFrame, sampleRate)
|
Chris@549
|
768 .toText(true)));
|
Chris@127
|
769
|
Chris@261
|
770 int tw = paint.fontMetrics().width(text);
|
Chris@261
|
771 int x = width()/2 - 4 - tw;
|
Chris@127
|
772
|
Chris@127
|
773 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@127
|
774 }
|
Chris@261
|
775
|
Chris@261
|
776 QString text = QString("%1").arg(m_centreFrame);
|
Chris@261
|
777
|
Chris@261
|
778 int x = width()/2 + 4;
|
Chris@261
|
779
|
Chris@261
|
780 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@261
|
781 }
|
Chris@261
|
782 }
|
Chris@127
|
783
|
Chris@261
|
784 void
|
Chris@759
|
785 Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model *model)
|
Chris@759
|
786 {
|
Chris@759
|
787 int x0 = getXForFrame(model->getStartFrame());
|
Chris@759
|
788 int x1 = getXForFrame(model->getEndFrame());
|
Chris@759
|
789
|
Chris@759
|
790 paint.save();
|
Chris@759
|
791
|
Chris@759
|
792 QBrush brush;
|
Chris@759
|
793
|
Chris@759
|
794 if (hasLightBackground()) {
|
Chris@759
|
795 brush = QBrush(QColor("#f8f8f8"));
|
Chris@759
|
796 paint.setPen(Qt::black);
|
Chris@759
|
797 } else {
|
Chris@759
|
798 brush = QBrush(QColor("#101010"));
|
Chris@759
|
799 paint.setPen(Qt::white);
|
Chris@759
|
800 }
|
Chris@759
|
801
|
Chris@759
|
802 if (x0 > r.x()) {
|
Chris@759
|
803 paint.fillRect(0, 0, x0, height(), brush);
|
Chris@759
|
804 paint.drawLine(x0, 0, x0, height());
|
Chris@759
|
805 }
|
Chris@759
|
806
|
Chris@759
|
807 if (x1 < r.x() + r.width()) {
|
Chris@759
|
808 paint.fillRect(x1, 0, width() - x1, height(), brush);
|
Chris@759
|
809 paint.drawLine(x1, 0, x1, height());
|
Chris@759
|
810 }
|
Chris@759
|
811
|
Chris@759
|
812 paint.restore();
|
Chris@759
|
813 }
|
Chris@759
|
814
|
Chris@759
|
815 void
|
Chris@326
|
816 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model,
|
Chris@326
|
817 bool down)
|
Chris@320
|
818 {
|
Chris@320
|
819 const Model *reference = model->getAlignmentReference();
|
Chris@320
|
820 /*
|
Chris@320
|
821 if (!reference) {
|
Chris@682
|
822 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl;
|
Chris@320
|
823 } else if (reference == model) {
|
Chris@682
|
824 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl;
|
Chris@320
|
825 } else {
|
Chris@682
|
826 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl;
|
Chris@320
|
827 }
|
Chris@320
|
828 */
|
Chris@320
|
829 QString text;
|
Chris@320
|
830 int completion = 100;
|
Chris@320
|
831
|
Chris@320
|
832 if (reference == model) {
|
Chris@320
|
833 text = tr("Reference");
|
Chris@320
|
834 } else if (!reference) {
|
Chris@320
|
835 text = tr("Unaligned");
|
Chris@320
|
836 } else {
|
Chris@320
|
837 completion = model->getAlignmentCompletion();
|
Chris@320
|
838 if (completion == 0) {
|
Chris@320
|
839 text = tr("Unaligned");
|
Chris@320
|
840 } else if (completion < 100) {
|
Chris@320
|
841 text = tr("Aligning: %1%").arg(completion);
|
Chris@320
|
842 } else {
|
Chris@320
|
843 text = tr("Aligned");
|
Chris@320
|
844 }
|
Chris@320
|
845 }
|
Chris@320
|
846
|
Chris@320
|
847 paint.save();
|
Chris@320
|
848 QFont font(paint.font());
|
Chris@320
|
849 font.setBold(true);
|
Chris@320
|
850 paint.setFont(font);
|
Chris@326
|
851 if (completion < 100) paint.setBrush(Qt::red);
|
Chris@326
|
852
|
Chris@326
|
853 int y = 5;
|
Chris@326
|
854 if (down) y += paint.fontMetrics().height();
|
Chris@326
|
855 int w = paint.fontMetrics().width(text);
|
Chris@326
|
856 int h = paint.fontMetrics().height();
|
Chris@326
|
857 if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) {
|
Chris@326
|
858 paint.restore();
|
Chris@326
|
859 return;
|
Chris@326
|
860 }
|
Chris@320
|
861
|
Chris@320
|
862 drawVisibleText(paint, m_scaleWidth + 5,
|
Chris@326
|
863 paint.fontMetrics().ascent() + y, text, OutlinedText);
|
Chris@320
|
864
|
Chris@320
|
865 paint.restore();
|
Chris@320
|
866 }
|
Chris@320
|
867
|
Chris@320
|
868 void
|
Chris@320
|
869 Pane::modelAlignmentCompletionChanged()
|
Chris@320
|
870 {
|
Chris@320
|
871 View::modelAlignmentCompletionChanged();
|
Chris@320
|
872 update(QRect(0, 0, 300, 100));
|
Chris@320
|
873 }
|
Chris@320
|
874
|
Chris@320
|
875 void
|
Chris@326
|
876 Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model)
|
Chris@326
|
877 {
|
Chris@326
|
878 QString title = model->getTitle();
|
Chris@326
|
879 QString maker = model->getMaker();
|
Chris@587
|
880 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl;
|
Chris@326
|
881 if (title == "") return;
|
Chris@326
|
882
|
Chris@326
|
883 QString text = title;
|
Chris@326
|
884 if (maker != "") {
|
Chris@326
|
885 text = tr("%1 - %2").arg(title).arg(maker);
|
Chris@326
|
886 }
|
Chris@326
|
887
|
Chris@326
|
888 paint.save();
|
Chris@326
|
889 QFont font(paint.font());
|
Chris@326
|
890 font.setItalic(true);
|
Chris@326
|
891 paint.setFont(font);
|
Chris@326
|
892
|
Chris@326
|
893 int y = 5;
|
Chris@326
|
894 int w = paint.fontMetrics().width(text);
|
Chris@326
|
895 int h = paint.fontMetrics().height();
|
Chris@326
|
896 if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) {
|
Chris@326
|
897 paint.restore();
|
Chris@326
|
898 return;
|
Chris@326
|
899 }
|
Chris@326
|
900
|
Chris@326
|
901 drawVisibleText(paint, m_scaleWidth + 5,
|
Chris@326
|
902 paint.fontMetrics().ascent() + y, text, OutlinedText);
|
Chris@326
|
903
|
Chris@326
|
904 paint.restore();
|
Chris@326
|
905 }
|
Chris@326
|
906
|
Chris@326
|
907 void
|
Chris@261
|
908 Pane::drawLayerNames(QRect r, QPainter &paint)
|
Chris@261
|
909 {
|
Chris@261
|
910 int fontHeight = paint.fontMetrics().height();
|
Chris@261
|
911 int fontAscent = paint.fontMetrics().ascent();
|
Chris@127
|
912
|
Chris@300
|
913 int lly = height() - 6;
|
Chris@300
|
914 if (m_manager->getZoomWheelsEnabled()) {
|
Chris@300
|
915 lly -= 20;
|
Chris@300
|
916 }
|
Chris@300
|
917
|
Chris@300
|
918 if (r.y() + r.height() < lly - int(m_layers.size()) * fontHeight) {
|
Chris@261
|
919 return;
|
Chris@127
|
920 }
|
Chris@127
|
921
|
Chris@294
|
922 QStringList texts;
|
Chris@299
|
923 std::vector<QPixmap> pixmaps;
|
Chris@294
|
924 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@294
|
925 texts.push_back((*i)->getLayerPresentationName());
|
Chris@682
|
926 // cerr << "Pane " << this << ": Layer presentation name for " << *i << ": "
|
Chris@682
|
927 // << texts[texts.size()-1] << endl;
|
Chris@299
|
928 pixmaps.push_back((*i)->getLayerPresentationPixmap
|
Chris@299
|
929 (QSize(fontAscent, fontAscent)));
|
Chris@294
|
930 }
|
Chris@127
|
931
|
Chris@294
|
932 int maxTextWidth = width() / 3;
|
Chris@294
|
933 texts = TextAbbrev::abbreviate(texts, paint.fontMetrics(), maxTextWidth);
|
Chris@294
|
934
|
Chris@261
|
935 int llx = width() - maxTextWidth - 5;
|
Chris@261
|
936 if (m_manager->getZoomWheelsEnabled()) {
|
Chris@261
|
937 llx -= 36;
|
Chris@261
|
938 }
|
Chris@261
|
939
|
Chris@300
|
940 if (r.x() + r.width() >= llx - fontAscent - 3) {
|
gyorgyf@645
|
941
|
Chris@802
|
942 for (int i = 0; i < texts.size(); ++i) {
|
Chris@299
|
943
|
Chris@682
|
944 // cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << endl;
|
Chris@261
|
945
|
Chris@261
|
946 if (i + 1 == texts.size()) {
|
Chris@287
|
947 paint.setPen(getForeground());
|
Chris@261
|
948 }
|
Chris@261
|
949
|
Chris@261
|
950 drawVisibleText(paint, llx,
|
Chris@261
|
951 lly - fontHeight + fontAscent,
|
Chris@261
|
952 texts[i], OutlinedText);
|
Chris@299
|
953
|
Chris@299
|
954 if (!pixmaps[i].isNull()) {
|
Chris@299
|
955 paint.drawPixmap(llx - fontAscent - 3,
|
Chris@299
|
956 lly - fontHeight + (fontHeight-fontAscent)/2,
|
Chris@299
|
957 pixmaps[i]);
|
Chris@299
|
958 }
|
Chris@261
|
959
|
Chris@261
|
960 lly -= fontHeight;
|
Chris@261
|
961 }
|
Chris@261
|
962 }
|
Chris@261
|
963 }
|
Chris@127
|
964
|
Chris@261
|
965 void
|
Chris@261
|
966 Pane::drawEditingSelection(QPainter &paint)
|
Chris@261
|
967 {
|
Chris@261
|
968 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@577
|
969
|
Chris@577
|
970 long origStart = m_editingSelection.getStartFrame();
|
Chris@577
|
971
|
Chris@577
|
972 int p0 = getXForFrame(origStart) + offset;
|
Chris@261
|
973 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@577
|
974
|
Chris@261
|
975 if (m_editingSelectionEdge < 0) {
|
Chris@261
|
976 p1 = getXForFrame(m_editingSelection.getEndFrame());
|
Chris@261
|
977 } else if (m_editingSelectionEdge > 0) {
|
Chris@261
|
978 p0 = getXForFrame(m_editingSelection.getStartFrame());
|
Chris@127
|
979 }
|
Chris@127
|
980
|
Chris@577
|
981 long newStart = getFrameForX(p0);
|
Chris@577
|
982 long newEnd = getFrameForX(p1);
|
Chris@577
|
983
|
Chris@261
|
984 paint.save();
|
Chris@287
|
985 paint.setPen(QPen(getForeground(), 2));
|
Chris@577
|
986
|
Chris@577
|
987 int fontHeight = paint.fontMetrics().height();
|
Chris@577
|
988 int fontAscent = paint.fontMetrics().ascent();
|
Chris@577
|
989 int sampleRate = getModelsSampleRate();
|
Chris@577
|
990 QString startText, endText, offsetText;
|
Chris@577
|
991 startText = QString("%1").arg(newStart);
|
Chris@577
|
992 endText = QString("%1").arg(newEnd);
|
Chris@577
|
993 offsetText = QString("%1").arg(newStart - origStart);
|
Chris@577
|
994 if (newStart >= origStart) {
|
Chris@577
|
995 offsetText = tr("+%1").arg(offsetText);
|
Chris@577
|
996 }
|
Chris@577
|
997 if (sampleRate) {
|
Chris@577
|
998 startText = QString("%1 / %2")
|
Chris@577
|
999 .arg(QString::fromStdString
|
Chris@577
|
1000 (RealTime::frame2RealTime(newStart, sampleRate).toText()))
|
Chris@577
|
1001 .arg(startText);
|
Chris@577
|
1002 endText = QString("%1 / %2")
|
Chris@577
|
1003 .arg(QString::fromStdString
|
Chris@577
|
1004 (RealTime::frame2RealTime(newEnd, sampleRate).toText()))
|
Chris@577
|
1005 .arg(endText);
|
Chris@577
|
1006 offsetText = QString("%1 / %2")
|
Chris@577
|
1007 .arg(QString::fromStdString
|
Chris@577
|
1008 (RealTime::frame2RealTime(newStart - origStart, sampleRate).toText()))
|
Chris@577
|
1009 .arg(offsetText);
|
Chris@577
|
1010 if (newStart >= origStart) {
|
Chris@577
|
1011 offsetText = tr("+%1").arg(offsetText);
|
Chris@577
|
1012 }
|
Chris@577
|
1013 }
|
Chris@577
|
1014 drawVisibleText(paint, p0 + 2, fontAscent + fontHeight + 4, startText, OutlinedText);
|
Chris@577
|
1015 drawVisibleText(paint, p1 + 2, fontAscent + fontHeight + 4, endText, OutlinedText);
|
Chris@577
|
1016 drawVisibleText(paint, p0 + 2, fontAscent + fontHeight*2 + 4, offsetText, OutlinedText);
|
Chris@577
|
1017 drawVisibleText(paint, p1 + 2, fontAscent + fontHeight*2 + 4, offsetText, OutlinedText);
|
Chris@261
|
1018
|
Chris@261
|
1019 //!!! duplicating display policy with View::drawSelections
|
Chris@261
|
1020
|
Chris@261
|
1021 if (m_editingSelectionEdge < 0) {
|
Chris@261
|
1022 paint.drawLine(p0, 1, p1, 1);
|
Chris@261
|
1023 paint.drawLine(p0, 0, p0, height());
|
Chris@261
|
1024 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@261
|
1025 } else if (m_editingSelectionEdge > 0) {
|
Chris@261
|
1026 paint.drawLine(p0, 1, p1, 1);
|
Chris@261
|
1027 paint.drawLine(p1, 0, p1, height());
|
Chris@261
|
1028 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@261
|
1029 } else {
|
Chris@261
|
1030 paint.setBrush(Qt::NoBrush);
|
Chris@261
|
1031 paint.drawRect(p0, 1, p1 - p0, height() - 2);
|
Chris@261
|
1032 }
|
Chris@261
|
1033 paint.restore();
|
Chris@261
|
1034 }
|
Chris@127
|
1035
|
Chris@261
|
1036 void
|
Chris@261
|
1037 Pane::drawDurationAndRate(QRect r, const Model *waveformModel,
|
Chris@261
|
1038 int sampleRate, QPainter &paint)
|
Chris@261
|
1039 {
|
Chris@261
|
1040 int fontHeight = paint.fontMetrics().height();
|
Chris@261
|
1041 int fontAscent = paint.fontMetrics().ascent();
|
Chris@127
|
1042
|
Chris@261
|
1043 if (r.y() + r.height() < height() - fontHeight - 6) return;
|
Chris@127
|
1044
|
Chris@261
|
1045 size_t modelRate = waveformModel->getSampleRate();
|
Chris@301
|
1046 size_t nativeRate = waveformModel->getNativeRate();
|
Chris@261
|
1047 size_t playbackRate = m_manager->getPlaybackSampleRate();
|
Chris@261
|
1048 size_t outputRate = m_manager->getOutputSampleRate();
|
Chris@261
|
1049
|
Chris@261
|
1050 QString srNote = "";
|
Chris@127
|
1051
|
Chris@301
|
1052 // Show (R) for waveform models that have been resampled or will
|
Chris@301
|
1053 // be resampled on playback, and (X) for waveform models that will
|
Chris@301
|
1054 // be played at the wrong rate because their rate differs from the
|
Chris@261
|
1055 // current playback rate (which is not necessarily that of the
|
Chris@261
|
1056 // main model).
|
Chris@127
|
1057
|
Chris@261
|
1058 if (playbackRate != 0) {
|
Chris@261
|
1059 if (modelRate == playbackRate) {
|
Chris@301
|
1060 if (modelRate != outputRate || modelRate != nativeRate) {
|
Chris@301
|
1061 srNote = " " + tr("(R)");
|
Chris@301
|
1062 }
|
Chris@261
|
1063 } else {
|
Chris@261
|
1064 srNote = " " + tr("(X)");
|
Chris@261
|
1065 }
|
Chris@127
|
1066 }
|
Chris@127
|
1067
|
Chris@261
|
1068 QString desc = tr("%1 / %2Hz%3")
|
Chris@261
|
1069 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
|
Chris@261
|
1070 sampleRate)
|
Chris@261
|
1071 .toText(false).c_str())
|
Chris@301
|
1072 .arg(nativeRate)
|
Chris@261
|
1073 .arg(srNote);
|
Chris@261
|
1074
|
Chris@384
|
1075 int x = m_scaleWidth + 5;
|
Chris@384
|
1076 int pbw = getProgressBarWidth();
|
Chris@384
|
1077 if (x < pbw + 5) x = pbw + 5;
|
Chris@384
|
1078
|
Chris@384
|
1079 if (r.x() < x + paint.fontMetrics().width(desc)) {
|
Chris@384
|
1080 drawVisibleText(paint, x,
|
Chris@261
|
1081 height() - fontHeight + fontAscent - 6,
|
Chris@261
|
1082 desc, OutlinedText);
|
Chris@261
|
1083 }
|
Chris@127
|
1084 }
|
Chris@127
|
1085
|
Chris@227
|
1086 bool
|
Chris@229
|
1087 Pane::render(QPainter &paint, int xorigin, size_t f0, size_t f1)
|
Chris@227
|
1088 {
|
Chris@229
|
1089 if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) {
|
Chris@227
|
1090 return false;
|
Chris@227
|
1091 }
|
Chris@227
|
1092
|
Chris@227
|
1093 if (m_scaleWidth > 0) {
|
Chris@227
|
1094
|
Chris@227
|
1095 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@227
|
1096 --vi;
|
Chris@227
|
1097
|
Chris@227
|
1098 paint.save();
|
Chris@227
|
1099
|
Chris@287
|
1100 paint.setPen(getForeground());
|
Chris@287
|
1101 paint.setBrush(getBackground());
|
Chris@229
|
1102 paint.drawRect(xorigin, -1, m_scaleWidth, height()+1);
|
Chris@227
|
1103
|
Chris@227
|
1104 paint.setBrush(Qt::NoBrush);
|
Chris@227
|
1105 (*vi)->paintVerticalScale
|
Chris@607
|
1106 (this, m_manager->shouldShowVerticalColourScale(),
|
Chris@607
|
1107 paint, QRect(xorigin, 0, m_scaleWidth, height()));
|
Chris@227
|
1108
|
Chris@227
|
1109 paint.restore();
|
Chris@227
|
1110 break;
|
Chris@227
|
1111 }
|
Chris@227
|
1112 }
|
Chris@227
|
1113
|
Chris@227
|
1114 return true;
|
Chris@227
|
1115 }
|
Chris@227
|
1116
|
Chris@227
|
1117 QImage *
|
Chris@229
|
1118 Pane::toNewImage(size_t f0, size_t f1)
|
Chris@227
|
1119 {
|
Chris@227
|
1120 size_t x0 = f0 / getZoomLevel();
|
Chris@227
|
1121 size_t x1 = f1 / getZoomLevel();
|
Chris@227
|
1122
|
Chris@227
|
1123 QImage *image = new QImage(x1 - x0 + m_scaleWidth,
|
Chris@227
|
1124 height(), QImage::Format_RGB32);
|
Chris@227
|
1125
|
Chris@227
|
1126 int formerScaleWidth = m_scaleWidth;
|
Chris@227
|
1127
|
Chris@227
|
1128 if (m_manager && m_manager->shouldShowVerticalScale()) {
|
Chris@227
|
1129 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@227
|
1130 --vi;
|
Chris@227
|
1131 QPainter paint(image);
|
Chris@607
|
1132 m_scaleWidth = (*vi)->getVerticalScaleWidth
|
Chris@607
|
1133 (this, m_manager->shouldShowVerticalColourScale(), paint);
|
Chris@227
|
1134 break;
|
Chris@227
|
1135 }
|
Chris@227
|
1136 } else {
|
Chris@227
|
1137 m_scaleWidth = 0;
|
Chris@227
|
1138 }
|
Chris@227
|
1139
|
Chris@227
|
1140 if (m_scaleWidth != formerScaleWidth) {
|
Chris@227
|
1141 delete image;
|
Chris@227
|
1142 image = new QImage(x1 - x0 + m_scaleWidth,
|
Chris@227
|
1143 height(), QImage::Format_RGB32);
|
Chris@227
|
1144 }
|
Chris@227
|
1145
|
Chris@227
|
1146 QPainter *paint = new QPainter(image);
|
Chris@229
|
1147 if (!render(*paint, 0, f0, f1)) {
|
Chris@227
|
1148 delete paint;
|
Chris@227
|
1149 delete image;
|
Chris@227
|
1150 return 0;
|
Chris@227
|
1151 } else {
|
Chris@227
|
1152 delete paint;
|
Chris@227
|
1153 return image;
|
Chris@227
|
1154 }
|
Chris@227
|
1155 }
|
Chris@227
|
1156
|
Chris@229
|
1157 QSize
|
Chris@229
|
1158 Pane::getImageSize(size_t f0, size_t f1)
|
Chris@229
|
1159 {
|
Chris@229
|
1160 QSize s = View::getImageSize(f0, f1);
|
Chris@229
|
1161 QImage *image = new QImage(100, 100, QImage::Format_RGB32);
|
Chris@229
|
1162 QPainter paint(image);
|
Chris@229
|
1163
|
Chris@229
|
1164 int sw = 0;
|
Chris@229
|
1165 if (m_manager && m_manager->shouldShowVerticalScale()) {
|
Chris@229
|
1166 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@229
|
1167 --vi;
|
Chris@607
|
1168 sw = (*vi)->getVerticalScaleWidth
|
Chris@607
|
1169 (this, m_manager->shouldShowVerticalColourScale(), paint);
|
Chris@229
|
1170 break;
|
Chris@229
|
1171 }
|
Chris@229
|
1172 }
|
Chris@229
|
1173
|
Chris@229
|
1174 return QSize(sw + s.width(), s.height());
|
Chris@229
|
1175 }
|
Chris@229
|
1176
|
Chris@222
|
1177 size_t
|
Chris@222
|
1178 Pane::getFirstVisibleFrame() const
|
Chris@222
|
1179 {
|
Chris@222
|
1180 long f0 = getFrameForX(m_scaleWidth);
|
Chris@222
|
1181 size_t f = View::getFirstVisibleFrame();
|
Chris@222
|
1182 if (f0 < 0 || f0 < long(f)) return f;
|
Chris@222
|
1183 return f0;
|
Chris@222
|
1184 }
|
Chris@222
|
1185
|
Chris@127
|
1186 Selection
|
Chris@127
|
1187 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
|
Chris@127
|
1188 {
|
Chris@127
|
1189 closeToLeftEdge = closeToRightEdge = false;
|
Chris@127
|
1190
|
Chris@127
|
1191 if (!m_manager) return Selection();
|
Chris@127
|
1192
|
Chris@127
|
1193 long testFrame = getFrameForX(x - 5);
|
Chris@127
|
1194 if (testFrame < 0) {
|
gyorgyf@645
|
1195 testFrame = getFrameForX(x);
|
gyorgyf@645
|
1196 if (testFrame < 0) return Selection();
|
Chris@127
|
1197 }
|
Chris@127
|
1198
|
Chris@127
|
1199 Selection selection = m_manager->getContainingSelection(testFrame, true);
|
Chris@127
|
1200 if (selection.isEmpty()) return selection;
|
Chris@127
|
1201
|
Chris@127
|
1202 int lx = getXForFrame(selection.getStartFrame());
|
Chris@127
|
1203 int rx = getXForFrame(selection.getEndFrame());
|
Chris@127
|
1204
|
Chris@127
|
1205 int fuzz = 2;
|
Chris@127
|
1206 if (x < lx - fuzz || x > rx + fuzz) return Selection();
|
Chris@127
|
1207
|
Chris@127
|
1208 int width = rx - lx;
|
Chris@127
|
1209 fuzz = 3;
|
Chris@127
|
1210 if (width < 12) fuzz = width / 4;
|
Chris@127
|
1211 if (fuzz < 1) fuzz = 1;
|
Chris@127
|
1212
|
Chris@127
|
1213 if (x < lx + fuzz) closeToLeftEdge = true;
|
Chris@127
|
1214 if (x > rx - fuzz) closeToRightEdge = true;
|
Chris@127
|
1215
|
Chris@127
|
1216 return selection;
|
Chris@127
|
1217 }
|
Chris@127
|
1218
|
Chris@174
|
1219 bool
|
Chris@174
|
1220 Pane::canTopLayerMoveVertical()
|
Chris@174
|
1221 {
|
Chris@174
|
1222 float vmin, vmax, dmin, dmax;
|
Chris@174
|
1223 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false;
|
Chris@174
|
1224 if (dmin <= vmin && dmax >= vmax) return false;
|
Chris@174
|
1225 return true;
|
Chris@174
|
1226 }
|
Chris@174
|
1227
|
Chris@174
|
1228 bool
|
Chris@174
|
1229 Pane::getTopLayerDisplayExtents(float &vmin, float &vmax,
|
Chris@188
|
1230 float &dmin, float &dmax,
|
Chris@188
|
1231 QString *unit)
|
Chris@174
|
1232 {
|
Chris@268
|
1233 Layer *layer = getTopLayer();
|
Chris@174
|
1234 if (!layer) return false;
|
Chris@174
|
1235 bool vlog;
|
Chris@174
|
1236 QString vunit;
|
Chris@188
|
1237 bool rv = (layer->getValueExtents(vmin, vmax, vlog, vunit) &&
|
Chris@188
|
1238 layer->getDisplayExtents(dmin, dmax));
|
Chris@188
|
1239 if (unit) *unit = vunit;
|
Chris@188
|
1240 return rv;
|
Chris@174
|
1241 }
|
Chris@174
|
1242
|
Chris@174
|
1243 bool
|
Chris@174
|
1244 Pane::setTopLayerDisplayExtents(float dmin, float dmax)
|
Chris@174
|
1245 {
|
Chris@268
|
1246 Layer *layer = getTopLayer();
|
Chris@174
|
1247 if (!layer) return false;
|
Chris@174
|
1248 return layer->setDisplayExtents(dmin, dmax);
|
Chris@174
|
1249 }
|
Chris@174
|
1250
|
Chris@127
|
1251 void
|
Chris@282
|
1252 Pane::registerShortcuts(KeyReference &kr)
|
Chris@282
|
1253 {
|
Chris@282
|
1254 kr.setCategory(tr("Zoom"));
|
Chris@282
|
1255 kr.registerAlternativeShortcut(tr("Zoom In"), tr("Wheel Up"));
|
Chris@282
|
1256 kr.registerAlternativeShortcut(tr("Zoom Out"), tr("Wheel Down"));
|
Chris@282
|
1257
|
Chris@282
|
1258 kr.setCategory(tr("General Pane Mouse Actions"));
|
Chris@282
|
1259
|
Chris@282
|
1260 kr.registerShortcut(tr("Zoom"), tr("Wheel"),
|
Chris@282
|
1261 tr("Zoom in or out in time axis"));
|
Chris@408
|
1262 kr.registerShortcut(tr("Scroll"), tr("Ctrl+Wheel"),
|
Chris@282
|
1263 tr("Scroll rapidly left or right in time axis"));
|
Chris@282
|
1264 kr.registerShortcut(tr("Zoom Vertically"), tr("Shift+Wheel"),
|
Chris@282
|
1265 tr("Zoom in or out in the vertical axis"));
|
Chris@282
|
1266 kr.registerShortcut(tr("Scroll Vertically"), tr("Alt+Wheel"),
|
Chris@282
|
1267 tr("Scroll up or down in the vertical axis"));
|
Chris@282
|
1268 kr.registerShortcut(tr("Navigate"), tr("Middle"),
|
Chris@282
|
1269 tr("Click middle button and drag to navigate with any tool"));
|
Chris@282
|
1270 kr.registerShortcut(tr("Relocate"), tr("Double-Click Middle"),
|
Chris@282
|
1271 tr("Double-click middle button to relocate with any tool"));
|
Chris@282
|
1272 kr.registerShortcut(tr("Menu"), tr("Right"),
|
Chris@282
|
1273 tr("Show pane context menu"));
|
Chris@282
|
1274 }
|
Chris@282
|
1275
|
Chris@753
|
1276 Layer *
|
Chris@753
|
1277 Pane::getTopFlexiNoteLayer()
|
Chris@753
|
1278 {
|
Chris@753
|
1279 for (int i = int(m_layers.size()) - 1; i >= 0; --i) {
|
Chris@753
|
1280 if (LayerFactory::getInstance()->getLayerType(m_layers[i]) ==
|
Chris@753
|
1281 LayerFactory::FlexiNotes) {
|
Chris@753
|
1282 return m_layers[i];
|
Chris@753
|
1283 }
|
Chris@753
|
1284 }
|
Chris@753
|
1285 return 0;
|
Chris@753
|
1286 }
|
Chris@753
|
1287
|
Chris@282
|
1288 void
|
Chris@127
|
1289 Pane::mousePressEvent(QMouseEvent *e)
|
Chris@127
|
1290 {
|
Chris@127
|
1291 if (e->buttons() & Qt::RightButton) {
|
Chris@189
|
1292 emit contextHelpChanged("");
|
Chris@127
|
1293 emit rightButtonMenuRequested(mapToGlobal(e->pos()));
|
Chris@127
|
1294 return;
|
Chris@127
|
1295 }
|
Chris@127
|
1296
|
Chris@682
|
1297 // cerr << "mousePressEvent" << endl;
|
Chris@341
|
1298
|
Chris@127
|
1299 m_clickPos = e->pos();
|
Chris@262
|
1300 m_mousePos = m_clickPos;
|
Chris@127
|
1301 m_clickedInRange = true;
|
Chris@127
|
1302 m_editingSelection = Selection();
|
Chris@127
|
1303 m_editingSelectionEdge = 0;
|
Chris@127
|
1304 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@127
|
1305 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@510
|
1306 m_altPressed = (e->modifiers() & Qt::AltModifier);
|
Chris@150
|
1307 m_dragMode = UnresolvedDrag;
|
Chris@127
|
1308
|
Chris@127
|
1309 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@711
|
1310 if (m_manager) mode = m_manager->getToolModeFor(this);
|
Chris@127
|
1311
|
Chris@127
|
1312 m_navigating = false;
|
Chris@343
|
1313 m_resizing = false;
|
Chris@343
|
1314 m_editing = false;
|
Chris@343
|
1315 m_releasing = false;
|
Chris@127
|
1316
|
Chris@283
|
1317 if (mode == ViewManager::NavigateMode ||
|
Chris@283
|
1318 (e->buttons() & Qt::MidButton) ||
|
Chris@283
|
1319 (mode == ViewManager::MeasureMode &&
|
Chris@283
|
1320 (e->buttons() & Qt::LeftButton) && m_shiftPressed)) {
|
Chris@127
|
1321
|
Chris@713
|
1322 if (mode != ViewManager::NavigateMode) {
|
Chris@713
|
1323 setCursor(Qt::PointingHandCursor);
|
Chris@713
|
1324 }
|
Chris@713
|
1325
|
Chris@713
|
1326 m_navigating = true;
|
Chris@713
|
1327 m_dragCentreFrame = m_centreFrame;
|
Chris@136
|
1328 m_dragStartMinValue = 0;
|
Chris@174
|
1329
|
Chris@174
|
1330 float vmin, vmax, dmin, dmax;
|
Chris@174
|
1331 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@174
|
1332 m_dragStartMinValue = dmin;
|
Chris@136
|
1333 }
|
Chris@136
|
1334
|
Chris@802
|
1335 // Schedule a play-head move to the mouse frame location. This
|
Chris@802
|
1336 // will happen only if nothing else of interest happens
|
Chris@802
|
1337 // (double-click, drag) before the timeout.
|
Chris@802
|
1338 schedulePlaybackFrameMove(getFrameForX(e->x()));
|
Chris@802
|
1339
|
Chris@127
|
1340 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
1341
|
Chris@217
|
1342 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
1343
|
Chris@713
|
1344 bool closeToLeft = false, closeToRight = false;
|
Chris@713
|
1345 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@713
|
1346
|
Chris@713
|
1347 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@713
|
1348
|
Chris@713
|
1349 m_manager->removeSelection(selection);
|
Chris@713
|
1350
|
Chris@713
|
1351 if (closeToLeft) {
|
Chris@713
|
1352 m_selectionStartFrame = selection.getEndFrame();
|
Chris@713
|
1353 } else {
|
Chris@713
|
1354 m_selectionStartFrame = selection.getStartFrame();
|
Chris@713
|
1355 }
|
Chris@713
|
1356
|
Chris@713
|
1357 m_manager->setInProgressSelection(selection, false);
|
Chris@713
|
1358 m_resizing = true;
|
Chris@713
|
1359
|
gyorgyf@645
|
1360 } else {
|
Chris@713
|
1361
|
Chris@713
|
1362 int mouseFrame = getFrameForX(e->x());
|
Chris@713
|
1363 size_t resolution = 1;
|
Chris@713
|
1364 int snapFrame = mouseFrame;
|
gyorgyf@645
|
1365
|
Chris@713
|
1366 Layer *layer = getSelectedLayer();
|
Chris@713
|
1367 if (layer && !m_shiftPressed) {
|
Chris@713
|
1368 layer->snapToFeatureFrame(this, snapFrame,
|
Chris@713
|
1369 resolution, Layer::SnapLeft);
|
Chris@713
|
1370 }
|
gyorgyf@645
|
1371
|
Chris@713
|
1372 if (snapFrame < 0) snapFrame = 0;
|
Chris@713
|
1373 m_selectionStartFrame = snapFrame;
|
Chris@713
|
1374 if (m_manager) {
|
Chris@713
|
1375 m_manager->setInProgressSelection
|
Chris@333
|
1376 (Selection(alignToReference(snapFrame),
|
Chris@333
|
1377 alignToReference(snapFrame + resolution)),
|
Chris@333
|
1378 !m_ctrlPressed);
|
Chris@713
|
1379 }
|
Chris@713
|
1380
|
Chris@713
|
1381 m_resizing = false;
|
Chris@802
|
1382
|
Chris@802
|
1383 // Schedule a play-head move to the mouse frame
|
Chris@802
|
1384 // location. This will happen only if nothing else of
|
Chris@802
|
1385 // interest happens (double-click, drag) before the
|
Chris@802
|
1386 // timeout.
|
Chris@802
|
1387 schedulePlaybackFrameMove(mouseFrame);
|
gyorgyf@645
|
1388 }
|
gyorgyf@645
|
1389
|
Chris@713
|
1390 update();
|
Chris@127
|
1391
|
Chris@127
|
1392 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
1393
|
Chris@713
|
1394 Layer *layer = getSelectedLayer();
|
Chris@713
|
1395 if (layer && layer->isLayerEditable()) {
|
Chris@713
|
1396 layer->drawStart(this, e);
|
Chris@713
|
1397 }
|
Chris@127
|
1398
|
Chris@335
|
1399 } else if (mode == ViewManager::EraseMode) {
|
Chris@335
|
1400
|
Chris@713
|
1401 Layer *layer = getSelectedLayer();
|
Chris@713
|
1402 if (layer && layer->isLayerEditable()) {
|
Chris@713
|
1403 layer->eraseStart(this, e);
|
Chris@713
|
1404 }
|
Chris@713
|
1405
|
Chris@713
|
1406 // GF: handle mouse press for NoteEditMode
|
gyorgyf@645
|
1407 } else if (mode == ViewManager::NoteEditMode) {
|
gyorgyf@645
|
1408
|
gyorgyf@645
|
1409 std::cerr << "mouse pressed in note edit mode" << std::endl;
|
Chris@753
|
1410 Layer *layer = getTopFlexiNoteLayer();
|
Chris@753
|
1411 if (layer) {
|
gyorgyf@635
|
1412 layer->splitStart(this, e);
|
gyorgyf@635
|
1413 }
|
Chris@335
|
1414
|
Chris@127
|
1415 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
1416
|
Chris@343
|
1417 // Do nothing here -- we'll do it in mouseMoveEvent when the
|
Chris@343
|
1418 // drag threshold has been passed
|
Chris@262
|
1419
|
Chris@262
|
1420 } else if (mode == ViewManager::MeasureMode) {
|
Chris@262
|
1421
|
Chris@268
|
1422 Layer *layer = getTopLayer();
|
Chris@267
|
1423 if (layer) layer->measureStart(this, e);
|
Chris@262
|
1424 update();
|
Chris@127
|
1425 }
|
Chris@127
|
1426
|
Chris@127
|
1427 emit paneInteractedWith();
|
Chris@127
|
1428 }
|
Chris@127
|
1429
|
Chris@127
|
1430 void
|
Chris@802
|
1431 Pane::schedulePlaybackFrameMove(int frame)
|
Chris@802
|
1432 {
|
Chris@802
|
1433 m_playbackFrameMoveTo = frame;
|
Chris@802
|
1434 m_playbackFrameMoveScheduled = true;
|
Chris@802
|
1435 QTimer::singleShot(QApplication::doubleClickInterval() + 10, this,
|
Chris@802
|
1436 SLOT(playbackScheduleTimerElapsed()));
|
Chris@802
|
1437 }
|
Chris@802
|
1438
|
Chris@802
|
1439 void
|
Chris@802
|
1440 Pane::playbackScheduleTimerElapsed()
|
Chris@802
|
1441 {
|
Chris@802
|
1442 if (m_playbackFrameMoveScheduled) {
|
Chris@802
|
1443 m_manager->setPlaybackFrame(m_playbackFrameMoveTo);
|
Chris@802
|
1444 m_playbackFrameMoveScheduled = false;
|
Chris@802
|
1445 }
|
Chris@802
|
1446 }
|
Chris@802
|
1447
|
Chris@802
|
1448 void
|
Chris@127
|
1449 Pane::mouseReleaseEvent(QMouseEvent *e)
|
Chris@127
|
1450 {
|
Chris@127
|
1451 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
1452 return;
|
Chris@127
|
1453 }
|
Chris@127
|
1454
|
Chris@682
|
1455 // cerr << "mouseReleaseEvent" << endl;
|
Chris@341
|
1456
|
Chris@127
|
1457 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@711
|
1458 if (m_manager) mode = m_manager->getToolModeFor(this);
|
Chris@127
|
1459
|
Chris@343
|
1460 m_releasing = true;
|
Chris@343
|
1461
|
Chris@127
|
1462 if (m_clickedInRange) {
|
Chris@713
|
1463 mouseMoveEvent(e);
|
Chris@127
|
1464 }
|
Chris@127
|
1465
|
Chris@790
|
1466 int mouseFrame = e ? getFrameForX(e->x()) : 0;
|
Chris@802
|
1467 if (mouseFrame < 0) mouseFrame = 0;
|
Chris@790
|
1468
|
Chris@127
|
1469 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@127
|
1470
|
Chris@713
|
1471 m_navigating = false;
|
Chris@713
|
1472
|
Chris@713
|
1473 if (mode != ViewManager::NavigateMode) {
|
Chris@713
|
1474 // restore cursor
|
Chris@713
|
1475 toolModeChanged();
|
Chris@713
|
1476 }
|
Chris@713
|
1477
|
Chris@713
|
1478 if (m_shiftPressed) {
|
Chris@713
|
1479
|
Chris@713
|
1480 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
|
Chris@713
|
1481 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
|
Chris@713
|
1482
|
Chris@713
|
1483 int y0 = std::min(m_clickPos.y(), m_mousePos.y());
|
Chris@713
|
1484 int y1 = std::max(m_clickPos.y(), m_mousePos.y());
|
Chris@127
|
1485
|
Chris@730
|
1486 emit regionOutlined(QRect(x0, y0, x1 - x0, y1 - y0));
|
Chris@713
|
1487 }
|
Chris@127
|
1488
|
Chris@127
|
1489 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
1490
|
Chris@343
|
1491 if (!hasTopLayerTimeXAxis()) {
|
Chris@343
|
1492 m_releasing = false;
|
Chris@343
|
1493 return;
|
Chris@343
|
1494 }
|
Chris@217
|
1495
|
Chris@713
|
1496 if (m_manager && m_manager->haveInProgressSelection()) {
|
Chris@713
|
1497
|
justin@726
|
1498 //cerr << "JTEST: release with selection" << endl;
|
Chris@713
|
1499 bool exclusive;
|
Chris@713
|
1500 Selection selection = m_manager->getInProgressSelection(exclusive);
|
gyorgyf@645
|
1501
|
Chris@713
|
1502 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
|
Chris@713
|
1503 selection = Selection();
|
Chris@713
|
1504 }
|
Chris@713
|
1505
|
Chris@713
|
1506 m_manager->clearInProgressSelection();
|
Chris@713
|
1507
|
Chris@713
|
1508 if (exclusive) {
|
Chris@713
|
1509 m_manager->setSelection(selection);
|
Chris@713
|
1510 } else {
|
Chris@713
|
1511 m_manager->addSelection(selection);
|
Chris@713
|
1512 }
|
justin@726
|
1513 }
|
Chris@713
|
1514
|
Chris@713
|
1515 update();
|
Chris@713
|
1516
|
Chris@713
|
1517 } else if (mode == ViewManager::DrawMode) {
|
Chris@713
|
1518
|
Chris@713
|
1519 Layer *layer = getSelectedLayer();
|
Chris@713
|
1520 if (layer && layer->isLayerEditable()) {
|
Chris@713
|
1521 layer->drawEnd(this, e);
|
Chris@713
|
1522 update();
|
gyorgyf@645
|
1523 }
|
Chris@127
|
1524
|
Chris@335
|
1525 } else if (mode == ViewManager::EraseMode) {
|
Chris@335
|
1526
|
gyorgyf@645
|
1527 Layer *layer = getSelectedLayer();
|
gyorgyf@645
|
1528 if (layer && layer->isLayerEditable()) {
|
gyorgyf@645
|
1529 layer->eraseEnd(this, e);
|
gyorgyf@645
|
1530 update();
|
gyorgyf@645
|
1531 }
|
gyorgyf@645
|
1532
|
gyorgyf@645
|
1533 } else if (mode == ViewManager::NoteEditMode) {
|
gyorgyf@645
|
1534
|
gyorgyf@645
|
1535 //GF: handle mouse release for NoteEditMode (note: works but will need to re-think this a bit later)
|
Chris@753
|
1536 Layer *layer = getTopFlexiNoteLayer();
|
Chris@753
|
1537
|
Chris@753
|
1538 if (layer) {
|
gyorgyf@635
|
1539 layer->splitEnd(this, e);
|
Chris@753
|
1540 update();
|
Chris@753
|
1541
|
Chris@753
|
1542 if (m_editing) {
|
Chris@753
|
1543 if (!editSelectionEnd(e)) {
|
Chris@753
|
1544 layer->editEnd(this, e);
|
Chris@753
|
1545 update();
|
Chris@753
|
1546 }
|
Chris@753
|
1547 }
|
Chris@753
|
1548 }
|
Chris@753
|
1549
|
Chris@753
|
1550 } else if (mode == ViewManager::EditMode) {
|
Chris@753
|
1551
|
Chris@343
|
1552 if (m_editing) {
|
Chris@343
|
1553 if (!editSelectionEnd(e)) {
|
Chris@343
|
1554 Layer *layer = getSelectedLayer();
|
Chris@343
|
1555 if (layer && layer->isLayerEditable()) {
|
Chris@343
|
1556 layer->editEnd(this, e);
|
Chris@343
|
1557 update();
|
Chris@343
|
1558 }
|
Chris@343
|
1559 }
|
gyorgyf@635
|
1560 }
|
Chris@607
|
1561
|
Chris@262
|
1562 } else if (mode == ViewManager::MeasureMode) {
|
Chris@262
|
1563
|
Chris@268
|
1564 Layer *layer = getTopLayer();
|
Chris@267
|
1565 if (layer) layer->measureEnd(this, e);
|
Chris@267
|
1566 if (m_measureCursor1) setCursor(*m_measureCursor1);
|
Chris@267
|
1567 update();
|
Chris@127
|
1568 }
|
Chris@127
|
1569
|
Chris@127
|
1570 m_clickedInRange = false;
|
Chris@343
|
1571 m_releasing = false;
|
Chris@127
|
1572
|
Chris@127
|
1573 emit paneInteractedWith();
|
Chris@127
|
1574 }
|
Chris@127
|
1575
|
Chris@127
|
1576 void
|
Chris@127
|
1577 Pane::mouseMoveEvent(QMouseEvent *e)
|
Chris@127
|
1578 {
|
Chris@127
|
1579 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
1580 return;
|
Chris@127
|
1581 }
|
Chris@127
|
1582
|
Chris@682
|
1583 // cerr << "mouseMoveEvent" << endl;
|
Chris@341
|
1584
|
Chris@616
|
1585 QPoint pos = e->pos();
|
Chris@616
|
1586 updateContextHelp(&pos);
|
Chris@189
|
1587
|
Chris@343
|
1588 if (m_navigating && m_clickedInRange && !m_releasing) {
|
Chris@343
|
1589
|
Chris@343
|
1590 // if no buttons pressed, and not called from
|
Chris@343
|
1591 // mouseReleaseEvent, we want to reset clicked-ness (to avoid
|
Chris@343
|
1592 // annoying continual drags when we moved the mouse outside
|
Chris@343
|
1593 // the window after pressing button first time).
|
Chris@343
|
1594
|
Chris@343
|
1595 if (!(e->buttons() & Qt::LeftButton) &&
|
Chris@343
|
1596 !(e->buttons() & Qt::MidButton)) {
|
Chris@343
|
1597 m_clickedInRange = false;
|
Chris@343
|
1598 return;
|
Chris@343
|
1599 }
|
Chris@343
|
1600 }
|
Chris@343
|
1601
|
Chris@127
|
1602 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@711
|
1603 if (m_manager) mode = m_manager->getToolModeFor(this);
|
Chris@127
|
1604
|
Chris@127
|
1605 QPoint prevPoint = m_identifyPoint;
|
Chris@127
|
1606 m_identifyPoint = e->pos();
|
Chris@127
|
1607
|
Chris@127
|
1608 if (!m_clickedInRange) {
|
gyorgyf@645
|
1609
|
gyorgyf@646
|
1610 // GF: handle mouse move for context sensitive cursor switching in NoteEditMode.
|
gyorgyf@646
|
1611 // GF: Propagate the event to FlexiNoteLayer. I somehow feel it's best handeled there rather than here, but perhaps not if this will be needed elsewhere too.
|
Chris@753
|
1612 if (mode == ViewManager::NoteEditMode) {
|
Chris@753
|
1613 FlexiNoteLayer *layer = qobject_cast<FlexiNoteLayer *>(getTopFlexiNoteLayer());
|
Chris@753
|
1614 if (layer) {
|
Chris@753
|
1615 layer->mouseMoveEvent(this, e); //!!! ew
|
matthiasm@785
|
1616 update();
|
matthiasm@785
|
1617 // return;
|
Chris@753
|
1618 }
|
gyorgyf@646
|
1619 }
|
gyorgyf@646
|
1620
|
gyorgyf@646
|
1621 if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) {
|
gyorgyf@646
|
1622 bool closeToLeft = false, closeToRight = false;
|
gyorgyf@646
|
1623 getSelectionAt(e->x(), closeToLeft, closeToRight);
|
gyorgyf@646
|
1624 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
gyorgyf@646
|
1625 setCursor(Qt::SizeHorCursor);
|
gyorgyf@646
|
1626 } else {
|
gyorgyf@646
|
1627 setCursor(Qt::ArrowCursor);
|
gyorgyf@646
|
1628 }
|
gyorgyf@645
|
1629 }
|
Chris@127
|
1630
|
Chris@127
|
1631 if (!m_manager->isPlaying()) {
|
Chris@127
|
1632
|
Chris@272
|
1633 bool updating = false;
|
Chris@272
|
1634
|
Chris@326
|
1635 if (getSelectedLayer() &&
|
Chris@326
|
1636 m_manager->shouldIlluminateLocalFeatures()) {
|
Chris@127
|
1637
|
Chris@174
|
1638 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@174
|
1639 m_identifyFeatures = true;
|
Chris@174
|
1640
|
Chris@174
|
1641 if (m_identifyFeatures != previouslyIdentifying ||
|
Chris@174
|
1642 m_identifyPoint != prevPoint) {
|
Chris@174
|
1643 update();
|
Chris@272
|
1644 updating = true;
|
Chris@272
|
1645 }
|
Chris@272
|
1646 }
|
Chris@272
|
1647
|
Chris@272
|
1648 if (!updating && mode == ViewManager::MeasureMode &&
|
Chris@272
|
1649 m_manager && !m_manager->isPlaying()) {
|
Chris@272
|
1650
|
Chris@272
|
1651 Layer *layer = getTopLayer();
|
Chris@272
|
1652 if (layer && layer->nearestMeasurementRectChanged
|
Chris@272
|
1653 (this, prevPoint, m_identifyPoint)) {
|
Chris@272
|
1654 update();
|
Chris@174
|
1655 }
|
Chris@174
|
1656 }
|
Chris@127
|
1657 }
|
Chris@127
|
1658
|
Chris@713
|
1659 return;
|
Chris@127
|
1660 }
|
Chris@127
|
1661
|
Chris@127
|
1662 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@127
|
1663
|
Chris@713
|
1664 if (m_shiftPressed) {
|
Chris@713
|
1665
|
Chris@713
|
1666 m_mousePos = e->pos();
|
Chris@713
|
1667 update();
|
Chris@713
|
1668
|
Chris@713
|
1669 } else {
|
Chris@127
|
1670
|
Chris@174
|
1671 dragTopLayer(e);
|
Chris@150
|
1672 }
|
Chris@127
|
1673
|
Chris@127
|
1674 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
1675
|
Chris@713
|
1676 if (!hasTopLayerTimeXAxis()) return;
|
Chris@713
|
1677
|
Chris@713
|
1678 dragExtendSelection(e);
|
Chris@127
|
1679
|
Chris@127
|
1680 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
1681
|
gyorgyf@649
|
1682 Layer *layer = getSelectedLayer();
|
gyorgyf@649
|
1683 if (layer && layer->isLayerEditable()) {
|
gyorgyf@649
|
1684 layer->drawDrag(this, e);
|
gyorgyf@649
|
1685 }
|
Chris@127
|
1686
|
Chris@335
|
1687 } else if (mode == ViewManager::EraseMode) {
|
Chris@335
|
1688
|
gyorgyf@649
|
1689 Layer *layer = getSelectedLayer();
|
gyorgyf@649
|
1690 if (layer && layer->isLayerEditable()) {
|
gyorgyf@649
|
1691 layer->eraseDrag(this, e);
|
gyorgyf@649
|
1692 }
|
gyorgyf@649
|
1693
|
Chris@713
|
1694 // GF: handling NoteEditMode dragging and boundary actions for mouseMoveEvent
|
gyorgyf@649
|
1695 } else if (mode == ViewManager::NoteEditMode) {
|
gyorgyf@649
|
1696
|
gyorgyf@649
|
1697 bool resist = true;
|
gyorgyf@649
|
1698
|
gyorgyf@649
|
1699 if ((e->modifiers() & Qt::ShiftModifier)) {
|
gyorgyf@649
|
1700 m_shiftPressed = true;
|
gyorgyf@649
|
1701 }
|
gyorgyf@649
|
1702
|
gyorgyf@649
|
1703 if (m_shiftPressed) resist = false;
|
gyorgyf@649
|
1704
|
gyorgyf@649
|
1705 m_dragMode = updateDragMode
|
gyorgyf@649
|
1706 (m_dragMode,
|
gyorgyf@649
|
1707 m_clickPos,
|
gyorgyf@649
|
1708 e->pos(),
|
gyorgyf@649
|
1709 true, // can move horiz
|
gyorgyf@649
|
1710 true, // can move vert
|
gyorgyf@649
|
1711 resist, // resist horiz
|
gyorgyf@649
|
1712 resist); // resist vert
|
gyorgyf@649
|
1713
|
gyorgyf@649
|
1714 if (!m_editing) {
|
gyorgyf@649
|
1715
|
gyorgyf@649
|
1716 if (m_dragMode != UnresolvedDrag) {
|
gyorgyf@649
|
1717
|
gyorgyf@649
|
1718 m_editing = true;
|
gyorgyf@649
|
1719
|
gyorgyf@649
|
1720 QMouseEvent clickEvent(QEvent::MouseButtonPress,
|
gyorgyf@649
|
1721 m_clickPos,
|
gyorgyf@649
|
1722 Qt::NoButton,
|
gyorgyf@649
|
1723 e->buttons(),
|
gyorgyf@649
|
1724 e->modifiers());
|
gyorgyf@649
|
1725
|
gyorgyf@649
|
1726 if (!editSelectionStart(&clickEvent)) {
|
Chris@753
|
1727 Layer *layer = getTopFlexiNoteLayer();
|
Chris@753
|
1728 if (layer) {
|
gyorgyf@649
|
1729 std::cerr << "calling edit start" << std::endl;
|
gyorgyf@649
|
1730 layer->editStart(this, &clickEvent);
|
gyorgyf@649
|
1731 }
|
gyorgyf@649
|
1732 }
|
gyorgyf@649
|
1733 }
|
gyorgyf@649
|
1734
|
gyorgyf@649
|
1735 } else {
|
gyorgyf@649
|
1736
|
gyorgyf@649
|
1737 if (!editSelectionDrag(e)) {
|
gyorgyf@649
|
1738
|
gyorgyf@649
|
1739 Layer *layer = getSelectedLayer();
|
gyorgyf@649
|
1740
|
gyorgyf@649
|
1741 if (layer && layer->isLayerEditable()) {
|
gyorgyf@649
|
1742
|
gyorgyf@649
|
1743 int x = e->x();
|
gyorgyf@649
|
1744 int y = e->y();
|
gyorgyf@649
|
1745 if (m_dragMode == VerticalDrag) x = m_clickPos.x();
|
gyorgyf@649
|
1746 else if (m_dragMode == HorizontalDrag) y = m_clickPos.y();
|
gyorgyf@649
|
1747
|
gyorgyf@649
|
1748 QMouseEvent moveEvent(QEvent::MouseMove,
|
gyorgyf@649
|
1749 QPoint(x, y),
|
gyorgyf@649
|
1750 Qt::NoButton,
|
gyorgyf@649
|
1751 e->buttons(),
|
gyorgyf@649
|
1752 e->modifiers());
|
gyorgyf@649
|
1753 std::cerr << "calling editDrag" << std::endl;
|
gyorgyf@649
|
1754 layer->editDrag(this, &moveEvent);
|
gyorgyf@649
|
1755 }
|
gyorgyf@649
|
1756 }
|
gyorgyf@649
|
1757 }
|
Chris@335
|
1758
|
Chris@127
|
1759 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
1760
|
Chris@551
|
1761 bool resist = true;
|
Chris@551
|
1762
|
Chris@551
|
1763 if ((e->modifiers() & Qt::ShiftModifier)) {
|
Chris@551
|
1764 m_shiftPressed = true;
|
Chris@551
|
1765 // ... but don't set it false if shift has been
|
Chris@551
|
1766 // released -- we want the state when we started
|
Chris@551
|
1767 // dragging to be used most of the time
|
Chris@343
|
1768 }
|
Chris@343
|
1769
|
Chris@551
|
1770 if (m_shiftPressed) resist = false;
|
Chris@551
|
1771
|
Chris@551
|
1772 m_dragMode = updateDragMode
|
Chris@551
|
1773 (m_dragMode,
|
Chris@551
|
1774 m_clickPos,
|
Chris@551
|
1775 e->pos(),
|
Chris@551
|
1776 true, // can move horiz
|
Chris@551
|
1777 true, // can move vert
|
Chris@551
|
1778 resist, // resist horiz
|
Chris@551
|
1779 resist); // resist vert
|
Chris@551
|
1780
|
Chris@343
|
1781 if (!m_editing) {
|
Chris@343
|
1782
|
Chris@551
|
1783 if (m_dragMode != UnresolvedDrag) {
|
Chris@343
|
1784
|
Chris@343
|
1785 m_editing = true;
|
Chris@343
|
1786
|
Chris@343
|
1787 QMouseEvent clickEvent(QEvent::MouseButtonPress,
|
Chris@343
|
1788 m_clickPos,
|
Chris@343
|
1789 Qt::NoButton,
|
Chris@343
|
1790 e->buttons(),
|
Chris@343
|
1791 e->modifiers());
|
Chris@343
|
1792
|
Chris@343
|
1793 if (!editSelectionStart(&clickEvent)) {
|
Chris@343
|
1794 Layer *layer = getSelectedLayer();
|
Chris@343
|
1795 if (layer && layer->isLayerEditable()) {
|
Chris@343
|
1796 layer->editStart(this, &clickEvent);
|
Chris@343
|
1797 }
|
Chris@343
|
1798 }
|
Chris@343
|
1799 }
|
Chris@551
|
1800
|
Chris@551
|
1801 } else {
|
Chris@551
|
1802
|
Chris@551
|
1803 if (!editSelectionDrag(e)) {
|
Chris@551
|
1804
|
Chris@551
|
1805 Layer *layer = getSelectedLayer();
|
Chris@551
|
1806
|
Chris@551
|
1807 if (layer && layer->isLayerEditable()) {
|
Chris@551
|
1808
|
Chris@551
|
1809 int x = e->x();
|
Chris@551
|
1810 int y = e->y();
|
Chris@551
|
1811 if (m_dragMode == VerticalDrag) x = m_clickPos.x();
|
Chris@551
|
1812 else if (m_dragMode == HorizontalDrag) y = m_clickPos.y();
|
Chris@551
|
1813
|
Chris@551
|
1814 QMouseEvent moveEvent(QEvent::MouseMove,
|
Chris@551
|
1815 QPoint(x, y),
|
Chris@551
|
1816 Qt::NoButton,
|
Chris@551
|
1817 e->buttons(),
|
Chris@551
|
1818 e->modifiers());
|
Chris@551
|
1819
|
Chris@551
|
1820 layer->editDrag(this, &moveEvent);
|
Chris@551
|
1821 }
|
Chris@551
|
1822 }
|
Chris@343
|
1823 }
|
Chris@259
|
1824
|
Chris@259
|
1825 } else if (mode == ViewManager::MeasureMode) {
|
Chris@259
|
1826
|
Chris@267
|
1827 if (m_measureCursor2) setCursor(*m_measureCursor2);
|
Chris@266
|
1828
|
Chris@268
|
1829 Layer *layer = getTopLayer();
|
Chris@290
|
1830 if (layer) {
|
Chris@290
|
1831 layer->measureDrag(this, e);
|
Chris@290
|
1832 if (layer->hasTimeXAxis()) edgeScrollMaybe(e->x());
|
Chris@290
|
1833 }
|
Chris@267
|
1834
|
Chris@267
|
1835 update();
|
Chris@127
|
1836 }
|
Chris@802
|
1837
|
Chris@802
|
1838 if (m_dragMode != UnresolvedDrag) {
|
Chris@802
|
1839 m_playbackFrameMoveScheduled = false;
|
Chris@802
|
1840 }
|
Chris@127
|
1841 }
|
Chris@127
|
1842
|
Chris@127
|
1843 void
|
Chris@730
|
1844 Pane::zoomToRegion(QRect r)
|
Chris@174
|
1845 {
|
Chris@730
|
1846 int x0 = r.x();
|
Chris@730
|
1847 int y0 = r.y();
|
Chris@730
|
1848 int x1 = r.x() + r.width();
|
Chris@730
|
1849 int y1 = r.y() + r.height();
|
Chris@730
|
1850
|
Chris@174
|
1851 int w = x1 - x0;
|
gyorgyf@645
|
1852
|
Chris@174
|
1853 long newStartFrame = getFrameForX(x0);
|
gyorgyf@645
|
1854
|
Chris@174
|
1855 long visibleFrames = getEndFrame() - getStartFrame();
|
Chris@174
|
1856 if (newStartFrame <= -visibleFrames) {
|
Chris@174
|
1857 newStartFrame = -visibleFrames + 1;
|
Chris@174
|
1858 }
|
gyorgyf@645
|
1859
|
Chris@174
|
1860 if (newStartFrame >= long(getModelsEndFrame())) {
|
Chris@174
|
1861 newStartFrame = getModelsEndFrame() - 1;
|
Chris@174
|
1862 }
|
gyorgyf@645
|
1863
|
Chris@174
|
1864 float ratio = float(w) / float(width());
|
Chris@682
|
1865 // cerr << "ratio: " << ratio << endl;
|
Chris@174
|
1866 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
|
Chris@174
|
1867 if (newZoomLevel < 1) newZoomLevel = 1;
|
Chris@174
|
1868
|
Chris@682
|
1869 // cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl;
|
Chris@174
|
1870 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
|
Chris@174
|
1871 setStartFrame(newStartFrame);
|
Chris@174
|
1872
|
Chris@174
|
1873 QString unit;
|
Chris@174
|
1874 float min, max;
|
Chris@174
|
1875 bool log;
|
Chris@174
|
1876 Layer *layer = 0;
|
Chris@174
|
1877 for (LayerList::const_iterator i = m_layers.begin();
|
Chris@174
|
1878 i != m_layers.end(); ++i) {
|
Chris@174
|
1879 if ((*i)->getValueExtents(min, max, log, unit) &&
|
Chris@174
|
1880 (*i)->getDisplayExtents(min, max)) {
|
Chris@174
|
1881 layer = *i;
|
Chris@174
|
1882 break;
|
Chris@174
|
1883 }
|
Chris@174
|
1884 }
|
Chris@174
|
1885
|
Chris@174
|
1886 if (layer) {
|
Chris@174
|
1887 if (log) {
|
Chris@174
|
1888 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min);
|
Chris@174
|
1889 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max);
|
Chris@174
|
1890 }
|
Chris@174
|
1891 float rmin = min + ((max - min) * (height() - y1)) / height();
|
Chris@174
|
1892 float rmax = min + ((max - min) * (height() - y0)) / height();
|
Chris@682
|
1893 cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl;
|
Chris@174
|
1894 if (log) {
|
Chris@522
|
1895 rmin = powf(10, rmin);
|
Chris@522
|
1896 rmax = powf(10, rmax);
|
Chris@174
|
1897 }
|
Chris@682
|
1898 cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl;
|
Chris@174
|
1899
|
Chris@174
|
1900 layer->setDisplayExtents(rmin, rmax);
|
Chris@174
|
1901 updateVerticalPanner();
|
Chris@174
|
1902 }
|
Chris@174
|
1903 }
|
Chris@174
|
1904
|
Chris@174
|
1905 void
|
Chris@174
|
1906 Pane::dragTopLayer(QMouseEvent *e)
|
Chris@174
|
1907 {
|
Chris@174
|
1908 // We need to avoid making it too easy to drag both
|
Chris@174
|
1909 // horizontally and vertically, in the case where the
|
Chris@174
|
1910 // mouse is moved "mostly" in horizontal or vertical axis
|
Chris@174
|
1911 // with only a small variation in the other axis. This is
|
Chris@174
|
1912 // particularly important during playback (when we want to
|
Chris@174
|
1913 // avoid small horizontal motions) or in slow refresh
|
Chris@174
|
1914 // layers like spectrogram (when we want to avoid small
|
Chris@174
|
1915 // vertical motions).
|
Chris@174
|
1916 //
|
Chris@174
|
1917 // To this end we have horizontal and vertical thresholds
|
Chris@174
|
1918 // and a series of states: unresolved, horizontally or
|
Chris@174
|
1919 // vertically constrained, free.
|
Chris@174
|
1920 //
|
Chris@174
|
1921 // When the mouse first moves, we're unresolved: we
|
Chris@174
|
1922 // restrict ourselves to whichever direction seems safest,
|
Chris@174
|
1923 // until the mouse has passed a small threshold distance
|
Chris@174
|
1924 // from the click point. Then we lock in to one of the
|
Chris@174
|
1925 // constrained modes, based on which axis that distance
|
Chris@174
|
1926 // was measured in first. Finally, if it turns out we've
|
Chris@174
|
1927 // also moved more than a certain larger distance in the
|
Chris@174
|
1928 // other direction as well, we may switch into free mode.
|
Chris@174
|
1929 //
|
Chris@174
|
1930 // If the top layer is incapable of being dragged
|
Chris@174
|
1931 // vertically, the logic is short circuited.
|
Chris@174
|
1932
|
Chris@343
|
1933 m_dragMode = updateDragMode
|
Chris@343
|
1934 (m_dragMode,
|
Chris@343
|
1935 m_clickPos,
|
Chris@343
|
1936 e->pos(),
|
Chris@343
|
1937 true, // can move horiz
|
Chris@343
|
1938 canTopLayerMoveVertical(), // can move vert
|
Chris@343
|
1939 canTopLayerMoveVertical() || (m_manager && m_manager->isPlaying()), // resist horiz
|
Chris@343
|
1940 !(m_manager && m_manager->isPlaying())); // resist vert
|
Chris@174
|
1941
|
Chris@343
|
1942 if (m_dragMode == HorizontalDrag ||
|
Chris@343
|
1943 m_dragMode == FreeDrag) {
|
Chris@174
|
1944
|
Chris@174
|
1945 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
|
Chris@174
|
1946
|
Chris@174
|
1947 size_t newCentreFrame = m_dragCentreFrame;
|
gyorgyf@645
|
1948
|
Chris@174
|
1949 if (frameOff < 0) {
|
Chris@174
|
1950 newCentreFrame -= frameOff;
|
Chris@174
|
1951 } else if (newCentreFrame >= size_t(frameOff)) {
|
Chris@174
|
1952 newCentreFrame -= frameOff;
|
Chris@174
|
1953 } else {
|
Chris@174
|
1954 newCentreFrame = 0;
|
Chris@174
|
1955 }
|
Chris@363
|
1956
|
gyorgyf@645
|
1957 #ifdef DEBUG_PANE
|
Chris@587
|
1958 SVDEBUG << "Pane::dragTopLayer: newCentreFrame = " << newCentreFrame <<
|
Chris@585
|
1959 ", models end frame = " << getModelsEndFrame() << endl;
|
Chris@363
|
1960 #endif
|
Chris@339
|
1961
|
Chris@174
|
1962 if (newCentreFrame >= getModelsEndFrame()) {
|
Chris@174
|
1963 newCentreFrame = getModelsEndFrame();
|
Chris@174
|
1964 if (newCentreFrame > 0) --newCentreFrame;
|
Chris@174
|
1965 }
|
Chris@174
|
1966
|
Chris@174
|
1967 if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) {
|
Chris@510
|
1968 setCentreFrame(newCentreFrame, !m_altPressed);
|
Chris@174
|
1969 }
|
Chris@174
|
1970 }
|
Chris@174
|
1971
|
Chris@343
|
1972 if (m_dragMode == VerticalDrag ||
|
Chris@343
|
1973 m_dragMode == FreeDrag) {
|
Chris@174
|
1974
|
Chris@174
|
1975 float vmin = 0.f, vmax = 0.f;
|
Chris@174
|
1976 float dmin = 0.f, dmax = 0.f;
|
Chris@174
|
1977
|
Chris@174
|
1978 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@174
|
1979
|
Chris@682
|
1980 // cerr << "ydiff = " << ydiff << endl;
|
Chris@174
|
1981
|
Chris@343
|
1982 int ydiff = e->y() - m_clickPos.y();
|
Chris@174
|
1983 float perpix = (dmax - dmin) / height();
|
Chris@174
|
1984 float valdiff = ydiff * perpix;
|
Chris@682
|
1985 // cerr << "valdiff = " << valdiff << endl;
|
Chris@174
|
1986
|
Chris@343
|
1987 if (m_dragMode == UnresolvedDrag && ydiff != 0) {
|
Chris@343
|
1988 m_dragMode = VerticalDrag;
|
Chris@343
|
1989 }
|
Chris@343
|
1990
|
Chris@174
|
1991 float newmin = m_dragStartMinValue + valdiff;
|
Chris@174
|
1992 float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff;
|
Chris@174
|
1993 if (newmin < vmin) {
|
Chris@174
|
1994 newmax += vmin - newmin;
|
Chris@174
|
1995 newmin += vmin - newmin;
|
Chris@174
|
1996 }
|
Chris@174
|
1997 if (newmax > vmax) {
|
Chris@174
|
1998 newmin -= newmax - vmax;
|
Chris@174
|
1999 newmax -= newmax - vmax;
|
Chris@174
|
2000 }
|
Chris@682
|
2001 // cerr << "(" << dmin << ", " << dmax << ") -> ("
|
Chris@682
|
2002 // << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << endl;
|
Chris@174
|
2003
|
Chris@174
|
2004 setTopLayerDisplayExtents(newmin, newmax);
|
Chris@174
|
2005 updateVerticalPanner();
|
Chris@174
|
2006 }
|
Chris@174
|
2007 }
|
Chris@174
|
2008 }
|
Chris@174
|
2009
|
Chris@343
|
2010 Pane::DragMode
|
Chris@343
|
2011 Pane::updateDragMode(DragMode dragMode,
|
Chris@343
|
2012 QPoint origin,
|
Chris@343
|
2013 QPoint point,
|
Chris@343
|
2014 bool canMoveHorizontal,
|
Chris@343
|
2015 bool canMoveVertical,
|
Chris@343
|
2016 bool resistHorizontal,
|
Chris@343
|
2017 bool resistVertical)
|
Chris@343
|
2018 {
|
Chris@343
|
2019 int xdiff = point.x() - origin.x();
|
Chris@343
|
2020 int ydiff = point.y() - origin.y();
|
Chris@343
|
2021
|
Chris@343
|
2022 int smallThreshold = 10, bigThreshold = 80;
|
Chris@343
|
2023
|
Chris@587
|
2024 // SVDEBUG << "Pane::updateDragMode: xdiff = " << xdiff << ", ydiff = "
|
Chris@585
|
2025 // << ydiff << ", canMoveVertical = " << canMoveVertical << ", drag mode = " << m_dragMode << endl;
|
Chris@343
|
2026
|
Chris@343
|
2027 if (dragMode == UnresolvedDrag) {
|
Chris@343
|
2028
|
Chris@343
|
2029 if (abs(ydiff) > smallThreshold &&
|
Chris@343
|
2030 abs(ydiff) > abs(xdiff) * 2 &&
|
Chris@343
|
2031 canMoveVertical) {
|
Chris@587
|
2032 // SVDEBUG << "Pane::updateDragMode: passed vertical threshold" << endl;
|
Chris@343
|
2033 dragMode = VerticalDrag;
|
Chris@343
|
2034 } else if (abs(xdiff) > smallThreshold &&
|
Chris@343
|
2035 abs(xdiff) > abs(ydiff) * 2 &&
|
Chris@343
|
2036 canMoveHorizontal) {
|
Chris@587
|
2037 // SVDEBUG << "Pane::updateDragMode: passed horizontal threshold" << endl;
|
Chris@343
|
2038 dragMode = HorizontalDrag;
|
Chris@343
|
2039 } else if (abs(xdiff) > smallThreshold &&
|
Chris@343
|
2040 abs(ydiff) > smallThreshold &&
|
Chris@343
|
2041 canMoveVertical &&
|
Chris@343
|
2042 canMoveHorizontal) {
|
Chris@587
|
2043 // SVDEBUG << "Pane::updateDragMode: passed both thresholds" << endl;
|
Chris@343
|
2044 dragMode = FreeDrag;
|
Chris@343
|
2045 }
|
Chris@343
|
2046 }
|
Chris@343
|
2047
|
Chris@343
|
2048 if (dragMode == VerticalDrag && canMoveHorizontal) {
|
Chris@343
|
2049 if (abs(xdiff) > bigThreshold) dragMode = FreeDrag;
|
Chris@343
|
2050 }
|
Chris@343
|
2051
|
Chris@343
|
2052 if (dragMode == HorizontalDrag && canMoveVertical) {
|
Chris@343
|
2053 if (abs(ydiff) > bigThreshold) dragMode = FreeDrag;
|
Chris@343
|
2054 }
|
Chris@343
|
2055
|
Chris@343
|
2056 if (dragMode == UnresolvedDrag) {
|
Chris@343
|
2057 if (!resistHorizontal && xdiff != 0) {
|
Chris@343
|
2058 dragMode = HorizontalDrag;
|
Chris@343
|
2059 }
|
Chris@343
|
2060 if (!resistVertical && ydiff != 0) {
|
Chris@343
|
2061 if (dragMode == HorizontalDrag) dragMode = FreeDrag;
|
Chris@343
|
2062 else dragMode = VerticalDrag;
|
Chris@343
|
2063 }
|
Chris@343
|
2064 }
|
Chris@343
|
2065
|
Chris@343
|
2066 return dragMode;
|
Chris@343
|
2067 }
|
Chris@343
|
2068
|
Chris@174
|
2069 void
|
Chris@174
|
2070 Pane::dragExtendSelection(QMouseEvent *e)
|
Chris@174
|
2071 {
|
Chris@174
|
2072 int mouseFrame = getFrameForX(e->x());
|
Chris@174
|
2073 size_t resolution = 1;
|
Chris@174
|
2074 int snapFrameLeft = mouseFrame;
|
Chris@174
|
2075 int snapFrameRight = mouseFrame;
|
gyorgyf@645
|
2076
|
Chris@174
|
2077 Layer *layer = getSelectedLayer();
|
Chris@174
|
2078 if (layer && !m_shiftPressed) {
|
Chris@174
|
2079 layer->snapToFeatureFrame(this, snapFrameLeft,
|
Chris@174
|
2080 resolution, Layer::SnapLeft);
|
Chris@174
|
2081 layer->snapToFeatureFrame(this, snapFrameRight,
|
Chris@174
|
2082 resolution, Layer::SnapRight);
|
Chris@174
|
2083 }
|
Chris@174
|
2084
|
Chris@682
|
2085 // cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << endl;
|
Chris@174
|
2086
|
Chris@174
|
2087 if (snapFrameLeft < 0) snapFrameLeft = 0;
|
Chris@174
|
2088 if (snapFrameRight < 0) snapFrameRight = 0;
|
gyorgyf@645
|
2089
|
Chris@174
|
2090 size_t min, max;
|
gyorgyf@645
|
2091
|
Chris@248
|
2092 if (m_selectionStartFrame > size_t(snapFrameLeft)) {
|
Chris@174
|
2093 min = snapFrameLeft;
|
Chris@174
|
2094 max = m_selectionStartFrame;
|
Chris@248
|
2095 } else if (size_t(snapFrameRight) > m_selectionStartFrame) {
|
Chris@174
|
2096 min = m_selectionStartFrame;
|
Chris@174
|
2097 max = snapFrameRight;
|
Chris@174
|
2098 } else {
|
Chris@174
|
2099 min = snapFrameLeft;
|
Chris@174
|
2100 max = snapFrameRight;
|
Chris@174
|
2101 }
|
Chris@174
|
2102
|
Chris@174
|
2103 if (m_manager) {
|
Chris@333
|
2104 m_manager->setInProgressSelection(Selection(alignToReference(min),
|
Chris@333
|
2105 alignToReference(max)),
|
Chris@174
|
2106 !m_resizing && !m_ctrlPressed);
|
Chris@174
|
2107 }
|
Chris@174
|
2108
|
Chris@259
|
2109 edgeScrollMaybe(e->x());
|
Chris@259
|
2110
|
Chris@259
|
2111 update();
|
Chris@802
|
2112
|
Chris@802
|
2113 if (min != max) {
|
Chris@802
|
2114 m_playbackFrameMoveScheduled = false;
|
Chris@802
|
2115 }
|
Chris@259
|
2116 }
|
Chris@259
|
2117
|
Chris@259
|
2118 void
|
Chris@259
|
2119 Pane::edgeScrollMaybe(int x)
|
Chris@259
|
2120 {
|
Chris@259
|
2121 int mouseFrame = getFrameForX(x);
|
Chris@259
|
2122
|
Chris@174
|
2123 bool doScroll = false;
|
Chris@174
|
2124 if (!m_manager) doScroll = true;
|
Chris@174
|
2125 if (!m_manager->isPlaying()) doScroll = true;
|
Chris@174
|
2126 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
|
Chris@174
|
2127
|
Chris@174
|
2128 if (doScroll) {
|
Chris@174
|
2129 int offset = mouseFrame - getStartFrame();
|
Chris@174
|
2130 int available = getEndFrame() - getStartFrame();
|
Chris@259
|
2131 int move = 0;
|
Chris@174
|
2132 if (offset >= available * 0.95) {
|
Chris@259
|
2133 move = int(offset - available * 0.95) + 1;
|
Chris@259
|
2134 } else if (offset <= available * 0.10) {
|
Chris@259
|
2135 move = int(available * 0.10 - offset) + 1;
|
Chris@259
|
2136 move = -move;
|
Chris@259
|
2137 }
|
Chris@259
|
2138 if (move != 0) {
|
Chris@174
|
2139 setCentreFrame(m_centreFrame + move);
|
Chris@259
|
2140 update();
|
Chris@174
|
2141 }
|
Chris@174
|
2142 }
|
Chris@174
|
2143 }
|
Chris@174
|
2144
|
Chris@174
|
2145 void
|
Chris@127
|
2146 Pane::mouseDoubleClickEvent(QMouseEvent *e)
|
Chris@127
|
2147 {
|
Chris@127
|
2148 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
2149 return;
|
Chris@127
|
2150 }
|
Chris@127
|
2151
|
Chris@802
|
2152 cerr << "mouseDoubleClickEvent" << endl;
|
Chris@127
|
2153
|
Chris@127
|
2154 m_clickPos = e->pos();
|
Chris@127
|
2155 m_clickedInRange = true;
|
Chris@127
|
2156 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@127
|
2157 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@510
|
2158 m_altPressed = (e->modifiers() & Qt::AltModifier);
|
Chris@127
|
2159
|
Chris@802
|
2160 // cancel any pending move that came from a single click
|
Chris@802
|
2161 m_playbackFrameMoveScheduled = false;
|
Chris@802
|
2162
|
Chris@127
|
2163 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@711
|
2164 if (m_manager) mode = m_manager->getToolModeFor(this);
|
Chris@127
|
2165
|
Chris@255
|
2166 bool relocate = (mode == ViewManager::NavigateMode ||
|
Chris@255
|
2167 (e->buttons() & Qt::MidButton));
|
Chris@255
|
2168
|
Chris@716
|
2169 if (mode == ViewManager::SelectMode) {
|
Chris@716
|
2170 m_clickedInRange = false;
|
Chris@716
|
2171 m_manager->clearInProgressSelection();
|
Chris@716
|
2172 emit doubleClickSelectInvoked(getFrameForX(e->x()));
|
Chris@716
|
2173 return;
|
Chris@716
|
2174 }
|
Chris@716
|
2175
|
Chris@127
|
2176 if (mode == ViewManager::NavigateMode ||
|
Chris@127
|
2177 mode == ViewManager::EditMode) {
|
Chris@127
|
2178
|
matthiasm@660
|
2179 Layer *layer = getSelectedLayer();
|
matthiasm@660
|
2180 if (layer && layer->isLayerEditable()) {
|
matthiasm@660
|
2181 if (layer->editOpen(this, e)) relocate = false;
|
matthiasm@660
|
2182 }
|
Chris@280
|
2183
|
Chris@280
|
2184 } else if (mode == ViewManager::MeasureMode) {
|
Chris@280
|
2185
|
Chris@280
|
2186 Layer *layer = getTopLayer();
|
Chris@280
|
2187 if (layer) layer->measureDoubleClick(this, e);
|
Chris@280
|
2188 update();
|
Chris@127
|
2189 }
|
Chris@255
|
2190
|
Chris@255
|
2191 if (relocate) {
|
Chris@255
|
2192
|
Chris@255
|
2193 long f = getFrameForX(e->x());
|
Chris@255
|
2194
|
Chris@255
|
2195 setCentreFrame(f);
|
Chris@255
|
2196
|
Chris@255
|
2197 m_dragCentreFrame = f;
|
Chris@255
|
2198 m_dragStartMinValue = 0;
|
Chris@255
|
2199 m_dragMode = UnresolvedDrag;
|
Chris@255
|
2200
|
Chris@255
|
2201 float vmin, vmax, dmin, dmax;
|
Chris@255
|
2202 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@255
|
2203 m_dragStartMinValue = dmin;
|
Chris@255
|
2204 }
|
Chris@255
|
2205 }
|
matthiasm@660
|
2206
|
matthiasm@660
|
2207 if (mode == ViewManager::NoteEditMode) {
|
matthiasm@660
|
2208 std::cerr << "double click in note edit mode" << std::endl;
|
matthiasm@660
|
2209 Layer *layer = getSelectedLayer();
|
matthiasm@660
|
2210 if (layer && layer->isLayerEditable()) {
|
matthiasm@660
|
2211 layer->addNote(this, e);
|
matthiasm@660
|
2212 }
|
matthiasm@660
|
2213 }
|
Chris@551
|
2214
|
Chris@551
|
2215 m_clickedInRange = false; // in case mouseReleaseEvent is not properly called
|
Chris@127
|
2216 }
|
Chris@127
|
2217
|
Chris@127
|
2218 void
|
Chris@290
|
2219 Pane::enterEvent(QEvent *)
|
Chris@290
|
2220 {
|
Chris@290
|
2221 m_mouseInWidget = true;
|
Chris@290
|
2222 }
|
Chris@290
|
2223
|
Chris@290
|
2224 void
|
Chris@127
|
2225 Pane::leaveEvent(QEvent *)
|
Chris@127
|
2226 {
|
Chris@290
|
2227 m_mouseInWidget = false;
|
Chris@127
|
2228 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@127
|
2229 m_identifyFeatures = false;
|
Chris@127
|
2230 if (previouslyIdentifying) update();
|
Chris@189
|
2231 emit contextHelpChanged("");
|
Chris@127
|
2232 }
|
Chris@127
|
2233
|
Chris@127
|
2234 void
|
Chris@133
|
2235 Pane::resizeEvent(QResizeEvent *)
|
Chris@133
|
2236 {
|
Chris@133
|
2237 updateHeadsUpDisplay();
|
Chris@133
|
2238 }
|
Chris@133
|
2239
|
Chris@133
|
2240 void
|
Chris@127
|
2241 Pane::wheelEvent(QWheelEvent *e)
|
Chris@127
|
2242 {
|
Chris@682
|
2243 //cerr << "wheelEvent, delta " << e->delta() << endl;
|
Chris@127
|
2244
|
Chris@127
|
2245 int count = e->delta();
|
Chris@127
|
2246
|
Chris@127
|
2247 if (count > 0) {
|
gyorgyf@645
|
2248 if (count >= 120) count /= 120;
|
gyorgyf@645
|
2249 else count = 1;
|
Chris@127
|
2250 }
|
Chris@127
|
2251
|
Chris@127
|
2252 if (count < 0) {
|
gyorgyf@645
|
2253 if (count <= -120) count /= 120;
|
gyorgyf@645
|
2254 else count = -1;
|
Chris@127
|
2255 }
|
Chris@127
|
2256
|
Chris@127
|
2257 if (e->modifiers() & Qt::ControlModifier) {
|
Chris@127
|
2258
|
gyorgyf@645
|
2259 // Scroll left or right, rapidly
|
gyorgyf@645
|
2260
|
gyorgyf@645
|
2261 if (getStartFrame() < 0 &&
|
gyorgyf@645
|
2262 getEndFrame() >= getModelsEndFrame()) return;
|
gyorgyf@645
|
2263
|
gyorgyf@645
|
2264 long delta = ((width() / 2) * count * m_zoomLevel);
|
gyorgyf@645
|
2265
|
gyorgyf@645
|
2266 if (int(m_centreFrame) < delta) {
|
gyorgyf@645
|
2267 setCentreFrame(0);
|
gyorgyf@645
|
2268 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
|
gyorgyf@645
|
2269 setCentreFrame(getModelsEndFrame());
|
gyorgyf@645
|
2270 } else {
|
gyorgyf@645
|
2271 setCentreFrame(m_centreFrame - delta);
|
gyorgyf@645
|
2272 }
|
Chris@127
|
2273
|
Chris@256
|
2274 } else if (e->modifiers() & Qt::ShiftModifier) {
|
Chris@256
|
2275
|
Chris@256
|
2276 // Zoom vertically
|
Chris@256
|
2277
|
Chris@256
|
2278 if (m_vpan) {
|
Chris@256
|
2279 m_vpan->scroll(e->delta() > 0);
|
Chris@256
|
2280 }
|
Chris@256
|
2281
|
Chris@256
|
2282 } else if (e->modifiers() & Qt::AltModifier) {
|
Chris@256
|
2283
|
Chris@256
|
2284 // Zoom vertically
|
Chris@256
|
2285
|
Chris@256
|
2286 if (m_vthumb) {
|
Chris@256
|
2287 m_vthumb->scroll(e->delta() > 0);
|
Chris@256
|
2288 }
|
Chris@256
|
2289
|
Chris@127
|
2290 } else {
|
Chris@127
|
2291
|
gyorgyf@645
|
2292 // Zoom in or out
|
gyorgyf@645
|
2293
|
gyorgyf@645
|
2294 int newZoomLevel = m_zoomLevel;
|
Chris@127
|
2295
|
gyorgyf@645
|
2296 while (count > 0) {
|
gyorgyf@645
|
2297 if (newZoomLevel <= 2) {
|
gyorgyf@645
|
2298 newZoomLevel = 1;
|
gyorgyf@645
|
2299 break;
|
gyorgyf@645
|
2300 }
|
gyorgyf@645
|
2301 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
gyorgyf@645
|
2302 ZoomConstraint::RoundDown);
|
gyorgyf@645
|
2303 --count;
|
gyorgyf@645
|
2304 }
|
gyorgyf@645
|
2305
|
gyorgyf@645
|
2306 while (count < 0) {
|
gyorgyf@645
|
2307 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
gyorgyf@645
|
2308 ZoomConstraint::RoundUp);
|
gyorgyf@645
|
2309 ++count;
|
gyorgyf@645
|
2310 }
|
gyorgyf@645
|
2311
|
gyorgyf@645
|
2312 if (newZoomLevel != m_zoomLevel) {
|
gyorgyf@645
|
2313 setZoomLevel(newZoomLevel);
|
gyorgyf@645
|
2314 }
|
Chris@127
|
2315 }
|
Chris@127
|
2316
|
Chris@127
|
2317 emit paneInteractedWith();
|
Chris@127
|
2318 }
|
Chris@127
|
2319
|
Chris@132
|
2320 void
|
Chris@132
|
2321 Pane::horizontalThumbwheelMoved(int value)
|
Chris@132
|
2322 {
|
Chris@137
|
2323 //!!! dupe with updateHeadsUpDisplay
|
Chris@137
|
2324
|
Chris@132
|
2325 int count = 0;
|
Chris@132
|
2326 int level = 1;
|
Chris@137
|
2327
|
Chris@137
|
2328
|
Chris@137
|
2329 //!!! pull out into function (presumably in View)
|
Chris@137
|
2330 bool haveConstraint = false;
|
Chris@137
|
2331 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
|
Chris@137
|
2332 ++i) {
|
Chris@137
|
2333 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
|
Chris@137
|
2334 haveConstraint = true;
|
Chris@137
|
2335 break;
|
Chris@137
|
2336 }
|
Chris@132
|
2337 }
|
Chris@132
|
2338
|
Chris@137
|
2339 if (haveConstraint) {
|
Chris@137
|
2340 while (true) {
|
Chris@137
|
2341 if (m_hthumb->getMaximumValue() - value == count) break;
|
Chris@137
|
2342 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@137
|
2343 ZoomConstraint::RoundUp);
|
Chris@137
|
2344 if (newLevel == level) break;
|
Chris@137
|
2345 level = newLevel;
|
Chris@137
|
2346 if (++count == 50) break;
|
Chris@137
|
2347 }
|
Chris@137
|
2348 } else {
|
Chris@137
|
2349 while (true) {
|
Chris@137
|
2350 if (m_hthumb->getMaximumValue() - value == count) break;
|
Chris@137
|
2351 int step = level / 10;
|
Chris@137
|
2352 int pwr = 0;
|
Chris@137
|
2353 while (step > 0) {
|
Chris@137
|
2354 ++pwr;
|
Chris@137
|
2355 step /= 2;
|
Chris@137
|
2356 }
|
Chris@137
|
2357 step = 1;
|
Chris@137
|
2358 while (pwr > 0) {
|
Chris@137
|
2359 step *= 2;
|
Chris@137
|
2360 --pwr;
|
Chris@137
|
2361 }
|
Chris@682
|
2362 // cerr << level << endl;
|
Chris@137
|
2363 level += step;
|
Chris@137
|
2364 if (++count == 100 || level > 262144) break;
|
Chris@137
|
2365 }
|
Chris@137
|
2366 }
|
Chris@137
|
2367
|
Chris@682
|
2368 // cerr << "new level is " << level << endl;
|
Chris@132
|
2369 setZoomLevel(level);
|
Chris@132
|
2370 }
|
Chris@132
|
2371
|
Chris@132
|
2372 void
|
Chris@132
|
2373 Pane::verticalThumbwheelMoved(int value)
|
Chris@132
|
2374 {
|
Chris@133
|
2375 Layer *layer = 0;
|
Chris@133
|
2376 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
2377 if (layer) {
|
Chris@133
|
2378 int defaultStep = 0;
|
Chris@133
|
2379 int max = layer->getVerticalZoomSteps(defaultStep);
|
Chris@133
|
2380 if (max == 0) {
|
Chris@133
|
2381 updateHeadsUpDisplay();
|
Chris@133
|
2382 return;
|
Chris@133
|
2383 }
|
Chris@133
|
2384 if (value > max) {
|
Chris@133
|
2385 value = max;
|
Chris@133
|
2386 }
|
Chris@133
|
2387 layer->setVerticalZoomStep(value);
|
Chris@174
|
2388 updateVerticalPanner();
|
Chris@133
|
2389 }
|
Chris@132
|
2390 }
|
Chris@132
|
2391
|
Chris@174
|
2392 void
|
Chris@174
|
2393 Pane::verticalPannerMoved(float x0, float y0, float w, float h)
|
Chris@174
|
2394 {
|
Chris@174
|
2395 float vmin, vmax, dmin, dmax;
|
Chris@174
|
2396 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return;
|
Chris@174
|
2397 float y1 = y0 + h;
|
Chris@174
|
2398 float newmax = vmin + ((1.0 - y0) * (vmax - vmin));
|
Chris@174
|
2399 float newmin = vmin + ((1.0 - y1) * (vmax - vmin));
|
Chris@682
|
2400 // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w
|
Chris@682
|
2401 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl;
|
Chris@174
|
2402 setTopLayerDisplayExtents(newmin, newmax);
|
Chris@174
|
2403 }
|
Chris@174
|
2404
|
Chris@188
|
2405 void
|
Chris@188
|
2406 Pane::editVerticalPannerExtents()
|
Chris@188
|
2407 {
|
Chris@188
|
2408 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
|
Chris@188
|
2409
|
Chris@188
|
2410 float vmin, vmax, dmin, dmax;
|
Chris@188
|
2411 QString unit;
|
Chris@188
|
2412 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit)
|
Chris@188
|
2413 || vmax == vmin) {
|
Chris@188
|
2414 return;
|
Chris@188
|
2415 }
|
Chris@188
|
2416
|
Chris@188
|
2417 RangeInputDialog dialog(tr("Enter new range"),
|
Chris@188
|
2418 tr("New vertical display range, from %1 to %2 %4:")
|
Chris@188
|
2419 .arg(vmin).arg(vmax).arg(unit),
|
Chris@188
|
2420 unit, vmin, vmax, this);
|
Chris@188
|
2421 dialog.setRange(dmin, dmax);
|
Chris@188
|
2422
|
Chris@188
|
2423 if (dialog.exec() == QDialog::Accepted) {
|
Chris@188
|
2424 dialog.getRange(dmin, dmax);
|
Chris@188
|
2425 setTopLayerDisplayExtents(dmin, dmax);
|
Chris@188
|
2426 updateVerticalPanner();
|
Chris@188
|
2427 }
|
Chris@188
|
2428 }
|
Chris@188
|
2429
|
Chris@312
|
2430 void
|
Chris@437
|
2431 Pane::layerParametersChanged()
|
Chris@437
|
2432 {
|
Chris@437
|
2433 View::layerParametersChanged();
|
Chris@437
|
2434 updateHeadsUpDisplay();
|
Chris@437
|
2435 }
|
Chris@437
|
2436
|
Chris@437
|
2437 void
|
Chris@312
|
2438 Pane::dragEnterEvent(QDragEnterEvent *e)
|
Chris@312
|
2439 {
|
Chris@312
|
2440 QStringList formats(e->mimeData()->formats());
|
Chris@682
|
2441 cerr << "dragEnterEvent: format: "
|
Chris@683
|
2442 << formats.join(",")
|
Chris@312
|
2443 << ", possibleActions: " << e->possibleActions()
|
Chris@682
|
2444 << ", proposedAction: " << e->proposedAction() << endl;
|
Chris@312
|
2445
|
Chris@616
|
2446 if (e->mimeData()->hasFormat("text/uri-list") ||
|
Chris@616
|
2447 e->mimeData()->hasFormat("text/plain")) {
|
Chris@312
|
2448
|
Chris@312
|
2449 if (e->proposedAction() & Qt::CopyAction) {
|
Chris@312
|
2450 e->acceptProposedAction();
|
Chris@312
|
2451 } else {
|
Chris@312
|
2452 e->setDropAction(Qt::CopyAction);
|
Chris@312
|
2453 e->accept();
|
Chris@312
|
2454 }
|
Chris@312
|
2455 }
|
Chris@312
|
2456 }
|
Chris@312
|
2457
|
Chris@312
|
2458 void
|
Chris@312
|
2459 Pane::dropEvent(QDropEvent *e)
|
Chris@312
|
2460 {
|
Chris@683
|
2461 cerr << "dropEvent: text: \"" << e->mimeData()->text()
|
Chris@682
|
2462 << "\"" << endl;
|
Chris@312
|
2463
|
Chris@616
|
2464 if (e->mimeData()->hasFormat("text/uri-list") ||
|
Chris@616
|
2465 e->mimeData()->hasFormat("text/plain")) {
|
Chris@312
|
2466
|
Chris@312
|
2467 if (e->proposedAction() & Qt::CopyAction) {
|
Chris@312
|
2468 e->acceptProposedAction();
|
Chris@312
|
2469 } else {
|
Chris@312
|
2470 e->setDropAction(Qt::CopyAction);
|
Chris@312
|
2471 e->accept();
|
Chris@312
|
2472 }
|
Chris@312
|
2473
|
Chris@616
|
2474 if (e->mimeData()->hasFormat("text/uri-list")) {
|
Chris@616
|
2475
|
Chris@616
|
2476 SVDEBUG << "accepting... data is \"" << e->mimeData()->data("text/uri-list").data() << "\"" << endl;
|
Chris@312
|
2477 emit dropAccepted(QString::fromLocal8Bit
|
Chris@616
|
2478 (e->mimeData()->data("text/uri-list").data())
|
Chris@312
|
2479 .split(QRegExp("[\\r\\n]+"),
|
Chris@312
|
2480 QString::SkipEmptyParts));
|
Chris@312
|
2481 } else {
|
Chris@312
|
2482 emit dropAccepted(QString::fromLocal8Bit
|
Chris@616
|
2483 (e->mimeData()->data("text/plain").data()));
|
Chris@312
|
2484 }
|
Chris@312
|
2485 }
|
Chris@312
|
2486 }
|
Chris@312
|
2487
|
Chris@127
|
2488 bool
|
Chris@127
|
2489 Pane::editSelectionStart(QMouseEvent *e)
|
Chris@127
|
2490 {
|
Chris@127
|
2491 if (!m_identifyFeatures ||
|
Chris@711
|
2492 !m_manager ||
|
Chris@711
|
2493 m_manager->getToolModeFor(this) != ViewManager::EditMode) {
|
Chris@711
|
2494 return false;
|
Chris@127
|
2495 }
|
Chris@127
|
2496
|
Chris@127
|
2497 bool closeToLeft, closeToRight;
|
Chris@127
|
2498 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight));
|
Chris@127
|
2499 if (s.isEmpty()) return false;
|
Chris@127
|
2500 m_editingSelection = s;
|
Chris@127
|
2501 m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0);
|
Chris@127
|
2502 m_mousePos = e->pos();
|
Chris@127
|
2503 return true;
|
Chris@127
|
2504 }
|
Chris@127
|
2505
|
Chris@127
|
2506 bool
|
Chris@127
|
2507 Pane::editSelectionDrag(QMouseEvent *e)
|
Chris@127
|
2508 {
|
Chris@127
|
2509 if (m_editingSelection.isEmpty()) return false;
|
Chris@127
|
2510 m_mousePos = e->pos();
|
Chris@127
|
2511 update();
|
Chris@127
|
2512 return true;
|
Chris@127
|
2513 }
|
Chris@127
|
2514
|
Chris@127
|
2515 bool
|
Chris@248
|
2516 Pane::editSelectionEnd(QMouseEvent *)
|
Chris@127
|
2517 {
|
Chris@127
|
2518 if (m_editingSelection.isEmpty()) return false;
|
Chris@127
|
2519
|
Chris@127
|
2520 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@127
|
2521 Layer *layer = getSelectedLayer();
|
Chris@127
|
2522
|
Chris@127
|
2523 if (offset == 0 || !layer) {
|
Chris@716
|
2524 m_editingSelection = Selection();
|
Chris@716
|
2525 return true;
|
Chris@127
|
2526 }
|
Chris@127
|
2527
|
Chris@127
|
2528 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
|
Chris@127
|
2529 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@127
|
2530
|
Chris@127
|
2531 long f0 = getFrameForX(p0);
|
Chris@127
|
2532 long f1 = getFrameForX(p1);
|
Chris@127
|
2533
|
Chris@127
|
2534 Selection newSelection(f0, f1);
|
Chris@127
|
2535
|
Chris@127
|
2536 if (m_editingSelectionEdge == 0) {
|
gyorgyf@645
|
2537
|
Chris@127
|
2538 CommandHistory::getInstance()->startCompoundOperation
|
Chris@127
|
2539 (tr("Drag Selection"), true);
|
Chris@127
|
2540
|
Chris@716
|
2541 layer->moveSelection(m_editingSelection, f0);
|
gyorgyf@645
|
2542
|
Chris@127
|
2543 } else {
|
gyorgyf@645
|
2544
|
Chris@127
|
2545 CommandHistory::getInstance()->startCompoundOperation
|
Chris@127
|
2546 (tr("Resize Selection"), true);
|
Chris@127
|
2547
|
Chris@716
|
2548 if (m_editingSelectionEdge < 0) {
|
Chris@716
|
2549 f1 = m_editingSelection.getEndFrame();
|
Chris@716
|
2550 } else {
|
Chris@716
|
2551 f0 = m_editingSelection.getStartFrame();
|
Chris@716
|
2552 }
|
Chris@716
|
2553
|
Chris@716
|
2554 newSelection = Selection(f0, f1);
|
Chris@716
|
2555 layer->resizeSelection(m_editingSelection, newSelection);
|
Chris@127
|
2556 }
|
Chris@127
|
2557
|
Chris@127
|
2558 m_manager->removeSelection(m_editingSelection);
|
Chris@127
|
2559 m_manager->addSelection(newSelection);
|
Chris@127
|
2560
|
Chris@127
|
2561 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@127
|
2562
|
Chris@127
|
2563 m_editingSelection = Selection();
|
Chris@127
|
2564 return true;
|
Chris@127
|
2565 }
|
Chris@127
|
2566
|
Chris@127
|
2567 void
|
Chris@127
|
2568 Pane::toolModeChanged()
|
Chris@127
|
2569 {
|
Chris@711
|
2570 ViewManager::ToolMode mode = m_manager->getToolModeFor(this);
|
Chris@587
|
2571 // SVDEBUG << "Pane::toolModeChanged(" << mode << ")" << endl;
|
Chris@127
|
2572
|
Chris@267
|
2573 if (mode == ViewManager::MeasureMode && !m_measureCursor1) {
|
Chris@267
|
2574 m_measureCursor1 = new QCursor(QBitmap(":/icons/measure1cursor.xbm"),
|
Chris@267
|
2575 QBitmap(":/icons/measure1mask.xbm"),
|
Chris@267
|
2576 15, 14);
|
Chris@267
|
2577 m_measureCursor2 = new QCursor(QBitmap(":/icons/measure2cursor.xbm"),
|
Chris@267
|
2578 QBitmap(":/icons/measure2mask.xbm"),
|
Chris@267
|
2579 16, 17);
|
Chris@257
|
2580 }
|
Chris@257
|
2581
|
Chris@127
|
2582 switch (mode) {
|
Chris@127
|
2583
|
Chris@127
|
2584 case ViewManager::NavigateMode:
|
Chris@713
|
2585 setCursor(Qt::PointingHandCursor);
|
Chris@713
|
2586 break;
|
gyorgyf@645
|
2587
|
Chris@127
|
2588 case ViewManager::SelectMode:
|
Chris@713
|
2589 setCursor(Qt::ArrowCursor);
|
Chris@713
|
2590 break;
|
gyorgyf@645
|
2591
|
Chris@127
|
2592 case ViewManager::EditMode:
|
Chris@713
|
2593 setCursor(Qt::UpArrowCursor);
|
Chris@713
|
2594 break;
|
gyorgyf@645
|
2595
|
Chris@127
|
2596 case ViewManager::DrawMode:
|
Chris@713
|
2597 setCursor(Qt::CrossCursor);
|
Chris@713
|
2598 break;
|
gyorgyf@645
|
2599
|
Chris@335
|
2600 case ViewManager::EraseMode:
|
Chris@713
|
2601 setCursor(Qt::CrossCursor);
|
Chris@713
|
2602 break;
|
Chris@257
|
2603
|
Chris@257
|
2604 case ViewManager::MeasureMode:
|
Chris@267
|
2605 if (m_measureCursor1) setCursor(*m_measureCursor1);
|
Chris@713
|
2606 break;
|
Chris@713
|
2607
|
Chris@713
|
2608 // GF: NoteEditMode uses the same default cursor as EditMode, but it will change in a context sensitive manner.
|
gyorgyf@645
|
2609 case ViewManager::NoteEditMode:
|
Chris@713
|
2610 setCursor(Qt::UpArrowCursor);
|
Chris@713
|
2611 break;
|
gyorgyf@645
|
2612
|
gyorgyf@645
|
2613 /*
|
Chris@127
|
2614 case ViewManager::TextMode:
|
gyorgyf@645
|
2615 setCursor(Qt::IBeamCursor);
|
gyorgyf@645
|
2616 break;
|
Chris@127
|
2617 */
|
Chris@127
|
2618 }
|
Chris@127
|
2619 }
|
Chris@127
|
2620
|
Chris@133
|
2621 void
|
Chris@133
|
2622 Pane::zoomWheelsEnabledChanged()
|
Chris@133
|
2623 {
|
Chris@133
|
2624 updateHeadsUpDisplay();
|
Chris@133
|
2625 update();
|
Chris@133
|
2626 }
|
Chris@133
|
2627
|
Chris@133
|
2628 void
|
Chris@224
|
2629 Pane::viewZoomLevelChanged(View *v, unsigned long z, bool locked)
|
Chris@133
|
2630 {
|
Chris@682
|
2631 // cerr << "Pane[" << this << "]::zoomLevelChanged (global now "
|
Chris@682
|
2632 // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << endl;
|
Chris@192
|
2633
|
Chris@224
|
2634 View::viewZoomLevelChanged(v, z, locked);
|
Chris@224
|
2635
|
Chris@232
|
2636 if (m_hthumb && !m_hthumb->isVisible()) return;
|
Chris@224
|
2637
|
Chris@222
|
2638 if (v != this) {
|
Chris@222
|
2639 if (!locked || !m_followZoom) return;
|
Chris@222
|
2640 }
|
Chris@222
|
2641
|
Chris@133
|
2642 if (m_manager && m_manager->getZoomWheelsEnabled()) {
|
Chris@133
|
2643 updateHeadsUpDisplay();
|
Chris@133
|
2644 }
|
Chris@133
|
2645 }
|
Chris@133
|
2646
|
Chris@133
|
2647 void
|
Chris@133
|
2648 Pane::propertyContainerSelected(View *v, PropertyContainer *pc)
|
Chris@133
|
2649 {
|
Chris@133
|
2650 Layer *layer = 0;
|
Chris@133
|
2651
|
Chris@133
|
2652 if (getLayerCount() > 0) {
|
Chris@133
|
2653 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
2654 disconnect(layer, SIGNAL(verticalZoomChanged()),
|
Chris@133
|
2655 this, SLOT(verticalZoomChanged()));
|
Chris@133
|
2656 }
|
Chris@133
|
2657
|
Chris@133
|
2658 View::propertyContainerSelected(v, pc);
|
Chris@133
|
2659 updateHeadsUpDisplay();
|
Chris@133
|
2660
|
Chris@187
|
2661 if (m_vthumb) {
|
Chris@187
|
2662 RangeMapper *rm = 0;
|
Chris@187
|
2663 if (layer) rm = layer->getNewVerticalZoomRangeMapper();
|
Chris@187
|
2664 if (rm) m_vthumb->setRangeMapper(rm);
|
Chris@187
|
2665 }
|
Chris@187
|
2666
|
Chris@133
|
2667 if (getLayerCount() > 0) {
|
Chris@133
|
2668 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
2669 connect(layer, SIGNAL(verticalZoomChanged()),
|
Chris@133
|
2670 this, SLOT(verticalZoomChanged()));
|
Chris@133
|
2671 }
|
Chris@133
|
2672 }
|
Chris@133
|
2673
|
Chris@133
|
2674 void
|
Chris@133
|
2675 Pane::verticalZoomChanged()
|
Chris@133
|
2676 {
|
Chris@133
|
2677 Layer *layer = 0;
|
Chris@133
|
2678
|
Chris@133
|
2679 if (getLayerCount() > 0) {
|
Chris@133
|
2680
|
Chris@133
|
2681 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
2682
|
Chris@133
|
2683 if (m_vthumb && m_vthumb->isVisible()) {
|
Chris@133
|
2684 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
|
Chris@133
|
2685 }
|
Chris@133
|
2686 }
|
Chris@133
|
2687 }
|
Chris@133
|
2688
|
Chris@189
|
2689 void
|
Chris@189
|
2690 Pane::updateContextHelp(const QPoint *pos)
|
Chris@189
|
2691 {
|
Chris@189
|
2692 QString help = "";
|
Chris@189
|
2693
|
Chris@189
|
2694 if (m_clickedInRange) {
|
Chris@189
|
2695 emit contextHelpChanged("");
|
Chris@189
|
2696 return;
|
Chris@189
|
2697 }
|
Chris@189
|
2698
|
Chris@189
|
2699 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@711
|
2700 if (m_manager) mode = m_manager->getToolModeFor(this);
|
Chris@189
|
2701
|
Chris@189
|
2702 bool editable = false;
|
Chris@189
|
2703 Layer *layer = getSelectedLayer();
|
Chris@189
|
2704 if (layer && layer->isLayerEditable()) {
|
Chris@189
|
2705 editable = true;
|
Chris@189
|
2706 }
|
Chris@189
|
2707
|
Chris@189
|
2708 if (mode == ViewManager::NavigateMode) {
|
Chris@189
|
2709
|
Chris@189
|
2710 help = tr("Click and drag to navigate");
|
Chris@189
|
2711
|
Chris@189
|
2712 } else if (mode == ViewManager::SelectMode) {
|
Chris@189
|
2713
|
Chris@217
|
2714 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
2715
|
Chris@189
|
2716 bool haveSelection = (m_manager && !m_manager->getSelections().empty());
|
Chris@189
|
2717
|
Chris@189
|
2718 if (haveSelection) {
|
Chris@597
|
2719 #ifdef Q_OS_MAC
|
Chris@597
|
2720 if (editable) {
|
Chris@597
|
2721 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; hold Cmd for multi-select; middle-click and drag to navigate");
|
Chris@597
|
2722 } else {
|
Chris@597
|
2723 help = tr("Click and drag to select a range; hold Cmd for multi-select; middle-click and drag to navigate");
|
Chris@597
|
2724 }
|
Chris@597
|
2725 #else
|
Chris@189
|
2726 if (editable) {
|
Chris@189
|
2727 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; hold Ctrl for multi-select; middle-click and drag to navigate");
|
Chris@189
|
2728 } else {
|
Chris@189
|
2729 help = tr("Click and drag to select a range; hold Ctrl for multi-select; middle-click and drag to navigate");
|
Chris@189
|
2730 }
|
Chris@597
|
2731 #endif
|
Chris@189
|
2732
|
Chris@189
|
2733 if (pos) {
|
Chris@189
|
2734 bool closeToLeft = false, closeToRight = false;
|
Chris@189
|
2735 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
|
Chris@189
|
2736 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@189
|
2737
|
Chris@189
|
2738 help = tr("Click and drag to move the selection boundary");
|
Chris@189
|
2739 }
|
Chris@189
|
2740 }
|
Chris@189
|
2741 } else {
|
Chris@189
|
2742 if (editable) {
|
Chris@189
|
2743 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; middle-click to navigate");
|
Chris@189
|
2744 } else {
|
Chris@189
|
2745 help = tr("Click and drag to select a range; middle-click and drag to navigate");
|
Chris@189
|
2746 }
|
Chris@189
|
2747 }
|
Chris@189
|
2748
|
Chris@189
|
2749 } else if (mode == ViewManager::DrawMode) {
|
Chris@189
|
2750
|
Chris@189
|
2751 //!!! could call through to a layer function to find out exact meaning
|
Chris@713
|
2752 if (editable) {
|
Chris@189
|
2753 help = tr("Click to add a new item in the active layer");
|
Chris@189
|
2754 }
|
Chris@335
|
2755
|
Chris@335
|
2756 } else if (mode == ViewManager::EraseMode) {
|
Chris@335
|
2757
|
Chris@335
|
2758 //!!! could call through to a layer function to find out exact meaning
|
Chris@713
|
2759 if (editable) {
|
Chris@335
|
2760 help = tr("Click to erase an item from the active layer");
|
Chris@335
|
2761 }
|
Chris@189
|
2762
|
Chris@189
|
2763 } else if (mode == ViewManager::EditMode) {
|
Chris@189
|
2764
|
Chris@189
|
2765 //!!! could call through to layer
|
Chris@713
|
2766 if (editable) {
|
Chris@551
|
2767 help = tr("Click and drag an item in the active layer to move it; hold Shift to override initial resistance");
|
Chris@189
|
2768 if (pos) {
|
Chris@189
|
2769 bool closeToLeft = false, closeToRight = false;
|
Chris@189
|
2770 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
|
Chris@189
|
2771 if (!selection.isEmpty()) {
|
Chris@189
|
2772 help = tr("Click and drag to move all items in the selected range");
|
Chris@189
|
2773 }
|
Chris@189
|
2774 }
|
Chris@189
|
2775 }
|
Chris@189
|
2776 }
|
Chris@189
|
2777
|
Chris@189
|
2778 emit contextHelpChanged(help);
|
Chris@189
|
2779 }
|
Chris@189
|
2780
|
Chris@189
|
2781 void
|
Chris@189
|
2782 Pane::mouseEnteredWidget()
|
Chris@189
|
2783 {
|
Chris@189
|
2784 QWidget *w = dynamic_cast<QWidget *>(sender());
|
Chris@189
|
2785 if (!w) return;
|
Chris@189
|
2786
|
Chris@189
|
2787 if (w == m_vpan) {
|
Chris@189
|
2788 emit contextHelpChanged(tr("Click and drag to adjust the visible range of the vertical scale"));
|
Chris@189
|
2789 } else if (w == m_vthumb) {
|
Chris@189
|
2790 emit contextHelpChanged(tr("Click and drag to adjust the vertical zoom level"));
|
Chris@189
|
2791 } else if (w == m_hthumb) {
|
Chris@189
|
2792 emit contextHelpChanged(tr("Click and drag to adjust the horizontal zoom level"));
|
Chris@189
|
2793 } else if (w == m_reset) {
|
Chris@189
|
2794 emit contextHelpChanged(tr("Reset horizontal and vertical zoom levels to their defaults"));
|
Chris@189
|
2795 }
|
Chris@189
|
2796 }
|
Chris@189
|
2797
|
Chris@189
|
2798 void
|
Chris@189
|
2799 Pane::mouseLeftWidget()
|
Chris@189
|
2800 {
|
Chris@189
|
2801 emit contextHelpChanged("");
|
Chris@189
|
2802 }
|
Chris@189
|
2803
|
Chris@316
|
2804 void
|
Chris@316
|
2805 Pane::toXml(QTextStream &stream,
|
Chris@316
|
2806 QString indent, QString extraAttributes) const
|
Chris@127
|
2807 {
|
Chris@316
|
2808 View::toXml
|
Chris@316
|
2809 (stream, indent,
|
gyorgyf@645
|
2810 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3")
|
gyorgyf@645
|
2811 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes));
|
Chris@127
|
2812 }
|
Chris@127
|
2813
|
Chris@127
|
2814
|