Mercurial > hg > svcore
comparison base/View.h @ 0:da6937383da8
initial import
author | Chris Cannam |
---|---|
date | Tue, 10 Jan 2006 16:33:16 +0000 |
parents | |
children | d86891498eef |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:da6937383da8 |
---|---|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 A waveform viewer and audio annotation editor. | |
5 Chris Cannam, Queen Mary University of London, 2005 | |
6 | |
7 This is experimental software. Not for distribution. | |
8 */ | |
9 | |
10 #ifndef _CANVAS_H_ | |
11 #define _CANVAS_H_ | |
12 | |
13 #include <QFrame> | |
14 #include <QProgressBar> | |
15 | |
16 #include "base/ZoomConstraint.h" | |
17 #include "base/PropertyContainer.h" | |
18 | |
19 class Layer; | |
20 class ViewManager; | |
21 | |
22 #include <map> | |
23 | |
24 /** | |
25 * View is the base class of widgets that display one or more | |
26 * overlaid views of data against a horizontal time scale. | |
27 * | |
28 * A View may have any number of attached Layers, each of which | |
29 * is expected to have one data Model (although multiple views may | |
30 * share the same model). | |
31 * | |
32 * A View may be panned in time and zoomed, although the | |
33 * mechanisms for doing so (as well as any other operations and | |
34 * properties available) depend on the subclass. | |
35 */ | |
36 | |
37 class View : public QFrame, | |
38 public PropertyContainer | |
39 { | |
40 Q_OBJECT | |
41 | |
42 public: | |
43 /** | |
44 * Deleting a View deletes all its views. However, it is | |
45 * also acceptable for the views to be deleted by other code (in | |
46 * which case they will remove themselves from this View | |
47 * automatically), or to be removed explicitly without deleting | |
48 * using removeLayer. | |
49 */ | |
50 virtual ~View(); | |
51 | |
52 /** | |
53 * Retrieve the first visible sample frame on the widget. | |
54 * This is a calculated value based on the centre-frame, widget | |
55 * width and zoom level. The result may be negative. | |
56 */ | |
57 virtual long getStartFrame() const; | |
58 | |
59 /** | |
60 * Set the widget pan based on the given first visible frame. The | |
61 * frame value may be negative. | |
62 */ | |
63 virtual void setStartFrame(long); | |
64 | |
65 /** | |
66 * Return the centre frame of the visible widget. This is an | |
67 * exact value that does not depend on the zoom block size. Other | |
68 * frame values (start, end) are calculated from this based on the | |
69 * zoom and other factors. | |
70 */ | |
71 virtual size_t getCentreFrame() const { return m_centreFrame; } | |
72 | |
73 /** | |
74 * Set the centre frame of the visible widget. | |
75 */ | |
76 virtual void setCentreFrame(size_t f) { setCentreFrame(f, true); } | |
77 | |
78 /** | |
79 * Retrieve the last visible sample frame on the widget. | |
80 * This is a calculated value based on the centre-frame, widget | |
81 * width and zoom level. | |
82 */ | |
83 virtual size_t getEndFrame() const; | |
84 | |
85 /** | |
86 * Return the zoom level, i.e. the number of frames per pixel. | |
87 */ | |
88 virtual int getZoomLevel() const { return m_zoomLevel; } | |
89 | |
90 /** | |
91 * Set the zoom level, i.e. the number of frames per pixel. The | |
92 * centre frame will be unchanged; the start and end frames will | |
93 * change. | |
94 */ | |
95 virtual void setZoomLevel(size_t z); | |
96 | |
97 /** | |
98 * Zoom in or out. | |
99 */ | |
100 virtual void zoom(bool in); | |
101 | |
102 virtual void addLayer(Layer *v); | |
103 virtual void removeLayer(Layer *v); // does not delete the layer | |
104 virtual int getLayerCount() const { return m_layers.size(); } | |
105 | |
106 /** | |
107 * Return a layer, counted in stacking order. That is, layer 0 is | |
108 * the bottom layer and layer "getLayerCount()-1" is the top one. | |
109 */ | |
110 virtual Layer *getLayer(int n) { return m_layers[n]; } | |
111 | |
112 virtual void setViewManager(ViewManager *m); | |
113 | |
114 virtual void setFollowGlobalPan(bool f); | |
115 virtual bool getFollowGlobalPan() const { return m_followPan; } | |
116 | |
117 virtual void setFollowGlobalZoom(bool f); | |
118 virtual bool getFollowGlobalZoom() const { return m_followZoom; } | |
119 | |
120 virtual void setLightBackground(bool lb) { m_lightBackground = lb; } | |
121 virtual bool hasLightBackground() const { return m_lightBackground; } | |
122 | |
123 virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) { | |
124 return false; | |
125 } | |
126 | |
127 enum PlaybackFollowMode { | |
128 PlaybackScrollContinuous, | |
129 PlaybackScrollPage, | |
130 PlaybackIgnore | |
131 }; | |
132 virtual void setPlaybackFollow(PlaybackFollowMode m); | |
133 virtual PlaybackFollowMode getPlaybackFollow() const { return m_followPlay; } | |
134 | |
135 virtual PropertyList getProperties() const; | |
136 virtual PropertyType getPropertyType(const PropertyName &) const; | |
137 virtual int getPropertyRangeAndValue(const PropertyName &, | |
138 int *min, int *max) const; | |
139 virtual QString getPropertyValueLabel(const PropertyName &, | |
140 int value) const; | |
141 virtual void setProperty(const PropertyName &, int value); | |
142 | |
143 virtual size_t getPropertyContainerCount() const; | |
144 virtual const PropertyContainer *getPropertyContainer(size_t i) const; | |
145 virtual PropertyContainer *getPropertyContainer(size_t i); | |
146 | |
147 virtual QString getPropertyContainerName() const { | |
148 return objectName(); | |
149 } | |
150 | |
151 signals: | |
152 void propertyContainerAdded(PropertyContainer *pc); | |
153 void propertyContainerRemoved(PropertyContainer *pc); | |
154 void propertyContainerPropertyChanged(PropertyContainer *pc); | |
155 void propertyContainerNameChanged(PropertyContainer *pc); | |
156 | |
157 void centreFrameChanged(void *, unsigned long, bool); | |
158 void zoomLevelChanged(void *, unsigned long, bool); | |
159 | |
160 public slots: | |
161 virtual void modelChanged(); | |
162 virtual void modelChanged(size_t startFrame, size_t endFrame); | |
163 virtual void modelCompletionChanged(); | |
164 virtual void modelReplaced(); | |
165 virtual void layerParametersChanged(); | |
166 virtual void layerNameChanged(); | |
167 | |
168 virtual void viewManagerCentreFrameChanged(void *, unsigned long, bool); | |
169 virtual void viewManagerPlaybackFrameChanged(unsigned long); | |
170 virtual void viewManagerZoomLevelChanged(void *, unsigned long, bool); | |
171 | |
172 virtual void propertyContainerSelected(PropertyContainer *pc); | |
173 | |
174 protected: | |
175 View(QWidget *, bool showProgress); | |
176 virtual void paintEvent(QPaintEvent *e); | |
177 | |
178 typedef std::vector<Layer *> LayerList; | |
179 | |
180 size_t getModelsStartFrame() const; | |
181 size_t getModelsEndFrame() const; | |
182 int getModelsSampleRate() const; | |
183 bool areLayersScrollable() const; | |
184 LayerList getScrollableBackLayers(bool &changed) const; | |
185 LayerList getNonScrollableFrontLayers(bool &changed) const; | |
186 size_t getZoomConstraintBlockSize(size_t blockSize, | |
187 ZoomConstraint::RoundingDirection dir = | |
188 ZoomConstraint::RoundNearest) const; | |
189 | |
190 void setCentreFrame(size_t f, bool e); | |
191 | |
192 void checkProgress(void *object); | |
193 | |
194 size_t m_centreFrame; | |
195 int m_zoomLevel; | |
196 bool m_newModel; | |
197 bool m_followPan; | |
198 bool m_followZoom; | |
199 PlaybackFollowMode m_followPlay; | |
200 size_t m_playPointerFrame; | |
201 bool m_lightBackground; | |
202 bool m_showProgress; | |
203 | |
204 QPixmap *m_cache; | |
205 size_t m_cacheCentreFrame; | |
206 int m_cacheZoomLevel; | |
207 | |
208 bool m_deleting; | |
209 | |
210 LayerList m_layers; // I don't own these, but see note in dtor comment above | |
211 | |
212 // caches for use in getScrollableBackLayers, getNonScrollableFrontLayers | |
213 mutable LayerList m_lastScrollableBackLayers; | |
214 mutable LayerList m_lastNonScrollableBackLayers; | |
215 | |
216 class LayerProgressBar : public QProgressBar { | |
217 public: | |
218 LayerProgressBar(QWidget *parent) : QProgressBar(parent) { } | |
219 virtual QString text() const { return m_text; } | |
220 virtual void setText(QString text) { m_text = text; } | |
221 protected: | |
222 QString m_text; | |
223 }; | |
224 | |
225 typedef std::map<Layer *, LayerProgressBar *> ProgressMap; | |
226 ProgressMap m_progressBars; // I own the ProgressBars | |
227 | |
228 ViewManager *m_manager; // I don't own this | |
229 }; | |
230 | |
231 #endif | |
232 |