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