ViewProxy.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef VIEW_PROXY_H
16 #define VIEW_PROXY_H
17 
19 
20 #include "data/model/AlignmentModel.h"
21 
23 {
24 public:
30  ViewProxy(View *view, int scaleFactor) :
31  m_view(view), m_scaleFactor(scaleFactor) { }
32 
49  ViewProxy(View *view, int scaleFactor, ModelId alignment) :
50  m_view(view), m_scaleFactor(scaleFactor), m_alignment(alignment) { }
51 
52  int getId() const override {
53  return m_view->getId();
54  }
55  sv_frame_t getStartFrame() const override {
57  }
58  sv_frame_t getCentreFrame() const override {
60  }
61  sv_frame_t getEndFrame() const override {
63  }
64  int getXForFrame(sv_frame_t frame) const override {
67  }
68  sv_frame_t getFrameForX(int x) const override {
69  sv_frame_t f0 = m_view->getFrameForX(x / m_scaleFactor);
70  if (m_scaleFactor == 1) return alignToReference(f0);
71  sv_frame_t f1 = m_view->getFrameForX((x / m_scaleFactor) + 1);
72  sv_frame_t f = f0 + ((f1 - f0) * (x % m_scaleFactor)) / m_scaleFactor;
73  return alignToReference(f);
74  }
75  int getXForViewX(int viewx) const override {
76  return viewx * m_scaleFactor;
77  }
78  int getViewXForX(int x) const override {
79  return x / m_scaleFactor;
80  }
81  sv_frame_t getModelsStartFrame() const override {
83  }
84  sv_frame_t getModelsEndFrame() const override {
86  }
87  double getYForFrequency(double frequency,
88  double minFreq, double maxFreq,
89  bool logarithmic) const override {
90  return m_scaleFactor *
91  m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic);
92  }
93  double getFrequencyForY(double y, double minFreq, double maxFreq,
94  bool logarithmic) const override {
95  return m_view->getFrequencyForY
96  (y / m_scaleFactor, minFreq, maxFreq, logarithmic);
97  }
98  int getTextLabelYCoord(const Layer *layer, QPainter &paint) const override {
99  return m_scaleFactor * m_view->getTextLabelYCoord(layer, paint);
100  }
101  bool getVisibleExtentsForUnit(QString unit, double &min, double &max,
102  bool &log) const override {
103  return m_view->getVisibleExtentsForUnit(unit, min, max, log);
104  }
105  ZoomLevel getZoomLevel() const override {
106  ZoomLevel z = m_view->getZoomLevel();
107  if (z.zone == ZoomLevel::FramesPerPixel) {
108  z.level /= m_scaleFactor;
109  if (z.level < 1) {
110  z.level = 1;
111  }
112  } else {
113  z.level *= m_scaleFactor;
114  }
115  return z;
116  }
117  QRect getPaintRect() const override {
118  QRect r = m_view->getPaintRect();
119  return QRect(r.x() * m_scaleFactor,
120  r.y() * m_scaleFactor,
121  r.width() * m_scaleFactor,
122  r.height() * m_scaleFactor);
123  }
124  QSize getPaintSize() const override {
125  return getPaintRect().size();
126  }
127  int getPaintWidth() const override {
128  return getPaintRect().width();
129  }
130  int getPaintHeight() const override {
131  return getPaintRect().height();
132  }
133  bool hasLightBackground() const override {
134  return m_view->hasLightBackground();
135  }
136  QColor getForeground() const override {
137  return m_view->getForeground();
138  }
139  QColor getBackground() const override {
140  return m_view->getBackground();
141  }
142  ViewManager *getViewManager() const override {
143  return m_view->getViewManager();
144  }
145 
147  QPoint &point) const override {
148  QPoint p;
149  bool should = m_view->shouldIlluminateLocalFeatures(layer, p);
150  point = QPoint(p.x() * m_scaleFactor, p.y() * m_scaleFactor);
151  return should;
152  }
153 
154  bool shouldShowFeatureLabels() const override {
156  }
157 
158  void drawMeasurementRect(QPainter &p, const Layer *layer,
159  QRect rect, bool focus) const override {
160  m_view->drawMeasurementRect(p, layer, rect, focus);
161  }
162 
163  void updatePaintRect(QRect r) override {
164  m_view->update(r.x() / m_scaleFactor,
165  r.y() / m_scaleFactor,
166  r.width() / m_scaleFactor,
167  r.height() / m_scaleFactor);
168  }
169 
177  double scaleSize(double size) const override {
178  return m_view->scaleSize(size * m_scaleFactor);
179  }
180 
184  int scalePixelSize(int size) const override {
185  return m_view->scalePixelSize(size * m_scaleFactor);
186  }
187 
193  double scalePenWidth(double width) const override {
194  if (width <= 0) { // zero-width pen, produce a scaled one-pixel pen
195  width = 1;
196  }
197  width *= sqrt(double(m_scaleFactor));
198  return m_view->scalePenWidth(width);
199  }
200 
204  QPen scalePen(QPen pen) const override {
205  return QPen(pen.color(), scalePenWidth(pen.width()));
206  }
207 
208  View *getView() override { return m_view; }
209  const View *getView() const override { return m_view; }
210 
211 private:
214  ModelId m_alignment;
215 
216  sv_frame_t alignToReference(sv_frame_t frame) const {
217  if (auto am = ModelById::getAs<AlignmentModel>(m_alignment)) {
218  return am->toReference(frame);
219  } else {
220  return frame;
221  }
222  }
223 
224  sv_frame_t alignFromReference(sv_frame_t frame) const {
225  if (auto am = ModelById::getAs<AlignmentModel>(m_alignment)) {
226  return am->fromReference(frame);
227  } else {
228  return frame;
229  }
230  }
231 };
232 
233 #endif
const View * getView() const override
Definition: ViewProxy.h:209
ViewManager * getViewManager() const override
Definition: ViewProxy.h:142
int m_scaleFactor
Definition: ViewProxy.h:213
The base class for visual representations of the data found in a Model.
Definition: Layer.h:54
double getYForFrequency(double frequency, double minFreq, double maxFreq, bool logarithmic) const override
Return the (maybe fractional) pixel y-coordinate corresponding to a given frequency, if the frequency range is as specified.
Definition: ViewProxy.h:87
sv_frame_t alignToReference(sv_frame_t frame) const
Definition: ViewProxy.h:216
View * m_view
Definition: ViewProxy.h:212
int scalePixelSize(int size) const override
Definition: View.cpp:1834
int getId() const override
Retrieve the id of this object.
Definition: View.h:72
void drawMeasurementRect(QPainter &p, const Layer *layer, QRect rect, bool focus) const override
Definition: ViewProxy.h:158
bool getVisibleExtentsForUnit(QString unit, double &min, double &max, bool &log) const override
Return the visible vertical extents for the given unit, if any.
Definition: View.cpp:197
double getFrequencyForY(double y, double minFreq, double maxFreq, bool logarithmic) const override
Return the closest frequency to the given pixel y-coordinate, if the frequency range is as specified...
Definition: View.cpp:700
int getXForFrame(sv_frame_t frame) const override
Return the pixel x-coordinate corresponding to a given sample frame (which may be negative)...
Definition: ViewProxy.h:64
sv_frame_t getFrameForX(int x) const override
Return the closest frame to the given pixel x-coordinate.
Definition: ViewProxy.h:68
double scalePenWidth(double width) const override
Definition: View.cpp:1843
sv_frame_t getCentreFrame() const override
Return the centre frame of the visible widget.
Definition: View.h:93
QColor getForeground() const override
Definition: View.cpp:824
QColor getBackground() const override
Definition: ViewProxy.h:139
double scaleSize(double size) const override
Scale up a size in pixels for a hi-dpi display without pixel doubling.
Definition: ViewProxy.h:177
ModelId m_alignment
Definition: ViewProxy.h:214
QPen scalePen(QPen pen) const override
Apply scalePenWidth to a pen.
Definition: ViewProxy.h:204
ViewProxy(View *view, int scaleFactor, ModelId alignment)
Create a re-aligning ViewProxy for the given view, mapping using the given scale factor.
Definition: ViewProxy.h:49
sv_frame_t alignFromReference(sv_frame_t frame) const
Definition: ViewProxy.h:224
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
bool shouldIlluminateLocalFeatures(const Layer *layer, QPoint &point) const override
Definition: ViewProxy.h:146
bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const override
Definition: View.h:282
sv_frame_t getEndFrame() const override
Retrieve the last visible sample frame on the widget.
Definition: ViewProxy.h:61
sv_frame_t getFrameForX(int x) const override
Return the closest frame to the given pixel x-coordinate.
Definition: View.cpp:600
ZoomLevel getZoomLevel() const override
Return the zoom level, i.e.
Definition: View.cpp:732
QColor getBackground() const override
Definition: View.cpp:804
sv_frame_t getModelsEndFrame() const override
Definition: ViewProxy.h:84
sv_frame_t getCentreFrame() const override
Return the centre frame of the visible widget.
Definition: ViewProxy.h:58
int scalePixelSize(int size) const override
Integer version of scaleSize.
Definition: ViewProxy.h:184
int getTextLabelYCoord(const Layer *layer, QPainter &) const override
Return a y-coordinate at which text labels for individual items in a layer may be drawn...
Definition: View.cpp:367
double getFrequencyForY(double y, double minFreq, double maxFreq, bool logarithmic) const override
Return the closest frequency to the given (maybe fractional) pixel y-coordinate, if the frequency ran...
Definition: ViewProxy.h:93
sv_frame_t getStartFrame() const override
Retrieve the first visible sample frame on the widget.
Definition: ViewProxy.h:55
QRect getPaintRect() const override
To be called from a layer, to obtain the extent of the surface that the layer is currently painting t...
Definition: View.cpp:2219
QColor getForeground() const override
Definition: ViewProxy.h:136
int getViewXForX(int x) const override
Return the closest view x-coordinate corresponding to a given pixel x-coordinate. ...
Definition: ViewProxy.h:78
bool shouldShowFeatureLabels() const override
Definition: View.h:279
bool hasLightBackground() const override
Definition: ViewProxy.h:133
ViewProxy(View *view, int scaleFactor)
Create a standard ViewProxy for the given view, mapping using the given scale factor.
Definition: ViewProxy.h:30
View * getView() override
Definition: ViewProxy.h:208
sv_frame_t getModelsStartFrame() const override
Definition: View.cpp:1451
bool hasLightBackground() const override
Definition: View.cpp:774
QRect getPaintRect() const override
To be called from a layer, to obtain the extent of the surface that the layer is currently painting t...
Definition: ViewProxy.h:117
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
void updatePaintRect(QRect r) override
Definition: ViewProxy.h:163
The ViewManager manages properties that may need to be synchronised between separate Views...
Definition: ViewManager.h:78
int getPaintWidth() const override
Definition: ViewProxy.h:127
bool getVisibleExtentsForUnit(QString unit, double &min, double &max, bool &log) const override
Return the visible vertical extents for the given unit, if any.
Definition: ViewProxy.h:101
int getPaintHeight() const override
Definition: ViewProxy.h:130
sv_frame_t getStartFrame() const override
Retrieve the first visible sample frame on the widget.
Definition: View.cpp:445
int getId() const override
Retrieve the id of this object.
Definition: ViewProxy.h:52
double scaleSize(double size) const override
Definition: View.cpp:1807
sv_frame_t getModelsEndFrame() const override
Definition: View.cpp:1475
sv_frame_t getEndFrame() const override
Retrieve the last visible sample frame on the widget.
Definition: View.cpp:451
bool shouldShowFeatureLabels() const override
Definition: ViewProxy.h:154
int getXForViewX(int viewx) const override
Return the closest pixel x-coordinate corresponding to a given view x-coordinate. ...
Definition: ViewProxy.h:75
double getYForFrequency(double frequency, double minFreq, double maxFreq, bool logarithmic) const override
Return the pixel y-coordinate corresponding to a given frequency, if the frequency range is as specif...
Definition: View.cpp:666
sv_frame_t getModelsStartFrame() const override
Definition: ViewProxy.h:81
int getTextLabelYCoord(const Layer *layer, QPainter &paint) const override
Return a y-coordinate at which text labels for individual items in a layer may be drawn...
Definition: ViewProxy.h:98
void drawMeasurementRect(QPainter &p, const Layer *, QRect rect, bool focus) const override
Definition: View.cpp:2767
ViewManager * getViewManager() const override
Definition: View.h:264
ZoomLevel getZoomLevel() const override
Return the zoom level, i.e.
Definition: ViewProxy.h:105
int getXForFrame(sv_frame_t frame) const override
Return the pixel x-coordinate corresponding to a given sample frame.
Definition: View.cpp:527
QSize getPaintSize() const override
Definition: ViewProxy.h:124
double scalePenWidth(double width) const override
Scale up pen width for a hi-dpi display without pixel doubling.
Definition: ViewProxy.h:193