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