TimeValueLayer.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_TIME_VALUE_LAYER_H
17 #define SV_TIME_VALUE_LAYER_H
18 
19 #include "SingleColourLayer.h"
20 #include "VerticalScaleLayer.h"
21 #include "ColourScaleLayer.h"
22 
23 #include "data/model/SparseTimeValueModel.h"
24 
25 #include <QObject>
26 #include <QColor>
27 
28 class View;
29 class QPainter;
30 
32  public VerticalScaleLayer,
33  public ColourScaleLayer
34 {
35  Q_OBJECT
36 
37 public:
39 
40  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
41 
42  int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
43  void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
44 
45  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
46  QString getLabelPreceding(sv_frame_t) const override;
47 
48  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
49  int &resolution,
50  SnapType snap, int ycoord) const override;
51  bool snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame,
52  int &resolution,
53  SnapType snap) const override;
54 
55  void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
56  void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
57  void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
58 
59  void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
60  void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
61  void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
62 
63  void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
64  void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
65  void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
66 
67  bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
68 
69  void moveSelection(Selection s, sv_frame_t newStartFrame) override;
70  void resizeSelection(Selection s, Selection newSize) override;
71  void deleteSelection(Selection s) override;
72 
73  void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
74  bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
75  bool interactive) override;
76 
77  ModelId getModel() const override { return m_model; }
78  void setModel(ModelId model); // a SparseTimeValueModel
79 
80  PropertyList getProperties() const override;
81  QString getPropertyLabel(const PropertyName &) const override;
82  QString getPropertyIconName(const PropertyName &) const override;
83  PropertyType getPropertyType(const PropertyName &) const override;
84  QString getPropertyGroupName(const PropertyName &) const override;
85  int getPropertyRangeAndValue(const PropertyName &,
86  int *min, int *max, int *deflt) const override;
87  QString getPropertyValueLabel(const PropertyName &,
88  int value) const override;
89  void setProperty(const PropertyName &, int value) override;
90 
91  void setFillColourMap(int);
92  int getFillColourMap() const { return m_colourMap; }
93 
94  enum PlotStyle {
102  };
103 
104  void setPlotStyle(PlotStyle style);
105  PlotStyle getPlotStyle() const { return m_plotStyle; }
106 
112  };
113 
114  void setVerticalScale(VerticalScale scale);
116 
117  void setDrawSegmentDivisions(bool);
119 
120  void setShowDerivative(bool);
121  bool getShowDerivative() const { return m_derivative; }
122 
123  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
124 
125  bool isLayerEditable() const override { return true; }
126 
127  int getCompletion(LayerGeometryProvider *) const override;
128 
129  bool needsTextLabelHeight() const override;
130 
131  bool getValueExtents(double &min, double &max,
132  bool &logarithmic, QString &unit) const override;
133 
134  bool getDisplayExtents(double &min, double &max) const override;
135  bool setDisplayExtents(double min, double max) override;
136 
137  int getVerticalZoomSteps(int &defaultStep) const override;
138  int getCurrentVerticalZoomStep() const override;
139  void setVerticalZoomStep(int) override;
140  RangeMapper *getNewVerticalZoomRangeMapper() const override;
141 
142  void toXml(QTextStream &stream, QString indent = "",
143  QString extraAttributes = "") const override;
144 
145  void setProperties(const QXmlAttributes &attributes) override;
146 
149  if (m_plotStyle == PlotSegmentation) {
151  } else {
152  return ColourDistinguishes;
153  }
154  }
155 
157  bool hasLightBackground() const override {
158  if (m_plotStyle == PlotSegmentation) {
159  return true;
160  } else {
162  }
163  }
164 
166  int getYForValue(LayerGeometryProvider *, double value) const override;
167  double getValueForY(LayerGeometryProvider *, int y) const override;
168  QString getScaleUnits() const override;
169  QColor getColourForValue(LayerGeometryProvider *v, double value) const override;
170 
171 protected:
172  void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
173  bool shouldAutoAlign() const;
174 
175  EventVector getLocalPoints(LayerGeometryProvider *v, int) const;
176 
177  int getDefaultColourHint(bool dark, bool &impose) override;
178 
179  ModelId m_model;
180  bool m_editing;
183  ChangeEventsCommand *m_editingCommand;
190 
191  mutable double m_scaleMinimum;
192  mutable double m_scaleMaximum;
193 
194  void finish(ChangeEventsCommand *command) {
195  Command *c = command->finish();
196  if (c) CommandHistory::getInstance()->addCommand(c, false);
197  }
198 };
199 
200 #endif
201 
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
bool snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const override
Adjust the given frame to snap to the next feature that has "effectively" the same value as the featu...
ModelId getModel() const override
Return the ID of the model represented in this layer.
void editStart(LayerGeometryProvider *v, QMouseEvent *) override
void editEnd(LayerGeometryProvider *v, QMouseEvent *) override
QString getPropertyIconName(const PropertyName &) const override
void drawStart(LayerGeometryProvider *v, QMouseEvent *) override
void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const
void editDrag(LayerGeometryProvider *v, QMouseEvent *) override
void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override
void finish(ChangeEventsCommand *command)
RangeMapper * getNewVerticalZoomRangeMapper() const override
Create and return a range mapper for vertical zoom step values.
double getValueForY(LayerGeometryProvider *, int y) const override
void setPlotStyle(PlotStyle style)
void addCommand(Command *command)
Add a command to the command history.
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override
Paint the given rectangle of this layer onto the given view using the given painter, superimposing it on top of any existing material in that view.
ColourSignificance
Definition: Layer.h:348
bool getDisplayExtents(double &min, double &max) const override
Return the minimum and maximum values within the visible area for the y axis of this layer...
QString getScaleUnits() const override
void resizeSelection(Selection s, Selection newSize) override
VerticalScale m_verticalScale
void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override
PropertyList getProperties() const override
QString getPropertyValueLabel(const PropertyName &, int value) const override
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
Interface for layers in which the Y axis represents (or can sometimes represent, depending on the dis...
int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override
ColourSignificance getLayerColourSignificance() const override
Override from SingleColourLayer.
void setModel(ModelId model)
Interface for layers in which a colour scale represents (or can sometimes represent, depending on the display mode) the sample value.
bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive) override
Paste from the given clipboard onto the layer at the given frame offset.
void setProperty(const PropertyName &, int value) override
bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap, int ycoord) const override
Adjust the given frame to snap to the nearest feature, if possible.
void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override
bool isLayerEditable() const override
This should return true if the layer can be edited by the user.
QColor getColourForValue(LayerGeometryProvider *v, double value) const override
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
ChangeEventsCommand * m_editingCommand
SnapType
Definition: Layer.h:195
bool isLayerScrollable(const LayerGeometryProvider *v) const override
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
static CommandHistory * getInstance()
bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const override
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
PropertyType getPropertyType(const PropertyName &) const override
int getVerticalZoomSteps(int &defaultStep) const override
Get the number of vertical zoom steps available for this layer.
void setVerticalScale(VerticalScale scale)
EventVector getLocalPoints(LayerGeometryProvider *v, int) const
void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override
int getCurrentVerticalZoomStep() const override
Get the current vertical zoom step.
int getYForValue(LayerGeometryProvider *, double value) const override
VerticalScaleLayer and ColourScaleLayer methods.
bool setDisplayExtents(double min, double max) override
Set the displayed minimum and maximum values for the y axis to the given range, if supported...
void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override
PlotStyle getPlotStyle() const
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
QString getLabelPreceding(sv_frame_t) const override
VerticalScale getVerticalScale() const
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
void setDrawSegmentDivisions(bool)
bool shouldAutoAlign() const
bool getShowDerivative() const
void setVerticalZoomStep(int) override
Set the vertical zoom step.
bool m_drawSegmentDivisions
bool hasLightBackground() const override
Return true if the layer currently has a dark colour on a light background, false if it has a light c...
bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override
Open an editor on the item under the mouse (e.g.
int getDefaultColourHint(bool dark, bool &impose) override
void setShowDerivative(bool)
int getFillColourMap() const
PlotStyle m_plotStyle
bool needsTextLabelHeight() const override
True if this layer will need to place text labels when it is painted.
void moveSelection(Selection s, sv_frame_t newStartFrame) override
void setFillColourMap(int)
bool hasLightBackground() const override
Override from SingleColourLayer.
void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override
QString getPropertyLabel(const PropertyName &) const override
QString getPropertyGroupName(const PropertyName &) const override
bool getDrawSegmentDivisions() const
void deleteSelection(Selection s) override
void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override