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