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