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