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