comparison view/ViewProxy.h @ 978:64c2b3a4435a 3.0-integration

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