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@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@128
|
16 #include "Pane.h"
|
Chris@128
|
17 #include "layer/Layer.h"
|
Chris@128
|
18 #include "data/model/Model.h"
|
Chris@127
|
19 #include "base/ZoomConstraint.h"
|
Chris@127
|
20 #include "base/RealTime.h"
|
Chris@127
|
21 #include "base/Profiler.h"
|
Chris@128
|
22 #include "ViewManager.h"
|
Chris@127
|
23 #include "base/CommandHistory.h"
|
Chris@127
|
24 #include "layer/WaveformLayer.h"
|
Chris@127
|
25
|
Chris@127
|
26 #include <QPaintEvent>
|
Chris@127
|
27 #include <QPainter>
|
Chris@257
|
28 #include <QBitmap>
|
Chris@257
|
29 #include <QCursor>
|
Chris@127
|
30 #include <iostream>
|
Chris@127
|
31 #include <cmath>
|
Chris@127
|
32
|
Chris@133
|
33 //!!! for HUD -- pull out into a separate class
|
Chris@133
|
34 #include <QFrame>
|
Chris@133
|
35 #include <QGridLayout>
|
Chris@133
|
36 #include <QPushButton>
|
Chris@133
|
37 #include "widgets/Thumbwheel.h"
|
Chris@172
|
38 #include "widgets/Panner.h"
|
Chris@188
|
39 #include "widgets/RangeInputDialog.h"
|
Chris@189
|
40 #include "widgets/NotifyingPushButton.h"
|
Chris@133
|
41
|
Chris@127
|
42 using std::cerr;
|
Chris@127
|
43 using std::endl;
|
Chris@127
|
44
|
Chris@127
|
45 Pane::Pane(QWidget *w) :
|
Chris@127
|
46 View(w, true),
|
Chris@127
|
47 m_identifyFeatures(false),
|
Chris@127
|
48 m_clickedInRange(false),
|
Chris@127
|
49 m_shiftPressed(false),
|
Chris@127
|
50 m_ctrlPressed(false),
|
Chris@127
|
51 m_navigating(false),
|
Chris@127
|
52 m_resizing(false),
|
Chris@133
|
53 m_centreLineVisible(true),
|
Chris@222
|
54 m_scaleWidth(0),
|
Chris@237
|
55 m_headsUpDisplay(0),
|
Chris@237
|
56 m_vpan(0),
|
Chris@237
|
57 m_hthumb(0),
|
Chris@237
|
58 m_vthumb(0),
|
Chris@237
|
59 m_reset(0)
|
Chris@127
|
60 {
|
Chris@127
|
61 setObjectName("Pane");
|
Chris@127
|
62 setMouseTracking(true);
|
Chris@133
|
63
|
Chris@133
|
64 updateHeadsUpDisplay();
|
Chris@133
|
65 }
|
Chris@133
|
66
|
Chris@133
|
67 void
|
Chris@133
|
68 Pane::updateHeadsUpDisplay()
|
Chris@133
|
69 {
|
Chris@187
|
70 Profiler profiler("Pane::updateHeadsUpDisplay", true);
|
Chris@187
|
71
|
Chris@192
|
72 if (!isVisible()) return;
|
Chris@192
|
73
|
Chris@132
|
74 /*
|
Chris@132
|
75 int count = 0;
|
Chris@132
|
76 int currentLevel = 1;
|
Chris@132
|
77 int level = 1;
|
Chris@132
|
78 while (true) {
|
Chris@132
|
79 if (getZoomLevel() == level) currentLevel = count;
|
Chris@132
|
80 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@132
|
81 ZoomConstraint::RoundUp);
|
Chris@132
|
82 if (newLevel == level) break;
|
Chris@132
|
83 if (newLevel == 131072) break; //!!! just because
|
Chris@132
|
84 level = newLevel;
|
Chris@132
|
85 ++count;
|
Chris@132
|
86 }
|
Chris@132
|
87
|
Chris@132
|
88 std::cerr << "Have " << count+1 << " zoom levels" << std::endl;
|
Chris@132
|
89 */
|
Chris@133
|
90
|
Chris@188
|
91 Layer *layer = 0;
|
Chris@188
|
92 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@188
|
93
|
Chris@133
|
94 if (!m_headsUpDisplay) {
|
Chris@133
|
95
|
Chris@133
|
96 m_headsUpDisplay = new QFrame(this);
|
Chris@133
|
97
|
Chris@133
|
98 QGridLayout *layout = new QGridLayout;
|
Chris@133
|
99 layout->setMargin(0);
|
Chris@133
|
100 layout->setSpacing(0);
|
Chris@133
|
101 m_headsUpDisplay->setLayout(layout);
|
Chris@133
|
102
|
Chris@133
|
103 m_hthumb = new Thumbwheel(Qt::Horizontal);
|
Chris@187
|
104 m_hthumb->setObjectName(tr("Horizontal Zoom"));
|
Chris@173
|
105 layout->addWidget(m_hthumb, 1, 0, 1, 2);
|
Chris@133
|
106 m_hthumb->setFixedWidth(70);
|
Chris@133
|
107 m_hthumb->setFixedHeight(16);
|
Chris@133
|
108 m_hthumb->setDefaultValue(0);
|
Chris@165
|
109 m_hthumb->setSpeed(0.6);
|
Chris@133
|
110 connect(m_hthumb, SIGNAL(valueChanged(int)), this,
|
Chris@133
|
111 SLOT(horizontalThumbwheelMoved(int)));
|
Chris@189
|
112 connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
113 connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@172
|
114
|
Chris@172
|
115 m_vpan = new Panner;
|
Chris@172
|
116 layout->addWidget(m_vpan, 0, 1);
|
Chris@173
|
117 m_vpan->setFixedWidth(12);
|
Chris@172
|
118 m_vpan->setFixedHeight(70);
|
Chris@174
|
119 m_vpan->setAlpha(80, 130);
|
Chris@174
|
120 connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)),
|
Chris@174
|
121 this, SLOT(verticalPannerMoved(float, float, float, float)));
|
Chris@188
|
122 connect(m_vpan, SIGNAL(doubleClicked()),
|
Chris@188
|
123 this, SLOT(editVerticalPannerExtents()));
|
Chris@189
|
124 connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
125 connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@172
|
126
|
Chris@133
|
127 m_vthumb = new Thumbwheel(Qt::Vertical);
|
Chris@187
|
128 m_vthumb->setObjectName(tr("Vertical Zoom"));
|
Chris@172
|
129 layout->addWidget(m_vthumb, 0, 2);
|
Chris@133
|
130 m_vthumb->setFixedWidth(16);
|
Chris@133
|
131 m_vthumb->setFixedHeight(70);
|
Chris@133
|
132 connect(m_vthumb, SIGNAL(valueChanged(int)), this,
|
Chris@133
|
133 SLOT(verticalThumbwheelMoved(int)));
|
Chris@189
|
134 connect(m_vthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
135 connect(m_vthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@133
|
136
|
Chris@188
|
137 if (layer) {
|
Chris@188
|
138 RangeMapper *rm = layer->getNewVerticalZoomRangeMapper();
|
Chris@188
|
139 if (rm) m_vthumb->setRangeMapper(rm);
|
Chris@188
|
140 }
|
Chris@188
|
141
|
Chris@189
|
142 m_reset = new NotifyingPushButton;
|
Chris@189
|
143 m_reset->setFixedHeight(16);
|
Chris@189
|
144 m_reset->setFixedWidth(16);
|
Chris@189
|
145 layout->addWidget(m_reset, 1, 2);
|
Chris@189
|
146 connect(m_reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault()));
|
Chris@189
|
147 connect(m_reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault()));
|
Chris@189
|
148 connect(m_reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault()));
|
Chris@189
|
149 connect(m_reset, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@189
|
150 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@133
|
151 }
|
Chris@133
|
152
|
Chris@133
|
153 int count = 0;
|
Chris@133
|
154 int current = 0;
|
Chris@133
|
155 int level = 1;
|
Chris@133
|
156
|
Chris@137
|
157 //!!! pull out into function (presumably in View)
|
Chris@137
|
158 bool haveConstraint = false;
|
Chris@137
|
159 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
|
Chris@137
|
160 ++i) {
|
Chris@137
|
161 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
|
Chris@137
|
162 haveConstraint = true;
|
Chris@137
|
163 break;
|
Chris@137
|
164 }
|
Chris@137
|
165 }
|
Chris@137
|
166
|
Chris@137
|
167 if (haveConstraint) {
|
Chris@137
|
168 while (true) {
|
Chris@137
|
169 if (getZoomLevel() == level) current = count;
|
Chris@137
|
170 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@137
|
171 ZoomConstraint::RoundUp);
|
Chris@137
|
172 if (newLevel == level) break;
|
Chris@137
|
173 level = newLevel;
|
Chris@137
|
174 if (++count == 50) break;
|
Chris@137
|
175 }
|
Chris@137
|
176 } else {
|
Chris@137
|
177 // if we have no particular constraints, we can really spread out
|
Chris@137
|
178 while (true) {
|
Chris@137
|
179 if (getZoomLevel() >= level) current = count;
|
Chris@137
|
180 int step = level / 10;
|
Chris@137
|
181 int pwr = 0;
|
Chris@137
|
182 while (step > 0) {
|
Chris@137
|
183 ++pwr;
|
Chris@137
|
184 step /= 2;
|
Chris@137
|
185 }
|
Chris@137
|
186 step = 1;
|
Chris@137
|
187 while (pwr > 0) {
|
Chris@137
|
188 step *= 2;
|
Chris@137
|
189 --pwr;
|
Chris@137
|
190 }
|
Chris@154
|
191 // std::cerr << level << std::endl;
|
Chris@137
|
192 level += step;
|
Chris@137
|
193 if (++count == 100 || level > 262144) break;
|
Chris@137
|
194 }
|
Chris@133
|
195 }
|
Chris@133
|
196
|
Chris@133
|
197 // std::cerr << "Have " << count << " zoom levels" << std::endl;
|
Chris@133
|
198
|
Chris@133
|
199 m_hthumb->setMinimumValue(0);
|
Chris@133
|
200 m_hthumb->setMaximumValue(count);
|
Chris@133
|
201 m_hthumb->setValue(count - current);
|
Chris@133
|
202
|
Chris@133
|
203 // std::cerr << "set value to " << count-current << std::endl;
|
Chris@133
|
204
|
Chris@133
|
205 // std::cerr << "default value is " << m_hthumb->getDefaultValue() << std::endl;
|
Chris@133
|
206
|
Chris@133
|
207 if (count != 50 && m_hthumb->getDefaultValue() == 0) {
|
Chris@133
|
208 m_hthumb->setDefaultValue(count - current);
|
Chris@133
|
209 // std::cerr << "set default value to " << m_hthumb->getDefaultValue() << std::endl;
|
Chris@133
|
210 }
|
Chris@133
|
211
|
Chris@204
|
212 bool haveVThumb = false;
|
Chris@204
|
213
|
Chris@133
|
214 if (layer) {
|
Chris@133
|
215 int defaultStep = 0;
|
Chris@133
|
216 int max = layer->getVerticalZoomSteps(defaultStep);
|
Chris@133
|
217 if (max == 0) {
|
Chris@133
|
218 m_vthumb->hide();
|
Chris@133
|
219 } else {
|
Chris@204
|
220 haveVThumb = true;
|
Chris@133
|
221 m_vthumb->show();
|
Chris@187
|
222 m_vthumb->blockSignals(true);
|
Chris@133
|
223 m_vthumb->setMinimumValue(0);
|
Chris@133
|
224 m_vthumb->setMaximumValue(max);
|
Chris@133
|
225 m_vthumb->setDefaultValue(defaultStep);
|
Chris@133
|
226 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
|
Chris@187
|
227 m_vthumb->blockSignals(false);
|
Chris@135
|
228
|
Chris@205
|
229 // std::cerr << "Vertical thumbwheel: min 0, max " << max
|
Chris@205
|
230 // << ", default " << defaultStep << ", value "
|
Chris@205
|
231 // << m_vthumb->getValue() << std::endl;
|
Chris@135
|
232
|
Chris@133
|
233 }
|
Chris@133
|
234 }
|
Chris@133
|
235
|
Chris@174
|
236 updateVerticalPanner();
|
Chris@174
|
237
|
Chris@133
|
238 if (m_manager && m_manager->getZoomWheelsEnabled() &&
|
Chris@133
|
239 width() > 120 && height() > 100) {
|
Chris@165
|
240 if (!m_headsUpDisplay->isVisible()) {
|
Chris@165
|
241 m_headsUpDisplay->show();
|
Chris@165
|
242 }
|
Chris@204
|
243 if (haveVThumb) {
|
Chris@204
|
244 m_headsUpDisplay->setFixedHeight(m_vthumb->height() + m_hthumb->height());
|
Chris@133
|
245 m_headsUpDisplay->move(width() - 86, height() - 86);
|
Chris@133
|
246 } else {
|
Chris@204
|
247 m_headsUpDisplay->setFixedHeight(m_hthumb->height());
|
Chris@204
|
248 m_headsUpDisplay->move(width() - 86, height() - 16);
|
Chris@133
|
249 }
|
Chris@133
|
250 } else {
|
Chris@133
|
251 m_headsUpDisplay->hide();
|
Chris@133
|
252 }
|
Chris@127
|
253 }
|
Chris@127
|
254
|
Chris@174
|
255 void
|
Chris@174
|
256 Pane::updateVerticalPanner()
|
Chris@174
|
257 {
|
Chris@174
|
258 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
|
Chris@174
|
259
|
Chris@208
|
260 // In principle we should show or hide the panner on the basis of
|
Chris@208
|
261 // whether the top layer has adjustable display extents, and we do
|
Chris@208
|
262 // that below. However, we have no basis for layout of the panner
|
Chris@208
|
263 // if the vertical scroll wheel is not also present. So if we
|
Chris@208
|
264 // have no vertical scroll wheel, we should remove the panner as
|
Chris@208
|
265 // well. Ideally any layer that implements display extents should
|
Chris@208
|
266 // implement vertical zoom steps as well, but they don't all at
|
Chris@208
|
267 // the moment.
|
Chris@208
|
268
|
Chris@208
|
269 Layer *layer = 0;
|
Chris@208
|
270 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@208
|
271 int discard;
|
Chris@208
|
272 if (layer && layer->getVerticalZoomSteps(discard) == 0) {
|
Chris@208
|
273 m_vpan->hide();
|
Chris@208
|
274 return;
|
Chris@208
|
275 }
|
Chris@208
|
276
|
Chris@174
|
277 float vmin, vmax, dmin, dmax;
|
Chris@174
|
278 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) {
|
Chris@174
|
279 float y0 = (dmin - vmin) / (vmax - vmin);
|
Chris@174
|
280 float y1 = (dmax - vmin) / (vmax - vmin);
|
Chris@174
|
281 m_vpan->blockSignals(true);
|
Chris@174
|
282 m_vpan->setRectExtents(0, 1.0 - y1, 1, y1 - y0);
|
Chris@174
|
283 m_vpan->blockSignals(false);
|
Chris@174
|
284 m_vpan->show();
|
Chris@174
|
285 } else {
|
Chris@174
|
286 m_vpan->hide();
|
Chris@174
|
287 }
|
Chris@174
|
288 }
|
Chris@174
|
289
|
Chris@127
|
290 bool
|
Chris@127
|
291 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
|
Chris@127
|
292 {
|
Chris@127
|
293 QPoint discard;
|
Chris@127
|
294 bool b0, b1;
|
Chris@127
|
295
|
Chris@127
|
296 if (layer == getSelectedLayer() &&
|
Chris@127
|
297 !shouldIlluminateLocalSelection(discard, b0, b1)) {
|
Chris@127
|
298
|
Chris@127
|
299 pos = m_identifyPoint;
|
Chris@127
|
300 return m_identifyFeatures;
|
Chris@127
|
301 }
|
Chris@127
|
302
|
Chris@127
|
303 return false;
|
Chris@127
|
304 }
|
Chris@127
|
305
|
Chris@127
|
306 bool
|
Chris@127
|
307 Pane::shouldIlluminateLocalSelection(QPoint &pos,
|
Chris@127
|
308 bool &closeToLeft,
|
Chris@127
|
309 bool &closeToRight) const
|
Chris@127
|
310 {
|
Chris@127
|
311 if (m_identifyFeatures &&
|
Chris@127
|
312 m_manager &&
|
Chris@127
|
313 m_manager->getToolMode() == ViewManager::EditMode &&
|
Chris@127
|
314 !m_manager->getSelections().empty() &&
|
Chris@127
|
315 !selectionIsBeingEdited()) {
|
Chris@127
|
316
|
Chris@127
|
317 Selection s(getSelectionAt(m_identifyPoint.x(),
|
Chris@127
|
318 closeToLeft, closeToRight));
|
Chris@127
|
319
|
Chris@127
|
320 if (!s.isEmpty()) {
|
Chris@127
|
321 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
|
Chris@127
|
322
|
Chris@127
|
323 pos = m_identifyPoint;
|
Chris@127
|
324 return true;
|
Chris@127
|
325 }
|
Chris@127
|
326 }
|
Chris@127
|
327 }
|
Chris@127
|
328
|
Chris@127
|
329 return false;
|
Chris@127
|
330 }
|
Chris@127
|
331
|
Chris@127
|
332 bool
|
Chris@127
|
333 Pane::selectionIsBeingEdited() const
|
Chris@127
|
334 {
|
Chris@127
|
335 if (!m_editingSelection.isEmpty()) {
|
Chris@127
|
336 if (m_mousePos != m_clickPos &&
|
Chris@127
|
337 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) {
|
Chris@127
|
338 return true;
|
Chris@127
|
339 }
|
Chris@127
|
340 }
|
Chris@127
|
341 return false;
|
Chris@127
|
342 }
|
Chris@127
|
343
|
Chris@127
|
344 void
|
Chris@127
|
345 Pane::setCentreLineVisible(bool visible)
|
Chris@127
|
346 {
|
Chris@127
|
347 m_centreLineVisible = visible;
|
Chris@127
|
348 update();
|
Chris@127
|
349 }
|
Chris@127
|
350
|
Chris@127
|
351 void
|
Chris@127
|
352 Pane::paintEvent(QPaintEvent *e)
|
Chris@127
|
353 {
|
Chris@127
|
354 // Profiler profiler("Pane::paintEvent", true);
|
Chris@127
|
355
|
Chris@127
|
356 QPainter paint;
|
Chris@127
|
357
|
Chris@127
|
358 QRect r(rect());
|
Chris@127
|
359
|
Chris@127
|
360 if (e) {
|
Chris@127
|
361 r = e->rect();
|
Chris@127
|
362 }
|
Chris@127
|
363 /*
|
Chris@127
|
364 paint.begin(this);
|
Chris@127
|
365 paint.setClipRect(r);
|
Chris@127
|
366
|
Chris@127
|
367 if (hasLightBackground()) {
|
Chris@127
|
368 paint.setPen(Qt::white);
|
Chris@127
|
369 paint.setBrush(Qt::white);
|
Chris@127
|
370 } else {
|
Chris@127
|
371 paint.setPen(Qt::black);
|
Chris@127
|
372 paint.setBrush(Qt::black);
|
Chris@127
|
373 }
|
Chris@127
|
374 paint.drawRect(r);
|
Chris@127
|
375
|
Chris@127
|
376 paint.end();
|
Chris@127
|
377 */
|
Chris@127
|
378 View::paintEvent(e);
|
Chris@127
|
379
|
Chris@127
|
380 paint.begin(this);
|
Chris@127
|
381
|
Chris@127
|
382 if (e) {
|
Chris@127
|
383 paint.setClipRect(r);
|
Chris@127
|
384 }
|
Chris@127
|
385
|
Chris@127
|
386 int fontHeight = paint.fontMetrics().height();
|
Chris@127
|
387 int fontAscent = paint.fontMetrics().ascent();
|
Chris@127
|
388
|
Chris@127
|
389 if (m_manager &&
|
Chris@127
|
390 !m_manager->isPlaying() &&
|
Chris@127
|
391 m_manager->getToolMode() == ViewManager::SelectMode) {
|
Chris@127
|
392
|
Chris@127
|
393 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@127
|
394 --vi;
|
Chris@127
|
395
|
Chris@127
|
396 std::vector<QRect> crosshairExtents;
|
Chris@127
|
397
|
Chris@127
|
398 if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint,
|
Chris@127
|
399 crosshairExtents)) {
|
Chris@127
|
400 (*vi)->paintCrosshairs(this, paint, m_identifyPoint);
|
Chris@127
|
401 break;
|
Chris@127
|
402 } else if ((*vi)->isLayerOpaque()) {
|
Chris@127
|
403 break;
|
Chris@127
|
404 }
|
Chris@127
|
405 }
|
Chris@127
|
406 }
|
Chris@127
|
407
|
Chris@258
|
408 Layer *topLayer = 0;
|
Chris@258
|
409 const Model *waveformModel = 0; // just for reporting purposes
|
Chris@127
|
410 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@127
|
411 --vi;
|
Chris@258
|
412 if (!topLayer) topLayer = *vi;
|
Chris@127
|
413 if (dynamic_cast<WaveformLayer *>(*vi)) {
|
Chris@127
|
414 waveformModel = (*vi)->getModel();
|
Chris@258
|
415 break;
|
Chris@127
|
416 }
|
Chris@258
|
417 }
|
Chris@127
|
418
|
Chris@258
|
419 Layer *scaleLayer = 0;
|
Chris@258
|
420
|
Chris@258
|
421 if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) {
|
Chris@258
|
422
|
Chris@258
|
423 float min, max;
|
Chris@258
|
424 bool log;
|
Chris@258
|
425 QString unit;
|
Chris@258
|
426
|
Chris@258
|
427 // If the top layer has no scale and reports no display
|
Chris@258
|
428 // extents, but does report a unit, then the scale should be
|
Chris@258
|
429 // drawn from any underlying layer with a scale and that unit.
|
Chris@258
|
430 // If the top layer has no scale and no value extents at all,
|
Chris@258
|
431 // then the scale should be drawn from any underlying layer
|
Chris@258
|
432 // with a scale regardless of unit.
|
Chris@258
|
433
|
Chris@258
|
434 int sw = topLayer->getVerticalScaleWidth(this, paint);
|
Chris@258
|
435
|
Chris@258
|
436 if (sw > 0) {
|
Chris@258
|
437 scaleLayer = topLayer;
|
Chris@258
|
438 m_scaleWidth = sw;
|
Chris@258
|
439
|
Chris@227
|
440 } else {
|
Chris@258
|
441
|
Chris@258
|
442 bool hasDisplayExtents = topLayer->getDisplayExtents(min, max);
|
Chris@258
|
443 bool hasValueExtents = topLayer->getValueExtents(min, max, log, unit);
|
Chris@258
|
444
|
Chris@258
|
445 if (!hasDisplayExtents) {
|
Chris@258
|
446
|
Chris@258
|
447 if (!hasValueExtents) {
|
Chris@258
|
448
|
Chris@258
|
449 for (LayerList::iterator vi = m_layers.end();
|
Chris@258
|
450 vi != m_layers.begin(); ) {
|
Chris@258
|
451
|
Chris@258
|
452 --vi;
|
Chris@258
|
453
|
Chris@258
|
454 if ((*vi) == topLayer) continue;
|
Chris@258
|
455
|
Chris@258
|
456 sw = (*vi)->getVerticalScaleWidth(this, paint);
|
Chris@258
|
457
|
Chris@258
|
458 if (sw > 0) {
|
Chris@258
|
459 scaleLayer = *vi;
|
Chris@258
|
460 m_scaleWidth = sw;
|
Chris@258
|
461 break;
|
Chris@258
|
462 }
|
Chris@258
|
463 }
|
Chris@258
|
464 } else if (unit != "") { // && hasValueExtents && !hasDisplayExtents
|
Chris@258
|
465
|
Chris@258
|
466 QString requireUnit = unit;
|
Chris@258
|
467
|
Chris@258
|
468 for (LayerList::iterator vi = m_layers.end();
|
Chris@258
|
469 vi != m_layers.begin(); ) {
|
Chris@258
|
470
|
Chris@258
|
471 --vi;
|
Chris@258
|
472
|
Chris@258
|
473 if ((*vi) == topLayer) continue;
|
Chris@258
|
474
|
Chris@258
|
475 if ((*vi)->getDisplayExtents(min, max)) {
|
Chris@258
|
476
|
Chris@258
|
477 // search no further than this: if the
|
Chris@258
|
478 // scale from this layer isn't suitable,
|
Chris@258
|
479 // we'll have to draw no scale (else we'd
|
Chris@258
|
480 // risk ending up with the wrong scale)
|
Chris@258
|
481
|
Chris@258
|
482 if ((*vi)->getValueExtents(min, max, log, unit) &&
|
Chris@258
|
483 unit == requireUnit) {
|
Chris@258
|
484
|
Chris@258
|
485 sw = (*vi)->getVerticalScaleWidth(this, paint);
|
Chris@258
|
486 if (sw > 0) {
|
Chris@258
|
487 scaleLayer = *vi;
|
Chris@258
|
488 m_scaleWidth = sw;
|
Chris@258
|
489 }
|
Chris@258
|
490 }
|
Chris@258
|
491 break;
|
Chris@258
|
492 }
|
Chris@258
|
493 }
|
Chris@258
|
494 }
|
Chris@258
|
495 }
|
Chris@127
|
496 }
|
Chris@258
|
497 }
|
Chris@127
|
498
|
Chris@258
|
499 if (!scaleLayer) m_scaleWidth = 0;
|
Chris@258
|
500
|
Chris@258
|
501 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) {
|
Chris@127
|
502
|
Chris@127
|
503 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
|
Chris@127
|
504
|
Chris@127
|
505 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
|
Chris@258
|
506 paint.save();
|
Chris@258
|
507
|
Chris@258
|
508 paint.setPen(Qt::black);
|
Chris@258
|
509 paint.setBrush(Qt::white);
|
Chris@258
|
510 paint.drawRect(0, -1, m_scaleWidth, height()+1);
|
Chris@258
|
511
|
Chris@258
|
512 paint.setBrush(Qt::NoBrush);
|
Chris@258
|
513 scaleLayer->paintVerticalScale
|
Chris@258
|
514 (this, paint, QRect(0, 0, m_scaleWidth, height()));
|
Chris@258
|
515
|
Chris@258
|
516 paint.restore();
|
Chris@258
|
517 }
|
Chris@258
|
518
|
Chris@258
|
519 if (m_identifyFeatures && topLayer) {
|
Chris@258
|
520
|
Chris@258
|
521 QPoint pos = m_identifyPoint;
|
Chris@258
|
522 QString desc = topLayer->getFeatureDescription(this, pos);
|
Chris@258
|
523
|
Chris@258
|
524 if (desc != "") {
|
Chris@258
|
525
|
Chris@127
|
526 paint.save();
|
Chris@127
|
527
|
Chris@258
|
528 int tabStop =
|
Chris@258
|
529 paint.fontMetrics().width(tr("Some lengthy prefix:"));
|
Chris@127
|
530
|
Chris@258
|
531 QRect boundingRect =
|
Chris@258
|
532 paint.fontMetrics().boundingRect
|
Chris@258
|
533 (rect(),
|
Chris@258
|
534 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
|
Chris@258
|
535 desc, tabStop);
|
Chris@258
|
536
|
Chris@258
|
537 if (hasLightBackground()) {
|
Chris@258
|
538 paint.setPen(Qt::NoPen);
|
Chris@258
|
539 paint.setBrush(QColor(250, 250, 250, 200));
|
Chris@258
|
540 } else {
|
Chris@258
|
541 paint.setPen(Qt::NoPen);
|
Chris@258
|
542 paint.setBrush(QColor(50, 50, 50, 200));
|
Chris@258
|
543 }
|
Chris@258
|
544
|
Chris@258
|
545 int extra = paint.fontMetrics().descent();
|
Chris@258
|
546 paint.drawRect(width() - boundingRect.width() - 10 - extra,
|
Chris@258
|
547 10 - extra,
|
Chris@258
|
548 boundingRect.width() + 2 * extra,
|
Chris@258
|
549 boundingRect.height() + extra);
|
Chris@258
|
550
|
Chris@258
|
551 if (hasLightBackground()) {
|
Chris@258
|
552 paint.setPen(QColor(150, 20, 0));
|
Chris@258
|
553 } else {
|
Chris@258
|
554 paint.setPen(QColor(255, 150, 100));
|
Chris@258
|
555 }
|
Chris@258
|
556
|
Chris@258
|
557 QTextOption option;
|
Chris@258
|
558 option.setWrapMode(QTextOption::NoWrap);
|
Chris@258
|
559 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
|
Chris@258
|
560 option.setTabStop(tabStop);
|
Chris@258
|
561 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
|
Chris@258
|
562 boundingRect.width(),
|
Chris@258
|
563 boundingRect.height()),
|
Chris@258
|
564 desc,
|
Chris@258
|
565 option);
|
Chris@127
|
566
|
Chris@127
|
567 paint.restore();
|
Chris@127
|
568 }
|
Chris@127
|
569 }
|
Chris@127
|
570
|
Chris@127
|
571 int sampleRate = getModelsSampleRate();
|
Chris@127
|
572 paint.setBrush(Qt::NoBrush);
|
Chris@127
|
573
|
Chris@189
|
574 if (m_centreLineVisible &&
|
Chris@189
|
575 m_manager &&
|
Chris@189
|
576 m_manager->shouldShowCentreLine()) {
|
Chris@127
|
577
|
Chris@189
|
578 QColor c = QColor(0, 0, 0);
|
Chris@189
|
579 if (!hasLightBackground()) {
|
Chris@189
|
580 c = QColor(240, 240, 240);
|
Chris@189
|
581 }
|
Chris@189
|
582 paint.setPen(c);
|
Chris@189
|
583 int x = width() / 2 + 1;
|
Chris@189
|
584 paint.drawLine(x, 0, x, height() - 1);
|
Chris@189
|
585 paint.drawLine(x-1, 1, x+1, 1);
|
Chris@189
|
586 paint.drawLine(x-2, 0, x+2, 0);
|
Chris@189
|
587 paint.drawLine(x-1, height() - 2, x+1, height() - 2);
|
Chris@189
|
588 paint.drawLine(x-2, height() - 1, x+2, height() - 1);
|
Chris@127
|
589
|
Chris@127
|
590 paint.setPen(QColor(50, 50, 50));
|
Chris@127
|
591
|
Chris@127
|
592 int y = height() - fontHeight
|
Chris@127
|
593 + fontAscent - 6;
|
Chris@127
|
594
|
Chris@127
|
595 LayerList::iterator vi = m_layers.end();
|
Chris@127
|
596
|
Chris@127
|
597 if (vi != m_layers.begin()) {
|
Chris@127
|
598
|
Chris@127
|
599 switch ((*--vi)->getPreferredFrameCountPosition()) {
|
Chris@127
|
600
|
Chris@127
|
601 case Layer::PositionTop:
|
Chris@127
|
602 y = fontAscent + 6;
|
Chris@127
|
603 break;
|
Chris@127
|
604
|
Chris@127
|
605 case Layer::PositionMiddle:
|
Chris@127
|
606 y = (height() - fontHeight) / 2
|
Chris@127
|
607 + fontAscent;
|
Chris@127
|
608 break;
|
Chris@127
|
609
|
Chris@127
|
610 case Layer::PositionBottom:
|
Chris@127
|
611 // y already set correctly
|
Chris@127
|
612 break;
|
Chris@127
|
613 }
|
Chris@127
|
614 }
|
Chris@127
|
615
|
Chris@189
|
616 if (m_manager && m_manager->shouldShowFrameCount()) {
|
Chris@127
|
617
|
Chris@127
|
618 if (sampleRate) {
|
Chris@127
|
619
|
Chris@127
|
620 QString text(QString::fromStdString
|
Chris@127
|
621 (RealTime::frame2RealTime
|
Chris@127
|
622 (m_centreFrame, sampleRate).toText(true)));
|
Chris@127
|
623
|
Chris@127
|
624 int tw = paint.fontMetrics().width(text);
|
Chris@127
|
625 int x = width()/2 - 4 - tw;
|
Chris@127
|
626
|
Chris@127
|
627 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@127
|
628 }
|
Chris@127
|
629
|
Chris@127
|
630 QString text = QString("%1").arg(m_centreFrame);
|
Chris@127
|
631
|
Chris@127
|
632 int x = width()/2 + 4;
|
Chris@127
|
633
|
Chris@127
|
634 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@127
|
635 }
|
Chris@127
|
636
|
Chris@127
|
637 } else {
|
Chris@127
|
638
|
Chris@127
|
639 paint.setPen(QColor(50, 50, 50));
|
Chris@127
|
640 }
|
Chris@127
|
641
|
Chris@127
|
642 if (waveformModel &&
|
Chris@127
|
643 m_manager &&
|
Chris@189
|
644 m_manager->shouldShowDuration() &&
|
Chris@127
|
645 r.y() + r.height() >= height() - fontHeight - 6) {
|
Chris@127
|
646
|
Chris@150
|
647 size_t modelRate = waveformModel->getSampleRate();
|
Chris@127
|
648 size_t playbackRate = m_manager->getPlaybackSampleRate();
|
Chris@224
|
649 size_t outputRate = m_manager->getOutputSampleRate();
|
Chris@224
|
650
|
Chris@127
|
651 QString srNote = "";
|
Chris@127
|
652
|
Chris@127
|
653 // Show (R) for waveform models that will be resampled on
|
Chris@127
|
654 // playback, and (X) for waveform models that will be played
|
Chris@224
|
655 // at the wrong rate because their rate differs from the
|
Chris@224
|
656 // current playback rate (which is not necessarily that of the
|
Chris@224
|
657 // main model).
|
Chris@127
|
658
|
Chris@224
|
659 if (playbackRate != 0) {
|
Chris@224
|
660 if (modelRate == playbackRate) {
|
Chris@224
|
661 if (modelRate != outputRate) srNote = " " + tr("(R)");
|
Chris@224
|
662 } else {
|
Chris@224
|
663 srNote = " " + tr("(X)");
|
Chris@224
|
664 }
|
Chris@224
|
665 }
|
Chris@127
|
666
|
Chris@127
|
667 QString desc = tr("%1 / %2Hz%3")
|
Chris@127
|
668 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
|
Chris@127
|
669 sampleRate)
|
Chris@127
|
670 .toText(false).c_str())
|
Chris@150
|
671 .arg(modelRate)
|
Chris@127
|
672 .arg(srNote);
|
Chris@127
|
673
|
Chris@223
|
674 if (r.x() < m_scaleWidth + 5 + paint.fontMetrics().width(desc)) {
|
Chris@223
|
675 drawVisibleText(paint, m_scaleWidth + 5,
|
Chris@127
|
676 height() - fontHeight + fontAscent - 6,
|
Chris@127
|
677 desc, OutlinedText);
|
Chris@127
|
678 }
|
Chris@127
|
679 }
|
Chris@127
|
680
|
Chris@127
|
681 if (m_manager &&
|
Chris@189
|
682 m_manager->shouldShowLayerNames() &&
|
Chris@248
|
683 r.y() + r.height() >= height() - int(m_layers.size()) * fontHeight - 6) {
|
Chris@127
|
684
|
Chris@127
|
685 std::vector<QString> texts;
|
Chris@127
|
686 int maxTextWidth = 0;
|
Chris@127
|
687
|
Chris@127
|
688 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@127
|
689
|
Chris@127
|
690 QString text = (*i)->getLayerPresentationName();
|
Chris@127
|
691 int tw = paint.fontMetrics().width(text);
|
Chris@127
|
692 bool reduced = false;
|
Chris@127
|
693 while (tw > width() / 3 && text.length() > 4) {
|
Chris@127
|
694 if (!reduced && text.length() > 8) {
|
Chris@127
|
695 text = text.left(text.length() - 4);
|
Chris@127
|
696 } else {
|
Chris@127
|
697 text = text.left(text.length() - 2);
|
Chris@127
|
698 }
|
Chris@127
|
699 reduced = true;
|
Chris@127
|
700 tw = paint.fontMetrics().width(text + "...");
|
Chris@127
|
701 }
|
Chris@127
|
702 if (reduced) {
|
Chris@127
|
703 texts.push_back(text + "...");
|
Chris@127
|
704 } else {
|
Chris@127
|
705 texts.push_back(text);
|
Chris@127
|
706 }
|
Chris@127
|
707 if (tw > maxTextWidth) maxTextWidth = tw;
|
Chris@127
|
708 }
|
Chris@127
|
709
|
Chris@127
|
710 int lly = height() - 6;
|
Chris@133
|
711 int llx = width() - maxTextWidth - 5;
|
Chris@127
|
712
|
Chris@133
|
713 if (m_manager->getZoomWheelsEnabled()) {
|
Chris@133
|
714 lly -= 20;
|
Chris@173
|
715 llx -= 36;
|
Chris@133
|
716 }
|
Chris@133
|
717
|
Chris@133
|
718 if (r.x() + r.width() >= llx) {
|
Chris@127
|
719
|
Chris@248
|
720 for (size_t i = 0; i < texts.size(); ++i) {
|
Chris@127
|
721
|
Chris@248
|
722 if (i + 1 == texts.size()) {
|
Chris@127
|
723 paint.setPen(Qt::black);
|
Chris@127
|
724 }
|
Chris@127
|
725
|
Chris@133
|
726 drawVisibleText(paint, llx,
|
Chris@127
|
727 lly - fontHeight + fontAscent,
|
Chris@127
|
728 texts[i], OutlinedText);
|
Chris@127
|
729
|
Chris@127
|
730 lly -= fontHeight;
|
Chris@127
|
731 }
|
Chris@127
|
732 }
|
Chris@127
|
733 }
|
Chris@127
|
734
|
Chris@127
|
735 if (m_clickedInRange && m_shiftPressed) {
|
Chris@127
|
736 if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) {
|
Chris@127
|
737 //!!! be nice if this looked a bit more in keeping with the
|
Chris@127
|
738 //selection block
|
Chris@127
|
739 paint.setPen(Qt::blue);
|
Chris@127
|
740 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
|
Chris@127
|
741 m_mousePos.x() - m_clickPos.x(),
|
Chris@127
|
742 m_mousePos.y() - m_clickPos.y());
|
Chris@127
|
743 }
|
Chris@127
|
744 }
|
Chris@127
|
745
|
Chris@127
|
746 if (selectionIsBeingEdited()) {
|
Chris@127
|
747
|
Chris@127
|
748 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@127
|
749 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
|
Chris@127
|
750 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@127
|
751
|
Chris@127
|
752 if (m_editingSelectionEdge < 0) {
|
Chris@127
|
753 p1 = getXForFrame(m_editingSelection.getEndFrame());
|
Chris@127
|
754 } else if (m_editingSelectionEdge > 0) {
|
Chris@127
|
755 p0 = getXForFrame(m_editingSelection.getStartFrame());
|
Chris@127
|
756 }
|
Chris@127
|
757
|
Chris@127
|
758 paint.save();
|
Chris@127
|
759 if (hasLightBackground()) {
|
Chris@127
|
760 paint.setPen(QPen(Qt::black, 2));
|
Chris@127
|
761 } else {
|
Chris@127
|
762 paint.setPen(QPen(Qt::white, 2));
|
Chris@127
|
763 }
|
Chris@127
|
764
|
Chris@127
|
765 //!!! duplicating display policy with View::drawSelections
|
Chris@127
|
766
|
Chris@127
|
767 if (m_editingSelectionEdge < 0) {
|
Chris@127
|
768 paint.drawLine(p0, 1, p1, 1);
|
Chris@127
|
769 paint.drawLine(p0, 0, p0, height());
|
Chris@127
|
770 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@127
|
771 } else if (m_editingSelectionEdge > 0) {
|
Chris@127
|
772 paint.drawLine(p0, 1, p1, 1);
|
Chris@127
|
773 paint.drawLine(p1, 0, p1, height());
|
Chris@127
|
774 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@127
|
775 } else {
|
Chris@127
|
776 paint.setBrush(Qt::NoBrush);
|
Chris@127
|
777 paint.drawRect(p0, 1, p1 - p0, height() - 2);
|
Chris@127
|
778 }
|
Chris@127
|
779 paint.restore();
|
Chris@127
|
780 }
|
Chris@127
|
781
|
Chris@127
|
782 paint.end();
|
Chris@127
|
783 }
|
Chris@127
|
784
|
Chris@227
|
785 bool
|
Chris@229
|
786 Pane::render(QPainter &paint, int xorigin, size_t f0, size_t f1)
|
Chris@227
|
787 {
|
Chris@229
|
788 if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) {
|
Chris@227
|
789 return false;
|
Chris@227
|
790 }
|
Chris@227
|
791
|
Chris@227
|
792 if (m_scaleWidth > 0) {
|
Chris@227
|
793
|
Chris@227
|
794 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@227
|
795 --vi;
|
Chris@227
|
796
|
Chris@227
|
797 paint.save();
|
Chris@227
|
798
|
Chris@227
|
799 paint.setPen(Qt::black);
|
Chris@227
|
800 paint.setBrush(Qt::white);
|
Chris@229
|
801 paint.drawRect(xorigin, -1, m_scaleWidth, height()+1);
|
Chris@227
|
802
|
Chris@227
|
803 paint.setBrush(Qt::NoBrush);
|
Chris@227
|
804 (*vi)->paintVerticalScale
|
Chris@229
|
805 (this, paint, QRect(xorigin, 0, m_scaleWidth, height()));
|
Chris@227
|
806
|
Chris@227
|
807 paint.restore();
|
Chris@227
|
808 break;
|
Chris@227
|
809 }
|
Chris@227
|
810 }
|
Chris@227
|
811
|
Chris@227
|
812 return true;
|
Chris@227
|
813 }
|
Chris@227
|
814
|
Chris@227
|
815 QImage *
|
Chris@229
|
816 Pane::toNewImage(size_t f0, size_t f1)
|
Chris@227
|
817 {
|
Chris@227
|
818 size_t x0 = f0 / getZoomLevel();
|
Chris@227
|
819 size_t x1 = f1 / getZoomLevel();
|
Chris@227
|
820
|
Chris@227
|
821 QImage *image = new QImage(x1 - x0 + m_scaleWidth,
|
Chris@227
|
822 height(), QImage::Format_RGB32);
|
Chris@227
|
823
|
Chris@227
|
824 int formerScaleWidth = m_scaleWidth;
|
Chris@227
|
825
|
Chris@227
|
826 if (m_manager && m_manager->shouldShowVerticalScale()) {
|
Chris@227
|
827 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@227
|
828 --vi;
|
Chris@227
|
829 QPainter paint(image);
|
Chris@227
|
830 m_scaleWidth = (*vi)->getVerticalScaleWidth(this, paint);
|
Chris@227
|
831 break;
|
Chris@227
|
832 }
|
Chris@227
|
833 } else {
|
Chris@227
|
834 m_scaleWidth = 0;
|
Chris@227
|
835 }
|
Chris@227
|
836
|
Chris@227
|
837 if (m_scaleWidth != formerScaleWidth) {
|
Chris@227
|
838 delete image;
|
Chris@227
|
839 image = new QImage(x1 - x0 + m_scaleWidth,
|
Chris@227
|
840 height(), QImage::Format_RGB32);
|
Chris@227
|
841 }
|
Chris@227
|
842
|
Chris@227
|
843 QPainter *paint = new QPainter(image);
|
Chris@229
|
844 if (!render(*paint, 0, f0, f1)) {
|
Chris@227
|
845 delete paint;
|
Chris@227
|
846 delete image;
|
Chris@227
|
847 return 0;
|
Chris@227
|
848 } else {
|
Chris@227
|
849 delete paint;
|
Chris@227
|
850 return image;
|
Chris@227
|
851 }
|
Chris@227
|
852 }
|
Chris@227
|
853
|
Chris@229
|
854 QSize
|
Chris@229
|
855 Pane::getImageSize(size_t f0, size_t f1)
|
Chris@229
|
856 {
|
Chris@229
|
857 QSize s = View::getImageSize(f0, f1);
|
Chris@229
|
858 QImage *image = new QImage(100, 100, QImage::Format_RGB32);
|
Chris@229
|
859 QPainter paint(image);
|
Chris@229
|
860
|
Chris@229
|
861 int sw = 0;
|
Chris@229
|
862 if (m_manager && m_manager->shouldShowVerticalScale()) {
|
Chris@229
|
863 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@229
|
864 --vi;
|
Chris@229
|
865 QPainter paint(image);
|
Chris@229
|
866 sw = (*vi)->getVerticalScaleWidth(this, paint);
|
Chris@229
|
867 break;
|
Chris@229
|
868 }
|
Chris@229
|
869 }
|
Chris@229
|
870
|
Chris@229
|
871 return QSize(sw + s.width(), s.height());
|
Chris@229
|
872 }
|
Chris@229
|
873
|
Chris@222
|
874 size_t
|
Chris@222
|
875 Pane::getFirstVisibleFrame() const
|
Chris@222
|
876 {
|
Chris@222
|
877 long f0 = getFrameForX(m_scaleWidth);
|
Chris@222
|
878 size_t f = View::getFirstVisibleFrame();
|
Chris@222
|
879 if (f0 < 0 || f0 < long(f)) return f;
|
Chris@222
|
880 return f0;
|
Chris@222
|
881 }
|
Chris@222
|
882
|
Chris@127
|
883 Selection
|
Chris@127
|
884 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
|
Chris@127
|
885 {
|
Chris@127
|
886 closeToLeftEdge = closeToRightEdge = false;
|
Chris@127
|
887
|
Chris@127
|
888 if (!m_manager) return Selection();
|
Chris@127
|
889
|
Chris@127
|
890 long testFrame = getFrameForX(x - 5);
|
Chris@127
|
891 if (testFrame < 0) {
|
Chris@127
|
892 testFrame = getFrameForX(x);
|
Chris@127
|
893 if (testFrame < 0) return Selection();
|
Chris@127
|
894 }
|
Chris@127
|
895
|
Chris@127
|
896 Selection selection = m_manager->getContainingSelection(testFrame, true);
|
Chris@127
|
897 if (selection.isEmpty()) return selection;
|
Chris@127
|
898
|
Chris@127
|
899 int lx = getXForFrame(selection.getStartFrame());
|
Chris@127
|
900 int rx = getXForFrame(selection.getEndFrame());
|
Chris@127
|
901
|
Chris@127
|
902 int fuzz = 2;
|
Chris@127
|
903 if (x < lx - fuzz || x > rx + fuzz) return Selection();
|
Chris@127
|
904
|
Chris@127
|
905 int width = rx - lx;
|
Chris@127
|
906 fuzz = 3;
|
Chris@127
|
907 if (width < 12) fuzz = width / 4;
|
Chris@127
|
908 if (fuzz < 1) fuzz = 1;
|
Chris@127
|
909
|
Chris@127
|
910 if (x < lx + fuzz) closeToLeftEdge = true;
|
Chris@127
|
911 if (x > rx - fuzz) closeToRightEdge = true;
|
Chris@127
|
912
|
Chris@127
|
913 return selection;
|
Chris@127
|
914 }
|
Chris@127
|
915
|
Chris@174
|
916 bool
|
Chris@174
|
917 Pane::canTopLayerMoveVertical()
|
Chris@174
|
918 {
|
Chris@174
|
919 float vmin, vmax, dmin, dmax;
|
Chris@174
|
920 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false;
|
Chris@174
|
921 if (dmin <= vmin && dmax >= vmax) return false;
|
Chris@174
|
922 return true;
|
Chris@174
|
923 }
|
Chris@174
|
924
|
Chris@174
|
925 bool
|
Chris@174
|
926 Pane::getTopLayerDisplayExtents(float &vmin, float &vmax,
|
Chris@188
|
927 float &dmin, float &dmax,
|
Chris@188
|
928 QString *unit)
|
Chris@174
|
929 {
|
Chris@174
|
930 Layer *layer = 0;
|
Chris@174
|
931 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@174
|
932 if (!layer) return false;
|
Chris@174
|
933 bool vlog;
|
Chris@174
|
934 QString vunit;
|
Chris@188
|
935 bool rv = (layer->getValueExtents(vmin, vmax, vlog, vunit) &&
|
Chris@188
|
936 layer->getDisplayExtents(dmin, dmax));
|
Chris@188
|
937 if (unit) *unit = vunit;
|
Chris@188
|
938 return rv;
|
Chris@174
|
939 }
|
Chris@174
|
940
|
Chris@174
|
941 bool
|
Chris@174
|
942 Pane::setTopLayerDisplayExtents(float dmin, float dmax)
|
Chris@174
|
943 {
|
Chris@174
|
944 Layer *layer = 0;
|
Chris@174
|
945 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@174
|
946 if (!layer) return false;
|
Chris@174
|
947 return layer->setDisplayExtents(dmin, dmax);
|
Chris@174
|
948 }
|
Chris@174
|
949
|
Chris@127
|
950 void
|
Chris@127
|
951 Pane::mousePressEvent(QMouseEvent *e)
|
Chris@127
|
952 {
|
Chris@127
|
953 if (e->buttons() & Qt::RightButton) {
|
Chris@189
|
954 emit contextHelpChanged("");
|
Chris@127
|
955 emit rightButtonMenuRequested(mapToGlobal(e->pos()));
|
Chris@127
|
956 return;
|
Chris@127
|
957 }
|
Chris@127
|
958
|
Chris@127
|
959 m_clickPos = e->pos();
|
Chris@127
|
960 m_clickedInRange = true;
|
Chris@127
|
961 m_editingSelection = Selection();
|
Chris@127
|
962 m_editingSelectionEdge = 0;
|
Chris@127
|
963 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@127
|
964 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@150
|
965 m_dragMode = UnresolvedDrag;
|
Chris@127
|
966
|
Chris@127
|
967 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
968 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
969
|
Chris@127
|
970 m_navigating = false;
|
Chris@127
|
971
|
Chris@127
|
972 if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)) {
|
Chris@127
|
973
|
Chris@127
|
974 if (mode != ViewManager::NavigateMode) {
|
Chris@127
|
975 setCursor(Qt::PointingHandCursor);
|
Chris@127
|
976 }
|
Chris@127
|
977
|
Chris@127
|
978 m_navigating = true;
|
Chris@127
|
979 m_dragCentreFrame = m_centreFrame;
|
Chris@136
|
980 m_dragStartMinValue = 0;
|
Chris@174
|
981
|
Chris@174
|
982 float vmin, vmax, dmin, dmax;
|
Chris@174
|
983 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@174
|
984 m_dragStartMinValue = dmin;
|
Chris@136
|
985 }
|
Chris@136
|
986
|
Chris@127
|
987 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
988
|
Chris@217
|
989 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
990
|
Chris@127
|
991 bool closeToLeft = false, closeToRight = false;
|
Chris@127
|
992 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@127
|
993
|
Chris@127
|
994 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@127
|
995
|
Chris@127
|
996 m_manager->removeSelection(selection);
|
Chris@127
|
997
|
Chris@127
|
998 if (closeToLeft) {
|
Chris@127
|
999 m_selectionStartFrame = selection.getEndFrame();
|
Chris@127
|
1000 } else {
|
Chris@127
|
1001 m_selectionStartFrame = selection.getStartFrame();
|
Chris@127
|
1002 }
|
Chris@127
|
1003
|
Chris@127
|
1004 m_manager->setInProgressSelection(selection, false);
|
Chris@127
|
1005 m_resizing = true;
|
Chris@127
|
1006
|
Chris@127
|
1007 } else {
|
Chris@127
|
1008
|
Chris@127
|
1009 int mouseFrame = getFrameForX(e->x());
|
Chris@127
|
1010 size_t resolution = 1;
|
Chris@127
|
1011 int snapFrame = mouseFrame;
|
Chris@127
|
1012
|
Chris@127
|
1013 Layer *layer = getSelectedLayer();
|
Chris@127
|
1014 if (layer && !m_shiftPressed) {
|
Chris@127
|
1015 layer->snapToFeatureFrame(this, snapFrame,
|
Chris@127
|
1016 resolution, Layer::SnapLeft);
|
Chris@127
|
1017 }
|
Chris@127
|
1018
|
Chris@127
|
1019 if (snapFrame < 0) snapFrame = 0;
|
Chris@127
|
1020 m_selectionStartFrame = snapFrame;
|
Chris@127
|
1021 if (m_manager) {
|
Chris@127
|
1022 m_manager->setInProgressSelection(Selection(snapFrame,
|
Chris@127
|
1023 snapFrame + resolution),
|
Chris@127
|
1024 !m_ctrlPressed);
|
Chris@127
|
1025 }
|
Chris@127
|
1026
|
Chris@127
|
1027 m_resizing = false;
|
Chris@127
|
1028 }
|
Chris@127
|
1029
|
Chris@127
|
1030 update();
|
Chris@127
|
1031
|
Chris@127
|
1032 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
1033
|
Chris@127
|
1034 Layer *layer = getSelectedLayer();
|
Chris@127
|
1035 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
1036 layer->drawStart(this, e);
|
Chris@127
|
1037 }
|
Chris@127
|
1038
|
Chris@127
|
1039 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
1040
|
Chris@127
|
1041 if (!editSelectionStart(e)) {
|
Chris@127
|
1042 Layer *layer = getSelectedLayer();
|
Chris@127
|
1043 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
1044 layer->editStart(this, e);
|
Chris@127
|
1045 }
|
Chris@127
|
1046 }
|
Chris@127
|
1047 }
|
Chris@127
|
1048
|
Chris@127
|
1049 emit paneInteractedWith();
|
Chris@127
|
1050 }
|
Chris@127
|
1051
|
Chris@127
|
1052 void
|
Chris@127
|
1053 Pane::mouseReleaseEvent(QMouseEvent *e)
|
Chris@127
|
1054 {
|
Chris@127
|
1055 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
1056 return;
|
Chris@127
|
1057 }
|
Chris@127
|
1058
|
Chris@127
|
1059 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
1060 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
1061
|
Chris@127
|
1062 if (m_clickedInRange) {
|
Chris@127
|
1063 mouseMoveEvent(e);
|
Chris@127
|
1064 }
|
Chris@127
|
1065
|
Chris@127
|
1066 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@127
|
1067
|
Chris@127
|
1068 m_navigating = false;
|
Chris@127
|
1069
|
Chris@127
|
1070 if (mode != ViewManager::NavigateMode) {
|
Chris@127
|
1071 // restore cursor
|
Chris@127
|
1072 toolModeChanged();
|
Chris@127
|
1073 }
|
Chris@127
|
1074
|
Chris@127
|
1075 if (m_shiftPressed) {
|
Chris@127
|
1076
|
Chris@127
|
1077 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
|
Chris@127
|
1078 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
|
Chris@127
|
1079
|
Chris@127
|
1080 int y0 = std::min(m_clickPos.y(), m_mousePos.y());
|
Chris@127
|
1081 int y1 = std::max(m_clickPos.y(), m_mousePos.y());
|
Chris@127
|
1082
|
Chris@174
|
1083 zoomToRegion(x0, y0, x1, y1);
|
Chris@127
|
1084 }
|
Chris@127
|
1085
|
Chris@127
|
1086 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
1087
|
Chris@217
|
1088 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
1089
|
Chris@127
|
1090 if (m_manager && m_manager->haveInProgressSelection()) {
|
Chris@127
|
1091
|
Chris@127
|
1092 bool exclusive;
|
Chris@127
|
1093 Selection selection = m_manager->getInProgressSelection(exclusive);
|
Chris@127
|
1094
|
Chris@127
|
1095 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
|
Chris@127
|
1096 selection = Selection();
|
Chris@127
|
1097 }
|
Chris@127
|
1098
|
Chris@127
|
1099 m_manager->clearInProgressSelection();
|
Chris@127
|
1100
|
Chris@127
|
1101 if (exclusive) {
|
Chris@127
|
1102 m_manager->setSelection(selection);
|
Chris@127
|
1103 } else {
|
Chris@127
|
1104 m_manager->addSelection(selection);
|
Chris@127
|
1105 }
|
Chris@127
|
1106 }
|
Chris@127
|
1107
|
Chris@127
|
1108 update();
|
Chris@127
|
1109
|
Chris@127
|
1110 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
1111
|
Chris@127
|
1112 Layer *layer = getSelectedLayer();
|
Chris@127
|
1113 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
1114 layer->drawEnd(this, e);
|
Chris@127
|
1115 update();
|
Chris@127
|
1116 }
|
Chris@127
|
1117
|
Chris@127
|
1118 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
1119
|
Chris@127
|
1120 if (!editSelectionEnd(e)) {
|
Chris@127
|
1121 Layer *layer = getSelectedLayer();
|
Chris@127
|
1122 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
1123 layer->editEnd(this, e);
|
Chris@127
|
1124 update();
|
Chris@127
|
1125 }
|
Chris@127
|
1126 }
|
Chris@127
|
1127 }
|
Chris@127
|
1128
|
Chris@127
|
1129 m_clickedInRange = false;
|
Chris@127
|
1130
|
Chris@127
|
1131 emit paneInteractedWith();
|
Chris@127
|
1132 }
|
Chris@127
|
1133
|
Chris@127
|
1134 void
|
Chris@127
|
1135 Pane::mouseMoveEvent(QMouseEvent *e)
|
Chris@127
|
1136 {
|
Chris@127
|
1137 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
1138 return;
|
Chris@127
|
1139 }
|
Chris@127
|
1140
|
Chris@189
|
1141 updateContextHelp(&e->pos());
|
Chris@189
|
1142
|
Chris@127
|
1143 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
1144 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
1145
|
Chris@127
|
1146 QPoint prevPoint = m_identifyPoint;
|
Chris@127
|
1147 m_identifyPoint = e->pos();
|
Chris@127
|
1148
|
Chris@127
|
1149 if (!m_clickedInRange) {
|
Chris@127
|
1150
|
Chris@217
|
1151 if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) {
|
Chris@127
|
1152 bool closeToLeft = false, closeToRight = false;
|
Chris@127
|
1153 getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@127
|
1154 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@127
|
1155 setCursor(Qt::SizeHorCursor);
|
Chris@127
|
1156 } else {
|
Chris@127
|
1157 setCursor(Qt::ArrowCursor);
|
Chris@127
|
1158 }
|
Chris@127
|
1159 }
|
Chris@127
|
1160
|
Chris@127
|
1161 if (!m_manager->isPlaying()) {
|
Chris@127
|
1162
|
Chris@174
|
1163 if (getSelectedLayer()) {
|
Chris@127
|
1164
|
Chris@174
|
1165 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@174
|
1166 m_identifyFeatures = true;
|
Chris@174
|
1167
|
Chris@174
|
1168 if (m_identifyFeatures != previouslyIdentifying ||
|
Chris@174
|
1169 m_identifyPoint != prevPoint) {
|
Chris@174
|
1170 update();
|
Chris@174
|
1171 }
|
Chris@174
|
1172 }
|
Chris@127
|
1173 }
|
Chris@127
|
1174
|
Chris@127
|
1175 return;
|
Chris@127
|
1176 }
|
Chris@127
|
1177
|
Chris@127
|
1178 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@127
|
1179
|
Chris@127
|
1180 if (m_shiftPressed) {
|
Chris@127
|
1181
|
Chris@127
|
1182 m_mousePos = e->pos();
|
Chris@127
|
1183 update();
|
Chris@127
|
1184
|
Chris@127
|
1185 } else {
|
Chris@127
|
1186
|
Chris@174
|
1187 dragTopLayer(e);
|
Chris@150
|
1188 }
|
Chris@127
|
1189
|
Chris@127
|
1190 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
1191
|
Chris@217
|
1192 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
1193
|
Chris@174
|
1194 dragExtendSelection(e);
|
Chris@127
|
1195
|
Chris@127
|
1196 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
1197
|
Chris@127
|
1198 Layer *layer = getSelectedLayer();
|
Chris@127
|
1199 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
1200 layer->drawDrag(this, e);
|
Chris@127
|
1201 }
|
Chris@127
|
1202
|
Chris@127
|
1203 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
1204
|
Chris@127
|
1205 if (!editSelectionDrag(e)) {
|
Chris@127
|
1206 Layer *layer = getSelectedLayer();
|
Chris@127
|
1207 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
1208 layer->editDrag(this, e);
|
Chris@127
|
1209 }
|
Chris@127
|
1210 }
|
Chris@127
|
1211 }
|
Chris@127
|
1212 }
|
Chris@127
|
1213
|
Chris@127
|
1214 void
|
Chris@174
|
1215 Pane::zoomToRegion(int x0, int y0, int x1, int y1)
|
Chris@174
|
1216 {
|
Chris@174
|
1217 int w = x1 - x0;
|
Chris@174
|
1218
|
Chris@174
|
1219 long newStartFrame = getFrameForX(x0);
|
Chris@174
|
1220
|
Chris@174
|
1221 long visibleFrames = getEndFrame() - getStartFrame();
|
Chris@174
|
1222 if (newStartFrame <= -visibleFrames) {
|
Chris@174
|
1223 newStartFrame = -visibleFrames + 1;
|
Chris@174
|
1224 }
|
Chris@174
|
1225
|
Chris@174
|
1226 if (newStartFrame >= long(getModelsEndFrame())) {
|
Chris@174
|
1227 newStartFrame = getModelsEndFrame() - 1;
|
Chris@174
|
1228 }
|
Chris@174
|
1229
|
Chris@174
|
1230 float ratio = float(w) / float(width());
|
Chris@174
|
1231 // std::cerr << "ratio: " << ratio << std::endl;
|
Chris@174
|
1232 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
|
Chris@174
|
1233 if (newZoomLevel < 1) newZoomLevel = 1;
|
Chris@174
|
1234
|
Chris@174
|
1235 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
|
Chris@174
|
1236 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
|
Chris@174
|
1237 setStartFrame(newStartFrame);
|
Chris@174
|
1238
|
Chris@174
|
1239 QString unit;
|
Chris@174
|
1240 float min, max;
|
Chris@174
|
1241 bool log;
|
Chris@174
|
1242 Layer *layer = 0;
|
Chris@174
|
1243 for (LayerList::const_iterator i = m_layers.begin();
|
Chris@174
|
1244 i != m_layers.end(); ++i) {
|
Chris@174
|
1245 if ((*i)->getValueExtents(min, max, log, unit) &&
|
Chris@174
|
1246 (*i)->getDisplayExtents(min, max)) {
|
Chris@174
|
1247 layer = *i;
|
Chris@174
|
1248 break;
|
Chris@174
|
1249 }
|
Chris@174
|
1250 }
|
Chris@174
|
1251
|
Chris@174
|
1252 if (layer) {
|
Chris@174
|
1253 if (log) {
|
Chris@174
|
1254 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min);
|
Chris@174
|
1255 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max);
|
Chris@174
|
1256 }
|
Chris@174
|
1257 float rmin = min + ((max - min) * (height() - y1)) / height();
|
Chris@174
|
1258 float rmax = min + ((max - min) * (height() - y0)) / height();
|
Chris@174
|
1259 std::cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << std::endl;
|
Chris@174
|
1260 if (log) {
|
Chris@174
|
1261 rmin = powf(10, rmin);
|
Chris@174
|
1262 rmax = powf(10, rmax);
|
Chris@174
|
1263 }
|
Chris@174
|
1264 std::cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit.toStdString() << std::endl;
|
Chris@174
|
1265
|
Chris@174
|
1266 layer->setDisplayExtents(rmin, rmax);
|
Chris@174
|
1267 updateVerticalPanner();
|
Chris@174
|
1268 }
|
Chris@174
|
1269 }
|
Chris@174
|
1270
|
Chris@174
|
1271 void
|
Chris@174
|
1272 Pane::dragTopLayer(QMouseEvent *e)
|
Chris@174
|
1273 {
|
Chris@174
|
1274 // We need to avoid making it too easy to drag both
|
Chris@174
|
1275 // horizontally and vertically, in the case where the
|
Chris@174
|
1276 // mouse is moved "mostly" in horizontal or vertical axis
|
Chris@174
|
1277 // with only a small variation in the other axis. This is
|
Chris@174
|
1278 // particularly important during playback (when we want to
|
Chris@174
|
1279 // avoid small horizontal motions) or in slow refresh
|
Chris@174
|
1280 // layers like spectrogram (when we want to avoid small
|
Chris@174
|
1281 // vertical motions).
|
Chris@174
|
1282 //
|
Chris@174
|
1283 // To this end we have horizontal and vertical thresholds
|
Chris@174
|
1284 // and a series of states: unresolved, horizontally or
|
Chris@174
|
1285 // vertically constrained, free.
|
Chris@174
|
1286 //
|
Chris@174
|
1287 // When the mouse first moves, we're unresolved: we
|
Chris@174
|
1288 // restrict ourselves to whichever direction seems safest,
|
Chris@174
|
1289 // until the mouse has passed a small threshold distance
|
Chris@174
|
1290 // from the click point. Then we lock in to one of the
|
Chris@174
|
1291 // constrained modes, based on which axis that distance
|
Chris@174
|
1292 // was measured in first. Finally, if it turns out we've
|
Chris@174
|
1293 // also moved more than a certain larger distance in the
|
Chris@174
|
1294 // other direction as well, we may switch into free mode.
|
Chris@174
|
1295 //
|
Chris@174
|
1296 // If the top layer is incapable of being dragged
|
Chris@174
|
1297 // vertically, the logic is short circuited.
|
Chris@174
|
1298
|
Chris@174
|
1299 int xdiff = e->x() - m_clickPos.x();
|
Chris@174
|
1300 int ydiff = e->y() - m_clickPos.y();
|
Chris@174
|
1301 int smallThreshold = 10, bigThreshold = 50;
|
Chris@174
|
1302
|
Chris@174
|
1303 bool canMoveVertical = canTopLayerMoveVertical();
|
Chris@174
|
1304 bool canMoveHorizontal = true;
|
Chris@174
|
1305
|
Chris@174
|
1306 if (!canMoveHorizontal) {
|
Chris@174
|
1307 m_dragMode = HorizontalDrag;
|
Chris@174
|
1308 }
|
Chris@174
|
1309
|
Chris@174
|
1310 if (m_dragMode == UnresolvedDrag) {
|
Chris@174
|
1311
|
Chris@174
|
1312 if (abs(ydiff) > smallThreshold &&
|
Chris@174
|
1313 abs(ydiff) > abs(xdiff) * 2) {
|
Chris@174
|
1314 m_dragMode = VerticalDrag;
|
Chris@174
|
1315 } else if (abs(xdiff) > smallThreshold &&
|
Chris@174
|
1316 abs(xdiff) > abs(ydiff) * 2) {
|
Chris@174
|
1317 m_dragMode = HorizontalDrag;
|
Chris@174
|
1318 } else if (abs(xdiff) > smallThreshold &&
|
Chris@174
|
1319 abs(ydiff) > smallThreshold) {
|
Chris@174
|
1320 m_dragMode = FreeDrag;
|
Chris@174
|
1321 } else {
|
Chris@174
|
1322 // When playing, we don't want to disturb the play
|
Chris@174
|
1323 // position too easily; when not playing, we don't
|
Chris@174
|
1324 // want to move up/down too easily
|
Chris@174
|
1325 if (m_manager && m_manager->isPlaying()) {
|
Chris@174
|
1326 canMoveHorizontal = false;
|
Chris@174
|
1327 } else {
|
Chris@174
|
1328 canMoveVertical = false;
|
Chris@174
|
1329 }
|
Chris@174
|
1330 }
|
Chris@174
|
1331 }
|
Chris@174
|
1332
|
Chris@174
|
1333 if (m_dragMode == VerticalDrag) {
|
Chris@174
|
1334 if (abs(xdiff) > bigThreshold) m_dragMode = FreeDrag;
|
Chris@174
|
1335 else canMoveHorizontal = false;
|
Chris@174
|
1336 }
|
Chris@174
|
1337
|
Chris@174
|
1338 if (m_dragMode == HorizontalDrag && canMoveVertical) {
|
Chris@174
|
1339 if (abs(ydiff) > bigThreshold) m_dragMode = FreeDrag;
|
Chris@174
|
1340 else canMoveVertical = false;
|
Chris@174
|
1341 }
|
Chris@174
|
1342
|
Chris@174
|
1343 if (canMoveHorizontal) {
|
Chris@174
|
1344
|
Chris@174
|
1345 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
|
Chris@174
|
1346
|
Chris@174
|
1347 size_t newCentreFrame = m_dragCentreFrame;
|
Chris@174
|
1348
|
Chris@174
|
1349 if (frameOff < 0) {
|
Chris@174
|
1350 newCentreFrame -= frameOff;
|
Chris@174
|
1351 } else if (newCentreFrame >= size_t(frameOff)) {
|
Chris@174
|
1352 newCentreFrame -= frameOff;
|
Chris@174
|
1353 } else {
|
Chris@174
|
1354 newCentreFrame = 0;
|
Chris@174
|
1355 }
|
Chris@174
|
1356
|
Chris@174
|
1357 if (newCentreFrame >= getModelsEndFrame()) {
|
Chris@174
|
1358 newCentreFrame = getModelsEndFrame();
|
Chris@174
|
1359 if (newCentreFrame > 0) --newCentreFrame;
|
Chris@174
|
1360 }
|
Chris@174
|
1361
|
Chris@174
|
1362 if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) {
|
Chris@174
|
1363 setCentreFrame(newCentreFrame);
|
Chris@174
|
1364 }
|
Chris@174
|
1365 }
|
Chris@174
|
1366
|
Chris@174
|
1367 if (canMoveVertical) {
|
Chris@174
|
1368
|
Chris@174
|
1369 float vmin = 0.f, vmax = 0.f;
|
Chris@174
|
1370 float dmin = 0.f, dmax = 0.f;
|
Chris@174
|
1371
|
Chris@174
|
1372 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@174
|
1373
|
Chris@248
|
1374 // std::cerr << "ydiff = " << ydiff << std::endl;
|
Chris@174
|
1375
|
Chris@174
|
1376 float perpix = (dmax - dmin) / height();
|
Chris@174
|
1377 float valdiff = ydiff * perpix;
|
Chris@248
|
1378 // std::cerr << "valdiff = " << valdiff << std::endl;
|
Chris@174
|
1379
|
Chris@174
|
1380 float newmin = m_dragStartMinValue + valdiff;
|
Chris@174
|
1381 float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff;
|
Chris@174
|
1382 if (newmin < vmin) {
|
Chris@174
|
1383 newmax += vmin - newmin;
|
Chris@174
|
1384 newmin += vmin - newmin;
|
Chris@174
|
1385 }
|
Chris@174
|
1386 if (newmax > vmax) {
|
Chris@174
|
1387 newmin -= newmax - vmax;
|
Chris@174
|
1388 newmax -= newmax - vmax;
|
Chris@174
|
1389 }
|
Chris@248
|
1390 // std::cerr << "(" << dmin << ", " << dmax << ") -> ("
|
Chris@248
|
1391 // << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << std::endl;
|
Chris@174
|
1392
|
Chris@174
|
1393 setTopLayerDisplayExtents(newmin, newmax);
|
Chris@174
|
1394 updateVerticalPanner();
|
Chris@174
|
1395 }
|
Chris@174
|
1396 }
|
Chris@174
|
1397 }
|
Chris@174
|
1398
|
Chris@174
|
1399 void
|
Chris@174
|
1400 Pane::dragExtendSelection(QMouseEvent *e)
|
Chris@174
|
1401 {
|
Chris@174
|
1402 int mouseFrame = getFrameForX(e->x());
|
Chris@174
|
1403 size_t resolution = 1;
|
Chris@174
|
1404 int snapFrameLeft = mouseFrame;
|
Chris@174
|
1405 int snapFrameRight = mouseFrame;
|
Chris@174
|
1406
|
Chris@174
|
1407 Layer *layer = getSelectedLayer();
|
Chris@174
|
1408 if (layer && !m_shiftPressed) {
|
Chris@174
|
1409 layer->snapToFeatureFrame(this, snapFrameLeft,
|
Chris@174
|
1410 resolution, Layer::SnapLeft);
|
Chris@174
|
1411 layer->snapToFeatureFrame(this, snapFrameRight,
|
Chris@174
|
1412 resolution, Layer::SnapRight);
|
Chris@174
|
1413 }
|
Chris@174
|
1414
|
Chris@174
|
1415 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl;
|
Chris@174
|
1416
|
Chris@174
|
1417 if (snapFrameLeft < 0) snapFrameLeft = 0;
|
Chris@174
|
1418 if (snapFrameRight < 0) snapFrameRight = 0;
|
Chris@174
|
1419
|
Chris@174
|
1420 size_t min, max;
|
Chris@174
|
1421
|
Chris@248
|
1422 if (m_selectionStartFrame > size_t(snapFrameLeft)) {
|
Chris@174
|
1423 min = snapFrameLeft;
|
Chris@174
|
1424 max = m_selectionStartFrame;
|
Chris@248
|
1425 } else if (size_t(snapFrameRight) > m_selectionStartFrame) {
|
Chris@174
|
1426 min = m_selectionStartFrame;
|
Chris@174
|
1427 max = snapFrameRight;
|
Chris@174
|
1428 } else {
|
Chris@174
|
1429 min = snapFrameLeft;
|
Chris@174
|
1430 max = snapFrameRight;
|
Chris@174
|
1431 }
|
Chris@174
|
1432
|
Chris@174
|
1433 if (m_manager) {
|
Chris@174
|
1434 m_manager->setInProgressSelection(Selection(min, max),
|
Chris@174
|
1435 !m_resizing && !m_ctrlPressed);
|
Chris@174
|
1436 }
|
Chris@174
|
1437
|
Chris@174
|
1438 bool doScroll = false;
|
Chris@174
|
1439 if (!m_manager) doScroll = true;
|
Chris@174
|
1440 if (!m_manager->isPlaying()) doScroll = true;
|
Chris@174
|
1441 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
|
Chris@174
|
1442
|
Chris@174
|
1443 if (doScroll) {
|
Chris@174
|
1444 int offset = mouseFrame - getStartFrame();
|
Chris@174
|
1445 int available = getEndFrame() - getStartFrame();
|
Chris@174
|
1446 if (offset >= available * 0.95) {
|
Chris@174
|
1447 int move = int(offset - available * 0.95) + 1;
|
Chris@174
|
1448 setCentreFrame(m_centreFrame + move);
|
Chris@174
|
1449 } else if (offset <= available * 0.10) {
|
Chris@174
|
1450 int move = int(available * 0.10 - offset) + 1;
|
Chris@248
|
1451 if (move < 0) {
|
Chris@248
|
1452 setCentreFrame(m_centreFrame + (-move));
|
Chris@258
|
1453 } else if (m_centreFrame > size_t(move)) {
|
Chris@174
|
1454 setCentreFrame(m_centreFrame - move);
|
Chris@174
|
1455 } else {
|
Chris@174
|
1456 setCentreFrame(0);
|
Chris@174
|
1457 }
|
Chris@174
|
1458 }
|
Chris@174
|
1459 }
|
Chris@174
|
1460
|
Chris@174
|
1461 update();
|
Chris@174
|
1462 }
|
Chris@174
|
1463
|
Chris@174
|
1464 void
|
Chris@127
|
1465 Pane::mouseDoubleClickEvent(QMouseEvent *e)
|
Chris@127
|
1466 {
|
Chris@127
|
1467 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
1468 return;
|
Chris@127
|
1469 }
|
Chris@127
|
1470
|
Chris@127
|
1471 // std::cerr << "mouseDoubleClickEvent" << std::endl;
|
Chris@127
|
1472
|
Chris@127
|
1473 m_clickPos = e->pos();
|
Chris@127
|
1474 m_clickedInRange = true;
|
Chris@127
|
1475 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@127
|
1476 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@127
|
1477
|
Chris@127
|
1478 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
1479 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
1480
|
Chris@255
|
1481 bool relocate = (mode == ViewManager::NavigateMode ||
|
Chris@255
|
1482 (e->buttons() & Qt::MidButton));
|
Chris@255
|
1483
|
Chris@127
|
1484 if (mode == ViewManager::NavigateMode ||
|
Chris@127
|
1485 mode == ViewManager::EditMode) {
|
Chris@127
|
1486
|
Chris@127
|
1487 Layer *layer = getSelectedLayer();
|
Chris@127
|
1488 if (layer && layer->isLayerEditable()) {
|
Chris@255
|
1489 if (layer->editOpen(this, e)) relocate = false;
|
Chris@127
|
1490 }
|
Chris@127
|
1491 }
|
Chris@255
|
1492
|
Chris@255
|
1493 if (relocate) {
|
Chris@255
|
1494
|
Chris@255
|
1495 long f = getFrameForX(e->x());
|
Chris@255
|
1496
|
Chris@255
|
1497 setCentreFrame(f);
|
Chris@255
|
1498
|
Chris@255
|
1499 m_dragCentreFrame = f;
|
Chris@255
|
1500 m_dragStartMinValue = 0;
|
Chris@255
|
1501 m_dragMode = UnresolvedDrag;
|
Chris@255
|
1502
|
Chris@255
|
1503 float vmin, vmax, dmin, dmax;
|
Chris@255
|
1504 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@255
|
1505 m_dragStartMinValue = dmin;
|
Chris@255
|
1506 }
|
Chris@255
|
1507 }
|
Chris@127
|
1508 }
|
Chris@127
|
1509
|
Chris@127
|
1510 void
|
Chris@127
|
1511 Pane::leaveEvent(QEvent *)
|
Chris@127
|
1512 {
|
Chris@127
|
1513 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@127
|
1514 m_identifyFeatures = false;
|
Chris@127
|
1515 if (previouslyIdentifying) update();
|
Chris@189
|
1516 emit contextHelpChanged("");
|
Chris@127
|
1517 }
|
Chris@127
|
1518
|
Chris@127
|
1519 void
|
Chris@133
|
1520 Pane::resizeEvent(QResizeEvent *)
|
Chris@133
|
1521 {
|
Chris@133
|
1522 updateHeadsUpDisplay();
|
Chris@133
|
1523 }
|
Chris@133
|
1524
|
Chris@133
|
1525 void
|
Chris@127
|
1526 Pane::wheelEvent(QWheelEvent *e)
|
Chris@127
|
1527 {
|
Chris@127
|
1528 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
|
Chris@127
|
1529
|
Chris@127
|
1530 int count = e->delta();
|
Chris@127
|
1531
|
Chris@127
|
1532 if (count > 0) {
|
Chris@127
|
1533 if (count >= 120) count /= 120;
|
Chris@127
|
1534 else count = 1;
|
Chris@127
|
1535 }
|
Chris@127
|
1536
|
Chris@127
|
1537 if (count < 0) {
|
Chris@127
|
1538 if (count <= -120) count /= 120;
|
Chris@127
|
1539 else count = -1;
|
Chris@127
|
1540 }
|
Chris@127
|
1541
|
Chris@127
|
1542 if (e->modifiers() & Qt::ControlModifier) {
|
Chris@127
|
1543
|
Chris@127
|
1544 // Scroll left or right, rapidly
|
Chris@127
|
1545
|
Chris@127
|
1546 if (getStartFrame() < 0 &&
|
Chris@127
|
1547 getEndFrame() >= getModelsEndFrame()) return;
|
Chris@127
|
1548
|
Chris@127
|
1549 long delta = ((width() / 2) * count * m_zoomLevel);
|
Chris@127
|
1550
|
Chris@127
|
1551 if (int(m_centreFrame) < delta) {
|
Chris@127
|
1552 setCentreFrame(0);
|
Chris@127
|
1553 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
|
Chris@127
|
1554 setCentreFrame(getModelsEndFrame());
|
Chris@127
|
1555 } else {
|
Chris@127
|
1556 setCentreFrame(m_centreFrame - delta);
|
Chris@127
|
1557 }
|
Chris@127
|
1558
|
Chris@256
|
1559 } else if (e->modifiers() & Qt::ShiftModifier) {
|
Chris@256
|
1560
|
Chris@256
|
1561 // Zoom vertically
|
Chris@256
|
1562
|
Chris@256
|
1563 if (m_vpan) {
|
Chris@256
|
1564 m_vpan->scroll(e->delta() > 0);
|
Chris@256
|
1565 }
|
Chris@256
|
1566
|
Chris@256
|
1567 } else if (e->modifiers() & Qt::AltModifier) {
|
Chris@256
|
1568
|
Chris@256
|
1569 // Zoom vertically
|
Chris@256
|
1570
|
Chris@256
|
1571 if (m_vthumb) {
|
Chris@256
|
1572 m_vthumb->scroll(e->delta() > 0);
|
Chris@256
|
1573 }
|
Chris@256
|
1574
|
Chris@127
|
1575 } else {
|
Chris@127
|
1576
|
Chris@127
|
1577 // Zoom in or out
|
Chris@127
|
1578
|
Chris@127
|
1579 int newZoomLevel = m_zoomLevel;
|
Chris@127
|
1580
|
Chris@127
|
1581 while (count > 0) {
|
Chris@127
|
1582 if (newZoomLevel <= 2) {
|
Chris@127
|
1583 newZoomLevel = 1;
|
Chris@127
|
1584 break;
|
Chris@127
|
1585 }
|
Chris@127
|
1586 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
Chris@127
|
1587 ZoomConstraint::RoundDown);
|
Chris@127
|
1588 --count;
|
Chris@127
|
1589 }
|
Chris@127
|
1590
|
Chris@127
|
1591 while (count < 0) {
|
Chris@127
|
1592 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
Chris@127
|
1593 ZoomConstraint::RoundUp);
|
Chris@127
|
1594 ++count;
|
Chris@127
|
1595 }
|
Chris@127
|
1596
|
Chris@127
|
1597 if (newZoomLevel != m_zoomLevel) {
|
Chris@127
|
1598 setZoomLevel(newZoomLevel);
|
Chris@127
|
1599 }
|
Chris@127
|
1600 }
|
Chris@127
|
1601
|
Chris@127
|
1602 emit paneInteractedWith();
|
Chris@127
|
1603 }
|
Chris@127
|
1604
|
Chris@132
|
1605 void
|
Chris@132
|
1606 Pane::horizontalThumbwheelMoved(int value)
|
Chris@132
|
1607 {
|
Chris@137
|
1608 //!!! dupe with updateHeadsUpDisplay
|
Chris@137
|
1609
|
Chris@132
|
1610 int count = 0;
|
Chris@132
|
1611 int level = 1;
|
Chris@137
|
1612
|
Chris@137
|
1613
|
Chris@137
|
1614 //!!! pull out into function (presumably in View)
|
Chris@137
|
1615 bool haveConstraint = false;
|
Chris@137
|
1616 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
|
Chris@137
|
1617 ++i) {
|
Chris@137
|
1618 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
|
Chris@137
|
1619 haveConstraint = true;
|
Chris@137
|
1620 break;
|
Chris@137
|
1621 }
|
Chris@132
|
1622 }
|
Chris@132
|
1623
|
Chris@137
|
1624 if (haveConstraint) {
|
Chris@137
|
1625 while (true) {
|
Chris@137
|
1626 if (m_hthumb->getMaximumValue() - value == count) break;
|
Chris@137
|
1627 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@137
|
1628 ZoomConstraint::RoundUp);
|
Chris@137
|
1629 if (newLevel == level) break;
|
Chris@137
|
1630 level = newLevel;
|
Chris@137
|
1631 if (++count == 50) break;
|
Chris@137
|
1632 }
|
Chris@137
|
1633 } else {
|
Chris@137
|
1634 while (true) {
|
Chris@137
|
1635 if (m_hthumb->getMaximumValue() - value == count) break;
|
Chris@137
|
1636 int step = level / 10;
|
Chris@137
|
1637 int pwr = 0;
|
Chris@137
|
1638 while (step > 0) {
|
Chris@137
|
1639 ++pwr;
|
Chris@137
|
1640 step /= 2;
|
Chris@137
|
1641 }
|
Chris@137
|
1642 step = 1;
|
Chris@137
|
1643 while (pwr > 0) {
|
Chris@137
|
1644 step *= 2;
|
Chris@137
|
1645 --pwr;
|
Chris@137
|
1646 }
|
Chris@137
|
1647 // std::cerr << level << std::endl;
|
Chris@137
|
1648 level += step;
|
Chris@137
|
1649 if (++count == 100 || level > 262144) break;
|
Chris@137
|
1650 }
|
Chris@137
|
1651 }
|
Chris@137
|
1652
|
Chris@244
|
1653 // std::cerr << "new level is " << level << std::endl;
|
Chris@132
|
1654 setZoomLevel(level);
|
Chris@132
|
1655 }
|
Chris@132
|
1656
|
Chris@132
|
1657 void
|
Chris@132
|
1658 Pane::verticalThumbwheelMoved(int value)
|
Chris@132
|
1659 {
|
Chris@133
|
1660 Layer *layer = 0;
|
Chris@133
|
1661 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1662 if (layer) {
|
Chris@133
|
1663 int defaultStep = 0;
|
Chris@133
|
1664 int max = layer->getVerticalZoomSteps(defaultStep);
|
Chris@133
|
1665 if (max == 0) {
|
Chris@133
|
1666 updateHeadsUpDisplay();
|
Chris@133
|
1667 return;
|
Chris@133
|
1668 }
|
Chris@133
|
1669 if (value > max) {
|
Chris@133
|
1670 value = max;
|
Chris@133
|
1671 }
|
Chris@133
|
1672 layer->setVerticalZoomStep(value);
|
Chris@174
|
1673 updateVerticalPanner();
|
Chris@133
|
1674 }
|
Chris@132
|
1675 }
|
Chris@132
|
1676
|
Chris@174
|
1677 void
|
Chris@174
|
1678 Pane::verticalPannerMoved(float x0, float y0, float w, float h)
|
Chris@174
|
1679 {
|
Chris@174
|
1680 float vmin, vmax, dmin, dmax;
|
Chris@174
|
1681 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return;
|
Chris@174
|
1682 float y1 = y0 + h;
|
Chris@174
|
1683 float newmax = vmin + ((1.0 - y0) * (vmax - vmin));
|
Chris@174
|
1684 float newmin = vmin + ((1.0 - y1) * (vmax - vmin));
|
Chris@174
|
1685 std::cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w
|
Chris@174
|
1686 << "," << h << ") -> (" << newmin << "," << newmax << ")" << std::endl;
|
Chris@174
|
1687 setTopLayerDisplayExtents(newmin, newmax);
|
Chris@174
|
1688 }
|
Chris@174
|
1689
|
Chris@188
|
1690 void
|
Chris@188
|
1691 Pane::editVerticalPannerExtents()
|
Chris@188
|
1692 {
|
Chris@188
|
1693 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
|
Chris@188
|
1694
|
Chris@188
|
1695 float vmin, vmax, dmin, dmax;
|
Chris@188
|
1696 QString unit;
|
Chris@188
|
1697 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit)
|
Chris@188
|
1698 || vmax == vmin) {
|
Chris@188
|
1699 return;
|
Chris@188
|
1700 }
|
Chris@188
|
1701
|
Chris@188
|
1702 RangeInputDialog dialog(tr("Enter new range"),
|
Chris@188
|
1703 tr("New vertical display range, from %1 to %2 %4:")
|
Chris@188
|
1704 .arg(vmin).arg(vmax).arg(unit),
|
Chris@188
|
1705 unit, vmin, vmax, this);
|
Chris@188
|
1706 dialog.setRange(dmin, dmax);
|
Chris@188
|
1707
|
Chris@188
|
1708 if (dialog.exec() == QDialog::Accepted) {
|
Chris@188
|
1709 dialog.getRange(dmin, dmax);
|
Chris@188
|
1710 setTopLayerDisplayExtents(dmin, dmax);
|
Chris@188
|
1711 updateVerticalPanner();
|
Chris@188
|
1712 }
|
Chris@188
|
1713 }
|
Chris@188
|
1714
|
Chris@127
|
1715 bool
|
Chris@127
|
1716 Pane::editSelectionStart(QMouseEvent *e)
|
Chris@127
|
1717 {
|
Chris@127
|
1718 if (!m_identifyFeatures ||
|
Chris@127
|
1719 !m_manager ||
|
Chris@127
|
1720 m_manager->getToolMode() != ViewManager::EditMode) {
|
Chris@127
|
1721 return false;
|
Chris@127
|
1722 }
|
Chris@127
|
1723
|
Chris@127
|
1724 bool closeToLeft, closeToRight;
|
Chris@127
|
1725 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight));
|
Chris@127
|
1726 if (s.isEmpty()) return false;
|
Chris@127
|
1727 m_editingSelection = s;
|
Chris@127
|
1728 m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0);
|
Chris@127
|
1729 m_mousePos = e->pos();
|
Chris@127
|
1730 return true;
|
Chris@127
|
1731 }
|
Chris@127
|
1732
|
Chris@127
|
1733 bool
|
Chris@127
|
1734 Pane::editSelectionDrag(QMouseEvent *e)
|
Chris@127
|
1735 {
|
Chris@127
|
1736 if (m_editingSelection.isEmpty()) return false;
|
Chris@127
|
1737 m_mousePos = e->pos();
|
Chris@127
|
1738 update();
|
Chris@127
|
1739 return true;
|
Chris@127
|
1740 }
|
Chris@127
|
1741
|
Chris@127
|
1742 bool
|
Chris@248
|
1743 Pane::editSelectionEnd(QMouseEvent *)
|
Chris@127
|
1744 {
|
Chris@127
|
1745 if (m_editingSelection.isEmpty()) return false;
|
Chris@127
|
1746
|
Chris@127
|
1747 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@127
|
1748 Layer *layer = getSelectedLayer();
|
Chris@127
|
1749
|
Chris@127
|
1750 if (offset == 0 || !layer) {
|
Chris@127
|
1751 m_editingSelection = Selection();
|
Chris@127
|
1752 return true;
|
Chris@127
|
1753 }
|
Chris@127
|
1754
|
Chris@127
|
1755 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
|
Chris@127
|
1756 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@127
|
1757
|
Chris@127
|
1758 long f0 = getFrameForX(p0);
|
Chris@127
|
1759 long f1 = getFrameForX(p1);
|
Chris@127
|
1760
|
Chris@127
|
1761 Selection newSelection(f0, f1);
|
Chris@127
|
1762
|
Chris@127
|
1763 if (m_editingSelectionEdge == 0) {
|
Chris@127
|
1764
|
Chris@127
|
1765 CommandHistory::getInstance()->startCompoundOperation
|
Chris@127
|
1766 (tr("Drag Selection"), true);
|
Chris@127
|
1767
|
Chris@127
|
1768 layer->moveSelection(m_editingSelection, f0);
|
Chris@127
|
1769
|
Chris@127
|
1770 } else {
|
Chris@127
|
1771
|
Chris@127
|
1772 CommandHistory::getInstance()->startCompoundOperation
|
Chris@127
|
1773 (tr("Resize Selection"), true);
|
Chris@127
|
1774
|
Chris@127
|
1775 if (m_editingSelectionEdge < 0) {
|
Chris@127
|
1776 f1 = m_editingSelection.getEndFrame();
|
Chris@127
|
1777 } else {
|
Chris@127
|
1778 f0 = m_editingSelection.getStartFrame();
|
Chris@127
|
1779 }
|
Chris@127
|
1780
|
Chris@127
|
1781 newSelection = Selection(f0, f1);
|
Chris@127
|
1782 layer->resizeSelection(m_editingSelection, newSelection);
|
Chris@127
|
1783 }
|
Chris@127
|
1784
|
Chris@127
|
1785 m_manager->removeSelection(m_editingSelection);
|
Chris@127
|
1786 m_manager->addSelection(newSelection);
|
Chris@127
|
1787
|
Chris@127
|
1788 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@127
|
1789
|
Chris@127
|
1790 m_editingSelection = Selection();
|
Chris@127
|
1791 return true;
|
Chris@127
|
1792 }
|
Chris@127
|
1793
|
Chris@127
|
1794 void
|
Chris@127
|
1795 Pane::toolModeChanged()
|
Chris@127
|
1796 {
|
Chris@127
|
1797 ViewManager::ToolMode mode = m_manager->getToolMode();
|
Chris@127
|
1798 // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
|
Chris@127
|
1799
|
Chris@257
|
1800 static QCursor measureCursor;
|
Chris@257
|
1801 static bool measureCursorCreated = false;
|
Chris@257
|
1802
|
Chris@257
|
1803 if (!measureCursorCreated) {
|
Chris@257
|
1804 measureCursor = QCursor(QBitmap(":/icons/measure1cursor.xbm"),
|
Chris@257
|
1805 QBitmap(":/icons/measure1mask.xbm"),
|
Chris@257
|
1806 15, 14);
|
Chris@257
|
1807 measureCursorCreated = true;
|
Chris@257
|
1808 }
|
Chris@257
|
1809
|
Chris@127
|
1810 switch (mode) {
|
Chris@127
|
1811
|
Chris@127
|
1812 case ViewManager::NavigateMode:
|
Chris@127
|
1813 setCursor(Qt::PointingHandCursor);
|
Chris@127
|
1814 break;
|
Chris@127
|
1815
|
Chris@127
|
1816 case ViewManager::SelectMode:
|
Chris@127
|
1817 setCursor(Qt::ArrowCursor);
|
Chris@127
|
1818 break;
|
Chris@127
|
1819
|
Chris@127
|
1820 case ViewManager::EditMode:
|
Chris@127
|
1821 setCursor(Qt::UpArrowCursor);
|
Chris@127
|
1822 break;
|
Chris@127
|
1823
|
Chris@127
|
1824 case ViewManager::DrawMode:
|
Chris@127
|
1825 setCursor(Qt::CrossCursor);
|
Chris@127
|
1826 break;
|
Chris@257
|
1827
|
Chris@257
|
1828 case ViewManager::MeasureMode:
|
Chris@257
|
1829 setCursor(measureCursor);
|
Chris@257
|
1830 break;
|
Chris@257
|
1831
|
Chris@127
|
1832 /*
|
Chris@127
|
1833 case ViewManager::TextMode:
|
Chris@127
|
1834 setCursor(Qt::IBeamCursor);
|
Chris@127
|
1835 break;
|
Chris@127
|
1836 */
|
Chris@127
|
1837 }
|
Chris@127
|
1838 }
|
Chris@127
|
1839
|
Chris@133
|
1840 void
|
Chris@133
|
1841 Pane::zoomWheelsEnabledChanged()
|
Chris@133
|
1842 {
|
Chris@133
|
1843 updateHeadsUpDisplay();
|
Chris@133
|
1844 update();
|
Chris@133
|
1845 }
|
Chris@133
|
1846
|
Chris@133
|
1847 void
|
Chris@224
|
1848 Pane::viewZoomLevelChanged(View *v, unsigned long z, bool locked)
|
Chris@133
|
1849 {
|
Chris@212
|
1850 // std::cerr << "Pane[" << this << "]::zoomLevelChanged (global now "
|
Chris@212
|
1851 // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << std::endl;
|
Chris@192
|
1852
|
Chris@224
|
1853 View::viewZoomLevelChanged(v, z, locked);
|
Chris@224
|
1854
|
Chris@232
|
1855 if (m_hthumb && !m_hthumb->isVisible()) return;
|
Chris@224
|
1856
|
Chris@222
|
1857 if (v != this) {
|
Chris@222
|
1858 if (!locked || !m_followZoom) return;
|
Chris@222
|
1859 }
|
Chris@222
|
1860
|
Chris@133
|
1861 if (m_manager && m_manager->getZoomWheelsEnabled()) {
|
Chris@133
|
1862 updateHeadsUpDisplay();
|
Chris@133
|
1863 }
|
Chris@133
|
1864 }
|
Chris@133
|
1865
|
Chris@133
|
1866 void
|
Chris@133
|
1867 Pane::propertyContainerSelected(View *v, PropertyContainer *pc)
|
Chris@133
|
1868 {
|
Chris@133
|
1869 Layer *layer = 0;
|
Chris@133
|
1870
|
Chris@133
|
1871 if (getLayerCount() > 0) {
|
Chris@133
|
1872 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1873 disconnect(layer, SIGNAL(verticalZoomChanged()),
|
Chris@133
|
1874 this, SLOT(verticalZoomChanged()));
|
Chris@133
|
1875 }
|
Chris@133
|
1876
|
Chris@133
|
1877 View::propertyContainerSelected(v, pc);
|
Chris@133
|
1878 updateHeadsUpDisplay();
|
Chris@133
|
1879
|
Chris@187
|
1880 if (m_vthumb) {
|
Chris@187
|
1881 RangeMapper *rm = 0;
|
Chris@187
|
1882 if (layer) rm = layer->getNewVerticalZoomRangeMapper();
|
Chris@187
|
1883 if (rm) m_vthumb->setRangeMapper(rm);
|
Chris@187
|
1884 }
|
Chris@187
|
1885
|
Chris@133
|
1886 if (getLayerCount() > 0) {
|
Chris@133
|
1887 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1888 connect(layer, SIGNAL(verticalZoomChanged()),
|
Chris@133
|
1889 this, SLOT(verticalZoomChanged()));
|
Chris@133
|
1890 }
|
Chris@133
|
1891 }
|
Chris@133
|
1892
|
Chris@133
|
1893 void
|
Chris@133
|
1894 Pane::verticalZoomChanged()
|
Chris@133
|
1895 {
|
Chris@133
|
1896 Layer *layer = 0;
|
Chris@133
|
1897
|
Chris@133
|
1898 if (getLayerCount() > 0) {
|
Chris@133
|
1899
|
Chris@133
|
1900 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1901
|
Chris@133
|
1902 if (m_vthumb && m_vthumb->isVisible()) {
|
Chris@133
|
1903 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
|
Chris@133
|
1904 }
|
Chris@133
|
1905 }
|
Chris@133
|
1906 }
|
Chris@133
|
1907
|
Chris@189
|
1908 void
|
Chris@189
|
1909 Pane::updateContextHelp(const QPoint *pos)
|
Chris@189
|
1910 {
|
Chris@189
|
1911 QString help = "";
|
Chris@189
|
1912
|
Chris@189
|
1913 if (m_clickedInRange) {
|
Chris@189
|
1914 emit contextHelpChanged("");
|
Chris@189
|
1915 return;
|
Chris@189
|
1916 }
|
Chris@189
|
1917
|
Chris@189
|
1918 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@189
|
1919 if (m_manager) mode = m_manager->getToolMode();
|
Chris@189
|
1920
|
Chris@189
|
1921 bool editable = false;
|
Chris@189
|
1922 Layer *layer = getSelectedLayer();
|
Chris@189
|
1923 if (layer && layer->isLayerEditable()) {
|
Chris@189
|
1924 editable = true;
|
Chris@189
|
1925 }
|
Chris@189
|
1926
|
Chris@189
|
1927 if (mode == ViewManager::NavigateMode) {
|
Chris@189
|
1928
|
Chris@189
|
1929 help = tr("Click and drag to navigate");
|
Chris@189
|
1930
|
Chris@189
|
1931 } else if (mode == ViewManager::SelectMode) {
|
Chris@189
|
1932
|
Chris@217
|
1933 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
1934
|
Chris@189
|
1935 bool haveSelection = (m_manager && !m_manager->getSelections().empty());
|
Chris@189
|
1936
|
Chris@189
|
1937 if (haveSelection) {
|
Chris@189
|
1938 if (editable) {
|
Chris@189
|
1939 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
|
1940 } else {
|
Chris@189
|
1941 help = tr("Click and drag to select a range; hold Ctrl for multi-select; middle-click and drag to navigate");
|
Chris@189
|
1942 }
|
Chris@189
|
1943
|
Chris@189
|
1944 if (pos) {
|
Chris@189
|
1945 bool closeToLeft = false, closeToRight = false;
|
Chris@189
|
1946 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
|
Chris@189
|
1947 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@189
|
1948
|
Chris@189
|
1949 help = tr("Click and drag to move the selection boundary");
|
Chris@189
|
1950 }
|
Chris@189
|
1951 }
|
Chris@189
|
1952 } else {
|
Chris@189
|
1953 if (editable) {
|
Chris@189
|
1954 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; middle-click to navigate");
|
Chris@189
|
1955 } else {
|
Chris@189
|
1956 help = tr("Click and drag to select a range; middle-click and drag to navigate");
|
Chris@189
|
1957 }
|
Chris@189
|
1958 }
|
Chris@189
|
1959
|
Chris@189
|
1960 } else if (mode == ViewManager::DrawMode) {
|
Chris@189
|
1961
|
Chris@189
|
1962 //!!! could call through to a layer function to find out exact meaning
|
Chris@189
|
1963 if (editable) {
|
Chris@189
|
1964 help = tr("Click to add a new item in the active layer");
|
Chris@189
|
1965 }
|
Chris@189
|
1966
|
Chris@189
|
1967 } else if (mode == ViewManager::EditMode) {
|
Chris@189
|
1968
|
Chris@189
|
1969 //!!! could call through to layer
|
Chris@189
|
1970 if (editable) {
|
Chris@189
|
1971 help = tr("Click and drag an item in the active layer to move it");
|
Chris@189
|
1972 if (pos) {
|
Chris@189
|
1973 bool closeToLeft = false, closeToRight = false;
|
Chris@189
|
1974 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
|
Chris@189
|
1975 if (!selection.isEmpty()) {
|
Chris@189
|
1976 help = tr("Click and drag to move all items in the selected range");
|
Chris@189
|
1977 }
|
Chris@189
|
1978 }
|
Chris@189
|
1979 }
|
Chris@189
|
1980 }
|
Chris@189
|
1981
|
Chris@189
|
1982 emit contextHelpChanged(help);
|
Chris@189
|
1983 }
|
Chris@189
|
1984
|
Chris@189
|
1985 void
|
Chris@189
|
1986 Pane::mouseEnteredWidget()
|
Chris@189
|
1987 {
|
Chris@189
|
1988 QWidget *w = dynamic_cast<QWidget *>(sender());
|
Chris@189
|
1989 if (!w) return;
|
Chris@189
|
1990
|
Chris@189
|
1991 if (w == m_vpan) {
|
Chris@189
|
1992 emit contextHelpChanged(tr("Click and drag to adjust the visible range of the vertical scale"));
|
Chris@189
|
1993 } else if (w == m_vthumb) {
|
Chris@189
|
1994 emit contextHelpChanged(tr("Click and drag to adjust the vertical zoom level"));
|
Chris@189
|
1995 } else if (w == m_hthumb) {
|
Chris@189
|
1996 emit contextHelpChanged(tr("Click and drag to adjust the horizontal zoom level"));
|
Chris@189
|
1997 } else if (w == m_reset) {
|
Chris@189
|
1998 emit contextHelpChanged(tr("Reset horizontal and vertical zoom levels to their defaults"));
|
Chris@189
|
1999 }
|
Chris@189
|
2000 }
|
Chris@189
|
2001
|
Chris@189
|
2002 void
|
Chris@189
|
2003 Pane::mouseLeftWidget()
|
Chris@189
|
2004 {
|
Chris@189
|
2005 emit contextHelpChanged("");
|
Chris@189
|
2006 }
|
Chris@189
|
2007
|
Chris@127
|
2008 QString
|
Chris@127
|
2009 Pane::toXmlString(QString indent, QString extraAttributes) const
|
Chris@127
|
2010 {
|
Chris@127
|
2011 return View::toXmlString
|
Chris@127
|
2012 (indent,
|
Chris@127
|
2013 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3")
|
Chris@127
|
2014 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes));
|
Chris@127
|
2015 }
|
Chris@127
|
2016
|
Chris@127
|
2017
|