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