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 _TIME_INSTANT_LAYER_H_ 00017 #define _TIME_INSTANT_LAYER_H_ 00018 00019 #include "SingleColourLayer.h" 00020 #include "data/model/SparseOneDimensionalModel.h" 00021 00022 #include <QObject> 00023 #include <QColor> 00024 00025 class View; 00026 class QPainter; 00027 00028 class TimeInstantLayer : public SingleColourLayer 00029 { 00030 Q_OBJECT 00031 00032 public: 00033 TimeInstantLayer(); 00034 virtual ~TimeInstantLayer(); 00035 00036 virtual void paint(View *v, QPainter &paint, QRect rect) const; 00037 00038 virtual QString getLabelPreceding(int) const; 00039 virtual QString getFeatureDescription(View *v, QPoint &) const; 00040 00041 virtual bool snapToFeatureFrame(View *v, int &frame, 00042 int &resolution, 00043 SnapType snap) const; 00044 00045 virtual void drawStart(View *v, QMouseEvent *); 00046 virtual void drawDrag(View *v, QMouseEvent *); 00047 virtual void drawEnd(View *v, QMouseEvent *); 00048 00049 virtual void eraseStart(View *v, QMouseEvent *); 00050 virtual void eraseDrag(View *v, QMouseEvent *); 00051 virtual void eraseEnd(View *v, QMouseEvent *); 00052 00053 virtual void editStart(View *v, QMouseEvent *); 00054 virtual void editDrag(View *v, QMouseEvent *); 00055 virtual void editEnd(View *v, QMouseEvent *); 00056 00057 virtual bool editOpen(View *, QMouseEvent *); 00058 00059 virtual void moveSelection(Selection s, int newStartFrame); 00060 virtual void resizeSelection(Selection s, Selection newSize); 00061 virtual void deleteSelection(Selection s); 00062 00063 virtual void copy(View *v, Selection s, Clipboard &to); 00064 virtual bool paste(View *v, const Clipboard &from, int frameOffset, 00065 bool interactive); 00066 00067 virtual const Model *getModel() const { return m_model; } 00068 void setModel(SparseOneDimensionalModel *model); 00069 00070 virtual PropertyList getProperties() const; 00071 virtual QString getPropertyLabel(const PropertyName &) const; 00072 virtual PropertyType getPropertyType(const PropertyName &) const; 00073 virtual int getPropertyRangeAndValue(const PropertyName &, 00074 int *min, int *max, int *deflt) const; 00075 virtual QString getPropertyValueLabel(const PropertyName &, 00076 int value) const; 00077 virtual void setProperty(const PropertyName &, int value); 00078 00079 enum PlotStyle { 00080 PlotInstants, 00081 PlotSegmentation 00082 }; 00083 00084 void setPlotStyle(PlotStyle style); 00085 PlotStyle getPlotStyle() const { return m_plotStyle; } 00086 00087 virtual bool isLayerScrollable(const View *v) const; 00088 00089 virtual bool isLayerEditable() const { return true; } 00090 00091 virtual int getCompletion(View *) const { return m_model->getCompletion(); } 00092 00093 virtual bool needsTextLabelHeight() const { return m_model->hasTextLabels(); } 00094 00095 virtual bool getValueExtents(float &, float &, bool &, QString &) const { 00096 return false; 00097 } 00098 00099 virtual void toXml(QTextStream &stream, QString indent = "", 00100 QString extraAttributes = "") const; 00101 00102 void setProperties(const QXmlAttributes &attributes); 00103 00104 virtual ColourSignificance getLayerColourSignificance() const { 00105 if (m_plotStyle == PlotSegmentation) { 00106 return ColourHasMeaningfulValue; 00107 } else { 00108 return ColourDistinguishes; 00109 } 00110 } 00111 00112 virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } 00113 00114 protected: 00115 SparseOneDimensionalModel::PointList getLocalPoints(View *v, int) const; 00116 00117 virtual int getDefaultColourHint(bool dark, bool &impose); 00118 00119 bool clipboardAlignmentDiffers(View *v, const Clipboard &) const; 00120 00121 SparseOneDimensionalModel *m_model; 00122 bool m_editing; 00123 SparseOneDimensionalModel::Point m_editingPoint; 00124 SparseOneDimensionalModel::EditCommand *m_editingCommand; 00125 PlotStyle m_plotStyle; 00126 00127 void finish(SparseOneDimensionalModel::EditCommand *command) { 00128 Command *c = command->finish(); 00129 if (c) CommandHistory::getInstance()->addCommand(c, false); 00130 } 00131 }; 00132 00133 #endif 00134