comparison view/ViewProxy.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 4e5c1c326794
children 5144d7185fb5
comparison
equal deleted inserted replaced
976:f2c63ec85901 1045:f535f6e5dbb0
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 "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(int y, double minFreq, double maxFreq,
67 bool logarithmic) const {
68 double f0 = m_view->getFrequencyForY
69 (y / m_scaleFactor, minFreq, maxFreq, logarithmic);
70 if (m_scaleFactor == 1) return f0;
71 double f1 = m_view->getFrequencyForY
72 ((y / m_scaleFactor) + 1, minFreq, maxFreq, logarithmic);
73 return f0 + ((f1 - f0) * (y % m_scaleFactor)) / m_scaleFactor;
74 }
75 virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const {
76 return m_scaleFactor * m_view->getTextLabelHeight(layer, paint);
77 }
78 virtual bool getValueExtents(QString unit, double &min, double &max,
79 bool &log) const {
80 return m_view->getValueExtents(unit, min, max, log);
81 }
82 virtual int getZoomLevel() const {
83 int z = m_view->getZoomLevel();
84 // cerr << "getZoomLevel: from " << z << " to ";
85 z = z / m_scaleFactor;
86 // cerr << z << endl;
87 if (z < 1) z = 1;
88 return z;
89 }
90 virtual QRect getPaintRect() const {
91 QRect r = m_view->getPaintRect();
92 return QRect(r.x() * m_scaleFactor,
93 r.y() * m_scaleFactor,
94 r.width() * m_scaleFactor,
95 r.height() * m_scaleFactor);
96 }
97 virtual QSize getPaintSize() const {
98 return getPaintRect().size();
99 }
100 virtual int getPaintWidth() const {
101 return getPaintRect().width();
102 }
103 virtual int getPaintHeight() const {
104 return getPaintRect().height();
105 }
106 virtual bool hasLightBackground() const {
107 return m_view->hasLightBackground();
108 }
109 virtual QColor getForeground() const {
110 return m_view->getForeground();
111 }
112 virtual QColor getBackground() const {
113 return m_view->getBackground();
114 }
115 virtual ViewManager *getViewManager() const {
116 return m_view->getViewManager();
117 }
118
119 virtual bool shouldIlluminateLocalFeatures(const Layer *layer,
120 QPoint &point) const {
121 QPoint p;
122 bool should = m_view->shouldIlluminateLocalFeatures(layer, p);
123 point = QPoint(p.x() * m_scaleFactor, p.y() * m_scaleFactor);
124 return should;
125 }
126
127 virtual bool shouldShowFeatureLabels() const {
128 return m_view->shouldShowFeatureLabels();
129 }
130
131 virtual void drawVisibleText(QPainter &p, int x, int y,
132 QString text, TextStyle style) const {
133 m_view->drawVisibleText(p, x, y, text, style);
134 }
135
136 virtual void drawMeasurementRect(QPainter &p, const Layer *layer,
137 QRect rect, bool focus) const {
138 m_view->drawMeasurementRect(p, layer, rect, focus);
139 }
140
141 virtual void updatePaintRect(QRect r) {
142 m_view->update(r.x() / m_scaleFactor,
143 r.y() / m_scaleFactor,
144 r.width() / m_scaleFactor,
145 r.height() / m_scaleFactor);
146 }
147
148 virtual View *getView() { return m_view; }
149 virtual const View *getView() const { return m_view; }
150
151 private:
152 View *m_view;
153 int m_scaleFactor;
154 };
155
156 #endif