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