comparison view/ViewProxy.h @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents 179ea8a2f650
children a34a2a25907c
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
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
18 #include "layer/LayerGeometryProvider.h"
19
20 class ViewProxy : public LayerGeometryProvider
21 {
22 public:
23 ViewProxy(View *view, int scaleFactor) :
24 m_view(view), m_scaleFactor(scaleFactor) { }
25
26 virtual int getId() const {
27 return m_view->getId();
28 }
29 virtual sv_frame_t getStartFrame() const {
30 return m_view->getStartFrame();
31 }
32 virtual sv_frame_t getCentreFrame() const {
33 return m_view->getCentreFrame();
34 }
35 virtual sv_frame_t getEndFrame() const {
36 return m_view->getEndFrame();
37 }
38 virtual int getXForFrame(sv_frame_t frame) const {
39 //!!! not actually correct, if frame lies between view's pixels
40 return m_scaleFactor * m_view->getXForFrame(frame);
41 }
42 virtual sv_frame_t getFrameForX(int x) const {
43 sv_frame_t f0 = m_view->getFrameForX(x / m_scaleFactor);
44 if (m_scaleFactor == 1) return f0;
45 sv_frame_t f1 = m_view->getFrameForX((x / m_scaleFactor) + 1);
46 return f0 + ((f1 - f0) * (x % m_scaleFactor)) / m_scaleFactor;
47 }
48 virtual int getXForViewX(int viewx) const {
49 return viewx * m_scaleFactor;
50 }
51 virtual int getViewXForX(int x) const {
52 return x / m_scaleFactor;
53 }
54 virtual sv_frame_t getModelsStartFrame() const {
55 return m_view->getModelsStartFrame();
56 }
57 virtual sv_frame_t getModelsEndFrame() const {
58 return m_view->getModelsEndFrame();
59 }
60 virtual double getYForFrequency(double frequency,
61 double minFreq, double maxFreq,
62 bool logarithmic) const {
63 return m_scaleFactor *
64 m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic);
65 }
66 virtual double getFrequencyForY(double y, double minFreq, double maxFreq,
67 bool logarithmic) const {
68 return m_view->getFrequencyForY
69 (y / m_scaleFactor, minFreq, maxFreq, logarithmic);
70 }
71 virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const {
72 return m_scaleFactor * m_view->getTextLabelHeight(layer, paint);
73 }
74 virtual bool getValueExtents(QString unit, double &min, double &max,
75 bool &log) const {
76 return m_view->getValueExtents(unit, min, max, log);
77 }
78 virtual int getZoomLevel() const {
79 int z = m_view->getZoomLevel();
80 // cerr << "getZoomLevel: from " << z << " to ";
81 z = z / m_scaleFactor;
82 // cerr << z << endl;
83 if (z < 1) z = 1;
84 return z;
85 }
86 virtual QRect getPaintRect() const {
87 QRect r = m_view->getPaintRect();
88 return QRect(r.x() * m_scaleFactor,
89 r.y() * m_scaleFactor,
90 r.width() * m_scaleFactor,
91 r.height() * m_scaleFactor);
92 }
93 virtual QSize getPaintSize() const {
94 return getPaintRect().size();
95 }
96 virtual int getPaintWidth() const {
97 return getPaintRect().width();
98 }
99 virtual int getPaintHeight() const {
100 return getPaintRect().height();
101 }
102 virtual bool hasLightBackground() const {
103 return m_view->hasLightBackground();
104 }
105 virtual QColor getForeground() const {
106 return m_view->getForeground();
107 }
108 virtual QColor getBackground() const {
109 return m_view->getBackground();
110 }
111 virtual ViewManager *getViewManager() const {
112 return m_view->getViewManager();
113 }
114
115 virtual bool shouldIlluminateLocalFeatures(const Layer *layer,
116 QPoint &point) const {
117 QPoint p;
118 bool should = m_view->shouldIlluminateLocalFeatures(layer, p);
119 point = QPoint(p.x() * m_scaleFactor, p.y() * m_scaleFactor);
120 return should;
121 }
122
123 virtual bool shouldShowFeatureLabels() const {
124 return m_view->shouldShowFeatureLabels();
125 }
126
127 virtual void drawMeasurementRect(QPainter &p, const Layer *layer,
128 QRect rect, bool focus) const {
129 m_view->drawMeasurementRect(p, layer, rect, focus);
130 }
131
132 virtual void updatePaintRect(QRect r) {
133 m_view->update(r.x() / m_scaleFactor,
134 r.y() / m_scaleFactor,
135 r.width() / m_scaleFactor,
136 r.height() / m_scaleFactor);
137 }
138
139 virtual View *getView() { return m_view; }
140 virtual const View *getView() const { return m_view; }
141
142 private:
143 View *m_view;
144 int m_scaleFactor;
145 };
146
147 #endif