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