Chris@0
|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 A waveform viewer and audio annotation editor.
|
Chris@2
|
5 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@0
|
6
|
Chris@0
|
7 This is experimental software. Not for distribution.
|
Chris@0
|
8 */
|
Chris@0
|
9
|
Chris@0
|
10 #ifndef _CANVAS_H_
|
Chris@0
|
11 #define _CANVAS_H_
|
Chris@0
|
12
|
Chris@0
|
13 #include <QFrame>
|
Chris@0
|
14 #include <QProgressBar>
|
Chris@0
|
15
|
Chris@0
|
16 #include "base/ZoomConstraint.h"
|
Chris@0
|
17 #include "base/PropertyContainer.h"
|
Chris@8
|
18 #include "base/ViewManager.h"
|
Chris@3
|
19 #include "base/XmlExportable.h"
|
Chris@0
|
20
|
Chris@0
|
21 class Layer;
|
Chris@29
|
22 class ViewPropertyContainer;
|
Chris@0
|
23
|
Chris@0
|
24 #include <map>
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * View is the base class of widgets that display one or more
|
Chris@0
|
28 * overlaid views of data against a horizontal time scale.
|
Chris@0
|
29 *
|
Chris@0
|
30 * A View may have any number of attached Layers, each of which
|
Chris@0
|
31 * is expected to have one data Model (although multiple views may
|
Chris@0
|
32 * share the same model).
|
Chris@0
|
33 *
|
Chris@0
|
34 * A View may be panned in time and zoomed, although the
|
Chris@0
|
35 * mechanisms for doing so (as well as any other operations and
|
Chris@0
|
36 * properties available) depend on the subclass.
|
Chris@0
|
37 */
|
Chris@0
|
38
|
Chris@0
|
39 class View : public QFrame,
|
Chris@3
|
40 public XmlExportable
|
Chris@0
|
41 {
|
Chris@0
|
42 Q_OBJECT
|
Chris@0
|
43
|
Chris@0
|
44 public:
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Deleting a View deletes all its views. However, it is
|
Chris@0
|
47 * also acceptable for the views to be deleted by other code (in
|
Chris@0
|
48 * which case they will remove themselves from this View
|
Chris@0
|
49 * automatically), or to be removed explicitly without deleting
|
Chris@0
|
50 * using removeLayer.
|
Chris@0
|
51 */
|
Chris@0
|
52 virtual ~View();
|
Chris@0
|
53
|
Chris@0
|
54 /**
|
Chris@0
|
55 * Retrieve the first visible sample frame on the widget.
|
Chris@0
|
56 * This is a calculated value based on the centre-frame, widget
|
Chris@0
|
57 * width and zoom level. The result may be negative.
|
Chris@0
|
58 */
|
Chris@0
|
59 virtual long getStartFrame() const;
|
Chris@0
|
60
|
Chris@0
|
61 /**
|
Chris@0
|
62 * Set the widget pan based on the given first visible frame. The
|
Chris@0
|
63 * frame value may be negative.
|
Chris@0
|
64 */
|
Chris@0
|
65 virtual void setStartFrame(long);
|
Chris@0
|
66
|
Chris@0
|
67 /**
|
Chris@0
|
68 * Return the centre frame of the visible widget. This is an
|
Chris@0
|
69 * exact value that does not depend on the zoom block size. Other
|
Chris@0
|
70 * frame values (start, end) are calculated from this based on the
|
Chris@0
|
71 * zoom and other factors.
|
Chris@0
|
72 */
|
Chris@0
|
73 virtual size_t getCentreFrame() const { return m_centreFrame; }
|
Chris@0
|
74
|
Chris@0
|
75 /**
|
Chris@0
|
76 * Set the centre frame of the visible widget.
|
Chris@0
|
77 */
|
Chris@0
|
78 virtual void setCentreFrame(size_t f) { setCentreFrame(f, true); }
|
Chris@0
|
79
|
Chris@0
|
80 /**
|
Chris@0
|
81 * Retrieve the last visible sample frame on the widget.
|
Chris@0
|
82 * This is a calculated value based on the centre-frame, widget
|
Chris@0
|
83 * width and zoom level.
|
Chris@0
|
84 */
|
Chris@0
|
85 virtual size_t getEndFrame() const;
|
Chris@0
|
86
|
Chris@0
|
87 /**
|
Chris@15
|
88 * Return the pixel x-coordinate corresponding to a given sample
|
Chris@15
|
89 * frame (which may be negative).
|
Chris@15
|
90 */
|
Chris@15
|
91 int getXForFrame(long frame) const;
|
Chris@15
|
92
|
Chris@15
|
93 /**
|
Chris@15
|
94 * Return the closest frame to the given pixel x-coordinate.
|
Chris@15
|
95 */
|
Chris@15
|
96 long getFrameForX(int x) const;
|
Chris@15
|
97
|
Chris@15
|
98 /**
|
Chris@22
|
99 * Return the zoom level, i.e. the number of frames per pixel
|
Chris@0
|
100 */
|
Chris@22
|
101 int getZoomLevel() const;
|
Chris@0
|
102
|
Chris@0
|
103 /**
|
Chris@0
|
104 * Set the zoom level, i.e. the number of frames per pixel. The
|
Chris@0
|
105 * centre frame will be unchanged; the start and end frames will
|
Chris@0
|
106 * change.
|
Chris@0
|
107 */
|
Chris@0
|
108 virtual void setZoomLevel(size_t z);
|
Chris@0
|
109
|
Chris@0
|
110 /**
|
Chris@0
|
111 * Zoom in or out.
|
Chris@0
|
112 */
|
Chris@0
|
113 virtual void zoom(bool in);
|
Chris@0
|
114
|
Chris@12
|
115 /**
|
Chris@12
|
116 * Scroll left or right by a smallish or largish amount.
|
Chris@12
|
117 */
|
Chris@12
|
118 virtual void scroll(bool right, bool lots);
|
Chris@12
|
119
|
Chris@0
|
120 virtual void addLayer(Layer *v);
|
Chris@0
|
121 virtual void removeLayer(Layer *v); // does not delete the layer
|
Chris@0
|
122 virtual int getLayerCount() const { return m_layers.size(); }
|
Chris@0
|
123
|
Chris@0
|
124 /**
|
Chris@0
|
125 * Return a layer, counted in stacking order. That is, layer 0 is
|
Chris@0
|
126 * the bottom layer and layer "getLayerCount()-1" is the top one.
|
Chris@0
|
127 */
|
Chris@0
|
128 virtual Layer *getLayer(int n) { return m_layers[n]; }
|
Chris@0
|
129
|
Chris@8
|
130 /**
|
Chris@8
|
131 * Return the layer last selected by the user. This is normally
|
Chris@8
|
132 * the top layer, the same as getLayer(getLayerCount()-1).
|
Chris@8
|
133 * However, if the user has selected the pane itself more recently
|
Chris@8
|
134 * than any of the layers on it, this function will return 0. It
|
Chris@8
|
135 * will also return 0 if there are no layers.
|
Chris@8
|
136 */
|
Chris@8
|
137 virtual Layer *getSelectedLayer();
|
Chris@8
|
138
|
Chris@0
|
139 virtual void setViewManager(ViewManager *m);
|
Chris@0
|
140
|
Chris@0
|
141 virtual void setFollowGlobalPan(bool f);
|
Chris@0
|
142 virtual bool getFollowGlobalPan() const { return m_followPan; }
|
Chris@0
|
143
|
Chris@0
|
144 virtual void setFollowGlobalZoom(bool f);
|
Chris@0
|
145 virtual bool getFollowGlobalZoom() const { return m_followZoom; }
|
Chris@0
|
146
|
Chris@0
|
147 virtual void setLightBackground(bool lb) { m_lightBackground = lb; }
|
Chris@0
|
148 virtual bool hasLightBackground() const { return m_lightBackground; }
|
Chris@0
|
149
|
Chris@0
|
150 virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) {
|
Chris@0
|
151 return false;
|
Chris@0
|
152 }
|
Chris@0
|
153
|
Chris@0
|
154 enum PlaybackFollowMode {
|
Chris@0
|
155 PlaybackScrollContinuous,
|
Chris@0
|
156 PlaybackScrollPage,
|
Chris@0
|
157 PlaybackIgnore
|
Chris@0
|
158 };
|
Chris@0
|
159 virtual void setPlaybackFollow(PlaybackFollowMode m);
|
Chris@0
|
160 virtual PlaybackFollowMode getPlaybackFollow() const { return m_followPlay; }
|
Chris@0
|
161
|
Chris@30
|
162 typedef PropertyContainer::PropertyName PropertyName;
|
Chris@30
|
163
|
Chris@29
|
164 // We implement the PropertyContainer API, although we don't
|
Chris@29
|
165 // actually subclass PropertyContainer. We have our own
|
Chris@29
|
166 // PropertyContainer that we can return on request that just
|
Chris@29
|
167 // delegates back to us.
|
Chris@29
|
168 virtual PropertyContainer::PropertyList getProperties() const;
|
Chris@30
|
169 virtual PropertyContainer::PropertyType getPropertyType(const PropertyName &) const;
|
Chris@30
|
170 virtual int getPropertyRangeAndValue(const PropertyName &,
|
Chris@29
|
171 int *min, int *max) const;
|
Chris@30
|
172 virtual QString getPropertyValueLabel(const PropertyName &,
|
Chris@0
|
173 int value) const;
|
Chris@30
|
174 virtual void setProperty(const PropertyName &, int value);
|
Chris@0
|
175 virtual QString getPropertyContainerName() const {
|
Chris@0
|
176 return objectName();
|
Chris@0
|
177 }
|
Chris@30
|
178 virtual QString getPropertyContainerIconName() const = 0;
|
Chris@0
|
179
|
Chris@29
|
180 virtual size_t getPropertyContainerCount() const;
|
Chris@29
|
181
|
Chris@29
|
182 virtual const PropertyContainer *getPropertyContainer(size_t i) const;
|
Chris@29
|
183 virtual PropertyContainer *getPropertyContainer(size_t i);
|
Chris@29
|
184
|
Chris@3
|
185 virtual QString toXmlString(QString indent = "",
|
Chris@3
|
186 QString extraAttributes = "") const;
|
Chris@3
|
187
|
Chris@0
|
188 signals:
|
Chris@0
|
189 void propertyContainerAdded(PropertyContainer *pc);
|
Chris@0
|
190 void propertyContainerRemoved(PropertyContainer *pc);
|
Chris@0
|
191 void propertyContainerPropertyChanged(PropertyContainer *pc);
|
Chris@0
|
192 void propertyContainerNameChanged(PropertyContainer *pc);
|
Chris@30
|
193 void propertyChanged(PropertyName);
|
Chris@0
|
194
|
Chris@0
|
195 void centreFrameChanged(void *, unsigned long, bool);
|
Chris@0
|
196 void zoomLevelChanged(void *, unsigned long, bool);
|
Chris@0
|
197
|
Chris@0
|
198 public slots:
|
Chris@0
|
199 virtual void modelChanged();
|
Chris@0
|
200 virtual void modelChanged(size_t startFrame, size_t endFrame);
|
Chris@0
|
201 virtual void modelCompletionChanged();
|
Chris@0
|
202 virtual void modelReplaced();
|
Chris@0
|
203 virtual void layerParametersChanged();
|
Chris@0
|
204 virtual void layerNameChanged();
|
Chris@0
|
205
|
Chris@0
|
206 virtual void viewManagerCentreFrameChanged(void *, unsigned long, bool);
|
Chris@0
|
207 virtual void viewManagerPlaybackFrameChanged(unsigned long);
|
Chris@0
|
208 virtual void viewManagerZoomLevelChanged(void *, unsigned long, bool);
|
Chris@0
|
209
|
Chris@0
|
210 virtual void propertyContainerSelected(PropertyContainer *pc);
|
Chris@0
|
211
|
Chris@9
|
212 virtual void selectionChanged();
|
Chris@8
|
213 virtual void toolModeChanged();
|
Chris@8
|
214
|
Chris@0
|
215 protected:
|
Chris@0
|
216 View(QWidget *, bool showProgress);
|
Chris@0
|
217 virtual void paintEvent(QPaintEvent *e);
|
Chris@9
|
218 virtual void drawSelections(QPainter &);
|
Chris@10
|
219 virtual bool shouldLabelSelections() const { return true; }
|
Chris@0
|
220
|
Chris@0
|
221 typedef std::vector<Layer *> LayerList;
|
Chris@0
|
222
|
Chris@0
|
223 size_t getModelsStartFrame() const;
|
Chris@0
|
224 size_t getModelsEndFrame() const;
|
Chris@0
|
225 int getModelsSampleRate() const;
|
Chris@0
|
226 bool areLayersScrollable() const;
|
Chris@0
|
227 LayerList getScrollableBackLayers(bool &changed) const;
|
Chris@0
|
228 LayerList getNonScrollableFrontLayers(bool &changed) const;
|
Chris@0
|
229 size_t getZoomConstraintBlockSize(size_t blockSize,
|
Chris@0
|
230 ZoomConstraint::RoundingDirection dir =
|
Chris@0
|
231 ZoomConstraint::RoundNearest) const;
|
Chris@0
|
232
|
Chris@10
|
233 bool setCentreFrame(size_t f, bool doEmit);
|
Chris@0
|
234
|
Chris@0
|
235 void checkProgress(void *object);
|
Chris@0
|
236
|
Chris@3
|
237 size_t m_centreFrame;
|
Chris@3
|
238 int m_zoomLevel;
|
Chris@3
|
239 bool m_followPan;
|
Chris@3
|
240 bool m_followZoom;
|
Chris@3
|
241 PlaybackFollowMode m_followPlay;
|
Chris@3
|
242 size_t m_playPointerFrame;
|
Chris@3
|
243 bool m_lightBackground;
|
Chris@3
|
244 bool m_showProgress;
|
Chris@0
|
245
|
Chris@3
|
246 QPixmap *m_cache;
|
Chris@3
|
247 size_t m_cacheCentreFrame;
|
Chris@3
|
248 int m_cacheZoomLevel;
|
Chris@9
|
249 bool m_selectionCached;
|
Chris@0
|
250
|
Chris@3
|
251 bool m_deleting;
|
Chris@0
|
252
|
Chris@3
|
253 LayerList m_layers; // I don't own these, but see dtor note above
|
Chris@8
|
254 bool m_haveSelectedLayer;
|
Chris@0
|
255
|
Chris@0
|
256 // caches for use in getScrollableBackLayers, getNonScrollableFrontLayers
|
Chris@0
|
257 mutable LayerList m_lastScrollableBackLayers;
|
Chris@0
|
258 mutable LayerList m_lastNonScrollableBackLayers;
|
Chris@0
|
259
|
Chris@0
|
260 class LayerProgressBar : public QProgressBar {
|
Chris@0
|
261 public:
|
Chris@16
|
262 LayerProgressBar(QWidget *parent);
|
Chris@0
|
263 virtual QString text() const { return m_text; }
|
Chris@0
|
264 virtual void setText(QString text) { m_text = text; }
|
Chris@0
|
265 protected:
|
Chris@0
|
266 QString m_text;
|
Chris@0
|
267 };
|
Chris@0
|
268
|
Chris@0
|
269 typedef std::map<Layer *, LayerProgressBar *> ProgressMap;
|
Chris@0
|
270 ProgressMap m_progressBars; // I own the ProgressBars
|
Chris@0
|
271
|
Chris@0
|
272 ViewManager *m_manager; // I don't own this
|
Chris@29
|
273 ViewPropertyContainer *m_propertyContainer; // I own this
|
Chris@29
|
274 };
|
Chris@29
|
275
|
Chris@29
|
276
|
Chris@29
|
277 // Use this for delegation, because we can't subclass from
|
Chris@29
|
278 // PropertyContainer (which is a QObject) ourselves because of
|
Chris@29
|
279 // ambiguity with QFrame parent
|
Chris@29
|
280
|
Chris@29
|
281 class ViewPropertyContainer : public PropertyContainer
|
Chris@29
|
282 {
|
Chris@29
|
283 Q_OBJECT
|
Chris@29
|
284
|
Chris@29
|
285 public:
|
Chris@29
|
286 ViewPropertyContainer(View *v);
|
Chris@29
|
287 PropertyList getProperties() const { return m_v->getProperties(); }
|
Chris@29
|
288 PropertyType getPropertyType(const PropertyName &n) const {
|
Chris@29
|
289 return m_v->getPropertyType(n);
|
Chris@29
|
290 }
|
Chris@29
|
291 int getPropertyRangeAndValue(const PropertyName &n, int *min, int *max) const {
|
Chris@29
|
292 return m_v->getPropertyRangeAndValue(n, min, max);
|
Chris@29
|
293 }
|
Chris@29
|
294 QString getPropertyValueLabel(const PropertyName &n, int value) const {
|
Chris@29
|
295 return m_v->getPropertyValueLabel(n, value);
|
Chris@29
|
296 }
|
Chris@29
|
297 QString getPropertyContainerName() const {
|
Chris@29
|
298 return m_v->getPropertyContainerName();
|
Chris@29
|
299 }
|
Chris@29
|
300 QString getPropertyContainerIconName() const {
|
Chris@30
|
301 return m_v->getPropertyContainerIconName();
|
Chris@29
|
302 }
|
Chris@29
|
303
|
Chris@29
|
304 public slots:
|
Chris@29
|
305 virtual void setProperty(const PropertyName &n, int value) {
|
Chris@29
|
306 m_v->setProperty(n, value);
|
Chris@29
|
307 }
|
Chris@29
|
308
|
Chris@29
|
309 protected:
|
Chris@29
|
310 View *m_v;
|
Chris@0
|
311 };
|
Chris@0
|
312
|
Chris@0
|
313 #endif
|
Chris@0
|
314
|