BoxLayer.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 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef SV_BOX_LAYER_H
16 #define SV_BOX_LAYER_H
17 
18 #include "SingleColourLayer.h"
19 #include "VerticalScaleLayer.h"
20 
21 #include "data/model/BoxModel.h"
22 
23 #include <QObject>
24 #include <QColor>
25 
26 #include <map>
27 
28 class View;
29 class QPainter;
30 
31 class BoxLayer : public SingleColourLayer,
32  public VerticalScaleLayer
33 {
34  Q_OBJECT
35 
36 public:
37  BoxLayer();
38 
39  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
40 
41  int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
42  void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
43 
44  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
45  QString getLabelPreceding(sv_frame_t) const override;
46 
47  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
48  int &resolution,
49  SnapType snap, int ycoord) const override;
50 
51  void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
52  void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
53  void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
54 
55  void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
56  void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
57  void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
58 
59  void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
60  void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
61  void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
62 
63  bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
64 
65  void moveSelection(Selection s, sv_frame_t newStartFrame) override;
66  void resizeSelection(Selection s, Selection newSize) override;
67  void deleteSelection(Selection s) override;
68 
69  void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
70  bool paste(LayerGeometryProvider *v, const Clipboard &from,
71  sv_frame_t frameOffset, bool interactive) override;
72 
73  ModelId getModel() const override { return m_model; }
74  void setModel(ModelId model); // a BoxModel
75 
76  PropertyList getProperties() const override;
77  QString getPropertyLabel(const PropertyName &) const override;
78  PropertyType getPropertyType(const PropertyName &) const override;
79  QString getPropertyGroupName(const PropertyName &) const override;
80  int getPropertyRangeAndValue(const PropertyName &,
81  int *min, int *max, int *deflt) const override;
82  QString getPropertyValueLabel(const PropertyName &,
83  int value) const override;
84  void setProperty(const PropertyName &, int value) override;
85 
90  };
91 
92  void setVerticalScale(VerticalScale scale);
94 
95  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
96 
97  bool isLayerEditable() const override { return true; }
98 
99  int getCompletion(LayerGeometryProvider *) const override;
100 
101  bool getValueExtents(double &min, double &max,
102  bool &log, QString &unit) const override;
103 
104  bool getDisplayExtents(double &min, double &max) const override;
105 
106  bool adoptExtents(double min, double max, QString unit) override;
107 
108  void toXml(QTextStream &stream, QString indent = "",
109  QString extraAttributes = "") const override;
110 
111  void setProperties(const QXmlAttributes &attributes) override;
112 
114  int getYForValue(LayerGeometryProvider *v, double value) const override;
115  double getValueForY(LayerGeometryProvider *v, int y) const override;
116  QString getScaleUnits() const override;
117 
118 protected:
119  void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
120 
121  // Return the event that "most closely contains" the given
122  // coordinates, if any; or the closest event that spans the given
123  // x coordinate in the time axis; or false otherwise. This
124  // subsumes the uses of both getPointToDrag and getLocalPoints in
125  // some other layer implementations.
126  bool getLocalPoint(LayerGeometryProvider *v, int x, int y, Event &) const;
127 
128  ModelId m_model;
129  bool m_editing;
136  ChangeEventsCommand *m_editingCommand;
138 
139  std::pair<float, float> getRange(const Event &e) const {
140  return { e.getValue(), e.getValue() + fabsf(e.getLevel()) };
141  }
142 
143  void finish(ChangeEventsCommand *command) {
144  Command *c = command->finish();
145  if (c) CommandHistory::getInstance()->addCommand(c, false);
146  }
147 };
148 
149 #endif
150 
QString getPropertyGroupName(const PropertyName &) const override
Definition: BoxLayer.cpp:113
bool getLocalPoint(LayerGeometryProvider *v, int x, int y, Event &) const
Definition: BoxLayer.cpp:243
VerticalScale
Definition: BoxLayer.h:86
void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override
Definition: BoxLayer.cpp:1091
PropertyType getPropertyType(const PropertyName &) const override
Definition: BoxLayer.cpp:105
PropertyList getProperties() const override
Definition: BoxLayer.cpp:88
void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override
Definition: BoxLayer.cpp:735
QString getPropertyLabel(const PropertyName &) const override
Definition: BoxLayer.cpp:97
bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override
Open an editor on the item under the mouse (e.g.
Definition: BoxLayer.cpp:963
double getValueForY(LayerGeometryProvider *v, int y) const override
Definition: BoxLayer.cpp:514
void finish(ChangeEventsCommand *command)
Definition: BoxLayer.h:143
void addCommand(Command *command)
Add a command to the command history.
bool isLayerEditable() const override
This should return true if the layer can be edited by the user.
Definition: BoxLayer.h:97
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
Definition: BoxLayer.cpp:1185
void setProperty(const PropertyName &, int value) override
Definition: BoxLayer.cpp:167
void editDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:905
ModelId getModel() const override
Return the ID of the model represented in this layer.
Definition: BoxLayer.h:73
bool adoptExtents(double min, double max, QString unit) override
Consider using the given value extents and units for this layer.
Definition: BoxLayer.cpp:226
void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:826
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.
Event m_originalPoint
Definition: BoxLayer.h:134
VerticalScale m_verticalScale
Definition: BoxLayer.h:137
Interface for layers in which the Y axis represents (or can sometimes represent, depending on the dis...
int getYForValue(LayerGeometryProvider *v, double value) const override
VerticalScaleLayer methods.
Definition: BoxLayer.cpp:495
QString getPropertyValueLabel(const PropertyName &, int value) const override
Definition: BoxLayer.cpp:152
bool getValueExtents(double &min, double &max, bool &log, 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...
Definition: BoxLayer.cpp:199
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
Definition: BoxLayer.cpp:320
void setVerticalScale(VerticalScale scale)
Definition: BoxLayer.cpp:184
std::pair< float, float > getRange(const Event &e) const
Definition: BoxLayer.h:139
void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:852
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.
Definition: BoxLayer.cpp:1105
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...
Definition: BoxLayer.cpp:214
SnapType
Definition: Layer.h:195
void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:789
static CommandHistory * getInstance()
int m_dragPointY
Definition: BoxLayer.h:131
ModelId m_model
Definition: BoxLayer.h:128
void editEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:935
QString getScaleUnits() const override
Definition: BoxLayer.cpp:441
void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const
Definition: BoxLayer.cpp:449
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
Definition: BoxLayer.cpp:122
int m_dragPointX
Definition: BoxLayer.h:130
int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override
Definition: BoxLayer.cpp:719
VerticalScale getVerticalScale() const
Definition: BoxLayer.h:93
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
ChangeEventsCommand * m_editingCommand
Definition: BoxLayer.h:136
void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:836
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.
Definition: BoxLayer.cpp:532
int m_dragStartY
Definition: BoxLayer.h:133
void setProperties(const QXmlAttributes &attributes) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
Definition: BoxLayer.cpp:1196
void deleteSelection(Selection s) override
Definition: BoxLayer.cpp:1068
void resizeSelection(Selection s, Selection newSize) override
Definition: BoxLayer.cpp:1037
void setModel(ModelId model)
Definition: BoxLayer.cpp:68
void drawStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:766
bool m_editing
Definition: BoxLayer.h:129
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...
Definition: BoxLayer.cpp:192
void editStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:880
BoxLayer()
Definition: BoxLayer.cpp:44
QString getLabelPreceding(sv_frame_t) const override
Definition: BoxLayer.cpp:303
int m_dragStartX
Definition: BoxLayer.h:132
Event m_editingPoint
Definition: BoxLayer.h:135
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.
Definition: BoxLayer.cpp:369
void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: BoxLayer.cpp:857
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
Definition: BoxLayer.cpp:60
void moveSelection(Selection s, sv_frame_t newStartFrame) override
Definition: BoxLayer.cpp:1013