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