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