Chris@919
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@919
|
2
|
Chris@919
|
3 /*
|
Chris@919
|
4 Sonic Visualiser
|
Chris@919
|
5 An audio file viewer and annotation editor.
|
Chris@919
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@919
|
7
|
Chris@919
|
8 This program is free software; you can redistribute it and/or
|
Chris@919
|
9 modify it under the terms of the GNU General Public License as
|
Chris@919
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@919
|
11 License, or (at your option) any later version. See the file
|
Chris@919
|
12 COPYING included with this distribution for more information.
|
Chris@919
|
13 */
|
Chris@919
|
14
|
Chris@919
|
15 #ifndef VIEW_PROXY_H
|
Chris@919
|
16 #define VIEW_PROXY_H
|
Chris@919
|
17
|
Chris@1077
|
18 #include "layer/LayerGeometryProvider.h"
|
Chris@919
|
19
|
Chris@919
|
20 class ViewProxy : public LayerGeometryProvider
|
Chris@919
|
21 {
|
Chris@919
|
22 public:
|
Chris@919
|
23 ViewProxy(View *view, int scaleFactor) :
|
Chris@1266
|
24 m_view(view), m_scaleFactor(scaleFactor) { }
|
Chris@919
|
25
|
Chris@1044
|
26 virtual int getId() const {
|
Chris@1044
|
27 return m_view->getId();
|
Chris@1044
|
28 }
|
Chris@919
|
29 virtual sv_frame_t getStartFrame() const {
|
Chris@1266
|
30 return m_view->getStartFrame();
|
Chris@919
|
31 }
|
Chris@919
|
32 virtual sv_frame_t getCentreFrame() const {
|
Chris@1266
|
33 return m_view->getCentreFrame();
|
Chris@919
|
34 }
|
Chris@919
|
35 virtual sv_frame_t getEndFrame() const {
|
Chris@1266
|
36 return m_view->getEndFrame();
|
Chris@919
|
37 }
|
Chris@919
|
38 virtual int getXForFrame(sv_frame_t frame) const {
|
Chris@950
|
39 //!!! not actually correct, if frame lies between view's pixels
|
Chris@1266
|
40 return m_scaleFactor * m_view->getXForFrame(frame);
|
Chris@919
|
41 }
|
Chris@919
|
42 virtual sv_frame_t getFrameForX(int x) const {
|
Chris@950
|
43 sv_frame_t f0 = m_view->getFrameForX(x / m_scaleFactor);
|
Chris@950
|
44 if (m_scaleFactor == 1) return f0;
|
Chris@950
|
45 sv_frame_t f1 = m_view->getFrameForX((x / m_scaleFactor) + 1);
|
Chris@950
|
46 return f0 + ((f1 - f0) * (x % m_scaleFactor)) / m_scaleFactor;
|
Chris@919
|
47 }
|
Chris@1030
|
48 virtual int getXForViewX(int viewx) const {
|
Chris@1030
|
49 return viewx * m_scaleFactor;
|
Chris@1030
|
50 }
|
Chris@1030
|
51 virtual int getViewXForX(int x) const {
|
Chris@1030
|
52 return x / m_scaleFactor;
|
Chris@1030
|
53 }
|
Chris@919
|
54 virtual sv_frame_t getModelsStartFrame() const {
|
Chris@1266
|
55 return m_view->getModelsStartFrame();
|
Chris@919
|
56 }
|
Chris@919
|
57 virtual sv_frame_t getModelsEndFrame() const {
|
Chris@1266
|
58 return m_view->getModelsEndFrame();
|
Chris@919
|
59 }
|
Chris@919
|
60 virtual double getYForFrequency(double frequency,
|
Chris@1266
|
61 double minFreq, double maxFreq,
|
Chris@919
|
62 bool logarithmic) const {
|
Chris@1266
|
63 return m_scaleFactor *
|
Chris@1266
|
64 m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic);
|
Chris@919
|
65 }
|
Chris@1085
|
66 virtual double getFrequencyForY(double y, double minFreq, double maxFreq,
|
Chris@1266
|
67 bool logarithmic) const {
|
Chris@1085
|
68 return m_view->getFrequencyForY
|
Chris@950
|
69 (y / m_scaleFactor, minFreq, maxFreq, logarithmic);
|
Chris@919
|
70 }
|
Chris@919
|
71 virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const {
|
Chris@1266
|
72 return m_scaleFactor * m_view->getTextLabelHeight(layer, paint);
|
Chris@919
|
73 }
|
Chris@919
|
74 virtual bool getValueExtents(QString unit, double &min, double &max,
|
Chris@919
|
75 bool &log) const {
|
Chris@1266
|
76 return m_view->getValueExtents(unit, min, max, log);
|
Chris@919
|
77 }
|
Chris@919
|
78 virtual int getZoomLevel() const {
|
Chris@1266
|
79 int z = m_view->getZoomLevel();
|
Chris@1266
|
80 // cerr << "getZoomLevel: from " << z << " to ";
|
Chris@1266
|
81 z = z / m_scaleFactor;
|
Chris@1266
|
82 // cerr << z << endl;
|
Chris@999
|
83 if (z < 1) z = 1;
|
Chris@1266
|
84 return z;
|
Chris@919
|
85 }
|
Chris@919
|
86 virtual QRect getPaintRect() const {
|
Chris@1266
|
87 QRect r = m_view->getPaintRect();
|
Chris@1266
|
88 return QRect(r.x() * m_scaleFactor,
|
Chris@1266
|
89 r.y() * m_scaleFactor,
|
Chris@1266
|
90 r.width() * m_scaleFactor,
|
Chris@1266
|
91 r.height() * m_scaleFactor);
|
Chris@919
|
92 }
|
Chris@954
|
93 virtual QSize getPaintSize() const {
|
Chris@954
|
94 return getPaintRect().size();
|
Chris@954
|
95 }
|
Chris@954
|
96 virtual int getPaintWidth() const {
|
Chris@954
|
97 return getPaintRect().width();
|
Chris@954
|
98 }
|
Chris@954
|
99 virtual int getPaintHeight() const {
|
Chris@954
|
100 return getPaintRect().height();
|
Chris@954
|
101 }
|
Chris@919
|
102 virtual bool hasLightBackground() const {
|
Chris@1266
|
103 return m_view->hasLightBackground();
|
Chris@919
|
104 }
|
Chris@919
|
105 virtual QColor getForeground() const {
|
Chris@1266
|
106 return m_view->getForeground();
|
Chris@919
|
107 }
|
Chris@919
|
108 virtual QColor getBackground() const {
|
Chris@1266
|
109 return m_view->getBackground();
|
Chris@919
|
110 }
|
Chris@919
|
111 virtual ViewManager *getViewManager() const {
|
Chris@1266
|
112 return m_view->getViewManager();
|
Chris@919
|
113 }
|
Chris@1266
|
114
|
Chris@954
|
115 virtual bool shouldIlluminateLocalFeatures(const Layer *layer,
|
Chris@954
|
116 QPoint &point) const {
|
Chris@954
|
117 QPoint p;
|
Chris@1266
|
118 bool should = m_view->shouldIlluminateLocalFeatures(layer, p);
|
Chris@954
|
119 point = QPoint(p.x() * m_scaleFactor, p.y() * m_scaleFactor);
|
Chris@954
|
120 return should;
|
Chris@919
|
121 }
|
Chris@954
|
122
|
Chris@919
|
123 virtual bool shouldShowFeatureLabels() const {
|
Chris@1266
|
124 return m_view->shouldShowFeatureLabels();
|
Chris@919
|
125 }
|
Chris@919
|
126
|
Chris@919
|
127 virtual void drawMeasurementRect(QPainter &p, const Layer *layer,
|
Chris@919
|
128 QRect rect, bool focus) const {
|
Chris@1266
|
129 m_view->drawMeasurementRect(p, layer, rect, focus);
|
Chris@919
|
130 }
|
Chris@919
|
131
|
Chris@1030
|
132 virtual void updatePaintRect(QRect r) {
|
Chris@1030
|
133 m_view->update(r.x() / m_scaleFactor,
|
Chris@1030
|
134 r.y() / m_scaleFactor,
|
Chris@1030
|
135 r.width() / m_scaleFactor,
|
Chris@1030
|
136 r.height() / m_scaleFactor);
|
Chris@1030
|
137 }
|
Chris@1030
|
138
|
Chris@919
|
139 virtual View *getView() { return m_view; }
|
Chris@919
|
140 virtual const View *getView() const { return m_view; }
|
Chris@919
|
141
|
Chris@919
|
142 private:
|
Chris@919
|
143 View *m_view;
|
Chris@919
|
144 int m_scaleFactor;
|
Chris@919
|
145 };
|
Chris@919
|
146
|
Chris@919
|
147 #endif
|