Chris@49
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@52
|
4 Sonic Visualiser
|
Chris@52
|
5 An audio file viewer and annotation editor.
|
Chris@52
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@52
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@52
|
9 This program is free software; you can redistribute it and/or
|
Chris@52
|
10 modify it under the terms of the GNU General Public License as
|
Chris@52
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@52
|
12 License, or (at your option) any later version. See the file
|
Chris@52
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "base/View.h"
|
Chris@0
|
17 #include "base/Layer.h"
|
Chris@0
|
18 #include "base/Model.h"
|
Chris@0
|
19 #include "base/ZoomConstraint.h"
|
Chris@0
|
20 #include "base/Profiler.h"
|
Chris@0
|
21
|
Chris@0
|
22 #include "layer/TimeRulerLayer.h" //!!! damn, shouldn't be including that here
|
Chris@25
|
23 #include "model/PowerOfSqrtTwoZoomConstraint.h" //!!! likewise
|
Chris@0
|
24
|
Chris@0
|
25 #include <QPainter>
|
Chris@0
|
26 #include <QPaintEvent>
|
Chris@0
|
27 #include <QRect>
|
Chris@0
|
28 #include <QApplication>
|
Chris@0
|
29
|
Chris@0
|
30 #include <iostream>
|
Chris@16
|
31 #include <cassert>
|
Martin@37
|
32 #include <math.h>
|
Chris@0
|
33
|
Chris@18
|
34 //#define DEBUG_VIEW_WIDGET_PAINT 1
|
Chris@0
|
35
|
Chris@0
|
36 using std::cerr;
|
Chris@0
|
37 using std::endl;
|
Chris@0
|
38
|
Chris@0
|
39 View::View(QWidget *w, bool showProgress) :
|
Chris@0
|
40 QFrame(w),
|
Chris@0
|
41 m_centreFrame(0),
|
Chris@0
|
42 m_zoomLevel(1024),
|
Chris@0
|
43 m_followPan(true),
|
Chris@0
|
44 m_followZoom(true),
|
Chris@0
|
45 m_followPlay(PlaybackScrollPage),
|
Chris@0
|
46 m_lightBackground(true),
|
Chris@0
|
47 m_showProgress(showProgress),
|
Chris@0
|
48 m_cache(0),
|
Chris@0
|
49 m_cacheCentreFrame(0),
|
Chris@0
|
50 m_cacheZoomLevel(1024),
|
Chris@9
|
51 m_selectionCached(false),
|
Chris@0
|
52 m_deleting(false),
|
Chris@8
|
53 m_haveSelectedLayer(false),
|
Chris@29
|
54 m_manager(0),
|
Chris@29
|
55 m_propertyContainer(new ViewPropertyContainer(this))
|
Chris@0
|
56 {
|
Chris@0
|
57 // QWidget::setAttribute(Qt::WA_PaintOnScreen);
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 View::~View()
|
Chris@0
|
61 {
|
Chris@43
|
62 std::cerr << "View::~View(" << this << ")" << std::endl;
|
Chris@43
|
63
|
Chris@0
|
64 m_deleting = true;
|
Chris@29
|
65 delete m_propertyContainer;
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 PropertyContainer::PropertyList
|
Chris@0
|
69 View::getProperties() const
|
Chris@0
|
70 {
|
Chris@29
|
71 PropertyContainer::PropertyList list;
|
Chris@0
|
72 list.push_back(tr("Global Scroll"));
|
Chris@0
|
73 list.push_back(tr("Global Zoom"));
|
Chris@0
|
74 list.push_back(tr("Follow Playback"));
|
Chris@0
|
75 return list;
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 PropertyContainer::PropertyType
|
Chris@29
|
79 View::getPropertyType(const PropertyContainer::PropertyName &name) const
|
Chris@0
|
80 {
|
Chris@29
|
81 if (name == tr("Global Scroll")) return PropertyContainer::ToggleProperty;
|
Chris@29
|
82 if (name == tr("Global Zoom")) return PropertyContainer::ToggleProperty;
|
Chris@29
|
83 if (name == tr("Follow Playback")) return PropertyContainer::ValueProperty;
|
Chris@29
|
84 return PropertyContainer::InvalidProperty;
|
Chris@0
|
85 }
|
Chris@0
|
86
|
Chris@0
|
87 int
|
Chris@29
|
88 View::getPropertyRangeAndValue(const PropertyContainer::PropertyName &name,
|
Chris@29
|
89 int *min, int *max) const
|
Chris@0
|
90 {
|
Chris@0
|
91 if (name == tr("Global Scroll")) return m_followPan;
|
Chris@0
|
92 if (name == tr("Global Zoom")) return m_followZoom;
|
Chris@29
|
93 if (name == tr("Follow Playback")) {
|
Chris@29
|
94 if (min) *min = 0;
|
Chris@29
|
95 if (max) *max = 2;
|
Chris@29
|
96 return int(m_followPlay);
|
Chris@29
|
97 }
|
Chris@29
|
98 if (min) *min = 0;
|
Chris@29
|
99 if (max) *max = 0;
|
Chris@29
|
100 return 0;
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@0
|
103 QString
|
Chris@29
|
104 View::getPropertyValueLabel(const PropertyContainer::PropertyName &name,
|
Chris@29
|
105 int value) const
|
Chris@0
|
106 {
|
Chris@0
|
107 if (name == tr("Follow Playback")) {
|
Chris@0
|
108 switch (value) {
|
Chris@0
|
109 default:
|
Chris@0
|
110 case 0: return tr("Scroll");
|
Chris@0
|
111 case 1: return tr("Page");
|
Chris@0
|
112 case 2: return tr("Off");
|
Chris@0
|
113 }
|
Chris@0
|
114 }
|
Chris@0
|
115 return tr("<unknown>");
|
Chris@0
|
116 }
|
Chris@0
|
117
|
Chris@0
|
118 void
|
Chris@29
|
119 View::setProperty(const PropertyContainer::PropertyName &name, int value)
|
Chris@0
|
120 {
|
Chris@0
|
121 if (name == tr("Global Scroll")) {
|
Chris@0
|
122 setFollowGlobalPan(value != 0);
|
Chris@0
|
123 } else if (name == tr("Global Zoom")) {
|
Chris@0
|
124 setFollowGlobalZoom(value != 0);
|
Chris@0
|
125 } else if (name == tr("Follow Playback")) {
|
Chris@0
|
126 switch (value) {
|
Chris@0
|
127 default:
|
Chris@0
|
128 case 0: setPlaybackFollow(PlaybackScrollContinuous); break;
|
Chris@0
|
129 case 1: setPlaybackFollow(PlaybackScrollPage); break;
|
Chris@0
|
130 case 2: setPlaybackFollow(PlaybackIgnore); break;
|
Chris@0
|
131 }
|
Chris@0
|
132 }
|
Chris@0
|
133 }
|
Chris@0
|
134
|
Chris@0
|
135 size_t
|
Chris@0
|
136 View::getPropertyContainerCount() const
|
Chris@0
|
137 {
|
Chris@0
|
138 return m_layers.size() + 1; // the 1 is for me
|
Chris@0
|
139 }
|
Chris@0
|
140
|
Chris@0
|
141 const PropertyContainer *
|
Chris@0
|
142 View::getPropertyContainer(size_t i) const
|
Chris@0
|
143 {
|
Chris@0
|
144 return (const PropertyContainer *)(((View *)this)->
|
Chris@0
|
145 getPropertyContainer(i));
|
Chris@0
|
146 }
|
Chris@0
|
147
|
Chris@0
|
148 PropertyContainer *
|
Chris@0
|
149 View::getPropertyContainer(size_t i)
|
Chris@0
|
150 {
|
Chris@29
|
151 if (i == 0) return m_propertyContainer;
|
Chris@0
|
152 return m_layers[i-1];
|
Chris@0
|
153 }
|
Chris@0
|
154
|
Chris@0
|
155 void
|
Chris@44
|
156 View::propertyContainerSelected(View *client, PropertyContainer *pc)
|
Chris@0
|
157 {
|
Chris@44
|
158 if (client != this) return;
|
Chris@44
|
159
|
Chris@29
|
160 if (pc == m_propertyContainer) {
|
Chris@8
|
161 if (m_haveSelectedLayer) {
|
Chris@8
|
162 m_haveSelectedLayer = false;
|
Chris@8
|
163 update();
|
Chris@8
|
164 }
|
Chris@8
|
165 return;
|
Chris@8
|
166 }
|
Chris@0
|
167
|
Chris@0
|
168 delete m_cache;
|
Chris@0
|
169 m_cache = 0;
|
Chris@0
|
170
|
Chris@0
|
171 Layer *selectedLayer = 0;
|
Chris@0
|
172
|
Chris@0
|
173 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@0
|
174 if (*i == pc) {
|
Chris@0
|
175 selectedLayer = *i;
|
Chris@0
|
176 m_layers.erase(i);
|
Chris@0
|
177 break;
|
Chris@0
|
178 }
|
Chris@0
|
179 }
|
Chris@0
|
180
|
Chris@0
|
181 if (selectedLayer) {
|
Chris@8
|
182 m_haveSelectedLayer = true;
|
Chris@0
|
183 m_layers.push_back(selectedLayer);
|
Chris@0
|
184 update();
|
Chris@8
|
185 } else {
|
Chris@8
|
186 m_haveSelectedLayer = false;
|
Chris@0
|
187 }
|
Chris@0
|
188 }
|
Chris@0
|
189
|
Chris@8
|
190 void
|
Chris@8
|
191 View::toolModeChanged()
|
Chris@8
|
192 {
|
Chris@8
|
193 std::cerr << "View::toolModeChanged(" << m_manager->getToolMode() << ")" << std::endl;
|
Chris@8
|
194 }
|
Chris@8
|
195
|
Chris@0
|
196 long
|
Chris@0
|
197 View::getStartFrame() const
|
Chris@0
|
198 {
|
Chris@0
|
199 size_t w2 = (width() / 2) * m_zoomLevel;
|
Chris@0
|
200 size_t frame = m_centreFrame;
|
Chris@0
|
201 if (frame >= w2) {
|
Chris@0
|
202 frame -= w2;
|
Chris@0
|
203 return (frame / m_zoomLevel * m_zoomLevel);
|
Chris@0
|
204 } else {
|
Chris@0
|
205 frame = w2 - frame;
|
Chris@0
|
206 frame = frame / m_zoomLevel * m_zoomLevel;
|
Chris@0
|
207 return -(long)frame - m_zoomLevel;
|
Chris@0
|
208 }
|
Chris@0
|
209 }
|
Chris@0
|
210
|
Chris@0
|
211 size_t
|
Chris@0
|
212 View::getEndFrame() const
|
Chris@0
|
213 {
|
Chris@16
|
214 return getFrameForX(width()) - 1;
|
Chris@0
|
215 }
|
Chris@0
|
216
|
Chris@0
|
217 void
|
Chris@0
|
218 View::setStartFrame(long f)
|
Chris@0
|
219 {
|
Chris@0
|
220 setCentreFrame(f + m_zoomLevel * (width() / 2));
|
Chris@0
|
221 }
|
Chris@0
|
222
|
Chris@10
|
223 bool
|
Chris@0
|
224 View::setCentreFrame(size_t f, bool e)
|
Chris@0
|
225 {
|
Chris@10
|
226 bool changeVisible = false;
|
Chris@10
|
227
|
Chris@0
|
228 if (m_centreFrame != f) {
|
Chris@0
|
229
|
Chris@0
|
230 int formerPixel = m_centreFrame / m_zoomLevel;
|
Chris@0
|
231
|
Chris@0
|
232 m_centreFrame = f;
|
Chris@0
|
233
|
Chris@0
|
234 int newPixel = m_centreFrame / m_zoomLevel;
|
Chris@0
|
235
|
Chris@0
|
236 if (newPixel != formerPixel) {
|
Chris@0
|
237
|
Chris@0
|
238 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
239 std::cout << "View(" << this << ")::setCentreFrame: newPixel " << newPixel << ", formerPixel " << formerPixel << std::endl;
|
Chris@0
|
240 #endif
|
Chris@0
|
241 update();
|
Chris@10
|
242
|
Chris@10
|
243 changeVisible = true;
|
Chris@0
|
244 }
|
Chris@0
|
245
|
Chris@0
|
246 if (e) emit centreFrameChanged(this, f, m_followPan);
|
Chris@0
|
247 }
|
Chris@10
|
248
|
Chris@10
|
249 return changeVisible;
|
Chris@0
|
250 }
|
Chris@0
|
251
|
Chris@15
|
252 int
|
Chris@15
|
253 View::getXForFrame(long frame) const
|
Chris@15
|
254 {
|
Chris@15
|
255 return (frame - getStartFrame()) / m_zoomLevel;
|
Chris@15
|
256 }
|
Chris@15
|
257
|
Chris@15
|
258 long
|
Chris@15
|
259 View::getFrameForX(int x) const
|
Chris@15
|
260 {
|
Chris@15
|
261 return (long(x) * long(m_zoomLevel)) + getStartFrame();
|
Chris@15
|
262 }
|
Chris@15
|
263
|
Chris@33
|
264 float
|
Chris@33
|
265 View::getYForFrequency(float frequency,
|
Chris@33
|
266 float minf,
|
Chris@33
|
267 float maxf,
|
Chris@33
|
268 bool logarithmic) const
|
Chris@33
|
269 {
|
Chris@33
|
270 int h = height();
|
Chris@33
|
271
|
Chris@33
|
272 if (logarithmic) {
|
Chris@33
|
273
|
Chris@33
|
274 static float lastminf = 0.0, lastmaxf = 0.0;
|
Chris@33
|
275 static float logminf = 0.0, logmaxf = 0.0;
|
Chris@33
|
276
|
Chris@33
|
277 if (lastminf != minf) {
|
Chris@33
|
278 lastminf = (minf == 0.0 ? 1.0 : minf);
|
Chris@33
|
279 logminf = log10f(minf);
|
Chris@33
|
280 }
|
Chris@33
|
281 if (lastmaxf != maxf) {
|
Chris@33
|
282 lastmaxf = (maxf < lastminf ? lastminf : maxf);
|
Chris@33
|
283 logmaxf = log10f(maxf);
|
Chris@33
|
284 }
|
Chris@33
|
285
|
Chris@33
|
286 if (logminf == logmaxf) return 0;
|
Chris@33
|
287 return h - (h * (log10f(frequency) - logminf)) / (logmaxf - logminf);
|
Chris@33
|
288
|
Chris@33
|
289 } else {
|
Chris@33
|
290
|
Chris@33
|
291 if (minf == maxf) return 0;
|
Chris@33
|
292 return h - (h * (frequency - minf)) / (maxf - minf);
|
Chris@33
|
293 }
|
Chris@33
|
294 }
|
Chris@33
|
295
|
Chris@33
|
296 float
|
Chris@33
|
297 View::getFrequencyForY(int y,
|
Chris@33
|
298 float minf,
|
Chris@33
|
299 float maxf,
|
Chris@33
|
300 bool logarithmic) const
|
Chris@33
|
301 {
|
Chris@33
|
302 int h = height();
|
Chris@33
|
303
|
Chris@33
|
304 if (logarithmic) {
|
Chris@33
|
305
|
Chris@33
|
306 static float lastminf = 0.0, lastmaxf = 0.0;
|
Chris@33
|
307 static float logminf = 0.0, logmaxf = 0.0;
|
Chris@33
|
308
|
Chris@33
|
309 if (lastminf != minf) {
|
Chris@33
|
310 lastminf = (minf == 0.0 ? 1.0 : minf);
|
Chris@33
|
311 logminf = log10f(minf);
|
Chris@33
|
312 }
|
Chris@33
|
313 if (lastmaxf != maxf) {
|
Chris@33
|
314 lastmaxf = (maxf < lastminf ? lastminf : maxf);
|
Chris@33
|
315 logmaxf = log10f(maxf);
|
Chris@33
|
316 }
|
Chris@33
|
317
|
Chris@33
|
318 if (logminf == logmaxf) return 0;
|
Chris@33
|
319 return pow(10.f, logminf + ((logmaxf - logminf) * (h - y)) / h);
|
Chris@33
|
320
|
Chris@33
|
321 } else {
|
Chris@33
|
322
|
Chris@33
|
323 if (minf == maxf) return 0;
|
Chris@33
|
324 return minf + ((h - y) * (maxf - minf)) / h;
|
Chris@33
|
325 }
|
Chris@33
|
326 }
|
Chris@33
|
327
|
Chris@22
|
328 int
|
Chris@22
|
329 View::getZoomLevel() const
|
Chris@22
|
330 {
|
Martin@54
|
331 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Martin@54
|
332 std::cout << "zoom level: " << m_zoomLevel << std::endl;
|
Martin@54
|
333 #endif
|
Chris@22
|
334 return m_zoomLevel;
|
Chris@22
|
335 }
|
Chris@22
|
336
|
Chris@0
|
337 void
|
Chris@0
|
338 View::setZoomLevel(size_t z)
|
Chris@0
|
339 {
|
Chris@0
|
340 if (m_zoomLevel != int(z)) {
|
Chris@0
|
341 m_zoomLevel = z;
|
Chris@0
|
342 emit zoomLevelChanged(this, z, m_followZoom);
|
Chris@0
|
343 update();
|
Chris@0
|
344 }
|
Chris@0
|
345 }
|
Chris@0
|
346
|
Chris@16
|
347 View::LayerProgressBar::LayerProgressBar(QWidget *parent) :
|
Chris@16
|
348 QProgressBar(parent)
|
Chris@16
|
349 {
|
Chris@16
|
350 QFont f(font());
|
Chris@16
|
351 f.setPointSize(f.pointSize() * 8 / 10);
|
Chris@16
|
352 setFont(f);
|
Chris@16
|
353 }
|
Chris@16
|
354
|
Chris@0
|
355 void
|
Chris@0
|
356 View::addLayer(Layer *layer)
|
Chris@0
|
357 {
|
Chris@0
|
358 delete m_cache;
|
Chris@0
|
359 m_cache = 0;
|
Chris@0
|
360
|
Chris@0
|
361 m_layers.push_back(layer);
|
Chris@0
|
362
|
Chris@0
|
363 m_progressBars[layer] = new LayerProgressBar(this);
|
Chris@0
|
364 m_progressBars[layer]->setMinimum(0);
|
Chris@0
|
365 m_progressBars[layer]->setMaximum(100);
|
Chris@0
|
366 m_progressBars[layer]->setMinimumWidth(80);
|
Chris@0
|
367 m_progressBars[layer]->hide();
|
Chris@16
|
368
|
Chris@0
|
369 connect(layer, SIGNAL(layerParametersChanged()),
|
Chris@0
|
370 this, SLOT(layerParametersChanged()));
|
Chris@0
|
371 connect(layer, SIGNAL(layerNameChanged()),
|
Chris@0
|
372 this, SLOT(layerNameChanged()));
|
Chris@0
|
373 connect(layer, SIGNAL(modelChanged()),
|
Chris@0
|
374 this, SLOT(modelChanged()));
|
Chris@0
|
375 connect(layer, SIGNAL(modelCompletionChanged()),
|
Chris@0
|
376 this, SLOT(modelCompletionChanged()));
|
Chris@0
|
377 connect(layer, SIGNAL(modelChanged(size_t, size_t)),
|
Chris@0
|
378 this, SLOT(modelChanged(size_t, size_t)));
|
Chris@0
|
379 connect(layer, SIGNAL(modelReplaced()),
|
Chris@0
|
380 this, SLOT(modelReplaced()));
|
Chris@0
|
381
|
Chris@0
|
382 update();
|
Chris@0
|
383
|
Chris@0
|
384 emit propertyContainerAdded(layer);
|
Chris@0
|
385 }
|
Chris@0
|
386
|
Chris@0
|
387 void
|
Chris@0
|
388 View::removeLayer(Layer *layer)
|
Chris@0
|
389 {
|
Chris@0
|
390 if (m_deleting) {
|
Chris@0
|
391 return;
|
Chris@0
|
392 }
|
Chris@0
|
393
|
Chris@0
|
394 delete m_cache;
|
Chris@0
|
395 m_cache = 0;
|
Chris@0
|
396
|
Chris@0
|
397 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@0
|
398 if (*i == layer) {
|
Chris@0
|
399 m_layers.erase(i);
|
Chris@0
|
400 if (m_progressBars.find(layer) != m_progressBars.end()) {
|
Chris@0
|
401 delete m_progressBars[layer];
|
Chris@0
|
402 m_progressBars.erase(layer);
|
Chris@0
|
403 }
|
Chris@0
|
404 break;
|
Chris@0
|
405 }
|
Chris@0
|
406 }
|
Chris@0
|
407
|
Chris@0
|
408 update();
|
Chris@0
|
409
|
Chris@0
|
410 emit propertyContainerRemoved(layer);
|
Chris@0
|
411 }
|
Chris@0
|
412
|
Chris@8
|
413 Layer *
|
Chris@8
|
414 View::getSelectedLayer()
|
Chris@8
|
415 {
|
Chris@8
|
416 if (m_haveSelectedLayer && !m_layers.empty()) {
|
Chris@8
|
417 return getLayer(getLayerCount() - 1);
|
Chris@8
|
418 } else {
|
Chris@8
|
419 return 0;
|
Chris@8
|
420 }
|
Chris@8
|
421 }
|
Chris@8
|
422
|
Chris@36
|
423 const Layer *
|
Chris@36
|
424 View::getSelectedLayer() const
|
Chris@36
|
425 {
|
Chris@36
|
426 return const_cast<const Layer *>(const_cast<View *>(this)->getSelectedLayer());
|
Chris@36
|
427 }
|
Chris@36
|
428
|
Chris@0
|
429 void
|
Chris@0
|
430 View::setViewManager(ViewManager *manager)
|
Chris@0
|
431 {
|
Chris@0
|
432 if (m_manager) {
|
Chris@0
|
433 m_manager->disconnect(this, SLOT(viewManagerCentreFrameChanged(void *, unsigned long, bool)));
|
Chris@0
|
434 m_manager->disconnect(this, SLOT(viewManagerZoomLevelChanged(void *, unsigned long, bool)));
|
Chris@0
|
435 disconnect(m_manager, SIGNAL(centreFrameChanged(void *, unsigned long, bool)));
|
Chris@0
|
436 disconnect(m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)));
|
Chris@8
|
437 disconnect(m_manager, SIGNAL(toolModeChanged()));
|
Chris@8
|
438 disconnect(m_manager, SIGNAL(selectionChanged()));
|
Chris@9
|
439 disconnect(m_manager, SIGNAL(inProgressSelectionChanged()));
|
Chris@0
|
440 }
|
Chris@0
|
441
|
Chris@0
|
442 m_manager = manager;
|
Chris@0
|
443 if (m_followPan) setCentreFrame(m_manager->getGlobalCentreFrame(), false);
|
Chris@0
|
444 if (m_followZoom) setZoomLevel(m_manager->getGlobalZoom());
|
Chris@0
|
445
|
Chris@0
|
446 connect(m_manager, SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
|
Chris@0
|
447 this, SLOT(viewManagerCentreFrameChanged(void *, unsigned long, bool)));
|
Chris@0
|
448 connect(m_manager, SIGNAL(playbackFrameChanged(unsigned long)),
|
Chris@0
|
449 this, SLOT(viewManagerPlaybackFrameChanged(unsigned long)));
|
Chris@0
|
450 connect(m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)),
|
Chris@0
|
451 this, SLOT(viewManagerZoomLevelChanged(void *, unsigned long, bool)));
|
Chris@8
|
452 connect(m_manager, SIGNAL(toolModeChanged()),
|
Chris@8
|
453 this, SLOT(toolModeChanged()));
|
Chris@8
|
454 connect(m_manager, SIGNAL(selectionChanged()),
|
Chris@9
|
455 this, SLOT(selectionChanged()));
|
Chris@9
|
456 connect(m_manager, SIGNAL(inProgressSelectionChanged()),
|
Chris@9
|
457 this, SLOT(selectionChanged()));
|
Chris@0
|
458
|
Chris@0
|
459 connect(this, SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
|
Chris@0
|
460 m_manager, SIGNAL(centreFrameChanged(void *, unsigned long, bool)));
|
Chris@0
|
461 connect(this, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)),
|
Chris@0
|
462 m_manager, SIGNAL(zoomLevelChanged(void *, unsigned long, bool)));
|
Chris@8
|
463
|
Chris@8
|
464 toolModeChanged();
|
Chris@0
|
465 }
|
Chris@0
|
466
|
Chris@0
|
467 void
|
Chris@0
|
468 View::setFollowGlobalPan(bool f)
|
Chris@0
|
469 {
|
Chris@0
|
470 m_followPan = f;
|
Chris@29
|
471 emit propertyContainerPropertyChanged(m_propertyContainer);
|
Chris@0
|
472 }
|
Chris@0
|
473
|
Chris@0
|
474 void
|
Chris@0
|
475 View::setFollowGlobalZoom(bool f)
|
Chris@0
|
476 {
|
Chris@0
|
477 m_followZoom = f;
|
Chris@29
|
478 emit propertyContainerPropertyChanged(m_propertyContainer);
|
Chris@0
|
479 }
|
Chris@0
|
480
|
Chris@0
|
481 void
|
Chris@46
|
482 View::drawVisibleText(QPainter &paint, int x, int y, QString text, TextStyle style)
|
Chris@45
|
483 {
|
Chris@46
|
484 if (style == OutlinedText) {
|
Chris@46
|
485
|
Chris@46
|
486 QColor origPenColour = paint.pen().color();
|
Chris@46
|
487 QColor penColour = origPenColour;
|
Chris@46
|
488 QColor surroundColour = Qt::white; //palette().background().color();
|
Chris@46
|
489
|
Chris@46
|
490 if (!hasLightBackground()) {
|
Chris@46
|
491 int h, s, v;
|
Chris@46
|
492 penColour.getHsv(&h, &s, &v);
|
Chris@46
|
493 penColour = QColor::fromHsv(h, s, 255 - v);
|
Chris@46
|
494 surroundColour = Qt::black;
|
Chris@46
|
495 }
|
Chris@46
|
496
|
Chris@46
|
497 paint.setPen(surroundColour);
|
Chris@46
|
498
|
Chris@46
|
499 for (int dx = -1; dx <= 1; ++dx) {
|
Chris@46
|
500 for (int dy = -1; dy <= 1; ++dy) {
|
Chris@46
|
501 if (!(dx || dy)) continue;
|
Chris@46
|
502 paint.drawText(x + dx, y + dy, text);
|
Chris@46
|
503 }
|
Chris@46
|
504 }
|
Chris@46
|
505
|
Chris@46
|
506 paint.setPen(penColour);
|
Chris@46
|
507
|
Chris@46
|
508 paint.drawText(x, y, text);
|
Chris@46
|
509
|
Chris@46
|
510 paint.setPen(origPenColour);
|
Chris@46
|
511
|
Chris@46
|
512 } else {
|
Chris@46
|
513
|
Chris@46
|
514 std::cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << std::endl;
|
Chris@46
|
515 }
|
Chris@45
|
516 }
|
Chris@45
|
517
|
Chris@45
|
518 void
|
Chris@0
|
519 View::setPlaybackFollow(PlaybackFollowMode m)
|
Chris@0
|
520 {
|
Chris@0
|
521 m_followPlay = m;
|
Chris@29
|
522 emit propertyContainerPropertyChanged(m_propertyContainer);
|
Chris@0
|
523 }
|
Chris@0
|
524
|
Chris@0
|
525 void
|
Chris@0
|
526 View::modelChanged()
|
Chris@0
|
527 {
|
Chris@0
|
528 QObject *obj = sender();
|
Chris@0
|
529
|
Chris@0
|
530 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1
|
531 std::cerr << "View(" << this << ")::modelChanged()" << std::endl;
|
Chris@0
|
532 #endif
|
Chris@31
|
533
|
Chris@31
|
534 // If the model that has changed is not used by any of the cached
|
Chris@31
|
535 // layers, we won't need to recreate the cache
|
Chris@31
|
536
|
Chris@31
|
537 bool recreate = false;
|
Chris@31
|
538
|
Chris@31
|
539 bool discard;
|
Chris@31
|
540 LayerList scrollables = getScrollableBackLayers(false, discard);
|
Chris@31
|
541 for (LayerList::const_iterator i = scrollables.begin();
|
Chris@31
|
542 i != scrollables.end(); ++i) {
|
Chris@31
|
543 if (*i == obj || (*i)->getModel() == obj) {
|
Chris@31
|
544 recreate = true;
|
Chris@31
|
545 break;
|
Chris@31
|
546 }
|
Chris@31
|
547 }
|
Chris@31
|
548
|
Chris@31
|
549 if (recreate) {
|
Chris@31
|
550 delete m_cache;
|
Chris@31
|
551 m_cache = 0;
|
Chris@31
|
552 }
|
Chris@0
|
553
|
Chris@0
|
554 checkProgress(obj);
|
Chris@0
|
555
|
Chris@0
|
556 update();
|
Chris@0
|
557 }
|
Chris@0
|
558
|
Chris@0
|
559 void
|
Chris@0
|
560 View::modelChanged(size_t startFrame, size_t endFrame)
|
Chris@0
|
561 {
|
Chris@0
|
562 QObject *obj = sender();
|
Chris@0
|
563
|
Chris@0
|
564 long myStartFrame = getStartFrame();
|
Chris@0
|
565 size_t myEndFrame = getEndFrame();
|
Chris@0
|
566
|
Chris@1
|
567 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1
|
568 std::cerr << "View(" << this << ")::modelChanged(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << std::endl;
|
Chris@1
|
569 #endif
|
Chris@1
|
570
|
Chris@0
|
571 if (myStartFrame > 0 && endFrame < size_t(myStartFrame)) {
|
Chris@0
|
572 checkProgress(obj);
|
Chris@0
|
573 return;
|
Chris@0
|
574 }
|
Chris@0
|
575 if (startFrame > myEndFrame) {
|
Chris@0
|
576 checkProgress(obj);
|
Chris@0
|
577 return;
|
Chris@0
|
578 }
|
Chris@0
|
579
|
Chris@31
|
580 // If the model that has changed is not used by any of the cached
|
Chris@31
|
581 // layers, we won't need to recreate the cache
|
Chris@31
|
582
|
Chris@31
|
583 bool recreate = false;
|
Chris@31
|
584
|
Chris@31
|
585 bool discard;
|
Chris@31
|
586 LayerList scrollables = getScrollableBackLayers(false, discard);
|
Chris@31
|
587 for (LayerList::const_iterator i = scrollables.begin();
|
Chris@31
|
588 i != scrollables.end(); ++i) {
|
Chris@31
|
589 if (*i == obj || (*i)->getModel() == obj) {
|
Chris@31
|
590 recreate = true;
|
Chris@31
|
591 break;
|
Chris@31
|
592 }
|
Chris@31
|
593 }
|
Chris@31
|
594
|
Chris@31
|
595 if (recreate) {
|
Chris@31
|
596 delete m_cache;
|
Chris@31
|
597 m_cache = 0;
|
Chris@31
|
598 }
|
Chris@0
|
599
|
Chris@0
|
600 if (long(startFrame) < myStartFrame) startFrame = myStartFrame;
|
Chris@0
|
601 if (endFrame > myEndFrame) endFrame = myEndFrame;
|
Chris@0
|
602
|
Chris@15
|
603 int x0 = getXForFrame(startFrame);
|
Chris@15
|
604 int x1 = getXForFrame(endFrame + 1);
|
Chris@15
|
605 if (x1 < x0) x1 = x0;
|
Chris@0
|
606
|
Chris@0
|
607 checkProgress(obj);
|
Chris@0
|
608
|
Chris@31
|
609 update();
|
Chris@31
|
610 //!! update(x0, 0, x1 - x0 + 1, height());
|
Chris@0
|
611 }
|
Chris@0
|
612
|
Chris@0
|
613 void
|
Chris@0
|
614 View::modelCompletionChanged()
|
Chris@0
|
615 {
|
Chris@0
|
616 QObject *obj = sender();
|
Chris@0
|
617 checkProgress(obj);
|
Chris@0
|
618 }
|
Chris@0
|
619
|
Chris@0
|
620 void
|
Chris@0
|
621 View::modelReplaced()
|
Chris@0
|
622 {
|
Chris@0
|
623 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1
|
624 std::cerr << "View(" << this << ")::modelReplaced()" << std::endl;
|
Chris@0
|
625 #endif
|
Chris@1
|
626 delete m_cache;
|
Chris@1
|
627 m_cache = 0;
|
Chris@1
|
628
|
Chris@0
|
629 update();
|
Chris@0
|
630 }
|
Chris@0
|
631
|
Chris@0
|
632 void
|
Chris@0
|
633 View::layerParametersChanged()
|
Chris@0
|
634 {
|
Chris@0
|
635 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@0
|
636
|
Chris@0
|
637 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
638 std::cerr << "View::layerParametersChanged()" << std::endl;
|
Chris@0
|
639 #endif
|
Chris@0
|
640
|
Chris@0
|
641 delete m_cache;
|
Chris@0
|
642 m_cache = 0;
|
Chris@0
|
643 update();
|
Chris@0
|
644
|
Chris@0
|
645 if (layer) {
|
Chris@0
|
646 emit propertyContainerPropertyChanged(layer);
|
Chris@0
|
647 }
|
Chris@0
|
648 }
|
Chris@0
|
649
|
Chris@0
|
650 void
|
Chris@0
|
651 View::layerNameChanged()
|
Chris@0
|
652 {
|
Chris@0
|
653 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@0
|
654 if (layer) emit propertyContainerNameChanged(layer);
|
Chris@0
|
655 }
|
Chris@0
|
656
|
Chris@0
|
657 void
|
Chris@0
|
658 View::viewManagerCentreFrameChanged(void *p, unsigned long f, bool locked)
|
Chris@0
|
659 {
|
Chris@0
|
660 if (m_followPan && p != this && locked) {
|
Chris@0
|
661 if (m_manager && (sender() == m_manager)) {
|
Chris@0
|
662 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
663 std::cerr << this << ": manager frame changed " << f << " from " << p << std::endl;
|
Chris@0
|
664 #endif
|
Chris@0
|
665 setCentreFrame(f);
|
Chris@0
|
666 if (p == this) repaint();
|
Chris@0
|
667 }
|
Chris@0
|
668 }
|
Chris@0
|
669 }
|
Chris@0
|
670
|
Chris@0
|
671 void
|
Chris@0
|
672 View::viewManagerPlaybackFrameChanged(unsigned long f)
|
Chris@0
|
673 {
|
Chris@0
|
674 if (m_manager) {
|
Chris@0
|
675 if (sender() != m_manager) return;
|
Chris@0
|
676 }
|
Chris@0
|
677
|
Chris@0
|
678 if (m_playPointerFrame == f) return;
|
Chris@15
|
679 bool visible = (getXForFrame(m_playPointerFrame) != getXForFrame(f));
|
Chris@0
|
680 size_t oldPlayPointerFrame = m_playPointerFrame;
|
Chris@0
|
681 m_playPointerFrame = f;
|
Chris@0
|
682 if (!visible) return;
|
Chris@0
|
683
|
Chris@21
|
684 bool modifierPressed = // we only care about these ones
|
Chris@21
|
685 ((QApplication::keyboardModifiers() & Qt::ShiftModifier) ||
|
Chris@21
|
686 (QApplication::keyboardModifiers() & Qt::ControlModifier));
|
Chris@20
|
687
|
Chris@0
|
688 switch (m_followPlay) {
|
Chris@0
|
689
|
Chris@0
|
690 case PlaybackScrollContinuous:
|
Chris@10
|
691 if (QApplication::mouseButtons() == Qt::NoButton &&
|
Chris@21
|
692 !modifierPressed) {
|
Chris@0
|
693 setCentreFrame(f, false);
|
Chris@0
|
694 }
|
Chris@0
|
695 break;
|
Chris@0
|
696
|
Chris@0
|
697 case PlaybackScrollPage:
|
Chris@0
|
698 {
|
Chris@15
|
699 int xold = getXForFrame(oldPlayPointerFrame);
|
Chris@10
|
700 repaint(xold - 1, 0, 3, height());
|
Chris@10
|
701
|
Chris@15
|
702 long w = getEndFrame() - getStartFrame();
|
Chris@0
|
703 w -= w/5;
|
Chris@0
|
704 long sf = (f / w) * w - w/8;
|
Chris@10
|
705
|
Chris@10
|
706 if (m_manager &&
|
Chris@10
|
707 m_manager->isPlaying() &&
|
Chris@10
|
708 m_manager->getPlaySelectionMode()) {
|
Chris@24
|
709 MultiSelection::SelectionList selections = m_manager->getSelections();
|
Chris@10
|
710 if (!selections.empty()) {
|
Chris@10
|
711 size_t selectionStart = selections.begin()->getStartFrame();
|
Chris@10
|
712 if (sf < long(selectionStart) - w / 10) {
|
Chris@10
|
713 sf = long(selectionStart) - w / 10;
|
Chris@10
|
714 }
|
Chris@10
|
715 }
|
Chris@10
|
716 }
|
Chris@10
|
717
|
Chris@0
|
718 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
719 std::cerr << "PlaybackScrollPage: f = " << f << ", sf = " << sf << ", start frame "
|
Chris@0
|
720 << getStartFrame() << std::endl;
|
Chris@0
|
721 #endif
|
Chris@10
|
722
|
Chris@15
|
723 // We don't consider scrolling unless the pointer is outside
|
Chris@15
|
724 // the clearly visible range already
|
Chris@15
|
725
|
Chris@15
|
726 int xnew = getXForFrame(m_playPointerFrame);
|
Chris@15
|
727
|
Chris@18
|
728 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@18
|
729 std::cerr << "xnew = " << xnew << ", width = " << width() << std::endl;
|
Chris@18
|
730 #endif
|
Chris@18
|
731
|
Chris@15
|
732 if (xnew < width()/8 || xnew > (width()*7)/8) {
|
Chris@15
|
733 if (QApplication::mouseButtons() == Qt::NoButton &&
|
Chris@21
|
734 !modifierPressed) {
|
Chris@15
|
735 long offset = getFrameForX(width()/2) - getStartFrame();
|
Chris@15
|
736 long newCentre = sf + offset;
|
Chris@15
|
737 bool changed = setCentreFrame(newCentre, false);
|
Chris@15
|
738 if (changed) {
|
Chris@15
|
739 xold = getXForFrame(oldPlayPointerFrame);
|
Chris@15
|
740 update(xold - 1, 0, 3, height());
|
Chris@15
|
741 }
|
Chris@10
|
742 }
|
Chris@10
|
743 }
|
Chris@10
|
744
|
Chris@0
|
745 update(xnew - 1, 0, 3, height());
|
Chris@10
|
746
|
Chris@0
|
747 break;
|
Chris@0
|
748 }
|
Chris@0
|
749
|
Chris@0
|
750 case PlaybackIgnore:
|
Chris@0
|
751 if (long(f) >= getStartFrame() && f < getEndFrame()) {
|
Chris@0
|
752 update();
|
Chris@0
|
753 }
|
Chris@0
|
754 break;
|
Chris@0
|
755 }
|
Chris@0
|
756 }
|
Chris@0
|
757
|
Chris@0
|
758 void
|
Chris@0
|
759 View::viewManagerZoomLevelChanged(void *p, unsigned long z, bool locked)
|
Chris@0
|
760 {
|
Chris@0
|
761 if (m_followZoom && p != this && locked) {
|
Chris@0
|
762 if (m_manager && (sender() == m_manager)) {
|
Chris@0
|
763 setZoomLevel(z);
|
Chris@0
|
764 if (p == this) repaint();
|
Chris@0
|
765 }
|
Chris@0
|
766 }
|
Chris@0
|
767 }
|
Chris@0
|
768
|
Chris@9
|
769 void
|
Chris@9
|
770 View::selectionChanged()
|
Chris@9
|
771 {
|
Chris@9
|
772 if (m_selectionCached) {
|
Chris@9
|
773 delete m_cache;
|
Chris@9
|
774 m_cache = 0;
|
Chris@9
|
775 m_selectionCached = false;
|
Chris@9
|
776 }
|
Chris@9
|
777 update();
|
Chris@9
|
778 }
|
Chris@9
|
779
|
Chris@0
|
780 size_t
|
Chris@0
|
781 View::getModelsStartFrame() const
|
Chris@0
|
782 {
|
Chris@0
|
783 bool first = true;
|
Chris@0
|
784 size_t startFrame = 0;
|
Chris@0
|
785
|
Chris@0
|
786 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@0
|
787
|
Chris@0
|
788 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
|
Chris@0
|
789
|
Chris@0
|
790 size_t thisStartFrame = (*i)->getModel()->getStartFrame();
|
Chris@0
|
791
|
Chris@0
|
792 if (first || thisStartFrame < startFrame) {
|
Chris@0
|
793 startFrame = thisStartFrame;
|
Chris@0
|
794 }
|
Chris@0
|
795 first = false;
|
Chris@0
|
796 }
|
Chris@0
|
797 }
|
Chris@0
|
798 return startFrame;
|
Chris@0
|
799 }
|
Chris@0
|
800
|
Chris@0
|
801 size_t
|
Chris@0
|
802 View::getModelsEndFrame() const
|
Chris@0
|
803 {
|
Chris@0
|
804 bool first = true;
|
Chris@0
|
805 size_t endFrame = 0;
|
Chris@0
|
806
|
Chris@0
|
807 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@0
|
808
|
Chris@0
|
809 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
|
Chris@0
|
810
|
Chris@0
|
811 size_t thisEndFrame = (*i)->getModel()->getEndFrame();
|
Chris@0
|
812
|
Chris@0
|
813 if (first || thisEndFrame > endFrame) {
|
Chris@0
|
814 endFrame = thisEndFrame;
|
Chris@0
|
815 }
|
Chris@0
|
816 first = false;
|
Chris@0
|
817 }
|
Chris@0
|
818 }
|
Chris@0
|
819
|
Chris@0
|
820 if (first) return getModelsStartFrame();
|
Chris@0
|
821 return endFrame;
|
Chris@0
|
822 }
|
Chris@0
|
823
|
Chris@0
|
824 int
|
Chris@0
|
825 View::getModelsSampleRate() const
|
Chris@0
|
826 {
|
Chris@0
|
827 //!!! Just go for the first, for now. If we were supporting
|
Chris@0
|
828 // multiple samplerates, we'd probably want to do frame/time
|
Chris@0
|
829 // conversion in the model
|
Chris@0
|
830
|
Chris@0
|
831 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@0
|
832 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
|
Chris@0
|
833 return (*i)->getModel()->getSampleRate();
|
Chris@0
|
834 }
|
Chris@0
|
835 }
|
Chris@0
|
836 return 0;
|
Chris@0
|
837 }
|
Chris@0
|
838
|
Chris@0
|
839 bool
|
Chris@0
|
840 View::areLayersScrollable() const
|
Chris@0
|
841 {
|
Chris@0
|
842 // True iff all views are scrollable
|
Chris@0
|
843 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@36
|
844 if (!(*i)->isLayerScrollable(this)) return false;
|
Chris@0
|
845 }
|
Chris@0
|
846 return true;
|
Chris@0
|
847 }
|
Chris@0
|
848
|
Chris@0
|
849 View::LayerList
|
Chris@31
|
850 View::getScrollableBackLayers(bool testChanged, bool &changed) const
|
Chris@0
|
851 {
|
Chris@0
|
852 changed = false;
|
Chris@0
|
853
|
Chris@46
|
854 // We want a list of all the scrollable layers that are behind the
|
Chris@46
|
855 // backmost non-scrollable layer.
|
Chris@46
|
856
|
Chris@0
|
857 LayerList scrollables;
|
Chris@0
|
858 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@36
|
859 if ((*i)->isLayerDormant(this)) continue;
|
Chris@46
|
860 if ((*i)->isLayerOpaque()) {
|
Chris@46
|
861 // You can't see anything behind an opaque layer!
|
Chris@46
|
862 scrollables.clear();
|
Chris@46
|
863 }
|
Chris@36
|
864 if ((*i)->isLayerScrollable(this)) scrollables.push_back(*i);
|
Chris@46
|
865 else break;
|
Chris@0
|
866 }
|
Chris@0
|
867
|
Chris@31
|
868 if (testChanged && scrollables != m_lastScrollableBackLayers) {
|
Chris@0
|
869 m_lastScrollableBackLayers = scrollables;
|
Chris@0
|
870 changed = true;
|
Chris@0
|
871 }
|
Chris@0
|
872 return scrollables;
|
Chris@0
|
873 }
|
Chris@0
|
874
|
Chris@0
|
875 View::LayerList
|
Chris@31
|
876 View::getNonScrollableFrontLayers(bool testChanged, bool &changed) const
|
Chris@0
|
877 {
|
Chris@0
|
878 changed = false;
|
Chris@31
|
879 LayerList scrollables = getScrollableBackLayers(testChanged, changed);
|
Chris@0
|
880 LayerList nonScrollables;
|
Chris@0
|
881
|
Chris@0
|
882 // Everything in front of the first non-scrollable from the back
|
Chris@0
|
883 // should also be considered non-scrollable
|
Chris@0
|
884
|
Chris@46
|
885 bool started = false;
|
Chris@46
|
886
|
Chris@0
|
887 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@36
|
888 if ((*i)->isLayerDormant(this)) continue;
|
Chris@46
|
889 if (!started && (*i)->isLayerScrollable(this)) {
|
Chris@0
|
890 continue;
|
Chris@0
|
891 }
|
Chris@46
|
892 started = true;
|
Chris@46
|
893 if ((*i)->isLayerOpaque()) {
|
Chris@46
|
894 // You can't see anything behind an opaque layer!
|
Chris@46
|
895 nonScrollables.clear();
|
Chris@46
|
896 }
|
Chris@0
|
897 nonScrollables.push_back(*i);
|
Chris@0
|
898 }
|
Chris@0
|
899
|
Chris@31
|
900 if (testChanged && nonScrollables != m_lastNonScrollableBackLayers) {
|
Chris@0
|
901 m_lastNonScrollableBackLayers = nonScrollables;
|
Chris@0
|
902 changed = true;
|
Chris@0
|
903 }
|
Chris@0
|
904
|
Chris@0
|
905 return nonScrollables;
|
Chris@0
|
906 }
|
Chris@0
|
907
|
Chris@0
|
908 size_t
|
Chris@0
|
909 View::getZoomConstraintBlockSize(size_t blockSize,
|
Chris@0
|
910 ZoomConstraint::RoundingDirection dir)
|
Chris@0
|
911 const
|
Chris@0
|
912 {
|
Chris@0
|
913 size_t candidate = blockSize;
|
Chris@0
|
914 bool haveCandidate = false;
|
Chris@0
|
915
|
Chris@25
|
916 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint;
|
Chris@25
|
917
|
Chris@0
|
918 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@0
|
919
|
Chris@25
|
920 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint();
|
Chris@25
|
921 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint;
|
Chris@0
|
922
|
Chris@25
|
923 size_t thisBlockSize =
|
Chris@25
|
924 zoomConstraint->getNearestBlockSize(blockSize, dir);
|
Chris@0
|
925
|
Chris@25
|
926 // Go for the block size that's furthest from the one
|
Chris@25
|
927 // passed in. Most of the time, that's what we want.
|
Chris@25
|
928 if (!haveCandidate ||
|
Chris@25
|
929 (thisBlockSize > blockSize && thisBlockSize > candidate) ||
|
Chris@25
|
930 (thisBlockSize < blockSize && thisBlockSize < candidate)) {
|
Chris@25
|
931 candidate = thisBlockSize;
|
Chris@25
|
932 haveCandidate = true;
|
Chris@0
|
933 }
|
Chris@0
|
934 }
|
Chris@0
|
935
|
Chris@0
|
936 return candidate;
|
Chris@0
|
937 }
|
Chris@0
|
938
|
Chris@0
|
939 void
|
Chris@0
|
940 View::zoom(bool in)
|
Chris@0
|
941 {
|
Chris@0
|
942 int newZoomLevel = m_zoomLevel;
|
Chris@0
|
943
|
Chris@0
|
944 if (in) {
|
Chris@0
|
945 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
Chris@0
|
946 ZoomConstraint::RoundDown);
|
Chris@0
|
947 } else {
|
Chris@0
|
948 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
Chris@0
|
949 ZoomConstraint::RoundUp);
|
Chris@0
|
950 }
|
Chris@0
|
951
|
Chris@0
|
952 if (newZoomLevel != m_zoomLevel) {
|
Chris@0
|
953 setZoomLevel(newZoomLevel);
|
Chris@0
|
954 }
|
Chris@0
|
955 }
|
Chris@0
|
956
|
Chris@0
|
957 void
|
Chris@12
|
958 View::scroll(bool right, bool lots)
|
Chris@12
|
959 {
|
Chris@12
|
960 long delta;
|
Chris@12
|
961 if (lots) {
|
Chris@15
|
962 delta = (getEndFrame() - getStartFrame()) / 2;
|
Chris@12
|
963 } else {
|
Chris@15
|
964 delta = (getEndFrame() - getStartFrame()) / 20;
|
Chris@12
|
965 }
|
Chris@12
|
966 if (right) delta = -delta;
|
Chris@12
|
967
|
Chris@12
|
968 if (int(m_centreFrame) < delta) {
|
Chris@12
|
969 setCentreFrame(0);
|
Chris@12
|
970 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
|
Chris@12
|
971 setCentreFrame(getModelsEndFrame());
|
Chris@12
|
972 } else {
|
Chris@12
|
973 setCentreFrame(m_centreFrame - delta);
|
Chris@12
|
974 }
|
Chris@12
|
975 }
|
Chris@12
|
976
|
Chris@12
|
977 void
|
Chris@0
|
978 View::checkProgress(void *object)
|
Chris@0
|
979 {
|
Chris@0
|
980 if (!m_showProgress) return;
|
Chris@0
|
981
|
Chris@0
|
982 int ph = height();
|
Chris@0
|
983
|
Chris@0
|
984 for (ProgressMap::const_iterator i = m_progressBars.begin();
|
Chris@0
|
985 i != m_progressBars.end(); ++i) {
|
Chris@0
|
986
|
Chris@0
|
987 if (i->first == object) {
|
Chris@0
|
988
|
Chris@0
|
989 int completion = i->first->getCompletion();
|
Chris@0
|
990
|
Chris@0
|
991 if (completion >= 100) {
|
Chris@0
|
992
|
Chris@0
|
993 i->second->hide();
|
Chris@0
|
994
|
Chris@0
|
995 } else {
|
Chris@0
|
996
|
Chris@0
|
997 i->second->setText(i->first->getPropertyContainerName());
|
Chris@0
|
998 i->second->setValue(completion);
|
Chris@0
|
999 i->second->move(0, ph - i->second->height());
|
Chris@0
|
1000
|
Chris@0
|
1001 i->second->show();
|
Chris@0
|
1002 i->second->update();
|
Chris@0
|
1003
|
Chris@0
|
1004 ph -= i->second->height();
|
Chris@0
|
1005 }
|
Chris@0
|
1006 } else {
|
Chris@0
|
1007 if (i->second->isVisible()) {
|
Chris@0
|
1008 ph -= i->second->height();
|
Chris@0
|
1009 }
|
Chris@0
|
1010 }
|
Chris@0
|
1011 }
|
Chris@0
|
1012 }
|
Chris@0
|
1013
|
Chris@0
|
1014 void
|
Chris@0
|
1015 View::paintEvent(QPaintEvent *e)
|
Chris@0
|
1016 {
|
Chris@0
|
1017 // Profiler prof("View::paintEvent", true);
|
Chris@0
|
1018 // std::cerr << "View::paintEvent" << std::endl;
|
Chris@0
|
1019
|
Chris@0
|
1020 if (m_layers.empty()) {
|
Chris@0
|
1021 QFrame::paintEvent(e);
|
Chris@0
|
1022 return;
|
Chris@0
|
1023 }
|
Chris@0
|
1024
|
Chris@0
|
1025 // ensure our constraints are met
|
Chris@0
|
1026 m_zoomLevel = getZoomConstraintBlockSize(m_zoomLevel,
|
Chris@0
|
1027 ZoomConstraint::RoundUp);
|
Chris@0
|
1028
|
Chris@0
|
1029 QPainter paint;
|
Chris@0
|
1030 bool repaintCache = false;
|
Chris@0
|
1031 bool paintedCacheRect = false;
|
Chris@0
|
1032
|
Chris@0
|
1033 QRect cacheRect(rect());
|
Chris@0
|
1034
|
Chris@0
|
1035 if (e) {
|
Chris@0
|
1036 cacheRect &= e->rect();
|
Chris@0
|
1037 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1038 std::cerr << "paint rect " << cacheRect.width() << "x" << cacheRect.height()
|
Chris@0
|
1039 << ", my rect " << width() << "x" << height() << std::endl;
|
Chris@0
|
1040 #endif
|
Chris@0
|
1041 }
|
Chris@0
|
1042
|
Chris@0
|
1043 QRect nonCacheRect(cacheRect);
|
Chris@0
|
1044
|
Chris@0
|
1045 // If not all layers are scrollable, but some of the back layers
|
Chris@46
|
1046 // are, we should store only those in the cache.
|
Chris@0
|
1047
|
Chris@0
|
1048 bool layersChanged = false;
|
Chris@31
|
1049 LayerList scrollables = getScrollableBackLayers(true, layersChanged);
|
Chris@31
|
1050 LayerList nonScrollables = getNonScrollableFrontLayers(true, layersChanged);
|
Chris@9
|
1051 bool selectionCacheable = nonScrollables.empty();
|
Chris@9
|
1052 bool haveSelections = m_manager && !m_manager->getSelections().empty();
|
Chris@9
|
1053 bool selectionDrawn = false;
|
Chris@0
|
1054
|
Chris@46
|
1055 // If all the non-scrollable layers are non-opaque, then we draw
|
Chris@46
|
1056 // the selection rectangle behind them and cache it. If any are
|
Chris@46
|
1057 // opaque, however, we can't cache.
|
Chris@46
|
1058 //
|
Chris@10
|
1059 if (!selectionCacheable) {
|
Chris@10
|
1060 selectionCacheable = true;
|
Chris@10
|
1061 for (LayerList::const_iterator i = nonScrollables.begin();
|
Chris@10
|
1062 i != nonScrollables.end(); ++i) {
|
Chris@10
|
1063 if ((*i)->isLayerOpaque()) {
|
Chris@10
|
1064 selectionCacheable = false;
|
Chris@10
|
1065 break;
|
Chris@10
|
1066 }
|
Chris@10
|
1067 }
|
Chris@10
|
1068 }
|
Chris@10
|
1069
|
Chris@34
|
1070 if (selectionCacheable) {
|
Chris@34
|
1071 QPoint localPos;
|
Chris@34
|
1072 bool closeToLeft, closeToRight;
|
Chris@34
|
1073 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) {
|
Chris@34
|
1074 selectionCacheable = false;
|
Chris@34
|
1075 }
|
Chris@34
|
1076 }
|
Chris@34
|
1077
|
Chris@0
|
1078 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1079 std::cerr << "View(" << this << ")::paintEvent: have " << scrollables.size()
|
Chris@0
|
1080 << " scrollable back layers and " << nonScrollables.size()
|
Chris@0
|
1081 << " non-scrollable front layers" << std::endl;
|
Chris@9
|
1082 std::cerr << "haveSelections " << haveSelections << ", selectionCacheable "
|
Chris@9
|
1083 << selectionCacheable << ", m_selectionCached " << m_selectionCached << std::endl;
|
Chris@0
|
1084 #endif
|
Chris@0
|
1085
|
Chris@9
|
1086 if (layersChanged || scrollables.empty() ||
|
Chris@9
|
1087 (haveSelections && (selectionCacheable != m_selectionCached))) {
|
Chris@0
|
1088 delete m_cache;
|
Chris@0
|
1089 m_cache = 0;
|
Chris@9
|
1090 m_selectionCached = false;
|
Chris@0
|
1091 }
|
Chris@0
|
1092
|
Chris@0
|
1093 if (!scrollables.empty()) {
|
Chris@0
|
1094 if (!m_cache ||
|
Chris@0
|
1095 m_cacheZoomLevel != m_zoomLevel ||
|
Chris@0
|
1096 width() != m_cache->width() ||
|
Chris@0
|
1097 height() != m_cache->height()) {
|
Chris@0
|
1098
|
Chris@0
|
1099 // cache is not valid
|
Chris@0
|
1100
|
Chris@0
|
1101 if (cacheRect.width() < width()/10) {
|
Chris@0
|
1102 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1103 std::cerr << "View(" << this << ")::paintEvent: small repaint, not bothering to recreate cache" << std::endl;
|
Chris@0
|
1104 #endif
|
Chris@0
|
1105 } else {
|
Chris@0
|
1106 delete m_cache;
|
Chris@0
|
1107 m_cache = new QPixmap(width(), height());
|
Chris@0
|
1108 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1109 std::cerr << "View(" << this << ")::paintEvent: recreated cache" << std::endl;
|
Chris@0
|
1110 #endif
|
Chris@0
|
1111 cacheRect = rect();
|
Chris@0
|
1112 repaintCache = true;
|
Chris@0
|
1113 }
|
Chris@0
|
1114
|
Chris@0
|
1115 } else if (m_cacheCentreFrame != m_centreFrame) {
|
Chris@0
|
1116
|
Chris@15
|
1117 long dx =
|
Chris@15
|
1118 getXForFrame(m_cacheCentreFrame) -
|
Chris@15
|
1119 getXForFrame(m_centreFrame);
|
Chris@0
|
1120
|
Chris@0
|
1121 if (dx > -width() && dx < width()) {
|
Chris@0
|
1122 #if defined(Q_WS_WIN32) || defined(Q_WS_MAC)
|
Chris@0
|
1123 // Copying a pixmap to itself doesn't work properly on Windows
|
Chris@0
|
1124 // or Mac (it only works when moving in one direction)
|
Chris@0
|
1125 static QPixmap *tmpPixmap = 0;
|
Chris@0
|
1126 if (!tmpPixmap ||
|
Chris@0
|
1127 tmpPixmap->width() != width() ||
|
Chris@0
|
1128 tmpPixmap->height() != height()) {
|
Chris@0
|
1129 delete tmpPixmap;
|
Chris@0
|
1130 tmpPixmap = new QPixmap(width(), height());
|
Chris@0
|
1131 }
|
Chris@0
|
1132 paint.begin(tmpPixmap);
|
Chris@0
|
1133 paint.drawPixmap(0, 0, *m_cache);
|
Chris@0
|
1134 paint.end();
|
Chris@0
|
1135 paint.begin(m_cache);
|
Chris@0
|
1136 paint.drawPixmap(dx, 0, *tmpPixmap);
|
Chris@0
|
1137 paint.end();
|
Chris@0
|
1138 #else
|
Chris@0
|
1139 // But it seems to be fine on X11
|
Chris@0
|
1140 paint.begin(m_cache);
|
Chris@0
|
1141 paint.drawPixmap(dx, 0, *m_cache);
|
Chris@0
|
1142 paint.end();
|
Chris@0
|
1143 #endif
|
Chris@0
|
1144
|
Chris@0
|
1145 if (dx < 0) {
|
Chris@0
|
1146 cacheRect = QRect(width() + dx, 0, -dx, height());
|
Chris@0
|
1147 } else {
|
Chris@0
|
1148 cacheRect = QRect(0, 0, dx, height());
|
Chris@0
|
1149 }
|
Chris@0
|
1150 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1151 std::cerr << "View(" << this << ")::paintEvent: scrolled cache by " << dx << std::endl;
|
Chris@0
|
1152 #endif
|
Chris@0
|
1153 } else {
|
Chris@0
|
1154 cacheRect = rect();
|
Chris@0
|
1155 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1156 std::cerr << "View(" << this << ")::paintEvent: scrolling too far" << std::endl;
|
Chris@0
|
1157 #endif
|
Chris@0
|
1158 }
|
Chris@0
|
1159 repaintCache = true;
|
Chris@0
|
1160
|
Chris@0
|
1161 } else {
|
Chris@0
|
1162 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1163 std::cerr << "View(" << this << ")::paintEvent: cache is good" << std::endl;
|
Chris@0
|
1164 #endif
|
Chris@0
|
1165 paint.begin(this);
|
Chris@0
|
1166 paint.drawPixmap(cacheRect, *m_cache, cacheRect);
|
Chris@0
|
1167 paint.end();
|
Chris@0
|
1168 QFrame::paintEvent(e);
|
Chris@0
|
1169 paintedCacheRect = true;
|
Chris@0
|
1170 }
|
Chris@0
|
1171
|
Chris@0
|
1172 m_cacheCentreFrame = m_centreFrame;
|
Chris@0
|
1173 m_cacheZoomLevel = m_zoomLevel;
|
Chris@0
|
1174 }
|
Chris@0
|
1175
|
Chris@0
|
1176 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@0
|
1177 // std::cerr << "View(" << this << ")::paintEvent: cacheRect " << cacheRect << ", nonCacheRect " << (nonCacheRect | cacheRect) << ", repaintCache " << repaintCache << ", paintedCacheRect " << paintedCacheRect << std::endl;
|
Chris@0
|
1178 #endif
|
Chris@0
|
1179
|
Chris@0
|
1180 // Scrollable (cacheable) items first
|
Chris@0
|
1181
|
Chris@0
|
1182 if (!paintedCacheRect) {
|
Chris@0
|
1183
|
Chris@0
|
1184 if (repaintCache) paint.begin(m_cache);
|
Chris@0
|
1185 else paint.begin(this);
|
Chris@0
|
1186
|
Chris@0
|
1187 paint.setClipRect(cacheRect);
|
Chris@0
|
1188
|
Chris@0
|
1189 if (hasLightBackground()) {
|
Chris@0
|
1190 paint.setPen(Qt::white);
|
Chris@0
|
1191 paint.setBrush(Qt::white);
|
Chris@0
|
1192 } else {
|
Chris@0
|
1193 paint.setPen(Qt::black);
|
Chris@0
|
1194 paint.setBrush(Qt::black);
|
Chris@0
|
1195 }
|
Chris@0
|
1196 paint.drawRect(cacheRect);
|
Chris@0
|
1197
|
Chris@0
|
1198 paint.setPen(Qt::black);
|
Chris@0
|
1199 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
1200
|
Chris@0
|
1201 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) {
|
Chris@8
|
1202 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@8
|
1203 paint.save();
|
Chris@36
|
1204 (*i)->paint(this, paint, cacheRect);
|
Chris@8
|
1205 paint.restore();
|
Chris@0
|
1206 }
|
Chris@9
|
1207
|
Chris@9
|
1208 if (haveSelections && selectionCacheable) {
|
Chris@9
|
1209 drawSelections(paint);
|
Chris@9
|
1210 m_selectionCached = repaintCache;
|
Chris@9
|
1211 selectionDrawn = true;
|
Chris@9
|
1212 }
|
Chris@0
|
1213
|
Chris@0
|
1214 paint.end();
|
Chris@0
|
1215
|
Chris@0
|
1216 if (repaintCache) {
|
Chris@0
|
1217 cacheRect |= (e ? e->rect() : rect());
|
Chris@0
|
1218 paint.begin(this);
|
Chris@0
|
1219 paint.drawPixmap(cacheRect, *m_cache, cacheRect);
|
Chris@0
|
1220 paint.end();
|
Chris@0
|
1221 }
|
Chris@0
|
1222 }
|
Chris@0
|
1223
|
Chris@0
|
1224 // Now non-cacheable items. We always need to redraw the
|
Chris@0
|
1225 // non-cacheable items across at least the area we drew of the
|
Chris@0
|
1226 // cacheable items.
|
Chris@0
|
1227
|
Chris@0
|
1228 nonCacheRect |= cacheRect;
|
Chris@0
|
1229
|
Chris@0
|
1230 paint.begin(this);
|
Chris@0
|
1231 paint.setClipRect(nonCacheRect);
|
Chris@0
|
1232
|
Chris@0
|
1233 if (scrollables.empty()) {
|
Chris@0
|
1234 if (hasLightBackground()) {
|
Chris@0
|
1235 paint.setPen(Qt::white);
|
Chris@0
|
1236 paint.setBrush(Qt::white);
|
Chris@0
|
1237 } else {
|
Chris@0
|
1238 paint.setPen(Qt::black);
|
Chris@0
|
1239 paint.setBrush(Qt::black);
|
Chris@0
|
1240 }
|
Chris@0
|
1241 paint.drawRect(nonCacheRect);
|
Chris@0
|
1242 }
|
Chris@0
|
1243
|
Chris@0
|
1244 paint.setPen(Qt::black);
|
Chris@0
|
1245 paint.setBrush(Qt::NoBrush);
|
Chris@0
|
1246
|
Chris@0
|
1247 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) {
|
Chris@36
|
1248 (*i)->paint(this, paint, nonCacheRect);
|
Chris@0
|
1249 }
|
Chris@0
|
1250
|
Chris@9
|
1251 paint.end();
|
Chris@8
|
1252
|
Chris@9
|
1253 paint.begin(this);
|
Chris@9
|
1254 if (e) paint.setClipRect(e->rect());
|
Chris@9
|
1255 if (!m_selectionCached) {
|
Chris@9
|
1256 drawSelections(paint);
|
Chris@8
|
1257 }
|
Chris@0
|
1258 paint.end();
|
Chris@0
|
1259
|
Chris@0
|
1260 if (m_followPlay != PlaybackScrollContinuous) {
|
Chris@0
|
1261
|
Chris@0
|
1262 paint.begin(this);
|
Chris@0
|
1263
|
Chris@0
|
1264 if (long(m_playPointerFrame) > getStartFrame() &&
|
Chris@0
|
1265 m_playPointerFrame < getEndFrame()) {
|
Chris@0
|
1266
|
Chris@15
|
1267 int playx = getXForFrame(m_playPointerFrame);
|
Chris@0
|
1268
|
Chris@0
|
1269 paint.setPen(Qt::black);
|
Chris@0
|
1270 paint.drawLine(playx - 1, 0, playx - 1, height() - 1);
|
Chris@0
|
1271 paint.drawLine(playx + 1, 0, playx + 1, height() - 1);
|
Chris@0
|
1272 paint.drawPoint(playx, 0);
|
Chris@0
|
1273 paint.drawPoint(playx, height() - 1);
|
Chris@0
|
1274 paint.setPen(Qt::white);
|
Chris@0
|
1275 paint.drawLine(playx, 1, playx, height() - 2);
|
Chris@0
|
1276 }
|
Chris@0
|
1277
|
Chris@0
|
1278 paint.end();
|
Chris@0
|
1279 }
|
Chris@0
|
1280
|
Chris@0
|
1281 QFrame::paintEvent(e);
|
Chris@0
|
1282 }
|
Chris@0
|
1283
|
Chris@9
|
1284 void
|
Chris@9
|
1285 View::drawSelections(QPainter &paint)
|
Chris@9
|
1286 {
|
Chris@24
|
1287 MultiSelection::SelectionList selections;
|
Chris@9
|
1288
|
Chris@9
|
1289 if (m_manager) {
|
Chris@9
|
1290 selections = m_manager->getSelections();
|
Chris@9
|
1291 if (m_manager->haveInProgressSelection()) {
|
Chris@9
|
1292 bool exclusive;
|
Chris@9
|
1293 Selection inProgressSelection =
|
Chris@9
|
1294 m_manager->getInProgressSelection(exclusive);
|
Chris@9
|
1295 if (exclusive) selections.clear();
|
Chris@9
|
1296 selections.insert(inProgressSelection);
|
Chris@9
|
1297 }
|
Chris@9
|
1298 }
|
Chris@9
|
1299
|
Chris@9
|
1300 paint.save();
|
Chris@9
|
1301 paint.setBrush(QColor(150, 150, 255, 80));
|
Chris@9
|
1302
|
Chris@10
|
1303 int sampleRate = getModelsSampleRate();
|
Chris@10
|
1304
|
Chris@34
|
1305 QPoint localPos;
|
Chris@34
|
1306 long illuminateFrame = -1;
|
Chris@34
|
1307 bool closeToLeft, closeToRight;
|
Chris@34
|
1308
|
Chris@34
|
1309 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) {
|
Chris@34
|
1310 illuminateFrame = getFrameForX(localPos.x());
|
Chris@34
|
1311 }
|
Chris@34
|
1312
|
Chris@10
|
1313 const QFontMetrics &metrics = paint.fontMetrics();
|
Chris@10
|
1314
|
Chris@24
|
1315 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@9
|
1316 i != selections.end(); ++i) {
|
Chris@9
|
1317
|
Chris@15
|
1318 int p0 = getXForFrame(i->getStartFrame());
|
Chris@15
|
1319 int p1 = getXForFrame(i->getEndFrame());
|
Chris@9
|
1320
|
Chris@10
|
1321 if (p1 < 0 || p0 > width()) continue;
|
Chris@9
|
1322
|
Chris@9
|
1323 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@9
|
1324 std::cerr << "View::drawSelections: " << p0 << ",-1 [" << (p1-p0) << "x" << (height()+1) << "]" << std::endl;
|
Chris@9
|
1325 #endif
|
Chris@9
|
1326
|
Chris@34
|
1327 bool illuminateThis =
|
Chris@34
|
1328 (illuminateFrame >= 0 && i->contains(illuminateFrame));
|
Chris@34
|
1329
|
Chris@34
|
1330 paint.setPen(QColor(150, 150, 255));
|
Chris@9
|
1331 paint.drawRect(p0, -1, p1 - p0, height() + 1);
|
Chris@10
|
1332
|
Chris@34
|
1333 if (illuminateThis) {
|
Chris@34
|
1334 paint.save();
|
Chris@34
|
1335 if (hasLightBackground()) {
|
Chris@34
|
1336 paint.setPen(QPen(Qt::black, 2));
|
Chris@34
|
1337 } else {
|
Chris@34
|
1338 paint.setPen(QPen(Qt::white, 2));
|
Chris@34
|
1339 }
|
Chris@34
|
1340 if (closeToLeft) {
|
Chris@34
|
1341 paint.drawLine(p0, 1, p1, 1);
|
Chris@34
|
1342 paint.drawLine(p0, 0, p0, height());
|
Chris@34
|
1343 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@34
|
1344 } else if (closeToRight) {
|
Chris@34
|
1345 paint.drawLine(p0, 1, p1, 1);
|
Chris@34
|
1346 paint.drawLine(p1, 0, p1, height());
|
Chris@34
|
1347 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@34
|
1348 } else {
|
Chris@34
|
1349 paint.setBrush(Qt::NoBrush);
|
Chris@34
|
1350 paint.drawRect(p0, 1, p1 - p0, height() - 2);
|
Chris@34
|
1351 }
|
Chris@34
|
1352 paint.restore();
|
Chris@34
|
1353 }
|
Chris@34
|
1354
|
Chris@10
|
1355 if (sampleRate && shouldLabelSelections()) {
|
Chris@10
|
1356
|
Chris@10
|
1357 QString startText = QString("%1 / %2")
|
Chris@10
|
1358 .arg(QString::fromStdString
|
Chris@10
|
1359 (RealTime::frame2RealTime
|
Chris@10
|
1360 (i->getStartFrame(), sampleRate).toText(true)))
|
Chris@10
|
1361 .arg(i->getStartFrame());
|
Chris@10
|
1362
|
Chris@10
|
1363 QString endText = QString(" %1 / %2")
|
Chris@10
|
1364 .arg(QString::fromStdString
|
Chris@10
|
1365 (RealTime::frame2RealTime
|
Chris@10
|
1366 (i->getEndFrame(), sampleRate).toText(true)))
|
Chris@10
|
1367 .arg(i->getEndFrame());
|
Chris@10
|
1368
|
Chris@10
|
1369 QString durationText = QString("(%1 / %2) ")
|
Chris@10
|
1370 .arg(QString::fromStdString
|
Chris@10
|
1371 (RealTime::frame2RealTime
|
Chris@10
|
1372 (i->getEndFrame() - i->getStartFrame(), sampleRate)
|
Chris@10
|
1373 .toText(true)))
|
Chris@10
|
1374 .arg(i->getEndFrame() - i->getStartFrame());
|
Chris@10
|
1375
|
Chris@10
|
1376 int sw = metrics.width(startText),
|
Chris@10
|
1377 ew = metrics.width(endText),
|
Chris@10
|
1378 dw = metrics.width(durationText);
|
Chris@10
|
1379
|
Chris@10
|
1380 int sy = metrics.ascent() + metrics.height() + 4;
|
Chris@10
|
1381 int ey = sy;
|
Chris@10
|
1382 int dy = sy + metrics.height();
|
Chris@10
|
1383
|
Chris@10
|
1384 int sx = p0 + 2;
|
Chris@10
|
1385 int ex = sx;
|
Chris@10
|
1386 int dx = sx;
|
Chris@10
|
1387
|
Chris@10
|
1388 if (sw + ew > (p1 - p0)) {
|
Chris@10
|
1389 ey += metrics.height();
|
Chris@10
|
1390 dy += metrics.height();
|
Chris@10
|
1391 }
|
Chris@10
|
1392
|
Chris@10
|
1393 if (ew < (p1 - p0)) {
|
Chris@10
|
1394 ex = p1 - 2 - ew;
|
Chris@10
|
1395 }
|
Chris@10
|
1396
|
Chris@10
|
1397 if (dw < (p1 - p0)) {
|
Chris@10
|
1398 dx = p1 - 2 - dw;
|
Chris@10
|
1399 }
|
Chris@10
|
1400
|
Chris@10
|
1401 paint.drawText(sx, sy, startText);
|
Chris@10
|
1402 paint.drawText(ex, ey, endText);
|
Chris@10
|
1403 paint.drawText(dx, dy, durationText);
|
Chris@10
|
1404 }
|
Chris@9
|
1405 }
|
Chris@9
|
1406
|
Chris@9
|
1407 paint.restore();
|
Chris@9
|
1408 }
|
Chris@9
|
1409
|
Chris@3
|
1410 QString
|
Chris@3
|
1411 View::toXmlString(QString indent, QString extraAttributes) const
|
Chris@3
|
1412 {
|
Chris@3
|
1413 QString s;
|
Chris@3
|
1414
|
Chris@3
|
1415 s += indent;
|
Chris@3
|
1416
|
Chris@3
|
1417 s += QString("<view "
|
Chris@3
|
1418 "centre=\"%1\" "
|
Chris@3
|
1419 "zoom=\"%2\" "
|
Chris@3
|
1420 "followPan=\"%3\" "
|
Chris@3
|
1421 "followZoom=\"%4\" "
|
Chris@3
|
1422 "tracking=\"%5\" "
|
Chris@3
|
1423 "light=\"%6\" %7>\n")
|
Chris@3
|
1424 .arg(m_centreFrame)
|
Chris@3
|
1425 .arg(m_zoomLevel)
|
Chris@3
|
1426 .arg(m_followPan)
|
Chris@3
|
1427 .arg(m_followZoom)
|
Chris@3
|
1428 .arg(m_followPlay == PlaybackScrollContinuous ? "scroll" :
|
Chris@3
|
1429 m_followPlay == PlaybackScrollPage ? "page" : "ignore")
|
Chris@3
|
1430 .arg(m_lightBackground)
|
Chris@3
|
1431 .arg(extraAttributes);
|
Chris@3
|
1432
|
Chris@3
|
1433 for (size_t i = 0; i < m_layers.size(); ++i) {
|
Chris@3
|
1434 s += m_layers[i]->toXmlString(indent + " ");
|
Chris@3
|
1435 }
|
Chris@3
|
1436
|
Chris@4
|
1437 s += indent + "</view>\n";
|
Chris@3
|
1438
|
Chris@3
|
1439 return s;
|
Chris@3
|
1440 }
|
Chris@3
|
1441
|
Chris@29
|
1442 ViewPropertyContainer::ViewPropertyContainer(View *v) :
|
Chris@29
|
1443 m_v(v)
|
Chris@29
|
1444 {
|
Chris@29
|
1445 connect(m_v, SIGNAL(propertyChanged(PropertyName)),
|
Chris@29
|
1446 this, SIGNAL(propertyChanged(PropertyName)));
|
Chris@29
|
1447 }
|
Chris@3
|
1448
|
Chris@0
|
1449 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
1450 #include "View.moc.cpp"
|
Chris@0
|
1451 #endif
|
Chris@0
|
1452
|