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@919
|
18 #include "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@919
|
24 m_view(view), m_scaleFactor(scaleFactor) { }
|
Chris@919
|
25
|
Chris@919
|
26 virtual sv_frame_t getStartFrame() const {
|
Chris@919
|
27 return m_view->getStartFrame();
|
Chris@919
|
28 }
|
Chris@919
|
29 virtual sv_frame_t getCentreFrame() const {
|
Chris@919
|
30 return m_view->getCentreFrame();
|
Chris@919
|
31 }
|
Chris@919
|
32 virtual sv_frame_t getEndFrame() const {
|
Chris@919
|
33 return m_view->getEndFrame();
|
Chris@919
|
34 }
|
Chris@919
|
35 virtual int getXForFrame(sv_frame_t frame) const {
|
Chris@950
|
36 //!!! not actually correct, if frame lies between view's pixels
|
Chris@919
|
37 return m_scaleFactor * m_view->getXForFrame(frame);
|
Chris@919
|
38 }
|
Chris@919
|
39 virtual sv_frame_t getFrameForX(int x) const {
|
Chris@950
|
40 sv_frame_t f0 = m_view->getFrameForX(x / m_scaleFactor);
|
Chris@950
|
41 if (m_scaleFactor == 1) return f0;
|
Chris@950
|
42 sv_frame_t f1 = m_view->getFrameForX((x / m_scaleFactor) + 1);
|
Chris@950
|
43 return f0 + ((f1 - f0) * (x % m_scaleFactor)) / m_scaleFactor;
|
Chris@919
|
44 }
|
Chris@919
|
45 virtual sv_frame_t getModelsStartFrame() const {
|
Chris@919
|
46 return m_view->getModelsStartFrame();
|
Chris@919
|
47 }
|
Chris@919
|
48 virtual sv_frame_t getModelsEndFrame() const {
|
Chris@919
|
49 return m_view->getModelsEndFrame();
|
Chris@919
|
50 }
|
Chris@919
|
51 virtual double getYForFrequency(double frequency,
|
Chris@919
|
52 double minFreq, double maxFreq,
|
Chris@919
|
53 bool logarithmic) const {
|
Chris@919
|
54 return m_scaleFactor *
|
Chris@919
|
55 m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic);
|
Chris@919
|
56 }
|
Chris@919
|
57 virtual double getFrequencyForY(int y, double minFreq, double maxFreq,
|
Chris@919
|
58 bool logarithmic) const {
|
Chris@950
|
59 double f0 = m_view->getFrequencyForY
|
Chris@950
|
60 (y / m_scaleFactor, minFreq, maxFreq, logarithmic);
|
Chris@950
|
61 if (m_scaleFactor == 1) return f0;
|
Chris@950
|
62 double f1 = m_view->getFrequencyForY
|
Chris@950
|
63 ((y / m_scaleFactor) + 1, minFreq, maxFreq, logarithmic);
|
Chris@950
|
64 return f0 + ((f1 - f0) * (y % m_scaleFactor)) / m_scaleFactor;
|
Chris@919
|
65 }
|
Chris@919
|
66 virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const {
|
Chris@919
|
67 return m_scaleFactor * m_view->getTextLabelHeight(layer, paint);
|
Chris@919
|
68 }
|
Chris@919
|
69 virtual bool getValueExtents(QString unit, double &min, double &max,
|
Chris@919
|
70 bool &log) const {
|
Chris@919
|
71 return m_view->getValueExtents(unit, min, max, log);
|
Chris@919
|
72 }
|
Chris@919
|
73 virtual int getZoomLevel() const {
|
Chris@919
|
74 //!!! aarg, what if it's already 1?
|
Chris@919
|
75 int z = m_view->getZoomLevel();
|
Chris@919
|
76 cerr << "getZoomLevel: from " << z << " to ";
|
Chris@919
|
77 z = z / m_scaleFactor;
|
Chris@919
|
78 cerr << z << endl;
|
Chris@919
|
79 return z;
|
Chris@919
|
80 }
|
Chris@919
|
81 virtual QRect getPaintRect() const {
|
Chris@919
|
82 QRect r = m_view->getPaintRect();
|
Chris@919
|
83 return QRect(r.x() * m_scaleFactor,
|
Chris@919
|
84 r.y() * m_scaleFactor,
|
Chris@919
|
85 r.width() * m_scaleFactor,
|
Chris@919
|
86 r.height() * m_scaleFactor);
|
Chris@919
|
87 }
|
Chris@919
|
88 virtual QSize getPaintSize() const { return getPaintRect().size(); }
|
Chris@919
|
89 virtual int getPaintWidth() const { return getPaintRect().width(); }
|
Chris@919
|
90 virtual int getPaintHeight() const { return getPaintRect().height(); }
|
Chris@919
|
91 virtual bool hasLightBackground() const {
|
Chris@919
|
92 return m_view->hasLightBackground();
|
Chris@919
|
93 }
|
Chris@919
|
94 virtual QColor getForeground() const {
|
Chris@919
|
95 return m_view->getForeground();
|
Chris@919
|
96 }
|
Chris@919
|
97 virtual QColor getBackground() const {
|
Chris@919
|
98 return m_view->getBackground();
|
Chris@919
|
99 }
|
Chris@919
|
100 virtual ViewManager *getViewManager() const {
|
Chris@919
|
101 return m_view->getViewManager();
|
Chris@919
|
102 }
|
Chris@919
|
103
|
Chris@919
|
104 virtual bool shouldIlluminateLocalFeatures(const Layer *layer, QPoint &point) const {
|
Chris@919
|
105 return m_view->shouldIlluminateLocalFeatures(layer, point);
|
Chris@919
|
106 }
|
Chris@919
|
107 virtual bool shouldShowFeatureLabels() const {
|
Chris@919
|
108 return m_view->shouldShowFeatureLabels();
|
Chris@919
|
109 }
|
Chris@919
|
110
|
Chris@919
|
111 virtual void drawVisibleText(QPainter &p, int x, int y,
|
Chris@919
|
112 QString text, TextStyle style) const {
|
Chris@919
|
113 m_view->drawVisibleText(p, x, y, text, style);
|
Chris@919
|
114 }
|
Chris@919
|
115
|
Chris@919
|
116 virtual void drawMeasurementRect(QPainter &p, const Layer *layer,
|
Chris@919
|
117 QRect rect, bool focus) const {
|
Chris@919
|
118 m_view->drawMeasurementRect(p, layer, rect, focus);
|
Chris@919
|
119 }
|
Chris@919
|
120
|
Chris@919
|
121 virtual View *getView() { return m_view; }
|
Chris@919
|
122 virtual const View *getView() const { return m_view; }
|
Chris@919
|
123
|
Chris@919
|
124 private:
|
Chris@919
|
125 View *m_view;
|
Chris@919
|
126 int m_scaleFactor;
|
Chris@919
|
127 };
|
Chris@919
|
128
|
Chris@919
|
129 #endif
|