TextLayer.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_TEXT_LAYER_H
17 #define SV_TEXT_LAYER_H
18 
19 #include "SingleColourLayer.h"
20 #include "data/model/TextModel.h"
21 
22 #include <QObject>
23 #include <QColor>
24 
25 class View;
26 class QPainter;
27 
29 {
30  Q_OBJECT
31 
32 public:
33  TextLayer();
34 
35  void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
36 
37  QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
38 
39  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
40  int &resolution,
41  SnapType snap, int ycoord) const override;
42 
43  void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
44  void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
45  void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
46 
47  void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
48  void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
49  void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
50 
51  void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
52  void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
53  void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
54 
55  void moveSelection(Selection s, sv_frame_t newStartFrame) override;
56  void resizeSelection(Selection s, Selection newSize) override;
57  void deleteSelection(Selection s) override;
58 
59  void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
60  bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
61  bool interactive) override;
62 
63  bool editOpen(LayerGeometryProvider *, QMouseEvent *) override; // on double-click
64 
65  ModelId getModel() const override { return m_model; }
66  void setModel(ModelId model); // a TextModel
67 
68  PropertyList getProperties() const override;
69  QString getPropertyLabel(const PropertyName &) const override;
70  PropertyType getPropertyType(const PropertyName &) const override;
71  int getPropertyRangeAndValue(const PropertyName &,
72  int *min, int *max, int *deflt) const override;
73  QString getPropertyValueLabel(const PropertyName &,
74  int value) const override;
75  void setProperty(const PropertyName &, int value) override;
76 
77  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
78 
79  bool isLayerEditable() const override { return true; }
80 
81  int getCompletion(LayerGeometryProvider *) const override;
82 
83  bool getValueExtents(double &min, double &max,
84  bool &logarithmic, QString &unit) const override;
85 
86  int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const override { return 0; }
87 
88  void toXml(QTextStream &stream, QString indent = "",
89  QString extraAttributes = "") const override;
90 
91  void setProperties(const QXmlAttributes &attributes) override;
92 
93 protected:
94  int getYForHeight(LayerGeometryProvider *v, double height) const;
95  double getHeightForY(LayerGeometryProvider *v, int y) const;
96 
97  int getDefaultColourHint(bool dark, bool &impose) override;
98 
99  EventVector getLocalPoints(LayerGeometryProvider *v, int x, int y) const;
100 
101  bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
102 
103  ModelId m_model;
104  bool m_editing;
105  QPoint m_editOrigin;
108  ChangeEventsCommand *m_editingCommand;
109 
110  void finish(ChangeEventsCommand *command) {
111  Command *c = command->finish();
112  if (c) CommandHistory::getInstance()->addCommand(c, false);
113  }
114 };
115 
116 #endif
117 
void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:425
ModelId m_model
Definition: TextLayer.h:103
Event m_editingPoint
Definition: TextLayer.h:107
int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const override
Definition: TextLayer.h:86
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...
Definition: TextLayer.cpp:112
Event m_originalPoint
Definition: TextLayer.h:106
void moveSelection(Selection s, sv_frame_t newStartFrame) override
Definition: TextLayer.cpp:618
void editEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:563
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
Definition: TextLayer.cpp:46
void addCommand(Command *command)
Add a command to the command history.
void setModel(ModelId model)
Definition: TextLayer.cpp:54
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: TextLayer.cpp:118
EventVector getLocalPoints(LayerGeometryProvider *v, int x, int y) const
Definition: TextLayer.cpp:125
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
Definition: TextLayer.cpp:92
ChangeEventsCommand * m_editingCommand
Definition: TextLayer.h:108
int getDefaultColourHint(bool dark, bool &impose) override
Definition: TextLayer.cpp:787
bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap, int ycoord) const override
!! too much overlap with TimeValueLayer/TimeInstantLayer
Definition: TextLayer.cpp:239
bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const
Definition: TextLayer.cpp:171
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.
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: TextLayer.cpp:292
QString getPropertyValueLabel(const PropertyName &, int value) const override
Definition: TextLayer.cpp:99
QPoint m_editOrigin
Definition: TextLayer.h:105
PropertyType getPropertyType(const PropertyName &) const override
Definition: TextLayer.cpp:86
void resizeSelection(Selection s, Selection newSize) override
Definition: TextLayer.cpp:640
void editDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:535
void deleteSelection(Selection s) override
Definition: TextLayer.cpp:669
void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:446
SnapType
Definition: Layer.h:195
void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:492
static CommandHistory * getInstance()
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: TextLayer.cpp:802
bool editOpen(LayerGeometryProvider *, QMouseEvent *) override
Open an editor on the item under the mouse (e.g.
Definition: TextLayer.cpp:592
int getYForHeight(LayerGeometryProvider *v, double height) const
Definition: TextLayer.cpp:278
void setProperty(const PropertyName &, int value) override
Definition: TextLayer.cpp:106
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
Definition: TextLayer.cpp:795
void drawStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:398
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
ModelId getModel() const override
Return the ID of the model represented in this layer.
Definition: TextLayer.h:65
bool m_editing
Definition: TextLayer.h:104
void finish(ChangeEventsCommand *command)
Definition: TextLayer.h:110
void editStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:512
void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:471
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
Definition: TextLayer.cpp:200
PropertyList getProperties() const override
Definition: TextLayer.cpp:73
void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override
Definition: TextLayer.cpp:487
QString getPropertyLabel(const PropertyName &) const override
Definition: TextLayer.cpp:80
bool isLayerEditable() const override
This should return true if the layer can be edited by the user.
Definition: TextLayer.h:79
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: TextLayer.cpp:702
void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override
Definition: TextLayer.cpp:688
double getHeightForY(LayerGeometryProvider *v, int y) const
Definition: TextLayer.cpp:285