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