annotate base/Layer.h @ 35:0164c8d3023b

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