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