Chris@127
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@127
|
2
|
Chris@127
|
3 /*
|
Chris@127
|
4 Sonic Visualiser
|
Chris@127
|
5 An audio file viewer and annotation editor.
|
Chris@127
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@127
|
7 This file copyright 2006 Chris Cannam.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@128
|
16 #include "View.h"
|
Chris@128
|
17 #include "layer/Layer.h"
|
Chris@128
|
18 #include "data/model/Model.h"
|
Chris@127
|
19 #include "base/ZoomConstraint.h"
|
Chris@127
|
20 #include "base/Profiler.h"
|
Chris@278
|
21 #include "base/Pitch.h"
|
Chris@338
|
22 #include "base/Preferences.h"
|
Chris@919
|
23 #include "ViewProxy.h"
|
Chris@127
|
24
|
Chris@301
|
25 #include "layer/TimeRulerLayer.h"
|
Chris@287
|
26 #include "layer/SingleColourLayer.h"
|
Chris@1078
|
27 #include "layer/PaintAssistant.h"
|
Chris@1078
|
28
|
Chris@301
|
29 #include "data/model/PowerOfSqrtTwoZoomConstraint.h"
|
Chris@301
|
30 #include "data/model/RangeSummarisableTimeValueModel.h"
|
Chris@127
|
31
|
Chris@797
|
32 #include "widgets/IconLoader.h"
|
Chris@797
|
33
|
Chris@127
|
34 #include <QPainter>
|
Chris@127
|
35 #include <QPaintEvent>
|
Chris@127
|
36 #include <QRect>
|
Chris@127
|
37 #include <QApplication>
|
Chris@226
|
38 #include <QProgressDialog>
|
Chris@316
|
39 #include <QTextStream>
|
Chris@338
|
40 #include <QFont>
|
Chris@583
|
41 #include <QMessageBox>
|
Chris@797
|
42 #include <QPushButton>
|
Chris@956
|
43 #include <QSettings>
|
Chris@1202
|
44 #include <QSvgGenerator>
|
Chris@127
|
45
|
Chris@127
|
46 #include <iostream>
|
Chris@127
|
47 #include <cassert>
|
Chris@520
|
48 #include <cmath>
|
Chris@127
|
49
|
Chris@1003
|
50 //#define DEBUG_VIEW 1
|
Chris@1003
|
51 //#define DEBUG_VIEW_WIDGET_PAINT 1
|
Chris@127
|
52
|
Chris@127
|
53 View::View(QWidget *w, bool showProgress) :
|
Chris@127
|
54 QFrame(w),
|
Chris@1044
|
55 m_id(getNextId()),
|
Chris@127
|
56 m_centreFrame(0),
|
Chris@127
|
57 m_zoomLevel(1024),
|
Chris@127
|
58 m_followPan(true),
|
Chris@127
|
59 m_followZoom(true),
|
Chris@815
|
60 m_followPlay(PlaybackScrollPageWithCentre),
|
Chris@789
|
61 m_followPlayIsDetached(false),
|
Chris@153
|
62 m_playPointerFrame(0),
|
Chris@127
|
63 m_showProgress(showProgress),
|
Chris@127
|
64 m_cache(0),
|
Chris@952
|
65 m_buffer(0),
|
Chris@127
|
66 m_cacheCentreFrame(0),
|
Chris@127
|
67 m_cacheZoomLevel(1024),
|
Chris@127
|
68 m_selectionCached(false),
|
Chris@127
|
69 m_deleting(false),
|
Chris@127
|
70 m_haveSelectedLayer(false),
|
Chris@127
|
71 m_manager(0),
|
Chris@127
|
72 m_propertyContainer(new ViewPropertyContainer(this))
|
Chris@127
|
73 {
|
Chris@728
|
74 // cerr << "View::View(" << this << ")" << endl;
|
Chris@127
|
75 }
|
Chris@127
|
76
|
Chris@127
|
77 View::~View()
|
Chris@127
|
78 {
|
Chris@728
|
79 // cerr << "View::~View(" << this << ")" << endl;
|
Chris@127
|
80
|
Chris@127
|
81 m_deleting = true;
|
Chris@127
|
82 delete m_propertyContainer;
|
Chris@1215
|
83 delete m_cache;
|
Chris@1215
|
84 delete m_buffer;
|
Chris@127
|
85 }
|
Chris@127
|
86
|
Chris@127
|
87 PropertyContainer::PropertyList
|
Chris@127
|
88 View::getProperties() const
|
Chris@127
|
89 {
|
Chris@127
|
90 PropertyContainer::PropertyList list;
|
Chris@127
|
91 list.push_back("Global Scroll");
|
Chris@127
|
92 list.push_back("Global Zoom");
|
Chris@127
|
93 list.push_back("Follow Playback");
|
Chris@127
|
94 return list;
|
Chris@127
|
95 }
|
Chris@127
|
96
|
Chris@127
|
97 QString
|
Chris@127
|
98 View::getPropertyLabel(const PropertyName &pn) const
|
Chris@127
|
99 {
|
Chris@127
|
100 if (pn == "Global Scroll") return tr("Global Scroll");
|
Chris@127
|
101 if (pn == "Global Zoom") return tr("Global Zoom");
|
Chris@127
|
102 if (pn == "Follow Playback") return tr("Follow Playback");
|
Chris@127
|
103 return "";
|
Chris@127
|
104 }
|
Chris@127
|
105
|
Chris@127
|
106 PropertyContainer::PropertyType
|
Chris@127
|
107 View::getPropertyType(const PropertyContainer::PropertyName &name) const
|
Chris@127
|
108 {
|
Chris@127
|
109 if (name == "Global Scroll") return PropertyContainer::ToggleProperty;
|
Chris@127
|
110 if (name == "Global Zoom") return PropertyContainer::ToggleProperty;
|
Chris@127
|
111 if (name == "Follow Playback") return PropertyContainer::ValueProperty;
|
Chris@127
|
112 return PropertyContainer::InvalidProperty;
|
Chris@127
|
113 }
|
Chris@127
|
114
|
Chris@127
|
115 int
|
Chris@127
|
116 View::getPropertyRangeAndValue(const PropertyContainer::PropertyName &name,
|
Chris@1266
|
117 int *min, int *max, int *deflt) const
|
Chris@127
|
118 {
|
Chris@216
|
119 if (deflt) *deflt = 1;
|
Chris@127
|
120 if (name == "Global Scroll") return m_followPan;
|
Chris@127
|
121 if (name == "Global Zoom") return m_followZoom;
|
Chris@127
|
122 if (name == "Follow Playback") {
|
Chris@1266
|
123 if (min) *min = 0;
|
Chris@1266
|
124 if (max) *max = 2;
|
Chris@815
|
125 if (deflt) *deflt = int(PlaybackScrollPageWithCentre);
|
Chris@815
|
126 switch (m_followPlay) {
|
Chris@815
|
127 case PlaybackScrollContinuous: return 0;
|
Chris@815
|
128 case PlaybackScrollPageWithCentre: case PlaybackScrollPage: return 1;
|
Chris@815
|
129 case PlaybackIgnore: return 2;
|
Chris@815
|
130 }
|
Chris@127
|
131 }
|
Chris@127
|
132 if (min) *min = 0;
|
Chris@127
|
133 if (max) *max = 0;
|
Chris@216
|
134 if (deflt) *deflt = 0;
|
Chris@127
|
135 return 0;
|
Chris@127
|
136 }
|
Chris@127
|
137
|
Chris@127
|
138 QString
|
Chris@127
|
139 View::getPropertyValueLabel(const PropertyContainer::PropertyName &name,
|
Chris@1266
|
140 int value) const
|
Chris@127
|
141 {
|
Chris@127
|
142 if (name == "Follow Playback") {
|
Chris@1266
|
143 switch (value) {
|
Chris@1266
|
144 default:
|
Chris@1266
|
145 case 0: return tr("Scroll");
|
Chris@1266
|
146 case 1: return tr("Page");
|
Chris@1266
|
147 case 2: return tr("Off");
|
Chris@1266
|
148 }
|
Chris@127
|
149 }
|
Chris@127
|
150 return tr("<unknown>");
|
Chris@127
|
151 }
|
Chris@127
|
152
|
Chris@127
|
153 void
|
Chris@127
|
154 View::setProperty(const PropertyContainer::PropertyName &name, int value)
|
Chris@127
|
155 {
|
Chris@127
|
156 if (name == "Global Scroll") {
|
Chris@1266
|
157 setFollowGlobalPan(value != 0);
|
Chris@127
|
158 } else if (name == "Global Zoom") {
|
Chris@1266
|
159 setFollowGlobalZoom(value != 0);
|
Chris@127
|
160 } else if (name == "Follow Playback") {
|
Chris@1266
|
161 switch (value) {
|
Chris@1266
|
162 default:
|
Chris@1266
|
163 case 0: setPlaybackFollow(PlaybackScrollContinuous); break;
|
Chris@1266
|
164 case 1: setPlaybackFollow(PlaybackScrollPageWithCentre); break;
|
Chris@1266
|
165 case 2: setPlaybackFollow(PlaybackIgnore); break;
|
Chris@1266
|
166 }
|
Chris@127
|
167 }
|
Chris@127
|
168 }
|
Chris@127
|
169
|
Chris@806
|
170 int
|
Chris@127
|
171 View::getPropertyContainerCount() const
|
Chris@127
|
172 {
|
Chris@908
|
173 return int(m_fixedOrderLayers.size()) + 1; // the 1 is for me
|
Chris@127
|
174 }
|
Chris@127
|
175
|
Chris@127
|
176 const PropertyContainer *
|
Chris@806
|
177 View::getPropertyContainer(int i) const
|
Chris@127
|
178 {
|
Chris@127
|
179 return (const PropertyContainer *)(((View *)this)->
|
Chris@1266
|
180 getPropertyContainer(i));
|
Chris@127
|
181 }
|
Chris@127
|
182
|
Chris@127
|
183 PropertyContainer *
|
Chris@806
|
184 View::getPropertyContainer(int i)
|
Chris@127
|
185 {
|
Chris@127
|
186 if (i == 0) return m_propertyContainer;
|
Chris@837
|
187 return m_fixedOrderLayers[i-1];
|
Chris@127
|
188 }
|
Chris@127
|
189
|
Chris@127
|
190 bool
|
Chris@904
|
191 View::getValueExtents(QString unit, double &min, double &max, bool &log) const
|
Chris@127
|
192 {
|
Chris@127
|
193 bool have = false;
|
Chris@127
|
194
|
Chris@835
|
195 for (LayerList::const_iterator i = m_layerStack.begin();
|
Chris@835
|
196 i != m_layerStack.end(); ++i) {
|
Chris@127
|
197
|
Chris@127
|
198 QString layerUnit;
|
Chris@904
|
199 double layerMin = 0.0, layerMax = 0.0;
|
Chris@904
|
200 double displayMin = 0.0, displayMax = 0.0;
|
Chris@127
|
201 bool layerLog = false;
|
Chris@127
|
202
|
Chris@127
|
203 if ((*i)->getValueExtents(layerMin, layerMax, layerLog, layerUnit) &&
|
Chris@127
|
204 layerUnit.toLower() == unit.toLower()) {
|
Chris@127
|
205
|
Chris@127
|
206 if ((*i)->getDisplayExtents(displayMin, displayMax)) {
|
Chris@127
|
207
|
Chris@127
|
208 min = displayMin;
|
Chris@127
|
209 max = displayMax;
|
Chris@127
|
210 log = layerLog;
|
Chris@127
|
211 have = true;
|
Chris@127
|
212 break;
|
Chris@127
|
213
|
Chris@127
|
214 } else {
|
Chris@127
|
215
|
Chris@127
|
216 if (!have || layerMin < min) min = layerMin;
|
Chris@127
|
217 if (!have || layerMax > max) max = layerMax;
|
Chris@127
|
218 if (layerLog) log = true;
|
Chris@127
|
219 have = true;
|
Chris@127
|
220 }
|
Chris@127
|
221 }
|
Chris@127
|
222 }
|
Chris@127
|
223
|
Chris@127
|
224 return have;
|
Chris@127
|
225 }
|
Chris@127
|
226
|
Chris@127
|
227 int
|
Chris@127
|
228 View::getTextLabelHeight(const Layer *layer, QPainter &paint) const
|
Chris@127
|
229 {
|
Chris@127
|
230 std::map<int, Layer *> sortedLayers;
|
Chris@127
|
231
|
Chris@835
|
232 for (LayerList::const_iterator i = m_layerStack.begin();
|
Chris@835
|
233 i != m_layerStack.end(); ++i) {
|
Chris@127
|
234 if ((*i)->needsTextLabelHeight()) {
|
Chris@127
|
235 sortedLayers[getObjectExportId(*i)] = *i;
|
Chris@127
|
236 }
|
Chris@127
|
237 }
|
Chris@127
|
238
|
Chris@1273
|
239 int y = ViewManager::scalePixelSize(15) + paint.fontMetrics().ascent();
|
Chris@127
|
240
|
Chris@127
|
241 for (std::map<int, Layer *>::const_iterator i = sortedLayers.begin();
|
Chris@127
|
242 i != sortedLayers.end(); ++i) {
|
Chris@1273
|
243 if (i->second == layer) break;
|
Chris@127
|
244 y += paint.fontMetrics().height();
|
Chris@127
|
245 }
|
Chris@127
|
246
|
Chris@127
|
247 return y;
|
Chris@127
|
248 }
|
Chris@127
|
249
|
Chris@127
|
250 void
|
Chris@127
|
251 View::propertyContainerSelected(View *client, PropertyContainer *pc)
|
Chris@127
|
252 {
|
Chris@127
|
253 if (client != this) return;
|
Chris@127
|
254
|
Chris@127
|
255 if (pc == m_propertyContainer) {
|
Chris@1266
|
256 if (m_haveSelectedLayer) {
|
Chris@1266
|
257 m_haveSelectedLayer = false;
|
Chris@1266
|
258 update();
|
Chris@1266
|
259 }
|
Chris@1266
|
260 return;
|
Chris@127
|
261 }
|
Chris@127
|
262
|
Chris@127
|
263 delete m_cache;
|
Chris@127
|
264 m_cache = 0;
|
Chris@127
|
265
|
Chris@127
|
266 Layer *selectedLayer = 0;
|
Chris@127
|
267
|
Chris@835
|
268 for (LayerList::iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
269 if (*i == pc) {
|
Chris@1266
|
270 selectedLayer = *i;
|
Chris@1266
|
271 m_layerStack.erase(i);
|
Chris@1266
|
272 break;
|
Chris@1266
|
273 }
|
Chris@127
|
274 }
|
Chris@127
|
275
|
Chris@127
|
276 if (selectedLayer) {
|
Chris@1266
|
277 m_haveSelectedLayer = true;
|
Chris@1266
|
278 m_layerStack.push_back(selectedLayer);
|
Chris@1266
|
279 update();
|
Chris@127
|
280 } else {
|
Chris@1266
|
281 m_haveSelectedLayer = false;
|
Chris@127
|
282 }
|
Chris@298
|
283
|
Chris@298
|
284 emit propertyContainerSelected(pc);
|
Chris@127
|
285 }
|
Chris@127
|
286
|
Chris@127
|
287 void
|
Chris@127
|
288 View::toolModeChanged()
|
Chris@127
|
289 {
|
Chris@587
|
290 // SVDEBUG << "View::toolModeChanged(" << m_manager->getToolMode() << ")" << endl;
|
Chris@127
|
291 }
|
Chris@127
|
292
|
Chris@133
|
293 void
|
Chris@133
|
294 View::overlayModeChanged()
|
Chris@133
|
295 {
|
Chris@206
|
296 delete m_cache;
|
Chris@206
|
297 m_cache = 0;
|
Chris@133
|
298 update();
|
Chris@133
|
299 }
|
Chris@133
|
300
|
Chris@133
|
301 void
|
Chris@133
|
302 View::zoomWheelsEnabledChanged()
|
Chris@133
|
303 {
|
Chris@133
|
304 // subclass might override this
|
Chris@133
|
305 }
|
Chris@133
|
306
|
Chris@908
|
307 sv_frame_t
|
Chris@127
|
308 View::getStartFrame() const
|
Chris@127
|
309 {
|
Chris@313
|
310 return getFrameForX(0);
|
Chris@127
|
311 }
|
Chris@127
|
312
|
Chris@908
|
313 sv_frame_t
|
Chris@127
|
314 View::getEndFrame() const
|
Chris@127
|
315 {
|
Chris@127
|
316 return getFrameForX(width()) - 1;
|
Chris@127
|
317 }
|
Chris@127
|
318
|
Chris@127
|
319 void
|
Chris@908
|
320 View::setStartFrame(sv_frame_t f)
|
Chris@127
|
321 {
|
Chris@127
|
322 setCentreFrame(f + m_zoomLevel * (width() / 2));
|
Chris@127
|
323 }
|
Chris@127
|
324
|
Chris@127
|
325 bool
|
Chris@908
|
326 View::setCentreFrame(sv_frame_t f, bool e)
|
Chris@127
|
327 {
|
Chris@127
|
328 bool changeVisible = false;
|
Chris@127
|
329
|
Chris@127
|
330 if (m_centreFrame != f) {
|
Chris@127
|
331
|
Chris@1266
|
332 int formerPixel = int(m_centreFrame / m_zoomLevel);
|
Chris@1266
|
333
|
Chris@1266
|
334 m_centreFrame = f;
|
Chris@1266
|
335
|
Chris@1266
|
336 int newPixel = int(m_centreFrame / m_zoomLevel);
|
Chris@1266
|
337
|
Chris@1266
|
338 if (newPixel != formerPixel) {
|
Chris@127
|
339
|
Chris@127
|
340 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
341 cout << "View(" << this << ")::setCentreFrame: newPixel " << newPixel << ", formerPixel " << formerPixel << endl;
|
Chris@127
|
342 #endif
|
Chris@1266
|
343 update();
|
Chris@1266
|
344
|
Chris@1266
|
345 changeVisible = true;
|
Chris@1266
|
346 }
|
Chris@1266
|
347
|
Chris@1266
|
348 if (e) {
|
Chris@908
|
349 sv_frame_t rf = alignToReference(f);
|
Chris@830
|
350 #ifdef DEBUG_VIEW
|
Chris@682
|
351 cerr << "View[" << this << "]::setCentreFrame(" << f
|
Chris@333
|
352 << "): emitting centreFrameChanged("
|
Chris@682
|
353 << rf << ")" << endl;
|
Chris@355
|
354 #endif
|
Chris@333
|
355 emit centreFrameChanged(rf, m_followPan, m_followPlay);
|
Chris@333
|
356 }
|
Chris@127
|
357 }
|
Chris@127
|
358
|
Chris@127
|
359 return changeVisible;
|
Chris@127
|
360 }
|
Chris@127
|
361
|
Chris@127
|
362 int
|
Chris@908
|
363 View::getXForFrame(sv_frame_t frame) const
|
Chris@127
|
364 {
|
Chris@908
|
365 return int((frame - getStartFrame()) / m_zoomLevel);
|
Chris@127
|
366 }
|
Chris@127
|
367
|
Chris@908
|
368 sv_frame_t
|
Chris@127
|
369 View::getFrameForX(int x) const
|
Chris@127
|
370 {
|
Chris@1020
|
371 sv_frame_t z = m_zoomLevel; // nb not just int, or multiplication may overflow
|
Chris@908
|
372 sv_frame_t frame = m_centreFrame - (width()/2) * z;
|
Chris@354
|
373
|
Chris@1020
|
374 frame = (frame / z) * z; // this is start frame
|
Chris@1020
|
375 frame = frame + x * z;
|
Chris@1020
|
376
|
Chris@355
|
377 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1020
|
378 cerr << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl;
|
Chris@355
|
379 #endif
|
Chris@354
|
380
|
Chris@1020
|
381 return frame;
|
Chris@127
|
382 }
|
Chris@127
|
383
|
Chris@904
|
384 double
|
Chris@904
|
385 View::getYForFrequency(double frequency,
|
Chris@1266
|
386 double minf,
|
Chris@1266
|
387 double maxf,
|
Chris@1266
|
388 bool logarithmic) const
|
Chris@127
|
389 {
|
Chris@382
|
390 Profiler profiler("View::getYForFrequency");
|
Chris@382
|
391
|
Chris@127
|
392 int h = height();
|
Chris@127
|
393
|
Chris@127
|
394 if (logarithmic) {
|
Chris@127
|
395
|
Chris@1266
|
396 static double lastminf = 0.0, lastmaxf = 0.0;
|
Chris@1266
|
397 static double logminf = 0.0, logmaxf = 0.0;
|
Chris@1266
|
398
|
Chris@1266
|
399 if (lastminf != minf) {
|
Chris@1266
|
400 lastminf = (minf == 0.0 ? 1.0 : minf);
|
Chris@1266
|
401 logminf = log10(minf);
|
Chris@1266
|
402 }
|
Chris@1266
|
403 if (lastmaxf != maxf) {
|
Chris@1266
|
404 lastmaxf = (maxf < lastminf ? lastminf : maxf);
|
Chris@1266
|
405 logmaxf = log10(maxf);
|
Chris@1266
|
406 }
|
Chris@1266
|
407
|
Chris@1266
|
408 if (logminf == logmaxf) return 0;
|
Chris@1266
|
409 return h - (h * (log10(frequency) - logminf)) / (logmaxf - logminf);
|
Chris@127
|
410
|
Chris@127
|
411 } else {
|
Chris@1266
|
412
|
Chris@1266
|
413 if (minf == maxf) return 0;
|
Chris@1266
|
414 return h - (h * (frequency - minf)) / (maxf - minf);
|
Chris@127
|
415 }
|
Chris@127
|
416 }
|
Chris@127
|
417
|
Chris@904
|
418 double
|
Chris@1085
|
419 View::getFrequencyForY(double y,
|
Chris@1266
|
420 double minf,
|
Chris@1266
|
421 double maxf,
|
Chris@1266
|
422 bool logarithmic) const
|
Chris@127
|
423 {
|
Chris@1085
|
424 double h = height();
|
Chris@127
|
425
|
Chris@127
|
426 if (logarithmic) {
|
Chris@127
|
427
|
Chris@1266
|
428 static double lastminf = 0.0, lastmaxf = 0.0;
|
Chris@1266
|
429 static double logminf = 0.0, logmaxf = 0.0;
|
Chris@1266
|
430
|
Chris@1266
|
431 if (lastminf != minf) {
|
Chris@1266
|
432 lastminf = (minf == 0.0 ? 1.0 : minf);
|
Chris@1266
|
433 logminf = log10(minf);
|
Chris@1266
|
434 }
|
Chris@1266
|
435 if (lastmaxf != maxf) {
|
Chris@1266
|
436 lastmaxf = (maxf < lastminf ? lastminf : maxf);
|
Chris@1266
|
437 logmaxf = log10(maxf);
|
Chris@1266
|
438 }
|
Chris@1266
|
439
|
Chris@1266
|
440 if (logminf == logmaxf) return 0;
|
Chris@1266
|
441 return pow(10.0, logminf + ((logmaxf - logminf) * (h - y)) / h);
|
Chris@127
|
442
|
Chris@127
|
443 } else {
|
Chris@127
|
444
|
Chris@1266
|
445 if (minf == maxf) return 0;
|
Chris@1266
|
446 return minf + ((h - y) * (maxf - minf)) / h;
|
Chris@127
|
447 }
|
Chris@127
|
448 }
|
Chris@127
|
449
|
Chris@127
|
450 int
|
Chris@127
|
451 View::getZoomLevel() const
|
Chris@127
|
452 {
|
Chris@127
|
453 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
454 // cout << "zoom level: " << m_zoomLevel << endl;
|
Chris@127
|
455 #endif
|
Chris@127
|
456 return m_zoomLevel;
|
Chris@127
|
457 }
|
Chris@127
|
458
|
Chris@956
|
459 int
|
Chris@956
|
460 View::effectiveDevicePixelRatio() const
|
Chris@956
|
461 {
|
Chris@956
|
462 #ifdef Q_OS_MAC
|
Chris@956
|
463 int dpratio = devicePixelRatio();
|
Chris@956
|
464 if (dpratio > 1) {
|
Chris@956
|
465 QSettings settings;
|
Chris@956
|
466 settings.beginGroup("Preferences");
|
Chris@956
|
467 if (!settings.value("scaledHiDpi", true).toBool()) {
|
Chris@956
|
468 dpratio = 1;
|
Chris@956
|
469 }
|
Chris@956
|
470 settings.endGroup();
|
Chris@956
|
471 }
|
Chris@956
|
472 return dpratio;
|
Chris@956
|
473 #else
|
Chris@956
|
474 return 1;
|
Chris@956
|
475 #endif
|
Chris@956
|
476 }
|
Chris@956
|
477
|
Chris@127
|
478 void
|
Chris@806
|
479 View::setZoomLevel(int z)
|
Chris@127
|
480 {
|
Chris@956
|
481 int dpratio = effectiveDevicePixelRatio();
|
Chris@950
|
482 if (z < dpratio) return;
|
Chris@462
|
483 if (z < 1) z = 1;
|
Chris@127
|
484 if (m_zoomLevel != int(z)) {
|
Chris@1266
|
485 m_zoomLevel = z;
|
Chris@1266
|
486 emit zoomLevelChanged(z, m_followZoom);
|
Chris@1266
|
487 update();
|
Chris@127
|
488 }
|
Chris@127
|
489 }
|
Chris@127
|
490
|
Chris@224
|
491 bool
|
Chris@224
|
492 View::hasLightBackground() const
|
Chris@224
|
493 {
|
Chris@287
|
494 bool darkPalette = false;
|
Chris@292
|
495 if (m_manager) darkPalette = m_manager->getGlobalDarkBackground();
|
Chris@287
|
496
|
Chris@287
|
497 Layer::ColourSignificance maxSignificance = Layer::ColourAbsent;
|
Chris@287
|
498 bool mostSignificantHasDarkBackground = false;
|
Chris@287
|
499
|
Chris@835
|
500 for (LayerList::const_iterator i = m_layerStack.begin();
|
Chris@835
|
501 i != m_layerStack.end(); ++i) {
|
Chris@287
|
502
|
Chris@287
|
503 Layer::ColourSignificance s = (*i)->getLayerColourSignificance();
|
Chris@287
|
504 bool light = (*i)->hasLightBackground();
|
Chris@287
|
505
|
Chris@287
|
506 if (int(s) > int(maxSignificance)) {
|
Chris@287
|
507 maxSignificance = s;
|
Chris@287
|
508 mostSignificantHasDarkBackground = !light;
|
Chris@287
|
509 } else if (s == maxSignificance && !light) {
|
Chris@287
|
510 mostSignificantHasDarkBackground = true;
|
Chris@287
|
511 }
|
Chris@224
|
512 }
|
Chris@287
|
513
|
Chris@1314
|
514 if (int(maxSignificance) >= int(Layer::ColourDistinguishes)) {
|
Chris@287
|
515 return !mostSignificantHasDarkBackground;
|
Chris@287
|
516 } else {
|
Chris@287
|
517 return !darkPalette;
|
Chris@287
|
518 }
|
Chris@287
|
519 }
|
Chris@287
|
520
|
Chris@287
|
521 QColor
|
Chris@287
|
522 View::getBackground() const
|
Chris@287
|
523 {
|
Chris@287
|
524 bool light = hasLightBackground();
|
Chris@287
|
525
|
Chris@287
|
526 QColor widgetbg = palette().window().color();
|
Chris@287
|
527 bool widgetLight =
|
Chris@287
|
528 (widgetbg.red() + widgetbg.green() + widgetbg.blue()) > 384;
|
Chris@287
|
529
|
Chris@296
|
530 if (widgetLight == light) {
|
Chris@296
|
531 if (widgetLight) {
|
Chris@296
|
532 return widgetbg.light();
|
Chris@296
|
533 } else {
|
Chris@296
|
534 return widgetbg.dark();
|
Chris@296
|
535 }
|
Chris@296
|
536 }
|
Chris@287
|
537 else if (light) return Qt::white;
|
Chris@287
|
538 else return Qt::black;
|
Chris@287
|
539 }
|
Chris@287
|
540
|
Chris@287
|
541 QColor
|
Chris@287
|
542 View::getForeground() const
|
Chris@287
|
543 {
|
Chris@287
|
544 bool light = hasLightBackground();
|
Chris@287
|
545
|
Chris@287
|
546 QColor widgetfg = palette().text().color();
|
Chris@287
|
547 bool widgetLight =
|
Chris@287
|
548 (widgetfg.red() + widgetfg.green() + widgetfg.blue()) > 384;
|
Chris@287
|
549
|
Chris@287
|
550 if (widgetLight != light) return widgetfg;
|
Chris@287
|
551 else if (light) return Qt::black;
|
Chris@287
|
552 else return Qt::white;
|
Chris@224
|
553 }
|
Chris@224
|
554
|
Chris@127
|
555 void
|
Chris@127
|
556 View::addLayer(Layer *layer)
|
Chris@127
|
557 {
|
Chris@127
|
558 delete m_cache;
|
Chris@127
|
559 m_cache = 0;
|
Chris@127
|
560
|
Chris@287
|
561 SingleColourLayer *scl = dynamic_cast<SingleColourLayer *>(layer);
|
Chris@287
|
562 if (scl) scl->setDefaultColourFor(this);
|
Chris@287
|
563
|
Chris@836
|
564 m_fixedOrderLayers.push_back(layer);
|
Chris@835
|
565 m_layerStack.push_back(layer);
|
Chris@127
|
566
|
Chris@555
|
567 QProgressBar *pb = new QProgressBar(this);
|
Chris@555
|
568 pb->setMinimum(0);
|
Chris@555
|
569 pb->setMaximum(0);
|
Chris@555
|
570 pb->setFixedWidth(80);
|
Chris@555
|
571 pb->setTextVisible(false);
|
Chris@555
|
572
|
Chris@797
|
573 QPushButton *cancel = new QPushButton(this);
|
Chris@1350
|
574 cancel->setIcon(IconLoader().load("cancel"));
|
Chris@797
|
575 cancel->setFlat(true);
|
Chris@1351
|
576 int scaled20 = ViewManager::scalePixelSize(20);
|
Chris@1351
|
577 cancel->setFixedSize(QSize(scaled20, scaled20));
|
Chris@797
|
578 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
Chris@797
|
579
|
Chris@555
|
580 ProgressBarRec pbr;
|
Chris@797
|
581 pbr.cancel = cancel;
|
Chris@555
|
582 pbr.bar = pb;
|
Chris@555
|
583 pbr.lastCheck = 0;
|
Chris@555
|
584 pbr.checkTimer = new QTimer();
|
Chris@555
|
585 connect(pbr.checkTimer, SIGNAL(timeout()), this,
|
Chris@555
|
586 SLOT(progressCheckStalledTimerElapsed()));
|
Chris@555
|
587
|
Chris@555
|
588 m_progressBars[layer] = pbr;
|
Chris@555
|
589
|
Chris@555
|
590 QFont f(pb->font());
|
Chris@339
|
591 int fs = Preferences::getInstance()->getViewFontSize();
|
Chris@339
|
592 f.setPointSize(std::min(fs, int(ceil(fs * 0.85))));
|
Chris@339
|
593
|
Chris@797
|
594 cancel->hide();
|
Chris@797
|
595
|
Chris@555
|
596 pb->setFont(f);
|
Chris@555
|
597 pb->hide();
|
Chris@127
|
598
|
Chris@127
|
599 connect(layer, SIGNAL(layerParametersChanged()),
|
Chris@1266
|
600 this, SLOT(layerParametersChanged()));
|
Chris@197
|
601 connect(layer, SIGNAL(layerParameterRangesChanged()),
|
Chris@1266
|
602 this, SLOT(layerParameterRangesChanged()));
|
Chris@268
|
603 connect(layer, SIGNAL(layerMeasurementRectsChanged()),
|
Chris@1266
|
604 this, SLOT(layerMeasurementRectsChanged()));
|
Chris@127
|
605 connect(layer, SIGNAL(layerNameChanged()),
|
Chris@1266
|
606 this, SLOT(layerNameChanged()));
|
Chris@127
|
607 connect(layer, SIGNAL(modelChanged()),
|
Chris@1266
|
608 this, SLOT(modelChanged()));
|
Chris@127
|
609 connect(layer, SIGNAL(modelCompletionChanged()),
|
Chris@1266
|
610 this, SLOT(modelCompletionChanged()));
|
Chris@320
|
611 connect(layer, SIGNAL(modelAlignmentCompletionChanged()),
|
Chris@1266
|
612 this, SLOT(modelAlignmentCompletionChanged()));
|
Chris@908
|
613 connect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
|
Chris@1266
|
614 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
|
Chris@127
|
615 connect(layer, SIGNAL(modelReplaced()),
|
Chris@1266
|
616 this, SLOT(modelReplaced()));
|
Chris@127
|
617
|
Chris@127
|
618 update();
|
Chris@127
|
619
|
Chris@127
|
620 emit propertyContainerAdded(layer);
|
Chris@127
|
621 }
|
Chris@127
|
622
|
Chris@127
|
623 void
|
Chris@127
|
624 View::removeLayer(Layer *layer)
|
Chris@127
|
625 {
|
Chris@127
|
626 if (m_deleting) {
|
Chris@1266
|
627 return;
|
Chris@127
|
628 }
|
Chris@127
|
629
|
Chris@127
|
630 delete m_cache;
|
Chris@127
|
631 m_cache = 0;
|
Chris@127
|
632
|
Chris@836
|
633 for (LayerList::iterator i = m_fixedOrderLayers.begin();
|
Chris@836
|
634 i != m_fixedOrderLayers.end();
|
Chris@836
|
635 ++i) {
|
Chris@1266
|
636 if (*i == layer) {
|
Chris@1266
|
637 m_fixedOrderLayers.erase(i);
|
Chris@836
|
638 break;
|
Chris@836
|
639 }
|
Chris@836
|
640 }
|
Chris@836
|
641
|
Chris@836
|
642 for (LayerList::iterator i = m_layerStack.begin();
|
Chris@836
|
643 i != m_layerStack.end();
|
Chris@836
|
644 ++i) {
|
Chris@1266
|
645 if (*i == layer) {
|
Chris@1266
|
646 m_layerStack.erase(i);
|
Chris@1266
|
647 if (m_progressBars.find(layer) != m_progressBars.end()) {
|
Chris@1266
|
648 delete m_progressBars[layer].bar;
|
Chris@797
|
649 delete m_progressBars[layer].cancel;
|
Chris@1266
|
650 delete m_progressBars[layer].checkTimer;
|
Chris@1266
|
651 m_progressBars.erase(layer);
|
Chris@1266
|
652 }
|
Chris@1266
|
653 break;
|
Chris@1266
|
654 }
|
Chris@127
|
655 }
|
Chris@127
|
656
|
Chris@197
|
657 disconnect(layer, SIGNAL(layerParametersChanged()),
|
Chris@197
|
658 this, SLOT(layerParametersChanged()));
|
Chris@197
|
659 disconnect(layer, SIGNAL(layerParameterRangesChanged()),
|
Chris@197
|
660 this, SLOT(layerParameterRangesChanged()));
|
Chris@197
|
661 disconnect(layer, SIGNAL(layerNameChanged()),
|
Chris@197
|
662 this, SLOT(layerNameChanged()));
|
Chris@197
|
663 disconnect(layer, SIGNAL(modelChanged()),
|
Chris@197
|
664 this, SLOT(modelChanged()));
|
Chris@197
|
665 disconnect(layer, SIGNAL(modelCompletionChanged()),
|
Chris@197
|
666 this, SLOT(modelCompletionChanged()));
|
Chris@320
|
667 disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()),
|
Chris@320
|
668 this, SLOT(modelAlignmentCompletionChanged()));
|
Chris@908
|
669 disconnect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
|
Chris@908
|
670 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
|
Chris@197
|
671 disconnect(layer, SIGNAL(modelReplaced()),
|
Chris@197
|
672 this, SLOT(modelReplaced()));
|
Chris@197
|
673
|
Chris@127
|
674 update();
|
Chris@127
|
675
|
Chris@127
|
676 emit propertyContainerRemoved(layer);
|
Chris@127
|
677 }
|
Chris@127
|
678
|
Chris@127
|
679 Layer *
|
Chris@834
|
680 View::getInteractionLayer()
|
Chris@834
|
681 {
|
Chris@834
|
682 Layer *sl = getSelectedLayer();
|
Chris@834
|
683 if (sl && !(sl->isLayerDormant(this))) {
|
Chris@834
|
684 return sl;
|
Chris@834
|
685 }
|
Chris@835
|
686 if (!m_layerStack.empty()) {
|
Chris@834
|
687 int n = getLayerCount();
|
Chris@834
|
688 while (n > 0) {
|
Chris@834
|
689 --n;
|
Chris@834
|
690 Layer *layer = getLayer(n);
|
Chris@834
|
691 if (!(layer->isLayerDormant(this))) {
|
Chris@834
|
692 return layer;
|
Chris@834
|
693 }
|
Chris@834
|
694 }
|
Chris@834
|
695 }
|
Chris@834
|
696 return 0;
|
Chris@834
|
697 }
|
Chris@834
|
698
|
Chris@841
|
699 const Layer *
|
Chris@841
|
700 View::getInteractionLayer() const
|
Chris@841
|
701 {
|
Chris@841
|
702 return const_cast<const Layer *>(const_cast<View *>(this)->getInteractionLayer());
|
Chris@841
|
703 }
|
Chris@841
|
704
|
Chris@834
|
705 Layer *
|
Chris@127
|
706 View::getSelectedLayer()
|
Chris@127
|
707 {
|
Chris@835
|
708 if (m_haveSelectedLayer && !m_layerStack.empty()) {
|
Chris@839
|
709 return getLayer(getLayerCount() - 1);
|
Chris@127
|
710 } else {
|
Chris@1266
|
711 return 0;
|
Chris@127
|
712 }
|
Chris@127
|
713 }
|
Chris@127
|
714
|
Chris@127
|
715 const Layer *
|
Chris@127
|
716 View::getSelectedLayer() const
|
Chris@127
|
717 {
|
Chris@127
|
718 return const_cast<const Layer *>(const_cast<View *>(this)->getSelectedLayer());
|
Chris@127
|
719 }
|
Chris@127
|
720
|
Chris@127
|
721 void
|
Chris@127
|
722 View::setViewManager(ViewManager *manager)
|
Chris@127
|
723 {
|
Chris@127
|
724 if (m_manager) {
|
Chris@1266
|
725 m_manager->disconnect(this, SLOT(globalCentreFrameChanged(sv_frame_t)));
|
Chris@1266
|
726 m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, sv_frame_t)));
|
Chris@1266
|
727 m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t)));
|
Chris@1266
|
728 m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool)));
|
Chris@211
|
729 m_manager->disconnect(this, SLOT(toolModeChanged()));
|
Chris@211
|
730 m_manager->disconnect(this, SLOT(selectionChanged()));
|
Chris@211
|
731 m_manager->disconnect(this, SLOT(overlayModeChanged()));
|
Chris@211
|
732 m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged()));
|
Chris@908
|
733 disconnect(m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode)));
|
Chris@1266
|
734 disconnect(m_manager, SLOT(zoomLevelChanged(int, bool)));
|
Chris@127
|
735 }
|
Chris@127
|
736
|
Chris@127
|
737 m_manager = manager;
|
Chris@127
|
738
|
Chris@908
|
739 connect(m_manager, SIGNAL(globalCentreFrameChanged(sv_frame_t)),
|
Chris@1266
|
740 this, SLOT(globalCentreFrameChanged(sv_frame_t)));
|
Chris@908
|
741 connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, sv_frame_t)),
|
Chris@1266
|
742 this, SLOT(viewCentreFrameChanged(View *, sv_frame_t)));
|
Chris@908
|
743 connect(m_manager, SIGNAL(playbackFrameChanged(sv_frame_t)),
|
Chris@1266
|
744 this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t)));
|
Chris@806
|
745
|
Chris@806
|
746 connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)),
|
Chris@1266
|
747 this, SLOT(viewZoomLevelChanged(View *, int, bool)));
|
Chris@211
|
748
|
Chris@127
|
749 connect(m_manager, SIGNAL(toolModeChanged()),
|
Chris@1266
|
750 this, SLOT(toolModeChanged()));
|
Chris@127
|
751 connect(m_manager, SIGNAL(selectionChanged()),
|
Chris@1266
|
752 this, SLOT(selectionChanged()));
|
Chris@127
|
753 connect(m_manager, SIGNAL(inProgressSelectionChanged()),
|
Chris@1266
|
754 this, SLOT(selectionChanged()));
|
Chris@127
|
755 connect(m_manager, SIGNAL(overlayModeChanged()),
|
Chris@133
|
756 this, SLOT(overlayModeChanged()));
|
Chris@607
|
757 connect(m_manager, SIGNAL(showCentreLineChanged()),
|
Chris@607
|
758 this, SLOT(overlayModeChanged()));
|
Chris@133
|
759 connect(m_manager, SIGNAL(zoomWheelsEnabledChanged()),
|
Chris@133
|
760 this, SLOT(zoomWheelsEnabledChanged()));
|
Chris@127
|
761
|
Chris@908
|
762 connect(this, SIGNAL(centreFrameChanged(sv_frame_t, bool,
|
Chris@211
|
763 PlaybackFollowMode)),
|
Chris@908
|
764 m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool,
|
Chris@211
|
765 PlaybackFollowMode)));
|
Chris@211
|
766
|
Chris@806
|
767 connect(this, SIGNAL(zoomLevelChanged(int, bool)),
|
Chris@1266
|
768 m_manager, SLOT(viewZoomLevelChanged(int, bool)));
|
Chris@127
|
769
|
Chris@815
|
770 switch (m_followPlay) {
|
Chris@815
|
771
|
Chris@815
|
772 case PlaybackScrollPage:
|
Chris@815
|
773 case PlaybackScrollPageWithCentre:
|
Chris@364
|
774 setCentreFrame(m_manager->getGlobalCentreFrame(), false);
|
Chris@815
|
775 break;
|
Chris@815
|
776
|
Chris@815
|
777 case PlaybackScrollContinuous:
|
Chris@236
|
778 setCentreFrame(m_manager->getPlaybackFrame(), false);
|
Chris@815
|
779 break;
|
Chris@815
|
780
|
Chris@815
|
781 case PlaybackIgnore:
|
Chris@815
|
782 if (m_followPan) {
|
Chris@815
|
783 setCentreFrame(m_manager->getGlobalCentreFrame(), false);
|
Chris@815
|
784 }
|
Chris@815
|
785 break;
|
Chris@236
|
786 }
|
Chris@516
|
787
|
Chris@236
|
788 if (m_followZoom) setZoomLevel(m_manager->getGlobalZoom());
|
Chris@236
|
789
|
Chris@511
|
790 movePlayPointer(getAlignedPlaybackFrame());
|
Chris@511
|
791
|
Chris@127
|
792 toolModeChanged();
|
Chris@127
|
793 }
|
Chris@127
|
794
|
Chris@127
|
795 void
|
Chris@908
|
796 View::setViewManager(ViewManager *vm, sv_frame_t initialCentreFrame)
|
Chris@516
|
797 {
|
Chris@516
|
798 setViewManager(vm);
|
Chris@516
|
799 setCentreFrame(initialCentreFrame, false);
|
Chris@516
|
800 }
|
Chris@516
|
801
|
Chris@516
|
802 void
|
Chris@127
|
803 View::setFollowGlobalPan(bool f)
|
Chris@127
|
804 {
|
Chris@127
|
805 m_followPan = f;
|
Chris@127
|
806 emit propertyContainerPropertyChanged(m_propertyContainer);
|
Chris@127
|
807 }
|
Chris@127
|
808
|
Chris@127
|
809 void
|
Chris@127
|
810 View::setFollowGlobalZoom(bool f)
|
Chris@127
|
811 {
|
Chris@127
|
812 m_followZoom = f;
|
Chris@127
|
813 emit propertyContainerPropertyChanged(m_propertyContainer);
|
Chris@127
|
814 }
|
Chris@127
|
815
|
Chris@127
|
816 void
|
Chris@127
|
817 View::setPlaybackFollow(PlaybackFollowMode m)
|
Chris@127
|
818 {
|
Chris@127
|
819 m_followPlay = m;
|
Chris@127
|
820 emit propertyContainerPropertyChanged(m_propertyContainer);
|
Chris@127
|
821 }
|
Chris@127
|
822
|
Chris@127
|
823 void
|
Chris@127
|
824 View::modelChanged()
|
Chris@127
|
825 {
|
Chris@127
|
826 QObject *obj = sender();
|
Chris@127
|
827
|
Chris@127
|
828 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@682
|
829 cerr << "View(" << this << ")::modelChanged()" << endl;
|
Chris@127
|
830 #endif
|
Chris@127
|
831
|
Chris@127
|
832 // If the model that has changed is not used by any of the cached
|
Chris@127
|
833 // layers, we won't need to recreate the cache
|
Chris@127
|
834
|
Chris@127
|
835 bool recreate = false;
|
Chris@127
|
836
|
Chris@127
|
837 bool discard;
|
Chris@127
|
838 LayerList scrollables = getScrollableBackLayers(false, discard);
|
Chris@127
|
839 for (LayerList::const_iterator i = scrollables.begin();
|
Chris@1266
|
840 i != scrollables.end(); ++i) {
|
Chris@1266
|
841 if (*i == obj || (*i)->getModel() == obj) {
|
Chris@1266
|
842 recreate = true;
|
Chris@1266
|
843 break;
|
Chris@1266
|
844 }
|
Chris@127
|
845 }
|
Chris@127
|
846
|
Chris@127
|
847 if (recreate) {
|
Chris@1266
|
848 delete m_cache;
|
Chris@1266
|
849 m_cache = 0;
|
Chris@127
|
850 }
|
Chris@127
|
851
|
Chris@336
|
852 emit layerModelChanged();
|
Chris@336
|
853
|
Chris@127
|
854 checkProgress(obj);
|
Chris@127
|
855
|
Chris@127
|
856 update();
|
Chris@127
|
857 }
|
Chris@127
|
858
|
Chris@127
|
859 void
|
Chris@908
|
860 View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
|
Chris@127
|
861 {
|
Chris@127
|
862 QObject *obj = sender();
|
Chris@127
|
863
|
Chris@908
|
864 sv_frame_t myStartFrame = getStartFrame();
|
Chris@908
|
865 sv_frame_t myEndFrame = getEndFrame();
|
Chris@127
|
866
|
Chris@127
|
867 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@806
|
868 cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl;
|
Chris@127
|
869 #endif
|
Chris@127
|
870
|
Chris@908
|
871 if (myStartFrame > 0 && endFrame < myStartFrame) {
|
Chris@1266
|
872 checkProgress(obj);
|
Chris@1266
|
873 return;
|
Chris@127
|
874 }
|
Chris@127
|
875 if (startFrame > myEndFrame) {
|
Chris@1266
|
876 checkProgress(obj);
|
Chris@1266
|
877 return;
|
Chris@127
|
878 }
|
Chris@127
|
879
|
Chris@127
|
880 // If the model that has changed is not used by any of the cached
|
Chris@127
|
881 // layers, we won't need to recreate the cache
|
Chris@127
|
882
|
Chris@127
|
883 bool recreate = false;
|
Chris@127
|
884
|
Chris@127
|
885 bool discard;
|
Chris@127
|
886 LayerList scrollables = getScrollableBackLayers(false, discard);
|
Chris@127
|
887 for (LayerList::const_iterator i = scrollables.begin();
|
Chris@1266
|
888 i != scrollables.end(); ++i) {
|
Chris@1266
|
889 if (*i == obj || (*i)->getModel() == obj) {
|
Chris@1266
|
890 recreate = true;
|
Chris@1266
|
891 break;
|
Chris@1266
|
892 }
|
Chris@127
|
893 }
|
Chris@127
|
894
|
Chris@127
|
895 if (recreate) {
|
Chris@1266
|
896 delete m_cache;
|
Chris@1266
|
897 m_cache = 0;
|
Chris@127
|
898 }
|
Chris@127
|
899
|
Chris@806
|
900 if (startFrame < myStartFrame) startFrame = myStartFrame;
|
Chris@127
|
901 if (endFrame > myEndFrame) endFrame = myEndFrame;
|
Chris@127
|
902
|
Chris@127
|
903 checkProgress(obj);
|
Chris@127
|
904
|
Chris@127
|
905 update();
|
Chris@127
|
906 }
|
Chris@127
|
907
|
Chris@127
|
908 void
|
Chris@127
|
909 View::modelCompletionChanged()
|
Chris@127
|
910 {
|
Chris@682
|
911 // cerr << "View(" << this << ")::modelCompletionChanged()" << endl;
|
Chris@301
|
912
|
Chris@127
|
913 QObject *obj = sender();
|
Chris@127
|
914 checkProgress(obj);
|
Chris@127
|
915 }
|
Chris@127
|
916
|
Chris@127
|
917 void
|
Chris@320
|
918 View::modelAlignmentCompletionChanged()
|
Chris@320
|
919 {
|
Chris@682
|
920 // cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << endl;
|
Chris@320
|
921
|
Chris@320
|
922 QObject *obj = sender();
|
Chris@320
|
923 checkProgress(obj);
|
Chris@320
|
924 }
|
Chris@320
|
925
|
Chris@320
|
926 void
|
Chris@127
|
927 View::modelReplaced()
|
Chris@127
|
928 {
|
Chris@127
|
929 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@682
|
930 cerr << "View(" << this << ")::modelReplaced()" << endl;
|
Chris@127
|
931 #endif
|
Chris@127
|
932 delete m_cache;
|
Chris@127
|
933 m_cache = 0;
|
Chris@127
|
934
|
Chris@127
|
935 update();
|
Chris@127
|
936 }
|
Chris@127
|
937
|
Chris@127
|
938 void
|
Chris@127
|
939 View::layerParametersChanged()
|
Chris@127
|
940 {
|
Chris@127
|
941 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@127
|
942
|
Chris@127
|
943 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@587
|
944 SVDEBUG << "View::layerParametersChanged()" << endl;
|
Chris@127
|
945 #endif
|
Chris@127
|
946
|
Chris@127
|
947 delete m_cache;
|
Chris@127
|
948 m_cache = 0;
|
Chris@127
|
949 update();
|
Chris@127
|
950
|
Chris@127
|
951 if (layer) {
|
Chris@1266
|
952 emit propertyContainerPropertyChanged(layer);
|
Chris@127
|
953 }
|
Chris@127
|
954 }
|
Chris@127
|
955
|
Chris@127
|
956 void
|
Chris@197
|
957 View::layerParameterRangesChanged()
|
Chris@197
|
958 {
|
Chris@197
|
959 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@197
|
960 if (layer) emit propertyContainerPropertyRangeChanged(layer);
|
Chris@197
|
961 }
|
Chris@197
|
962
|
Chris@197
|
963 void
|
Chris@268
|
964 View::layerMeasurementRectsChanged()
|
Chris@268
|
965 {
|
Chris@268
|
966 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@268
|
967 if (layer) update();
|
Chris@268
|
968 }
|
Chris@268
|
969
|
Chris@268
|
970 void
|
Chris@127
|
971 View::layerNameChanged()
|
Chris@127
|
972 {
|
Chris@127
|
973 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@127
|
974 if (layer) emit propertyContainerNameChanged(layer);
|
Chris@127
|
975 }
|
Chris@127
|
976
|
Chris@127
|
977 void
|
Chris@908
|
978 View::globalCentreFrameChanged(sv_frame_t rf)
|
Chris@127
|
979 {
|
Chris@211
|
980 if (m_followPan) {
|
Chris@908
|
981 sv_frame_t f = alignFromReference(rf);
|
Chris@830
|
982 #ifdef DEBUG_VIEW
|
Chris@682
|
983 cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf
|
Chris@682
|
984 << "): setting centre frame to " << f << endl;
|
Chris@363
|
985 #endif
|
Chris@333
|
986 setCentreFrame(f, false);
|
Chris@127
|
987 }
|
Chris@127
|
988 }
|
Chris@127
|
989
|
Chris@127
|
990 void
|
Chris@908
|
991 View::viewCentreFrameChanged(View *, sv_frame_t )
|
Chris@211
|
992 {
|
Chris@211
|
993 // We do nothing with this, but a subclass might
|
Chris@211
|
994 }
|
Chris@211
|
995
|
Chris@211
|
996 void
|
Chris@908
|
997 View::viewManagerPlaybackFrameChanged(sv_frame_t f)
|
Chris@127
|
998 {
|
Chris@127
|
999 if (m_manager) {
|
Chris@1266
|
1000 if (sender() != m_manager) return;
|
Chris@127
|
1001 }
|
Chris@127
|
1002
|
Chris@830
|
1003 #ifdef DEBUG_VIEW
|
Chris@830
|
1004 cerr << "View::viewManagerPlaybackFrameChanged(" << f << ")" << endl;
|
Chris@830
|
1005 #endif
|
Chris@830
|
1006
|
Chris@301
|
1007 f = getAlignedPlaybackFrame();
|
Chris@301
|
1008
|
Chris@830
|
1009 #ifdef DEBUG_VIEW
|
Chris@951
|
1010 cerr << " -> aligned frame = " << f << endl;
|
Chris@830
|
1011 #endif
|
Chris@830
|
1012
|
Chris@511
|
1013 movePlayPointer(f);
|
Chris@511
|
1014 }
|
Chris@511
|
1015
|
Chris@511
|
1016 void
|
Chris@908
|
1017 View::movePlayPointer(sv_frame_t newFrame)
|
Chris@511
|
1018 {
|
Chris@830
|
1019 #ifdef DEBUG_VIEW
|
Chris@830
|
1020 cerr << "View(" << this << ")::movePlayPointer(" << newFrame << ")" << endl;
|
Chris@830
|
1021 #endif
|
Chris@830
|
1022
|
Chris@511
|
1023 if (m_playPointerFrame == newFrame) return;
|
Chris@511
|
1024 bool visibleChange =
|
Chris@511
|
1025 (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame));
|
Chris@908
|
1026 sv_frame_t oldPlayPointerFrame = m_playPointerFrame;
|
Chris@511
|
1027 m_playPointerFrame = newFrame;
|
Chris@511
|
1028 if (!visibleChange) return;
|
Chris@127
|
1029
|
Chris@513
|
1030 bool somethingGoingOn =
|
Chris@513
|
1031 ((QApplication::mouseButtons() != Qt::NoButton) ||
|
Chris@513
|
1032 (QApplication::keyboardModifiers() & Qt::AltModifier));
|
Chris@513
|
1033
|
Chris@789
|
1034 bool pointerInVisibleArea =
|
Chris@1266
|
1035 long(m_playPointerFrame) >= getStartFrame() &&
|
Chris@789
|
1036 (m_playPointerFrame < getEndFrame() ||
|
Chris@789
|
1037 // include old pointer location so we know to refresh when moving out
|
Chris@789
|
1038 oldPlayPointerFrame < getEndFrame());
|
Chris@789
|
1039
|
Chris@127
|
1040 switch (m_followPlay) {
|
Chris@127
|
1041
|
Chris@127
|
1042 case PlaybackScrollContinuous:
|
Chris@1266
|
1043 if (!somethingGoingOn) {
|
Chris@1266
|
1044 setCentreFrame(m_playPointerFrame, false);
|
Chris@1266
|
1045 }
|
Chris@1266
|
1046 break;
|
Chris@127
|
1047
|
Chris@127
|
1048 case PlaybackScrollPage:
|
Chris@815
|
1049 case PlaybackScrollPageWithCentre:
|
Chris@789
|
1050
|
Chris@789
|
1051 if (!pointerInVisibleArea && somethingGoingOn) {
|
Chris@789
|
1052
|
Chris@789
|
1053 m_followPlayIsDetached = true;
|
Chris@789
|
1054
|
Chris@789
|
1055 } else if (!pointerInVisibleArea && m_followPlayIsDetached) {
|
Chris@789
|
1056
|
Chris@789
|
1057 // do nothing; we aren't tracking until the pointer comes back in
|
Chris@789
|
1058
|
Chris@789
|
1059 } else {
|
Chris@789
|
1060
|
Chris@789
|
1061 int xold = getXForFrame(oldPlayPointerFrame);
|
Chris@789
|
1062 update(xold - 4, 0, 9, height());
|
Chris@789
|
1063
|
Chris@908
|
1064 sv_frame_t w = getEndFrame() - getStartFrame();
|
Chris@789
|
1065 w -= w/5;
|
Chris@908
|
1066 sv_frame_t sf = (m_playPointerFrame / w) * w - w/8;
|
Chris@789
|
1067
|
Chris@789
|
1068 if (m_manager &&
|
Chris@789
|
1069 m_manager->isPlaying() &&
|
Chris@789
|
1070 m_manager->getPlaySelectionMode()) {
|
Chris@789
|
1071 MultiSelection::SelectionList selections = m_manager->getSelections();
|
Chris@789
|
1072 if (!selections.empty()) {
|
Chris@908
|
1073 sv_frame_t selectionStart = selections.begin()->getStartFrame();
|
Chris@808
|
1074 if (sf < selectionStart - w / 10) {
|
Chris@808
|
1075 sf = selectionStart - w / 10;
|
Chris@789
|
1076 }
|
Chris@789
|
1077 }
|
Chris@789
|
1078 }
|
Chris@127
|
1079
|
Chris@127
|
1080 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@789
|
1081 cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame "
|
Chris@789
|
1082 << getStartFrame() << endl;
|
Chris@127
|
1083 #endif
|
Chris@127
|
1084
|
Chris@789
|
1085 // We don't consider scrolling unless the pointer is outside
|
Chris@789
|
1086 // the central visible range already
|
Chris@789
|
1087
|
Chris@789
|
1088 int xnew = getXForFrame(m_playPointerFrame);
|
Chris@127
|
1089
|
Chris@127
|
1090 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@789
|
1091 cerr << "xnew = " << xnew << ", width = " << width() << endl;
|
Chris@127
|
1092 #endif
|
Chris@127
|
1093
|
Chris@789
|
1094 bool shouldScroll = (xnew > (width() * 7) / 8);
|
Chris@789
|
1095
|
Chris@789
|
1096 if (!m_followPlayIsDetached && (xnew < width() / 8)) {
|
Chris@789
|
1097 shouldScroll = true;
|
Chris@789
|
1098 }
|
Chris@789
|
1099
|
Chris@789
|
1100 if (xnew > width() / 8) {
|
Chris@789
|
1101 m_followPlayIsDetached = false;
|
Chris@791
|
1102 } else if (somethingGoingOn) {
|
Chris@791
|
1103 m_followPlayIsDetached = true;
|
Chris@789
|
1104 }
|
Chris@789
|
1105
|
Chris@789
|
1106 if (!somethingGoingOn && shouldScroll) {
|
Chris@908
|
1107 sv_frame_t offset = getFrameForX(width()/2) - getStartFrame();
|
Chris@908
|
1108 sv_frame_t newCentre = sf + offset;
|
Chris@789
|
1109 bool changed = setCentreFrame(newCentre, false);
|
Chris@789
|
1110 if (changed) {
|
Chris@789
|
1111 xold = getXForFrame(oldPlayPointerFrame);
|
Chris@789
|
1112 update(xold - 4, 0, 9, height());
|
Chris@789
|
1113 }
|
Chris@789
|
1114 }
|
Chris@789
|
1115
|
Chris@789
|
1116 update(xnew - 4, 0, 9, height());
|
Chris@789
|
1117 }
|
Chris@789
|
1118 break;
|
Chris@127
|
1119
|
Chris@127
|
1120 case PlaybackIgnore:
|
Chris@1266
|
1121 if (m_playPointerFrame >= getStartFrame() &&
|
Chris@511
|
1122 m_playPointerFrame < getEndFrame()) {
|
Chris@1266
|
1123 update();
|
Chris@1266
|
1124 }
|
Chris@1266
|
1125 break;
|
Chris@127
|
1126 }
|
Chris@127
|
1127 }
|
Chris@127
|
1128
|
Chris@127
|
1129 void
|
Chris@806
|
1130 View::viewZoomLevelChanged(View *p, int z, bool locked)
|
Chris@127
|
1131 {
|
Chris@244
|
1132 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@682
|
1133 cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl;
|
Chris@244
|
1134 #endif
|
Chris@127
|
1135 if (m_followZoom && p != this && locked) {
|
Chris@222
|
1136 setZoomLevel(z);
|
Chris@127
|
1137 }
|
Chris@127
|
1138 }
|
Chris@127
|
1139
|
Chris@127
|
1140 void
|
Chris@127
|
1141 View::selectionChanged()
|
Chris@127
|
1142 {
|
Chris@127
|
1143 if (m_selectionCached) {
|
Chris@1266
|
1144 delete m_cache;
|
Chris@1266
|
1145 m_cache = 0;
|
Chris@1266
|
1146 m_selectionCached = false;
|
Chris@127
|
1147 }
|
Chris@127
|
1148 update();
|
Chris@127
|
1149 }
|
Chris@127
|
1150
|
Chris@908
|
1151 sv_frame_t
|
Chris@222
|
1152 View::getFirstVisibleFrame() const
|
Chris@222
|
1153 {
|
Chris@908
|
1154 sv_frame_t f0 = getStartFrame();
|
Chris@908
|
1155 sv_frame_t f = getModelsStartFrame();
|
Chris@806
|
1156 if (f0 < 0 || f0 < f) return f;
|
Chris@222
|
1157 return f0;
|
Chris@222
|
1158 }
|
Chris@222
|
1159
|
Chris@908
|
1160 sv_frame_t
|
Chris@222
|
1161 View::getLastVisibleFrame() const
|
Chris@222
|
1162 {
|
Chris@908
|
1163 sv_frame_t f0 = getEndFrame();
|
Chris@908
|
1164 sv_frame_t f = getModelsEndFrame();
|
Chris@222
|
1165 if (f0 > f) return f;
|
Chris@222
|
1166 return f0;
|
Chris@222
|
1167 }
|
Chris@222
|
1168
|
Chris@908
|
1169 sv_frame_t
|
Chris@127
|
1170 View::getModelsStartFrame() const
|
Chris@127
|
1171 {
|
Chris@127
|
1172 bool first = true;
|
Chris@908
|
1173 sv_frame_t startFrame = 0;
|
Chris@127
|
1174
|
Chris@835
|
1175 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@127
|
1176
|
Chris@1266
|
1177 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
|
Chris@1266
|
1178
|
Chris@1266
|
1179 sv_frame_t thisStartFrame = (*i)->getModel()->getStartFrame();
|
Chris@1266
|
1180
|
Chris@1266
|
1181 if (first || thisStartFrame < startFrame) {
|
Chris@1266
|
1182 startFrame = thisStartFrame;
|
Chris@1266
|
1183 }
|
Chris@1266
|
1184 first = false;
|
Chris@1266
|
1185 }
|
Chris@127
|
1186 }
|
Chris@127
|
1187 return startFrame;
|
Chris@127
|
1188 }
|
Chris@127
|
1189
|
Chris@908
|
1190 sv_frame_t
|
Chris@127
|
1191 View::getModelsEndFrame() const
|
Chris@127
|
1192 {
|
Chris@127
|
1193 bool first = true;
|
Chris@908
|
1194 sv_frame_t endFrame = 0;
|
Chris@127
|
1195
|
Chris@835
|
1196 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@127
|
1197
|
Chris@1266
|
1198 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
|
Chris@1266
|
1199
|
Chris@1266
|
1200 sv_frame_t thisEndFrame = (*i)->getModel()->getEndFrame();
|
Chris@1266
|
1201
|
Chris@1266
|
1202 if (first || thisEndFrame > endFrame) {
|
Chris@1266
|
1203 endFrame = thisEndFrame;
|
Chris@1266
|
1204 }
|
Chris@1266
|
1205 first = false;
|
Chris@1266
|
1206 }
|
Chris@127
|
1207 }
|
Chris@127
|
1208
|
Chris@127
|
1209 if (first) return getModelsStartFrame();
|
Chris@127
|
1210 return endFrame;
|
Chris@127
|
1211 }
|
Chris@127
|
1212
|
Chris@908
|
1213 sv_samplerate_t
|
Chris@127
|
1214 View::getModelsSampleRate() const
|
Chris@127
|
1215 {
|
Chris@127
|
1216 //!!! Just go for the first, for now. If we were supporting
|
Chris@127
|
1217 // multiple samplerates, we'd probably want to do frame/time
|
Chris@127
|
1218 // conversion in the model
|
Chris@127
|
1219
|
Chris@159
|
1220 //!!! nah, this wants to always return the sr of the main model!
|
Chris@159
|
1221
|
Chris@835
|
1222 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
1223 if ((*i)->getModel() && (*i)->getModel()->isOK()) {
|
Chris@1266
|
1224 return (*i)->getModel()->getSampleRate();
|
Chris@1266
|
1225 }
|
Chris@127
|
1226 }
|
Chris@127
|
1227 return 0;
|
Chris@127
|
1228 }
|
Chris@127
|
1229
|
Chris@315
|
1230 View::ModelSet
|
Chris@315
|
1231 View::getModels()
|
Chris@315
|
1232 {
|
Chris@315
|
1233 ModelSet models;
|
Chris@315
|
1234
|
Chris@315
|
1235 for (int i = 0; i < getLayerCount(); ++i) {
|
Chris@315
|
1236
|
Chris@315
|
1237 Layer *layer = getLayer(i);
|
Chris@315
|
1238
|
Chris@315
|
1239 if (dynamic_cast<TimeRulerLayer *>(layer)) {
|
Chris@315
|
1240 continue;
|
Chris@315
|
1241 }
|
Chris@315
|
1242
|
Chris@315
|
1243 if (layer && layer->getModel()) {
|
Chris@315
|
1244 Model *model = layer->getModel();
|
Chris@315
|
1245 models.insert(model);
|
Chris@315
|
1246 }
|
Chris@315
|
1247 }
|
Chris@315
|
1248
|
Chris@315
|
1249 return models;
|
Chris@315
|
1250 }
|
Chris@315
|
1251
|
Chris@320
|
1252 Model *
|
Chris@320
|
1253 View::getAligningModel() const
|
Chris@301
|
1254 {
|
Chris@320
|
1255 if (!m_manager ||
|
Chris@320
|
1256 !m_manager->getAlignMode() ||
|
Chris@314
|
1257 !m_manager->getPlaybackModel()) {
|
Chris@320
|
1258 return 0;
|
Chris@314
|
1259 }
|
Chris@301
|
1260
|
Chris@320
|
1261 Model *anyModel = 0;
|
Chris@359
|
1262 Model *alignedModel = 0;
|
Chris@320
|
1263 Model *goodModel = 0;
|
Chris@301
|
1264
|
Chris@835
|
1265 for (LayerList::const_iterator i = m_layerStack.begin();
|
Chris@835
|
1266 i != m_layerStack.end(); ++i) {
|
Chris@320
|
1267
|
Chris@320
|
1268 Layer *layer = *i;
|
Chris@320
|
1269
|
Chris@320
|
1270 if (!layer) continue;
|
Chris@320
|
1271 if (dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@301
|
1272
|
Chris@301
|
1273 Model *model = (*i)->getModel();
|
Chris@301
|
1274 if (!model) continue;
|
Chris@301
|
1275
|
Chris@359
|
1276 anyModel = model;
|
Chris@359
|
1277
|
Chris@320
|
1278 if (model->getAlignmentReference()) {
|
Chris@359
|
1279 alignedModel = model;
|
Chris@320
|
1280 if (layer->isLayerOpaque() ||
|
Chris@320
|
1281 dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
|
Chris@320
|
1282 goodModel = model;
|
Chris@320
|
1283 }
|
Chris@301
|
1284 }
|
Chris@320
|
1285 }
|
Chris@301
|
1286
|
Chris@320
|
1287 if (goodModel) return goodModel;
|
Chris@359
|
1288 else if (alignedModel) return alignedModel;
|
Chris@320
|
1289 else return anyModel;
|
Chris@320
|
1290 }
|
Chris@320
|
1291
|
Chris@908
|
1292 sv_frame_t
|
Chris@908
|
1293 View::alignFromReference(sv_frame_t f) const
|
Chris@320
|
1294 {
|
Chris@856
|
1295 if (!m_manager || !m_manager->getAlignMode()) return f;
|
Chris@320
|
1296 Model *aligningModel = getAligningModel();
|
Chris@320
|
1297 if (!aligningModel) return f;
|
Chris@320
|
1298 return aligningModel->alignFromReference(f);
|
Chris@320
|
1299 }
|
Chris@320
|
1300
|
Chris@908
|
1301 sv_frame_t
|
Chris@908
|
1302 View::alignToReference(sv_frame_t f) const
|
Chris@320
|
1303 {
|
Chris@321
|
1304 if (!m_manager->getAlignMode()) return f;
|
Chris@320
|
1305 Model *aligningModel = getAligningModel();
|
Chris@320
|
1306 if (!aligningModel) return f;
|
Chris@320
|
1307 return aligningModel->alignToReference(f);
|
Chris@320
|
1308 }
|
Chris@320
|
1309
|
Chris@908
|
1310 sv_frame_t
|
Chris@320
|
1311 View::getAlignedPlaybackFrame() const
|
Chris@320
|
1312 {
|
Chris@856
|
1313 if (!m_manager) return 0;
|
Chris@908
|
1314 sv_frame_t pf = m_manager->getPlaybackFrame();
|
Chris@321
|
1315 if (!m_manager->getAlignMode()) return pf;
|
Chris@321
|
1316
|
Chris@320
|
1317 Model *aligningModel = getAligningModel();
|
Chris@320
|
1318 if (!aligningModel) return pf;
|
Chris@830
|
1319
|
Chris@908
|
1320 sv_frame_t af = aligningModel->alignFromReference(pf);
|
Chris@301
|
1321
|
Chris@301
|
1322 return af;
|
Chris@301
|
1323 }
|
Chris@301
|
1324
|
Chris@127
|
1325 bool
|
Chris@127
|
1326 View::areLayersScrollable() const
|
Chris@127
|
1327 {
|
Chris@127
|
1328 // True iff all views are scrollable
|
Chris@835
|
1329 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
1330 if (!(*i)->isLayerScrollable(this)) return false;
|
Chris@127
|
1331 }
|
Chris@127
|
1332 return true;
|
Chris@127
|
1333 }
|
Chris@127
|
1334
|
Chris@127
|
1335 View::LayerList
|
Chris@127
|
1336 View::getScrollableBackLayers(bool testChanged, bool &changed) const
|
Chris@127
|
1337 {
|
Chris@127
|
1338 changed = false;
|
Chris@127
|
1339
|
Chris@127
|
1340 // We want a list of all the scrollable layers that are behind the
|
Chris@127
|
1341 // backmost non-scrollable layer.
|
Chris@127
|
1342
|
Chris@127
|
1343 LayerList scrollables;
|
Chris@127
|
1344 bool metUnscrollable = false;
|
Chris@127
|
1345
|
Chris@835
|
1346 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@587
|
1347 // SVDEBUG << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << endl;
|
Chris@682
|
1348 // cerr << "(name is " << (*i)->objectName() << ")"
|
Chris@682
|
1349 // << endl;
|
Chris@587
|
1350 // SVDEBUG << "View::getScrollableBackLayers: I am " << this << endl;
|
Chris@1266
|
1351 if ((*i)->isLayerDormant(this)) continue;
|
Chris@1266
|
1352 if ((*i)->isLayerOpaque()) {
|
Chris@1266
|
1353 // You can't see anything behind an opaque layer!
|
Chris@1266
|
1354 scrollables.clear();
|
Chris@127
|
1355 if (metUnscrollable) break;
|
Chris@1266
|
1356 }
|
Chris@1266
|
1357 if (!metUnscrollable && (*i)->isLayerScrollable(this)) {
|
Chris@127
|
1358 scrollables.push_back(*i);
|
Chris@127
|
1359 } else {
|
Chris@127
|
1360 metUnscrollable = true;
|
Chris@127
|
1361 }
|
Chris@127
|
1362 }
|
Chris@127
|
1363
|
Chris@127
|
1364 if (testChanged && scrollables != m_lastScrollableBackLayers) {
|
Chris@1266
|
1365 m_lastScrollableBackLayers = scrollables;
|
Chris@1266
|
1366 changed = true;
|
Chris@127
|
1367 }
|
Chris@127
|
1368 return scrollables;
|
Chris@127
|
1369 }
|
Chris@127
|
1370
|
Chris@127
|
1371 View::LayerList
|
Chris@127
|
1372 View::getNonScrollableFrontLayers(bool testChanged, bool &changed) const
|
Chris@127
|
1373 {
|
Chris@127
|
1374 changed = false;
|
Chris@127
|
1375 LayerList nonScrollables;
|
Chris@127
|
1376
|
Chris@127
|
1377 // Everything in front of the first non-scrollable from the back
|
Chris@127
|
1378 // should also be considered non-scrollable
|
Chris@127
|
1379
|
Chris@127
|
1380 bool started = false;
|
Chris@127
|
1381
|
Chris@835
|
1382 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
1383 if ((*i)->isLayerDormant(this)) continue;
|
Chris@1266
|
1384 if (!started && (*i)->isLayerScrollable(this)) {
|
Chris@1266
|
1385 continue;
|
Chris@1266
|
1386 }
|
Chris@1266
|
1387 started = true;
|
Chris@1266
|
1388 if ((*i)->isLayerOpaque()) {
|
Chris@1266
|
1389 // You can't see anything behind an opaque layer!
|
Chris@1266
|
1390 nonScrollables.clear();
|
Chris@1266
|
1391 }
|
Chris@1266
|
1392 nonScrollables.push_back(*i);
|
Chris@127
|
1393 }
|
Chris@127
|
1394
|
Chris@127
|
1395 if (testChanged && nonScrollables != m_lastNonScrollableBackLayers) {
|
Chris@1266
|
1396 m_lastNonScrollableBackLayers = nonScrollables;
|
Chris@1266
|
1397 changed = true;
|
Chris@127
|
1398 }
|
Chris@127
|
1399
|
Chris@127
|
1400 return nonScrollables;
|
Chris@127
|
1401 }
|
Chris@127
|
1402
|
Chris@806
|
1403 int
|
Chris@806
|
1404 View::getZoomConstraintBlockSize(int blockSize,
|
Chris@1266
|
1405 ZoomConstraint::RoundingDirection dir)
|
Chris@127
|
1406 const
|
Chris@127
|
1407 {
|
Chris@806
|
1408 int candidate = blockSize;
|
Chris@127
|
1409 bool haveCandidate = false;
|
Chris@127
|
1410
|
Chris@127
|
1411 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint;
|
Chris@127
|
1412
|
Chris@835
|
1413 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@127
|
1414
|
Chris@1266
|
1415 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint();
|
Chris@1266
|
1416 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint;
|
Chris@1266
|
1417
|
Chris@1266
|
1418 int thisBlockSize =
|
Chris@1266
|
1419 zoomConstraint->getNearestBlockSize(blockSize, dir);
|
Chris@1266
|
1420
|
Chris@1266
|
1421 // Go for the block size that's furthest from the one
|
Chris@1266
|
1422 // passed in. Most of the time, that's what we want.
|
Chris@1266
|
1423 if (!haveCandidate ||
|
Chris@1266
|
1424 (thisBlockSize > blockSize && thisBlockSize > candidate) ||
|
Chris@1266
|
1425 (thisBlockSize < blockSize && thisBlockSize < candidate)) {
|
Chris@1266
|
1426 candidate = thisBlockSize;
|
Chris@1266
|
1427 haveCandidate = true;
|
Chris@1266
|
1428 }
|
Chris@127
|
1429 }
|
Chris@127
|
1430
|
Chris@127
|
1431 return candidate;
|
Chris@127
|
1432 }
|
Chris@127
|
1433
|
Chris@183
|
1434 bool
|
Chris@183
|
1435 View::areLayerColoursSignificant() const
|
Chris@183
|
1436 {
|
Chris@835
|
1437 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
1438 if ((*i)->getLayerColourSignificance() ==
|
Chris@287
|
1439 Layer::ColourHasMeaningfulValue) return true;
|
Chris@183
|
1440 if ((*i)->isLayerOpaque()) break;
|
Chris@183
|
1441 }
|
Chris@183
|
1442 return false;
|
Chris@183
|
1443 }
|
Chris@183
|
1444
|
Chris@217
|
1445 bool
|
Chris@217
|
1446 View::hasTopLayerTimeXAxis() const
|
Chris@217
|
1447 {
|
Chris@835
|
1448 LayerList::const_iterator i = m_layerStack.end();
|
Chris@835
|
1449 if (i == m_layerStack.begin()) return false;
|
Chris@217
|
1450 --i;
|
Chris@217
|
1451 return (*i)->hasTimeXAxis();
|
Chris@217
|
1452 }
|
Chris@217
|
1453
|
Chris@127
|
1454 void
|
Chris@127
|
1455 View::zoom(bool in)
|
Chris@127
|
1456 {
|
Chris@127
|
1457 int newZoomLevel = m_zoomLevel;
|
Chris@127
|
1458
|
Chris@127
|
1459 if (in) {
|
Chris@1266
|
1460 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
Chris@1266
|
1461 ZoomConstraint::RoundDown);
|
Chris@127
|
1462 } else {
|
Chris@1266
|
1463 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
Chris@1266
|
1464 ZoomConstraint::RoundUp);
|
Chris@127
|
1465 }
|
Chris@127
|
1466
|
Chris@127
|
1467 if (newZoomLevel != m_zoomLevel) {
|
Chris@1266
|
1468 setZoomLevel(newZoomLevel);
|
Chris@127
|
1469 }
|
Chris@127
|
1470 }
|
Chris@127
|
1471
|
Chris@127
|
1472 void
|
Chris@510
|
1473 View::scroll(bool right, bool lots, bool e)
|
Chris@127
|
1474 {
|
Chris@908
|
1475 sv_frame_t delta;
|
Chris@127
|
1476 if (lots) {
|
Chris@1266
|
1477 delta = (getEndFrame() - getStartFrame()) / 2;
|
Chris@127
|
1478 } else {
|
Chris@1266
|
1479 delta = (getEndFrame() - getStartFrame()) / 20;
|
Chris@127
|
1480 }
|
Chris@127
|
1481 if (right) delta = -delta;
|
Chris@127
|
1482
|
Chris@908
|
1483 if (m_centreFrame < delta) {
|
Chris@1266
|
1484 setCentreFrame(0, e);
|
Chris@908
|
1485 } else if (m_centreFrame - delta >= getModelsEndFrame()) {
|
Chris@1266
|
1486 setCentreFrame(getModelsEndFrame(), e);
|
Chris@127
|
1487 } else {
|
Chris@1266
|
1488 setCentreFrame(m_centreFrame - delta, e);
|
Chris@127
|
1489 }
|
Chris@127
|
1490 }
|
Chris@127
|
1491
|
Chris@127
|
1492 void
|
Chris@797
|
1493 View::cancelClicked()
|
Chris@797
|
1494 {
|
Chris@797
|
1495 QPushButton *cancel = qobject_cast<QPushButton *>(sender());
|
Chris@797
|
1496 if (!cancel) return;
|
Chris@797
|
1497
|
Chris@797
|
1498 for (ProgressMap::iterator i = m_progressBars.begin();
|
Chris@1266
|
1499 i != m_progressBars.end(); ++i) {
|
Chris@797
|
1500
|
Chris@797
|
1501 if (i->second.cancel == cancel) {
|
Chris@797
|
1502
|
Chris@797
|
1503 Layer *layer = i->first;
|
Chris@797
|
1504 Model *model = layer->getModel();
|
Chris@797
|
1505
|
Chris@797
|
1506 if (model) model->abandon();
|
Chris@797
|
1507 }
|
Chris@797
|
1508 }
|
Chris@797
|
1509 }
|
Chris@797
|
1510
|
Chris@797
|
1511 void
|
Chris@127
|
1512 View::checkProgress(void *object)
|
Chris@127
|
1513 {
|
Chris@127
|
1514 if (!m_showProgress) return;
|
Chris@127
|
1515
|
Chris@127
|
1516 int ph = height();
|
Chris@127
|
1517
|
Chris@555
|
1518 for (ProgressMap::iterator i = m_progressBars.begin();
|
Chris@1266
|
1519 i != m_progressBars.end(); ++i) {
|
Chris@127
|
1520
|
Chris@555
|
1521 QProgressBar *pb = i->second.bar;
|
Chris@797
|
1522 QPushButton *cancel = i->second.cancel;
|
Chris@555
|
1523
|
Chris@1266
|
1524 if (i->first == object) {
|
Chris@127
|
1525
|
Chris@555
|
1526 // The timer is used to test for stalls. If the progress
|
Chris@555
|
1527 // bar does not get updated for some length of time, the
|
Chris@555
|
1528 // timer prompts it to go back into "indeterminate" mode
|
Chris@555
|
1529 QTimer *timer = i->second.checkTimer;
|
Chris@555
|
1530
|
Chris@1266
|
1531 int completion = i->first->getCompletion(this);
|
Chris@301
|
1532 QString text = i->first->getPropertyContainerName();
|
Chris@583
|
1533 QString error = i->first->getError(this);
|
Chris@583
|
1534
|
Chris@583
|
1535 if (error != "" && error != m_lastError) {
|
Chris@583
|
1536 QMessageBox::critical(this, tr("Layer rendering error"), error);
|
Chris@583
|
1537 m_lastError = error;
|
Chris@583
|
1538 }
|
Chris@301
|
1539
|
Chris@387
|
1540 Model *model = i->first->getModel();
|
Chris@387
|
1541 RangeSummarisableTimeValueModel *wfm =
|
Chris@387
|
1542 dynamic_cast<RangeSummarisableTimeValueModel *>(model);
|
Chris@387
|
1543
|
Chris@388
|
1544 if (completion > 0) {
|
Chris@555
|
1545 pb->setMaximum(100); // was 0, for indeterminate start
|
Chris@388
|
1546 }
|
Chris@388
|
1547
|
Chris@301
|
1548 if (completion >= 100) {
|
Chris@301
|
1549
|
Chris@301
|
1550 //!!!
|
Chris@326
|
1551 if (wfm ||
|
Chris@776
|
1552 (model &&
|
Chris@776
|
1553 (wfm = dynamic_cast<RangeSummarisableTimeValueModel *>
|
Chris@776
|
1554 (model->getSourceModel())))) {
|
Chris@301
|
1555 completion = wfm->getAlignmentCompletion();
|
Chris@587
|
1556 // SVDEBUG << "View::checkProgress: Alignment completion = " << completion << endl;
|
Chris@301
|
1557 if (completion < 100) {
|
Chris@301
|
1558 text = tr("Alignment");
|
Chris@301
|
1559 }
|
Chris@301
|
1560 }
|
Chris@387
|
1561
|
Chris@387
|
1562 } else if (wfm) {
|
Chris@387
|
1563 update(); // ensure duration &c gets updated
|
Chris@301
|
1564 }
|
Chris@127
|
1565
|
Chris@1266
|
1566 if (completion >= 100) {
|
Chris@1266
|
1567
|
Chris@1266
|
1568 pb->hide();
|
Chris@797
|
1569 cancel->hide();
|
Chris@555
|
1570 timer->stop();
|
Chris@127
|
1571
|
Chris@1266
|
1572 } else {
|
Chris@127
|
1573
|
Chris@682
|
1574 // cerr << "progress = " << completion << endl;
|
Chris@555
|
1575
|
Chris@555
|
1576 if (!pb->isVisible()) {
|
Chris@555
|
1577 i->second.lastCheck = 0;
|
Chris@555
|
1578 timer->setInterval(2000);
|
Chris@555
|
1579 timer->start();
|
Chris@555
|
1580 }
|
Chris@555
|
1581
|
Chris@1351
|
1582 int scaled20 = ViewManager::scalePixelSize(20);
|
Chris@1351
|
1583
|
Chris@1351
|
1584 cancel->move(0, ph - pb->height()/2 - scaled20/2);
|
Chris@797
|
1585 cancel->show();
|
Chris@797
|
1586
|
Chris@1266
|
1587 pb->setValue(completion);
|
Chris@1351
|
1588 pb->move(scaled20, ph - pb->height());
|
Chris@1266
|
1589
|
Chris@1266
|
1590 pb->show();
|
Chris@1266
|
1591 pb->update();
|
Chris@1266
|
1592
|
Chris@1266
|
1593 ph -= pb->height();
|
Chris@1266
|
1594 }
|
Chris@1266
|
1595 } else {
|
Chris@1266
|
1596 if (pb->isVisible()) {
|
Chris@1266
|
1597 ph -= pb->height();
|
Chris@1266
|
1598 }
|
Chris@1266
|
1599 }
|
Chris@127
|
1600 }
|
Chris@127
|
1601 }
|
Chris@127
|
1602
|
Chris@555
|
1603 void
|
Chris@555
|
1604 View::progressCheckStalledTimerElapsed()
|
Chris@555
|
1605 {
|
Chris@555
|
1606 QObject *s = sender();
|
Chris@555
|
1607 QTimer *t = qobject_cast<QTimer *>(s);
|
Chris@555
|
1608 if (!t) return;
|
Chris@555
|
1609 for (ProgressMap::iterator i = m_progressBars.begin();
|
Chris@555
|
1610 i != m_progressBars.end(); ++i) {
|
Chris@555
|
1611 if (i->second.checkTimer == t) {
|
Chris@555
|
1612 int value = i->second.bar->value();
|
Chris@555
|
1613 if (value > 0 && value == i->second.lastCheck) {
|
Chris@555
|
1614 i->second.bar->setMaximum(0); // indeterminate
|
Chris@555
|
1615 }
|
Chris@555
|
1616 i->second.lastCheck = value;
|
Chris@555
|
1617 return;
|
Chris@555
|
1618 }
|
Chris@555
|
1619 }
|
Chris@555
|
1620 }
|
Chris@555
|
1621
|
Chris@384
|
1622 int
|
Chris@384
|
1623 View::getProgressBarWidth() const
|
Chris@384
|
1624 {
|
Chris@384
|
1625 for (ProgressMap::const_iterator i = m_progressBars.begin();
|
Chris@1266
|
1626 i != m_progressBars.end(); ++i) {
|
Chris@555
|
1627 if (i->second.bar && i->second.bar->isVisible()) {
|
Chris@555
|
1628 return i->second.bar->width();
|
Chris@555
|
1629 }
|
Chris@384
|
1630 }
|
Chris@384
|
1631
|
Chris@384
|
1632 return 0;
|
Chris@384
|
1633 }
|
Chris@384
|
1634
|
Chris@127
|
1635 void
|
Chris@339
|
1636 View::setPaintFont(QPainter &paint)
|
Chris@339
|
1637 {
|
Chris@955
|
1638 int scaleFactor = 1;
|
Chris@956
|
1639 int dpratio = effectiveDevicePixelRatio();
|
Chris@955
|
1640 if (dpratio > 1) {
|
Chris@955
|
1641 QPaintDevice *dev = paint.device();
|
Chris@955
|
1642 if (dynamic_cast<QPixmap *>(dev) || dynamic_cast<QImage *>(dev)) {
|
Chris@955
|
1643 scaleFactor = dpratio;
|
Chris@955
|
1644 }
|
Chris@955
|
1645 }
|
Chris@955
|
1646
|
Chris@339
|
1647 QFont font(paint.font());
|
Chris@955
|
1648 font.setPointSize(Preferences::getInstance()->getViewFontSize()
|
Chris@955
|
1649 * scaleFactor);
|
Chris@339
|
1650 paint.setFont(font);
|
Chris@339
|
1651 }
|
Chris@339
|
1652
|
Chris@915
|
1653 QRect
|
Chris@915
|
1654 View::getPaintRect() const
|
Chris@915
|
1655 {
|
Chris@919
|
1656 return rect();
|
Chris@915
|
1657 }
|
Chris@915
|
1658
|
Chris@339
|
1659 void
|
Chris@127
|
1660 View::paintEvent(QPaintEvent *e)
|
Chris@127
|
1661 {
|
Chris@127
|
1662 // Profiler prof("View::paintEvent", false);
|
Chris@800
|
1663 // cerr << "View::paintEvent: centre frame is " << m_centreFrame << endl;
|
matthiasm@785
|
1664
|
Chris@835
|
1665 if (m_layerStack.empty()) {
|
Chris@1266
|
1666 QFrame::paintEvent(e);
|
Chris@1266
|
1667 return;
|
Chris@127
|
1668 }
|
Chris@127
|
1669
|
Chris@127
|
1670 // ensure our constraints are met
|
Chris@137
|
1671
|
Chris@137
|
1672 /*!!! Should we do this only if we have layers that can't support other
|
Chris@137
|
1673 zoom levels?
|
Chris@137
|
1674
|
Chris@127
|
1675 m_zoomLevel = getZoomConstraintBlockSize(m_zoomLevel,
|
Chris@1266
|
1676 ZoomConstraint::RoundUp);
|
Chris@137
|
1677 */
|
Chris@127
|
1678
|
Chris@127
|
1679 QPainter paint;
|
Chris@127
|
1680 bool repaintCache = false;
|
Chris@127
|
1681 bool paintedCacheRect = false;
|
Chris@127
|
1682
|
Chris@127
|
1683 QRect cacheRect(rect());
|
Chris@127
|
1684
|
Chris@127
|
1685 if (e) {
|
Chris@1266
|
1686 cacheRect &= e->rect();
|
Chris@127
|
1687 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
1688 cerr << "paint rect " << cacheRect.width() << "x" << cacheRect.height()
|
Chris@1266
|
1689 << ", my rect " << width() << "x" << height() << endl;
|
Chris@127
|
1690 #endif
|
Chris@127
|
1691 }
|
Chris@127
|
1692
|
Chris@127
|
1693 QRect nonCacheRect(cacheRect);
|
Chris@127
|
1694
|
Chris@956
|
1695 int dpratio = effectiveDevicePixelRatio();
|
Chris@953
|
1696
|
Chris@127
|
1697 // If not all layers are scrollable, but some of the back layers
|
Chris@127
|
1698 // are, we should store only those in the cache.
|
Chris@127
|
1699
|
Chris@127
|
1700 bool layersChanged = false;
|
Chris@127
|
1701 LayerList scrollables = getScrollableBackLayers(true, layersChanged);
|
Chris@127
|
1702 LayerList nonScrollables = getNonScrollableFrontLayers(true, layersChanged);
|
Chris@127
|
1703 bool selectionCacheable = nonScrollables.empty();
|
Chris@127
|
1704 bool haveSelections = m_manager && !m_manager->getSelections().empty();
|
Chris@127
|
1705
|
Chris@127
|
1706 // If all the non-scrollable layers are non-opaque, then we draw
|
Chris@127
|
1707 // the selection rectangle behind them and cache it. If any are
|
Chris@953
|
1708 // opaque, however, or if our device-pixel ratio is not 1 (so we
|
Chris@953
|
1709 // need to paint direct to the widget), then we can't cache.
|
Chris@127
|
1710 //
|
Chris@953
|
1711 if (dpratio == 1) {
|
Chris@953
|
1712
|
Chris@953
|
1713 if (!selectionCacheable) {
|
Chris@953
|
1714 selectionCacheable = true;
|
Chris@953
|
1715 for (LayerList::const_iterator i = nonScrollables.begin();
|
Chris@953
|
1716 i != nonScrollables.end(); ++i) {
|
Chris@953
|
1717 if ((*i)->isLayerOpaque()) {
|
Chris@953
|
1718 selectionCacheable = false;
|
Chris@953
|
1719 break;
|
Chris@953
|
1720 }
|
Chris@953
|
1721 }
|
Chris@953
|
1722 }
|
Chris@953
|
1723
|
Chris@953
|
1724 if (selectionCacheable) {
|
Chris@953
|
1725 QPoint localPos;
|
Chris@953
|
1726 bool closeToLeft, closeToRight;
|
Chris@953
|
1727 if (shouldIlluminateLocalSelection
|
Chris@953
|
1728 (localPos, closeToLeft, closeToRight)) {
|
Chris@953
|
1729 selectionCacheable = false;
|
Chris@953
|
1730 }
|
Chris@953
|
1731 }
|
Chris@953
|
1732
|
Chris@953
|
1733 } else {
|
Chris@953
|
1734
|
Chris@953
|
1735 selectionCacheable = false;
|
Chris@127
|
1736 }
|
Chris@127
|
1737
|
Chris@127
|
1738 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@682
|
1739 cerr << "View(" << this << ")::paintEvent: have " << scrollables.size()
|
Chris@1266
|
1740 << " scrollable back layers and " << nonScrollables.size()
|
Chris@1266
|
1741 << " non-scrollable front layers" << endl;
|
Chris@682
|
1742 cerr << "haveSelections " << haveSelections << ", selectionCacheable "
|
Chris@1266
|
1743 << selectionCacheable << ", m_selectionCached " << m_selectionCached << endl;
|
Chris@127
|
1744 #endif
|
Chris@127
|
1745
|
Chris@127
|
1746 if (layersChanged || scrollables.empty() ||
|
Chris@1266
|
1747 (haveSelections && (selectionCacheable != m_selectionCached))) {
|
Chris@1266
|
1748 delete m_cache;
|
Chris@1266
|
1749 m_cache = 0;
|
Chris@1266
|
1750 m_selectionCached = false;
|
Chris@127
|
1751 }
|
Chris@127
|
1752
|
Chris@952
|
1753 QSize scaledCacheSize(scaledSize(size(), dpratio));
|
Chris@952
|
1754 QRect scaledCacheRect(scaledRect(cacheRect, dpratio));
|
Chris@952
|
1755
|
Chris@952
|
1756 if (!m_buffer || scaledCacheSize != m_buffer->size()) {
|
Chris@952
|
1757 delete m_buffer;
|
Chris@952
|
1758 m_buffer = new QPixmap(scaledCacheSize);
|
Chris@952
|
1759 }
|
Chris@952
|
1760
|
Chris@127
|
1761 if (!scrollables.empty()) {
|
Chris@244
|
1762
|
Chris@244
|
1763 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@682
|
1764 cerr << "View(" << this << "): cache " << m_cache << ", cache zoom "
|
Chris@682
|
1765 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl;
|
Chris@244
|
1766 #endif
|
Chris@244
|
1767
|
Chris@1266
|
1768 if (!m_cache ||
|
Chris@1266
|
1769 m_cacheZoomLevel != m_zoomLevel ||
|
Chris@914
|
1770 scaledCacheSize != m_cache->size()) {
|
Chris@127
|
1771
|
Chris@1266
|
1772 // cache is not valid
|
Chris@1266
|
1773
|
Chris@1266
|
1774 if (cacheRect.width() < width()/10) {
|
Chris@1266
|
1775 delete m_cache;
|
Chris@244
|
1776 m_cache = 0;
|
Chris@127
|
1777 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
1778 cerr << "View(" << this << ")::paintEvent: small repaint, not bothering to recreate cache" << endl;
|
Chris@127
|
1779 #endif
|
Chris@1266
|
1780 } else {
|
Chris@1266
|
1781 delete m_cache;
|
Chris@1266
|
1782 m_cache = new QPixmap(scaledCacheSize);
|
Chris@127
|
1783 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
1784 cerr << "View(" << this << ")::paintEvent: recreated cache" << endl;
|
Chris@127
|
1785 #endif
|
Chris@1266
|
1786 cacheRect = rect();
|
Chris@1266
|
1787 repaintCache = true;
|
Chris@1266
|
1788 }
|
Chris@1266
|
1789
|
Chris@1266
|
1790 } else if (m_cacheCentreFrame != m_centreFrame) {
|
Chris@1266
|
1791
|
Chris@1266
|
1792 int dx =
|
Chris@1266
|
1793 getXForFrame(m_cacheCentreFrame) -
|
Chris@1266
|
1794 getXForFrame(m_centreFrame);
|
Chris@1266
|
1795
|
Chris@1266
|
1796 if (dx > -width() && dx < width()) {
|
Chris@1266
|
1797 static QPixmap *tmpPixmap = 0;
|
Chris@1266
|
1798 if (!tmpPixmap || tmpPixmap->size() != scaledCacheSize) {
|
Chris@1266
|
1799 delete tmpPixmap;
|
Chris@1266
|
1800 tmpPixmap = new QPixmap(scaledCacheSize);
|
Chris@1266
|
1801 }
|
Chris@1266
|
1802 paint.begin(tmpPixmap);
|
Chris@1266
|
1803 paint.drawPixmap(0, 0, *m_cache);
|
Chris@1266
|
1804 paint.end();
|
Chris@1266
|
1805 paint.begin(m_cache);
|
Chris@1266
|
1806 paint.drawPixmap(dx, 0, *tmpPixmap);
|
Chris@1266
|
1807 paint.end();
|
Chris@1266
|
1808 if (dx < 0) {
|
Chris@1266
|
1809 cacheRect = QRect(width() + dx, 0, -dx, height());
|
Chris@1266
|
1810 } else {
|
Chris@1266
|
1811 cacheRect = QRect(0, 0, dx, height());
|
Chris@1266
|
1812 }
|
Chris@127
|
1813 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
1814 cerr << "View(" << this << ")::paintEvent: scrolled cache by " << dx << endl;
|
Chris@127
|
1815 #endif
|
Chris@1266
|
1816 } else {
|
Chris@1266
|
1817 cacheRect = rect();
|
Chris@127
|
1818 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
1819 cerr << "View(" << this << ")::paintEvent: scrolling too far" << endl;
|
Chris@127
|
1820 #endif
|
Chris@1266
|
1821 }
|
Chris@1266
|
1822 repaintCache = true;
|
Chris@1266
|
1823
|
Chris@1266
|
1824 } else {
|
Chris@127
|
1825 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
1826 cerr << "View(" << this << ")::paintEvent: cache is good" << endl;
|
Chris@127
|
1827 #endif
|
Chris@1266
|
1828 paint.begin(m_buffer);
|
Chris@1266
|
1829 paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect);
|
Chris@1266
|
1830 paint.end();
|
Chris@1266
|
1831 QFrame::paintEvent(e);
|
Chris@1266
|
1832 paintedCacheRect = true;
|
Chris@1266
|
1833 }
|
Chris@1266
|
1834
|
Chris@1266
|
1835 m_cacheCentreFrame = m_centreFrame;
|
Chris@1266
|
1836 m_cacheZoomLevel = m_zoomLevel;
|
Chris@127
|
1837 }
|
Chris@127
|
1838
|
Chris@127
|
1839 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@682
|
1840 // cerr << "View(" << this << ")::paintEvent: cacheRect " << cacheRect << ", nonCacheRect " << (nonCacheRect | cacheRect) << ", repaintCache " << repaintCache << ", paintedCacheRect " << paintedCacheRect << endl;
|
Chris@127
|
1841 #endif
|
Chris@127
|
1842
|
Chris@127
|
1843 // Scrollable (cacheable) items first
|
Chris@127
|
1844
|
Chris@919
|
1845 ViewProxy proxy(this, dpratio);
|
Chris@919
|
1846
|
Chris@127
|
1847 if (!paintedCacheRect) {
|
Chris@127
|
1848
|
Chris@914
|
1849 QRect rectToPaint;
|
Chris@914
|
1850
|
Chris@1266
|
1851 if (repaintCache) {
|
Chris@914
|
1852 paint.begin(m_cache);
|
Chris@914
|
1853 rectToPaint = scaledCacheRect;
|
Chris@914
|
1854 } else {
|
Chris@952
|
1855 paint.begin(m_buffer);
|
Chris@952
|
1856 rectToPaint = scaledCacheRect;
|
Chris@914
|
1857 }
|
Chris@914
|
1858
|
Chris@339
|
1859 setPaintFont(paint);
|
Chris@1266
|
1860 paint.setClipRect(rectToPaint);
|
Chris@287
|
1861
|
Chris@287
|
1862 paint.setPen(getBackground());
|
Chris@287
|
1863 paint.setBrush(getBackground());
|
Chris@1266
|
1864 paint.drawRect(rectToPaint);
|
Chris@1266
|
1865
|
Chris@1266
|
1866 paint.setPen(getForeground());
|
Chris@1266
|
1867 paint.setBrush(Qt::NoBrush);
|
Chris@1266
|
1868
|
Chris@1266
|
1869 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) {
|
Chris@1266
|
1870 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@1266
|
1871 paint.save();
|
Chris@951
|
1872 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@951
|
1873 cerr << "Painting scrollable layer " << *i << " using proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << rectToPaint.x() << "," << rectToPaint.y() << " " << rectToPaint.width() << "x" << rectToPaint.height() << endl;
|
Chris@951
|
1874 #endif
|
Chris@919
|
1875 (*i)->paint(&proxy, paint, rectToPaint);
|
Chris@1266
|
1876 paint.restore();
|
Chris@1266
|
1877 }
|
Chris@1266
|
1878
|
Chris@1266
|
1879 if (haveSelections && selectionCacheable) {
|
Chris@1266
|
1880 drawSelections(paint);
|
Chris@1266
|
1881 m_selectionCached = repaintCache;
|
Chris@1266
|
1882 }
|
Chris@1266
|
1883
|
Chris@1266
|
1884 paint.end();
|
Chris@1266
|
1885
|
Chris@1266
|
1886 if (repaintCache) {
|
Chris@1266
|
1887 cacheRect |= (e ? e->rect() : rect());
|
Chris@952
|
1888 scaledCacheRect = scaledRect(cacheRect, dpratio);
|
Chris@1266
|
1889 paint.begin(m_buffer);
|
Chris@1266
|
1890 paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect);
|
Chris@1266
|
1891 paint.end();
|
Chris@1266
|
1892 }
|
Chris@127
|
1893 }
|
Chris@127
|
1894
|
Chris@127
|
1895 // Now non-cacheable items. We always need to redraw the
|
Chris@127
|
1896 // non-cacheable items across at least the area we drew of the
|
Chris@127
|
1897 // cacheable items.
|
Chris@127
|
1898
|
Chris@127
|
1899 nonCacheRect |= cacheRect;
|
Chris@127
|
1900
|
Chris@952
|
1901 QRect scaledNonCacheRect = scaledRect(nonCacheRect, dpratio);
|
Chris@952
|
1902
|
Chris@952
|
1903 paint.begin(m_buffer);
|
Chris@952
|
1904 paint.setClipRect(scaledNonCacheRect);
|
Chris@339
|
1905 setPaintFont(paint);
|
Chris@127
|
1906 if (scrollables.empty()) {
|
Chris@287
|
1907 paint.setPen(getBackground());
|
Chris@287
|
1908 paint.setBrush(getBackground());
|
Chris@1266
|
1909 paint.drawRect(scaledNonCacheRect);
|
Chris@127
|
1910 }
|
Chris@1266
|
1911
|
Chris@287
|
1912 paint.setPen(getForeground());
|
Chris@127
|
1913 paint.setBrush(Qt::NoBrush);
|
Chris@1266
|
1914
|
Chris@127
|
1915 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) {
|
Chris@127
|
1916 // Profiler profiler2("View::paintEvent non-cacheable");
|
Chris@951
|
1917 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@951
|
1918 cerr << "Painting non-scrollable layer " << *i << " without proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << nonCacheRect.x() << "," << nonCacheRect.y() << " " << nonCacheRect.width() << "x" << nonCacheRect.height() << endl;
|
Chris@951
|
1919 #endif
|
Chris@1266
|
1920 (*i)->paint(&proxy, paint, scaledNonCacheRect);
|
Chris@127
|
1921 }
|
Chris@1266
|
1922
|
Chris@127
|
1923 paint.end();
|
Chris@953
|
1924
|
Chris@953
|
1925 paint.begin(this);
|
Chris@953
|
1926 QRect finalPaintRect = e ? e->rect() : rect();
|
Chris@953
|
1927 paint.drawPixmap(finalPaintRect, *m_buffer, scaledRect(finalPaintRect, dpratio));
|
Chris@953
|
1928 paint.end();
|
Chris@953
|
1929
|
Chris@953
|
1930 paint.begin(this);
|
Chris@339
|
1931 setPaintFont(paint);
|
Chris@953
|
1932 if (e) paint.setClipRect(e->rect());
|
Chris@127
|
1933 if (!m_selectionCached) {
|
Chris@1266
|
1934 drawSelections(paint);
|
Chris@127
|
1935 }
|
Chris@127
|
1936 paint.end();
|
Chris@127
|
1937
|
Chris@211
|
1938 bool showPlayPointer = true;
|
Chris@211
|
1939 if (m_followPlay == PlaybackScrollContinuous) {
|
Chris@211
|
1940 showPlayPointer = false;
|
Chris@806
|
1941 } else if (m_playPointerFrame <= getStartFrame() ||
|
Chris@211
|
1942 m_playPointerFrame >= getEndFrame()) {
|
Chris@211
|
1943 showPlayPointer = false;
|
Chris@211
|
1944 } else if (m_manager && !m_manager->isPlaying()) {
|
Chris@211
|
1945 if (m_playPointerFrame == getCentreFrame() &&
|
Chris@787
|
1946 m_manager->shouldShowCentreLine() &&
|
Chris@211
|
1947 m_followPlay != PlaybackIgnore) {
|
Chris@787
|
1948 // Don't show the play pointer when it is redundant with
|
Chris@787
|
1949 // the centre line
|
Chris@211
|
1950 showPlayPointer = false;
|
Chris@211
|
1951 }
|
Chris@211
|
1952 }
|
Chris@952
|
1953
|
Chris@211
|
1954 if (showPlayPointer) {
|
Chris@127
|
1955
|
Chris@1266
|
1956 paint.begin(this);
|
Chris@127
|
1957
|
Chris@211
|
1958 int playx = getXForFrame(m_playPointerFrame);
|
Chris@211
|
1959
|
Chris@287
|
1960 paint.setPen(getForeground());
|
Chris@211
|
1961 paint.drawLine(playx - 1, 0, playx - 1, height() - 1);
|
Chris@211
|
1962 paint.drawLine(playx + 1, 0, playx + 1, height() - 1);
|
Chris@211
|
1963 paint.drawPoint(playx, 0);
|
Chris@211
|
1964 paint.drawPoint(playx, height() - 1);
|
Chris@287
|
1965 paint.setPen(getBackground());
|
Chris@211
|
1966 paint.drawLine(playx, 1, playx, height() - 2);
|
Chris@127
|
1967
|
Chris@1266
|
1968 paint.end();
|
Chris@127
|
1969 }
|
Chris@127
|
1970
|
Chris@127
|
1971 QFrame::paintEvent(e);
|
Chris@127
|
1972 }
|
Chris@127
|
1973
|
Chris@127
|
1974 void
|
Chris@127
|
1975 View::drawSelections(QPainter &paint)
|
Chris@127
|
1976 {
|
Chris@217
|
1977 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
1978
|
Chris@127
|
1979 MultiSelection::SelectionList selections;
|
Chris@127
|
1980
|
Chris@127
|
1981 if (m_manager) {
|
Chris@1266
|
1982 selections = m_manager->getSelections();
|
Chris@1266
|
1983 if (m_manager->haveInProgressSelection()) {
|
Chris@1266
|
1984 bool exclusive;
|
Chris@1266
|
1985 Selection inProgressSelection =
|
Chris@1266
|
1986 m_manager->getInProgressSelection(exclusive);
|
Chris@1266
|
1987 if (exclusive) selections.clear();
|
Chris@1266
|
1988 selections.insert(inProgressSelection);
|
Chris@1266
|
1989 }
|
Chris@127
|
1990 }
|
Chris@127
|
1991
|
Chris@127
|
1992 paint.save();
|
Chris@183
|
1993
|
Chris@183
|
1994 bool translucent = !areLayerColoursSignificant();
|
Chris@183
|
1995
|
Chris@183
|
1996 if (translucent) {
|
Chris@183
|
1997 paint.setBrush(QColor(150, 150, 255, 80));
|
Chris@183
|
1998 } else {
|
Chris@183
|
1999 paint.setBrush(Qt::NoBrush);
|
Chris@183
|
2000 }
|
Chris@127
|
2001
|
Chris@908
|
2002 sv_samplerate_t sampleRate = getModelsSampleRate();
|
Chris@127
|
2003
|
Chris@127
|
2004 QPoint localPos;
|
Chris@908
|
2005 sv_frame_t illuminateFrame = -1;
|
Chris@127
|
2006 bool closeToLeft, closeToRight;
|
Chris@127
|
2007
|
Chris@127
|
2008 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) {
|
Chris@1266
|
2009 illuminateFrame = getFrameForX(localPos.x());
|
Chris@127
|
2010 }
|
Chris@127
|
2011
|
Chris@127
|
2012 const QFontMetrics &metrics = paint.fontMetrics();
|
Chris@127
|
2013
|
Chris@127
|
2014 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@1266
|
2015 i != selections.end(); ++i) {
|
Chris@1266
|
2016
|
Chris@1266
|
2017 int p0 = getXForFrame(alignFromReference(i->getStartFrame()));
|
Chris@1266
|
2018 int p1 = getXForFrame(alignFromReference(i->getEndFrame()));
|
Chris@1266
|
2019
|
Chris@1266
|
2020 if (p1 < 0 || p0 > width()) continue;
|
Chris@127
|
2021
|
Chris@127
|
2022 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
2023 SVDEBUG << "View::drawSelections: " << p0 << ",-1 [" << (p1-p0) << "x" << (height()+1) << "]" << endl;
|
Chris@127
|
2024 #endif
|
Chris@127
|
2025
|
Chris@1266
|
2026 bool illuminateThis =
|
Chris@1266
|
2027 (illuminateFrame >= 0 && i->contains(illuminateFrame));
|
Chris@1266
|
2028
|
Chris@1270
|
2029 double h = height();
|
Chris@1270
|
2030 double penWidth = PaintAssistant::scalePenWidth(1.0);
|
Chris@1270
|
2031 double half = penWidth/2.0;
|
Chris@1270
|
2032
|
Chris@1270
|
2033 paint.setPen(QPen(QColor(150, 150, 255), penWidth));
|
Chris@183
|
2034
|
Chris@183
|
2035 if (translucent && shouldLabelSelections()) {
|
Chris@1270
|
2036 paint.drawRect(QRectF(p0, -penWidth, p1 - p0, h + 2*penWidth));
|
Chris@183
|
2037 } else {
|
Chris@183
|
2038 // Make the top & bottom lines of the box visible if we
|
Chris@183
|
2039 // are lacking some of the other visual cues. There's no
|
Chris@183
|
2040 // particular logic to this, it's just a question of what
|
Chris@183
|
2041 // I happen to think looks nice.
|
Chris@1270
|
2042 paint.drawRect(QRectF(p0, half, p1 - p0, h - penWidth));
|
Chris@183
|
2043 }
|
Chris@127
|
2044
|
Chris@1266
|
2045 if (illuminateThis) {
|
Chris@1266
|
2046 paint.save();
|
Chris@1270
|
2047 penWidth = PaintAssistant::scalePenWidth(2.0);
|
Chris@1270
|
2048 half = penWidth/2.0;
|
Chris@1270
|
2049 paint.setPen(QPen(getForeground(), penWidth));
|
Chris@1266
|
2050 if (closeToLeft) {
|
Chris@1270
|
2051 paint.drawLine(QLineF(p0, half, p1, half));
|
Chris@1270
|
2052 paint.drawLine(QLineF(p0, half, p0, h - half));
|
Chris@1270
|
2053 paint.drawLine(QLineF(p0, h - half, p1, h - half));
|
Chris@1266
|
2054 } else if (closeToRight) {
|
Chris@1270
|
2055 paint.drawLine(QLineF(p0, half, p1, half));
|
Chris@1270
|
2056 paint.drawLine(QLineF(p1, half, p1, h - half));
|
Chris@1270
|
2057 paint.drawLine(QLineF(p0, h - half, p1, h - half));
|
Chris@1266
|
2058 } else {
|
Chris@1266
|
2059 paint.setBrush(Qt::NoBrush);
|
Chris@1270
|
2060 paint.drawRect(QRectF(p0, half, p1 - p0, h - penWidth));
|
Chris@1266
|
2061 }
|
Chris@1266
|
2062 paint.restore();
|
Chris@1266
|
2063 }
|
Chris@1266
|
2064
|
Chris@1266
|
2065 if (sampleRate && shouldLabelSelections() && m_manager &&
|
Chris@189
|
2066 m_manager->shouldShowSelectionExtents()) {
|
Chris@1266
|
2067
|
Chris@1266
|
2068 QString startText = QString("%1 / %2")
|
Chris@1266
|
2069 .arg(QString::fromStdString
|
Chris@1266
|
2070 (RealTime::frame2RealTime
|
Chris@1266
|
2071 (i->getStartFrame(), sampleRate).toText(true)))
|
Chris@1266
|
2072 .arg(i->getStartFrame());
|
Chris@1266
|
2073
|
Chris@1266
|
2074 QString endText = QString(" %1 / %2")
|
Chris@1266
|
2075 .arg(QString::fromStdString
|
Chris@1266
|
2076 (RealTime::frame2RealTime
|
Chris@1266
|
2077 (i->getEndFrame(), sampleRate).toText(true)))
|
Chris@1266
|
2078 .arg(i->getEndFrame());
|
Chris@1266
|
2079
|
Chris@1266
|
2080 QString durationText = QString("(%1 / %2) ")
|
Chris@1266
|
2081 .arg(QString::fromStdString
|
Chris@1266
|
2082 (RealTime::frame2RealTime
|
Chris@1266
|
2083 (i->getEndFrame() - i->getStartFrame(), sampleRate)
|
Chris@1266
|
2084 .toText(true)))
|
Chris@1266
|
2085 .arg(i->getEndFrame() - i->getStartFrame());
|
Chris@1266
|
2086
|
Chris@1266
|
2087 int sw = metrics.width(startText),
|
Chris@1266
|
2088 ew = metrics.width(endText),
|
Chris@1266
|
2089 dw = metrics.width(durationText);
|
Chris@1266
|
2090
|
Chris@1266
|
2091 int sy = metrics.ascent() + metrics.height() + 4;
|
Chris@1266
|
2092 int ey = sy;
|
Chris@1266
|
2093 int dy = sy + metrics.height();
|
Chris@1266
|
2094
|
Chris@1266
|
2095 int sx = p0 + 2;
|
Chris@1266
|
2096 int ex = sx;
|
Chris@1266
|
2097 int dx = sx;
|
Chris@127
|
2098
|
Chris@501
|
2099 bool durationBothEnds = true;
|
Chris@501
|
2100
|
Chris@1266
|
2101 if (sw + ew > (p1 - p0)) {
|
Chris@1266
|
2102 ey += metrics.height();
|
Chris@1266
|
2103 dy += metrics.height();
|
Chris@501
|
2104 durationBothEnds = false;
|
Chris@1266
|
2105 }
|
Chris@1266
|
2106
|
Chris@1266
|
2107 if (ew < (p1 - p0)) {
|
Chris@1266
|
2108 ex = p1 - 2 - ew;
|
Chris@1266
|
2109 }
|
Chris@1266
|
2110
|
Chris@1266
|
2111 if (dw < (p1 - p0)) {
|
Chris@1266
|
2112 dx = p1 - 2 - dw;
|
Chris@1266
|
2113 }
|
Chris@127
|
2114
|
Chris@1193
|
2115 PaintAssistant::drawVisibleText(this, paint, sx, sy, startText,
|
Chris@1193
|
2116 PaintAssistant::OutlinedText);
|
Chris@1193
|
2117 PaintAssistant::drawVisibleText(this, paint, ex, ey, endText,
|
Chris@1193
|
2118 PaintAssistant::OutlinedText);
|
Chris@1193
|
2119 PaintAssistant::drawVisibleText(this, paint, dx, dy, durationText,
|
Chris@1193
|
2120 PaintAssistant::OutlinedText);
|
Chris@501
|
2121 if (durationBothEnds) {
|
Chris@1193
|
2122 PaintAssistant::drawVisibleText(this, paint, sx, dy, durationText,
|
Chris@1193
|
2123 PaintAssistant::OutlinedText);
|
Chris@501
|
2124 }
|
Chris@1266
|
2125 }
|
Chris@127
|
2126 }
|
Chris@127
|
2127
|
Chris@127
|
2128 paint.restore();
|
Chris@127
|
2129 }
|
Chris@127
|
2130
|
Chris@267
|
2131 void
|
Chris@270
|
2132 View::drawMeasurementRect(QPainter &paint, const Layer *topLayer, QRect r,
|
Chris@270
|
2133 bool focus) const
|
Chris@267
|
2134 {
|
Chris@587
|
2135 // SVDEBUG << "View::drawMeasurementRect(" << r.x() << "," << r.y() << " "
|
Chris@585
|
2136 // << r.width() << "x" << r.height() << ")" << endl;
|
Chris@268
|
2137
|
Chris@267
|
2138 if (r.x() + r.width() < 0 || r.x() >= width()) return;
|
Chris@267
|
2139
|
Chris@270
|
2140 if (r.width() != 0 || r.height() != 0) {
|
Chris@270
|
2141 paint.save();
|
Chris@270
|
2142 if (focus) {
|
Chris@270
|
2143 paint.setPen(Qt::NoPen);
|
Chris@272
|
2144 QColor brushColour(Qt::black);
|
Chris@272
|
2145 brushColour.setAlpha(hasLightBackground() ? 15 : 40);
|
Chris@270
|
2146 paint.setBrush(brushColour);
|
Chris@270
|
2147 if (r.x() > 0) {
|
Chris@270
|
2148 paint.drawRect(0, 0, r.x(), height());
|
Chris@270
|
2149 }
|
Chris@270
|
2150 if (r.x() + r.width() < width()) {
|
Chris@270
|
2151 paint.drawRect(r.x() + r.width(), 0, width()-r.x()-r.width(), height());
|
Chris@270
|
2152 }
|
Chris@270
|
2153 if (r.y() > 0) {
|
Chris@270
|
2154 paint.drawRect(r.x(), 0, r.width(), r.y());
|
Chris@270
|
2155 }
|
Chris@270
|
2156 if (r.y() + r.height() < height()) {
|
Chris@270
|
2157 paint.drawRect(r.x(), r.y() + r.height(), r.width(), height()-r.y()-r.height());
|
Chris@270
|
2158 }
|
Chris@270
|
2159 paint.setBrush(Qt::NoBrush);
|
Chris@270
|
2160 }
|
Chris@270
|
2161 paint.setPen(Qt::green);
|
Chris@270
|
2162 paint.drawRect(r);
|
Chris@270
|
2163 paint.restore();
|
Chris@270
|
2164 } else {
|
Chris@270
|
2165 paint.save();
|
Chris@270
|
2166 paint.setPen(Qt::green);
|
Chris@270
|
2167 paint.drawPoint(r.x(), r.y());
|
Chris@270
|
2168 paint.restore();
|
Chris@270
|
2169 }
|
Chris@270
|
2170
|
Chris@270
|
2171 if (!focus) return;
|
Chris@270
|
2172
|
Chris@278
|
2173 paint.save();
|
Chris@278
|
2174 QFont fn = paint.font();
|
Chris@278
|
2175 if (fn.pointSize() > 8) {
|
Chris@278
|
2176 fn.setPointSize(fn.pointSize() - 1);
|
Chris@278
|
2177 paint.setFont(fn);
|
Chris@278
|
2178 }
|
Chris@278
|
2179
|
Chris@267
|
2180 int fontHeight = paint.fontMetrics().height();
|
Chris@267
|
2181 int fontAscent = paint.fontMetrics().ascent();
|
Chris@267
|
2182
|
Chris@904
|
2183 double v0, v1;
|
Chris@267
|
2184 QString u0, u1;
|
Chris@267
|
2185 bool b0 = false, b1 = false;
|
Chris@267
|
2186
|
Chris@267
|
2187 QString axs, ays, bxs, bys, dxs, dys;
|
Chris@267
|
2188
|
Chris@267
|
2189 int axx, axy, bxx, bxy, dxx, dxy;
|
Chris@267
|
2190 int aw = 0, bw = 0, dw = 0;
|
Chris@267
|
2191
|
Chris@267
|
2192 int labelCount = 0;
|
Chris@267
|
2193
|
Chris@362
|
2194 // top-left point, x-coord
|
Chris@362
|
2195
|
Chris@267
|
2196 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) {
|
Chris@267
|
2197 axs = QString("%1 %2").arg(v0).arg(u0);
|
Chris@278
|
2198 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
|
Chris@278
|
2199 axs = QString("%1 (%2)").arg(axs)
|
Chris@278
|
2200 .arg(Pitch::getPitchLabelForFrequency(v0));
|
Chris@278
|
2201 }
|
Chris@267
|
2202 aw = paint.fontMetrics().width(axs);
|
Chris@267
|
2203 ++labelCount;
|
Chris@267
|
2204 }
|
Chris@362
|
2205
|
Chris@362
|
2206 // bottom-right point, x-coord
|
Chris@267
|
2207
|
Chris@267
|
2208 if (r.width() > 0) {
|
Chris@267
|
2209 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) {
|
Chris@267
|
2210 bxs = QString("%1 %2").arg(v1).arg(u1);
|
Chris@278
|
2211 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
|
Chris@278
|
2212 bxs = QString("%1 (%2)").arg(bxs)
|
Chris@278
|
2213 .arg(Pitch::getPitchLabelForFrequency(v1));
|
Chris@278
|
2214 }
|
Chris@267
|
2215 bw = paint.fontMetrics().width(bxs);
|
Chris@267
|
2216 }
|
Chris@267
|
2217 }
|
Chris@362
|
2218
|
Chris@362
|
2219 // dimension, width
|
Chris@267
|
2220
|
Chris@283
|
2221 if (b0 && b1 && v1 != v0 && u0 == u1) {
|
Chris@362
|
2222 dxs = QString("[%1 %2]").arg(fabs(v1 - v0)).arg(u1);
|
Chris@267
|
2223 dw = paint.fontMetrics().width(dxs);
|
Chris@267
|
2224 }
|
Chris@267
|
2225
|
Chris@267
|
2226 b0 = false;
|
Chris@267
|
2227 b1 = false;
|
Chris@267
|
2228
|
Chris@362
|
2229 // top-left point, y-coord
|
Chris@362
|
2230
|
Chris@267
|
2231 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) {
|
Chris@267
|
2232 ays = QString("%1 %2").arg(v0).arg(u0);
|
Chris@278
|
2233 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
|
Chris@278
|
2234 ays = QString("%1 (%2)").arg(ays)
|
Chris@278
|
2235 .arg(Pitch::getPitchLabelForFrequency(v0));
|
Chris@278
|
2236 }
|
Chris@267
|
2237 aw = std::max(aw, paint.fontMetrics().width(ays));
|
Chris@267
|
2238 ++labelCount;
|
Chris@267
|
2239 }
|
Chris@267
|
2240
|
Chris@362
|
2241 // bottom-right point, y-coord
|
Chris@362
|
2242
|
Chris@267
|
2243 if (r.height() > 0) {
|
Chris@267
|
2244 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) {
|
Chris@267
|
2245 bys = QString("%1 %2").arg(v1).arg(u1);
|
Chris@278
|
2246 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
|
Chris@278
|
2247 bys = QString("%1 (%2)").arg(bys)
|
Chris@278
|
2248 .arg(Pitch::getPitchLabelForFrequency(v1));
|
Chris@278
|
2249 }
|
Chris@267
|
2250 bw = std::max(bw, paint.fontMetrics().width(bys));
|
Chris@267
|
2251 }
|
Chris@267
|
2252 }
|
Chris@274
|
2253
|
Chris@274
|
2254 bool bd = false;
|
Chris@904
|
2255 double dy = 0.f;
|
Chris@274
|
2256 QString du;
|
Chris@274
|
2257
|
Chris@362
|
2258 // dimension, height
|
Chris@362
|
2259
|
Chris@274
|
2260 if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(),
|
Chris@283
|
2261 dy, du)) &&
|
Chris@283
|
2262 dy != 0) {
|
Chris@274
|
2263 if (du != "") {
|
Chris@362
|
2264 if (du == "Hz") {
|
Chris@362
|
2265 int semis;
|
Chris@904
|
2266 double cents;
|
Chris@362
|
2267 semis = Pitch::getPitchForFrequencyDifference(v0, v1, ¢s);
|
Chris@362
|
2268 dys = QString("[%1 %2 (%3)]")
|
Chris@362
|
2269 .arg(dy).arg(du)
|
Chris@362
|
2270 .arg(Pitch::getLabelForPitchRange(semis, cents));
|
Chris@362
|
2271 } else {
|
Chris@362
|
2272 dys = QString("[%1 %2]").arg(dy).arg(du);
|
Chris@362
|
2273 }
|
Chris@274
|
2274 } else {
|
Chris@362
|
2275 dys = QString("[%1]").arg(dy);
|
Chris@274
|
2276 }
|
Chris@267
|
2277 dw = std::max(dw, paint.fontMetrics().width(dys));
|
Chris@267
|
2278 }
|
Chris@267
|
2279
|
Chris@267
|
2280 int mw = r.width();
|
Chris@267
|
2281 int mh = r.height();
|
Chris@267
|
2282
|
Chris@267
|
2283 bool edgeLabelsInside = false;
|
Chris@267
|
2284 bool sizeLabelsInside = false;
|
Chris@267
|
2285
|
Chris@267
|
2286 if (mw < std::max(aw, std::max(bw, dw)) + 4) {
|
Chris@267
|
2287 // defaults stand
|
Chris@267
|
2288 } else if (mw < aw + bw + 4) {
|
Chris@267
|
2289 if (mh > fontHeight * labelCount * 3 + 4) {
|
Chris@267
|
2290 edgeLabelsInside = true;
|
Chris@267
|
2291 sizeLabelsInside = true;
|
Chris@267
|
2292 } else if (mh > fontHeight * labelCount * 2 + 4) {
|
Chris@267
|
2293 edgeLabelsInside = true;
|
Chris@267
|
2294 }
|
Chris@267
|
2295 } else if (mw < aw + bw + dw + 4) {
|
Chris@267
|
2296 if (mh > fontHeight * labelCount * 3 + 4) {
|
Chris@267
|
2297 edgeLabelsInside = true;
|
Chris@267
|
2298 sizeLabelsInside = true;
|
Chris@267
|
2299 } else if (mh > fontHeight * labelCount + 4) {
|
Chris@267
|
2300 edgeLabelsInside = true;
|
Chris@267
|
2301 }
|
Chris@267
|
2302 } else {
|
Chris@267
|
2303 if (mh > fontHeight * labelCount + 4) {
|
Chris@267
|
2304 edgeLabelsInside = true;
|
Chris@267
|
2305 sizeLabelsInside = true;
|
Chris@267
|
2306 }
|
Chris@267
|
2307 }
|
Chris@267
|
2308
|
Chris@267
|
2309 if (edgeLabelsInside) {
|
Chris@267
|
2310
|
Chris@267
|
2311 axx = r.x() + 2;
|
Chris@267
|
2312 axy = r.y() + fontAscent + 2;
|
Chris@267
|
2313
|
Chris@267
|
2314 bxx = r.x() + r.width() - bw - 2;
|
Chris@267
|
2315 bxy = r.y() + r.height() - (labelCount-1) * fontHeight - 2;
|
Chris@267
|
2316
|
Chris@267
|
2317 } else {
|
Chris@267
|
2318
|
Chris@267
|
2319 axx = r.x() - aw - 2;
|
Chris@267
|
2320 axy = r.y() + fontAscent;
|
Chris@267
|
2321
|
Chris@267
|
2322 bxx = r.x() + r.width() + 2;
|
Chris@267
|
2323 bxy = r.y() + r.height() - (labelCount-1) * fontHeight;
|
Chris@267
|
2324 }
|
Chris@267
|
2325
|
Chris@267
|
2326 dxx = r.width()/2 + r.x() - dw/2;
|
Chris@267
|
2327
|
Chris@267
|
2328 if (sizeLabelsInside) {
|
Chris@267
|
2329
|
Chris@267
|
2330 dxy = r.height()/2 + r.y() - (labelCount * fontHeight)/2 + fontAscent;
|
Chris@267
|
2331
|
Chris@267
|
2332 } else {
|
Chris@267
|
2333
|
Chris@267
|
2334 dxy = r.y() + r.height() + fontAscent + 2;
|
Chris@267
|
2335 }
|
Chris@267
|
2336
|
Chris@267
|
2337 if (axs != "") {
|
Chris@1078
|
2338 PaintAssistant::drawVisibleText(this, paint, axx, axy, axs, PaintAssistant::OutlinedText);
|
Chris@267
|
2339 axy += fontHeight;
|
Chris@267
|
2340 }
|
Chris@267
|
2341
|
Chris@267
|
2342 if (ays != "") {
|
Chris@1078
|
2343 PaintAssistant::drawVisibleText(this, paint, axx, axy, ays, PaintAssistant::OutlinedText);
|
Chris@267
|
2344 axy += fontHeight;
|
Chris@267
|
2345 }
|
Chris@267
|
2346
|
Chris@267
|
2347 if (bxs != "") {
|
Chris@1078
|
2348 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bxs, PaintAssistant::OutlinedText);
|
Chris@267
|
2349 bxy += fontHeight;
|
Chris@267
|
2350 }
|
Chris@267
|
2351
|
Chris@267
|
2352 if (bys != "") {
|
Chris@1078
|
2353 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bys, PaintAssistant::OutlinedText);
|
Chris@267
|
2354 bxy += fontHeight;
|
Chris@267
|
2355 }
|
Chris@267
|
2356
|
Chris@267
|
2357 if (dxs != "") {
|
Chris@1078
|
2358 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dxs, PaintAssistant::OutlinedText);
|
Chris@267
|
2359 dxy += fontHeight;
|
Chris@267
|
2360 }
|
Chris@267
|
2361
|
Chris@267
|
2362 if (dys != "") {
|
Chris@1078
|
2363 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dys, PaintAssistant::OutlinedText);
|
Chris@267
|
2364 dxy += fontHeight;
|
Chris@267
|
2365 }
|
Chris@278
|
2366
|
Chris@278
|
2367 paint.restore();
|
Chris@267
|
2368 }
|
Chris@267
|
2369
|
Chris@227
|
2370 bool
|
Chris@908
|
2371 View::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1)
|
Chris@227
|
2372 {
|
Chris@908
|
2373 int x0 = int(f0 / m_zoomLevel);
|
Chris@908
|
2374 int x1 = int(f1 / m_zoomLevel);
|
Chris@806
|
2375
|
Chris@806
|
2376 int w = x1 - x0;
|
Chris@806
|
2377
|
Chris@908
|
2378 sv_frame_t origCentreFrame = m_centreFrame;
|
Chris@227
|
2379
|
Chris@227
|
2380 bool someLayersIncomplete = false;
|
Chris@227
|
2381
|
Chris@835
|
2382 for (LayerList::iterator i = m_layerStack.begin();
|
Chris@835
|
2383 i != m_layerStack.end(); ++i) {
|
Chris@227
|
2384
|
Chris@227
|
2385 int c = (*i)->getCompletion(this);
|
Chris@227
|
2386 if (c < 100) {
|
Chris@227
|
2387 someLayersIncomplete = true;
|
Chris@227
|
2388 break;
|
Chris@227
|
2389 }
|
Chris@227
|
2390 }
|
Chris@227
|
2391
|
Chris@227
|
2392 if (someLayersIncomplete) {
|
Chris@227
|
2393
|
Chris@227
|
2394 QProgressDialog progress(tr("Waiting for layers to be ready..."),
|
Chris@227
|
2395 tr("Cancel"), 0, 100, this);
|
Chris@227
|
2396
|
Chris@227
|
2397 int layerCompletion = 0;
|
Chris@227
|
2398
|
Chris@227
|
2399 while (layerCompletion < 100) {
|
Chris@227
|
2400
|
Chris@835
|
2401 for (LayerList::iterator i = m_layerStack.begin();
|
Chris@835
|
2402 i != m_layerStack.end(); ++i) {
|
Chris@227
|
2403
|
Chris@227
|
2404 int c = (*i)->getCompletion(this);
|
Chris@835
|
2405 if (i == m_layerStack.begin() || c < layerCompletion) {
|
Chris@227
|
2406 layerCompletion = c;
|
Chris@227
|
2407 }
|
Chris@227
|
2408 }
|
Chris@227
|
2409
|
Chris@227
|
2410 if (layerCompletion >= 100) break;
|
Chris@227
|
2411
|
Chris@227
|
2412 progress.setValue(layerCompletion);
|
Chris@227
|
2413 qApp->processEvents();
|
Chris@227
|
2414 if (progress.wasCanceled()) {
|
Chris@227
|
2415 update();
|
Chris@227
|
2416 return false;
|
Chris@227
|
2417 }
|
Chris@227
|
2418
|
Chris@227
|
2419 usleep(50000);
|
Chris@227
|
2420 }
|
Chris@227
|
2421 }
|
Chris@227
|
2422
|
Chris@227
|
2423 QProgressDialog progress(tr("Rendering image..."),
|
Chris@227
|
2424 tr("Cancel"), 0, w / width(), this);
|
Chris@227
|
2425
|
Chris@806
|
2426 for (int x = 0; x < w; x += width()) {
|
Chris@227
|
2427
|
Chris@227
|
2428 progress.setValue(x / width());
|
Chris@227
|
2429 qApp->processEvents();
|
Chris@227
|
2430 if (progress.wasCanceled()) {
|
Chris@227
|
2431 m_centreFrame = origCentreFrame;
|
Chris@227
|
2432 update();
|
Chris@227
|
2433 return false;
|
Chris@227
|
2434 }
|
Chris@227
|
2435
|
Chris@229
|
2436 m_centreFrame = f0 + (x + width()/2) * m_zoomLevel;
|
Chris@227
|
2437
|
Chris@227
|
2438 QRect chunk(0, 0, width(), height());
|
Chris@227
|
2439
|
Chris@287
|
2440 paint.setPen(getBackground());
|
Chris@287
|
2441 paint.setBrush(getBackground());
|
Chris@227
|
2442
|
Chris@1266
|
2443 paint.drawRect(QRect(xorigin + x, 0, width(), height()));
|
Chris@1266
|
2444
|
Chris@1266
|
2445 paint.setPen(getForeground());
|
Chris@1266
|
2446 paint.setBrush(Qt::NoBrush);
|
Chris@1266
|
2447
|
Chris@1266
|
2448 for (LayerList::iterator i = m_layerStack.begin();
|
Chris@835
|
2449 i != m_layerStack.end(); ++i) {
|
Chris@919
|
2450 if (!((*i)->isLayerDormant(this))){
|
Chris@919
|
2451
|
Chris@919
|
2452 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@919
|
2453
|
Chris@919
|
2454 paint.save();
|
Chris@919
|
2455 paint.translate(xorigin + x, 0);
|
Chris@919
|
2456
|
Chris@919
|
2457 cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl;
|
Chris@919
|
2458
|
Chris@919
|
2459 (*i)->setSynchronousPainting(true);
|
Chris@919
|
2460
|
Chris@919
|
2461 (*i)->paint(this, paint, chunk);
|
Chris@919
|
2462
|
Chris@919
|
2463 (*i)->setSynchronousPainting(false);
|
Chris@919
|
2464
|
Chris@919
|
2465 paint.restore();
|
Chris@919
|
2466 }
|
Chris@1266
|
2467 }
|
Chris@227
|
2468 }
|
Chris@227
|
2469
|
Chris@227
|
2470 m_centreFrame = origCentreFrame;
|
Chris@227
|
2471 update();
|
Chris@227
|
2472 return true;
|
Chris@227
|
2473 }
|
Chris@227
|
2474
|
Chris@227
|
2475 QImage *
|
Chris@1202
|
2476 View::renderToNewImage()
|
Chris@227
|
2477 {
|
Chris@908
|
2478 sv_frame_t f0 = getModelsStartFrame();
|
Chris@908
|
2479 sv_frame_t f1 = getModelsEndFrame();
|
Chris@227
|
2480
|
Chris@1202
|
2481 return renderPartToNewImage(f0, f1);
|
Chris@229
|
2482 }
|
Chris@229
|
2483
|
Chris@229
|
2484 QImage *
|
Chris@1202
|
2485 View::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1)
|
Chris@229
|
2486 {
|
Chris@908
|
2487 int x0 = int(f0 / getZoomLevel());
|
Chris@908
|
2488 int x1 = int(f1 / getZoomLevel());
|
Chris@227
|
2489
|
Chris@227
|
2490 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
|
Chris@227
|
2491
|
Chris@227
|
2492 QPainter *paint = new QPainter(image);
|
Chris@229
|
2493 if (!render(*paint, 0, f0, f1)) {
|
Chris@227
|
2494 delete paint;
|
Chris@227
|
2495 delete image;
|
Chris@227
|
2496 return 0;
|
Chris@227
|
2497 } else {
|
Chris@227
|
2498 delete paint;
|
Chris@227
|
2499 return image;
|
Chris@227
|
2500 }
|
Chris@227
|
2501 }
|
Chris@227
|
2502
|
Chris@229
|
2503 QSize
|
Chris@1202
|
2504 View::getRenderedImageSize()
|
Chris@229
|
2505 {
|
Chris@908
|
2506 sv_frame_t f0 = getModelsStartFrame();
|
Chris@908
|
2507 sv_frame_t f1 = getModelsEndFrame();
|
Chris@229
|
2508
|
Chris@1202
|
2509 return getRenderedPartImageSize(f0, f1);
|
Chris@229
|
2510 }
|
Chris@229
|
2511
|
Chris@229
|
2512 QSize
|
Chris@1202
|
2513 View::getRenderedPartImageSize(sv_frame_t f0, sv_frame_t f1)
|
Chris@229
|
2514 {
|
Chris@908
|
2515 int x0 = int(f0 / getZoomLevel());
|
Chris@908
|
2516 int x1 = int(f1 / getZoomLevel());
|
Chris@229
|
2517
|
Chris@229
|
2518 return QSize(x1 - x0, height());
|
Chris@229
|
2519 }
|
Chris@229
|
2520
|
Chris@1202
|
2521 bool
|
Chris@1202
|
2522 View::renderToSvgFile(QString filename)
|
Chris@1202
|
2523 {
|
Chris@1202
|
2524 sv_frame_t f0 = getModelsStartFrame();
|
Chris@1202
|
2525 sv_frame_t f1 = getModelsEndFrame();
|
Chris@1202
|
2526
|
Chris@1202
|
2527 return renderPartToSvgFile(filename, f0, f1);
|
Chris@1202
|
2528 }
|
Chris@1202
|
2529
|
Chris@1202
|
2530 bool
|
Chris@1202
|
2531 View::renderPartToSvgFile(QString filename, sv_frame_t f0, sv_frame_t f1)
|
Chris@1202
|
2532 {
|
Chris@1202
|
2533 int x0 = int(f0 / getZoomLevel());
|
Chris@1202
|
2534 int x1 = int(f1 / getZoomLevel());
|
Chris@1202
|
2535
|
Chris@1202
|
2536 QSvgGenerator generator;
|
Chris@1202
|
2537 generator.setFileName(filename);
|
Chris@1202
|
2538 generator.setSize(QSize(x1 - x0, height()));
|
Chris@1202
|
2539 generator.setViewBox(QRect(0, 0, x1 - x0, height()));
|
Chris@1202
|
2540 generator.setTitle(tr("Exported image from %1")
|
Chris@1202
|
2541 .arg(QApplication::applicationName()));
|
Chris@1202
|
2542
|
Chris@1202
|
2543 QPainter paint;
|
Chris@1202
|
2544 paint.begin(&generator);
|
Chris@1202
|
2545 bool result = render(paint, 0, f0, f1);
|
Chris@1202
|
2546 paint.end();
|
Chris@1202
|
2547 return result;
|
Chris@1202
|
2548 }
|
Chris@1202
|
2549
|
Chris@316
|
2550 void
|
Chris@316
|
2551 View::toXml(QTextStream &stream,
|
Chris@316
|
2552 QString indent, QString extraAttributes) const
|
Chris@127
|
2553 {
|
Chris@316
|
2554 stream << indent;
|
Chris@127
|
2555
|
Chris@316
|
2556 stream << QString("<view "
|
Chris@316
|
2557 "centre=\"%1\" "
|
Chris@316
|
2558 "zoom=\"%2\" "
|
Chris@316
|
2559 "followPan=\"%3\" "
|
Chris@316
|
2560 "followZoom=\"%4\" "
|
Chris@316
|
2561 "tracking=\"%5\" "
|
Chris@316
|
2562 " %6>\n")
|
Chris@1266
|
2563 .arg(m_centreFrame)
|
Chris@1266
|
2564 .arg(m_zoomLevel)
|
Chris@1266
|
2565 .arg(m_followPan)
|
Chris@1266
|
2566 .arg(m_followZoom)
|
Chris@1266
|
2567 .arg(m_followPlay == PlaybackScrollContinuous ? "scroll" :
|
Chris@1266
|
2568 m_followPlay == PlaybackScrollPageWithCentre ? "page" :
|
Chris@1266
|
2569 m_followPlay == PlaybackScrollPage ? "daw" :
|
Chris@815
|
2570 "ignore")
|
Chris@1266
|
2571 .arg(extraAttributes);
|
Chris@127
|
2572
|
Chris@838
|
2573 for (int i = 0; i < (int)m_fixedOrderLayers.size(); ++i) {
|
Chris@838
|
2574 bool visible = !m_fixedOrderLayers[i]->isLayerDormant(this);
|
Chris@838
|
2575 m_fixedOrderLayers[i]->toBriefXml(stream, indent + " ",
|
Chris@838
|
2576 QString("visible=\"%1\"")
|
Chris@838
|
2577 .arg(visible ? "true" : "false"));
|
Chris@127
|
2578 }
|
Chris@127
|
2579
|
Chris@316
|
2580 stream << indent + "</view>\n";
|
Chris@127
|
2581 }
|
Chris@127
|
2582
|
Chris@127
|
2583 ViewPropertyContainer::ViewPropertyContainer(View *v) :
|
Chris@127
|
2584 m_v(v)
|
Chris@127
|
2585 {
|
Chris@728
|
2586 // cerr << "ViewPropertyContainer: " << this << " is owned by View " << v << endl;
|
Chris@127
|
2587 connect(m_v, SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@1266
|
2588 this, SIGNAL(propertyChanged(PropertyContainer::PropertyName)));
|
Chris@127
|
2589 }
|
Chris@127
|
2590
|
Chris@728
|
2591 ViewPropertyContainer::~ViewPropertyContainer()
|
Chris@728
|
2592 {
|
Chris@728
|
2593 }
|