comparison layer/RegionLayer.h @ 411:96e4d7b9e165

* Add region model and layer; improve assignment of model types to feature extraction transforms with duration
author Chris Cannam
date Thu, 18 Sep 2008 16:08:14 +0000
parents
children d332ad1ca66b
comparison
equal deleted inserted replaced
410:33b7f5e54d60 411:96e4d7b9e165
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 "data/model/RegionModel.h"
21
22 #include <QObject>
23 #include <QColor>
24
25 class View;
26 class QPainter;
27
28 class RegionLayer : public SingleColourLayer
29 {
30 Q_OBJECT
31
32 public:
33 RegionLayer();
34
35 virtual void paint(View *v, QPainter &paint, QRect rect) const;
36
37 virtual QString getFeatureDescription(View *v, QPoint &) const;
38
39 virtual bool snapToFeatureFrame(View *v, int &frame,
40 size_t &resolution,
41 SnapType snap) const;
42
43 virtual void drawStart(View *v, QMouseEvent *);
44 virtual void drawDrag(View *v, QMouseEvent *);
45 virtual void drawEnd(View *v, QMouseEvent *);
46
47 virtual void eraseStart(View *v, QMouseEvent *);
48 virtual void eraseDrag(View *v, QMouseEvent *);
49 virtual void eraseEnd(View *v, QMouseEvent *);
50
51 virtual void editStart(View *v, QMouseEvent *);
52 virtual void editDrag(View *v, QMouseEvent *);
53 virtual void editEnd(View *v, QMouseEvent *);
54
55 virtual bool editOpen(View *v, QMouseEvent *);
56
57 virtual void moveSelection(Selection s, size_t newStartFrame);
58 virtual void resizeSelection(Selection s, Selection newSize);
59 virtual void deleteSelection(Selection s);
60
61 virtual void copy(View *v, Selection s, Clipboard &to);
62 virtual bool paste(View *v, const Clipboard &from, int frameOffset,
63 bool interactive);
64
65 virtual const Model *getModel() const { return m_model; }
66 void setModel(RegionModel *model);
67
68 virtual PropertyList getProperties() const;
69 virtual QString getPropertyLabel(const PropertyName &) const;
70 virtual PropertyType getPropertyType(const PropertyName &) const;
71 virtual QString getPropertyGroupName(const PropertyName &) const;
72 virtual int getPropertyRangeAndValue(const PropertyName &,
73 int *min, int *max, int *deflt) const;
74 virtual QString getPropertyValueLabel(const PropertyName &,
75 int value) const;
76 virtual void setProperty(const PropertyName &, int value);
77
78 enum VerticalScale {
79 AutoAlignScale,
80 LinearScale,
81 LogScale,
82 };
83
84 void setVerticalScale(VerticalScale scale);
85 VerticalScale getVerticalScale() const { return m_verticalScale; }
86
87 virtual bool isLayerScrollable(const View *v) const;
88
89 virtual bool isLayerEditable() const { return true; }
90
91 virtual int getCompletion(View *) const { return m_model->getCompletion(); }
92
93 virtual bool getValueExtents(float &min, float &max,
94 bool &log, QString &unit) const;
95
96 virtual bool getDisplayExtents(float &min, float &max) const;
97
98 virtual void toXml(QTextStream &stream, QString indent = "",
99 QString extraAttributes = "") const;
100
101 void setProperties(const QXmlAttributes &attributes);
102
103 protected:
104 void getScaleExtents(View *, float &min, float &max, bool &log) const;
105 int getYForValue(View *v, float value) const;
106 float getValueForY(View *v, int y) const;
107
108 virtual int getDefaultColourHint(bool dark, bool &impose);
109
110 RegionModel::PointList getLocalPoints(View *v, int) const;
111
112 RegionModel *m_model;
113 bool m_editing;
114 RegionModel::Point m_originalPoint;
115 RegionModel::Point m_editingPoint;
116 RegionModel::EditCommand *m_editingCommand;
117 VerticalScale m_verticalScale;
118
119 void finish(RegionModel::EditCommand *command) {
120 Command *c = command->finish();
121 if (c) CommandHistory::getInstance()->addCommand(c, false);
122 }
123 };
124
125 #endif
126