svgui
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _TEXT_LAYER_H_ 00017 #define _TEXT_LAYER_H_ 00018 00019 #include "SingleColourLayer.h" 00020 #include "data/model/TextModel.h" 00021 00022 #include <QObject> 00023 #include <QColor> 00024 00025 class View; 00026 class QPainter; 00027 00028 class TextLayer : public SingleColourLayer 00029 { 00030 Q_OBJECT 00031 00032 public: 00033 TextLayer(); 00034 00035 virtual void paint(View *v, QPainter &paint, QRect rect) const; 00036 00037 virtual QString getFeatureDescription(View *v, QPoint &) const; 00038 00039 virtual bool snapToFeatureFrame(View *v, int &frame, 00040 int &resolution, 00041 SnapType snap) const; 00042 00043 virtual void drawStart(View *v, QMouseEvent *); 00044 virtual void drawDrag(View *v, QMouseEvent *); 00045 virtual void drawEnd(View *v, QMouseEvent *); 00046 00047 virtual void eraseStart(View *v, QMouseEvent *); 00048 virtual void eraseDrag(View *v, QMouseEvent *); 00049 virtual void eraseEnd(View *v, QMouseEvent *); 00050 00051 virtual void editStart(View *v, QMouseEvent *); 00052 virtual void editDrag(View *v, QMouseEvent *); 00053 virtual void editEnd(View *v, QMouseEvent *); 00054 00055 virtual void moveSelection(Selection s, int newStartFrame); 00056 virtual void resizeSelection(Selection s, Selection newSize); 00057 virtual void deleteSelection(Selection s); 00058 00059 virtual void copy(View *v, Selection s, Clipboard &to); 00060 virtual bool paste(View *v, const Clipboard &from, int frameOffset, 00061 bool interactive); 00062 00063 virtual bool editOpen(View *, QMouseEvent *); // on double-click 00064 00065 virtual const Model *getModel() const { return m_model; } 00066 void setModel(TextModel *model); 00067 00068 virtual PropertyList getProperties() const; 00069 virtual QString getPropertyLabel(const PropertyName &) const; 00070 virtual PropertyType getPropertyType(const PropertyName &) const; 00071 virtual int getPropertyRangeAndValue(const PropertyName &, 00072 int *min, int *max, int *deflt) const; 00073 virtual QString getPropertyValueLabel(const PropertyName &, 00074 int value) const; 00075 virtual void setProperty(const PropertyName &, int value); 00076 00077 virtual bool isLayerScrollable(const View *v) const; 00078 00079 virtual bool isLayerEditable() const { return true; } 00080 00081 virtual int getCompletion(View *) const { return m_model->getCompletion(); } 00082 00083 virtual bool getValueExtents(float &min, float &max, 00084 bool &logarithmic, QString &unit) const; 00085 00086 virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } 00087 00088 virtual void toXml(QTextStream &stream, QString indent = "", 00089 QString extraAttributes = "") const; 00090 00091 void setProperties(const QXmlAttributes &attributes); 00092 00093 protected: 00094 int getYForHeight(View *v, float height) const; 00095 float getHeightForY(View *v, int y) const; 00096 00097 virtual int getDefaultColourHint(bool dark, bool &impose); 00098 00099 TextModel::PointList getLocalPoints(View *v, int x, int y) const; 00100 00101 bool getPointToDrag(View *v, int x, int y, TextModel::Point &) const; 00102 00103 TextModel *m_model; 00104 bool m_editing; 00105 QPoint m_editOrigin; 00106 TextModel::Point m_originalPoint; 00107 TextModel::Point m_editingPoint; 00108 TextModel::EditCommand *m_editingCommand; 00109 00110 void finish(TextModel::EditCommand *command) { 00111 Command *c = command->finish(); 00112 if (c) CommandHistory::getInstance()->addCommand(c, false); 00113 } 00114 }; 00115 00116 #endif 00117