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