comparison view/View.h @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents c603aba61702
children 37f86e26a8d2
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
16 #ifndef _VIEW_H_ 16 #ifndef _VIEW_H_
17 #define _VIEW_H_ 17 #define _VIEW_H_
18 18
19 #include <QFrame> 19 #include <QFrame>
20 #include <QProgressBar> 20 #include <QProgressBar>
21
22 #include "layer/LayerGeometryProvider.h"
21 23
22 #include "base/ZoomConstraint.h" 24 #include "base/ZoomConstraint.h"
23 #include "base/PropertyContainer.h" 25 #include "base/PropertyContainer.h"
24 #include "ViewManager.h" 26 #include "ViewManager.h"
25 #include "base/XmlExportable.h" 27 #include "base/XmlExportable.h"
47 * mechanisms for doing so (as well as any other operations and 49 * mechanisms for doing so (as well as any other operations and
48 * properties available) depend on the subclass. 50 * properties available) depend on the subclass.
49 */ 51 */
50 52
51 class View : public QFrame, 53 class View : public QFrame,
52 public XmlExportable 54 public XmlExportable,
55 public LayerGeometryProvider
53 { 56 {
54 Q_OBJECT 57 Q_OBJECT
55 58
56 public: 59 public:
57 /** 60 /**
58 * Deleting a View does not delete any of its layers. They should 61 * Deleting a View does not delete any of its layers. They should
59 * be managed elsewhere (e.g. by the Document). 62 * be managed elsewhere (e.g. by the Document).
60 */ 63 */
61 virtual ~View(); 64 virtual ~View();
62 65
66 /**
67 * Retrieve the id of this object. Views have their own unique
68 * ids, but ViewProxy objects share the id of their View.
69 */
70 int getId() const { return m_id; }
71
63 /** 72 /**
64 * Retrieve the first visible sample frame on the widget. 73 * Retrieve the first visible sample frame on the widget.
65 * This is a calculated value based on the centre-frame, widget 74 * This is a calculated value based on the centre-frame, widget
66 * width and zoom level. The result may be negative. 75 * width and zoom level. The result may be negative.
67 */ 76 */
101 110
102 /** 111 /**
103 * Return the closest frame to the given pixel x-coordinate. 112 * Return the closest frame to the given pixel x-coordinate.
104 */ 113 */
105 sv_frame_t getFrameForX(int x) const; 114 sv_frame_t getFrameForX(int x) const;
115
116 /**
117 * Return the closest pixel x-coordinate corresponding to a given
118 * view x-coordinate. Default is no scaling, ViewProxy handles
119 * scaling case.
120 */
121 int getXForViewX(int viewx) const { return viewx; }
122
123 /**
124 * Return the closest view x-coordinate corresponding to a given
125 * pixel x-coordinate. Default is no scaling, ViewProxy handles
126 * scaling case.
127 */
128 int getViewXForX(int x) const { return x; }
106 129
107 /** 130 /**
108 * Return the pixel y-coordinate corresponding to a given 131 * Return the pixel y-coordinate corresponding to a given
109 * frequency, if the frequency range is as specified. This does 132 * frequency, if the frequency range is as specified. This does
110 * not imply any policy about layer frequency ranges, but it might 133 * not imply any policy about layer frequency ranges, but it might
119 * Return the closest frequency to the given pixel y-coordinate, 142 * Return the closest frequency to the given pixel y-coordinate,
120 * if the frequency range is as specified. 143 * if the frequency range is as specified.
121 * 144 *
122 * Not thread-safe in logarithmic mode. Call only from GUI thread. 145 * Not thread-safe in logarithmic mode. Call only from GUI thread.
123 */ 146 */
124 double getFrequencyForY(int y, double minFreq, double maxFreq, 147 double getFrequencyForY(double y, double minFreq, double maxFreq,
125 bool logarithmic) const; 148 bool logarithmic) const;
126 149
127 /** 150 /**
128 * Return the zoom level, i.e. the number of frames per pixel 151 * Return the zoom level, i.e. the number of frames per pixel
129 */ 152 */
130 int getZoomLevel() const; 153 int getZoomLevel() const;
240 virtual bool getFollowGlobalZoom() const { return m_followZoom; } 263 virtual bool getFollowGlobalZoom() const { return m_followZoom; }
241 264
242 virtual bool hasLightBackground() const; 265 virtual bool hasLightBackground() const;
243 virtual QColor getForeground() const; 266 virtual QColor getForeground() const;
244 virtual QColor getBackground() const; 267 virtual QColor getBackground() const;
245
246 enum TextStyle {
247 BoxedText,
248 OutlinedText,
249 OutlinedItalicText
250 };
251
252 virtual void drawVisibleText(QPainter &p, int x, int y,
253 QString text, TextStyle style) const;
254 268
255 virtual void drawMeasurementRect(QPainter &p, const Layer *, 269 virtual void drawMeasurementRect(QPainter &p, const Layer *,
256 QRect rect, bool focus) const; 270 QRect rect, bool focus) const;
257 271
258 virtual bool shouldShowFeatureLabels() const { 272 virtual bool shouldShowFeatureLabels() const {
292 // The 0th property container is the view's own; the rest are the 306 // The 0th property container is the view's own; the rest are the
293 // layers in fixed-order series 307 // layers in fixed-order series
294 virtual const PropertyContainer *getPropertyContainer(int i) const; 308 virtual const PropertyContainer *getPropertyContainer(int i) const;
295 virtual PropertyContainer *getPropertyContainer(int i); 309 virtual PropertyContainer *getPropertyContainer(int i);
296 310
297 // Render the contents on a wide canvas 311 /**
298 virtual QImage *toNewImage(sv_frame_t f0, sv_frame_t f1); 312 * Render the view contents to a new QImage (which may be wider
299 virtual QImage *toNewImage(); 313 * than the visible View).
300 virtual QSize getImageSize(sv_frame_t f0, sv_frame_t f1); 314 */
301 virtual QSize getImageSize(); 315 virtual QImage *renderToNewImage();
302 316
317 /**
318 * Render the view contents between the given frame extents to a
319 * new QImage (which may be wider than the visible View).
320 */
321 virtual QImage *renderPartToNewImage(sv_frame_t f0, sv_frame_t f1);
322
323 /**
324 * Calculate and return the size of image that will be generated
325 * by renderToNewImage().
326 */
327 virtual QSize getRenderedImageSize();
328
329 /**
330 * Calculate and return the size of image that will be generated
331 * by renderPartToNewImage(f0, f1).
332 */
333 virtual QSize getRenderedPartImageSize(sv_frame_t f0, sv_frame_t f1);
334
335 /**
336 * Render the view contents to a new SVG file.
337 */
338 virtual bool renderToSvgFile(QString filename);
339
340 /**
341 * Render the view contents between the given frame extents to a
342 * new SVG file.
343 */
344 virtual bool renderPartToSvgFile(QString filename,
345 sv_frame_t f0, sv_frame_t f1);
346
303 virtual int getTextLabelHeight(const Layer *layer, QPainter &) const; 347 virtual int getTextLabelHeight(const Layer *layer, QPainter &) const;
304 348
305 virtual bool getValueExtents(QString unit, double &min, double &max, 349 virtual bool getValueExtents(QString unit, double &min, double &max,
306 bool &log) const; 350 bool &log) const;
307 351
312 virtual sv_frame_t getFirstVisibleFrame() const; 356 virtual sv_frame_t getFirstVisibleFrame() const;
313 virtual sv_frame_t getLastVisibleFrame() const; 357 virtual sv_frame_t getLastVisibleFrame() const;
314 358
315 sv_frame_t getModelsStartFrame() const; 359 sv_frame_t getModelsStartFrame() const;
316 sv_frame_t getModelsEndFrame() const; 360 sv_frame_t getModelsEndFrame() const;
361
362 /**
363 * To be called from a layer, to obtain the extent of the surface
364 * that the layer is currently painting to. This may be the extent
365 * of the view (if 1x display scaling is in effect) or of a larger
366 * cached pixmap (if greater display scaling is in effect).
367 */
368 QRect getPaintRect() const;
369
370 QSize getPaintSize() const { return getPaintRect().size(); }
371 int getPaintWidth() const { return getPaintRect().width(); }
372 int getPaintHeight() const { return getPaintRect().height(); }
317 373
318 typedef std::set<Model *> ModelSet; 374 typedef std::set<Model *> ModelSet;
319 ModelSet getModels(); 375 ModelSet getModels();
320 376
321 //!!! 377 //!!!
322 Model *getAligningModel() const; 378 Model *getAligningModel() const;
323 sv_frame_t alignFromReference(sv_frame_t) const; 379 sv_frame_t alignFromReference(sv_frame_t) const;
324 sv_frame_t alignToReference(sv_frame_t) const; 380 sv_frame_t alignToReference(sv_frame_t) const;
325 sv_frame_t getAlignedPlaybackFrame() const; 381 sv_frame_t getAlignedPlaybackFrame() const;
326 382
383 void updatePaintRect(QRect r) { update(r); }
384
385 View *getView() { return this; }
386 const View *getView() const { return this; }
387
327 signals: 388 signals:
328 void propertyContainerAdded(PropertyContainer *pc); 389 void propertyContainerAdded(PropertyContainer *pc);
329 void propertyContainerRemoved(PropertyContainer *pc); 390 void propertyContainerRemoved(PropertyContainer *pc);
330 void propertyContainerPropertyChanged(PropertyContainer *pc); 391 void propertyContainerPropertyChanged(PropertyContainer *pc);
331 void propertyContainerPropertyRangeChanged(PropertyContainer *pc); 392 void propertyContainerPropertyRangeChanged(PropertyContainer *pc);
337 398
338 void centreFrameChanged(sv_frame_t frame, 399 void centreFrameChanged(sv_frame_t frame,
339 bool globalScroll, 400 bool globalScroll,
340 PlaybackFollowMode followMode); 401 PlaybackFollowMode followMode);
341 402
342 void zoomLevelChanged(int, bool); 403 void zoomLevelChanged(int level, bool locked);
343 404
344 void contextHelpChanged(const QString &); 405 void contextHelpChanged(const QString &);
345 406
346 public slots: 407 public slots:
347 virtual void modelChanged(); 408 virtual void modelChanged();
370 431
371 virtual void progressCheckStalledTimerElapsed(); 432 virtual void progressCheckStalledTimerElapsed();
372 433
373 protected: 434 protected:
374 View(QWidget *, bool showProgress); 435 View(QWidget *, bool showProgress);
436
437 int m_id;
438
375 virtual void paintEvent(QPaintEvent *e); 439 virtual void paintEvent(QPaintEvent *e);
376 virtual void drawSelections(QPainter &); 440 virtual void drawSelections(QPainter &);
377 virtual bool shouldLabelSelections() const { return true; } 441 virtual bool shouldLabelSelections() const { return true; }
378 virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1); 442 virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1);
379 virtual void setPaintFont(QPainter &paint); 443 virtual void setPaintFont(QPainter &paint);
444
445 QSize scaledSize(const QSize &s, int factor) {
446 return QSize(s.width() * factor, s.height() * factor);
447 }
448 QRect scaledRect(const QRect &r, int factor) {
449 return QRect(r.x() * factor, r.y() * factor,
450 r.width() * factor, r.height() * factor);
451 }
380 452
381 typedef std::vector<Layer *> LayerList; 453 typedef std::vector<Layer *> LayerList;
382 454
383 sv_samplerate_t getModelsSampleRate() const; 455 sv_samplerate_t getModelsSampleRate() const;
384 bool areLayersScrollable() const; 456 bool areLayersScrollable() const;
403 475
404 void movePlayPointer(sv_frame_t f); 476 void movePlayPointer(sv_frame_t f);
405 477
406 void checkProgress(void *object); 478 void checkProgress(void *object);
407 int getProgressBarWidth() const; // if visible 479 int getProgressBarWidth() const; // if visible
480
481 int effectiveDevicePixelRatio() const;
408 482
409 sv_frame_t m_centreFrame; 483 sv_frame_t m_centreFrame;
410 int m_zoomLevel; 484 int m_zoomLevel;
411 bool m_followPan; 485 bool m_followPan;
412 bool m_followZoom; 486 bool m_followZoom;
414 bool m_followPlayIsDetached; 488 bool m_followPlayIsDetached;
415 sv_frame_t m_playPointerFrame; 489 sv_frame_t m_playPointerFrame;
416 bool m_lightBackground; 490 bool m_lightBackground;
417 bool m_showProgress; 491 bool m_showProgress;
418 492
419 QPixmap *m_cache; 493 QPixmap *m_cache; // I own this
494 QPixmap *m_buffer; // I own this
420 sv_frame_t m_cacheCentreFrame; 495 sv_frame_t m_cacheCentreFrame;
421 int m_cacheZoomLevel; 496 int m_cacheZoomLevel;
422 bool m_selectionCached; 497 bool m_selectionCached;
423 498
424 bool m_deleting; 499 bool m_deleting;