svgui  1.9
RegionLayer.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-2008 Chris Cannam and QMUL.
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 _REGION_LAYER_H_
17 #define _REGION_LAYER_H_
18 
19 #include "SingleColourLayer.h"
20 #include "VerticalScaleLayer.h"
21 #include "ColourScaleLayer.h"
22 
23 #include "data/model/RegionModel.h"
24 
25 #include <QObject>
26 #include <QColor>
27 
28 #include <map>
29 
30 class View;
31 class QPainter;
32 
34  public VerticalScaleLayer,
35  public ColourScaleLayer
36 {
37  Q_OBJECT
38 
39 public:
40  RegionLayer();
41 
42  virtual void paint(View *v, QPainter &paint, QRect rect) const;
43 
44  virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const;
45  virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const;
46 
47  virtual QString getFeatureDescription(View *v, QPoint &) const;
48  virtual QString getLabelPreceding(int) const;
49 
50  virtual bool snapToFeatureFrame(View *v, int &frame,
51  int &resolution,
52  SnapType snap) const;
53  virtual bool snapToSimilarFeature(View *v, int &frame,
54  int &resolution,
55  SnapType snap) const;
56 
57  virtual void drawStart(View *v, QMouseEvent *);
58  virtual void drawDrag(View *v, QMouseEvent *);
59  virtual void drawEnd(View *v, QMouseEvent *);
60 
61  virtual void eraseStart(View *v, QMouseEvent *);
62  virtual void eraseDrag(View *v, QMouseEvent *);
63  virtual void eraseEnd(View *v, QMouseEvent *);
64 
65  virtual void editStart(View *v, QMouseEvent *);
66  virtual void editDrag(View *v, QMouseEvent *);
67  virtual void editEnd(View *v, QMouseEvent *);
68 
69  virtual bool editOpen(View *v, QMouseEvent *);
70 
71  virtual void moveSelection(Selection s, int newStartFrame);
72  virtual void resizeSelection(Selection s, Selection newSize);
73  virtual void deleteSelection(Selection s);
74 
75  virtual void copy(View *v, Selection s, Clipboard &to);
76  virtual bool paste(View *v, const Clipboard &from, int frameOffset,
77  bool interactive);
78 
79  virtual const Model *getModel() const { return m_model; }
80  void setModel(RegionModel *model);
81 
82  virtual PropertyList getProperties() const;
83  virtual QString getPropertyLabel(const PropertyName &) const;
84  virtual PropertyType getPropertyType(const PropertyName &) const;
85  virtual QString getPropertyGroupName(const PropertyName &) const;
86  virtual int getPropertyRangeAndValue(const PropertyName &,
87  int *min, int *max, int *deflt) const;
88  virtual QString getPropertyValueLabel(const PropertyName &,
89  int value) const;
90  virtual void setProperty(const PropertyName &, int value);
91 
92  void setFillColourMap(int);
93  int getFillColourMap() const { return m_colourMap; }
94 
100  };
101 
102  void setVerticalScale(VerticalScale scale);
104 
105  enum PlotStyle {
108  };
109 
110  void setPlotStyle(PlotStyle style);
111  PlotStyle getPlotStyle() const { return m_plotStyle; }
112 
113  virtual bool isLayerScrollable(const View *v) const;
114 
115  virtual bool isLayerEditable() const { return true; }
116 
117  virtual int getCompletion(View *) const { return m_model->getCompletion(); }
118 
119  virtual bool getValueExtents(float &min, float &max,
120  bool &log, QString &unit) const;
121 
122  virtual bool getDisplayExtents(float &min, float &max) const;
123 
124  virtual void toXml(QTextStream &stream, QString indent = "",
125  QString extraAttributes = "") const;
126 
127  void setProperties(const QXmlAttributes &attributes);
128 
130  int getYForValue(View *v, float value) const;
131  float getValueForY(View *v, int y) const;
132  virtual QString getScaleUnits() const;
133  QColor getColourForValue(View *v, float value) const;
134 
135 protected slots:
136  void recalcSpacing();
137 
138 protected:
139  float getValueForY(View *v, int y, int avoid) const;
140  void getScaleExtents(View *, float &min, float &max, bool &log) const;
141 
142  virtual int getDefaultColourHint(bool dark, bool &impose);
143 
144  RegionModel::PointList getLocalPoints(View *v, int x) const;
145 
146  bool getPointToDrag(View *v, int x, int y, RegionModel::Point &) const;
147 
148  RegionModel *m_model;
149  bool m_editing;
154  RegionModel::Point m_originalPoint;
155  RegionModel::Point m_editingPoint;
156  RegionModel::EditCommand *m_editingCommand;
160 
161  typedef std::map<float, int> SpacingMap;
162 
163  // region value -> ordering
165 
166  // region value -> number of regions with this value
168 
169  int spacingIndexToY(View *v, int i) const;
170  float yToSpacingIndex(View *v, int y) const;
171 
172  void finish(RegionModel::EditCommand *command) {
173  Command *c = command->finish();
174  if (c) CommandHistory::getInstance()->addCommand(c, false);
175  }
176 };
177 
178 #endif
179 
void getScaleExtents(View *, float &min, float &max, bool &log) const
virtual bool editOpen(View *v, QMouseEvent *)
Open an editor on the item under the mouse (e.g.
virtual bool snapToFeatureFrame(View *v, int &frame, int &resolution, SnapType snap) const
Adjust the given frame to snap to the nearest feature, if possible.
float getValueForY(View *v, int y) const
VerticalScale getVerticalScale() const
Definition: RegionLayer.h:103
void setPlotStyle(PlotStyle style)
void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
virtual void deleteSelection(Selection s)
virtual void drawStart(View *v, QMouseEvent *)
int m_dragStartX
Definition: RegionLayer.h:152
void addCommand(Command *command)
Add a command to the command history.
virtual const Model * getModel() const
Definition: RegionLayer.h:79
bool m_editing
Definition: RegionLayer.h:149
virtual QString getFeatureDescription(View *v, QPoint &) const
int m_dragStartY
Definition: RegionLayer.h:153
virtual void editEnd(View *v, QMouseEvent *)
int m_dragPointX
Definition: RegionLayer.h:150
RegionModel::Point m_originalPoint
Definition: RegionLayer.h:154
void setVerticalScale(VerticalScale scale)
RegionModel::EditCommand * m_editingCommand
Definition: RegionLayer.h:156
virtual QString getScaleUnits() const
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
virtual void editStart(View *v, QMouseEvent *)
VerticalScale m_verticalScale
Definition: RegionLayer.h:157
virtual bool isLayerScrollable(const View *v) const
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
int m_dragPointY
Definition: RegionLayer.h:151
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
int spacingIndexToY(View *v, int i) const
virtual QString getPropertyGroupName(const PropertyName &) const
virtual int getCompletion(View *) const
Return the proportion of background work complete in drawing this view, as a percentage – in most cas...
Definition: RegionLayer.h:117
void setModel(RegionModel *model)
Definition: RegionLayer.cpp:65
RegionModel * m_model
Definition: RegionLayer.h:148
int getFillColourMap() const
Definition: RegionLayer.h:93
virtual void editDrag(View *v, QMouseEvent *)
virtual void drawDrag(View *v, QMouseEvent *)
virtual void setProperty(const PropertyName &, int value)
PlotStyle getPlotStyle() const
Definition: RegionLayer.h:111
SnapType
Definition: Layer.h:157
static CommandHistory * getInstance()
virtual PropertyType getPropertyType(const PropertyName &) const
virtual void moveSelection(Selection s, int newStartFrame)
int getYForValue(View *v, float value) const
VerticalScaleLayer and ColourScaleLayer methods.
float yToSpacingIndex(View *v, int y) const
SpacingMap m_distributionMap
Definition: RegionLayer.h:167
virtual void eraseEnd(View *v, QMouseEvent *)
virtual PropertyList getProperties() const
Definition: RegionLayer.cpp:88
virtual bool isLayerEditable() const
This should return true if the layer can be edited by the user.
Definition: RegionLayer.h:115
bool getPointToDrag(View *v, int x, int y, RegionModel::Point &) const
virtual bool getDisplayExtents(float &min, float &max) const
Return the minimum and maximum values within the displayed range for the y axis, if only a subset of ...
virtual void resizeSelection(Selection s, Selection newSize)
RegionModel::PointList getLocalPoints(View *v, int x) const
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
virtual bool snapToSimilarFeature(View *v, int &frame, int &resolution, SnapType snap) const
Adjust the given frame to snap to the next feature that has "effectively" the same value as the featu...
RegionModel::Point m_editingPoint
Definition: RegionLayer.h:155
virtual QString getLabelPreceding(int) const
virtual bool paste(View *v, const Clipboard &from, int frameOffset, bool interactive)
Paste from the given clipboard onto the layer at the given frame offset.
virtual void drawEnd(View *v, QMouseEvent *)
virtual void eraseDrag(View *v, QMouseEvent *)
void finish(RegionModel::EditCommand *command)
Definition: RegionLayer.h:172
PlotStyle m_plotStyle
Definition: RegionLayer.h:159
void recalcSpacing()
QColor getColourForValue(View *v, float value) const
void setFillColourMap(int)
virtual void copy(View *v, Selection s, Clipboard &to)
virtual bool getValueExtents(float &min, float &max, bool &log, QString &unit) const
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
std::map< float, int > SpacingMap
Definition: RegionLayer.h:161
virtual void eraseStart(View *v, QMouseEvent *)
SpacingMap m_spacingMap
Definition: RegionLayer.h:164
virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const
virtual void paint(View *v, QPainter &paint, QRect rect) const
Paint the given rectangle of this layer onto the given view using the given painter,...
virtual int getDefaultColourHint(bool dark, bool &impose)
virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const
virtual QString getPropertyLabel(const PropertyName &) const
Definition: RegionLayer.cpp:98