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