Mercurial > hg > easaier-soundaccess
comparison view/View.h @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children | 7b19f2719f91 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
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 _VIEW_H_ | |
17 #define _VIEW_H_ | |
18 | |
19 #include <QFrame> | |
20 #include <QProgressBar> | |
21 | |
22 #include "base/ZoomConstraint.h" | |
23 #include "base/PropertyContainer.h" | |
24 #include "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 bool hasLightBackground() const; | |
175 | |
176 enum TextStyle { | |
177 BoxedText, | |
178 OutlinedText | |
179 }; | |
180 | |
181 virtual void drawVisibleText(QPainter &p, int x, int y, | |
182 QString text, TextStyle style); | |
183 | |
184 virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const { | |
185 return false; | |
186 } | |
187 virtual bool shouldIlluminateLocalSelection(QPoint &, bool &, bool &) const { | |
188 return false; | |
189 } | |
190 | |
191 virtual void setPlaybackFollow(PlaybackFollowMode m); | |
192 virtual PlaybackFollowMode getPlaybackFollow() const { return m_followPlay; } | |
193 | |
194 typedef PropertyContainer::PropertyName PropertyName; | |
195 | |
196 // We implement the PropertyContainer API, although we don't | |
197 // actually subclass PropertyContainer. We have our own | |
198 // PropertyContainer that we can return on request that just | |
199 // delegates back to us. | |
200 virtual PropertyContainer::PropertyList getProperties() const; | |
201 virtual QString getPropertyLabel(const PropertyName &) const; | |
202 virtual PropertyContainer::PropertyType getPropertyType(const PropertyName &) const; | |
203 virtual int getPropertyRangeAndValue(const PropertyName &, | |
204 int *min, int *max, int *deflt) const; | |
205 virtual QString getPropertyValueLabel(const PropertyName &, | |
206 int value) const; | |
207 virtual void setProperty(const PropertyName &, int value); | |
208 virtual QString getPropertyContainerName() const { | |
209 return objectName(); | |
210 } | |
211 virtual QString getPropertyContainerIconName() const = 0; | |
212 | |
213 virtual size_t getPropertyContainerCount() const; | |
214 | |
215 virtual const PropertyContainer *getPropertyContainer(size_t i) const; | |
216 virtual PropertyContainer *getPropertyContainer(size_t i); | |
217 | |
218 // Render the contents on a wide canvas | |
219 virtual QImage *toNewImage(size_t f0, size_t f1); | |
220 virtual QImage *toNewImage(); | |
221 virtual QSize getImageSize(size_t f0, size_t f1); | |
222 virtual QSize getImageSize(); | |
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 // First frame actually in model, to right of scale, if present | |
233 virtual size_t getFirstVisibleFrame() const; | |
234 virtual size_t getLastVisibleFrame() const; | |
235 | |
236 size_t getModelsStartFrame() const; | |
237 size_t getModelsEndFrame() const; | |
238 | |
239 signals: | |
240 void propertyContainerAdded(PropertyContainer *pc); | |
241 void propertyContainerRemoved(PropertyContainer *pc); | |
242 void propertyContainerPropertyChanged(PropertyContainer *pc); | |
243 void propertyContainerPropertyRangeChanged(PropertyContainer *pc); | |
244 void propertyContainerNameChanged(PropertyContainer *pc); | |
245 void propertyChanged(PropertyContainer::PropertyName); | |
246 | |
247 void centreFrameChanged(unsigned long frame, | |
248 bool globalScroll, | |
249 PlaybackFollowMode followMode); | |
250 | |
251 void zoomLevelChanged(unsigned long, bool); | |
252 | |
253 void contextHelpChanged(const QString &); | |
254 | |
255 public slots: | |
256 virtual void modelChanged(); | |
257 virtual void modelChanged(size_t startFrame, size_t endFrame); | |
258 virtual void modelCompletionChanged(); | |
259 virtual void modelReplaced(); | |
260 virtual void layerParametersChanged(); | |
261 virtual void layerParameterRangesChanged(); | |
262 virtual void layerNameChanged(); | |
263 | |
264 virtual void globalCentreFrameChanged(unsigned long); | |
265 virtual void viewCentreFrameChanged(View *, unsigned long); | |
266 virtual void viewManagerPlaybackFrameChanged(unsigned long); | |
267 virtual void viewZoomLevelChanged(View *, unsigned long, bool); | |
268 | |
269 virtual void propertyContainerSelected(View *, PropertyContainer *pc); | |
270 | |
271 virtual void selectionChanged(); | |
272 virtual void toolModeChanged(); | |
273 virtual void overlayModeChanged(); | |
274 virtual void zoomWheelsEnabledChanged(); | |
275 | |
276 protected: | |
277 View(QWidget *, bool showProgress); | |
278 virtual void paintEvent(QPaintEvent *e); | |
279 virtual void drawSelections(QPainter &); | |
280 virtual bool shouldLabelSelections() const { return true; } | |
281 virtual bool render(QPainter &paint, int x0, size_t f0, size_t f1); | |
282 | |
283 typedef std::vector<Layer *> LayerList; | |
284 | |
285 int getModelsSampleRate() const; | |
286 bool areLayersScrollable() const; | |
287 LayerList getScrollableBackLayers(bool testChanged, bool &changed) const; | |
288 LayerList getNonScrollableFrontLayers(bool testChanged, bool &changed) const; | |
289 size_t getZoomConstraintBlockSize(size_t blockSize, | |
290 ZoomConstraint::RoundingDirection dir = | |
291 ZoomConstraint::RoundNearest) const; | |
292 | |
293 // True if the top layer(s) use colours for meaningful things. If | |
294 // this is the case, selections will be shown using unfilled boxes | |
295 // rather than with a translucent fill. | |
296 bool areLayerColoursSignificant() const; | |
297 | |
298 // True if the top layer has a time axis on the x coordinate (this | |
299 // is generally the case except for spectrum/slice layers). It | |
300 // will not be possible to make or display selections if this is | |
301 // false. | |
302 bool hasTopLayerTimeXAxis() const; | |
303 | |
304 bool setCentreFrame(size_t f, bool doEmit); | |
305 | |
306 void checkProgress(void *object); | |
307 | |
308 size_t m_centreFrame; | |
309 int m_zoomLevel; | |
310 bool m_followPan; | |
311 bool m_followZoom; | |
312 PlaybackFollowMode m_followPlay; | |
313 size_t m_playPointerFrame; | |
314 bool m_lightBackground; | |
315 bool m_showProgress; | |
316 | |
317 QPixmap *m_cache; | |
318 size_t m_cacheCentreFrame; | |
319 int m_cacheZoomLevel; | |
320 bool m_selectionCached; | |
321 | |
322 bool m_deleting; | |
323 | |
324 LayerList m_layers; // I don't own these, but see dtor note above | |
325 bool m_haveSelectedLayer; | |
326 | |
327 // caches for use in getScrollableBackLayers, getNonScrollableFrontLayers | |
328 mutable LayerList m_lastScrollableBackLayers; | |
329 mutable LayerList m_lastNonScrollableBackLayers; | |
330 | |
331 class LayerProgressBar : public QProgressBar { | |
332 public: | |
333 LayerProgressBar(QWidget *parent); | |
334 virtual QString text() const { return m_text; } | |
335 virtual void setText(QString text) { m_text = text; } | |
336 protected: | |
337 QString m_text; | |
338 }; | |
339 | |
340 typedef std::map<Layer *, LayerProgressBar *> ProgressMap; | |
341 ProgressMap m_progressBars; // I own the ProgressBars | |
342 | |
343 ViewManager *m_manager; // I don't own this | |
344 ViewPropertyContainer *m_propertyContainer; // I own this | |
345 }; | |
346 | |
347 | |
348 // Use this for delegation, because we can't subclass from | |
349 // PropertyContainer (which is a QObject) ourselves because of | |
350 // ambiguity with QFrame parent | |
351 | |
352 class ViewPropertyContainer : public PropertyContainer | |
353 { | |
354 Q_OBJECT | |
355 | |
356 public: | |
357 ViewPropertyContainer(View *v); | |
358 PropertyList getProperties() const { return m_v->getProperties(); } | |
359 QString getPropertyLabel(const PropertyName &n) const { | |
360 return m_v->getPropertyLabel(n); | |
361 } | |
362 PropertyType getPropertyType(const PropertyName &n) const { | |
363 return m_v->getPropertyType(n); | |
364 } | |
365 int getPropertyRangeAndValue(const PropertyName &n, int *min, int *max, | |
366 int *deflt) const { | |
367 return m_v->getPropertyRangeAndValue(n, min, max, deflt); | |
368 } | |
369 QString getPropertyValueLabel(const PropertyName &n, int value) const { | |
370 return m_v->getPropertyValueLabel(n, value); | |
371 } | |
372 QString getPropertyContainerName() const { | |
373 return m_v->getPropertyContainerName(); | |
374 } | |
375 QString getPropertyContainerIconName() const { | |
376 return m_v->getPropertyContainerIconName(); | |
377 } | |
378 | |
379 public slots: | |
380 virtual void setProperty(const PropertyName &n, int value) { | |
381 m_v->setProperty(n, value); | |
382 } | |
383 | |
384 protected: | |
385 View *m_v; | |
386 }; | |
387 | |
388 #endif | |
389 |