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