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-2008 Chris Cannam and QMUL. 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 _REGION_LAYER_H_ 00017 #define _REGION_LAYER_H_ 00018 00019 #include "SingleColourLayer.h" 00020 #include "VerticalScaleLayer.h" 00021 #include "ColourScaleLayer.h" 00022 00023 #include "data/model/RegionModel.h" 00024 00025 #include <QObject> 00026 #include <QColor> 00027 00028 #include <map> 00029 00030 class View; 00031 class QPainter; 00032 00033 class RegionLayer : public SingleColourLayer, 00034 public VerticalScaleLayer, 00035 public ColourScaleLayer 00036 { 00037 Q_OBJECT 00038 00039 public: 00040 RegionLayer(); 00041 00042 virtual void paint(View *v, QPainter &paint, QRect rect) const; 00043 00044 virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; 00045 virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; 00046 00047 virtual QString getFeatureDescription(View *v, QPoint &) const; 00048 virtual QString getLabelPreceding(int) const; 00049 00050 virtual bool snapToFeatureFrame(View *v, int &frame, 00051 int &resolution, 00052 SnapType snap) const; 00053 virtual bool snapToSimilarFeature(View *v, int &frame, 00054 int &resolution, 00055 SnapType snap) const; 00056 00057 virtual void drawStart(View *v, QMouseEvent *); 00058 virtual void drawDrag(View *v, QMouseEvent *); 00059 virtual void drawEnd(View *v, QMouseEvent *); 00060 00061 virtual void eraseStart(View *v, QMouseEvent *); 00062 virtual void eraseDrag(View *v, QMouseEvent *); 00063 virtual void eraseEnd(View *v, QMouseEvent *); 00064 00065 virtual void editStart(View *v, QMouseEvent *); 00066 virtual void editDrag(View *v, QMouseEvent *); 00067 virtual void editEnd(View *v, QMouseEvent *); 00068 00069 virtual bool editOpen(View *v, QMouseEvent *); 00070 00071 virtual void moveSelection(Selection s, int newStartFrame); 00072 virtual void resizeSelection(Selection s, Selection newSize); 00073 virtual void deleteSelection(Selection s); 00074 00075 virtual void copy(View *v, Selection s, Clipboard &to); 00076 virtual bool paste(View *v, const Clipboard &from, int frameOffset, 00077 bool interactive); 00078 00079 virtual const Model *getModel() const { return m_model; } 00080 void setModel(RegionModel *model); 00081 00082 virtual PropertyList getProperties() const; 00083 virtual QString getPropertyLabel(const PropertyName &) const; 00084 virtual PropertyType getPropertyType(const PropertyName &) const; 00085 virtual QString getPropertyGroupName(const PropertyName &) const; 00086 virtual int getPropertyRangeAndValue(const PropertyName &, 00087 int *min, int *max, int *deflt) const; 00088 virtual QString getPropertyValueLabel(const PropertyName &, 00089 int value) const; 00090 virtual void setProperty(const PropertyName &, int value); 00091 00092 void setFillColourMap(int); 00093 int getFillColourMap() const { return m_colourMap; } 00094 00095 enum VerticalScale { 00096 AutoAlignScale, 00097 EqualSpaced, 00098 LinearScale, 00099 LogScale, 00100 }; 00101 00102 void setVerticalScale(VerticalScale scale); 00103 VerticalScale getVerticalScale() const { return m_verticalScale; } 00104 00105 enum PlotStyle { 00106 PlotLines, 00107 PlotSegmentation 00108 }; 00109 00110 void setPlotStyle(PlotStyle style); 00111 PlotStyle getPlotStyle() const { return m_plotStyle; } 00112 00113 virtual bool isLayerScrollable(const View *v) const; 00114 00115 virtual bool isLayerEditable() const { return true; } 00116 00117 virtual int getCompletion(View *) const { return m_model->getCompletion(); } 00118 00119 virtual bool getValueExtents(float &min, float &max, 00120 bool &log, QString &unit) const; 00121 00122 virtual bool getDisplayExtents(float &min, float &max) const; 00123 00124 virtual void toXml(QTextStream &stream, QString indent = "", 00125 QString extraAttributes = "") const; 00126 00127 void setProperties(const QXmlAttributes &attributes); 00128 00130 int getYForValue(View *v, float value) const; 00131 float getValueForY(View *v, int y) const; 00132 virtual QString getScaleUnits() const; 00133 QColor getColourForValue(View *v, float value) const; 00134 00135 protected slots: 00136 void recalcSpacing(); 00137 00138 protected: 00139 float getValueForY(View *v, int y, int avoid) const; 00140 void getScaleExtents(View *, float &min, float &max, bool &log) const; 00141 00142 virtual int getDefaultColourHint(bool dark, bool &impose); 00143 00144 RegionModel::PointList getLocalPoints(View *v, int x) const; 00145 00146 bool getPointToDrag(View *v, int x, int y, RegionModel::Point &) const; 00147 00148 RegionModel *m_model; 00149 bool m_editing; 00150 int m_dragPointX; 00151 int m_dragPointY; 00152 int m_dragStartX; 00153 int m_dragStartY; 00154 RegionModel::Point m_originalPoint; 00155 RegionModel::Point m_editingPoint; 00156 RegionModel::EditCommand *m_editingCommand; 00157 VerticalScale m_verticalScale; 00158 int m_colourMap; 00159 PlotStyle m_plotStyle; 00160 00161 typedef std::map<float, int> SpacingMap; 00162 00163 // region value -> ordering 00164 SpacingMap m_spacingMap; 00165 00166 // region value -> number of regions with this value 00167 SpacingMap m_distributionMap; 00168 00169 int spacingIndexToY(View *v, int i) const; 00170 float yToSpacingIndex(View *v, int y) const; 00171 00172 void finish(RegionModel::EditCommand *command) { 00173 Command *c = command->finish(); 00174 if (c) CommandHistory::getInstance()->addCommand(c, false); 00175 } 00176 }; 00177 00178 #endif 00179