TimeInstantLayer.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_INSTANT_LAYER_H
17 #define SV_TIME_INSTANT_LAYER_H
18 
19 #include "SingleColourLayer.h"
20 #include "data/model/SparseOneDimensionalModel.h"
21 
22 #include <QObject>
23 #include <QColor>
24 
25 class View;
26 class QPainter;
27 
29 {
30  Q_OBJECT
31 
32 public:
34  virtual ~TimeInstantLayer();
35 
36  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
37 
38  QString getLabelPreceding(sv_frame_t) const override;
39  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
40 
41  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
42  int &resolution,
43  SnapType snap, int ycoord) const override;
44 
45  void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
46  void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
47  void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
48 
49  void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
50  void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
51  void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
52 
53  void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
54  void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
55  void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
56 
57  bool editOpen(LayerGeometryProvider *, QMouseEvent *) override;
58 
59  void moveSelection(Selection s, sv_frame_t newStartFrame) override;
60  void resizeSelection(Selection s, Selection newSize) override;
61  void deleteSelection(Selection s) override;
62 
63  void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
64  bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
65  bool interactive) override;
66 
67  ModelId getModel() const override { return m_model; }
68  void setModel(ModelId model); // a SparseOneDimensionalModel
69 
70  PropertyList getProperties() const override;
71  QString getPropertyLabel(const PropertyName &) const override;
72  PropertyType getPropertyType(const PropertyName &) const override;
73  int getPropertyRangeAndValue(const PropertyName &,
74  int *min, int *max, int *deflt) const override;
75  QString getPropertyValueLabel(const PropertyName &,
76  int value) const override;
77  void setProperty(const PropertyName &, int value) override;
78 
79  enum PlotStyle {
82  };
83 
84  void setPlotStyle(PlotStyle style);
85  PlotStyle getPlotStyle() const { return m_plotStyle; }
86 
87  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
88 
89  bool isLayerEditable() const override { return true; }
90 
91  int getCompletion(LayerGeometryProvider *) const override;
92 
93  bool needsTextLabelHeight() const override;
94 
95  bool getValueExtents(double &, double &, bool &, QString &) const override {
96  return false;
97  }
98 
99  void toXml(QTextStream &stream, QString indent = "",
100  QString extraAttributes = "") const override;
101 
102  void setProperties(const QXmlAttributes &attributes) override;
103 
105  if (m_plotStyle == PlotSegmentation) {
107  } else {
108  return ColourDistinguishes;
109  }
110  }
111 
112  int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const override { return 0; }
113 
114 protected:
115  EventVector getLocalPoints(LayerGeometryProvider *v, int) const;
116 
117  int getDefaultColourHint(bool dark, bool &impose) override;
118 
119  bool clipboardAlignmentDiffers(LayerGeometryProvider *v, const Clipboard &) const;
120 
121  ModelId m_model;
122  bool m_editing;
124  ChangeEventsCommand *m_editingCommand;
126 
127  void finish(ChangeEventsCommand *command) {
128  Command *c = command->finish();
129  if (c) CommandHistory::getInstance()->addCommand(c, false);
130  }
131 };
132 
133 #endif
134 
QString getPropertyValueLabel(const PropertyName &, int value) const override
QString getLabelPreceding(sv_frame_t) const override
void drawStart(LayerGeometryProvider *v, QMouseEvent *) override
ModelId getModel() const override
Return the ID of the model represented in this layer.
void editStart(LayerGeometryProvider *v, QMouseEvent *) override
QString getPropertyLabel(const PropertyName &) const override
void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override
bool needsTextLabelHeight() const override
True if this layer will need to place text labels when it is painted.
PlotStyle getPlotStyle() const
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 addCommand(Command *command)
Add a command to the command history.
void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override
void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override
void resizeSelection(Selection s, Selection newSize) override
ColourSignificance
Definition: Layer.h:348
void setProperty(const PropertyName &, int value) override
PropertyType getPropertyType(const PropertyName &) const override
void finish(ChangeEventsCommand *command)
void editDrag(LayerGeometryProvider *v, QMouseEvent *) override
bool isLayerEditable() const override
This should return true if the layer can be edited by the user.
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.
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override
int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const override
void setPlotStyle(PlotStyle style)
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...
PropertyList getProperties() const override
ChangeEventsCommand * m_editingCommand
SnapType
Definition: Layer.h:195
EventVector getLocalPoints(LayerGeometryProvider *v, int) const
void deleteSelection(Selection s) override
static CommandHistory * getInstance()
void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override
void moveSelection(Selection s, sv_frame_t newStartFrame) override
ColourSignificance getLayerColourSignificance() const override
Implements Layer::getLayerColourSignificance()
bool clipboardAlignmentDiffers(LayerGeometryProvider *v, const Clipboard &) const
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.
virtual ~TimeInstantLayer()
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
int getDefaultColourHint(bool dark, bool &impose) override
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
void eraseStart(LayerGeometryProvider *v, QMouseEvent *) 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...
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.
bool getValueExtents(double &, double &, bool &, QString &) const override
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
void setModel(ModelId model)
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
bool editOpen(LayerGeometryProvider *, QMouseEvent *) override
Open an editor on the item under the mouse (e.g.
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
void editEnd(LayerGeometryProvider *v, QMouseEvent *) override