Mercurial > hg > svgui
comparison view/View.h @ 127:89c625dda204
* Reorganising code base. This revision will not compile.
author | Chris Cannam |
---|---|
date | Mon, 31 Jul 2006 11:44:37 +0000 |
parents | |
children | 33929e0c3c6b |
comparison
equal
deleted
inserted
replaced
126:0e95c127bb53 | 127:89c625dda204 |
---|---|
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 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _CANVAS_H_ | |
17 #define _CANVAS_H_ | |
18 | |
19 #include <QFrame> | |
20 #include <QProgressBar> | |
21 | |
22 #include "base/ZoomConstraint.h" | |
23 #include "base/PropertyContainer.h" | |
24 #include "base/ViewManager.h" | |
25 #include "base/XmlExportable.h" | |
26 | |
27 // #define DEBUG_VIEW_WIDGET_PAINT 1 | |
28 | |
29 class Layer; | |
30 class ViewPropertyContainer; | |
31 | |
32 #include <map> | |
33 | |
34 /** | |
35 * View is the base class of widgets that display one or more | |
36 * overlaid views of data against a horizontal time scale. | |
37 * | |
38 * A View may have any number of attached Layers, each of which | |
39 * is expected to have one data Model (although multiple views may | |
40 * share the same model). | |
41 * | |
42 * A View may be panned in time and zoomed, although the | |
43 * mechanisms for doing so (as well as any other operations and | |
44 * properties available) depend on the subclass. | |
45 */ | |
46 | |
47 class View : public QFrame, | |
48 public XmlExportable | |
49 { | |
50 Q_OBJECT | |
51 | |
52 public: | |
53 /** | |
54 * Deleting a View does not delete any of its layers. They should | |
55 * be managed elsewhere (e.g. by the Document). | |
56 */ | |
57 virtual ~View(); | |
58 | |
59 /** | |
60 * Retrieve the first visible sample frame on the widget. | |
61 * This is a calculated value based on the centre-frame, widget | |
62 * width and zoom level. The result may be negative. | |
63 */ | |
64 virtual long getStartFrame() const; | |
65 | |
66 /** | |
67 * Set the widget pan based on the given first visible frame. The | |
68 * frame value may be negative. | |
69 */ | |
70 virtual void setStartFrame(long); | |
71 | |
72 /** | |
73 * Return the centre frame of the visible widget. This is an | |
74 * exact value that does not depend on the zoom block size. Other | |
75 * frame values (start, end) are calculated from this based on the | |
76 * zoom and other factors. | |
77 */ | |
78 virtual size_t getCentreFrame() const { return m_centreFrame; } | |
79 | |
80 /** | |
81 * Set the centre frame of the visible widget. | |
82 */ | |
83 virtual void setCentreFrame(size_t f) { setCentreFrame(f, true); } | |
84 | |
85 /** | |
86 * Retrieve the last visible sample frame on the widget. | |
87 * This is a calculated value based on the centre-frame, widget | |
88 * width and zoom level. | |
89 */ | |
90 virtual size_t getEndFrame() const; | |
91 | |
92 /** | |
93 * Return the pixel x-coordinate corresponding to a given sample | |
94 * frame (which may be negative). | |
95 */ | |
96 int getXForFrame(long frame) const; | |
97 | |
98 /** | |
99 * Return the closest frame to the given pixel x-coordinate. | |
100 */ | |
101 long getFrameForX(int x) const; | |
102 | |
103 /** | |
104 * Return the pixel y-coordinate corresponding to a given | |
105 * frequency, if the frequency range is as specified. This does | |
106 * not imply any policy about layer frequency ranges, but it might | |
107 * be useful for layers to match theirs up if desired. | |
108 * | |
109 * Not thread-safe in logarithmic mode. Call only from GUI thread. | |
110 */ | |
111 float getYForFrequency(float frequency, float minFreq, float maxFreq, | |
112 bool logarithmic) const; | |
113 | |
114 /** | |
115 * Return the closest frequency to the given pixel y-coordinate, | |
116 * if the frequency range is as specified. | |
117 * | |
118 * Not thread-safe in logarithmic mode. Call only from GUI thread. | |
119 */ | |
120 float getFrequencyForY(int y, float minFreq, float maxFreq, | |
121 bool logarithmic) const; | |
122 | |
123 /** | |
124 * Return the zoom level, i.e. the number of frames per pixel | |
125 */ | |
126 int getZoomLevel() const; | |
127 | |
128 /** | |
129 * Set the zoom level, i.e. the number of frames per pixel. The | |
130 * centre frame will be unchanged; the start and end frames will | |
131 * change. | |
132 */ | |
133 virtual void setZoomLevel(size_t z); | |
134 | |
135 /** | |
136 * Zoom in or out. | |
137 */ | |
138 virtual void zoom(bool in); | |
139 | |
140 /** | |
141 * Scroll left or right by a smallish or largish amount. | |
142 */ | |
143 virtual void scroll(bool right, bool lots); | |
144 | |
145 virtual void addLayer(Layer *v); | |
146 virtual void removeLayer(Layer *v); // does not delete the layer | |
147 virtual int getLayerCount() const { return m_layers.size(); } | |
148 | |
149 /** | |
150 * Return a layer, counted in stacking order. That is, layer 0 is | |
151 * the bottom layer and layer "getLayerCount()-1" is the top one. | |
152 */ | |
153 virtual Layer *getLayer(int n) { return m_layers[n]; } | |
154 | |
155 /** | |
156 * Return the layer last selected by the user. This is normally | |
157 * the top layer, the same as getLayer(getLayerCount()-1). | |
158 * However, if the user has selected the pane itself more recently | |
159 * than any of the layers on it, this function will return 0. It | |
160 * will also return 0 if there are no layers. | |
161 */ | |
162 virtual Layer *getSelectedLayer(); | |
163 virtual const Layer *getSelectedLayer() const; | |
164 | |
165 virtual void setViewManager(ViewManager *m); | |
166 virtual ViewManager *getViewManager() const { return m_manager; } | |
167 | |
168 virtual void setFollowGlobalPan(bool f); | |
169 virtual bool getFollowGlobalPan() const { return m_followPan; } | |
170 | |
171 virtual void setFollowGlobalZoom(bool f); | |
172 virtual bool getFollowGlobalZoom() const { return m_followZoom; } | |
173 | |
174 virtual void setLightBackground(bool lb) { m_lightBackground = lb; } | |
175 virtual bool hasLightBackground() const { return m_lightBackground; } | |
176 | |
177 enum TextStyle { | |
178 BoxedText, | |
179 OutlinedText | |
180 }; | |
181 | |
182 virtual void drawVisibleText(QPainter &p, int x, int y, | |
183 QString text, TextStyle style); | |
184 | |
185 virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const { | |
186 return false; | |
187 } | |
188 virtual bool shouldIlluminateLocalSelection(QPoint &, bool &, bool &) const { | |
189 return false; | |
190 } | |
191 | |
192 enum PlaybackFollowMode { | |
193 PlaybackScrollContinuous, | |
194 PlaybackScrollPage, | |
195 PlaybackIgnore | |
196 }; | |
197 virtual void setPlaybackFollow(PlaybackFollowMode m); | |
198 virtual PlaybackFollowMode getPlaybackFollow() const { return m_followPlay; } | |
199 | |
200 typedef PropertyContainer::PropertyName PropertyName; | |
201 | |
202 // We implement the PropertyContainer API, although we don't | |
203 // actually subclass PropertyContainer. We have our own | |
204 // PropertyContainer that we can return on request that just | |
205 // delegates back to us. | |
206 virtual PropertyContainer::PropertyList getProperties() const; | |
207 virtual QString getPropertyLabel(const PropertyName &) const; | |
208 virtual PropertyContainer::PropertyType getPropertyType(const PropertyName &) const; | |
209 virtual int getPropertyRangeAndValue(const PropertyName &, | |
210 int *min, int *max) const; | |
211 virtual QString getPropertyValueLabel(const PropertyName &, | |
212 int value) const; | |
213 virtual void setProperty(const PropertyName &, int value); | |
214 virtual QString getPropertyContainerName() const { | |
215 return objectName(); | |
216 } | |
217 virtual QString getPropertyContainerIconName() const = 0; | |
218 | |
219 virtual size_t getPropertyContainerCount() const; | |
220 | |
221 virtual const PropertyContainer *getPropertyContainer(size_t i) const; | |
222 virtual PropertyContainer *getPropertyContainer(size_t i); | |
223 | |
224 virtual int getTextLabelHeight(const Layer *layer, QPainter &) const; | |
225 | |
226 virtual bool getValueExtents(QString unit, float &min, float &max, | |
227 bool &log) const; | |
228 | |
229 virtual QString toXmlString(QString indent = "", | |
230 QString extraAttributes = "") const; | |
231 | |
232 size_t getModelsStartFrame() const; | |
233 size_t getModelsEndFrame() const; | |
234 | |
235 signals: | |
236 void propertyContainerAdded(PropertyContainer *pc); | |
237 void propertyContainerRemoved(PropertyContainer *pc); | |
238 void propertyContainerPropertyChanged(PropertyContainer *pc); | |
239 void propertyContainerNameChanged(PropertyContainer *pc); | |
240 void propertyChanged(PropertyContainer::PropertyName); | |
241 | |
242 void centreFrameChanged(void *, unsigned long, bool); | |
243 void zoomLevelChanged(void *, unsigned long, bool); | |
244 | |
245 public slots: | |
246 virtual void modelChanged(); | |
247 virtual void modelChanged(size_t startFrame, size_t endFrame); | |
248 virtual void modelCompletionChanged(); | |
249 virtual void modelReplaced(); | |
250 virtual void layerParametersChanged(); | |
251 virtual void layerNameChanged(); | |
252 | |
253 virtual void viewManagerCentreFrameChanged(void *, unsigned long, bool); | |
254 virtual void viewManagerPlaybackFrameChanged(unsigned long); | |
255 virtual void viewManagerZoomLevelChanged(void *, unsigned long, bool); | |
256 | |
257 virtual void propertyContainerSelected(View *, PropertyContainer *pc); | |
258 | |
259 virtual void selectionChanged(); | |
260 virtual void toolModeChanged(); | |
261 | |
262 protected: | |
263 View(QWidget *, bool showProgress); | |
264 virtual void paintEvent(QPaintEvent *e); | |
265 virtual void drawSelections(QPainter &); | |
266 virtual bool shouldLabelSelections() const { return true; } | |
267 | |
268 typedef std::vector<Layer *> LayerList; | |
269 | |
270 int getModelsSampleRate() const; | |
271 bool areLayersScrollable() const; | |
272 LayerList getScrollableBackLayers(bool testChanged, bool &changed) const; | |
273 LayerList getNonScrollableFrontLayers(bool testChanged, bool &changed) const; | |
274 size_t getZoomConstraintBlockSize(size_t blockSize, | |
275 ZoomConstraint::RoundingDirection dir = | |
276 ZoomConstraint::RoundNearest) const; | |
277 | |
278 bool setCentreFrame(size_t f, bool doEmit); | |
279 | |
280 void checkProgress(void *object); | |
281 | |
282 size_t m_centreFrame; | |
283 int m_zoomLevel; | |
284 bool m_followPan; | |
285 bool m_followZoom; | |
286 PlaybackFollowMode m_followPlay; | |
287 size_t m_playPointerFrame; | |
288 bool m_lightBackground; | |
289 bool m_showProgress; | |
290 | |
291 QPixmap *m_cache; | |
292 size_t m_cacheCentreFrame; | |
293 int m_cacheZoomLevel; | |
294 bool m_selectionCached; | |
295 | |
296 bool m_deleting; | |
297 | |
298 LayerList m_layers; // I don't own these, but see dtor note above | |
299 bool m_haveSelectedLayer; | |
300 | |
301 // caches for use in getScrollableBackLayers, getNonScrollableFrontLayers | |
302 mutable LayerList m_lastScrollableBackLayers; | |
303 mutable LayerList m_lastNonScrollableBackLayers; | |
304 | |
305 class LayerProgressBar : public QProgressBar { | |
306 public: | |
307 LayerProgressBar(QWidget *parent); | |
308 virtual QString text() const { return m_text; } | |
309 virtual void setText(QString text) { m_text = text; } | |
310 protected: | |
311 QString m_text; | |
312 }; | |
313 | |
314 typedef std::map<Layer *, LayerProgressBar *> ProgressMap; | |
315 ProgressMap m_progressBars; // I own the ProgressBars | |
316 | |
317 ViewManager *m_manager; // I don't own this | |
318 ViewPropertyContainer *m_propertyContainer; // I own this | |
319 }; | |
320 | |
321 | |
322 // Use this for delegation, because we can't subclass from | |
323 // PropertyContainer (which is a QObject) ourselves because of | |
324 // ambiguity with QFrame parent | |
325 | |
326 class ViewPropertyContainer : public PropertyContainer | |
327 { | |
328 Q_OBJECT | |
329 | |
330 public: | |
331 ViewPropertyContainer(View *v); | |
332 PropertyList getProperties() const { return m_v->getProperties(); } | |
333 QString getPropertyLabel(const PropertyName &n) const { | |
334 return m_v->getPropertyLabel(n); | |
335 } | |
336 PropertyType getPropertyType(const PropertyName &n) const { | |
337 return m_v->getPropertyType(n); | |
338 } | |
339 int getPropertyRangeAndValue(const PropertyName &n, int *min, int *max) const { | |
340 return m_v->getPropertyRangeAndValue(n, min, max); | |
341 } | |
342 QString getPropertyValueLabel(const PropertyName &n, int value) const { | |
343 return m_v->getPropertyValueLabel(n, value); | |
344 } | |
345 QString getPropertyContainerName() const { | |
346 return m_v->getPropertyContainerName(); | |
347 } | |
348 QString getPropertyContainerIconName() const { | |
349 return m_v->getPropertyContainerIconName(); | |
350 } | |
351 | |
352 public slots: | |
353 virtual void setProperty(const PropertyName &n, int value) { | |
354 m_v->setProperty(n, value); | |
355 } | |
356 | |
357 protected: | |
358 View *m_v; | |
359 }; | |
360 | |
361 #endif | |
362 |