Chris@0
|
1
|
Chris@0
|
2 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
3
|
Chris@0
|
4 /*
|
Chris@0
|
5 A waveform viewer and audio annotation editor.
|
Chris@2
|
6 Chris Cannam, Queen Mary University of London, 2005-2006
|
Chris@0
|
7
|
Chris@0
|
8 This is experimental software. Not for distribution.
|
Chris@0
|
9 */
|
Chris@0
|
10
|
Chris@26
|
11 #ifndef _LAYER_H_
|
Chris@26
|
12 #define _LAYER_H_
|
Chris@0
|
13
|
Chris@0
|
14 #include "PropertyContainer.h"
|
Chris@3
|
15 #include "XmlExportable.h"
|
Chris@0
|
16
|
Chris@0
|
17 #include <QObject>
|
Chris@0
|
18 #include <QRect>
|
Chris@6
|
19 #include <QXmlAttributes>
|
Chris@0
|
20
|
Chris@0
|
21 class ZoomConstraint;
|
Chris@0
|
22 class Model;
|
Chris@0
|
23 class QPainter;
|
Chris@0
|
24 class View;
|
Chris@12
|
25 class QMouseEvent;
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * The base class for visual representations of the data found in a
|
Chris@0
|
29 * Model. Layers are expected to be able to draw themselves onto a
|
Chris@0
|
30 * View, and may also be editable.
|
Chris@0
|
31 */
|
Chris@0
|
32
|
Chris@29
|
33 class Layer : public PropertyContainer,
|
Chris@3
|
34 public XmlExportable
|
Chris@0
|
35 {
|
Chris@0
|
36 Q_OBJECT
|
Chris@0
|
37
|
Chris@0
|
38 public:
|
Chris@0
|
39 Layer(View *w);
|
Chris@0
|
40 virtual ~Layer();
|
Chris@0
|
41
|
Chris@0
|
42 virtual const Model *getModel() const = 0;
|
Chris@0
|
43 virtual const ZoomConstraint *getZoomConstraint() const { return 0; }
|
Chris@0
|
44 virtual void paint(QPainter &, QRect) const = 0;
|
Chris@0
|
45
|
Chris@0
|
46 enum VerticalPosition {
|
Chris@0
|
47 PositionTop, PositionMiddle, PositionBottom
|
Chris@0
|
48 };
|
Chris@0
|
49 virtual VerticalPosition getPreferredTimeRulerPosition() const {
|
Chris@0
|
50 return PositionMiddle;
|
Chris@0
|
51 }
|
Chris@0
|
52 virtual VerticalPosition getPreferredFrameCountPosition() const {
|
Chris@0
|
53 return PositionBottom;
|
Chris@0
|
54 }
|
Chris@0
|
55
|
Chris@12
|
56 virtual QString getPropertyContainerIconName() const;
|
Chris@12
|
57
|
Chris@0
|
58 virtual QString getPropertyContainerName() const {
|
Chris@0
|
59 return objectName();
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 virtual int getVerticalScaleWidth(QPainter &) const { return 0; }
|
Chris@0
|
63 virtual void paintVerticalScale(QPainter &, QRect) const { }
|
Chris@0
|
64
|
Chris@20
|
65 virtual QString getFeatureDescription(QPoint &) const {
|
Chris@20
|
66 return "";
|
Chris@0
|
67 }
|
Chris@0
|
68
|
Chris@8
|
69 //!!! We also need a method (like the vertical scale method) for
|
Chris@8
|
70 //drawing additional scales like a colour scale. That is, unless
|
Chris@8
|
71 //all applicable layers can actually do this from
|
Chris@8
|
72 //paintVerticalScale as well?
|
Chris@8
|
73
|
Chris@23
|
74 enum SnapType {
|
Chris@23
|
75 SnapLeft,
|
Chris@23
|
76 SnapRight,
|
Chris@23
|
77 SnapNearest,
|
Chris@23
|
78 SnapNeighbouring
|
Chris@23
|
79 };
|
Chris@8
|
80
|
Chris@23
|
81 /**
|
Chris@23
|
82 * Adjust the given frame to snap to the nearest feature, if
|
Chris@23
|
83 * possible.
|
Chris@23
|
84 *
|
Chris@23
|
85 * If snap is SnapLeft or SnapRight, adjust the frame to match
|
Chris@23
|
86 * that of the nearest feature in the given direction regardless
|
Chris@23
|
87 * of how far away it is. If snap is SnapNearest, adjust the
|
Chris@23
|
88 * frame to that of the nearest feature in either direction. If
|
Chris@23
|
89 * snap is SnapNeighbouring, adjust the frame to that of the
|
Chris@23
|
90 * nearest feature if it is close, and leave it alone (returning
|
Chris@23
|
91 * false) otherwise. SnapNeighbouring should always choose the
|
Chris@23
|
92 * same feature that would be used in an editing operation through
|
Chris@23
|
93 * calls to editStart etc.
|
Chris@23
|
94 *
|
Chris@23
|
95 * Return true if a suitable feature was found and frame adjusted
|
Chris@23
|
96 * accordingly. Return false if no suitable feature was
|
Chris@23
|
97 * available. Also return the resolution of the model in this
|
Chris@23
|
98 * layer in sample frames.
|
Chris@23
|
99 */
|
Chris@23
|
100 virtual bool snapToFeatureFrame(int &frame,
|
Chris@23
|
101 size_t &resolution,
|
Chris@23
|
102 SnapType snap) const {
|
Chris@8
|
103 resolution = 1;
|
Chris@23
|
104 return false;
|
Chris@8
|
105 }
|
Chris@8
|
106
|
Chris@12
|
107 // Draw and edit modes:
|
Chris@8
|
108 //
|
Chris@12
|
109 // Layer needs to get actual mouse events, I guess. Draw mode is
|
Chris@8
|
110 // probably the easier.
|
Chris@8
|
111
|
Chris@13
|
112 virtual void drawStart(QMouseEvent *) { }
|
Chris@13
|
113 virtual void drawDrag(QMouseEvent *) { }
|
Chris@13
|
114 virtual void drawEnd(QMouseEvent *) { }
|
Chris@13
|
115
|
Chris@13
|
116 virtual void editStart(QMouseEvent *) { }
|
Chris@13
|
117 virtual void editDrag(QMouseEvent *) { }
|
Chris@13
|
118 virtual void editEnd(QMouseEvent *) { }
|
Chris@12
|
119
|
Chris@8
|
120 // Text mode:
|
Chris@8
|
121 //
|
Chris@8
|
122 // Label nearest feature. We need to get the feature coordinates
|
Chris@8
|
123 // and current label from the layer, and then the pane can pop up
|
Chris@8
|
124 // a little text entry dialog at the right location. Or we edit
|
Chris@8
|
125 // in place? Probably the dialog is easier.
|
Chris@8
|
126
|
Chris@0
|
127 /**
|
Chris@0
|
128 * This should return true if the view can safely be scrolled
|
Chris@0
|
129 * automatically by the widget (simply copying the existing data
|
Chris@0
|
130 * and then refreshing the exposed area) without altering its
|
Chris@0
|
131 * meaning. For the widget as a whole this is usually not
|
Chris@0
|
132 * possible because of invariant (non-scrolling) material
|
Chris@0
|
133 * displayed over the top, but the widget may be able to optimise
|
Chris@0
|
134 * scrolling better if it is known that individual views can be
|
Chris@0
|
135 * scrolled safely in this way.
|
Chris@0
|
136 */
|
Chris@0
|
137 virtual bool isLayerScrollable() const { return true; }
|
Chris@0
|
138
|
Chris@0
|
139 /**
|
Chris@10
|
140 * This should return true if the layer completely obscures any
|
Chris@10
|
141 * underlying layers. It's used to determine whether the view can
|
Chris@10
|
142 * safely draw any selection rectangles under the layer instead of
|
Chris@10
|
143 * over it, in the case where the layer is not scrollable and
|
Chris@10
|
144 * therefore needs to be redrawn each time (so that the selection
|
Chris@10
|
145 * rectangle can be cached).
|
Chris@10
|
146 */
|
Chris@10
|
147 virtual bool isLayerOpaque() const { return false; }
|
Chris@10
|
148
|
Chris@10
|
149 /**
|
Chris@18
|
150 * This should return true if the layer can be edited by the user.
|
Chris@18
|
151 * If this is the case, the appropriate edit tools may be made
|
Chris@18
|
152 * available by the application and the layer's drawStart/Drag/End
|
Chris@18
|
153 * and editStart/Drag/End methods should be implemented.
|
Chris@18
|
154 */
|
Chris@18
|
155 virtual bool isLayerEditable() const { return false; }
|
Chris@18
|
156
|
Chris@18
|
157 /**
|
Chris@0
|
158 * Return the proportion of background work complete in drawing
|
Chris@0
|
159 * this view, as a percentage -- in most cases this will be the
|
Chris@0
|
160 * value returned by pointer from a call to the underlying model's
|
Chris@0
|
161 * isReady(int *) call. The widget may choose to show a progress
|
Chris@0
|
162 * meter if it finds that this returns < 100 at any given moment.
|
Chris@0
|
163 */
|
Chris@0
|
164 virtual int getCompletion() const { return 100; }
|
Chris@0
|
165
|
Chris@0
|
166 virtual void setObjectName(const QString &name);
|
Chris@0
|
167
|
Chris@7
|
168 /**
|
Chris@15
|
169 * Return the pixel x-coordinate corresponding to a given sample
|
Chris@15
|
170 * frame (which may be negative).
|
Chris@15
|
171 */
|
Chris@15
|
172 int getXForFrame(long frame) const;
|
Chris@15
|
173
|
Chris@15
|
174 /**
|
Chris@15
|
175 * Return the closest frame to the given pixel x-coordinate.
|
Chris@15
|
176 */
|
Chris@15
|
177 long getFrameForX(int x) const;
|
Chris@15
|
178
|
Chris@15
|
179 /**
|
Chris@7
|
180 * Convert the layer's data (though not those of the model it
|
Chris@7
|
181 * refers to) into an XML string for file output. This class
|
Chris@7
|
182 * implements the basic name/type/model-id output; subclasses will
|
Chris@7
|
183 * typically call this superclass implementation with extra
|
Chris@7
|
184 * attributes describing their particular properties.
|
Chris@7
|
185 */
|
Chris@3
|
186 virtual QString toXmlString(QString indent = "",
|
Chris@3
|
187 QString extraAttributes = "") const;
|
Chris@3
|
188
|
Chris@7
|
189 /**
|
Chris@7
|
190 * Set the particular properties of a layer (those specific to the
|
Chris@7
|
191 * subclass) from a set of XML attributes. This is the effective
|
Chris@7
|
192 * inverse of the toXmlString method.
|
Chris@7
|
193 */
|
Chris@6
|
194 virtual void setProperties(const QXmlAttributes &) = 0;
|
Chris@6
|
195
|
Chris@24
|
196 /**
|
Chris@24
|
197 * Indicate that a layer is not currently visible and is not
|
Chris@24
|
198 * expected to become visible in the near future (for example
|
Chris@24
|
199 * because the user has explicitly removed or hidden it). The
|
Chris@24
|
200 * layer may respond by (for example) freeing any cache memory it
|
Chris@29
|
201 * is using, until next time its paint method is called. It does
|
Chris@29
|
202 * not need to remember not to draw itself; the view will handle
|
Chris@29
|
203 * that.
|
Chris@24
|
204 */
|
Chris@29
|
205 virtual void setLayerDormant(bool dormant) { m_dormant = dormant; }
|
Chris@24
|
206
|
Chris@29
|
207 /**
|
Chris@29
|
208 * Return whether the layer is dormant (i.e. hidden).
|
Chris@29
|
209 */
|
Chris@29
|
210 virtual bool isLayerDormant() const { return m_dormant; }
|
Chris@29
|
211
|
Chris@29
|
212 virtual PlayParameters *getPlayParameters();
|
Chris@29
|
213
|
Chris@29
|
214 public slots:
|
Chris@29
|
215 void showLayer(bool show);
|
Chris@28
|
216
|
Chris@0
|
217 signals:
|
Chris@0
|
218 void modelChanged();
|
Chris@0
|
219 void modelCompletionChanged();
|
Chris@0
|
220 void modelChanged(size_t startFrame, size_t endFrame);
|
Chris@0
|
221 void modelReplaced();
|
Chris@0
|
222
|
Chris@0
|
223 void layerParametersChanged();
|
Chris@0
|
224 void layerNameChanged();
|
Chris@0
|
225
|
Chris@0
|
226 protected:
|
Chris@0
|
227 View *m_view;
|
Chris@29
|
228 bool m_dormant;
|
Chris@0
|
229 };
|
Chris@0
|
230
|
Chris@0
|
231 #endif
|
Chris@0
|
232
|