comparison view/ViewProxy.h @ 919:a5488775f880 osx-retina

Pass proxy to layer for painting
author Chris Cannam
date Wed, 18 Mar 2015 13:52:07 +0000
parents
children 43888f891733
comparison
equal deleted inserted replaced
918:4fe7a09be0fe 919:a5488775f880
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 return m_scaleFactor * m_view->getXForFrame(frame);
37 }
38 virtual sv_frame_t getFrameForX(int x) const {
39 //!!! todo: interpolate
40 return m_view->getFrameForX(x / m_scaleFactor);
41 }
42 virtual sv_frame_t getModelsStartFrame() const {
43 return m_view->getModelsStartFrame();
44 }
45 virtual sv_frame_t getModelsEndFrame() const {
46 return m_view->getModelsEndFrame();
47 }
48 virtual double getYForFrequency(double frequency,
49 double minFreq, double maxFreq,
50 bool logarithmic) const {
51 return m_scaleFactor *
52 m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic);
53 }
54 virtual double getFrequencyForY(int y, double minFreq, double maxFreq,
55 bool logarithmic) const {
56 //!!! todo: interpolate
57 return m_view->getFrequencyForY(y / m_scaleFactor, minFreq, maxFreq, logarithmic);
58 }
59 virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const {
60 return m_scaleFactor * m_view->getTextLabelHeight(layer, paint);
61 }
62 virtual bool getValueExtents(QString unit, double &min, double &max,
63 bool &log) const {
64 return m_view->getValueExtents(unit, min, max, log);
65 }
66 virtual int getZoomLevel() const {
67 //!!! aarg, what if it's already 1?
68 int z = m_view->getZoomLevel();
69 cerr << "getZoomLevel: from " << z << " to ";
70 z = z / m_scaleFactor;
71 cerr << z << endl;
72 return z;
73 }
74 virtual QRect getPaintRect() const {
75 QRect r = m_view->getPaintRect();
76 return QRect(r.x() * m_scaleFactor,
77 r.y() * m_scaleFactor,
78 r.width() * m_scaleFactor,
79 r.height() * m_scaleFactor);
80 }
81 virtual QSize getPaintSize() const { return getPaintRect().size(); }
82 virtual int getPaintWidth() const { return getPaintRect().width(); }
83 virtual int getPaintHeight() const { return getPaintRect().height(); }
84 virtual bool hasLightBackground() const {
85 return m_view->hasLightBackground();
86 }
87 virtual QColor getForeground() const {
88 return m_view->getForeground();
89 }
90 virtual QColor getBackground() const {
91 return m_view->getBackground();
92 }
93 virtual ViewManager *getViewManager() const {
94 return m_view->getViewManager();
95 }
96
97 virtual bool shouldIlluminateLocalFeatures(const Layer *layer, QPoint &point) const {
98 return m_view->shouldIlluminateLocalFeatures(layer, point);
99 }
100 virtual bool shouldShowFeatureLabels() const {
101 return m_view->shouldShowFeatureLabels();
102 }
103
104 virtual void drawVisibleText(QPainter &p, int x, int y,
105 QString text, TextStyle style) const {
106 m_view->drawVisibleText(p, x, y, text, style);
107 }
108
109 virtual void drawMeasurementRect(QPainter &p, const Layer *layer,
110 QRect rect, bool focus) const {
111 m_view->drawMeasurementRect(p, layer, rect, focus);
112 }
113
114 virtual View *getView() { return m_view; }
115 virtual const View *getView() const { return m_view; }
116
117 private:
118 View *m_view;
119 int m_scaleFactor;
120 };
121
122 #endif