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