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