svgui  1.9
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 _TEXT_LAYER_H_
17 #define _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  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  int &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 void moveSelection(Selection s, int newStartFrame);
56  virtual void resizeSelection(Selection s, Selection newSize);
57  virtual void deleteSelection(Selection s);
58 
59  virtual void copy(View *v, Selection s, Clipboard &to);
60  virtual bool paste(View *v, const Clipboard &from, int frameOffset,
61  bool interactive);
62 
63  virtual bool editOpen(View *, QMouseEvent *); // on double-click
64 
65  virtual const Model *getModel() const { return m_model; }
66  void setModel(TextModel *model);
67 
68  virtual PropertyList getProperties() const;
69  virtual QString getPropertyLabel(const PropertyName &) const;
70  virtual PropertyType getPropertyType(const PropertyName &) const;
71  virtual int getPropertyRangeAndValue(const PropertyName &,
72  int *min, int *max, int *deflt) const;
73  virtual QString getPropertyValueLabel(const PropertyName &,
74  int value) const;
75  virtual void setProperty(const PropertyName &, int value);
76 
77  virtual bool isLayerScrollable(const View *v) const;
78 
79  virtual bool isLayerEditable() const { return true; }
80 
81  virtual int getCompletion(View *) const { return m_model->getCompletion(); }
82 
83  virtual bool getValueExtents(float &min, float &max,
84  bool &logarithmic, QString &unit) const;
85 
86  virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; }
87 
88  virtual void toXml(QTextStream &stream, QString indent = "",
89  QString extraAttributes = "") const;
90 
91  void setProperties(const QXmlAttributes &attributes);
92 
93 protected:
94  int getYForHeight(View *v, float height) const;
95  float getHeightForY(View *v, int y) const;
96 
97  virtual int getDefaultColourHint(bool dark, bool &impose);
98 
99  TextModel::PointList getLocalPoints(View *v, int x, int y) const;
100 
101  bool getPointToDrag(View *v, int x, int y, TextModel::Point &) const;
102 
103  TextModel *m_model;
104  bool m_editing;
105  QPoint m_editOrigin;
106  TextModel::Point m_originalPoint;
107  TextModel::Point m_editingPoint;
108  TextModel::EditCommand *m_editingCommand;
109 
110  void finish(TextModel::EditCommand *command) {
111  Command *c = command->finish();
112  if (c) CommandHistory::getInstance()->addCommand(c, false);
113  }
114 };
115 
116 #endif
117 
virtual void drawStart(View *v, QMouseEvent *)
Definition: TextLayer.cpp:414
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,...
Definition: TextLayer.cpp:309
virtual void deleteSelection(Selection s)
Definition: TextLayer.cpp:683
TextModel::Point m_editingPoint
Definition: TextLayer.h:107
virtual void drawEnd(View *v, QMouseEvent *)
Definition: TextLayer.cpp:459
TextModel::Point m_originalPoint
Definition: TextLayer.h:106
bool getPointToDrag(View *v, int x, int y, TextModel::Point &) const
Definition: TextLayer.cpp:157
virtual const Model * getModel() const
Definition: TextLayer.h:65
void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
Definition: TextLayer.cpp:817
void setModel(TextModel *model)
Definition: TextLayer.cpp:47
virtual int getVerticalScaleWidth(View *, bool, QPainter &) const
Definition: TextLayer.h:86
void addCommand(Command *command)
Add a command to the command history.
virtual bool getValueExtents(float &min, float &max, bool &logarithmic, QString &unit) const
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
Definition: TextLayer.cpp:99
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
Definition: TextLayer.cpp:86
virtual bool isLayerEditable() const
This should return true if the layer can be edited by the user.
Definition: TextLayer.h:79
void finish(TextModel::EditCommand *command)
Definition: TextLayer.h:110
virtual void eraseStart(View *v, QMouseEvent *)
Definition: TextLayer.cpp:483
virtual PropertyList getProperties() const
Definition: TextLayer.cpp:60
virtual void eraseDrag(View *v, QMouseEvent *)
Definition: TextLayer.cpp:498
virtual void editStart(View *v, QMouseEvent *)
Definition: TextLayer.cpp:524
TextModel * m_model
Definition: TextLayer.h:103
virtual void editDrag(View *v, QMouseEvent *)
Definition: TextLayer.cpp:546
QPoint m_editOrigin
Definition: TextLayer.h:105
TextModel::PointList getLocalPoints(View *v, int x, int y) const
Definition: TextLayer.cpp:113
virtual int getCompletion(View *) const
Return the proportion of background work complete in drawing this view, as a percentage – in most cas...
Definition: TextLayer.h:81
virtual void setProperty(const PropertyName &, int value)
Definition: TextLayer.cpp:93
virtual bool snapToFeatureFrame(View *v, int &frame, int &resolution, SnapType snap) const
!! too much overlap with TimeValueLayer/TimeInstantLayer
Definition: TextLayer.cpp:223
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
Definition: TextLayer.cpp:79
virtual void editEnd(View *v, QMouseEvent *)
Definition: TextLayer.cpp:573
SnapType
Definition: Layer.h:157
static CommandHistory * getInstance()
virtual void copy(View *v, Selection s, Clipboard &to)
Definition: TextLayer.cpp:702
int getYForHeight(View *v, float height) const
Definition: TextLayer.cpp:295
virtual PropertyType getPropertyType(const PropertyName &) const
Definition: TextLayer.cpp:73
virtual bool editOpen(View *, QMouseEvent *)
Open an editor on the item under the mouse (e.g.
Definition: TextLayer.cpp:601
virtual int getDefaultColourHint(bool dark, bool &impose)
Definition: TextLayer.cpp:802
virtual void eraseEnd(View *v, QMouseEvent *)
Definition: TextLayer.cpp:503
virtual void drawDrag(View *v, QMouseEvent *)
Definition: TextLayer.cpp:440
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
virtual void moveSelection(Selection s, int newStartFrame)
Definition: TextLayer.cpp:624
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...
Definition: TextLayer.cpp:105
float getHeightForY(View *v, int y) const
Definition: TextLayer.cpp:302
virtual void resizeSelection(Selection s, Selection newSize)
Definition: TextLayer.cpp:649
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.
Definition: TextLayer.cpp:810
bool m_editing
Definition: TextLayer.h:104
TextModel::EditCommand * m_editingCommand
Definition: TextLayer.h:108
virtual QString getFeatureDescription(View *v, QPoint &) const
Definition: TextLayer.cpp:185
virtual QString getPropertyLabel(const PropertyName &) const
Definition: TextLayer.cpp:67
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.
Definition: TextLayer.cpp:720