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