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@127
|
28 #include <iostream>
|
Chris@127
|
29 #include <cmath>
|
Chris@127
|
30
|
Chris@133
|
31 //!!! for HUD -- pull out into a separate class
|
Chris@133
|
32 #include <QFrame>
|
Chris@133
|
33 #include <QGridLayout>
|
Chris@133
|
34 #include <QPushButton>
|
Chris@133
|
35 #include "widgets/Thumbwheel.h"
|
Chris@172
|
36 #include "widgets/Panner.h"
|
Chris@133
|
37
|
Chris@127
|
38 using std::cerr;
|
Chris@127
|
39 using std::endl;
|
Chris@127
|
40
|
Chris@127
|
41 Pane::Pane(QWidget *w) :
|
Chris@127
|
42 View(w, true),
|
Chris@127
|
43 m_identifyFeatures(false),
|
Chris@127
|
44 m_clickedInRange(false),
|
Chris@127
|
45 m_shiftPressed(false),
|
Chris@127
|
46 m_ctrlPressed(false),
|
Chris@127
|
47 m_navigating(false),
|
Chris@127
|
48 m_resizing(false),
|
Chris@133
|
49 m_centreLineVisible(true),
|
Chris@133
|
50 m_headsUpDisplay(0)
|
Chris@127
|
51 {
|
Chris@127
|
52 setObjectName("Pane");
|
Chris@127
|
53 setMouseTracking(true);
|
Chris@133
|
54
|
Chris@133
|
55 updateHeadsUpDisplay();
|
Chris@133
|
56 }
|
Chris@133
|
57
|
Chris@133
|
58 void
|
Chris@133
|
59 Pane::updateHeadsUpDisplay()
|
Chris@133
|
60 {
|
Chris@187
|
61 Profiler profiler("Pane::updateHeadsUpDisplay", true);
|
Chris@187
|
62
|
Chris@132
|
63 /*
|
Chris@132
|
64 int count = 0;
|
Chris@132
|
65 int currentLevel = 1;
|
Chris@132
|
66 int level = 1;
|
Chris@132
|
67 while (true) {
|
Chris@132
|
68 if (getZoomLevel() == level) currentLevel = count;
|
Chris@132
|
69 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@132
|
70 ZoomConstraint::RoundUp);
|
Chris@132
|
71 if (newLevel == level) break;
|
Chris@132
|
72 if (newLevel == 131072) break; //!!! just because
|
Chris@132
|
73 level = newLevel;
|
Chris@132
|
74 ++count;
|
Chris@132
|
75 }
|
Chris@132
|
76
|
Chris@132
|
77 std::cerr << "Have " << count+1 << " zoom levels" << std::endl;
|
Chris@132
|
78 */
|
Chris@133
|
79
|
Chris@133
|
80 if (!m_headsUpDisplay) {
|
Chris@133
|
81
|
Chris@133
|
82 m_headsUpDisplay = new QFrame(this);
|
Chris@133
|
83
|
Chris@133
|
84 QGridLayout *layout = new QGridLayout;
|
Chris@133
|
85 layout->setMargin(0);
|
Chris@133
|
86 layout->setSpacing(0);
|
Chris@133
|
87 m_headsUpDisplay->setLayout(layout);
|
Chris@133
|
88
|
Chris@133
|
89 m_hthumb = new Thumbwheel(Qt::Horizontal);
|
Chris@187
|
90 m_hthumb->setObjectName(tr("Horizontal Zoom"));
|
Chris@173
|
91 layout->addWidget(m_hthumb, 1, 0, 1, 2);
|
Chris@133
|
92 m_hthumb->setFixedWidth(70);
|
Chris@133
|
93 m_hthumb->setFixedHeight(16);
|
Chris@133
|
94 m_hthumb->setDefaultValue(0);
|
Chris@165
|
95 m_hthumb->setSpeed(0.6);
|
Chris@133
|
96 connect(m_hthumb, SIGNAL(valueChanged(int)), this,
|
Chris@133
|
97 SLOT(horizontalThumbwheelMoved(int)));
|
Chris@172
|
98
|
Chris@172
|
99 m_vpan = new Panner;
|
Chris@172
|
100 layout->addWidget(m_vpan, 0, 1);
|
Chris@173
|
101 m_vpan->setFixedWidth(12);
|
Chris@172
|
102 m_vpan->setFixedHeight(70);
|
Chris@174
|
103 m_vpan->setAlpha(80, 130);
|
Chris@174
|
104 connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)),
|
Chris@174
|
105 this, SLOT(verticalPannerMoved(float, float, float, float)));
|
Chris@172
|
106
|
Chris@133
|
107 m_vthumb = new Thumbwheel(Qt::Vertical);
|
Chris@187
|
108 m_vthumb->setObjectName(tr("Vertical Zoom"));
|
Chris@172
|
109 layout->addWidget(m_vthumb, 0, 2);
|
Chris@133
|
110 m_vthumb->setFixedWidth(16);
|
Chris@133
|
111 m_vthumb->setFixedHeight(70);
|
Chris@133
|
112 connect(m_vthumb, SIGNAL(valueChanged(int)), this,
|
Chris@133
|
113 SLOT(verticalThumbwheelMoved(int)));
|
Chris@133
|
114
|
Chris@133
|
115 QPushButton *reset = new QPushButton;
|
Chris@133
|
116 reset->setFixedHeight(16);
|
Chris@133
|
117 reset->setFixedWidth(16);
|
Chris@172
|
118 layout->addWidget(reset, 1, 2);
|
Chris@133
|
119 connect(reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault()));
|
Chris@133
|
120 connect(reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault()));
|
Chris@133
|
121 }
|
Chris@133
|
122
|
Chris@133
|
123 int count = 0;
|
Chris@133
|
124 int current = 0;
|
Chris@133
|
125 int level = 1;
|
Chris@133
|
126
|
Chris@137
|
127 //!!! pull out into function (presumably in View)
|
Chris@137
|
128 bool haveConstraint = false;
|
Chris@137
|
129 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
|
Chris@137
|
130 ++i) {
|
Chris@137
|
131 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
|
Chris@137
|
132 haveConstraint = true;
|
Chris@137
|
133 break;
|
Chris@137
|
134 }
|
Chris@137
|
135 }
|
Chris@137
|
136
|
Chris@137
|
137 if (haveConstraint) {
|
Chris@137
|
138 while (true) {
|
Chris@137
|
139 if (getZoomLevel() == level) current = count;
|
Chris@137
|
140 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@137
|
141 ZoomConstraint::RoundUp);
|
Chris@137
|
142 if (newLevel == level) break;
|
Chris@137
|
143 level = newLevel;
|
Chris@137
|
144 if (++count == 50) break;
|
Chris@137
|
145 }
|
Chris@137
|
146 } else {
|
Chris@137
|
147 // if we have no particular constraints, we can really spread out
|
Chris@137
|
148 while (true) {
|
Chris@137
|
149 if (getZoomLevel() >= level) current = count;
|
Chris@137
|
150 int step = level / 10;
|
Chris@137
|
151 int pwr = 0;
|
Chris@137
|
152 while (step > 0) {
|
Chris@137
|
153 ++pwr;
|
Chris@137
|
154 step /= 2;
|
Chris@137
|
155 }
|
Chris@137
|
156 step = 1;
|
Chris@137
|
157 while (pwr > 0) {
|
Chris@137
|
158 step *= 2;
|
Chris@137
|
159 --pwr;
|
Chris@137
|
160 }
|
Chris@154
|
161 // std::cerr << level << std::endl;
|
Chris@137
|
162 level += step;
|
Chris@137
|
163 if (++count == 100 || level > 262144) break;
|
Chris@137
|
164 }
|
Chris@133
|
165 }
|
Chris@133
|
166
|
Chris@133
|
167 // std::cerr << "Have " << count << " zoom levels" << std::endl;
|
Chris@133
|
168
|
Chris@133
|
169 m_hthumb->setMinimumValue(0);
|
Chris@133
|
170 m_hthumb->setMaximumValue(count);
|
Chris@133
|
171 m_hthumb->setValue(count - current);
|
Chris@133
|
172
|
Chris@133
|
173 // std::cerr << "set value to " << count-current << std::endl;
|
Chris@133
|
174
|
Chris@133
|
175 // std::cerr << "default value is " << m_hthumb->getDefaultValue() << std::endl;
|
Chris@133
|
176
|
Chris@133
|
177 if (count != 50 && m_hthumb->getDefaultValue() == 0) {
|
Chris@133
|
178 m_hthumb->setDefaultValue(count - current);
|
Chris@133
|
179 // std::cerr << "set default value to " << m_hthumb->getDefaultValue() << std::endl;
|
Chris@133
|
180 }
|
Chris@133
|
181
|
Chris@133
|
182 Layer *layer = 0;
|
Chris@133
|
183 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
184 if (layer) {
|
Chris@133
|
185 int defaultStep = 0;
|
Chris@133
|
186 int max = layer->getVerticalZoomSteps(defaultStep);
|
Chris@133
|
187 if (max == 0) {
|
Chris@133
|
188 m_vthumb->hide();
|
Chris@133
|
189 } else {
|
Chris@133
|
190 m_vthumb->show();
|
Chris@187
|
191 m_vthumb->blockSignals(true);
|
Chris@133
|
192 m_vthumb->setMinimumValue(0);
|
Chris@133
|
193 m_vthumb->setMaximumValue(max);
|
Chris@133
|
194 m_vthumb->setDefaultValue(defaultStep);
|
Chris@133
|
195 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
|
Chris@187
|
196 m_vthumb->blockSignals(false);
|
Chris@135
|
197
|
Chris@135
|
198 std::cerr << "Vertical thumbwheel: min 0, max " << max
|
Chris@135
|
199 << ", default " << defaultStep << ", value "
|
Chris@135
|
200 << m_vthumb->getValue() << std::endl;
|
Chris@135
|
201
|
Chris@133
|
202 }
|
Chris@133
|
203 }
|
Chris@133
|
204
|
Chris@174
|
205 updateVerticalPanner();
|
Chris@174
|
206
|
Chris@133
|
207 if (m_manager && m_manager->getZoomWheelsEnabled() &&
|
Chris@133
|
208 width() > 120 && height() > 100) {
|
Chris@165
|
209 if (!m_headsUpDisplay->isVisible()) {
|
Chris@165
|
210 m_headsUpDisplay->show();
|
Chris@165
|
211 connect(m_manager, SIGNAL(zoomLevelChanged()),
|
Chris@165
|
212 this, SLOT(zoomLevelChanged()));
|
Chris@165
|
213 }
|
Chris@133
|
214 if (m_vthumb->isVisible()) {
|
Chris@133
|
215 m_headsUpDisplay->move(width() - 86, height() - 86);
|
Chris@133
|
216 } else {
|
Chris@133
|
217 m_headsUpDisplay->move(width() - 86, height() - 51);
|
Chris@133
|
218 }
|
Chris@133
|
219 } else {
|
Chris@133
|
220 m_headsUpDisplay->hide();
|
Chris@133
|
221 if (m_manager) {
|
Chris@133
|
222 disconnect(m_manager, SIGNAL(zoomLevelChanged()),
|
Chris@133
|
223 this, SLOT(zoomLevelChanged()));
|
Chris@133
|
224 }
|
Chris@133
|
225 }
|
Chris@127
|
226 }
|
Chris@127
|
227
|
Chris@174
|
228 void
|
Chris@174
|
229 Pane::updateVerticalPanner()
|
Chris@174
|
230 {
|
Chris@174
|
231 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
|
Chris@174
|
232
|
Chris@174
|
233 float vmin, vmax, dmin, dmax;
|
Chris@174
|
234 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) {
|
Chris@174
|
235 float y0 = (dmin - vmin) / (vmax - vmin);
|
Chris@174
|
236 float y1 = (dmax - vmin) / (vmax - vmin);
|
Chris@174
|
237 m_vpan->blockSignals(true);
|
Chris@174
|
238 m_vpan->setRectExtents(0, 1.0 - y1, 1, y1 - y0);
|
Chris@174
|
239 m_vpan->blockSignals(false);
|
Chris@174
|
240 m_vpan->show();
|
Chris@174
|
241 } else {
|
Chris@174
|
242 m_vpan->hide();
|
Chris@174
|
243 }
|
Chris@174
|
244 }
|
Chris@174
|
245
|
Chris@127
|
246 bool
|
Chris@127
|
247 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
|
Chris@127
|
248 {
|
Chris@127
|
249 QPoint discard;
|
Chris@127
|
250 bool b0, b1;
|
Chris@127
|
251
|
Chris@127
|
252 if (layer == getSelectedLayer() &&
|
Chris@127
|
253 !shouldIlluminateLocalSelection(discard, b0, b1)) {
|
Chris@127
|
254
|
Chris@127
|
255 pos = m_identifyPoint;
|
Chris@127
|
256 return m_identifyFeatures;
|
Chris@127
|
257 }
|
Chris@127
|
258
|
Chris@127
|
259 return false;
|
Chris@127
|
260 }
|
Chris@127
|
261
|
Chris@127
|
262 bool
|
Chris@127
|
263 Pane::shouldIlluminateLocalSelection(QPoint &pos,
|
Chris@127
|
264 bool &closeToLeft,
|
Chris@127
|
265 bool &closeToRight) const
|
Chris@127
|
266 {
|
Chris@127
|
267 if (m_identifyFeatures &&
|
Chris@127
|
268 m_manager &&
|
Chris@127
|
269 m_manager->getToolMode() == ViewManager::EditMode &&
|
Chris@127
|
270 !m_manager->getSelections().empty() &&
|
Chris@127
|
271 !selectionIsBeingEdited()) {
|
Chris@127
|
272
|
Chris@127
|
273 Selection s(getSelectionAt(m_identifyPoint.x(),
|
Chris@127
|
274 closeToLeft, closeToRight));
|
Chris@127
|
275
|
Chris@127
|
276 if (!s.isEmpty()) {
|
Chris@127
|
277 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
|
Chris@127
|
278
|
Chris@127
|
279 pos = m_identifyPoint;
|
Chris@127
|
280 return true;
|
Chris@127
|
281 }
|
Chris@127
|
282 }
|
Chris@127
|
283 }
|
Chris@127
|
284
|
Chris@127
|
285 return false;
|
Chris@127
|
286 }
|
Chris@127
|
287
|
Chris@127
|
288 bool
|
Chris@127
|
289 Pane::selectionIsBeingEdited() const
|
Chris@127
|
290 {
|
Chris@127
|
291 if (!m_editingSelection.isEmpty()) {
|
Chris@127
|
292 if (m_mousePos != m_clickPos &&
|
Chris@127
|
293 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) {
|
Chris@127
|
294 return true;
|
Chris@127
|
295 }
|
Chris@127
|
296 }
|
Chris@127
|
297 return false;
|
Chris@127
|
298 }
|
Chris@127
|
299
|
Chris@127
|
300 void
|
Chris@127
|
301 Pane::setCentreLineVisible(bool visible)
|
Chris@127
|
302 {
|
Chris@127
|
303 m_centreLineVisible = visible;
|
Chris@127
|
304 update();
|
Chris@127
|
305 }
|
Chris@127
|
306
|
Chris@127
|
307 void
|
Chris@127
|
308 Pane::paintEvent(QPaintEvent *e)
|
Chris@127
|
309 {
|
Chris@127
|
310 // Profiler profiler("Pane::paintEvent", true);
|
Chris@127
|
311
|
Chris@127
|
312 QPainter paint;
|
Chris@127
|
313
|
Chris@127
|
314 QRect r(rect());
|
Chris@127
|
315
|
Chris@127
|
316 if (e) {
|
Chris@127
|
317 r = e->rect();
|
Chris@127
|
318 }
|
Chris@127
|
319 /*
|
Chris@127
|
320 paint.begin(this);
|
Chris@127
|
321 paint.setClipRect(r);
|
Chris@127
|
322
|
Chris@127
|
323 if (hasLightBackground()) {
|
Chris@127
|
324 paint.setPen(Qt::white);
|
Chris@127
|
325 paint.setBrush(Qt::white);
|
Chris@127
|
326 } else {
|
Chris@127
|
327 paint.setPen(Qt::black);
|
Chris@127
|
328 paint.setBrush(Qt::black);
|
Chris@127
|
329 }
|
Chris@127
|
330 paint.drawRect(r);
|
Chris@127
|
331
|
Chris@127
|
332 paint.end();
|
Chris@127
|
333 */
|
Chris@127
|
334 View::paintEvent(e);
|
Chris@127
|
335
|
Chris@127
|
336 paint.begin(this);
|
Chris@127
|
337
|
Chris@127
|
338 if (e) {
|
Chris@127
|
339 paint.setClipRect(r);
|
Chris@127
|
340 }
|
Chris@127
|
341
|
Chris@127
|
342 const Model *waveformModel = 0; // just for reporting purposes
|
Chris@127
|
343 int verticalScaleWidth = 0;
|
Chris@127
|
344
|
Chris@127
|
345 int fontHeight = paint.fontMetrics().height();
|
Chris@127
|
346 int fontAscent = paint.fontMetrics().ascent();
|
Chris@127
|
347
|
Chris@127
|
348 if (m_manager &&
|
Chris@127
|
349 !m_manager->isPlaying() &&
|
Chris@127
|
350 m_manager->getToolMode() == ViewManager::SelectMode) {
|
Chris@127
|
351
|
Chris@127
|
352 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@127
|
353 --vi;
|
Chris@127
|
354
|
Chris@127
|
355 std::vector<QRect> crosshairExtents;
|
Chris@127
|
356
|
Chris@127
|
357 if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint,
|
Chris@127
|
358 crosshairExtents)) {
|
Chris@127
|
359 (*vi)->paintCrosshairs(this, paint, m_identifyPoint);
|
Chris@127
|
360 break;
|
Chris@127
|
361 } else if ((*vi)->isLayerOpaque()) {
|
Chris@127
|
362 break;
|
Chris@127
|
363 }
|
Chris@127
|
364 }
|
Chris@127
|
365 }
|
Chris@127
|
366
|
Chris@127
|
367 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@127
|
368 --vi;
|
Chris@127
|
369
|
Chris@127
|
370 if (dynamic_cast<WaveformLayer *>(*vi)) {
|
Chris@127
|
371 waveformModel = (*vi)->getModel();
|
Chris@127
|
372 }
|
Chris@127
|
373
|
Chris@127
|
374 if (!m_manager ||
|
Chris@127
|
375 m_manager->getOverlayMode() == ViewManager::NoOverlays) {
|
Chris@127
|
376 break;
|
Chris@127
|
377 }
|
Chris@127
|
378
|
Chris@127
|
379 verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint);
|
Chris@127
|
380
|
Chris@127
|
381 if (verticalScaleWidth > 0 && r.left() < verticalScaleWidth) {
|
Chris@127
|
382
|
Chris@127
|
383 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
|
Chris@127
|
384
|
Chris@127
|
385 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
|
Chris@127
|
386 paint.save();
|
Chris@127
|
387
|
Chris@127
|
388 paint.setPen(Qt::black);
|
Chris@127
|
389 paint.setBrush(Qt::white);
|
Chris@127
|
390 paint.drawRect(0, -1, verticalScaleWidth, height()+1);
|
Chris@127
|
391
|
Chris@127
|
392 paint.setBrush(Qt::NoBrush);
|
Chris@127
|
393 (*vi)->paintVerticalScale
|
Chris@127
|
394 (this, paint, QRect(0, 0, verticalScaleWidth, height()));
|
Chris@127
|
395
|
Chris@127
|
396 paint.restore();
|
Chris@127
|
397 }
|
Chris@127
|
398
|
Chris@127
|
399 if (m_identifyFeatures) {
|
Chris@127
|
400
|
Chris@127
|
401 QPoint pos = m_identifyPoint;
|
Chris@127
|
402 QString desc = (*vi)->getFeatureDescription(this, pos);
|
Chris@127
|
403
|
Chris@127
|
404 if (desc != "") {
|
Chris@127
|
405
|
Chris@127
|
406 paint.save();
|
Chris@127
|
407
|
Chris@127
|
408 int tabStop =
|
Chris@127
|
409 paint.fontMetrics().width(tr("Some lengthy prefix:"));
|
Chris@127
|
410
|
Chris@127
|
411 QRect boundingRect =
|
Chris@127
|
412 paint.fontMetrics().boundingRect
|
Chris@127
|
413 (rect(),
|
Chris@127
|
414 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
|
Chris@127
|
415 desc, tabStop);
|
Chris@127
|
416
|
Chris@127
|
417 if (hasLightBackground()) {
|
Chris@127
|
418 paint.setPen(Qt::NoPen);
|
Chris@127
|
419 paint.setBrush(QColor(250, 250, 250, 200));
|
Chris@127
|
420 } else {
|
Chris@127
|
421 paint.setPen(Qt::NoPen);
|
Chris@127
|
422 paint.setBrush(QColor(50, 50, 50, 200));
|
Chris@127
|
423 }
|
Chris@127
|
424
|
Chris@127
|
425 int extra = paint.fontMetrics().descent();
|
Chris@127
|
426 paint.drawRect(width() - boundingRect.width() - 10 - extra,
|
Chris@127
|
427 10 - extra,
|
Chris@127
|
428 boundingRect.width() + 2 * extra,
|
Chris@127
|
429 boundingRect.height() + extra);
|
Chris@127
|
430
|
Chris@127
|
431 if (hasLightBackground()) {
|
Chris@127
|
432 paint.setPen(QColor(150, 20, 0));
|
Chris@127
|
433 } else {
|
Chris@127
|
434 paint.setPen(QColor(255, 150, 100));
|
Chris@127
|
435 }
|
Chris@127
|
436
|
Chris@127
|
437 QTextOption option;
|
Chris@127
|
438 option.setWrapMode(QTextOption::NoWrap);
|
Chris@127
|
439 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
|
Chris@127
|
440 option.setTabStop(tabStop);
|
Chris@127
|
441 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
|
Chris@127
|
442 boundingRect.width(),
|
Chris@127
|
443 boundingRect.height()),
|
Chris@127
|
444 desc,
|
Chris@127
|
445 option);
|
Chris@127
|
446
|
Chris@127
|
447 paint.restore();
|
Chris@127
|
448 }
|
Chris@127
|
449 }
|
Chris@127
|
450
|
Chris@127
|
451 break;
|
Chris@127
|
452 }
|
Chris@127
|
453
|
Chris@127
|
454 int sampleRate = getModelsSampleRate();
|
Chris@127
|
455 paint.setBrush(Qt::NoBrush);
|
Chris@127
|
456
|
Chris@127
|
457 if (m_centreLineVisible) {
|
Chris@127
|
458
|
Chris@127
|
459 if (hasLightBackground()) {
|
Chris@127
|
460 paint.setPen(QColor(50, 50, 50));
|
Chris@127
|
461 } else {
|
Chris@127
|
462 paint.setPen(QColor(200, 200, 200));
|
Chris@127
|
463 }
|
Chris@127
|
464 paint.drawLine(width() / 2, 0, width() / 2, height() - 1);
|
Chris@127
|
465
|
Chris@127
|
466 paint.setPen(QColor(50, 50, 50));
|
Chris@127
|
467
|
Chris@127
|
468 int y = height() - fontHeight
|
Chris@127
|
469 + fontAscent - 6;
|
Chris@127
|
470
|
Chris@127
|
471 LayerList::iterator vi = m_layers.end();
|
Chris@127
|
472
|
Chris@127
|
473 if (vi != m_layers.begin()) {
|
Chris@127
|
474
|
Chris@127
|
475 switch ((*--vi)->getPreferredFrameCountPosition()) {
|
Chris@127
|
476
|
Chris@127
|
477 case Layer::PositionTop:
|
Chris@127
|
478 y = fontAscent + 6;
|
Chris@127
|
479 break;
|
Chris@127
|
480
|
Chris@127
|
481 case Layer::PositionMiddle:
|
Chris@127
|
482 y = (height() - fontHeight) / 2
|
Chris@127
|
483 + fontAscent;
|
Chris@127
|
484 break;
|
Chris@127
|
485
|
Chris@127
|
486 case Layer::PositionBottom:
|
Chris@127
|
487 // y already set correctly
|
Chris@127
|
488 break;
|
Chris@127
|
489 }
|
Chris@127
|
490 }
|
Chris@127
|
491
|
Chris@127
|
492 if (m_manager &&
|
Chris@127
|
493 m_manager->getOverlayMode() != ViewManager::NoOverlays) {
|
Chris@127
|
494
|
Chris@127
|
495 if (sampleRate) {
|
Chris@127
|
496
|
Chris@127
|
497 QString text(QString::fromStdString
|
Chris@127
|
498 (RealTime::frame2RealTime
|
Chris@127
|
499 (m_centreFrame, sampleRate).toText(true)));
|
Chris@127
|
500
|
Chris@127
|
501 int tw = paint.fontMetrics().width(text);
|
Chris@127
|
502 int x = width()/2 - 4 - tw;
|
Chris@127
|
503
|
Chris@127
|
504 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@127
|
505 }
|
Chris@127
|
506
|
Chris@127
|
507 QString text = QString("%1").arg(m_centreFrame);
|
Chris@127
|
508
|
Chris@127
|
509 int tw = paint.fontMetrics().width(text);
|
Chris@127
|
510 int x = width()/2 + 4;
|
Chris@127
|
511
|
Chris@127
|
512 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@127
|
513 }
|
Chris@127
|
514
|
Chris@127
|
515 } else {
|
Chris@127
|
516
|
Chris@127
|
517 paint.setPen(QColor(50, 50, 50));
|
Chris@127
|
518 }
|
Chris@127
|
519
|
Chris@127
|
520 if (waveformModel &&
|
Chris@127
|
521 m_manager &&
|
Chris@127
|
522 m_manager->getOverlayMode() != ViewManager::NoOverlays &&
|
Chris@127
|
523 r.y() + r.height() >= height() - fontHeight - 6) {
|
Chris@127
|
524
|
Chris@150
|
525 size_t modelRate = waveformModel->getSampleRate();
|
Chris@127
|
526 size_t mainModelRate = m_manager->getMainModelSampleRate();
|
Chris@127
|
527 size_t playbackRate = m_manager->getPlaybackSampleRate();
|
Chris@127
|
528
|
Chris@127
|
529 QString srNote = "";
|
Chris@127
|
530
|
Chris@127
|
531 // Show (R) for waveform models that will be resampled on
|
Chris@127
|
532 // playback, and (X) for waveform models that will be played
|
Chris@127
|
533 // at the wrong rate because their rate differs from that of
|
Chris@127
|
534 // the main model.
|
Chris@127
|
535
|
Chris@150
|
536 if (modelRate == mainModelRate) {
|
Chris@150
|
537 if (modelRate != playbackRate) srNote = " " + tr("(R)");
|
Chris@127
|
538 } else {
|
Chris@150
|
539 // std::cerr << "Sample rate = " << modelRate << ", main model rate = " << mainModelRate << std::endl;
|
Chris@127
|
540 srNote = " " + tr("(X)");
|
Chris@127
|
541 }
|
Chris@127
|
542
|
Chris@127
|
543 QString desc = tr("%1 / %2Hz%3")
|
Chris@127
|
544 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
|
Chris@127
|
545 sampleRate)
|
Chris@127
|
546 .toText(false).c_str())
|
Chris@150
|
547 .arg(modelRate)
|
Chris@127
|
548 .arg(srNote);
|
Chris@127
|
549
|
Chris@127
|
550 if (r.x() < verticalScaleWidth + 5 + paint.fontMetrics().width(desc)) {
|
Chris@127
|
551 drawVisibleText(paint, verticalScaleWidth + 5,
|
Chris@127
|
552 height() - fontHeight + fontAscent - 6,
|
Chris@127
|
553 desc, OutlinedText);
|
Chris@127
|
554 }
|
Chris@127
|
555 }
|
Chris@127
|
556
|
Chris@127
|
557 if (m_manager &&
|
Chris@127
|
558 m_manager->getOverlayMode() == ViewManager::AllOverlays &&
|
Chris@127
|
559 r.y() + r.height() >= height() - m_layers.size() * fontHeight - 6) {
|
Chris@127
|
560
|
Chris@127
|
561 std::vector<QString> texts;
|
Chris@127
|
562 int maxTextWidth = 0;
|
Chris@127
|
563
|
Chris@127
|
564 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@127
|
565
|
Chris@127
|
566 QString text = (*i)->getLayerPresentationName();
|
Chris@127
|
567 int tw = paint.fontMetrics().width(text);
|
Chris@127
|
568 bool reduced = false;
|
Chris@127
|
569 while (tw > width() / 3 && text.length() > 4) {
|
Chris@127
|
570 if (!reduced && text.length() > 8) {
|
Chris@127
|
571 text = text.left(text.length() - 4);
|
Chris@127
|
572 } else {
|
Chris@127
|
573 text = text.left(text.length() - 2);
|
Chris@127
|
574 }
|
Chris@127
|
575 reduced = true;
|
Chris@127
|
576 tw = paint.fontMetrics().width(text + "...");
|
Chris@127
|
577 }
|
Chris@127
|
578 if (reduced) {
|
Chris@127
|
579 texts.push_back(text + "...");
|
Chris@127
|
580 } else {
|
Chris@127
|
581 texts.push_back(text);
|
Chris@127
|
582 }
|
Chris@127
|
583 if (tw > maxTextWidth) maxTextWidth = tw;
|
Chris@127
|
584 }
|
Chris@127
|
585
|
Chris@127
|
586 int lly = height() - 6;
|
Chris@133
|
587 int llx = width() - maxTextWidth - 5;
|
Chris@127
|
588
|
Chris@133
|
589 if (m_manager->getZoomWheelsEnabled()) {
|
Chris@133
|
590 lly -= 20;
|
Chris@173
|
591 llx -= 36;
|
Chris@133
|
592 }
|
Chris@133
|
593
|
Chris@133
|
594 if (r.x() + r.width() >= llx) {
|
Chris@127
|
595
|
Chris@127
|
596 for (int i = 0; i < texts.size(); ++i) {
|
Chris@127
|
597
|
Chris@127
|
598 if (i == texts.size() - 1) {
|
Chris@127
|
599 paint.setPen(Qt::black);
|
Chris@127
|
600 }
|
Chris@127
|
601
|
Chris@133
|
602 drawVisibleText(paint, llx,
|
Chris@127
|
603 lly - fontHeight + fontAscent,
|
Chris@127
|
604 texts[i], OutlinedText);
|
Chris@127
|
605
|
Chris@127
|
606 lly -= fontHeight;
|
Chris@127
|
607 }
|
Chris@127
|
608 }
|
Chris@127
|
609 }
|
Chris@127
|
610
|
Chris@127
|
611 if (m_clickedInRange && m_shiftPressed) {
|
Chris@127
|
612 if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) {
|
Chris@127
|
613 //!!! be nice if this looked a bit more in keeping with the
|
Chris@127
|
614 //selection block
|
Chris@127
|
615 paint.setPen(Qt::blue);
|
Chris@127
|
616 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
|
Chris@127
|
617 m_mousePos.x() - m_clickPos.x(),
|
Chris@127
|
618 m_mousePos.y() - m_clickPos.y());
|
Chris@127
|
619 }
|
Chris@127
|
620 }
|
Chris@127
|
621
|
Chris@127
|
622 if (selectionIsBeingEdited()) {
|
Chris@127
|
623
|
Chris@127
|
624 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@127
|
625 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
|
Chris@127
|
626 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@127
|
627
|
Chris@127
|
628 if (m_editingSelectionEdge < 0) {
|
Chris@127
|
629 p1 = getXForFrame(m_editingSelection.getEndFrame());
|
Chris@127
|
630 } else if (m_editingSelectionEdge > 0) {
|
Chris@127
|
631 p0 = getXForFrame(m_editingSelection.getStartFrame());
|
Chris@127
|
632 }
|
Chris@127
|
633
|
Chris@127
|
634 paint.save();
|
Chris@127
|
635 if (hasLightBackground()) {
|
Chris@127
|
636 paint.setPen(QPen(Qt::black, 2));
|
Chris@127
|
637 } else {
|
Chris@127
|
638 paint.setPen(QPen(Qt::white, 2));
|
Chris@127
|
639 }
|
Chris@127
|
640
|
Chris@127
|
641 //!!! duplicating display policy with View::drawSelections
|
Chris@127
|
642
|
Chris@127
|
643 if (m_editingSelectionEdge < 0) {
|
Chris@127
|
644 paint.drawLine(p0, 1, p1, 1);
|
Chris@127
|
645 paint.drawLine(p0, 0, p0, height());
|
Chris@127
|
646 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@127
|
647 } else if (m_editingSelectionEdge > 0) {
|
Chris@127
|
648 paint.drawLine(p0, 1, p1, 1);
|
Chris@127
|
649 paint.drawLine(p1, 0, p1, height());
|
Chris@127
|
650 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@127
|
651 } else {
|
Chris@127
|
652 paint.setBrush(Qt::NoBrush);
|
Chris@127
|
653 paint.drawRect(p0, 1, p1 - p0, height() - 2);
|
Chris@127
|
654 }
|
Chris@127
|
655 paint.restore();
|
Chris@127
|
656 }
|
Chris@127
|
657
|
Chris@127
|
658 paint.end();
|
Chris@127
|
659 }
|
Chris@127
|
660
|
Chris@127
|
661 Selection
|
Chris@127
|
662 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
|
Chris@127
|
663 {
|
Chris@127
|
664 closeToLeftEdge = closeToRightEdge = false;
|
Chris@127
|
665
|
Chris@127
|
666 if (!m_manager) return Selection();
|
Chris@127
|
667
|
Chris@127
|
668 long testFrame = getFrameForX(x - 5);
|
Chris@127
|
669 if (testFrame < 0) {
|
Chris@127
|
670 testFrame = getFrameForX(x);
|
Chris@127
|
671 if (testFrame < 0) return Selection();
|
Chris@127
|
672 }
|
Chris@127
|
673
|
Chris@127
|
674 Selection selection = m_manager->getContainingSelection(testFrame, true);
|
Chris@127
|
675 if (selection.isEmpty()) return selection;
|
Chris@127
|
676
|
Chris@127
|
677 int lx = getXForFrame(selection.getStartFrame());
|
Chris@127
|
678 int rx = getXForFrame(selection.getEndFrame());
|
Chris@127
|
679
|
Chris@127
|
680 int fuzz = 2;
|
Chris@127
|
681 if (x < lx - fuzz || x > rx + fuzz) return Selection();
|
Chris@127
|
682
|
Chris@127
|
683 int width = rx - lx;
|
Chris@127
|
684 fuzz = 3;
|
Chris@127
|
685 if (width < 12) fuzz = width / 4;
|
Chris@127
|
686 if (fuzz < 1) fuzz = 1;
|
Chris@127
|
687
|
Chris@127
|
688 if (x < lx + fuzz) closeToLeftEdge = true;
|
Chris@127
|
689 if (x > rx - fuzz) closeToRightEdge = true;
|
Chris@127
|
690
|
Chris@127
|
691 return selection;
|
Chris@127
|
692 }
|
Chris@127
|
693
|
Chris@174
|
694 bool
|
Chris@174
|
695 Pane::canTopLayerMoveVertical()
|
Chris@174
|
696 {
|
Chris@174
|
697 float vmin, vmax, dmin, dmax;
|
Chris@174
|
698 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false;
|
Chris@174
|
699 if (dmin <= vmin && dmax >= vmax) return false;
|
Chris@174
|
700 return true;
|
Chris@174
|
701 }
|
Chris@174
|
702
|
Chris@174
|
703 bool
|
Chris@174
|
704 Pane::getTopLayerDisplayExtents(float &vmin, float &vmax,
|
Chris@174
|
705 float &dmin, float &dmax)
|
Chris@174
|
706 {
|
Chris@174
|
707 Layer *layer = 0;
|
Chris@174
|
708 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@174
|
709 if (!layer) return false;
|
Chris@174
|
710 bool vlog;
|
Chris@174
|
711 QString vunit;
|
Chris@174
|
712 return (layer->getValueExtents(vmin, vmax, vlog, vunit) &&
|
Chris@174
|
713 layer->getDisplayExtents(dmin, dmax));
|
Chris@174
|
714 }
|
Chris@174
|
715
|
Chris@174
|
716 bool
|
Chris@174
|
717 Pane::setTopLayerDisplayExtents(float dmin, float dmax)
|
Chris@174
|
718 {
|
Chris@174
|
719 Layer *layer = 0;
|
Chris@174
|
720 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@174
|
721 if (!layer) return false;
|
Chris@174
|
722 return layer->setDisplayExtents(dmin, dmax);
|
Chris@174
|
723 }
|
Chris@174
|
724
|
Chris@127
|
725 void
|
Chris@127
|
726 Pane::mousePressEvent(QMouseEvent *e)
|
Chris@127
|
727 {
|
Chris@127
|
728 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
729 emit rightButtonMenuRequested(mapToGlobal(e->pos()));
|
Chris@127
|
730 return;
|
Chris@127
|
731 }
|
Chris@127
|
732
|
Chris@127
|
733 m_clickPos = e->pos();
|
Chris@127
|
734 m_clickedInRange = true;
|
Chris@127
|
735 m_editingSelection = Selection();
|
Chris@127
|
736 m_editingSelectionEdge = 0;
|
Chris@127
|
737 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@127
|
738 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@150
|
739 m_dragMode = UnresolvedDrag;
|
Chris@127
|
740
|
Chris@127
|
741 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
742 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
743
|
Chris@127
|
744 m_navigating = false;
|
Chris@127
|
745
|
Chris@127
|
746 if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)) {
|
Chris@127
|
747
|
Chris@127
|
748 if (mode != ViewManager::NavigateMode) {
|
Chris@127
|
749 setCursor(Qt::PointingHandCursor);
|
Chris@127
|
750 }
|
Chris@127
|
751
|
Chris@127
|
752 m_navigating = true;
|
Chris@127
|
753 m_dragCentreFrame = m_centreFrame;
|
Chris@136
|
754 m_dragStartMinValue = 0;
|
Chris@174
|
755
|
Chris@174
|
756 float vmin, vmax, dmin, dmax;
|
Chris@174
|
757 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@174
|
758 m_dragStartMinValue = dmin;
|
Chris@136
|
759 }
|
Chris@136
|
760
|
Chris@127
|
761 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
762
|
Chris@127
|
763 bool closeToLeft = false, closeToRight = false;
|
Chris@127
|
764 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@127
|
765
|
Chris@127
|
766 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@127
|
767
|
Chris@127
|
768 m_manager->removeSelection(selection);
|
Chris@127
|
769
|
Chris@127
|
770 if (closeToLeft) {
|
Chris@127
|
771 m_selectionStartFrame = selection.getEndFrame();
|
Chris@127
|
772 } else {
|
Chris@127
|
773 m_selectionStartFrame = selection.getStartFrame();
|
Chris@127
|
774 }
|
Chris@127
|
775
|
Chris@127
|
776 m_manager->setInProgressSelection(selection, false);
|
Chris@127
|
777 m_resizing = true;
|
Chris@127
|
778
|
Chris@127
|
779 } else {
|
Chris@127
|
780
|
Chris@127
|
781 int mouseFrame = getFrameForX(e->x());
|
Chris@127
|
782 size_t resolution = 1;
|
Chris@127
|
783 int snapFrame = mouseFrame;
|
Chris@127
|
784
|
Chris@127
|
785 Layer *layer = getSelectedLayer();
|
Chris@127
|
786 if (layer && !m_shiftPressed) {
|
Chris@127
|
787 layer->snapToFeatureFrame(this, snapFrame,
|
Chris@127
|
788 resolution, Layer::SnapLeft);
|
Chris@127
|
789 }
|
Chris@127
|
790
|
Chris@127
|
791 if (snapFrame < 0) snapFrame = 0;
|
Chris@127
|
792 m_selectionStartFrame = snapFrame;
|
Chris@127
|
793 if (m_manager) {
|
Chris@127
|
794 m_manager->setInProgressSelection(Selection(snapFrame,
|
Chris@127
|
795 snapFrame + resolution),
|
Chris@127
|
796 !m_ctrlPressed);
|
Chris@127
|
797 }
|
Chris@127
|
798
|
Chris@127
|
799 m_resizing = false;
|
Chris@127
|
800 }
|
Chris@127
|
801
|
Chris@127
|
802 update();
|
Chris@127
|
803
|
Chris@127
|
804 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
805
|
Chris@127
|
806 Layer *layer = getSelectedLayer();
|
Chris@127
|
807 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
808 layer->drawStart(this, e);
|
Chris@127
|
809 }
|
Chris@127
|
810
|
Chris@127
|
811 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
812
|
Chris@127
|
813 if (!editSelectionStart(e)) {
|
Chris@127
|
814 Layer *layer = getSelectedLayer();
|
Chris@127
|
815 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
816 layer->editStart(this, e);
|
Chris@127
|
817 }
|
Chris@127
|
818 }
|
Chris@127
|
819 }
|
Chris@127
|
820
|
Chris@127
|
821 emit paneInteractedWith();
|
Chris@127
|
822 }
|
Chris@127
|
823
|
Chris@127
|
824 void
|
Chris@127
|
825 Pane::mouseReleaseEvent(QMouseEvent *e)
|
Chris@127
|
826 {
|
Chris@127
|
827 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
828 return;
|
Chris@127
|
829 }
|
Chris@127
|
830
|
Chris@127
|
831 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
832 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
833
|
Chris@127
|
834 if (m_clickedInRange) {
|
Chris@127
|
835 mouseMoveEvent(e);
|
Chris@127
|
836 }
|
Chris@127
|
837
|
Chris@127
|
838 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@127
|
839
|
Chris@127
|
840 m_navigating = false;
|
Chris@127
|
841
|
Chris@127
|
842 if (mode != ViewManager::NavigateMode) {
|
Chris@127
|
843 // restore cursor
|
Chris@127
|
844 toolModeChanged();
|
Chris@127
|
845 }
|
Chris@127
|
846
|
Chris@127
|
847 if (m_shiftPressed) {
|
Chris@127
|
848
|
Chris@127
|
849 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
|
Chris@127
|
850 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
|
Chris@127
|
851
|
Chris@127
|
852 int y0 = std::min(m_clickPos.y(), m_mousePos.y());
|
Chris@127
|
853 int y1 = std::max(m_clickPos.y(), m_mousePos.y());
|
Chris@127
|
854
|
Chris@174
|
855 zoomToRegion(x0, y0, x1, y1);
|
Chris@127
|
856 }
|
Chris@127
|
857
|
Chris@127
|
858 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
859
|
Chris@127
|
860 if (m_manager && m_manager->haveInProgressSelection()) {
|
Chris@127
|
861
|
Chris@127
|
862 bool exclusive;
|
Chris@127
|
863 Selection selection = m_manager->getInProgressSelection(exclusive);
|
Chris@127
|
864
|
Chris@127
|
865 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
|
Chris@127
|
866 selection = Selection();
|
Chris@127
|
867 }
|
Chris@127
|
868
|
Chris@127
|
869 m_manager->clearInProgressSelection();
|
Chris@127
|
870
|
Chris@127
|
871 if (exclusive) {
|
Chris@127
|
872 m_manager->setSelection(selection);
|
Chris@127
|
873 } else {
|
Chris@127
|
874 m_manager->addSelection(selection);
|
Chris@127
|
875 }
|
Chris@127
|
876 }
|
Chris@127
|
877
|
Chris@127
|
878 update();
|
Chris@127
|
879
|
Chris@127
|
880 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
881
|
Chris@127
|
882 Layer *layer = getSelectedLayer();
|
Chris@127
|
883 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
884 layer->drawEnd(this, e);
|
Chris@127
|
885 update();
|
Chris@127
|
886 }
|
Chris@127
|
887
|
Chris@127
|
888 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
889
|
Chris@127
|
890 if (!editSelectionEnd(e)) {
|
Chris@127
|
891 Layer *layer = getSelectedLayer();
|
Chris@127
|
892 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
893 layer->editEnd(this, e);
|
Chris@127
|
894 update();
|
Chris@127
|
895 }
|
Chris@127
|
896 }
|
Chris@127
|
897 }
|
Chris@127
|
898
|
Chris@127
|
899 m_clickedInRange = false;
|
Chris@127
|
900
|
Chris@127
|
901 emit paneInteractedWith();
|
Chris@127
|
902 }
|
Chris@127
|
903
|
Chris@127
|
904 void
|
Chris@127
|
905 Pane::mouseMoveEvent(QMouseEvent *e)
|
Chris@127
|
906 {
|
Chris@127
|
907 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
908 return;
|
Chris@127
|
909 }
|
Chris@127
|
910
|
Chris@127
|
911 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
912 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
913
|
Chris@127
|
914 QPoint prevPoint = m_identifyPoint;
|
Chris@127
|
915 m_identifyPoint = e->pos();
|
Chris@127
|
916
|
Chris@127
|
917 if (!m_clickedInRange) {
|
Chris@127
|
918
|
Chris@127
|
919 if (mode == ViewManager::SelectMode) {
|
Chris@127
|
920 bool closeToLeft = false, closeToRight = false;
|
Chris@127
|
921 getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@127
|
922 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@127
|
923 setCursor(Qt::SizeHorCursor);
|
Chris@127
|
924 } else {
|
Chris@127
|
925 setCursor(Qt::ArrowCursor);
|
Chris@127
|
926 }
|
Chris@127
|
927 }
|
Chris@127
|
928
|
Chris@127
|
929 if (!m_manager->isPlaying()) {
|
Chris@127
|
930
|
Chris@174
|
931 if (getSelectedLayer()) {
|
Chris@127
|
932
|
Chris@174
|
933 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@174
|
934 m_identifyFeatures = true;
|
Chris@174
|
935
|
Chris@174
|
936 if (m_identifyFeatures != previouslyIdentifying ||
|
Chris@174
|
937 m_identifyPoint != prevPoint) {
|
Chris@174
|
938 update();
|
Chris@174
|
939 }
|
Chris@174
|
940 }
|
Chris@127
|
941 }
|
Chris@127
|
942
|
Chris@127
|
943 return;
|
Chris@127
|
944 }
|
Chris@127
|
945
|
Chris@127
|
946 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@127
|
947
|
Chris@127
|
948 if (m_shiftPressed) {
|
Chris@127
|
949
|
Chris@127
|
950 m_mousePos = e->pos();
|
Chris@127
|
951 update();
|
Chris@127
|
952
|
Chris@127
|
953 } else {
|
Chris@127
|
954
|
Chris@174
|
955 dragTopLayer(e);
|
Chris@150
|
956 }
|
Chris@127
|
957
|
Chris@127
|
958 } else if (mode == ViewManager::SelectMode) {
|
Chris@127
|
959
|
Chris@174
|
960 dragExtendSelection(e);
|
Chris@127
|
961
|
Chris@127
|
962 } else if (mode == ViewManager::DrawMode) {
|
Chris@127
|
963
|
Chris@127
|
964 Layer *layer = getSelectedLayer();
|
Chris@127
|
965 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
966 layer->drawDrag(this, e);
|
Chris@127
|
967 }
|
Chris@127
|
968
|
Chris@127
|
969 } else if (mode == ViewManager::EditMode) {
|
Chris@127
|
970
|
Chris@127
|
971 if (!editSelectionDrag(e)) {
|
Chris@127
|
972 Layer *layer = getSelectedLayer();
|
Chris@127
|
973 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
974 layer->editDrag(this, e);
|
Chris@127
|
975 }
|
Chris@127
|
976 }
|
Chris@127
|
977 }
|
Chris@127
|
978 }
|
Chris@127
|
979
|
Chris@127
|
980 void
|
Chris@174
|
981 Pane::zoomToRegion(int x0, int y0, int x1, int y1)
|
Chris@174
|
982 {
|
Chris@174
|
983 int w = x1 - x0;
|
Chris@174
|
984
|
Chris@174
|
985 long newStartFrame = getFrameForX(x0);
|
Chris@174
|
986
|
Chris@174
|
987 long visibleFrames = getEndFrame() - getStartFrame();
|
Chris@174
|
988 if (newStartFrame <= -visibleFrames) {
|
Chris@174
|
989 newStartFrame = -visibleFrames + 1;
|
Chris@174
|
990 }
|
Chris@174
|
991
|
Chris@174
|
992 if (newStartFrame >= long(getModelsEndFrame())) {
|
Chris@174
|
993 newStartFrame = getModelsEndFrame() - 1;
|
Chris@174
|
994 }
|
Chris@174
|
995
|
Chris@174
|
996 float ratio = float(w) / float(width());
|
Chris@174
|
997 // std::cerr << "ratio: " << ratio << std::endl;
|
Chris@174
|
998 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
|
Chris@174
|
999 if (newZoomLevel < 1) newZoomLevel = 1;
|
Chris@174
|
1000
|
Chris@174
|
1001 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
|
Chris@174
|
1002 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
|
Chris@174
|
1003 setStartFrame(newStartFrame);
|
Chris@174
|
1004
|
Chris@174
|
1005 QString unit;
|
Chris@174
|
1006 float min, max;
|
Chris@174
|
1007 bool log;
|
Chris@174
|
1008 Layer *layer = 0;
|
Chris@174
|
1009 for (LayerList::const_iterator i = m_layers.begin();
|
Chris@174
|
1010 i != m_layers.end(); ++i) {
|
Chris@174
|
1011 if ((*i)->getValueExtents(min, max, log, unit) &&
|
Chris@174
|
1012 (*i)->getDisplayExtents(min, max)) {
|
Chris@174
|
1013 layer = *i;
|
Chris@174
|
1014 break;
|
Chris@174
|
1015 }
|
Chris@174
|
1016 }
|
Chris@174
|
1017
|
Chris@174
|
1018 if (layer) {
|
Chris@174
|
1019 if (log) {
|
Chris@174
|
1020 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min);
|
Chris@174
|
1021 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max);
|
Chris@174
|
1022 }
|
Chris@174
|
1023 float rmin = min + ((max - min) * (height() - y1)) / height();
|
Chris@174
|
1024 float rmax = min + ((max - min) * (height() - y0)) / height();
|
Chris@174
|
1025 std::cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << std::endl;
|
Chris@174
|
1026 if (log) {
|
Chris@174
|
1027 rmin = powf(10, rmin);
|
Chris@174
|
1028 rmax = powf(10, rmax);
|
Chris@174
|
1029 }
|
Chris@174
|
1030 std::cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit.toStdString() << std::endl;
|
Chris@174
|
1031
|
Chris@174
|
1032 layer->setDisplayExtents(rmin, rmax);
|
Chris@174
|
1033 updateVerticalPanner();
|
Chris@174
|
1034 }
|
Chris@174
|
1035 }
|
Chris@174
|
1036
|
Chris@174
|
1037 void
|
Chris@174
|
1038 Pane::dragTopLayer(QMouseEvent *e)
|
Chris@174
|
1039 {
|
Chris@174
|
1040 // We need to avoid making it too easy to drag both
|
Chris@174
|
1041 // horizontally and vertically, in the case where the
|
Chris@174
|
1042 // mouse is moved "mostly" in horizontal or vertical axis
|
Chris@174
|
1043 // with only a small variation in the other axis. This is
|
Chris@174
|
1044 // particularly important during playback (when we want to
|
Chris@174
|
1045 // avoid small horizontal motions) or in slow refresh
|
Chris@174
|
1046 // layers like spectrogram (when we want to avoid small
|
Chris@174
|
1047 // vertical motions).
|
Chris@174
|
1048 //
|
Chris@174
|
1049 // To this end we have horizontal and vertical thresholds
|
Chris@174
|
1050 // and a series of states: unresolved, horizontally or
|
Chris@174
|
1051 // vertically constrained, free.
|
Chris@174
|
1052 //
|
Chris@174
|
1053 // When the mouse first moves, we're unresolved: we
|
Chris@174
|
1054 // restrict ourselves to whichever direction seems safest,
|
Chris@174
|
1055 // until the mouse has passed a small threshold distance
|
Chris@174
|
1056 // from the click point. Then we lock in to one of the
|
Chris@174
|
1057 // constrained modes, based on which axis that distance
|
Chris@174
|
1058 // was measured in first. Finally, if it turns out we've
|
Chris@174
|
1059 // also moved more than a certain larger distance in the
|
Chris@174
|
1060 // other direction as well, we may switch into free mode.
|
Chris@174
|
1061 //
|
Chris@174
|
1062 // If the top layer is incapable of being dragged
|
Chris@174
|
1063 // vertically, the logic is short circuited.
|
Chris@174
|
1064
|
Chris@174
|
1065 int xdiff = e->x() - m_clickPos.x();
|
Chris@174
|
1066 int ydiff = e->y() - m_clickPos.y();
|
Chris@174
|
1067 int smallThreshold = 10, bigThreshold = 50;
|
Chris@174
|
1068
|
Chris@174
|
1069 bool canMoveVertical = canTopLayerMoveVertical();
|
Chris@174
|
1070 bool canMoveHorizontal = true;
|
Chris@174
|
1071
|
Chris@174
|
1072 if (!canMoveHorizontal) {
|
Chris@174
|
1073 m_dragMode = HorizontalDrag;
|
Chris@174
|
1074 }
|
Chris@174
|
1075
|
Chris@174
|
1076 if (m_dragMode == UnresolvedDrag) {
|
Chris@174
|
1077
|
Chris@174
|
1078 if (abs(ydiff) > smallThreshold &&
|
Chris@174
|
1079 abs(ydiff) > abs(xdiff) * 2) {
|
Chris@174
|
1080 m_dragMode = VerticalDrag;
|
Chris@174
|
1081 } else if (abs(xdiff) > smallThreshold &&
|
Chris@174
|
1082 abs(xdiff) > abs(ydiff) * 2) {
|
Chris@174
|
1083 m_dragMode = HorizontalDrag;
|
Chris@174
|
1084 } else if (abs(xdiff) > smallThreshold &&
|
Chris@174
|
1085 abs(ydiff) > smallThreshold) {
|
Chris@174
|
1086 m_dragMode = FreeDrag;
|
Chris@174
|
1087 } else {
|
Chris@174
|
1088 // When playing, we don't want to disturb the play
|
Chris@174
|
1089 // position too easily; when not playing, we don't
|
Chris@174
|
1090 // want to move up/down too easily
|
Chris@174
|
1091 if (m_manager && m_manager->isPlaying()) {
|
Chris@174
|
1092 canMoveHorizontal = false;
|
Chris@174
|
1093 } else {
|
Chris@174
|
1094 canMoveVertical = false;
|
Chris@174
|
1095 }
|
Chris@174
|
1096 }
|
Chris@174
|
1097 }
|
Chris@174
|
1098
|
Chris@174
|
1099 if (m_dragMode == VerticalDrag) {
|
Chris@174
|
1100 if (abs(xdiff) > bigThreshold) m_dragMode = FreeDrag;
|
Chris@174
|
1101 else canMoveHorizontal = false;
|
Chris@174
|
1102 }
|
Chris@174
|
1103
|
Chris@174
|
1104 if (m_dragMode == HorizontalDrag && canMoveVertical) {
|
Chris@174
|
1105 if (abs(ydiff) > bigThreshold) m_dragMode = FreeDrag;
|
Chris@174
|
1106 else canMoveVertical = false;
|
Chris@174
|
1107 }
|
Chris@174
|
1108
|
Chris@174
|
1109 if (canMoveHorizontal) {
|
Chris@174
|
1110
|
Chris@174
|
1111 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
|
Chris@174
|
1112
|
Chris@174
|
1113 size_t newCentreFrame = m_dragCentreFrame;
|
Chris@174
|
1114
|
Chris@174
|
1115 if (frameOff < 0) {
|
Chris@174
|
1116 newCentreFrame -= frameOff;
|
Chris@174
|
1117 } else if (newCentreFrame >= size_t(frameOff)) {
|
Chris@174
|
1118 newCentreFrame -= frameOff;
|
Chris@174
|
1119 } else {
|
Chris@174
|
1120 newCentreFrame = 0;
|
Chris@174
|
1121 }
|
Chris@174
|
1122
|
Chris@174
|
1123 if (newCentreFrame >= getModelsEndFrame()) {
|
Chris@174
|
1124 newCentreFrame = getModelsEndFrame();
|
Chris@174
|
1125 if (newCentreFrame > 0) --newCentreFrame;
|
Chris@174
|
1126 }
|
Chris@174
|
1127
|
Chris@174
|
1128 if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) {
|
Chris@174
|
1129 setCentreFrame(newCentreFrame);
|
Chris@174
|
1130 }
|
Chris@174
|
1131 }
|
Chris@174
|
1132
|
Chris@174
|
1133 if (canMoveVertical) {
|
Chris@174
|
1134
|
Chris@174
|
1135 float vmin = 0.f, vmax = 0.f;
|
Chris@174
|
1136 float dmin = 0.f, dmax = 0.f;
|
Chris@174
|
1137
|
Chris@174
|
1138 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
|
Chris@174
|
1139
|
Chris@174
|
1140 std::cerr << "ydiff = " << ydiff << std::endl;
|
Chris@174
|
1141
|
Chris@174
|
1142 float perpix = (dmax - dmin) / height();
|
Chris@174
|
1143 float valdiff = ydiff * perpix;
|
Chris@174
|
1144 std::cerr << "valdiff = " << valdiff << std::endl;
|
Chris@174
|
1145
|
Chris@174
|
1146 float newmin = m_dragStartMinValue + valdiff;
|
Chris@174
|
1147 float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff;
|
Chris@174
|
1148 if (newmin < vmin) {
|
Chris@174
|
1149 newmax += vmin - newmin;
|
Chris@174
|
1150 newmin += vmin - newmin;
|
Chris@174
|
1151 }
|
Chris@174
|
1152 if (newmax > vmax) {
|
Chris@174
|
1153 newmin -= newmax - vmax;
|
Chris@174
|
1154 newmax -= newmax - vmax;
|
Chris@174
|
1155 }
|
Chris@174
|
1156 std::cerr << "(" << dmin << ", " << dmax << ") -> ("
|
Chris@174
|
1157 << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << std::endl;
|
Chris@174
|
1158
|
Chris@174
|
1159 setTopLayerDisplayExtents(newmin, newmax);
|
Chris@174
|
1160 updateVerticalPanner();
|
Chris@174
|
1161 }
|
Chris@174
|
1162 }
|
Chris@174
|
1163 }
|
Chris@174
|
1164
|
Chris@174
|
1165 void
|
Chris@174
|
1166 Pane::dragExtendSelection(QMouseEvent *e)
|
Chris@174
|
1167 {
|
Chris@174
|
1168 int mouseFrame = getFrameForX(e->x());
|
Chris@174
|
1169 size_t resolution = 1;
|
Chris@174
|
1170 int snapFrameLeft = mouseFrame;
|
Chris@174
|
1171 int snapFrameRight = mouseFrame;
|
Chris@174
|
1172
|
Chris@174
|
1173 Layer *layer = getSelectedLayer();
|
Chris@174
|
1174 if (layer && !m_shiftPressed) {
|
Chris@174
|
1175 layer->snapToFeatureFrame(this, snapFrameLeft,
|
Chris@174
|
1176 resolution, Layer::SnapLeft);
|
Chris@174
|
1177 layer->snapToFeatureFrame(this, snapFrameRight,
|
Chris@174
|
1178 resolution, Layer::SnapRight);
|
Chris@174
|
1179 }
|
Chris@174
|
1180
|
Chris@174
|
1181 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl;
|
Chris@174
|
1182
|
Chris@174
|
1183 if (snapFrameLeft < 0) snapFrameLeft = 0;
|
Chris@174
|
1184 if (snapFrameRight < 0) snapFrameRight = 0;
|
Chris@174
|
1185
|
Chris@174
|
1186 size_t min, max;
|
Chris@174
|
1187
|
Chris@174
|
1188 if (m_selectionStartFrame > snapFrameLeft) {
|
Chris@174
|
1189 min = snapFrameLeft;
|
Chris@174
|
1190 max = m_selectionStartFrame;
|
Chris@174
|
1191 } else if (snapFrameRight > m_selectionStartFrame) {
|
Chris@174
|
1192 min = m_selectionStartFrame;
|
Chris@174
|
1193 max = snapFrameRight;
|
Chris@174
|
1194 } else {
|
Chris@174
|
1195 min = snapFrameLeft;
|
Chris@174
|
1196 max = snapFrameRight;
|
Chris@174
|
1197 }
|
Chris@174
|
1198
|
Chris@174
|
1199 if (m_manager) {
|
Chris@174
|
1200 m_manager->setInProgressSelection(Selection(min, max),
|
Chris@174
|
1201 !m_resizing && !m_ctrlPressed);
|
Chris@174
|
1202 }
|
Chris@174
|
1203
|
Chris@174
|
1204 bool doScroll = false;
|
Chris@174
|
1205 if (!m_manager) doScroll = true;
|
Chris@174
|
1206 if (!m_manager->isPlaying()) doScroll = true;
|
Chris@174
|
1207 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
|
Chris@174
|
1208
|
Chris@174
|
1209 if (doScroll) {
|
Chris@174
|
1210 int offset = mouseFrame - getStartFrame();
|
Chris@174
|
1211 int available = getEndFrame() - getStartFrame();
|
Chris@174
|
1212 if (offset >= available * 0.95) {
|
Chris@174
|
1213 int move = int(offset - available * 0.95) + 1;
|
Chris@174
|
1214 setCentreFrame(m_centreFrame + move);
|
Chris@174
|
1215 } else if (offset <= available * 0.10) {
|
Chris@174
|
1216 int move = int(available * 0.10 - offset) + 1;
|
Chris@174
|
1217 if (m_centreFrame > move) {
|
Chris@174
|
1218 setCentreFrame(m_centreFrame - move);
|
Chris@174
|
1219 } else {
|
Chris@174
|
1220 setCentreFrame(0);
|
Chris@174
|
1221 }
|
Chris@174
|
1222 }
|
Chris@174
|
1223 }
|
Chris@174
|
1224
|
Chris@174
|
1225 update();
|
Chris@174
|
1226 }
|
Chris@174
|
1227
|
Chris@174
|
1228 void
|
Chris@127
|
1229 Pane::mouseDoubleClickEvent(QMouseEvent *e)
|
Chris@127
|
1230 {
|
Chris@127
|
1231 if (e->buttons() & Qt::RightButton) {
|
Chris@127
|
1232 return;
|
Chris@127
|
1233 }
|
Chris@127
|
1234
|
Chris@127
|
1235 // std::cerr << "mouseDoubleClickEvent" << std::endl;
|
Chris@127
|
1236
|
Chris@127
|
1237 m_clickPos = e->pos();
|
Chris@127
|
1238 m_clickedInRange = true;
|
Chris@127
|
1239 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@127
|
1240 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@127
|
1241
|
Chris@127
|
1242 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@127
|
1243 if (m_manager) mode = m_manager->getToolMode();
|
Chris@127
|
1244
|
Chris@127
|
1245 if (mode == ViewManager::NavigateMode ||
|
Chris@127
|
1246 mode == ViewManager::EditMode) {
|
Chris@127
|
1247
|
Chris@127
|
1248 Layer *layer = getSelectedLayer();
|
Chris@127
|
1249 if (layer && layer->isLayerEditable()) {
|
Chris@127
|
1250 layer->editOpen(this, e);
|
Chris@127
|
1251 }
|
Chris@127
|
1252 }
|
Chris@127
|
1253 }
|
Chris@127
|
1254
|
Chris@127
|
1255 void
|
Chris@127
|
1256 Pane::leaveEvent(QEvent *)
|
Chris@127
|
1257 {
|
Chris@127
|
1258 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@127
|
1259 m_identifyFeatures = false;
|
Chris@127
|
1260 if (previouslyIdentifying) update();
|
Chris@127
|
1261 }
|
Chris@127
|
1262
|
Chris@127
|
1263 void
|
Chris@133
|
1264 Pane::resizeEvent(QResizeEvent *)
|
Chris@133
|
1265 {
|
Chris@133
|
1266 updateHeadsUpDisplay();
|
Chris@133
|
1267 }
|
Chris@133
|
1268
|
Chris@133
|
1269 void
|
Chris@127
|
1270 Pane::wheelEvent(QWheelEvent *e)
|
Chris@127
|
1271 {
|
Chris@127
|
1272 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
|
Chris@127
|
1273
|
Chris@127
|
1274 int count = e->delta();
|
Chris@127
|
1275
|
Chris@127
|
1276 if (count > 0) {
|
Chris@127
|
1277 if (count >= 120) count /= 120;
|
Chris@127
|
1278 else count = 1;
|
Chris@127
|
1279 }
|
Chris@127
|
1280
|
Chris@127
|
1281 if (count < 0) {
|
Chris@127
|
1282 if (count <= -120) count /= 120;
|
Chris@127
|
1283 else count = -1;
|
Chris@127
|
1284 }
|
Chris@127
|
1285
|
Chris@127
|
1286 if (e->modifiers() & Qt::ControlModifier) {
|
Chris@127
|
1287
|
Chris@127
|
1288 // Scroll left or right, rapidly
|
Chris@127
|
1289
|
Chris@127
|
1290 if (getStartFrame() < 0 &&
|
Chris@127
|
1291 getEndFrame() >= getModelsEndFrame()) return;
|
Chris@127
|
1292
|
Chris@127
|
1293 long delta = ((width() / 2) * count * m_zoomLevel);
|
Chris@127
|
1294
|
Chris@127
|
1295 if (int(m_centreFrame) < delta) {
|
Chris@127
|
1296 setCentreFrame(0);
|
Chris@127
|
1297 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
|
Chris@127
|
1298 setCentreFrame(getModelsEndFrame());
|
Chris@127
|
1299 } else {
|
Chris@127
|
1300 setCentreFrame(m_centreFrame - delta);
|
Chris@127
|
1301 }
|
Chris@127
|
1302
|
Chris@127
|
1303 } else {
|
Chris@127
|
1304
|
Chris@127
|
1305 // Zoom in or out
|
Chris@127
|
1306
|
Chris@127
|
1307 int newZoomLevel = m_zoomLevel;
|
Chris@127
|
1308
|
Chris@127
|
1309 while (count > 0) {
|
Chris@127
|
1310 if (newZoomLevel <= 2) {
|
Chris@127
|
1311 newZoomLevel = 1;
|
Chris@127
|
1312 break;
|
Chris@127
|
1313 }
|
Chris@127
|
1314 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
Chris@127
|
1315 ZoomConstraint::RoundDown);
|
Chris@127
|
1316 --count;
|
Chris@127
|
1317 }
|
Chris@127
|
1318
|
Chris@127
|
1319 while (count < 0) {
|
Chris@127
|
1320 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
Chris@127
|
1321 ZoomConstraint::RoundUp);
|
Chris@127
|
1322 ++count;
|
Chris@127
|
1323 }
|
Chris@127
|
1324
|
Chris@127
|
1325 if (newZoomLevel != m_zoomLevel) {
|
Chris@127
|
1326 setZoomLevel(newZoomLevel);
|
Chris@127
|
1327 }
|
Chris@127
|
1328 }
|
Chris@127
|
1329
|
Chris@127
|
1330 emit paneInteractedWith();
|
Chris@127
|
1331 }
|
Chris@127
|
1332
|
Chris@132
|
1333 void
|
Chris@132
|
1334 Pane::horizontalThumbwheelMoved(int value)
|
Chris@132
|
1335 {
|
Chris@137
|
1336 //!!! dupe with updateHeadsUpDisplay
|
Chris@137
|
1337
|
Chris@132
|
1338 int count = 0;
|
Chris@132
|
1339 int level = 1;
|
Chris@137
|
1340
|
Chris@137
|
1341
|
Chris@137
|
1342 //!!! pull out into function (presumably in View)
|
Chris@137
|
1343 bool haveConstraint = false;
|
Chris@137
|
1344 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
|
Chris@137
|
1345 ++i) {
|
Chris@137
|
1346 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
|
Chris@137
|
1347 haveConstraint = true;
|
Chris@137
|
1348 break;
|
Chris@137
|
1349 }
|
Chris@132
|
1350 }
|
Chris@132
|
1351
|
Chris@137
|
1352 if (haveConstraint) {
|
Chris@137
|
1353 while (true) {
|
Chris@137
|
1354 if (m_hthumb->getMaximumValue() - value == count) break;
|
Chris@137
|
1355 int newLevel = getZoomConstraintBlockSize(level + 1,
|
Chris@137
|
1356 ZoomConstraint::RoundUp);
|
Chris@137
|
1357 if (newLevel == level) break;
|
Chris@137
|
1358 level = newLevel;
|
Chris@137
|
1359 if (++count == 50) break;
|
Chris@137
|
1360 }
|
Chris@137
|
1361 } else {
|
Chris@137
|
1362 while (true) {
|
Chris@137
|
1363 if (m_hthumb->getMaximumValue() - value == count) break;
|
Chris@137
|
1364 int step = level / 10;
|
Chris@137
|
1365 int pwr = 0;
|
Chris@137
|
1366 while (step > 0) {
|
Chris@137
|
1367 ++pwr;
|
Chris@137
|
1368 step /= 2;
|
Chris@137
|
1369 }
|
Chris@137
|
1370 step = 1;
|
Chris@137
|
1371 while (pwr > 0) {
|
Chris@137
|
1372 step *= 2;
|
Chris@137
|
1373 --pwr;
|
Chris@137
|
1374 }
|
Chris@137
|
1375 // std::cerr << level << std::endl;
|
Chris@137
|
1376 level += step;
|
Chris@137
|
1377 if (++count == 100 || level > 262144) break;
|
Chris@137
|
1378 }
|
Chris@137
|
1379 }
|
Chris@137
|
1380
|
Chris@137
|
1381 std::cerr << "new level is " << level << std::endl;
|
Chris@132
|
1382 setZoomLevel(level);
|
Chris@132
|
1383 }
|
Chris@132
|
1384
|
Chris@132
|
1385 void
|
Chris@132
|
1386 Pane::verticalThumbwheelMoved(int value)
|
Chris@132
|
1387 {
|
Chris@133
|
1388 Layer *layer = 0;
|
Chris@133
|
1389 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1390 if (layer) {
|
Chris@133
|
1391 int defaultStep = 0;
|
Chris@133
|
1392 int max = layer->getVerticalZoomSteps(defaultStep);
|
Chris@133
|
1393 if (max == 0) {
|
Chris@133
|
1394 updateHeadsUpDisplay();
|
Chris@133
|
1395 return;
|
Chris@133
|
1396 }
|
Chris@133
|
1397 if (value > max) {
|
Chris@133
|
1398 value = max;
|
Chris@133
|
1399 }
|
Chris@133
|
1400 layer->setVerticalZoomStep(value);
|
Chris@174
|
1401 updateVerticalPanner();
|
Chris@133
|
1402 }
|
Chris@132
|
1403 }
|
Chris@132
|
1404
|
Chris@174
|
1405 void
|
Chris@174
|
1406 Pane::verticalPannerMoved(float x0, float y0, float w, float h)
|
Chris@174
|
1407 {
|
Chris@174
|
1408 float vmin, vmax, dmin, dmax;
|
Chris@174
|
1409 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return;
|
Chris@174
|
1410 float y1 = y0 + h;
|
Chris@174
|
1411 float newmax = vmin + ((1.0 - y0) * (vmax - vmin));
|
Chris@174
|
1412 float newmin = vmin + ((1.0 - y1) * (vmax - vmin));
|
Chris@174
|
1413 std::cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w
|
Chris@174
|
1414 << "," << h << ") -> (" << newmin << "," << newmax << ")" << std::endl;
|
Chris@174
|
1415 setTopLayerDisplayExtents(newmin, newmax);
|
Chris@174
|
1416 }
|
Chris@174
|
1417
|
Chris@127
|
1418 bool
|
Chris@127
|
1419 Pane::editSelectionStart(QMouseEvent *e)
|
Chris@127
|
1420 {
|
Chris@127
|
1421 if (!m_identifyFeatures ||
|
Chris@127
|
1422 !m_manager ||
|
Chris@127
|
1423 m_manager->getToolMode() != ViewManager::EditMode) {
|
Chris@127
|
1424 return false;
|
Chris@127
|
1425 }
|
Chris@127
|
1426
|
Chris@127
|
1427 bool closeToLeft, closeToRight;
|
Chris@127
|
1428 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight));
|
Chris@127
|
1429 if (s.isEmpty()) return false;
|
Chris@127
|
1430 m_editingSelection = s;
|
Chris@127
|
1431 m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0);
|
Chris@127
|
1432 m_mousePos = e->pos();
|
Chris@127
|
1433 return true;
|
Chris@127
|
1434 }
|
Chris@127
|
1435
|
Chris@127
|
1436 bool
|
Chris@127
|
1437 Pane::editSelectionDrag(QMouseEvent *e)
|
Chris@127
|
1438 {
|
Chris@127
|
1439 if (m_editingSelection.isEmpty()) return false;
|
Chris@127
|
1440 m_mousePos = e->pos();
|
Chris@127
|
1441 update();
|
Chris@127
|
1442 return true;
|
Chris@127
|
1443 }
|
Chris@127
|
1444
|
Chris@127
|
1445 bool
|
Chris@127
|
1446 Pane::editSelectionEnd(QMouseEvent *e)
|
Chris@127
|
1447 {
|
Chris@127
|
1448 if (m_editingSelection.isEmpty()) return false;
|
Chris@127
|
1449
|
Chris@127
|
1450 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@127
|
1451 Layer *layer = getSelectedLayer();
|
Chris@127
|
1452
|
Chris@127
|
1453 if (offset == 0 || !layer) {
|
Chris@127
|
1454 m_editingSelection = Selection();
|
Chris@127
|
1455 return true;
|
Chris@127
|
1456 }
|
Chris@127
|
1457
|
Chris@127
|
1458 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
|
Chris@127
|
1459 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@127
|
1460
|
Chris@127
|
1461 long f0 = getFrameForX(p0);
|
Chris@127
|
1462 long f1 = getFrameForX(p1);
|
Chris@127
|
1463
|
Chris@127
|
1464 Selection newSelection(f0, f1);
|
Chris@127
|
1465
|
Chris@127
|
1466 if (m_editingSelectionEdge == 0) {
|
Chris@127
|
1467
|
Chris@127
|
1468 CommandHistory::getInstance()->startCompoundOperation
|
Chris@127
|
1469 (tr("Drag Selection"), true);
|
Chris@127
|
1470
|
Chris@127
|
1471 layer->moveSelection(m_editingSelection, f0);
|
Chris@127
|
1472
|
Chris@127
|
1473 } else {
|
Chris@127
|
1474
|
Chris@127
|
1475 CommandHistory::getInstance()->startCompoundOperation
|
Chris@127
|
1476 (tr("Resize Selection"), true);
|
Chris@127
|
1477
|
Chris@127
|
1478 if (m_editingSelectionEdge < 0) {
|
Chris@127
|
1479 f1 = m_editingSelection.getEndFrame();
|
Chris@127
|
1480 } else {
|
Chris@127
|
1481 f0 = m_editingSelection.getStartFrame();
|
Chris@127
|
1482 }
|
Chris@127
|
1483
|
Chris@127
|
1484 newSelection = Selection(f0, f1);
|
Chris@127
|
1485 layer->resizeSelection(m_editingSelection, newSelection);
|
Chris@127
|
1486 }
|
Chris@127
|
1487
|
Chris@127
|
1488 m_manager->removeSelection(m_editingSelection);
|
Chris@127
|
1489 m_manager->addSelection(newSelection);
|
Chris@127
|
1490
|
Chris@127
|
1491 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@127
|
1492
|
Chris@127
|
1493 m_editingSelection = Selection();
|
Chris@127
|
1494 return true;
|
Chris@127
|
1495 }
|
Chris@127
|
1496
|
Chris@127
|
1497 void
|
Chris@127
|
1498 Pane::toolModeChanged()
|
Chris@127
|
1499 {
|
Chris@127
|
1500 ViewManager::ToolMode mode = m_manager->getToolMode();
|
Chris@127
|
1501 // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
|
Chris@127
|
1502
|
Chris@127
|
1503 switch (mode) {
|
Chris@127
|
1504
|
Chris@127
|
1505 case ViewManager::NavigateMode:
|
Chris@127
|
1506 setCursor(Qt::PointingHandCursor);
|
Chris@127
|
1507 break;
|
Chris@127
|
1508
|
Chris@127
|
1509 case ViewManager::SelectMode:
|
Chris@127
|
1510 setCursor(Qt::ArrowCursor);
|
Chris@127
|
1511 break;
|
Chris@127
|
1512
|
Chris@127
|
1513 case ViewManager::EditMode:
|
Chris@127
|
1514 setCursor(Qt::UpArrowCursor);
|
Chris@127
|
1515 break;
|
Chris@127
|
1516
|
Chris@127
|
1517 case ViewManager::DrawMode:
|
Chris@127
|
1518 setCursor(Qt::CrossCursor);
|
Chris@127
|
1519 break;
|
Chris@127
|
1520 /*
|
Chris@127
|
1521 case ViewManager::TextMode:
|
Chris@127
|
1522 setCursor(Qt::IBeamCursor);
|
Chris@127
|
1523 break;
|
Chris@127
|
1524 */
|
Chris@127
|
1525 }
|
Chris@127
|
1526 }
|
Chris@127
|
1527
|
Chris@133
|
1528 void
|
Chris@133
|
1529 Pane::zoomWheelsEnabledChanged()
|
Chris@133
|
1530 {
|
Chris@133
|
1531 updateHeadsUpDisplay();
|
Chris@133
|
1532 update();
|
Chris@133
|
1533 }
|
Chris@133
|
1534
|
Chris@133
|
1535 void
|
Chris@133
|
1536 Pane::zoomLevelChanged()
|
Chris@133
|
1537 {
|
Chris@133
|
1538 if (m_manager && m_manager->getZoomWheelsEnabled()) {
|
Chris@133
|
1539 updateHeadsUpDisplay();
|
Chris@133
|
1540 }
|
Chris@133
|
1541 }
|
Chris@133
|
1542
|
Chris@133
|
1543 void
|
Chris@133
|
1544 Pane::propertyContainerSelected(View *v, PropertyContainer *pc)
|
Chris@133
|
1545 {
|
Chris@133
|
1546 Layer *layer = 0;
|
Chris@133
|
1547
|
Chris@133
|
1548 if (getLayerCount() > 0) {
|
Chris@133
|
1549 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1550 disconnect(layer, SIGNAL(verticalZoomChanged()),
|
Chris@133
|
1551 this, SLOT(verticalZoomChanged()));
|
Chris@133
|
1552 }
|
Chris@133
|
1553
|
Chris@133
|
1554 View::propertyContainerSelected(v, pc);
|
Chris@133
|
1555 updateHeadsUpDisplay();
|
Chris@133
|
1556
|
Chris@187
|
1557 if (m_vthumb) {
|
Chris@187
|
1558 RangeMapper *rm = 0;
|
Chris@187
|
1559 if (layer) rm = layer->getNewVerticalZoomRangeMapper();
|
Chris@187
|
1560 if (rm) m_vthumb->setRangeMapper(rm);
|
Chris@187
|
1561 }
|
Chris@187
|
1562
|
Chris@133
|
1563 if (getLayerCount() > 0) {
|
Chris@133
|
1564 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1565 connect(layer, SIGNAL(verticalZoomChanged()),
|
Chris@133
|
1566 this, SLOT(verticalZoomChanged()));
|
Chris@133
|
1567 }
|
Chris@133
|
1568 }
|
Chris@133
|
1569
|
Chris@133
|
1570 void
|
Chris@133
|
1571 Pane::verticalZoomChanged()
|
Chris@133
|
1572 {
|
Chris@133
|
1573 Layer *layer = 0;
|
Chris@133
|
1574
|
Chris@133
|
1575 if (getLayerCount() > 0) {
|
Chris@133
|
1576
|
Chris@133
|
1577 layer = getLayer(getLayerCount() - 1);
|
Chris@133
|
1578
|
Chris@133
|
1579 if (m_vthumb && m_vthumb->isVisible()) {
|
Chris@133
|
1580 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
|
Chris@133
|
1581 }
|
Chris@133
|
1582 }
|
Chris@133
|
1583 }
|
Chris@133
|
1584
|
Chris@127
|
1585 QString
|
Chris@127
|
1586 Pane::toXmlString(QString indent, QString extraAttributes) const
|
Chris@127
|
1587 {
|
Chris@127
|
1588 return View::toXmlString
|
Chris@127
|
1589 (indent,
|
Chris@127
|
1590 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3")
|
Chris@127
|
1591 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes));
|
Chris@127
|
1592 }
|
Chris@127
|
1593
|
Chris@127
|
1594
|
Chris@127
|
1595 #ifdef INCLUDE_MOCFILES
|
Chris@127
|
1596 #include "Pane.moc.cpp"
|
Chris@127
|
1597 #endif
|
Chris@127
|
1598
|