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