Chris@127
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@127
|
2
|
Chris@127
|
3 /*
|
Chris@127
|
4 Sonic Visualiser
|
Chris@127
|
5 An audio file viewer and annotation editor.
|
Chris@127
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@127
|
8
|
Chris@127
|
9 This program is free software; you can redistribute it and/or
|
Chris@127
|
10 modify it under the terms of the GNU General Public License as
|
Chris@127
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@127
|
12 License, or (at your option) any later version. See the file
|
Chris@127
|
13 COPYING included with this distribution for more information.
|
Chris@127
|
14 */
|
Chris@127
|
15
|
Chris@1407
|
16 #ifndef SV_LAYER_H
|
Chris@1407
|
17 #define SV_LAYER_H
|
Chris@127
|
18
|
Chris@128
|
19 #include "base/PropertyContainer.h"
|
Chris@128
|
20 #include "base/XmlExportable.h"
|
Chris@128
|
21 #include "base/Selection.h"
|
Chris@127
|
22
|
Chris@1469
|
23 #include "data/model/Model.h"
|
Chris@1469
|
24
|
Chris@376
|
25 #include "widgets/CommandHistory.h"
|
Chris@376
|
26
|
Chris@523
|
27 #include "system/System.h"
|
Chris@523
|
28
|
Chris@127
|
29 #include <QObject>
|
Chris@127
|
30 #include <QRect>
|
Chris@127
|
31 #include <QXmlAttributes>
|
Chris@131
|
32 #include <QMutex>
|
Chris@299
|
33 #include <QPixmap>
|
Chris@127
|
34
|
Chris@127
|
35 #include <map>
|
Chris@268
|
36 #include <set>
|
Chris@127
|
37
|
Chris@552
|
38 #include <iostream>
|
Chris@552
|
39
|
Chris@127
|
40 class ZoomConstraint;
|
Chris@127
|
41 class QPainter;
|
Chris@127
|
42 class View;
|
Chris@916
|
43 class LayerGeometryProvider;
|
Chris@127
|
44 class QMouseEvent;
|
Chris@127
|
45 class Clipboard;
|
Chris@187
|
46 class RangeMapper;
|
Chris@127
|
47
|
Chris@127
|
48 /**
|
Chris@127
|
49 * The base class for visual representations of the data found in a
|
Chris@127
|
50 * Model. Layers are expected to be able to draw themselves onto a
|
Chris@127
|
51 * View, and may also be editable.
|
Chris@127
|
52 */
|
Chris@127
|
53
|
Chris@127
|
54 class Layer : public PropertyContainer,
|
Chris@1266
|
55 public XmlExportable
|
Chris@127
|
56 {
|
Chris@127
|
57 Q_OBJECT
|
Chris@127
|
58
|
Chris@127
|
59 public:
|
Chris@127
|
60 Layer();
|
Chris@127
|
61 virtual ~Layer();
|
Chris@127
|
62
|
Chris@1469
|
63 /**
|
Chris@1469
|
64 * Return the ID of the model represented in this layer.
|
Chris@1469
|
65 */
|
Chris@1469
|
66 virtual ModelId getModel() const = 0;
|
Chris@947
|
67
|
Chris@137
|
68 /**
|
Chris@137
|
69 * Return a zoom constraint object defining the supported zoom
|
Chris@137
|
70 * levels for this layer. If this returns zero, the layer will
|
Chris@137
|
71 * support any integer zoom level.
|
Chris@137
|
72 */
|
Chris@127
|
73 virtual const ZoomConstraint *getZoomConstraint() const { return 0; }
|
Chris@137
|
74
|
Chris@137
|
75 /**
|
Chris@137
|
76 * Return true if this layer can handle zoom levels other than
|
Chris@137
|
77 * those supported by its zoom constraint (presumably less
|
Chris@137
|
78 * efficiently or accurately than the officially supported zoom
|
Chris@137
|
79 * levels). If true, the layer will unenthusistically accept any
|
Chris@137
|
80 * integer zoom level from 1 to the maximum returned by its zoom
|
Chris@137
|
81 * constraint.
|
Chris@137
|
82 */
|
Chris@137
|
83 virtual bool supportsOtherZoomLevels() const { return true; }
|
Chris@137
|
84
|
Chris@389
|
85 /**
|
Chris@389
|
86 * Paint the given rectangle of this layer onto the given view
|
Chris@389
|
87 * using the given painter, superimposing it on top of any
|
Chris@916
|
88 * existing material in that view. The LayerGeometryProvider (an
|
Chris@916
|
89 * interface implemented by View) is provided here because it is
|
Chris@916
|
90 * possible for one layer to exist in more than one view, so the
|
Chris@916
|
91 * dimensions of the view may vary from one paint call to another
|
Chris@916
|
92 * (without any view having been resized).
|
Chris@389
|
93 */
|
Chris@916
|
94 virtual void paint(LayerGeometryProvider *, QPainter &, QRect) const = 0;
|
Chris@127
|
95
|
Chris@389
|
96 /**
|
Chris@389
|
97 * Enable or disable synchronous painting. If synchronous
|
Chris@389
|
98 * painting is enabled, a call to paint() must complete painting
|
Chris@389
|
99 * the entire rectangle before it returns. If synchronous
|
Chris@389
|
100 * painting is disabled (which should be the default), the paint()
|
Chris@389
|
101 * call may defer painting some regions if data is not yet
|
Chris@389
|
102 * available, by calling back on its view to schedule another
|
Chris@389
|
103 * update. Synchronous painting is necessary when rendering to an
|
Chris@389
|
104 * image. Simple layer types will always paint synchronously, and
|
Chris@389
|
105 * so may ignore this.
|
Chris@389
|
106 */
|
Chris@389
|
107 virtual void setSynchronousPainting(bool /* synchronous */) { }
|
Chris@389
|
108
|
Chris@127
|
109 enum VerticalPosition {
|
Chris@1266
|
110 PositionTop, PositionMiddle, PositionBottom
|
Chris@127
|
111 };
|
Chris@127
|
112 virtual VerticalPosition getPreferredTimeRulerPosition() const {
|
Chris@1266
|
113 return PositionMiddle;
|
Chris@127
|
114 }
|
Chris@127
|
115 virtual VerticalPosition getPreferredFrameCountPosition() const {
|
Chris@1266
|
116 return PositionBottom;
|
Chris@127
|
117 }
|
Chris@224
|
118 virtual bool hasLightBackground() const {
|
Chris@224
|
119 return true;
|
Chris@224
|
120 }
|
Chris@127
|
121
|
Chris@1406
|
122 QString getPropertyContainerIconName() const override;
|
Chris@127
|
123
|
Chris@1406
|
124 QString getPropertyContainerName() const override {
|
Chris@363
|
125 if (m_presentationName != "") return m_presentationName;
|
Chris@1266
|
126 else return objectName();
|
Chris@127
|
127 }
|
Chris@127
|
128
|
Chris@363
|
129 virtual void setPresentationName(QString name);
|
Chris@363
|
130
|
Chris@127
|
131 virtual QString getLayerPresentationName() const;
|
Chris@299
|
132 virtual QPixmap getLayerPresentationPixmap(QSize) const { return QPixmap(); }
|
Chris@127
|
133
|
Chris@916
|
134 virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool detailed,
|
Chris@607
|
135 QPainter &) const = 0;
|
Chris@607
|
136
|
Chris@916
|
137 virtual void paintVerticalScale(LayerGeometryProvider *, bool /* detailed */,
|
Chris@607
|
138 QPainter &, QRect) const { }
|
Chris@127
|
139
|
Chris@1390
|
140 virtual int getHorizontalScaleHeight(LayerGeometryProvider *, QPainter &) const { return 0; }
|
Chris@1390
|
141
|
Chris@916
|
142 virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint /* cursorPos */,
|
Chris@127
|
143 std::vector<QRect> &) const {
|
Chris@127
|
144 return false;
|
Chris@127
|
145 }
|
Chris@916
|
146 virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const { }
|
Chris@127
|
147
|
Chris@916
|
148 virtual void paintMeasurementRects(LayerGeometryProvider *, QPainter &,
|
Chris@272
|
149 bool showFocus, QPoint focusPoint) const;
|
Chris@272
|
150
|
Chris@916
|
151 virtual bool nearestMeasurementRectChanged(LayerGeometryProvider *, QPoint prev,
|
Chris@272
|
152 QPoint now) const;
|
Chris@267
|
153
|
Chris@916
|
154 virtual QString getFeatureDescription(LayerGeometryProvider *, QPoint &) const {
|
Chris@1266
|
155 return "";
|
Chris@127
|
156 }
|
Chris@127
|
157
|
Chris@909
|
158 virtual QString getLabelPreceding(sv_frame_t /* frame */) const {
|
Chris@552
|
159 return "";
|
Chris@552
|
160 }
|
Chris@552
|
161
|
Chris@127
|
162 enum SnapType {
|
Chris@1266
|
163 SnapLeft,
|
Chris@1266
|
164 SnapRight,
|
Chris@1266
|
165 SnapNeighbouring
|
Chris@127
|
166 };
|
Chris@127
|
167
|
Chris@127
|
168 /**
|
Chris@127
|
169 * Adjust the given frame to snap to the nearest feature, if
|
Chris@127
|
170 * possible.
|
Chris@127
|
171 *
|
Chris@127
|
172 * If snap is SnapLeft or SnapRight, adjust the frame to match
|
Chris@127
|
173 * that of the nearest feature in the given direction regardless
|
Chris@1431
|
174 * of how far away it is. If snap is SnapNeighbouring, adjust the
|
Chris@1431
|
175 * frame to that of the nearest feature in either direction if it
|
Chris@1431
|
176 * is close, and leave it alone (returning false) otherwise.
|
Chris@1431
|
177 * SnapNeighbouring should always choose the same feature that
|
Chris@1431
|
178 * would be used in an editing operation through calls to
|
Chris@1431
|
179 * editStart etc.
|
Chris@127
|
180 *
|
Chris@127
|
181 * Return true if a suitable feature was found and frame adjusted
|
Chris@180
|
182 * accordingly. Return false if no suitable feature was available
|
Chris@517
|
183 * (and leave frame unmodified). If returning true, also return
|
Chris@517
|
184 * the resolution of the model in this layer in sample frames.
|
Chris@127
|
185 */
|
Chris@916
|
186 virtual bool snapToFeatureFrame(LayerGeometryProvider * /* v */,
|
Chris@1266
|
187 sv_frame_t & /* frame */,
|
Chris@1266
|
188 int &resolution,
|
Chris@1266
|
189 SnapType /* snap */) const {
|
Chris@1266
|
190 resolution = 1;
|
Chris@1266
|
191 return false;
|
Chris@127
|
192 }
|
Chris@127
|
193
|
Chris@517
|
194 /**
|
Chris@517
|
195 * Adjust the given frame to snap to the next feature that has
|
Chris@517
|
196 * "effectively" the same value as the feature prior to the given
|
Chris@517
|
197 * frame, if possible.
|
Chris@517
|
198 *
|
Chris@517
|
199 * The snap type must be SnapLeft (snap to the time of the next
|
Chris@517
|
200 * feature prior to the one preceding the given frame that has a
|
Chris@517
|
201 * similar value to it) or SnapRight (snap to the time of the next
|
Chris@517
|
202 * feature following the given frame that has a similar value to
|
Chris@517
|
203 * the feature preceding it). Other values are not permitted.
|
Chris@517
|
204 *
|
Chris@517
|
205 * Return true if a suitable feature was found and frame adjusted
|
Chris@517
|
206 * accordingly. Return false if no suitable feature was available
|
Chris@517
|
207 * (and leave frame unmodified). If returning true, also return
|
Chris@517
|
208 * the resolution of the model in this layer in sample frames.
|
Chris@517
|
209 */
|
Chris@916
|
210 virtual bool snapToSimilarFeature(LayerGeometryProvider * /* v */,
|
Chris@904
|
211 sv_frame_t & /* source frame */,
|
Chris@805
|
212 int &resolution,
|
Chris@517
|
213 SnapType /* snap */) const {
|
Chris@1266
|
214 resolution = 1;
|
Chris@1266
|
215 return false;
|
Chris@517
|
216 }
|
Chris@517
|
217
|
Chris@335
|
218 // Draw, erase, and edit modes:
|
Chris@127
|
219 //
|
Chris@127
|
220 // Layer needs to get actual mouse events, I guess. Draw mode is
|
Chris@127
|
221 // probably the easier.
|
Chris@127
|
222
|
Chris@916
|
223 virtual void drawStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
224 virtual void drawDrag(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
225 virtual void drawEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@127
|
226
|
Chris@916
|
227 virtual void eraseStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
228 virtual void eraseDrag(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
229 virtual void eraseEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@335
|
230
|
Chris@916
|
231 virtual void editStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
232 virtual void editDrag(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
233 virtual void editEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@127
|
234
|
Chris@916
|
235 virtual void splitStart(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
236 virtual void splitEnd(LayerGeometryProvider *, QMouseEvent *) { }
|
Chris@916
|
237 virtual void addNote(LayerGeometryProvider *, QMouseEvent *) { };
|
gyorgyf@635
|
238
|
Chris@267
|
239 // Measurement rectangle (or equivalent). Unlike draw and edit,
|
Chris@267
|
240 // the base Layer class can provide working implementations of
|
Chris@267
|
241 // these for most situations.
|
Chris@267
|
242 //
|
Chris@916
|
243 virtual void measureStart(LayerGeometryProvider *, QMouseEvent *);
|
Chris@916
|
244 virtual void measureDrag(LayerGeometryProvider *, QMouseEvent *);
|
Chris@916
|
245 virtual void measureEnd(LayerGeometryProvider *, QMouseEvent *);
|
Chris@916
|
246 virtual void measureDoubleClick(LayerGeometryProvider *, QMouseEvent *);
|
Chris@267
|
247
|
Chris@283
|
248 virtual bool haveCurrentMeasureRect() const {
|
Chris@283
|
249 return m_haveCurrentMeasureRect;
|
Chris@283
|
250 }
|
Chris@283
|
251 virtual void deleteCurrentMeasureRect(); // using a command
|
Chris@283
|
252
|
Chris@255
|
253 /**
|
Chris@255
|
254 * Open an editor on the item under the mouse (e.g. on
|
Chris@255
|
255 * double-click). If there is no item or editing is not
|
Chris@255
|
256 * supported, return false.
|
Chris@255
|
257 */
|
Chris@916
|
258 virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *) { return false; }
|
Chris@127
|
259
|
Chris@905
|
260 virtual void moveSelection(Selection, sv_frame_t /* newStartFrame */) { }
|
Chris@127
|
261 virtual void resizeSelection(Selection, Selection /* newSize */) { }
|
Chris@127
|
262 virtual void deleteSelection(Selection) { }
|
Chris@127
|
263
|
Chris@916
|
264 virtual void copy(LayerGeometryProvider *, Selection, Clipboard & /* to */) { }
|
Chris@127
|
265
|
Chris@127
|
266 /**
|
Chris@127
|
267 * Paste from the given clipboard onto the layer at the given
|
Chris@127
|
268 * frame offset. If interactive is true, the layer may ask the
|
Chris@127
|
269 * user about paste options through a dialog if desired, and may
|
Chris@127
|
270 * return false if the user cancelled the paste operation. This
|
Chris@127
|
271 * function should return true if a paste actually occurred.
|
Chris@127
|
272 */
|
Chris@916
|
273 virtual bool paste(LayerGeometryProvider *,
|
Chris@359
|
274 const Clipboard & /* from */,
|
Chris@904
|
275 sv_frame_t /* frameOffset */,
|
Chris@127
|
276 bool /* interactive */) { return false; }
|
Chris@127
|
277
|
Chris@127
|
278 // Text mode:
|
Chris@127
|
279 //
|
Chris@127
|
280 // Label nearest feature. We need to get the feature coordinates
|
Chris@127
|
281 // and current label from the layer, and then the pane can pop up
|
Chris@127
|
282 // a little text entry dialog at the right location. Or we edit
|
Chris@127
|
283 // in place? Probably the dialog is easier.
|
Chris@127
|
284
|
Chris@127
|
285 /**
|
Chris@127
|
286 * This should return true if the layer can safely be scrolled
|
Chris@127
|
287 * automatically by a given view (simply copying the existing data
|
Chris@127
|
288 * and then refreshing the exposed area) without altering its
|
Chris@127
|
289 * meaning. For the view widget as a whole this is usually not
|
Chris@127
|
290 * possible because of invariant (non-scrolling) material
|
Chris@127
|
291 * displayed over the top, but the widget may be able to optimise
|
Chris@127
|
292 * scrolling better if it is known that individual views can be
|
Chris@127
|
293 * scrolled safely in this way.
|
Chris@127
|
294 */
|
Chris@916
|
295 virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return true; }
|
Chris@127
|
296
|
Chris@127
|
297 /**
|
Chris@127
|
298 * This should return true if the layer completely obscures any
|
Chris@127
|
299 * underlying layers. It's used to determine whether the view can
|
Chris@127
|
300 * safely draw any selection rectangles under the layer instead of
|
Chris@127
|
301 * over it, in the case where the layer is not scrollable and
|
Chris@127
|
302 * therefore needs to be redrawn each time (so that the selection
|
Chris@127
|
303 * rectangle can be cached).
|
Chris@127
|
304 */
|
Chris@127
|
305 virtual bool isLayerOpaque() const { return false; }
|
Chris@127
|
306
|
Chris@287
|
307 enum ColourSignificance {
|
Chris@287
|
308 ColourAbsent,
|
Chris@287
|
309 ColourIrrelevant,
|
Chris@287
|
310 ColourDistinguishes,
|
Chris@287
|
311 ColourAndBackgroundSignificant,
|
Chris@287
|
312 ColourHasMeaningfulValue
|
Chris@287
|
313 };
|
Chris@287
|
314
|
Chris@127
|
315 /**
|
Chris@287
|
316 * This should return the degree of meaning associated with colour
|
Chris@287
|
317 * in this layer.
|
Chris@287
|
318 *
|
Chris@287
|
319 * If ColourAbsent, the layer does not use colour. If
|
Chris@287
|
320 * ColourIrrelevant, the layer is coloured and the colour may be
|
Chris@287
|
321 * set by the user, but it doesn't really matter what the colour
|
Chris@287
|
322 * is (for example, in a time ruler layer). If
|
Chris@287
|
323 * ColourDistinguishes, then the colour is used to distinguish
|
Chris@287
|
324 * this layer from other similar layers (e.g. for data layers).
|
Chris@287
|
325 * If ColourAndBackgroundSignificant, then the layer should be
|
Chris@287
|
326 * given greater weight than ColourDistinguishes layers when
|
Chris@287
|
327 * choosing a background colour (e.g. for waveforms). If
|
Chris@287
|
328 * ColourHasMeaningfulValue, colours are actually meaningful --
|
Chris@287
|
329 * the view will then show selections using unfilled rectangles
|
Chris@287
|
330 * instead of translucent filled rectangles, so as not to disturb
|
Chris@287
|
331 * the colours underneath.
|
Chris@183
|
332 */
|
Chris@287
|
333 virtual ColourSignificance getLayerColourSignificance() const = 0;
|
Chris@183
|
334
|
Chris@183
|
335 /**
|
Chris@127
|
336 * This should return true if the layer can be edited by the user.
|
Chris@127
|
337 * If this is the case, the appropriate edit tools may be made
|
Chris@127
|
338 * available by the application and the layer's drawStart/Drag/End
|
Chris@127
|
339 * and editStart/Drag/End methods should be implemented.
|
Chris@127
|
340 */
|
Chris@127
|
341 virtual bool isLayerEditable() const { return false; }
|
Chris@127
|
342
|
Chris@127
|
343 /**
|
Chris@127
|
344 * Return the proportion of background work complete in drawing
|
Chris@127
|
345 * this view, as a percentage -- in most cases this will be the
|
Chris@127
|
346 * value returned by pointer from a call to the underlying model's
|
Chris@226
|
347 * isReady(int *) call. The view may choose to show a progress
|
Chris@127
|
348 * meter if it finds that this returns < 100 at any given moment.
|
Chris@127
|
349 */
|
Chris@916
|
350 virtual int getCompletion(LayerGeometryProvider *) const { return 100; }
|
Chris@127
|
351
|
Chris@583
|
352 /**
|
Chris@583
|
353 * Return an error string if any errors have occurred while
|
Chris@583
|
354 * loading or processing data for the given view. Return the
|
Chris@583
|
355 * empty string if no error has occurred.
|
Chris@583
|
356 */
|
Chris@916
|
357 virtual QString getError(LayerGeometryProvider *) const { return ""; }
|
Chris@583
|
358
|
Chris@127
|
359 virtual void setObjectName(const QString &name);
|
Chris@127
|
360
|
Chris@127
|
361 /**
|
Chris@127
|
362 * Convert the layer's data (though not those of the model it
|
Chris@316
|
363 * refers to) into XML for file output. This class implements the
|
Chris@316
|
364 * basic name/type/model-id output; subclasses will typically call
|
Chris@316
|
365 * this superclass implementation with extra attributes describing
|
Chris@316
|
366 * their particular properties.
|
Chris@127
|
367 */
|
Chris@1406
|
368 void toXml(QTextStream &stream, QString indent = "",
|
Chris@1406
|
369 QString extraAttributes = "") const override;
|
Chris@127
|
370
|
Chris@127
|
371 /**
|
Chris@127
|
372 * Set the particular properties of a layer (those specific to the
|
Chris@127
|
373 * subclass) from a set of XML attributes. This is the effective
|
Chris@316
|
374 * inverse of the toXml method.
|
Chris@127
|
375 */
|
Chris@127
|
376 virtual void setProperties(const QXmlAttributes &) = 0;
|
Chris@127
|
377
|
Chris@127
|
378 /**
|
Chris@316
|
379 * Produce XML containing the layer's ID and type. This is used
|
Chris@316
|
380 * to refer to the layer in the display section of the SV session
|
Chris@316
|
381 * file, for a layer that has already been described in the data
|
Chris@316
|
382 * section.
|
Chris@269
|
383 */
|
Chris@316
|
384 virtual void toBriefXml(QTextStream &stream,
|
Chris@316
|
385 QString indent = "",
|
Chris@316
|
386 QString extraAttributes = "") const;
|
Chris@269
|
387
|
Chris@269
|
388 /**
|
Chris@269
|
389 * Add a measurement rectangle from the given XML attributes
|
Chris@269
|
390 * (presumably taken from a measurement element).
|
Chris@269
|
391 * Does not use a command.
|
Chris@269
|
392 */
|
Chris@269
|
393 virtual void addMeasurementRect(const QXmlAttributes &);
|
Chris@269
|
394
|
Chris@269
|
395 /**
|
Chris@127
|
396 * Indicate that a layer is not currently visible in the given
|
Chris@127
|
397 * view and is not expected to become visible in the near future
|
Chris@127
|
398 * (for example because the user has explicitly removed or hidden
|
Chris@127
|
399 * it). The layer may respond by (for example) freeing any cache
|
Chris@127
|
400 * memory it is using, until next time its paint method is called,
|
Chris@127
|
401 * when it should set itself un-dormant again.
|
Chris@131
|
402 *
|
Chris@131
|
403 * A layer class that overrides this function must also call this
|
Chris@131
|
404 * class's implementation.
|
Chris@127
|
405 */
|
Chris@916
|
406 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
|
Chris@127
|
407
|
Chris@127
|
408 /**
|
Chris@127
|
409 * Return whether the layer is dormant (i.e. hidden) in the given
|
Chris@127
|
410 * view.
|
Chris@127
|
411 */
|
Chris@916
|
412 virtual bool isLayerDormant(const LayerGeometryProvider *v) const;
|
Chris@127
|
413
|
Chris@1406
|
414 PlayParameters *getPlayParameters() override;
|
Chris@127
|
415
|
Chris@1391
|
416 /**
|
Chris@1391
|
417 * True if this layer will need to place text labels when it is
|
Chris@1391
|
418 * painted. The view will take into account how many layers are
|
Chris@1391
|
419 * requesting this, and will provide a distinct y-coord to each
|
Chris@1391
|
420 * layer on request via View::getTextLabelHeight().
|
Chris@1391
|
421 */
|
Chris@127
|
422 virtual bool needsTextLabelHeight() const { return false; }
|
Chris@127
|
423
|
Chris@1389
|
424 /**
|
Chris@1389
|
425 * Return true if the X axis on the layer is time proportional to
|
Chris@1389
|
426 * audio frames, false otherwise. Almost all layer types return
|
Chris@1389
|
427 * true here: the exceptions are spectrum and slice layers.
|
Chris@1389
|
428 */
|
Chris@217
|
429 virtual bool hasTimeXAxis() const { return true; }
|
Chris@217
|
430
|
Chris@127
|
431 /**
|
Chris@1389
|
432 * Update the X and Y axis scales, where appropriate, to focus on
|
Chris@1389
|
433 * the given rectangular region. This should *only* be overridden
|
Chris@1389
|
434 * by layers whose hasTimeXAxis() returns false - the pane handles
|
Chris@1389
|
435 * zooming appropriately in every "normal" case.
|
Chris@1389
|
436 */
|
Chris@1389
|
437 virtual void zoomToRegion(const LayerGeometryProvider *, QRect) {
|
Chris@1389
|
438 return;
|
Chris@1389
|
439 }
|
Chris@1389
|
440
|
Chris@1389
|
441 /**
|
Chris@127
|
442 * Return the minimum and maximum values for the y axis of the
|
Chris@127
|
443 * model in this layer, as well as whether the layer is configured
|
Chris@127
|
444 * to use a logarithmic y axis display. Also return the unit for
|
Chris@127
|
445 * these values if known.
|
Chris@127
|
446 *
|
Chris@127
|
447 * This function returns the "normal" extents for the layer, not
|
Chris@127
|
448 * necessarily the extents actually in use in the display.
|
Chris@127
|
449 */
|
Chris@904
|
450 virtual bool getValueExtents(double &min, double &max,
|
Chris@127
|
451 bool &logarithmic, QString &unit) const = 0;
|
Chris@127
|
452
|
Chris@127
|
453 /**
|
Chris@127
|
454 * Return the minimum and maximum values within the displayed
|
Chris@127
|
455 * range for the y axis, if only a subset of the whole range of
|
Chris@127
|
456 * the model (returned by getValueExtents) is being displayed.
|
Chris@127
|
457 * Return false if the layer is not imposing a particular display
|
Chris@127
|
458 * extent (using the normal layer extents or deferring to whatever
|
Chris@127
|
459 * is in use for the same units elsewhere in the view).
|
Chris@127
|
460 */
|
Chris@904
|
461 virtual bool getDisplayExtents(double & /* min */,
|
Chris@904
|
462 double & /* max */) const {
|
Chris@127
|
463 return false;
|
Chris@127
|
464 }
|
Chris@127
|
465
|
Chris@127
|
466 /**
|
Chris@127
|
467 * Set the displayed minimum and maximum values for the y axis to
|
Chris@127
|
468 * the given range, if supported. Return false if not supported
|
Chris@127
|
469 * on this layer (and set nothing). In most cases, layers that
|
Chris@127
|
470 * return false for getDisplayExtents should also return false for
|
Chris@127
|
471 * this function.
|
Chris@127
|
472 */
|
Chris@904
|
473 virtual bool setDisplayExtents(double /* min */,
|
Chris@904
|
474 double /* max */) {
|
Chris@127
|
475 return false;
|
Chris@127
|
476 }
|
Chris@127
|
477
|
Chris@133
|
478 /**
|
Chris@260
|
479 * Return the value and unit at the given x coordinate in the
|
Chris@260
|
480 * given view. This is for descriptive purposes using the
|
Chris@260
|
481 * measurement tool. The default implementation works correctly
|
Chris@260
|
482 * if the layer hasTimeXAxis().
|
Chris@260
|
483 */
|
Chris@916
|
484 virtual bool getXScaleValue(const LayerGeometryProvider *v, int x,
|
Chris@904
|
485 double &value, QString &unit) const;
|
Chris@260
|
486
|
Chris@260
|
487 /**
|
Chris@260
|
488 * Return the value and unit at the given y coordinate in the
|
Chris@260
|
489 * given view.
|
Chris@260
|
490 */
|
Chris@916
|
491 virtual bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
|
Chris@904
|
492 double &/* value */, QString &/* unit */) const {
|
Chris@260
|
493 return false;
|
Chris@260
|
494 }
|
Chris@260
|
495
|
Chris@260
|
496 /**
|
Chris@274
|
497 * Return the difference between the values at the given y
|
Chris@274
|
498 * coordinates in the given view, and the unit of the difference.
|
Chris@274
|
499 * The default implementation just calls getYScaleValue twice and
|
Chris@274
|
500 * returns the difference, with the same unit.
|
Chris@274
|
501 */
|
Chris@916
|
502 virtual bool getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1,
|
Chris@904
|
503 double &diff, QString &unit) const;
|
Chris@274
|
504
|
Chris@274
|
505 /**
|
Chris@133
|
506 * Get the number of vertical zoom steps available for this layer.
|
Chris@133
|
507 * If vertical zooming is not available, return 0. The meaning of
|
Chris@133
|
508 * "zooming" is entirely up to the layer -- changing the zoom
|
Chris@133
|
509 * level may cause the layer to reset its display extents or
|
Chris@180
|
510 * change another property such as display gain. However, layers
|
Chris@180
|
511 * are advised for consistency to treat smaller zoom steps as
|
Chris@180
|
512 * "more distant" or "zoomed out" and larger ones as "closer" or
|
Chris@180
|
513 * "zoomed in".
|
Chris@180
|
514 *
|
Chris@133
|
515 * Layers that provide this facility should also emit the
|
Chris@133
|
516 * verticalZoomChanged signal if their vertical zoom changes
|
Chris@133
|
517 * due to factors other than setVerticalZoomStep being called.
|
Chris@133
|
518 */
|
Chris@248
|
519 virtual int getVerticalZoomSteps(int & /* defaultStep */) const { return 0; }
|
Chris@133
|
520
|
Chris@133
|
521 /**
|
Chris@133
|
522 * Get the current vertical zoom step. A layer may support finer
|
Chris@133
|
523 * control over ranges etc than is available through the integer
|
Chris@133
|
524 * zoom step mechanism; if this one does, it should just return
|
Chris@133
|
525 * the nearest of the available zoom steps to the current settings.
|
Chris@133
|
526 */
|
Chris@133
|
527 virtual int getCurrentVerticalZoomStep() const { return 0; }
|
Chris@133
|
528
|
Chris@133
|
529 /**
|
Chris@133
|
530 * Set the vertical zoom step. The meaning of "zooming" is
|
Chris@133
|
531 * entirely up to the layer -- changing the zoom level may cause
|
Chris@133
|
532 * the layer to reset its display extents or change another
|
Chris@133
|
533 * property such as display gain.
|
Chris@133
|
534 */
|
Chris@133
|
535 virtual void setVerticalZoomStep(int) { }
|
Chris@133
|
536
|
Chris@187
|
537 /**
|
Chris@187
|
538 * Create and return a range mapper for vertical zoom step values.
|
Chris@187
|
539 * See the RangeMapper documentation for more details. The
|
Chris@187
|
540 * returned value is allocated on the heap and will be deleted by
|
Chris@187
|
541 * the caller.
|
Chris@187
|
542 */
|
Chris@187
|
543 virtual RangeMapper *getNewVerticalZoomRangeMapper() const { return 0; }
|
Chris@187
|
544
|
Chris@947
|
545 /**
|
Chris@947
|
546 * Return true if this layer type can function without a model
|
Chris@947
|
547 * being set. If false (the default), the layer will not be loaded
|
Chris@947
|
548 * from a session if its model cannot be found.
|
Chris@947
|
549 */
|
Chris@947
|
550 virtual bool canExistWithoutModel() const { return false; }
|
Chris@947
|
551
|
Chris@127
|
552 public slots:
|
Chris@1456
|
553 /**
|
Chris@1456
|
554 * Change the visibility status (dormancy) of the layer in the
|
Chris@1456
|
555 * given view.
|
Chris@1456
|
556 */
|
Chris@916
|
557 void showLayer(LayerGeometryProvider *, bool show);
|
Chris@127
|
558
|
Chris@127
|
559 signals:
|
Chris@127
|
560 void modelChanged();
|
Chris@127
|
561 void modelCompletionChanged();
|
Chris@320
|
562 void modelAlignmentCompletionChanged();
|
Chris@906
|
563 void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
|
Chris@127
|
564 void modelReplaced();
|
Chris@127
|
565
|
Chris@127
|
566 void layerParametersChanged();
|
Chris@197
|
567 void layerParameterRangesChanged();
|
Chris@268
|
568 void layerMeasurementRectsChanged();
|
Chris@127
|
569 void layerNameChanged();
|
Chris@127
|
570
|
Chris@133
|
571 void verticalZoomChanged();
|
Chris@133
|
572
|
Chris@267
|
573 protected:
|
Chris@1469
|
574 void connectSignals(ModelId);
|
Chris@320
|
575
|
Chris@916
|
576 virtual sv_frame_t alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const;
|
Chris@916
|
577 virtual sv_frame_t alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const;
|
Chris@916
|
578 bool clipboardHasDifferentAlignment(LayerGeometryProvider *v, const Clipboard &clip) const;
|
Chris@359
|
579
|
Chris@267
|
580 struct MeasureRect {
|
Chris@268
|
581
|
Chris@267
|
582 mutable QRect pixrect;
|
Chris@268
|
583 bool haveFrames;
|
Chris@905
|
584 sv_frame_t startFrame; // only valid if haveFrames
|
Chris@905
|
585 sv_frame_t endFrame; // ditto
|
Chris@273
|
586 double startY;
|
Chris@273
|
587 double endY;
|
Chris@268
|
588
|
Chris@268
|
589 bool operator<(const MeasureRect &mr) const;
|
Chris@316
|
590 void toXml(QTextStream &stream, QString indent) const;
|
Chris@267
|
591 };
|
Chris@267
|
592
|
Chris@268
|
593 class AddMeasurementRectCommand : public Command
|
Chris@268
|
594 {
|
Chris@268
|
595 public:
|
Chris@268
|
596 AddMeasurementRectCommand(Layer *layer, MeasureRect rect) :
|
Chris@268
|
597 m_layer(layer), m_rect(rect) { }
|
Chris@268
|
598
|
Chris@1406
|
599 QString getName() const override;
|
Chris@1406
|
600 void execute() override;
|
Chris@1406
|
601 void unexecute() override;
|
Chris@268
|
602
|
Chris@268
|
603 private:
|
Chris@268
|
604 Layer *m_layer;
|
Chris@268
|
605 MeasureRect m_rect;
|
Chris@268
|
606 };
|
Chris@268
|
607
|
Chris@283
|
608 class DeleteMeasurementRectCommand : public Command
|
Chris@283
|
609 {
|
Chris@283
|
610 public:
|
Chris@283
|
611 DeleteMeasurementRectCommand(Layer *layer, MeasureRect rect) :
|
Chris@283
|
612 m_layer(layer), m_rect(rect) { }
|
Chris@283
|
613
|
Chris@1406
|
614 QString getName() const override;
|
Chris@1406
|
615 void execute() override;
|
Chris@1406
|
616 void unexecute() override;
|
Chris@283
|
617
|
Chris@283
|
618 private:
|
Chris@283
|
619 Layer *m_layer;
|
Chris@283
|
620 MeasureRect m_rect;
|
Chris@283
|
621 };
|
Chris@283
|
622
|
Chris@269
|
623 void addMeasureRectToSet(const MeasureRect &r) {
|
Chris@268
|
624 m_measureRects.insert(r);
|
Chris@268
|
625 emit layerMeasurementRectsChanged();
|
Chris@268
|
626 }
|
Chris@268
|
627
|
Chris@269
|
628 void deleteMeasureRectFromSet(const MeasureRect &r) {
|
Chris@268
|
629 m_measureRects.erase(r);
|
Chris@268
|
630 emit layerMeasurementRectsChanged();
|
Chris@268
|
631 }
|
Chris@268
|
632
|
Chris@268
|
633 typedef std::set<MeasureRect> MeasureRectSet;
|
Chris@268
|
634 MeasureRectSet m_measureRects;
|
Chris@267
|
635 MeasureRect m_draggingRect;
|
Chris@267
|
636 bool m_haveDraggingRect;
|
Chris@283
|
637 mutable bool m_haveCurrentMeasureRect;
|
Chris@283
|
638 mutable QPoint m_currentMeasureRectPoint;
|
Chris@272
|
639
|
Chris@272
|
640 // Note that pixrects are only correct for a single view.
|
Chris@272
|
641 // So we should update them at the start of the paint procedure
|
Chris@272
|
642 // (painting is single threaded) and only use them after that.
|
Chris@916
|
643 void updateMeasurePixrects(LayerGeometryProvider *v) const;
|
Chris@273
|
644
|
Chris@916
|
645 virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const;
|
Chris@916
|
646 virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const;
|
Chris@916
|
647 virtual void setMeasureRectFromPixrect(LayerGeometryProvider *v, MeasureRect &r, QRect pixrect) const;
|
Chris@272
|
648
|
Chris@272
|
649 // This assumes updateMeasurementPixrects has been called
|
Chris@272
|
650 MeasureRectSet::const_iterator findFocusedMeasureRect(QPoint) const;
|
Chris@267
|
651
|
Chris@916
|
652 void paintMeasurementRect(LayerGeometryProvider *v, QPainter &paint,
|
Chris@270
|
653 const MeasureRect &r, bool focus) const;
|
Chris@268
|
654
|
Chris@1315
|
655 bool valueExtentsMatchMine(LayerGeometryProvider *v) const;
|
Chris@1315
|
656
|
Chris@363
|
657 QString m_presentationName;
|
Chris@363
|
658
|
Chris@131
|
659 private:
|
Chris@131
|
660 mutable QMutex m_dormancyMutex;
|
Chris@127
|
661 mutable std::map<const void *, bool> m_dormancy;
|
Chris@127
|
662 };
|
Chris@127
|
663
|
Chris@127
|
664 #endif
|
Chris@127
|
665
|