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