comparison view/View.h @ 1045:f535f6e5dbb0 alignment-simple

Merge in from SV 3.0-integration branches
author Chris Cannam
date Wed, 02 Mar 2016 17:25:27 +0000
parents 36cddc3de023 4e5c1c326794
children 5144d7185fb5
comparison
equal deleted inserted replaced
976:f2c63ec85901 1045:f535f6e5dbb0
17 #define _VIEW_H_ 17 #define _VIEW_H_
18 18
19 #include <QFrame> 19 #include <QFrame>
20 #include <QProgressBar> 20 #include <QProgressBar>
21 21
22 #include "LayerGeometryProvider.h"
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"
26 #include "base/BaseTypes.h" 28 #include "base/BaseTypes.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
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 268
252 virtual void drawVisibleText(QPainter &p, int x, int y, 269 virtual void drawVisibleText(QPainter &p, int x, int y,
253 QString text, TextStyle style) const; 270 QString text, TextStyle style) const;
254 271
255 virtual void drawMeasurementRect(QPainter &p, const Layer *, 272 virtual void drawMeasurementRect(QPainter &p, const Layer *,
313 virtual sv_frame_t getLastVisibleFrame() const; 330 virtual sv_frame_t getLastVisibleFrame() const;
314 331
315 sv_frame_t getModelsStartFrame() const; 332 sv_frame_t getModelsStartFrame() const;
316 sv_frame_t getModelsEndFrame() const; 333 sv_frame_t getModelsEndFrame() const;
317 334
335 /**
336 * To be called from a layer, to obtain the extent of the surface
337 * that the layer is currently painting to. This may be the extent
338 * of the view (if 1x display scaling is in effect) or of a larger
339 * cached pixmap (if greater display scaling is in effect).
340 */
341 QRect getPaintRect() const;
342
343 QSize getPaintSize() const { return getPaintRect().size(); }
344 int getPaintWidth() const { return getPaintRect().width(); }
345 int getPaintHeight() const { return getPaintRect().height(); }
346
318 typedef std::set<Model *> ModelSet; 347 typedef std::set<Model *> ModelSet;
319 ModelSet getModels(); 348 ModelSet getModels();
320 349
321 //!!! 350 //!!!
322 Model *getAligningModel() const; 351 Model *getAligningModel() const;
323 sv_frame_t alignFromReference(sv_frame_t) const; 352 sv_frame_t alignFromReference(sv_frame_t) const;
324 sv_frame_t alignToReference(sv_frame_t) const; 353 sv_frame_t alignToReference(sv_frame_t) const;
325 sv_frame_t getAlignedPlaybackFrame() const; 354 sv_frame_t getAlignedPlaybackFrame() const;
326 355
356 void updatePaintRect(QRect r) { update(r); }
357
358 View *getView() { return this; }
359 const View *getView() const { return this; }
360
327 signals: 361 signals:
328 void propertyContainerAdded(PropertyContainer *pc); 362 void propertyContainerAdded(PropertyContainer *pc);
329 void propertyContainerRemoved(PropertyContainer *pc); 363 void propertyContainerRemoved(PropertyContainer *pc);
330 void propertyContainerPropertyChanged(PropertyContainer *pc); 364 void propertyContainerPropertyChanged(PropertyContainer *pc);
331 void propertyContainerPropertyRangeChanged(PropertyContainer *pc); 365 void propertyContainerPropertyRangeChanged(PropertyContainer *pc);
370 404
371 virtual void progressCheckStalledTimerElapsed(); 405 virtual void progressCheckStalledTimerElapsed();
372 406
373 protected: 407 protected:
374 View(QWidget *, bool showProgress); 408 View(QWidget *, bool showProgress);
409
410 int m_id;
411
375 virtual void paintEvent(QPaintEvent *e); 412 virtual void paintEvent(QPaintEvent *e);
376 virtual void drawSelections(QPainter &); 413 virtual void drawSelections(QPainter &);
377 virtual bool shouldLabelSelections() const { return true; } 414 virtual bool shouldLabelSelections() const { return true; }
378 virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1); 415 virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1);
379 virtual void setPaintFont(QPainter &paint); 416 virtual void setPaintFont(QPainter &paint);
417
418 QSize scaledSize(const QSize &s, int factor) {
419 return QSize(s.width() * factor, s.height() * factor);
420 }
421 QRect scaledRect(const QRect &r, int factor) {
422 return QRect(r.x() * factor, r.y() * factor,
423 r.width() * factor, r.height() * factor);
424 }
380 425
381 typedef std::vector<Layer *> LayerList; 426 typedef std::vector<Layer *> LayerList;
382 427
383 sv_samplerate_t getModelsSampleRate() const; 428 sv_samplerate_t getModelsSampleRate() const;
384 bool areLayersScrollable() const; 429 bool areLayersScrollable() const;
403 448
404 void movePlayPointer(sv_frame_t f); 449 void movePlayPointer(sv_frame_t f);
405 450
406 void checkProgress(void *object); 451 void checkProgress(void *object);
407 int getProgressBarWidth() const; // if visible 452 int getProgressBarWidth() const; // if visible
453
454 int effectiveDevicePixelRatio() const;
408 455
409 sv_frame_t m_centreFrame; 456 sv_frame_t m_centreFrame;
410 int m_zoomLevel; 457 int m_zoomLevel;
411 bool m_followPan; 458 bool m_followPan;
412 bool m_followZoom; 459 bool m_followZoom;
415 sv_frame_t m_playPointerFrame; 462 sv_frame_t m_playPointerFrame;
416 bool m_lightBackground; 463 bool m_lightBackground;
417 bool m_showProgress; 464 bool m_showProgress;
418 465
419 QPixmap *m_cache; 466 QPixmap *m_cache;
467 QPixmap *m_buffer;
420 sv_frame_t m_cacheCentreFrame; 468 sv_frame_t m_cacheCentreFrame;
421 int m_cacheZoomLevel; 469 int m_cacheZoomLevel;
422 bool m_selectionCached; 470 bool m_selectionCached;
423 471
424 bool m_deleting; 472 bool m_deleting;