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@1495
|
78 // cerr << "View::View(" << getId() << ")" << endl;
|
Chris@127
|
79 }
|
Chris@127
|
80
|
Chris@127
|
81 View::~View()
|
Chris@127
|
82 {
|
Chris@1495
|
83 // cerr << "View::~View(" << getId() << ")" << 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@1495
|
346 SVCERR << "View(" << getId() << ")::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@1495
|
359 SVCERR << "View(" << getId() << ")::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@1495
|
379 cerr << "View[" << getId() << "]::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@1495
|
928 #if defined(DEBUG_VIEW_WIDGET_PAINT) || defined(DEBUG_PROGRESS_STUFF)
|
Chris@1495
|
929 cerr << "View[" << getId() << "]::modelChanged(" << modelId << ")" << 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@1495
|
966 cerr << "View(" << getId() << ")::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@1495
|
1008 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1009 cerr << "View[" << getId() << "]::modelCompletionChanged(" << modelId << ")" << endl;
|
Chris@1495
|
1010 #endif
|
Chris@1481
|
1011 checkProgress(modelId);
|
Chris@127
|
1012 }
|
Chris@127
|
1013
|
Chris@127
|
1014 void
|
Chris@1481
|
1015 View::modelAlignmentCompletionChanged(ModelId modelId)
|
Chris@320
|
1016 {
|
Chris@1495
|
1017 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1018 cerr << "View[" << getId() << "]::modelAlignmentCompletionChanged(" << modelId << ")" << endl;
|
Chris@1495
|
1019 #endif
|
Chris@1481
|
1020 checkProgress(modelId);
|
Chris@320
|
1021 }
|
Chris@320
|
1022
|
Chris@320
|
1023 void
|
Chris@127
|
1024 View::modelReplaced()
|
Chris@127
|
1025 {
|
Chris@127
|
1026 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
1027 cerr << "View(" << getId() << ")::modelReplaced()" << endl;
|
Chris@127
|
1028 #endif
|
Chris@1357
|
1029 m_cacheValid = false;
|
Chris@127
|
1030 update();
|
Chris@127
|
1031 }
|
Chris@127
|
1032
|
Chris@127
|
1033 void
|
Chris@127
|
1034 View::layerParametersChanged()
|
Chris@127
|
1035 {
|
Chris@127
|
1036 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@127
|
1037
|
Chris@127
|
1038 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@587
|
1039 SVDEBUG << "View::layerParametersChanged()" << endl;
|
Chris@127
|
1040 #endif
|
Chris@127
|
1041
|
Chris@1357
|
1042 m_cacheValid = false;
|
Chris@127
|
1043 update();
|
Chris@127
|
1044
|
Chris@127
|
1045 if (layer) {
|
Chris@1266
|
1046 emit propertyContainerPropertyChanged(layer);
|
Chris@127
|
1047 }
|
Chris@127
|
1048 }
|
Chris@127
|
1049
|
Chris@127
|
1050 void
|
Chris@197
|
1051 View::layerParameterRangesChanged()
|
Chris@197
|
1052 {
|
Chris@197
|
1053 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@197
|
1054 if (layer) emit propertyContainerPropertyRangeChanged(layer);
|
Chris@197
|
1055 }
|
Chris@197
|
1056
|
Chris@197
|
1057 void
|
Chris@268
|
1058 View::layerMeasurementRectsChanged()
|
Chris@268
|
1059 {
|
Chris@268
|
1060 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@268
|
1061 if (layer) update();
|
Chris@268
|
1062 }
|
Chris@268
|
1063
|
Chris@268
|
1064 void
|
Chris@127
|
1065 View::layerNameChanged()
|
Chris@127
|
1066 {
|
Chris@127
|
1067 Layer *layer = dynamic_cast<Layer *>(sender());
|
Chris@127
|
1068 if (layer) emit propertyContainerNameChanged(layer);
|
Chris@127
|
1069 }
|
Chris@127
|
1070
|
Chris@127
|
1071 void
|
Chris@908
|
1072 View::globalCentreFrameChanged(sv_frame_t rf)
|
Chris@127
|
1073 {
|
Chris@211
|
1074 if (m_followPan) {
|
Chris@908
|
1075 sv_frame_t f = alignFromReference(rf);
|
Chris@830
|
1076 #ifdef DEBUG_VIEW
|
Chris@1495
|
1077 cerr << "View[" << getId() << "]::globalCentreFrameChanged(" << rf
|
Chris@682
|
1078 << "): setting centre frame to " << f << endl;
|
Chris@363
|
1079 #endif
|
Chris@333
|
1080 setCentreFrame(f, false);
|
Chris@127
|
1081 }
|
Chris@127
|
1082 }
|
Chris@127
|
1083
|
Chris@127
|
1084 void
|
Chris@908
|
1085 View::viewCentreFrameChanged(View *, sv_frame_t )
|
Chris@211
|
1086 {
|
Chris@211
|
1087 // We do nothing with this, but a subclass might
|
Chris@211
|
1088 }
|
Chris@211
|
1089
|
Chris@211
|
1090 void
|
Chris@908
|
1091 View::viewManagerPlaybackFrameChanged(sv_frame_t f)
|
Chris@127
|
1092 {
|
Chris@127
|
1093 if (m_manager) {
|
Chris@1266
|
1094 if (sender() != m_manager) return;
|
Chris@127
|
1095 }
|
Chris@127
|
1096
|
Chris@830
|
1097 #ifdef DEBUG_VIEW
|
Chris@830
|
1098 cerr << "View::viewManagerPlaybackFrameChanged(" << f << ")" << endl;
|
Chris@830
|
1099 #endif
|
Chris@830
|
1100
|
Chris@301
|
1101 f = getAlignedPlaybackFrame();
|
Chris@301
|
1102
|
Chris@830
|
1103 #ifdef DEBUG_VIEW
|
Chris@951
|
1104 cerr << " -> aligned frame = " << f << endl;
|
Chris@830
|
1105 #endif
|
Chris@830
|
1106
|
Chris@511
|
1107 movePlayPointer(f);
|
Chris@511
|
1108 }
|
Chris@511
|
1109
|
Chris@511
|
1110 void
|
Chris@908
|
1111 View::movePlayPointer(sv_frame_t newFrame)
|
Chris@511
|
1112 {
|
Chris@830
|
1113 #ifdef DEBUG_VIEW
|
Chris@1495
|
1114 cerr << "View(" << getId() << ")::movePlayPointer(" << newFrame << ")" << endl;
|
Chris@830
|
1115 #endif
|
Chris@830
|
1116
|
Chris@511
|
1117 if (m_playPointerFrame == newFrame) return;
|
Chris@511
|
1118 bool visibleChange =
|
Chris@511
|
1119 (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame));
|
Chris@908
|
1120 sv_frame_t oldPlayPointerFrame = m_playPointerFrame;
|
Chris@511
|
1121 m_playPointerFrame = newFrame;
|
Chris@511
|
1122 if (!visibleChange) return;
|
Chris@127
|
1123
|
Chris@513
|
1124 bool somethingGoingOn =
|
Chris@513
|
1125 ((QApplication::mouseButtons() != Qt::NoButton) ||
|
Chris@513
|
1126 (QApplication::keyboardModifiers() & Qt::AltModifier));
|
Chris@513
|
1127
|
Chris@789
|
1128 bool pointerInVisibleArea =
|
Chris@1266
|
1129 long(m_playPointerFrame) >= getStartFrame() &&
|
Chris@789
|
1130 (m_playPointerFrame < getEndFrame() ||
|
Chris@789
|
1131 // include old pointer location so we know to refresh when moving out
|
Chris@789
|
1132 oldPlayPointerFrame < getEndFrame());
|
Chris@789
|
1133
|
Chris@127
|
1134 switch (m_followPlay) {
|
Chris@127
|
1135
|
Chris@127
|
1136 case PlaybackScrollContinuous:
|
Chris@1266
|
1137 if (!somethingGoingOn) {
|
Chris@1266
|
1138 setCentreFrame(m_playPointerFrame, false);
|
Chris@1266
|
1139 }
|
Chris@1266
|
1140 break;
|
Chris@127
|
1141
|
Chris@127
|
1142 case PlaybackScrollPage:
|
Chris@815
|
1143 case PlaybackScrollPageWithCentre:
|
Chris@789
|
1144
|
Chris@789
|
1145 if (!pointerInVisibleArea && somethingGoingOn) {
|
Chris@789
|
1146
|
Chris@789
|
1147 m_followPlayIsDetached = true;
|
Chris@789
|
1148
|
Chris@789
|
1149 } else if (!pointerInVisibleArea && m_followPlayIsDetached) {
|
Chris@789
|
1150
|
Chris@789
|
1151 // do nothing; we aren't tracking until the pointer comes back in
|
Chris@789
|
1152
|
Chris@789
|
1153 } else {
|
Chris@789
|
1154
|
Chris@789
|
1155 int xold = getXForFrame(oldPlayPointerFrame);
|
Chris@789
|
1156 update(xold - 4, 0, 9, height());
|
Chris@789
|
1157
|
Chris@908
|
1158 sv_frame_t w = getEndFrame() - getStartFrame();
|
Chris@789
|
1159 w -= w/5;
|
Chris@1416
|
1160 sv_frame_t sf = m_playPointerFrame;
|
Chris@1416
|
1161 if (w > 0) {
|
Chris@1416
|
1162 sf = (sf / w) * w - w/8;
|
Chris@1416
|
1163 }
|
Chris@789
|
1164
|
Chris@789
|
1165 if (m_manager &&
|
Chris@789
|
1166 m_manager->isPlaying() &&
|
Chris@789
|
1167 m_manager->getPlaySelectionMode()) {
|
Chris@789
|
1168 MultiSelection::SelectionList selections = m_manager->getSelections();
|
Chris@789
|
1169 if (!selections.empty()) {
|
Chris@908
|
1170 sv_frame_t selectionStart = selections.begin()->getStartFrame();
|
Chris@808
|
1171 if (sf < selectionStart - w / 10) {
|
Chris@808
|
1172 sf = selectionStart - w / 10;
|
Chris@789
|
1173 }
|
Chris@789
|
1174 }
|
Chris@789
|
1175 }
|
Chris@127
|
1176
|
Chris@127
|
1177 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@789
|
1178 cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame "
|
Chris@789
|
1179 << getStartFrame() << endl;
|
Chris@127
|
1180 #endif
|
Chris@127
|
1181
|
Chris@789
|
1182 // We don't consider scrolling unless the pointer is outside
|
Chris@789
|
1183 // the central visible range already
|
Chris@789
|
1184
|
Chris@789
|
1185 int xnew = getXForFrame(m_playPointerFrame);
|
Chris@127
|
1186
|
Chris@127
|
1187 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@789
|
1188 cerr << "xnew = " << xnew << ", width = " << width() << endl;
|
Chris@127
|
1189 #endif
|
Chris@127
|
1190
|
Chris@789
|
1191 bool shouldScroll = (xnew > (width() * 7) / 8);
|
Chris@789
|
1192
|
Chris@789
|
1193 if (!m_followPlayIsDetached && (xnew < width() / 8)) {
|
Chris@789
|
1194 shouldScroll = true;
|
Chris@789
|
1195 }
|
Chris@789
|
1196
|
Chris@789
|
1197 if (xnew > width() / 8) {
|
Chris@789
|
1198 m_followPlayIsDetached = false;
|
Chris@791
|
1199 } else if (somethingGoingOn) {
|
Chris@791
|
1200 m_followPlayIsDetached = true;
|
Chris@789
|
1201 }
|
Chris@789
|
1202
|
Chris@789
|
1203 if (!somethingGoingOn && shouldScroll) {
|
Chris@908
|
1204 sv_frame_t offset = getFrameForX(width()/2) - getStartFrame();
|
Chris@908
|
1205 sv_frame_t newCentre = sf + offset;
|
Chris@789
|
1206 bool changed = setCentreFrame(newCentre, false);
|
Chris@789
|
1207 if (changed) {
|
Chris@789
|
1208 xold = getXForFrame(oldPlayPointerFrame);
|
Chris@789
|
1209 update(xold - 4, 0, 9, height());
|
Chris@789
|
1210 }
|
Chris@789
|
1211 }
|
Chris@789
|
1212
|
Chris@789
|
1213 update(xnew - 4, 0, 9, height());
|
Chris@789
|
1214 }
|
Chris@789
|
1215 break;
|
Chris@127
|
1216
|
Chris@127
|
1217 case PlaybackIgnore:
|
Chris@1266
|
1218 if (m_playPointerFrame >= getStartFrame() &&
|
Chris@511
|
1219 m_playPointerFrame < getEndFrame()) {
|
Chris@1266
|
1220 update();
|
Chris@1266
|
1221 }
|
Chris@1266
|
1222 break;
|
Chris@127
|
1223 }
|
Chris@127
|
1224 }
|
Chris@127
|
1225
|
Chris@127
|
1226 void
|
Chris@1183
|
1227 View::viewZoomLevelChanged(View *p, ZoomLevel z, bool locked)
|
Chris@127
|
1228 {
|
Chris@244
|
1229 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
1230 cerr << "View[" << getId() << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl;
|
Chris@244
|
1231 #endif
|
Chris@127
|
1232 if (m_followZoom && p != this && locked) {
|
Chris@222
|
1233 setZoomLevel(z);
|
Chris@127
|
1234 }
|
Chris@127
|
1235 }
|
Chris@127
|
1236
|
Chris@127
|
1237 void
|
Chris@127
|
1238 View::selectionChanged()
|
Chris@127
|
1239 {
|
Chris@127
|
1240 if (m_selectionCached) {
|
Chris@1357
|
1241 m_cacheValid = false;
|
Chris@1266
|
1242 m_selectionCached = false;
|
Chris@127
|
1243 }
|
Chris@127
|
1244 update();
|
Chris@127
|
1245 }
|
Chris@127
|
1246
|
Chris@908
|
1247 sv_frame_t
|
Chris@222
|
1248 View::getFirstVisibleFrame() const
|
Chris@222
|
1249 {
|
Chris@908
|
1250 sv_frame_t f0 = getStartFrame();
|
Chris@908
|
1251 sv_frame_t f = getModelsStartFrame();
|
Chris@806
|
1252 if (f0 < 0 || f0 < f) return f;
|
Chris@222
|
1253 return f0;
|
Chris@222
|
1254 }
|
Chris@222
|
1255
|
Chris@908
|
1256 sv_frame_t
|
Chris@222
|
1257 View::getLastVisibleFrame() const
|
Chris@222
|
1258 {
|
Chris@908
|
1259 sv_frame_t f0 = getEndFrame();
|
Chris@908
|
1260 sv_frame_t f = getModelsEndFrame();
|
Chris@222
|
1261 if (f0 > f) return f;
|
Chris@222
|
1262 return f0;
|
Chris@222
|
1263 }
|
Chris@222
|
1264
|
Chris@908
|
1265 sv_frame_t
|
Chris@127
|
1266 View::getModelsStartFrame() const
|
Chris@127
|
1267 {
|
Chris@127
|
1268 bool first = true;
|
Chris@908
|
1269 sv_frame_t startFrame = 0;
|
Chris@127
|
1270
|
Chris@1475
|
1271 for (Layer *layer: m_layerStack) {
|
Chris@1475
|
1272
|
Chris@1475
|
1273 auto model = ModelById::get(layer->getModel());
|
Chris@1475
|
1274
|
Chris@1475
|
1275 if (model && model->isOK()) {
|
Chris@1475
|
1276
|
Chris@1475
|
1277 sv_frame_t thisStartFrame = model->getStartFrame();
|
Chris@1266
|
1278
|
Chris@1266
|
1279 if (first || thisStartFrame < startFrame) {
|
Chris@1266
|
1280 startFrame = thisStartFrame;
|
Chris@1266
|
1281 }
|
Chris@1266
|
1282 first = false;
|
Chris@1266
|
1283 }
|
Chris@127
|
1284 }
|
Chris@1475
|
1285
|
Chris@127
|
1286 return startFrame;
|
Chris@127
|
1287 }
|
Chris@127
|
1288
|
Chris@908
|
1289 sv_frame_t
|
Chris@127
|
1290 View::getModelsEndFrame() const
|
Chris@127
|
1291 {
|
Chris@127
|
1292 bool first = true;
|
Chris@908
|
1293 sv_frame_t endFrame = 0;
|
Chris@127
|
1294
|
Chris@1475
|
1295 for (Layer *layer: m_layerStack) {
|
Chris@1475
|
1296
|
Chris@1475
|
1297 auto model = ModelById::get(layer->getModel());
|
Chris@1475
|
1298
|
Chris@1475
|
1299 if (model && model->isOK()) {
|
Chris@1475
|
1300
|
Chris@1475
|
1301 sv_frame_t thisEndFrame = model->getEndFrame();
|
Chris@1266
|
1302
|
Chris@1266
|
1303 if (first || thisEndFrame > endFrame) {
|
Chris@1266
|
1304 endFrame = thisEndFrame;
|
Chris@1266
|
1305 }
|
Chris@1266
|
1306 first = false;
|
Chris@1266
|
1307 }
|
Chris@127
|
1308 }
|
Chris@127
|
1309
|
Chris@127
|
1310 if (first) return getModelsStartFrame();
|
Chris@127
|
1311 return endFrame;
|
Chris@127
|
1312 }
|
Chris@127
|
1313
|
Chris@908
|
1314 sv_samplerate_t
|
Chris@127
|
1315 View::getModelsSampleRate() const
|
Chris@127
|
1316 {
|
Chris@127
|
1317 //!!! Just go for the first, for now. If we were supporting
|
Chris@127
|
1318 // multiple samplerates, we'd probably want to do frame/time
|
Chris@127
|
1319 // conversion in the model
|
Chris@127
|
1320
|
Chris@159
|
1321 //!!! nah, this wants to always return the sr of the main model!
|
Chris@159
|
1322
|
Chris@1475
|
1323 for (Layer *layer: m_layerStack) {
|
Chris@1475
|
1324
|
Chris@1475
|
1325 auto model = ModelById::get(layer->getModel());
|
Chris@1475
|
1326
|
Chris@1475
|
1327 if (model && model->isOK()) {
|
Chris@1475
|
1328 return model->getSampleRate();
|
Chris@1266
|
1329 }
|
Chris@127
|
1330 }
|
Chris@1475
|
1331
|
Chris@127
|
1332 return 0;
|
Chris@127
|
1333 }
|
Chris@127
|
1334
|
Chris@315
|
1335 View::ModelSet
|
Chris@315
|
1336 View::getModels()
|
Chris@315
|
1337 {
|
Chris@315
|
1338 ModelSet models;
|
Chris@315
|
1339
|
Chris@315
|
1340 for (int i = 0; i < getLayerCount(); ++i) {
|
Chris@315
|
1341
|
Chris@315
|
1342 Layer *layer = getLayer(i);
|
Chris@315
|
1343
|
Chris@315
|
1344 if (dynamic_cast<TimeRulerLayer *>(layer)) {
|
Chris@315
|
1345 continue;
|
Chris@315
|
1346 }
|
Chris@315
|
1347
|
Chris@1475
|
1348 if (layer && !layer->getModel().isNone()) {
|
Chris@1475
|
1349 models.insert(layer->getModel());
|
Chris@315
|
1350 }
|
Chris@315
|
1351 }
|
Chris@315
|
1352
|
Chris@315
|
1353 return models;
|
Chris@315
|
1354 }
|
Chris@315
|
1355
|
Chris@1475
|
1356 ModelId
|
Chris@320
|
1357 View::getAligningModel() const
|
Chris@301
|
1358 {
|
Chris@1490
|
1359 ModelId aligning, reference;
|
Chris@1490
|
1360 getAligningAndReferenceModels(aligning, reference);
|
Chris@1490
|
1361 return aligning;
|
Chris@1490
|
1362 }
|
Chris@1490
|
1363
|
Chris@1490
|
1364 void
|
Chris@1490
|
1365 View::getAligningAndReferenceModels(ModelId &aligning,
|
Chris@1490
|
1366 ModelId &reference) const
|
Chris@1490
|
1367 {
|
Chris@320
|
1368 if (!m_manager ||
|
Chris@320
|
1369 !m_manager->getAlignMode() ||
|
Chris@1479
|
1370 m_manager->getPlaybackModel().isNone()) {
|
Chris@1490
|
1371 return;
|
Chris@314
|
1372 }
|
Chris@301
|
1373
|
Chris@1475
|
1374 ModelId anyModel;
|
Chris@1475
|
1375
|
Chris@1475
|
1376 for (auto layer: m_layerStack) {
|
Chris@320
|
1377
|
Chris@320
|
1378 if (!layer) continue;
|
Chris@320
|
1379 if (dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@301
|
1380
|
Chris@1481
|
1381 ModelId thisId = layer->getModel();
|
Chris@1481
|
1382 auto model = ModelById::get(thisId);
|
Chris@301
|
1383 if (!model) continue;
|
Chris@301
|
1384
|
Chris@1481
|
1385 anyModel = thisId;
|
Chris@1475
|
1386
|
Chris@1475
|
1387 if (!model->getAlignmentReference().isNone()) {
|
Chris@1490
|
1388
|
Chris@320
|
1389 if (layer->isLayerOpaque() ||
|
Chris@1475
|
1390 std::dynamic_pointer_cast
|
Chris@1475
|
1391 <RangeSummarisableTimeValueModel>(model)) {
|
Chris@1490
|
1392
|
Chris@1490
|
1393 aligning = thisId;
|
Chris@1490
|
1394 reference = model->getAlignmentReference();
|
Chris@1490
|
1395 return;
|
Chris@1490
|
1396
|
Chris@1490
|
1397 } else if (aligning.isNone()) {
|
Chris@1490
|
1398
|
Chris@1490
|
1399 aligning = thisId;
|
Chris@1490
|
1400 reference = model->getAlignmentReference();
|
Chris@320
|
1401 }
|
Chris@301
|
1402 }
|
Chris@320
|
1403 }
|
Chris@301
|
1404
|
Chris@1490
|
1405 if (aligning.isNone()) {
|
Chris@1490
|
1406 aligning = anyModel;
|
Chris@1490
|
1407 reference = {};
|
Chris@1490
|
1408 }
|
Chris@320
|
1409 }
|
Chris@320
|
1410
|
Chris@908
|
1411 sv_frame_t
|
Chris@908
|
1412 View::alignFromReference(sv_frame_t f) const
|
Chris@320
|
1413 {
|
Chris@856
|
1414 if (!m_manager || !m_manager->getAlignMode()) return f;
|
Chris@1475
|
1415 auto aligningModel = ModelById::get(getAligningModel());
|
Chris@320
|
1416 if (!aligningModel) return f;
|
Chris@320
|
1417 return aligningModel->alignFromReference(f);
|
Chris@320
|
1418 }
|
Chris@320
|
1419
|
Chris@908
|
1420 sv_frame_t
|
Chris@908
|
1421 View::alignToReference(sv_frame_t f) const
|
Chris@320
|
1422 {
|
Chris@321
|
1423 if (!m_manager->getAlignMode()) return f;
|
Chris@1475
|
1424 auto aligningModel = ModelById::get(getAligningModel());
|
Chris@320
|
1425 if (!aligningModel) return f;
|
Chris@320
|
1426 return aligningModel->alignToReference(f);
|
Chris@320
|
1427 }
|
Chris@320
|
1428
|
Chris@908
|
1429 sv_frame_t
|
Chris@320
|
1430 View::getAlignedPlaybackFrame() const
|
Chris@320
|
1431 {
|
Chris@856
|
1432 if (!m_manager) return 0;
|
Chris@908
|
1433 sv_frame_t pf = m_manager->getPlaybackFrame();
|
Chris@321
|
1434 if (!m_manager->getAlignMode()) return pf;
|
Chris@321
|
1435
|
Chris@1475
|
1436 auto aligningModel = ModelById::get(getAligningModel());
|
Chris@320
|
1437 if (!aligningModel) return pf;
|
Chris@830
|
1438
|
Chris@908
|
1439 sv_frame_t af = aligningModel->alignFromReference(pf);
|
Chris@301
|
1440
|
Chris@301
|
1441 return af;
|
Chris@301
|
1442 }
|
Chris@301
|
1443
|
Chris@127
|
1444 bool
|
Chris@127
|
1445 View::areLayersScrollable() const
|
Chris@127
|
1446 {
|
Chris@127
|
1447 // True iff all views are scrollable
|
Chris@835
|
1448 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
1449 if (!(*i)->isLayerScrollable(this)) return false;
|
Chris@127
|
1450 }
|
Chris@127
|
1451 return true;
|
Chris@127
|
1452 }
|
Chris@127
|
1453
|
Chris@127
|
1454 View::LayerList
|
Chris@127
|
1455 View::getScrollableBackLayers(bool testChanged, bool &changed) const
|
Chris@127
|
1456 {
|
Chris@127
|
1457 changed = false;
|
Chris@127
|
1458
|
Chris@127
|
1459 // We want a list of all the scrollable layers that are behind the
|
Chris@127
|
1460 // backmost non-scrollable layer.
|
Chris@127
|
1461
|
Chris@127
|
1462 LayerList scrollables;
|
Chris@127
|
1463 bool metUnscrollable = false;
|
Chris@127
|
1464
|
Chris@835
|
1465 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@587
|
1466 // SVDEBUG << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << endl;
|
Chris@682
|
1467 // cerr << "(name is " << (*i)->objectName() << ")"
|
Chris@682
|
1468 // << endl;
|
Chris@1495
|
1469 // SVDEBUG << "View::getScrollableBackLayers: I am " << getId() << endl;
|
Chris@1266
|
1470 if ((*i)->isLayerDormant(this)) continue;
|
Chris@1266
|
1471 if ((*i)->isLayerOpaque()) {
|
Chris@1266
|
1472 // You can't see anything behind an opaque layer!
|
Chris@1266
|
1473 scrollables.clear();
|
Chris@127
|
1474 if (metUnscrollable) break;
|
Chris@1266
|
1475 }
|
Chris@1266
|
1476 if (!metUnscrollable && (*i)->isLayerScrollable(this)) {
|
Chris@127
|
1477 scrollables.push_back(*i);
|
Chris@127
|
1478 } else {
|
Chris@127
|
1479 metUnscrollable = true;
|
Chris@127
|
1480 }
|
Chris@127
|
1481 }
|
Chris@127
|
1482
|
Chris@127
|
1483 if (testChanged && scrollables != m_lastScrollableBackLayers) {
|
Chris@1266
|
1484 m_lastScrollableBackLayers = scrollables;
|
Chris@1266
|
1485 changed = true;
|
Chris@127
|
1486 }
|
Chris@127
|
1487 return scrollables;
|
Chris@127
|
1488 }
|
Chris@127
|
1489
|
Chris@127
|
1490 View::LayerList
|
Chris@127
|
1491 View::getNonScrollableFrontLayers(bool testChanged, bool &changed) const
|
Chris@127
|
1492 {
|
Chris@127
|
1493 changed = false;
|
Chris@127
|
1494 LayerList nonScrollables;
|
Chris@127
|
1495
|
Chris@127
|
1496 // Everything in front of the first non-scrollable from the back
|
Chris@127
|
1497 // should also be considered non-scrollable
|
Chris@127
|
1498
|
Chris@127
|
1499 bool started = false;
|
Chris@127
|
1500
|
Chris@835
|
1501 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
1502 if ((*i)->isLayerDormant(this)) continue;
|
Chris@1266
|
1503 if (!started && (*i)->isLayerScrollable(this)) {
|
Chris@1266
|
1504 continue;
|
Chris@1266
|
1505 }
|
Chris@1266
|
1506 started = true;
|
Chris@1266
|
1507 if ((*i)->isLayerOpaque()) {
|
Chris@1266
|
1508 // You can't see anything behind an opaque layer!
|
Chris@1266
|
1509 nonScrollables.clear();
|
Chris@1266
|
1510 }
|
Chris@1266
|
1511 nonScrollables.push_back(*i);
|
Chris@127
|
1512 }
|
Chris@127
|
1513
|
Chris@127
|
1514 if (testChanged && nonScrollables != m_lastNonScrollableBackLayers) {
|
Chris@1266
|
1515 m_lastNonScrollableBackLayers = nonScrollables;
|
Chris@1266
|
1516 changed = true;
|
Chris@127
|
1517 }
|
Chris@127
|
1518
|
Chris@127
|
1519 return nonScrollables;
|
Chris@127
|
1520 }
|
Chris@127
|
1521
|
Chris@1327
|
1522 ZoomLevel
|
Chris@1327
|
1523 View::getZoomConstraintLevel(ZoomLevel zoomLevel,
|
Chris@1327
|
1524 ZoomConstraint::RoundingDirection dir)
|
Chris@127
|
1525 const
|
Chris@127
|
1526 {
|
Chris@1327
|
1527 using namespace std::rel_ops;
|
Chris@1327
|
1528
|
Chris@1354
|
1529 ZoomLevel candidate =
|
Chris@1354
|
1530 RelativelyFineZoomConstraint().getNearestZoomLevel(zoomLevel, dir);
|
Chris@1354
|
1531
|
Chris@1354
|
1532 for (auto i : m_layerStack) {
|
Chris@1354
|
1533
|
Chris@1354
|
1534 if (i->supportsOtherZoomLevels() || !(i->getZoomConstraint())) {
|
Chris@1354
|
1535 continue;
|
Chris@1354
|
1536 }
|
Chris@1354
|
1537
|
Chris@1327
|
1538 ZoomLevel thisLevel =
|
Chris@1354
|
1539 i->getZoomConstraint()->getNearestZoomLevel(zoomLevel, dir);
|
Chris@1266
|
1540
|
Chris@1266
|
1541 // Go for the block size that's furthest from the one
|
Chris@1266
|
1542 // passed in. Most of the time, that's what we want.
|
Chris@1354
|
1543 if ((thisLevel > zoomLevel && thisLevel > candidate) ||
|
Chris@1327
|
1544 (thisLevel < zoomLevel && thisLevel < candidate)) {
|
Chris@1327
|
1545 candidate = thisLevel;
|
Chris@1266
|
1546 }
|
Chris@127
|
1547 }
|
Chris@127
|
1548
|
Chris@127
|
1549 return candidate;
|
Chris@127
|
1550 }
|
Chris@127
|
1551
|
Chris@1354
|
1552 int
|
Chris@1354
|
1553 View::countZoomLevels() const
|
Chris@1354
|
1554 {
|
Chris@1354
|
1555 int n = 0;
|
Chris@1354
|
1556 ZoomLevel min = ZoomConstraint().getMinZoomLevel();
|
Chris@1354
|
1557 ZoomLevel max = ZoomConstraint().getMaxZoomLevel();
|
Chris@1354
|
1558 ZoomLevel level = min;
|
Chris@1354
|
1559 while (true) {
|
Chris@1354
|
1560 ++n;
|
Chris@1354
|
1561 if (level == max) {
|
Chris@1354
|
1562 break;
|
Chris@1354
|
1563 }
|
Chris@1354
|
1564 level = getZoomConstraintLevel
|
Chris@1354
|
1565 (level.incremented(), ZoomConstraint::RoundUp);
|
Chris@1354
|
1566 }
|
Chris@1355
|
1567 // cerr << "View::countZoomLevels: " << n << endl;
|
Chris@1354
|
1568 return n;
|
Chris@1354
|
1569 }
|
Chris@1354
|
1570
|
Chris@1354
|
1571 ZoomLevel
|
Chris@1354
|
1572 View::getZoomLevelByIndex(int ix) const
|
Chris@1354
|
1573 {
|
Chris@1354
|
1574 int n = 0;
|
Chris@1354
|
1575 ZoomLevel min = ZoomConstraint().getMinZoomLevel();
|
Chris@1354
|
1576 ZoomLevel max = ZoomConstraint().getMaxZoomLevel();
|
Chris@1354
|
1577 ZoomLevel level = min;
|
Chris@1354
|
1578 while (true) {
|
Chris@1354
|
1579 if (n == ix) {
|
Chris@1355
|
1580 // cerr << "View::getZoomLevelByIndex: " << ix << " -> " << level
|
Chris@1355
|
1581 // << endl;
|
Chris@1354
|
1582 return level;
|
Chris@1354
|
1583 }
|
Chris@1354
|
1584 ++n;
|
Chris@1354
|
1585 if (level == max) {
|
Chris@1354
|
1586 break;
|
Chris@1354
|
1587 }
|
Chris@1354
|
1588 level = getZoomConstraintLevel
|
Chris@1354
|
1589 (level.incremented(), ZoomConstraint::RoundUp);
|
Chris@1354
|
1590 }
|
Chris@1355
|
1591 // cerr << "View::getZoomLevelByIndex: " << ix << " -> " << max << " (max)"
|
Chris@1355
|
1592 // << endl;
|
Chris@1354
|
1593 return max;
|
Chris@1354
|
1594 }
|
Chris@1354
|
1595
|
Chris@1354
|
1596 int
|
Chris@1354
|
1597 View::getZoomLevelIndex(ZoomLevel z) const
|
Chris@1354
|
1598 {
|
Chris@1354
|
1599 int n = 0;
|
Chris@1354
|
1600 ZoomLevel min = ZoomConstraint().getMinZoomLevel();
|
Chris@1354
|
1601 ZoomLevel max = ZoomConstraint().getMaxZoomLevel();
|
Chris@1354
|
1602 ZoomLevel level = min;
|
Chris@1354
|
1603 while (true) {
|
Chris@1354
|
1604 if (z == level) {
|
Chris@1355
|
1605 // cerr << "View::getZoomLevelIndex: " << z << " -> " << n
|
Chris@1355
|
1606 // << endl;
|
Chris@1354
|
1607 return n;
|
Chris@1354
|
1608 }
|
Chris@1354
|
1609 ++n;
|
Chris@1354
|
1610 if (level == max) {
|
Chris@1354
|
1611 break;
|
Chris@1354
|
1612 }
|
Chris@1354
|
1613 level = getZoomConstraintLevel
|
Chris@1354
|
1614 (level.incremented(), ZoomConstraint::RoundUp);
|
Chris@1354
|
1615 }
|
Chris@1355
|
1616 // cerr << "View::getZoomLevelIndex: " << z << " -> " << n << " (max)"
|
Chris@1355
|
1617 // << endl;
|
Chris@1354
|
1618 return n;
|
Chris@1354
|
1619 }
|
Chris@1354
|
1620
|
Chris@1401
|
1621 double
|
Chris@1401
|
1622 View::scaleSize(double size) const
|
Chris@1401
|
1623 {
|
Chris@1401
|
1624 static double ratio = 0.0;
|
Chris@1401
|
1625
|
Chris@1401
|
1626 if (ratio == 0.0) {
|
Chris@1401
|
1627 double baseEm;
|
Chris@1401
|
1628 #ifdef Q_OS_MAC
|
Chris@1401
|
1629 baseEm = 17.0;
|
Chris@1401
|
1630 #else
|
Chris@1401
|
1631 baseEm = 15.0;
|
Chris@1401
|
1632 #endif
|
Chris@1401
|
1633 double em = QFontMetrics(QFont()).height();
|
Chris@1401
|
1634 ratio = em / baseEm;
|
Chris@1401
|
1635
|
Chris@1401
|
1636 SVDEBUG << "View::scaleSize: ratio is " << ratio
|
Chris@1401
|
1637 << " (em = " << em << ")" << endl;
|
Chris@1401
|
1638
|
Chris@1401
|
1639 if (ratio < 1.0) {
|
Chris@1401
|
1640 SVDEBUG << "View::scaleSize: rounding ratio up to 1.0" << endl;
|
Chris@1401
|
1641 ratio = 1.0;
|
Chris@1401
|
1642 }
|
Chris@1401
|
1643 }
|
Chris@1401
|
1644
|
Chris@1401
|
1645 return size * ratio;
|
Chris@1401
|
1646 }
|
Chris@1401
|
1647
|
Chris@1402
|
1648 int
|
Chris@1402
|
1649 View::scalePixelSize(int size) const
|
Chris@1402
|
1650 {
|
Chris@1402
|
1651 double d = scaleSize(size);
|
Chris@1402
|
1652 int i = int(d + 0.5);
|
Chris@1402
|
1653 if (size != 0 && i == 0) i = 1;
|
Chris@1402
|
1654 return i;
|
Chris@1402
|
1655 }
|
Chris@1402
|
1656
|
Chris@1401
|
1657 double
|
Chris@1401
|
1658 View::scalePenWidth(double width) const
|
Chris@1401
|
1659 {
|
Chris@1401
|
1660 if (width <= 0) { // zero-width pen, produce a scaled one-pixel pen
|
Chris@1401
|
1661 width = 1;
|
Chris@1401
|
1662 }
|
Chris@1401
|
1663 double ratio = scaleSize(1.0);
|
Chris@1401
|
1664 return width * sqrt(ratio);
|
Chris@1401
|
1665 }
|
Chris@1401
|
1666
|
Chris@1401
|
1667 QPen
|
Chris@1401
|
1668 View::scalePen(QPen pen) const
|
Chris@1401
|
1669 {
|
Chris@1401
|
1670 return QPen(pen.color(), scalePenWidth(pen.width()));
|
Chris@1401
|
1671 }
|
Chris@1401
|
1672
|
Chris@183
|
1673 bool
|
Chris@183
|
1674 View::areLayerColoursSignificant() const
|
Chris@183
|
1675 {
|
Chris@835
|
1676 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) {
|
Chris@1266
|
1677 if ((*i)->getLayerColourSignificance() ==
|
Chris@287
|
1678 Layer::ColourHasMeaningfulValue) return true;
|
Chris@183
|
1679 if ((*i)->isLayerOpaque()) break;
|
Chris@183
|
1680 }
|
Chris@183
|
1681 return false;
|
Chris@183
|
1682 }
|
Chris@183
|
1683
|
Chris@217
|
1684 bool
|
Chris@217
|
1685 View::hasTopLayerTimeXAxis() const
|
Chris@217
|
1686 {
|
Chris@835
|
1687 LayerList::const_iterator i = m_layerStack.end();
|
Chris@835
|
1688 if (i == m_layerStack.begin()) return false;
|
Chris@217
|
1689 --i;
|
Chris@217
|
1690 return (*i)->hasTimeXAxis();
|
Chris@217
|
1691 }
|
Chris@217
|
1692
|
Chris@127
|
1693 void
|
Chris@127
|
1694 View::zoom(bool in)
|
Chris@127
|
1695 {
|
Chris@1183
|
1696 ZoomLevel newZoomLevel = m_zoomLevel;
|
Chris@127
|
1697
|
Chris@127
|
1698 if (in) {
|
Chris@1324
|
1699 newZoomLevel = getZoomConstraintLevel(m_zoomLevel.decremented(),
|
Chris@1183
|
1700 ZoomConstraint::RoundDown);
|
Chris@127
|
1701 } else {
|
Chris@1324
|
1702 newZoomLevel = getZoomConstraintLevel(m_zoomLevel.incremented(),
|
Chris@1183
|
1703 ZoomConstraint::RoundUp);
|
Chris@127
|
1704 }
|
Chris@127
|
1705
|
Chris@1327
|
1706 using namespace std::rel_ops;
|
Chris@1327
|
1707
|
Chris@127
|
1708 if (newZoomLevel != m_zoomLevel) {
|
Chris@1266
|
1709 setZoomLevel(newZoomLevel);
|
Chris@127
|
1710 }
|
Chris@127
|
1711 }
|
Chris@127
|
1712
|
Chris@127
|
1713 void
|
Chris@510
|
1714 View::scroll(bool right, bool lots, bool e)
|
Chris@127
|
1715 {
|
Chris@908
|
1716 sv_frame_t delta;
|
Chris@127
|
1717 if (lots) {
|
Chris@1266
|
1718 delta = (getEndFrame() - getStartFrame()) / 2;
|
Chris@127
|
1719 } else {
|
Chris@1266
|
1720 delta = (getEndFrame() - getStartFrame()) / 20;
|
Chris@127
|
1721 }
|
Chris@127
|
1722 if (right) delta = -delta;
|
Chris@127
|
1723
|
Chris@1363
|
1724 #ifdef DEBUG_VIEW
|
Chris@1363
|
1725 SVCERR << "View::scroll(" << right << ", " << lots << ", " << e << "): "
|
Chris@1363
|
1726 << "delta = " << delta << ", m_centreFrame = " << m_centreFrame
|
Chris@1363
|
1727 << endl;
|
Chris@1363
|
1728 #endif
|
Chris@1363
|
1729
|
Chris@908
|
1730 if (m_centreFrame < delta) {
|
Chris@1266
|
1731 setCentreFrame(0, e);
|
Chris@908
|
1732 } else if (m_centreFrame - delta >= getModelsEndFrame()) {
|
Chris@1266
|
1733 setCentreFrame(getModelsEndFrame(), e);
|
Chris@127
|
1734 } else {
|
Chris@1266
|
1735 setCentreFrame(m_centreFrame - delta, e);
|
Chris@127
|
1736 }
|
Chris@127
|
1737 }
|
Chris@127
|
1738
|
Chris@127
|
1739 void
|
Chris@797
|
1740 View::cancelClicked()
|
Chris@797
|
1741 {
|
Chris@797
|
1742 QPushButton *cancel = qobject_cast<QPushButton *>(sender());
|
Chris@797
|
1743 if (!cancel) return;
|
Chris@797
|
1744
|
Chris@1483
|
1745 Layer *layer = nullptr;
|
Chris@1483
|
1746
|
Chris@797
|
1747 for (ProgressMap::iterator i = m_progressBars.begin();
|
Chris@1266
|
1748 i != m_progressBars.end(); ++i) {
|
Chris@797
|
1749 if (i->second.cancel == cancel) {
|
Chris@1483
|
1750 layer = i->first;
|
Chris@1483
|
1751 break;
|
Chris@797
|
1752 }
|
Chris@797
|
1753 }
|
Chris@1483
|
1754
|
Chris@1483
|
1755 if (layer) {
|
Chris@1483
|
1756 emit cancelButtonPressed(layer);
|
Chris@1483
|
1757 }
|
Chris@797
|
1758 }
|
Chris@797
|
1759
|
Chris@797
|
1760 void
|
Chris@1481
|
1761 View::checkProgress(ModelId modelId)
|
Chris@127
|
1762 {
|
Chris@1448
|
1763 if (!m_showProgress) {
|
Chris@1448
|
1764 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1765 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << "): "
|
Chris@1448
|
1766 << "m_showProgress is off" << endl;
|
Chris@1448
|
1767 #endif
|
Chris@1448
|
1768 return;
|
Chris@1448
|
1769 }
|
Chris@127
|
1770
|
Chris@1458
|
1771 QSettings settings;
|
Chris@1458
|
1772 settings.beginGroup("View");
|
Chris@1458
|
1773 bool showCancelButton = settings.value("showcancelbuttons", true).toBool();
|
Chris@1458
|
1774 settings.endGroup();
|
Chris@1458
|
1775
|
Chris@127
|
1776 int ph = height();
|
Chris@1448
|
1777 bool found = false;
|
Chris@127
|
1778
|
Chris@555
|
1779 for (ProgressMap::iterator i = m_progressBars.begin();
|
Chris@1266
|
1780 i != m_progressBars.end(); ++i) {
|
Chris@127
|
1781
|
Chris@555
|
1782 QProgressBar *pb = i->second.bar;
|
Chris@797
|
1783 QPushButton *cancel = i->second.cancel;
|
Chris@555
|
1784
|
Chris@1481
|
1785 if (i->first && i->first->getModel() == modelId) {
|
Chris@127
|
1786
|
Chris@1448
|
1787 found = true;
|
Chris@1495
|
1788 bool isAlignmentProgress = false;
|
Chris@1448
|
1789
|
Chris@555
|
1790 // The timer is used to test for stalls. If the progress
|
Chris@555
|
1791 // bar does not get updated for some length of time, the
|
Chris@555
|
1792 // timer prompts it to go back into "indeterminate" mode
|
Chris@555
|
1793 QTimer *timer = i->second.checkTimer;
|
Chris@555
|
1794
|
Chris@1266
|
1795 int completion = i->first->getCompletion(this);
|
Chris@301
|
1796 QString text = i->first->getPropertyContainerName();
|
Chris@583
|
1797 QString error = i->first->getError(this);
|
Chris@583
|
1798
|
Chris@1448
|
1799 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1800 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << "): "
|
Chris@1448
|
1801 << "found progress bar " << pb << " for layer at height " << ph
|
Chris@1448
|
1802 << ": completion = " << completion << endl;
|
Chris@1448
|
1803 #endif
|
Chris@1448
|
1804
|
Chris@583
|
1805 if (error != "" && error != m_lastError) {
|
Chris@583
|
1806 QMessageBox::critical(this, tr("Layer rendering error"), error);
|
Chris@583
|
1807 m_lastError = error;
|
Chris@583
|
1808 }
|
Chris@301
|
1809
|
Chris@1476
|
1810 auto model = ModelById::get(modelId);
|
Chris@1476
|
1811 auto wfm = std::dynamic_pointer_cast
|
Chris@1476
|
1812 <RangeSummarisableTimeValueModel>(model);
|
Chris@387
|
1813
|
Chris@388
|
1814 if (completion > 0) {
|
Chris@555
|
1815 pb->setMaximum(100); // was 0, for indeterminate start
|
Chris@388
|
1816 }
|
Chris@388
|
1817
|
Chris@301
|
1818 if (completion >= 100) {
|
Chris@1476
|
1819
|
Chris@326
|
1820 if (wfm ||
|
Chris@776
|
1821 (model &&
|
Chris@1476
|
1822 (wfm = ModelById::getAs<RangeSummarisableTimeValueModel>
|
Chris@776
|
1823 (model->getSourceModel())))) {
|
Chris@1485
|
1824
|
Chris@1495
|
1825 isAlignmentProgress = true;
|
Chris@1495
|
1826
|
Chris@301
|
1827 completion = wfm->getAlignmentCompletion();
|
Chris@1448
|
1828
|
Chris@1485
|
1829 // We don't allow cancelling alignment operations
|
Chris@1485
|
1830 // - they aren't usually all that expensive, and
|
Chris@1485
|
1831 // it would leave things in a very uncertain state
|
Chris@1485
|
1832 showCancelButton = false;
|
Chris@1485
|
1833
|
Chris@1448
|
1834 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1835 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << "): "
|
Chris@1448
|
1836 << "alignment completion = " << completion << endl;
|
Chris@1448
|
1837 #endif
|
Chris@1448
|
1838
|
Chris@301
|
1839 if (completion < 100) {
|
Chris@301
|
1840 text = tr("Alignment");
|
Chris@301
|
1841 }
|
Chris@301
|
1842 }
|
Chris@387
|
1843
|
Chris@387
|
1844 } else if (wfm) {
|
Chris@387
|
1845 update(); // ensure duration &c gets updated
|
Chris@301
|
1846 }
|
Chris@127
|
1847
|
Chris@1266
|
1848 if (completion >= 100) {
|
Chris@1266
|
1849
|
Chris@1266
|
1850 pb->hide();
|
Chris@797
|
1851 cancel->hide();
|
Chris@555
|
1852 timer->stop();
|
Chris@127
|
1853
|
Chris@1495
|
1854 } else if (i->first->isLayerDormant(this) && !isAlignmentProgress) {
|
Chris@1495
|
1855
|
Chris@1495
|
1856 // A dormant (invisible) layer can still be busy
|
Chris@1495
|
1857 // generating, but we don't usually want to indicate
|
Chris@1495
|
1858 // it because it probably means it's a duplicate of a
|
Chris@1495
|
1859 // visible layer
|
Chris@1495
|
1860 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1861 SVCERR << "View[" << getId() << "]::checkProgress("
|
Chris@1495
|
1862 << modelId << "): layer is dormant" << endl;
|
Chris@1495
|
1863 #endif
|
Chris@1495
|
1864 pb->hide();
|
Chris@1495
|
1865 cancel->hide();
|
Chris@1495
|
1866 timer->stop();
|
Chris@1495
|
1867
|
Chris@1266
|
1868 } else {
|
Chris@127
|
1869
|
Chris@555
|
1870 if (!pb->isVisible()) {
|
Chris@555
|
1871 i->second.lastCheck = 0;
|
Chris@555
|
1872 timer->setInterval(2000);
|
Chris@555
|
1873 timer->start();
|
Chris@555
|
1874 }
|
Chris@555
|
1875
|
Chris@1458
|
1876 if (showCancelButton) {
|
Chris@1458
|
1877
|
Chris@1458
|
1878 int scaled20 = scalePixelSize(20);
|
Chris@1458
|
1879
|
Chris@1458
|
1880 cancel->move(0, ph - pb->height()/2 - scaled20/2);
|
Chris@1458
|
1881 cancel->show();
|
Chris@1458
|
1882
|
Chris@1458
|
1883 pb->setValue(completion);
|
Chris@1458
|
1884 pb->move(scaled20, ph - pb->height());
|
Chris@1458
|
1885
|
Chris@1458
|
1886 } else {
|
Chris@1458
|
1887
|
Chris@1458
|
1888 cancel->hide();
|
Chris@1458
|
1889
|
Chris@1458
|
1890 pb->setValue(completion);
|
Chris@1458
|
1891 pb->move(0, ph - pb->height());
|
Chris@1458
|
1892 }
|
Chris@1266
|
1893
|
Chris@1266
|
1894 pb->show();
|
Chris@1266
|
1895 pb->update();
|
Chris@1266
|
1896
|
Chris@1495
|
1897 if (pb->isVisible()) {
|
Chris@1495
|
1898 ph -= pb->height();
|
Chris@1495
|
1899 }
|
Chris@1266
|
1900 }
|
Chris@1266
|
1901 } else {
|
Chris@1266
|
1902 if (pb->isVisible()) {
|
Chris@1266
|
1903 ph -= pb->height();
|
Chris@1266
|
1904 }
|
Chris@1266
|
1905 }
|
Chris@127
|
1906 }
|
Chris@1448
|
1907
|
Chris@1448
|
1908 if (!found) {
|
Chris@1448
|
1909 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1910 SVCERR << "View[" << getId() << "]::checkProgress(" << modelId << "): "
|
Chris@1487
|
1911 << "failed to find layer for model in progress map"
|
Chris@1448
|
1912 << endl;
|
Chris@1448
|
1913 #endif
|
Chris@1448
|
1914 }
|
Chris@127
|
1915 }
|
Chris@127
|
1916
|
Chris@555
|
1917 void
|
Chris@555
|
1918 View::progressCheckStalledTimerElapsed()
|
Chris@555
|
1919 {
|
Chris@555
|
1920 QObject *s = sender();
|
Chris@555
|
1921 QTimer *t = qobject_cast<QTimer *>(s);
|
Chris@555
|
1922 if (!t) return;
|
Chris@1448
|
1923
|
Chris@555
|
1924 for (ProgressMap::iterator i = m_progressBars.begin();
|
Chris@555
|
1925 i != m_progressBars.end(); ++i) {
|
Chris@1448
|
1926
|
Chris@555
|
1927 if (i->second.checkTimer == t) {
|
Chris@1448
|
1928
|
Chris@1495
|
1929 int value = i->second.bar->value();
|
Chris@1495
|
1930
|
Chris@1448
|
1931 #ifdef DEBUG_PROGRESS_STUFF
|
Chris@1495
|
1932 SVCERR << "View[" << getId() << "]::progressCheckStalledTimerElapsed for layer " << i->first << ": value is " << value << endl;
|
Chris@1448
|
1933 #endif
|
Chris@1448
|
1934
|
Chris@555
|
1935 if (value > 0 && value == i->second.lastCheck) {
|
Chris@555
|
1936 i->second.bar->setMaximum(0); // indeterminate
|
Chris@555
|
1937 }
|
Chris@555
|
1938 i->second.lastCheck = value;
|
Chris@555
|
1939 return;
|
Chris@555
|
1940 }
|
Chris@555
|
1941 }
|
Chris@555
|
1942 }
|
Chris@555
|
1943
|
Chris@384
|
1944 int
|
Chris@384
|
1945 View::getProgressBarWidth() const
|
Chris@384
|
1946 {
|
Chris@384
|
1947 for (ProgressMap::const_iterator i = m_progressBars.begin();
|
Chris@1266
|
1948 i != m_progressBars.end(); ++i) {
|
Chris@555
|
1949 if (i->second.bar && i->second.bar->isVisible()) {
|
Chris@555
|
1950 return i->second.bar->width();
|
Chris@555
|
1951 }
|
Chris@384
|
1952 }
|
Chris@384
|
1953
|
Chris@384
|
1954 return 0;
|
Chris@384
|
1955 }
|
Chris@384
|
1956
|
Chris@127
|
1957 void
|
Chris@339
|
1958 View::setPaintFont(QPainter &paint)
|
Chris@339
|
1959 {
|
Chris@955
|
1960 int scaleFactor = 1;
|
Chris@956
|
1961 int dpratio = effectiveDevicePixelRatio();
|
Chris@955
|
1962 if (dpratio > 1) {
|
Chris@955
|
1963 QPaintDevice *dev = paint.device();
|
Chris@955
|
1964 if (dynamic_cast<QPixmap *>(dev) || dynamic_cast<QImage *>(dev)) {
|
Chris@955
|
1965 scaleFactor = dpratio;
|
Chris@955
|
1966 }
|
Chris@955
|
1967 }
|
Chris@955
|
1968
|
Chris@339
|
1969 QFont font(paint.font());
|
Chris@955
|
1970 font.setPointSize(Preferences::getInstance()->getViewFontSize()
|
Chris@955
|
1971 * scaleFactor);
|
Chris@339
|
1972 paint.setFont(font);
|
Chris@339
|
1973 }
|
Chris@339
|
1974
|
Chris@915
|
1975 QRect
|
Chris@915
|
1976 View::getPaintRect() const
|
Chris@915
|
1977 {
|
Chris@919
|
1978 return rect();
|
Chris@915
|
1979 }
|
Chris@915
|
1980
|
Chris@339
|
1981 void
|
Chris@127
|
1982 View::paintEvent(QPaintEvent *e)
|
Chris@127
|
1983 {
|
Chris@127
|
1984 // Profiler prof("View::paintEvent", false);
|
Chris@800
|
1985 // cerr << "View::paintEvent: centre frame is " << m_centreFrame << endl;
|
matthiasm@785
|
1986
|
Chris@835
|
1987 if (m_layerStack.empty()) {
|
Chris@1266
|
1988 QFrame::paintEvent(e);
|
Chris@1266
|
1989 return;
|
Chris@127
|
1990 }
|
Chris@127
|
1991
|
Chris@127
|
1992 // ensure our constraints are met
|
Chris@1354
|
1993 m_zoomLevel = getZoomConstraintLevel
|
Chris@1354
|
1994 (m_zoomLevel, ZoomConstraint::RoundNearest);
|
Chris@127
|
1995
|
Chris@1357
|
1996 // We have a cache, which retains the state of scrollable (back)
|
Chris@1357
|
1997 // layers from one paint to the next, and a buffer, which we paint
|
Chris@1357
|
1998 // onto before copying directly to the widget. Both are at scaled
|
Chris@1357
|
1999 // resolution (e.g. 2x on a pixel-doubled display), whereas the
|
Chris@1357
|
2000 // paint event always comes in at formal (1x) resolution.
|
Chris@1357
|
2001
|
Chris@1357
|
2002 // If we touch the cache, we always leave it in a valid state
|
Chris@1357
|
2003 // across its whole extent. When another method invalidates the
|
Chris@1357
|
2004 // cache, it does so by setting m_cacheValid false, so if that
|
Chris@1357
|
2005 // flag is true on entry, then the cache is valid across its whole
|
Chris@1357
|
2006 // extent - although it may be valid for a different centre frame,
|
Chris@1357
|
2007 // zoom level, or view size from those now in effect.
|
Chris@1357
|
2008
|
Chris@1357
|
2009 // Our process goes:
|
Chris@1357
|
2010 //
|
Chris@1357
|
2011 // 1. Check whether we have any scrollable (cacheable) layers. If
|
Chris@1357
|
2012 // we don't, then invalidate and ignore the cache and go to
|
Chris@1357
|
2013 // step 5. Otherwise:
|
Chris@1357
|
2014 //
|
Chris@1357
|
2015 // 2. Check the cache, scroll as necessary, identify any area that
|
Chris@1357
|
2016 // needs to be refreshed (this might be the whole cache).
|
Chris@1357
|
2017 //
|
Chris@1357
|
2018 // 3. Paint to cache the area that needs to be refreshed, from the
|
Chris@1357
|
2019 // stack of scrollable layers.
|
Chris@1357
|
2020 //
|
Chris@1357
|
2021 // 4. Paint to buffer from cache: if there are no non-cached areas
|
Chris@1357
|
2022 // or selections and the cache has not scrolled, then paint the
|
Chris@1357
|
2023 // union of the area of cache that has changed and the area
|
Chris@1357
|
2024 // that the paint event reported as exposed; otherwise paint
|
Chris@1357
|
2025 // the whole.
|
Chris@1357
|
2026 //
|
Chris@1357
|
2027 // 5. Paint the exposed area to the buffer from the cache plus all
|
Chris@1357
|
2028 // the layers that haven't been cached, plus selections etc.
|
Chris@1357
|
2029 //
|
Chris@1357
|
2030 // 6. Paint the exposed rect from the buffer.
|
Chris@1357
|
2031 //
|
Chris@1357
|
2032 // Note that all rects except the target for the final step are at
|
Chris@1357
|
2033 // cache (scaled, 2x as applicable) resolution.
|
Chris@1357
|
2034
|
Chris@1357
|
2035 int dpratio = effectiveDevicePixelRatio();
|
Chris@1357
|
2036
|
Chris@1357
|
2037 QRect requestedPaintArea(scaledRect(rect(), dpratio));
|
Chris@127
|
2038 if (e) {
|
Chris@1357
|
2039 // cut down to only the area actually exposed
|
Chris@1357
|
2040 requestedPaintArea &= scaledRect(e->rect(), dpratio);
|
Chris@127
|
2041 }
|
Chris@127
|
2042
|
Chris@127
|
2043 // If not all layers are scrollable, but some of the back layers
|
Chris@127
|
2044 // are, we should store only those in the cache.
|
Chris@127
|
2045
|
Chris@127
|
2046 bool layersChanged = false;
|
Chris@127
|
2047 LayerList scrollables = getScrollableBackLayers(true, layersChanged);
|
Chris@127
|
2048 LayerList nonScrollables = getNonScrollableFrontLayers(true, layersChanged);
|
Chris@127
|
2049
|
Chris@127
|
2050 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2051 cerr << "View(" << getId() << ")::paintEvent: have " << scrollables.size()
|
Chris@1266
|
2052 << " scrollable back layers and " << nonScrollables.size()
|
Chris@1266
|
2053 << " non-scrollable front layers" << endl;
|
Chris@127
|
2054 #endif
|
Chris@127
|
2055
|
Chris@1357
|
2056 if (layersChanged || scrollables.empty()) {
|
Chris@1357
|
2057 m_cacheValid = false;
|
Chris@127
|
2058 }
|
Chris@127
|
2059
|
Chris@1357
|
2060 QRect wholeArea(scaledRect(rect(), dpratio));
|
Chris@1357
|
2061 QSize wholeSize(scaledSize(size(), dpratio));
|
Chris@1357
|
2062
|
Chris@1357
|
2063 if (!m_buffer || wholeSize != m_buffer->size()) {
|
Chris@952
|
2064 delete m_buffer;
|
Chris@1357
|
2065 m_buffer = new QPixmap(wholeSize);
|
Chris@952
|
2066 }
|
Chris@1357
|
2067
|
Chris@1357
|
2068 bool shouldUseCache = false;
|
Chris@1357
|
2069 bool shouldRepaintCache = false;
|
Chris@1357
|
2070 QRect cacheAreaToRepaint;
|
Chris@952
|
2071
|
Chris@1357
|
2072 static HitCount count("View cache");
|
Chris@1357
|
2073
|
Chris@127
|
2074 if (!scrollables.empty()) {
|
Chris@244
|
2075
|
Chris@1357
|
2076 shouldUseCache = true;
|
Chris@1357
|
2077 shouldRepaintCache = true;
|
Chris@1357
|
2078 cacheAreaToRepaint = wholeArea;
|
Chris@1357
|
2079
|
Chris@244
|
2080 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2081 cerr << "View(" << getId() << "): cache " << m_cache << ", cache zoom "
|
Chris@682
|
2082 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl;
|
Chris@244
|
2083 #endif
|
Chris@244
|
2084
|
Chris@1327
|
2085 using namespace std::rel_ops;
|
Chris@1327
|
2086
|
Chris@1357
|
2087 if (!m_cacheValid ||
|
Chris@1357
|
2088 !m_cache ||
|
Chris@1266
|
2089 m_cacheZoomLevel != m_zoomLevel ||
|
Chris@1357
|
2090 m_cache->size() != wholeSize) {
|
Chris@1357
|
2091
|
Chris@1357
|
2092 // cache is not valid at all
|
Chris@1357
|
2093
|
Chris@1357
|
2094 if (requestedPaintArea.width() < wholeSize.width() / 10) {
|
Chris@1357
|
2095
|
Chris@1357
|
2096 m_cacheValid = false;
|
Chris@1357
|
2097 shouldUseCache = false;
|
Chris@1357
|
2098 shouldRepaintCache = false;
|
Chris@1357
|
2099
|
Chris@127
|
2100 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2101 cerr << "View(" << getId() << ")::paintEvent: cache is invalid but only small area requested, will repaint directly instead" << endl;
|
Chris@127
|
2102 #endif
|
Chris@1266
|
2103 } else {
|
Chris@1357
|
2104
|
Chris@1357
|
2105 if (!m_cache ||
|
Chris@1357
|
2106 m_cache->size() != wholeSize) {
|
Chris@1357
|
2107 delete m_cache;
|
Chris@1357
|
2108 m_cache = new QPixmap(wholeSize);
|
Chris@1357
|
2109 }
|
Chris@1357
|
2110
|
Chris@127
|
2111 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2112 cerr << "View(" << getId() << ")::paintEvent: cache is invalid, will repaint whole" << endl;
|
Chris@127
|
2113 #endif
|
Chris@1266
|
2114 }
|
Chris@1266
|
2115
|
Chris@1357
|
2116 count.miss();
|
Chris@1357
|
2117
|
Chris@1266
|
2118 } else if (m_cacheCentreFrame != m_centreFrame) {
|
Chris@1266
|
2119
|
Chris@1357
|
2120 int dx = dpratio * (getXForFrame(m_cacheCentreFrame) -
|
Chris@1357
|
2121 getXForFrame(m_centreFrame));
|
Chris@1357
|
2122
|
Chris@1357
|
2123 if (dx > -m_cache->width() && dx < m_cache->width()) {
|
Chris@1357
|
2124
|
Chris@1408
|
2125 m_cache->scroll(dx, 0, m_cache->rect(), nullptr);
|
Chris@1357
|
2126
|
Chris@1357
|
2127 if (dx < 0) {
|
Chris@1357
|
2128 cacheAreaToRepaint =
|
Chris@1357
|
2129 QRect(m_cache->width() + dx, 0, -dx, m_cache->height());
|
Chris@1357
|
2130 } else {
|
Chris@1357
|
2131 cacheAreaToRepaint =
|
Chris@1357
|
2132 QRect(0, 0, dx, m_cache->height());
|
Chris@1266
|
2133 }
|
Chris@1357
|
2134
|
Chris@1357
|
2135 count.partial();
|
Chris@1357
|
2136
|
Chris@127
|
2137 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2138 cerr << "View(" << getId() << ")::paintEvent: scrolled cache by " << dx << endl;
|
Chris@127
|
2139 #endif
|
Chris@1266
|
2140 } else {
|
Chris@1357
|
2141 count.miss();
|
Chris@127
|
2142 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2143 cerr << "View(" << getId() << ")::paintEvent: scrolling too far" << endl;
|
Chris@127
|
2144 #endif
|
Chris@1266
|
2145 }
|
Chris@1266
|
2146
|
Chris@1266
|
2147 } else {
|
Chris@127
|
2148 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2149 cerr << "View(" << getId() << ")::paintEvent: cache is good" << endl;
|
Chris@127
|
2150 #endif
|
Chris@1357
|
2151 count.hit();
|
Chris@1357
|
2152 shouldRepaintCache = false;
|
Chris@1266
|
2153 }
|
Chris@1357
|
2154 }
|
Chris@1357
|
2155
|
Chris@1357
|
2156 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1495
|
2157 cerr << "View(" << getId() << ")::paintEvent: m_cacheValid = " << m_cacheValid << ", shouldUseCache = " << shouldUseCache << ", shouldRepaintCache = " << shouldRepaintCache << ", cacheAreaToRepaint = " << cacheAreaToRepaint.x() << "," << cacheAreaToRepaint.y() << " " << cacheAreaToRepaint.width() << "x" << cacheAreaToRepaint.height() << endl;
|
Chris@1357
|
2158 #endif
|
Chris@1357
|
2159
|
Chris@1357
|
2160 if (shouldRepaintCache && !shouldUseCache) {
|
Chris@1357
|
2161 // If we are repainting the cache, then we paint the
|
Chris@1357
|
2162 // scrollables only to the cache, not to the buffer. So if
|
Chris@1357
|
2163 // shouldUseCache is also false, then the scrollables can't
|
Chris@1357
|
2164 // appear because they will only be on the cache
|
Chris@1357
|
2165 throw std::logic_error("ERROR: shouldRepaintCache is true, but shouldUseCache is false: this can't lead to the correct result");
|
Chris@1357
|
2166 }
|
Chris@1357
|
2167
|
Chris@1490
|
2168 // Create the ViewProxy for geometry provision, using the
|
Chris@1490
|
2169 // device-pixel ratio for pixel-doubled hi-dpi rendering as
|
Chris@1490
|
2170 // appropriate.
|
Chris@1490
|
2171
|
Chris@1490
|
2172 ViewProxy proxy(this, dpratio);
|
Chris@1490
|
2173
|
Chris@1490
|
2174 // Some layers may need an aligning proxy. If a layer's model has
|
Chris@1490
|
2175 // a source model that is the reference model for the aligning
|
Chris@1490
|
2176 // model, and the layer is tagged as to be aligned, then we use an
|
Chris@1490
|
2177 // aligning proxy.
|
Chris@1490
|
2178
|
Chris@1490
|
2179 ModelId alignmentModelId;
|
Chris@1490
|
2180 ModelId alignmentReferenceId;
|
Chris@1490
|
2181 auto aligningModel = ModelById::get(getAligningModel());
|
Chris@1490
|
2182 if (aligningModel) {
|
Chris@1490
|
2183 alignmentModelId = aligningModel->getAlignment();
|
Chris@1490
|
2184 alignmentReferenceId = aligningModel->getAlignmentReference();
|
Chris@1493
|
2185 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1492
|
2186 SVCERR << "alignmentModelId = " << alignmentModelId << " (reference = " << alignmentReferenceId << ")" << endl;
|
Chris@1493
|
2187 #endif
|
Chris@1490
|
2188 } else {
|
Chris@1493
|
2189 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1490
|
2190 SVCERR << "no aligningModel" << endl;
|
Chris@1493
|
2191 #endif
|
Chris@1490
|
2192 }
|
Chris@1490
|
2193 ViewProxy aligningProxy(this, dpratio, alignmentModelId);
|
Chris@1490
|
2194
|
Chris@1357
|
2195 // Scrollable (cacheable) items first. If we are repainting the
|
Chris@1357
|
2196 // cache, then we paint these to the cache; otherwise straight to
|
Chris@1357
|
2197 // the buffer.
|
Chris@1357
|
2198 QRect areaToPaint;
|
Chris@1357
|
2199 QPainter paint;
|
Chris@1357
|
2200
|
Chris@1357
|
2201 if (shouldRepaintCache) {
|
Chris@1357
|
2202 paint.begin(m_cache);
|
Chris@1357
|
2203 areaToPaint = cacheAreaToRepaint;
|
Chris@1357
|
2204 } else {
|
Chris@1357
|
2205 paint.begin(m_buffer);
|
Chris@1357
|
2206 areaToPaint = requestedPaintArea;
|
Chris@1357
|
2207 }
|
Chris@1357
|
2208
|
Chris@1357
|
2209 setPaintFont(paint);
|
Chris@1357
|
2210 paint.setClipRect(areaToPaint);
|
Chris@1357
|
2211
|
Chris@1357
|
2212 paint.setPen(getBackground());
|
Chris@1357
|
2213 paint.setBrush(getBackground());
|
Chris@1357
|
2214 paint.drawRect(areaToPaint);
|
Chris@1357
|
2215
|
Chris@1357
|
2216 paint.setPen(getForeground());
|
Chris@1357
|
2217 paint.setBrush(Qt::NoBrush);
|
Chris@1357
|
2218
|
Chris@1357
|
2219 for (LayerList::iterator i = scrollables.begin();
|
Chris@1357
|
2220 i != scrollables.end(); ++i) {
|
Chris@1357
|
2221
|
Chris@1357
|
2222 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@1357
|
2223 paint.save();
|
Chris@1357
|
2224
|
Chris@1490
|
2225 Layer *layer = *i;
|
Chris@1490
|
2226
|
Chris@1490
|
2227 bool useAligningProxy = false;
|
Chris@1490
|
2228 if (m_useAligningProxy) {
|
Chris@1490
|
2229 if (layer->getModel() == alignmentReferenceId ||
|
Chris@1490
|
2230 layer->getSourceModel() == alignmentReferenceId) {
|
Chris@1490
|
2231 useAligningProxy = true;
|
Chris@1490
|
2232 }
|
Chris@1490
|
2233 }
|
Chris@1490
|
2234
|
Chris@1357
|
2235 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1490
|
2236 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
|
2237 #endif
|
Chris@1490
|
2238
|
Chris@1490
|
2239 layer->paint(useAligningProxy ? &aligningProxy : &proxy,
|
Chris@1490
|
2240 paint, areaToPaint);
|
Chris@1357
|
2241
|
Chris@1357
|
2242 paint.restore();
|
Chris@1357
|
2243 }
|
Chris@1357
|
2244
|
Chris@1357
|
2245 paint.end();
|
Chris@1357
|
2246
|
Chris@1357
|
2247 if (shouldRepaintCache) {
|
Chris@1357
|
2248 // and now we have
|
Chris@1357
|
2249 m_cacheValid = true;
|
Chris@1266
|
2250 m_cacheCentreFrame = m_centreFrame;
|
Chris@1266
|
2251 m_cacheZoomLevel = m_zoomLevel;
|
Chris@127
|
2252 }
|
Chris@127
|
2253
|
Chris@1357
|
2254 if (shouldUseCache) {
|
Chris@1357
|
2255 paint.begin(m_buffer);
|
Chris@1357
|
2256 paint.drawPixmap(requestedPaintArea, *m_cache, requestedPaintArea);
|
Chris@1266
|
2257 paint.end();
|
Chris@127
|
2258 }
|
Chris@127
|
2259
|
Chris@1357
|
2260 // Now non-cacheable items.
|
Chris@1357
|
2261
|
Chris@952
|
2262 paint.begin(m_buffer);
|
Chris@1357
|
2263 paint.setClipRect(requestedPaintArea);
|
Chris@339
|
2264 setPaintFont(paint);
|
Chris@127
|
2265 if (scrollables.empty()) {
|
Chris@287
|
2266 paint.setPen(getBackground());
|
Chris@287
|
2267 paint.setBrush(getBackground());
|
Chris@1357
|
2268 paint.drawRect(requestedPaintArea);
|
Chris@127
|
2269 }
|
Chris@1266
|
2270
|
Chris@287
|
2271 paint.setPen(getForeground());
|
Chris@127
|
2272 paint.setBrush(Qt::NoBrush);
|
Chris@1266
|
2273
|
Chris@1357
|
2274 for (LayerList::iterator i = nonScrollables.begin();
|
Chris@1357
|
2275 i != nonScrollables.end(); ++i) {
|
Chris@1490
|
2276
|
Chris@1490
|
2277 Layer *layer = *i;
|
Chris@1490
|
2278
|
Chris@1490
|
2279 bool useAligningProxy = false;
|
Chris@1490
|
2280 if (m_useAligningProxy) {
|
Chris@1490
|
2281 if (layer->getModel() == alignmentReferenceId ||
|
Chris@1490
|
2282 layer->getSourceModel() == alignmentReferenceId) {
|
Chris@1490
|
2283 useAligningProxy = true;
|
Chris@1490
|
2284 }
|
Chris@1490
|
2285 }
|
Chris@1490
|
2286
|
Chris@951
|
2287 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1490
|
2288 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
|
2289 #endif
|
Chris@1490
|
2290
|
Chris@1490
|
2291 layer->paint(useAligningProxy ? &aligningProxy : &proxy,
|
Chris@1490
|
2292 paint, requestedPaintArea);
|
Chris@127
|
2293 }
|
Chris@1266
|
2294
|
Chris@127
|
2295 paint.end();
|
Chris@1357
|
2296
|
Chris@1357
|
2297 // Now paint to widget from buffer: target rects from here on,
|
Chris@1357
|
2298 // unlike all the preceding, are at formal (1x) resolution
|
Chris@953
|
2299
|
Chris@953
|
2300 paint.begin(this);
|
Chris@339
|
2301 setPaintFont(paint);
|
Chris@953
|
2302 if (e) paint.setClipRect(e->rect());
|
Chris@1357
|
2303
|
Chris@1357
|
2304 QRect finalPaintRect = e ? e->rect() : rect();
|
Chris@1357
|
2305 paint.drawPixmap(finalPaintRect, *m_buffer,
|
Chris@1357
|
2306 scaledRect(finalPaintRect, dpratio));
|
Chris@1357
|
2307
|
Chris@1357
|
2308 drawSelections(paint);
|
Chris@1357
|
2309 drawPlayPointer(paint);
|
Chris@1357
|
2310
|
Chris@127
|
2311 paint.end();
|
Chris@127
|
2312
|
Chris@127
|
2313 QFrame::paintEvent(e);
|
Chris@127
|
2314 }
|
Chris@127
|
2315
|
Chris@127
|
2316 void
|
Chris@127
|
2317 View::drawSelections(QPainter &paint)
|
Chris@127
|
2318 {
|
Chris@217
|
2319 if (!hasTopLayerTimeXAxis()) return;
|
Chris@217
|
2320
|
Chris@127
|
2321 MultiSelection::SelectionList selections;
|
Chris@127
|
2322
|
Chris@127
|
2323 if (m_manager) {
|
Chris@1266
|
2324 selections = m_manager->getSelections();
|
Chris@1266
|
2325 if (m_manager->haveInProgressSelection()) {
|
Chris@1266
|
2326 bool exclusive;
|
Chris@1266
|
2327 Selection inProgressSelection =
|
Chris@1266
|
2328 m_manager->getInProgressSelection(exclusive);
|
Chris@1266
|
2329 if (exclusive) selections.clear();
|
Chris@1266
|
2330 selections.insert(inProgressSelection);
|
Chris@1266
|
2331 }
|
Chris@127
|
2332 }
|
Chris@127
|
2333
|
Chris@127
|
2334 paint.save();
|
Chris@183
|
2335
|
Chris@183
|
2336 bool translucent = !areLayerColoursSignificant();
|
Chris@183
|
2337
|
Chris@183
|
2338 if (translucent) {
|
Chris@183
|
2339 paint.setBrush(QColor(150, 150, 255, 80));
|
Chris@183
|
2340 } else {
|
Chris@183
|
2341 paint.setBrush(Qt::NoBrush);
|
Chris@183
|
2342 }
|
Chris@127
|
2343
|
Chris@908
|
2344 sv_samplerate_t sampleRate = getModelsSampleRate();
|
Chris@127
|
2345
|
Chris@127
|
2346 QPoint localPos;
|
Chris@908
|
2347 sv_frame_t illuminateFrame = -1;
|
Chris@127
|
2348 bool closeToLeft, closeToRight;
|
Chris@127
|
2349
|
Chris@127
|
2350 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) {
|
Chris@1266
|
2351 illuminateFrame = getFrameForX(localPos.x());
|
Chris@127
|
2352 }
|
Chris@127
|
2353
|
Chris@127
|
2354 const QFontMetrics &metrics = paint.fontMetrics();
|
Chris@127
|
2355
|
Chris@127
|
2356 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@1266
|
2357 i != selections.end(); ++i) {
|
Chris@1266
|
2358
|
Chris@1266
|
2359 int p0 = getXForFrame(alignFromReference(i->getStartFrame()));
|
Chris@1266
|
2360 int p1 = getXForFrame(alignFromReference(i->getEndFrame()));
|
Chris@1266
|
2361
|
Chris@1266
|
2362 if (p1 < 0 || p0 > width()) continue;
|
Chris@127
|
2363
|
Chris@127
|
2364 #ifdef DEBUG_VIEW_WIDGET_PAINT
|
Chris@1266
|
2365 SVDEBUG << "View::drawSelections: " << p0 << ",-1 [" << (p1-p0) << "x" << (height()+1) << "]" << endl;
|
Chris@127
|
2366 #endif
|
Chris@127
|
2367
|
Chris@1266
|
2368 bool illuminateThis =
|
Chris@1266
|
2369 (illuminateFrame >= 0 && i->contains(illuminateFrame));
|
Chris@1266
|
2370
|
Chris@1270
|
2371 double h = height();
|
Chris@1401
|
2372 double penWidth = scalePenWidth(1.0);
|
Chris@1270
|
2373 double half = penWidth/2.0;
|
Chris@1270
|
2374
|
Chris@1270
|
2375 paint.setPen(QPen(QColor(150, 150, 255), penWidth));
|
Chris@183
|
2376
|
Chris@183
|
2377 if (translucent && shouldLabelSelections()) {
|
Chris@1270
|
2378 paint.drawRect(QRectF(p0, -penWidth, p1 - p0, h + 2*penWidth));
|
Chris@183
|
2379 } else {
|
Chris@183
|
2380 // Make the top & bottom lines of the box visible if we
|
Chris@183
|
2381 // are lacking some of the other visual cues. There's no
|
Chris@183
|
2382 // particular logic to this, it's just a question of what
|
Chris@183
|
2383 // I happen to think looks nice.
|
Chris@1270
|
2384 paint.drawRect(QRectF(p0, half, p1 - p0, h - penWidth));
|
Chris@183
|
2385 }
|
Chris@127
|
2386
|
Chris@1266
|
2387 if (illuminateThis) {
|
Chris@1266
|
2388 paint.save();
|
Chris@1401
|
2389 penWidth = scalePenWidth(2.0);
|
Chris@1270
|
2390 half = penWidth/2.0;
|
Chris@1270
|
2391 paint.setPen(QPen(getForeground(), penWidth));
|
Chris@1266
|
2392 if (closeToLeft) {
|
Chris@1270
|
2393 paint.drawLine(QLineF(p0, half, p1, half));
|
Chris@1270
|
2394 paint.drawLine(QLineF(p0, half, p0, h - half));
|
Chris@1270
|
2395 paint.drawLine(QLineF(p0, h - half, p1, h - half));
|
Chris@1266
|
2396 } else if (closeToRight) {
|
Chris@1270
|
2397 paint.drawLine(QLineF(p0, half, p1, half));
|
Chris@1270
|
2398 paint.drawLine(QLineF(p1, half, p1, h - half));
|
Chris@1270
|
2399 paint.drawLine(QLineF(p0, h - half, p1, h - half));
|
Chris@1266
|
2400 } else {
|
Chris@1266
|
2401 paint.setBrush(Qt::NoBrush);
|
Chris@1270
|
2402 paint.drawRect(QRectF(p0, half, p1 - p0, h - penWidth));
|
Chris@1266
|
2403 }
|
Chris@1266
|
2404 paint.restore();
|
Chris@1266
|
2405 }
|
Chris@1266
|
2406
|
Chris@1266
|
2407 if (sampleRate && shouldLabelSelections() && m_manager &&
|
Chris@189
|
2408 m_manager->shouldShowSelectionExtents()) {
|
Chris@1266
|
2409
|
Chris@1266
|
2410 QString startText = QString("%1 / %2")
|
Chris@1266
|
2411 .arg(QString::fromStdString
|
Chris@1266
|
2412 (RealTime::frame2RealTime
|
Chris@1266
|
2413 (i->getStartFrame(), sampleRate).toText(true)))
|
Chris@1266
|
2414 .arg(i->getStartFrame());
|
Chris@1266
|
2415
|
Chris@1266
|
2416 QString endText = QString(" %1 / %2")
|
Chris@1266
|
2417 .arg(QString::fromStdString
|
Chris@1266
|
2418 (RealTime::frame2RealTime
|
Chris@1266
|
2419 (i->getEndFrame(), sampleRate).toText(true)))
|
Chris@1266
|
2420 .arg(i->getEndFrame());
|
Chris@1266
|
2421
|
Chris@1266
|
2422 QString durationText = QString("(%1 / %2) ")
|
Chris@1266
|
2423 .arg(QString::fromStdString
|
Chris@1266
|
2424 (RealTime::frame2RealTime
|
Chris@1266
|
2425 (i->getEndFrame() - i->getStartFrame(), sampleRate)
|
Chris@1266
|
2426 .toText(true)))
|
Chris@1266
|
2427 .arg(i->getEndFrame() - i->getStartFrame());
|
Chris@1476
|
2428
|
Chris@1476
|
2429 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested
|
Chris@1476
|
2430 // replacement (horizontalAdvance) was only added in Qt 5.11
|
Chris@1476
|
2431 // which is too new for us
|
Chris@1476
|
2432 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
Chris@1266
|
2433
|
Chris@1266
|
2434 int sw = metrics.width(startText),
|
Chris@1266
|
2435 ew = metrics.width(endText),
|
Chris@1266
|
2436 dw = metrics.width(durationText);
|
Chris@1266
|
2437
|
Chris@1266
|
2438 int sy = metrics.ascent() + metrics.height() + 4;
|
Chris@1266
|
2439 int ey = sy;
|
Chris@1266
|
2440 int dy = sy + metrics.height();
|
Chris@1266
|
2441
|
Chris@1266
|
2442 int sx = p0 + 2;
|
Chris@1266
|
2443 int ex = sx;
|
Chris@1266
|
2444 int dx = sx;
|
Chris@127
|
2445
|
Chris@501
|
2446 bool durationBothEnds = true;
|
Chris@501
|
2447
|
Chris@1266
|
2448 if (sw + ew > (p1 - p0)) {
|
Chris@1266
|
2449 ey += metrics.height();
|
Chris@1266
|
2450 dy += metrics.height();
|
Chris@501
|
2451 durationBothEnds = false;
|
Chris@1266
|
2452 }
|
Chris@1266
|
2453
|
Chris@1266
|
2454 if (ew < (p1 - p0)) {
|
Chris@1266
|
2455 ex = p1 - 2 - ew;
|
Chris@1266
|
2456 }
|
Chris@1266
|
2457
|
Chris@1266
|
2458 if (dw < (p1 - p0)) {
|
Chris@1266
|
2459 dx = p1 - 2 - dw;
|
Chris@1266
|
2460 }
|
Chris@127
|
2461
|
Chris@1193
|
2462 PaintAssistant::drawVisibleText(this, paint, sx, sy, startText,
|
Chris@1193
|
2463 PaintAssistant::OutlinedText);
|
Chris@1193
|
2464 PaintAssistant::drawVisibleText(this, paint, ex, ey, endText,
|
Chris@1193
|
2465 PaintAssistant::OutlinedText);
|
Chris@1193
|
2466 PaintAssistant::drawVisibleText(this, paint, dx, dy, durationText,
|
Chris@1193
|
2467 PaintAssistant::OutlinedText);
|
Chris@501
|
2468 if (durationBothEnds) {
|
Chris@1193
|
2469 PaintAssistant::drawVisibleText(this, paint, sx, dy, durationText,
|
Chris@1193
|
2470 PaintAssistant::OutlinedText);
|
Chris@501
|
2471 }
|
Chris@1266
|
2472 }
|
Chris@127
|
2473 }
|
Chris@127
|
2474
|
Chris@127
|
2475 paint.restore();
|
Chris@127
|
2476 }
|
Chris@127
|
2477
|
Chris@267
|
2478 void
|
Chris@1357
|
2479 View::drawPlayPointer(QPainter &paint)
|
Chris@1357
|
2480 {
|
Chris@1357
|
2481 bool showPlayPointer = true;
|
Chris@1357
|
2482
|
Chris@1357
|
2483 if (m_followPlay == PlaybackScrollContinuous) {
|
Chris@1357
|
2484 showPlayPointer = false;
|
Chris@1357
|
2485 } else if (m_playPointerFrame <= getStartFrame() ||
|
Chris@1357
|
2486 m_playPointerFrame >= getEndFrame()) {
|
Chris@1357
|
2487 showPlayPointer = false;
|
Chris@1357
|
2488 } else if (m_manager && !m_manager->isPlaying()) {
|
Chris@1357
|
2489 if (m_playPointerFrame == getCentreFrame() &&
|
Chris@1357
|
2490 m_manager->shouldShowCentreLine() &&
|
Chris@1357
|
2491 m_followPlay != PlaybackIgnore) {
|
Chris@1357
|
2492 // Don't show the play pointer when it is redundant with
|
Chris@1357
|
2493 // the centre line
|
Chris@1357
|
2494 showPlayPointer = false;
|
Chris@1357
|
2495 }
|
Chris@1357
|
2496 }
|
Chris@1357
|
2497
|
Chris@1357
|
2498 if (showPlayPointer) {
|
Chris@1357
|
2499
|
Chris@1357
|
2500 int playx = getXForFrame(m_playPointerFrame);
|
Chris@1357
|
2501
|
Chris@1357
|
2502 paint.setPen(getForeground());
|
Chris@1357
|
2503 paint.drawLine(playx - 1, 0, playx - 1, height() - 1);
|
Chris@1357
|
2504 paint.drawLine(playx + 1, 0, playx + 1, height() - 1);
|
Chris@1357
|
2505 paint.drawPoint(playx, 0);
|
Chris@1357
|
2506 paint.drawPoint(playx, height() - 1);
|
Chris@1357
|
2507 paint.setPen(getBackground());
|
Chris@1357
|
2508 paint.drawLine(playx, 1, playx, height() - 2);
|
Chris@1357
|
2509 }
|
Chris@1357
|
2510 }
|
Chris@1357
|
2511
|
Chris@1357
|
2512 void
|
Chris@270
|
2513 View::drawMeasurementRect(QPainter &paint, const Layer *topLayer, QRect r,
|
Chris@270
|
2514 bool focus) const
|
Chris@267
|
2515 {
|
Chris@587
|
2516 // SVDEBUG << "View::drawMeasurementRect(" << r.x() << "," << r.y() << " "
|
Chris@585
|
2517 // << r.width() << "x" << r.height() << ")" << endl;
|
Chris@268
|
2518
|
Chris@267
|
2519 if (r.x() + r.width() < 0 || r.x() >= width()) return;
|
Chris@267
|
2520
|
Chris@270
|
2521 if (r.width() != 0 || r.height() != 0) {
|
Chris@270
|
2522 paint.save();
|
Chris@270
|
2523 if (focus) {
|
Chris@270
|
2524 paint.setPen(Qt::NoPen);
|
Chris@272
|
2525 QColor brushColour(Qt::black);
|
Chris@272
|
2526 brushColour.setAlpha(hasLightBackground() ? 15 : 40);
|
Chris@270
|
2527 paint.setBrush(brushColour);
|
Chris@270
|
2528 if (r.x() > 0) {
|
Chris@270
|
2529 paint.drawRect(0, 0, r.x(), height());
|
Chris@270
|
2530 }
|
Chris@270
|
2531 if (r.x() + r.width() < width()) {
|
Chris@270
|
2532 paint.drawRect(r.x() + r.width(), 0, width()-r.x()-r.width(), height());
|
Chris@270
|
2533 }
|
Chris@270
|
2534 if (r.y() > 0) {
|
Chris@270
|
2535 paint.drawRect(r.x(), 0, r.width(), r.y());
|
Chris@270
|
2536 }
|
Chris@270
|
2537 if (r.y() + r.height() < height()) {
|
Chris@270
|
2538 paint.drawRect(r.x(), r.y() + r.height(), r.width(), height()-r.y()-r.height());
|
Chris@270
|
2539 }
|
Chris@270
|
2540 paint.setBrush(Qt::NoBrush);
|
Chris@270
|
2541 }
|
Chris@270
|
2542 paint.setPen(Qt::green);
|
Chris@270
|
2543 paint.drawRect(r);
|
Chris@270
|
2544 paint.restore();
|
Chris@270
|
2545 } else {
|
Chris@270
|
2546 paint.save();
|
Chris@270
|
2547 paint.setPen(Qt::green);
|
Chris@270
|
2548 paint.drawPoint(r.x(), r.y());
|
Chris@270
|
2549 paint.restore();
|
Chris@270
|
2550 }
|
Chris@270
|
2551
|
Chris@270
|
2552 if (!focus) return;
|
Chris@270
|
2553
|
Chris@278
|
2554 paint.save();
|
Chris@278
|
2555 QFont fn = paint.font();
|
Chris@278
|
2556 if (fn.pointSize() > 8) {
|
Chris@278
|
2557 fn.setPointSize(fn.pointSize() - 1);
|
Chris@278
|
2558 paint.setFont(fn);
|
Chris@278
|
2559 }
|
Chris@278
|
2560
|
Chris@267
|
2561 int fontHeight = paint.fontMetrics().height();
|
Chris@267
|
2562 int fontAscent = paint.fontMetrics().ascent();
|
Chris@267
|
2563
|
Chris@904
|
2564 double v0, v1;
|
Chris@267
|
2565 QString u0, u1;
|
Chris@267
|
2566 bool b0 = false, b1 = false;
|
Chris@267
|
2567
|
Chris@267
|
2568 QString axs, ays, bxs, bys, dxs, dys;
|
Chris@267
|
2569
|
Chris@267
|
2570 int axx, axy, bxx, bxy, dxx, dxy;
|
Chris@267
|
2571 int aw = 0, bw = 0, dw = 0;
|
Chris@267
|
2572
|
Chris@267
|
2573 int labelCount = 0;
|
Chris@267
|
2574
|
Chris@362
|
2575 // top-left point, x-coord
|
Chris@362
|
2576
|
Chris@267
|
2577 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) {
|
Chris@267
|
2578 axs = QString("%1 %2").arg(v0).arg(u0);
|
Chris@278
|
2579 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
|
Chris@278
|
2580 axs = QString("%1 (%2)").arg(axs)
|
Chris@278
|
2581 .arg(Pitch::getPitchLabelForFrequency(v0));
|
Chris@278
|
2582 }
|
Chris@267
|
2583 aw = paint.fontMetrics().width(axs);
|
Chris@267
|
2584 ++labelCount;
|
Chris@267
|
2585 }
|
Chris@362
|
2586
|
Chris@362
|
2587 // bottom-right point, x-coord
|
Chris@267
|
2588
|
Chris@267
|
2589 if (r.width() > 0) {
|
Chris@267
|
2590 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) {
|
Chris@267
|
2591 bxs = QString("%1 %2").arg(v1).arg(u1);
|
Chris@278
|
2592 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
|
Chris@278
|
2593 bxs = QString("%1 (%2)").arg(bxs)
|
Chris@278
|
2594 .arg(Pitch::getPitchLabelForFrequency(v1));
|
Chris@278
|
2595 }
|
Chris@267
|
2596 bw = paint.fontMetrics().width(bxs);
|
Chris@267
|
2597 }
|
Chris@267
|
2598 }
|
Chris@362
|
2599
|
Chris@362
|
2600 // dimension, width
|
Chris@267
|
2601
|
Chris@283
|
2602 if (b0 && b1 && v1 != v0 && u0 == u1) {
|
Chris@362
|
2603 dxs = QString("[%1 %2]").arg(fabs(v1 - v0)).arg(u1);
|
Chris@267
|
2604 dw = paint.fontMetrics().width(dxs);
|
Chris@267
|
2605 }
|
Chris@267
|
2606
|
Chris@267
|
2607 b0 = false;
|
Chris@267
|
2608 b1 = false;
|
Chris@267
|
2609
|
Chris@362
|
2610 // top-left point, y-coord
|
Chris@362
|
2611
|
Chris@267
|
2612 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) {
|
Chris@267
|
2613 ays = QString("%1 %2").arg(v0).arg(u0);
|
Chris@278
|
2614 if (u0 == "Hz" && Pitch::isFrequencyInMidiRange(v0)) {
|
Chris@278
|
2615 ays = QString("%1 (%2)").arg(ays)
|
Chris@278
|
2616 .arg(Pitch::getPitchLabelForFrequency(v0));
|
Chris@278
|
2617 }
|
Chris@267
|
2618 aw = std::max(aw, paint.fontMetrics().width(ays));
|
Chris@267
|
2619 ++labelCount;
|
Chris@267
|
2620 }
|
Chris@267
|
2621
|
Chris@362
|
2622 // bottom-right point, y-coord
|
Chris@362
|
2623
|
Chris@267
|
2624 if (r.height() > 0) {
|
Chris@267
|
2625 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) {
|
Chris@267
|
2626 bys = QString("%1 %2").arg(v1).arg(u1);
|
Chris@278
|
2627 if (u1 == "Hz" && Pitch::isFrequencyInMidiRange(v1)) {
|
Chris@278
|
2628 bys = QString("%1 (%2)").arg(bys)
|
Chris@278
|
2629 .arg(Pitch::getPitchLabelForFrequency(v1));
|
Chris@278
|
2630 }
|
Chris@267
|
2631 bw = std::max(bw, paint.fontMetrics().width(bys));
|
Chris@267
|
2632 }
|
Chris@267
|
2633 }
|
Chris@274
|
2634
|
Chris@274
|
2635 bool bd = false;
|
Chris@904
|
2636 double dy = 0.f;
|
Chris@274
|
2637 QString du;
|
Chris@274
|
2638
|
Chris@362
|
2639 // dimension, height
|
Chris@362
|
2640
|
Chris@274
|
2641 if ((bd = topLayer->getYScaleDifference(this, r.y(), r.y() + r.height(),
|
Chris@283
|
2642 dy, du)) &&
|
Chris@283
|
2643 dy != 0) {
|
Chris@274
|
2644 if (du != "") {
|
Chris@362
|
2645 if (du == "Hz") {
|
Chris@362
|
2646 int semis;
|
Chris@904
|
2647 double cents;
|
Chris@362
|
2648 semis = Pitch::getPitchForFrequencyDifference(v0, v1, ¢s);
|
Chris@362
|
2649 dys = QString("[%1 %2 (%3)]")
|
Chris@362
|
2650 .arg(dy).arg(du)
|
Chris@362
|
2651 .arg(Pitch::getLabelForPitchRange(semis, cents));
|
Chris@362
|
2652 } else {
|
Chris@362
|
2653 dys = QString("[%1 %2]").arg(dy).arg(du);
|
Chris@362
|
2654 }
|
Chris@274
|
2655 } else {
|
Chris@362
|
2656 dys = QString("[%1]").arg(dy);
|
Chris@274
|
2657 }
|
Chris@267
|
2658 dw = std::max(dw, paint.fontMetrics().width(dys));
|
Chris@267
|
2659 }
|
Chris@267
|
2660
|
Chris@267
|
2661 int mw = r.width();
|
Chris@267
|
2662 int mh = r.height();
|
Chris@267
|
2663
|
Chris@267
|
2664 bool edgeLabelsInside = false;
|
Chris@267
|
2665 bool sizeLabelsInside = false;
|
Chris@267
|
2666
|
Chris@267
|
2667 if (mw < std::max(aw, std::max(bw, dw)) + 4) {
|
Chris@267
|
2668 // defaults stand
|
Chris@267
|
2669 } else if (mw < aw + bw + 4) {
|
Chris@267
|
2670 if (mh > fontHeight * labelCount * 3 + 4) {
|
Chris@267
|
2671 edgeLabelsInside = true;
|
Chris@267
|
2672 sizeLabelsInside = true;
|
Chris@267
|
2673 } else if (mh > fontHeight * labelCount * 2 + 4) {
|
Chris@267
|
2674 edgeLabelsInside = true;
|
Chris@267
|
2675 }
|
Chris@267
|
2676 } else if (mw < aw + bw + dw + 4) {
|
Chris@267
|
2677 if (mh > fontHeight * labelCount * 3 + 4) {
|
Chris@267
|
2678 edgeLabelsInside = true;
|
Chris@267
|
2679 sizeLabelsInside = true;
|
Chris@267
|
2680 } else if (mh > fontHeight * labelCount + 4) {
|
Chris@267
|
2681 edgeLabelsInside = true;
|
Chris@267
|
2682 }
|
Chris@267
|
2683 } else {
|
Chris@267
|
2684 if (mh > fontHeight * labelCount + 4) {
|
Chris@267
|
2685 edgeLabelsInside = true;
|
Chris@267
|
2686 sizeLabelsInside = true;
|
Chris@267
|
2687 }
|
Chris@267
|
2688 }
|
Chris@267
|
2689
|
Chris@267
|
2690 if (edgeLabelsInside) {
|
Chris@267
|
2691
|
Chris@267
|
2692 axx = r.x() + 2;
|
Chris@267
|
2693 axy = r.y() + fontAscent + 2;
|
Chris@267
|
2694
|
Chris@267
|
2695 bxx = r.x() + r.width() - bw - 2;
|
Chris@267
|
2696 bxy = r.y() + r.height() - (labelCount-1) * fontHeight - 2;
|
Chris@267
|
2697
|
Chris@267
|
2698 } else {
|
Chris@267
|
2699
|
Chris@267
|
2700 axx = r.x() - aw - 2;
|
Chris@267
|
2701 axy = r.y() + fontAscent;
|
Chris@267
|
2702
|
Chris@267
|
2703 bxx = r.x() + r.width() + 2;
|
Chris@267
|
2704 bxy = r.y() + r.height() - (labelCount-1) * fontHeight;
|
Chris@267
|
2705 }
|
Chris@267
|
2706
|
Chris@267
|
2707 dxx = r.width()/2 + r.x() - dw/2;
|
Chris@267
|
2708
|
Chris@267
|
2709 if (sizeLabelsInside) {
|
Chris@267
|
2710
|
Chris@267
|
2711 dxy = r.height()/2 + r.y() - (labelCount * fontHeight)/2 + fontAscent;
|
Chris@267
|
2712
|
Chris@267
|
2713 } else {
|
Chris@267
|
2714
|
Chris@267
|
2715 dxy = r.y() + r.height() + fontAscent + 2;
|
Chris@267
|
2716 }
|
Chris@267
|
2717
|
Chris@267
|
2718 if (axs != "") {
|
Chris@1078
|
2719 PaintAssistant::drawVisibleText(this, paint, axx, axy, axs, PaintAssistant::OutlinedText);
|
Chris@267
|
2720 axy += fontHeight;
|
Chris@267
|
2721 }
|
Chris@267
|
2722
|
Chris@267
|
2723 if (ays != "") {
|
Chris@1078
|
2724 PaintAssistant::drawVisibleText(this, paint, axx, axy, ays, PaintAssistant::OutlinedText);
|
Chris@267
|
2725 axy += fontHeight;
|
Chris@267
|
2726 }
|
Chris@267
|
2727
|
Chris@267
|
2728 if (bxs != "") {
|
Chris@1078
|
2729 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bxs, PaintAssistant::OutlinedText);
|
Chris@267
|
2730 bxy += fontHeight;
|
Chris@267
|
2731 }
|
Chris@267
|
2732
|
Chris@267
|
2733 if (bys != "") {
|
Chris@1078
|
2734 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bys, PaintAssistant::OutlinedText);
|
Chris@267
|
2735 bxy += fontHeight;
|
Chris@267
|
2736 }
|
Chris@267
|
2737
|
Chris@267
|
2738 if (dxs != "") {
|
Chris@1078
|
2739 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dxs, PaintAssistant::OutlinedText);
|
Chris@267
|
2740 dxy += fontHeight;
|
Chris@267
|
2741 }
|
Chris@267
|
2742
|
Chris@267
|
2743 if (dys != "") {
|
Chris@1078
|
2744 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dys, PaintAssistant::OutlinedText);
|
Chris@267
|
2745 dxy += fontHeight;
|
Chris@267
|
2746 }
|
Chris@278
|
2747
|
Chris@278
|
2748 paint.restore();
|
Chris@267
|
2749 }
|
Chris@267
|
2750
|
Chris@227
|
2751 bool
|
Chris@908
|
2752 View::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1)
|
Chris@227
|
2753 {
|
Chris@1327
|
2754 int x0 = int(round(m_zoomLevel.framesToPixels(double(f0))));
|
Chris@1327
|
2755 int x1 = int(round(m_zoomLevel.framesToPixels(double(f1))));
|
Chris@806
|
2756
|
Chris@806
|
2757 int w = x1 - x0;
|
Chris@806
|
2758
|
Chris@908
|
2759 sv_frame_t origCentreFrame = m_centreFrame;
|
Chris@227
|
2760
|
Chris@227
|
2761 bool someLayersIncomplete = false;
|
Chris@227
|
2762
|
Chris@835
|
2763 for (LayerList::iterator i = m_layerStack.begin();
|
Chris@835
|
2764 i != m_layerStack.end(); ++i) {
|
Chris@227
|
2765
|
Chris@227
|
2766 int c = (*i)->getCompletion(this);
|
Chris@227
|
2767 if (c < 100) {
|
Chris@227
|
2768 someLayersIncomplete = true;
|
Chris@227
|
2769 break;
|
Chris@227
|
2770 }
|
Chris@227
|
2771 }
|
Chris@227
|
2772
|
Chris@227
|
2773 if (someLayersIncomplete) {
|
Chris@227
|
2774
|
Chris@227
|
2775 QProgressDialog progress(tr("Waiting for layers to be ready..."),
|
Chris@227
|
2776 tr("Cancel"), 0, 100, this);
|
Chris@227
|
2777
|
Chris@227
|
2778 int layerCompletion = 0;
|
Chris@227
|
2779
|
Chris@227
|
2780 while (layerCompletion < 100) {
|
Chris@227
|
2781
|
Chris@835
|
2782 for (LayerList::iterator i = m_layerStack.begin();
|
Chris@835
|
2783 i != m_layerStack.end(); ++i) {
|
Chris@227
|
2784
|
Chris@227
|
2785 int c = (*i)->getCompletion(this);
|
Chris@835
|
2786 if (i == m_layerStack.begin() || c < layerCompletion) {
|
Chris@227
|
2787 layerCompletion = c;
|
Chris@227
|
2788 }
|
Chris@227
|
2789 }
|
Chris@227
|
2790
|
Chris@227
|
2791 if (layerCompletion >= 100) break;
|
Chris@227
|
2792
|
Chris@227
|
2793 progress.setValue(layerCompletion);
|
Chris@227
|
2794 qApp->processEvents();
|
Chris@227
|
2795 if (progress.wasCanceled()) {
|
Chris@227
|
2796 update();
|
Chris@227
|
2797 return false;
|
Chris@227
|
2798 }
|
Chris@227
|
2799
|
Chris@227
|
2800 usleep(50000);
|
Chris@227
|
2801 }
|
Chris@227
|
2802 }
|
Chris@227
|
2803
|
Chris@227
|
2804 QProgressDialog progress(tr("Rendering image..."),
|
Chris@227
|
2805 tr("Cancel"), 0, w / width(), this);
|
Chris@227
|
2806
|
Chris@806
|
2807 for (int x = 0; x < w; x += width()) {
|
Chris@227
|
2808
|
Chris@227
|
2809 progress.setValue(x / width());
|
Chris@227
|
2810 qApp->processEvents();
|
Chris@227
|
2811 if (progress.wasCanceled()) {
|
Chris@227
|
2812 m_centreFrame = origCentreFrame;
|
Chris@227
|
2813 update();
|
Chris@227
|
2814 return false;
|
Chris@227
|
2815 }
|
Chris@227
|
2816
|
Chris@1327
|
2817 m_centreFrame = f0 + sv_frame_t(round(m_zoomLevel.pixelsToFrames
|
Chris@1327
|
2818 (x + width()/2)));
|
Chris@227
|
2819
|
Chris@227
|
2820 QRect chunk(0, 0, width(), height());
|
Chris@227
|
2821
|
Chris@287
|
2822 paint.setPen(getBackground());
|
Chris@287
|
2823 paint.setBrush(getBackground());
|
Chris@227
|
2824
|
Chris@1266
|
2825 paint.drawRect(QRect(xorigin + x, 0, width(), height()));
|
Chris@1266
|
2826
|
Chris@1266
|
2827 paint.setPen(getForeground());
|
Chris@1266
|
2828 paint.setBrush(Qt::NoBrush);
|
Chris@1266
|
2829
|
Chris@1266
|
2830 for (LayerList::iterator i = m_layerStack.begin();
|
Chris@835
|
2831 i != m_layerStack.end(); ++i) {
|
Chris@919
|
2832 if (!((*i)->isLayerDormant(this))){
|
Chris@919
|
2833
|
Chris@919
|
2834 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@919
|
2835
|
Chris@919
|
2836 paint.save();
|
Chris@919
|
2837 paint.translate(xorigin + x, 0);
|
Chris@919
|
2838
|
Chris@919
|
2839 cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl;
|
Chris@919
|
2840
|
Chris@919
|
2841 (*i)->setSynchronousPainting(true);
|
Chris@919
|
2842
|
Chris@919
|
2843 (*i)->paint(this, paint, chunk);
|
Chris@919
|
2844
|
Chris@919
|
2845 (*i)->setSynchronousPainting(false);
|
Chris@919
|
2846
|
Chris@919
|
2847 paint.restore();
|
Chris@919
|
2848 }
|
Chris@1266
|
2849 }
|
Chris@227
|
2850 }
|
Chris@227
|
2851
|
Chris@227
|
2852 m_centreFrame = origCentreFrame;
|
Chris@227
|
2853 update();
|
Chris@227
|
2854 return true;
|
Chris@227
|
2855 }
|
Chris@227
|
2856
|
Chris@227
|
2857 QImage *
|
Chris@1202
|
2858 View::renderToNewImage()
|
Chris@227
|
2859 {
|
Chris@908
|
2860 sv_frame_t f0 = getModelsStartFrame();
|
Chris@908
|
2861 sv_frame_t f1 = getModelsEndFrame();
|
Chris@227
|
2862
|
Chris@1202
|
2863 return renderPartToNewImage(f0, f1);
|
Chris@229
|
2864 }
|
Chris@229
|
2865
|
Chris@229
|
2866 QImage *
|
Chris@1202
|
2867 View::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1)
|
Chris@229
|
2868 {
|
Chris@1327
|
2869 int x0 = int(round(getZoomLevel().framesToPixels(double(f0))));
|
Chris@1327
|
2870 int x1 = int(round(getZoomLevel().framesToPixels(double(f1))));
|
Chris@227
|
2871
|
Chris@227
|
2872 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
|
Chris@227
|
2873
|
Chris@227
|
2874 QPainter *paint = new QPainter(image);
|
Chris@229
|
2875 if (!render(*paint, 0, f0, f1)) {
|
Chris@227
|
2876 delete paint;
|
Chris@227
|
2877 delete image;
|
Chris@1408
|
2878 return nullptr;
|
Chris@227
|
2879 } else {
|
Chris@227
|
2880 delete paint;
|
Chris@227
|
2881 return image;
|
Chris@227
|
2882 }
|
Chris@227
|
2883 }
|
Chris@227
|
2884
|
Chris@229
|
2885 QSize
|
Chris@1202
|
2886 View::getRenderedImageSize()
|
Chris@229
|
2887 {
|
Chris@908
|
2888 sv_frame_t f0 = getModelsStartFrame();
|
Chris@908
|
2889 sv_frame_t f1 = getModelsEndFrame();
|
Chris@229
|
2890
|
Chris@1202
|
2891 return getRenderedPartImageSize(f0, f1);
|
Chris@229
|
2892 }
|
Chris@229
|
2893
|
Chris@229
|
2894 QSize
|
Chris@1202
|
2895 View::getRenderedPartImageSize(sv_frame_t f0, sv_frame_t f1)
|
Chris@229
|
2896 {
|
Chris@1327
|
2897 int x0 = int(round(getZoomLevel().framesToPixels(double(f0))));
|
Chris@1327
|
2898 int x1 = int(round(getZoomLevel().framesToPixels(double(f1))));
|
Chris@229
|
2899
|
Chris@229
|
2900 return QSize(x1 - x0, height());
|
Chris@229
|
2901 }
|
Chris@229
|
2902
|
Chris@1202
|
2903 bool
|
Chris@1202
|
2904 View::renderToSvgFile(QString filename)
|
Chris@1202
|
2905 {
|
Chris@1202
|
2906 sv_frame_t f0 = getModelsStartFrame();
|
Chris@1202
|
2907 sv_frame_t f1 = getModelsEndFrame();
|
Chris@1202
|
2908
|
Chris@1202
|
2909 return renderPartToSvgFile(filename, f0, f1);
|
Chris@1202
|
2910 }
|
Chris@1202
|
2911
|
Chris@1202
|
2912 bool
|
Chris@1202
|
2913 View::renderPartToSvgFile(QString filename, sv_frame_t f0, sv_frame_t f1)
|
Chris@1202
|
2914 {
|
Chris@1327
|
2915 int x0 = int(round(getZoomLevel().framesToPixels(double(f0))));
|
Chris@1327
|
2916 int x1 = int(round(getZoomLevel().framesToPixels(double(f1))));
|
Chris@1202
|
2917
|
Chris@1202
|
2918 QSvgGenerator generator;
|
Chris@1202
|
2919 generator.setFileName(filename);
|
Chris@1202
|
2920 generator.setSize(QSize(x1 - x0, height()));
|
Chris@1202
|
2921 generator.setViewBox(QRect(0, 0, x1 - x0, height()));
|
Chris@1202
|
2922 generator.setTitle(tr("Exported image from %1")
|
Chris@1202
|
2923 .arg(QApplication::applicationName()));
|
Chris@1202
|
2924
|
Chris@1202
|
2925 QPainter paint;
|
Chris@1202
|
2926 paint.begin(&generator);
|
Chris@1202
|
2927 bool result = render(paint, 0, f0, f1);
|
Chris@1202
|
2928 paint.end();
|
Chris@1202
|
2929 return result;
|
Chris@1202
|
2930 }
|
Chris@1202
|
2931
|
Chris@316
|
2932 void
|
Chris@316
|
2933 View::toXml(QTextStream &stream,
|
Chris@316
|
2934 QString indent, QString extraAttributes) const
|
Chris@127
|
2935 {
|
Chris@316
|
2936 stream << indent;
|
Chris@127
|
2937
|
Chris@1327
|
2938 int classicZoomValue, deepZoomValue;
|
Chris@1327
|
2939
|
Chris@1327
|
2940 if (m_zoomLevel.zone == ZoomLevel::FramesPerPixel) {
|
Chris@1327
|
2941 classicZoomValue = m_zoomLevel.level;
|
Chris@1327
|
2942 deepZoomValue = 1;
|
Chris@1327
|
2943 } else {
|
Chris@1327
|
2944 classicZoomValue = 1;
|
Chris@1327
|
2945 deepZoomValue = m_zoomLevel.level;
|
Chris@1327
|
2946 }
|
Chris@1327
|
2947
|
Chris@316
|
2948 stream << QString("<view "
|
Chris@316
|
2949 "centre=\"%1\" "
|
Chris@316
|
2950 "zoom=\"%2\" "
|
Chris@1327
|
2951 "deepZoom=\"%3\" "
|
Chris@1327
|
2952 "followPan=\"%4\" "
|
Chris@1327
|
2953 "followZoom=\"%5\" "
|
Chris@1327
|
2954 "tracking=\"%6\" "
|
Chris@1331
|
2955 " %7>\n")
|
Chris@1266
|
2956 .arg(m_centreFrame)
|
Chris@1327
|
2957 .arg(classicZoomValue)
|
Chris@1327
|
2958 .arg(deepZoomValue)
|
Chris@1266
|
2959 .arg(m_followPan)
|
Chris@1266
|
2960 .arg(m_followZoom)
|
Chris@1266
|
2961 .arg(m_followPlay == PlaybackScrollContinuous ? "scroll" :
|
Chris@1266
|
2962 m_followPlay == PlaybackScrollPageWithCentre ? "page" :
|
Chris@1266
|
2963 m_followPlay == PlaybackScrollPage ? "daw" :
|
Chris@815
|
2964 "ignore")
|
Chris@1266
|
2965 .arg(extraAttributes);
|
Chris@127
|
2966
|
Chris@838
|
2967 for (int i = 0; i < (int)m_fixedOrderLayers.size(); ++i) {
|
Chris@838
|
2968 bool visible = !m_fixedOrderLayers[i]->isLayerDormant(this);
|
Chris@838
|
2969 m_fixedOrderLayers[i]->toBriefXml(stream, indent + " ",
|
Chris@838
|
2970 QString("visible=\"%1\"")
|
Chris@838
|
2971 .arg(visible ? "true" : "false"));
|
Chris@127
|
2972 }
|
Chris@127
|
2973
|
Chris@316
|
2974 stream << indent + "</view>\n";
|
Chris@127
|
2975 }
|
Chris@127
|
2976
|
Chris@127
|
2977 ViewPropertyContainer::ViewPropertyContainer(View *v) :
|
Chris@127
|
2978 m_v(v)
|
Chris@127
|
2979 {
|
Chris@1495
|
2980 // cerr << "ViewPropertyContainer: " << getId() << " is owned by View " << v << endl;
|
Chris@127
|
2981 connect(m_v, SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@1266
|
2982 this, SIGNAL(propertyChanged(PropertyContainer::PropertyName)));
|
Chris@127
|
2983 }
|
Chris@127
|
2984
|
Chris@728
|
2985 ViewPropertyContainer::~ViewPropertyContainer()
|
Chris@728
|
2986 {
|
Chris@728
|
2987 }
|