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