svgui  1.9
TimeValueLayer.h
Go to the documentation of this file.
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_VALUE_LAYER_H_
00017 #define _TIME_VALUE_LAYER_H_
00018 
00019 #include "SingleColourLayer.h"
00020 #include "VerticalScaleLayer.h"
00021 #include "ColourScaleLayer.h"
00022 
00023 #include "data/model/SparseTimeValueModel.h"
00024 
00025 #include <QObject>
00026 #include <QColor>
00027 
00028 class View;
00029 class QPainter;
00030 
00031 class TimeValueLayer : public SingleColourLayer, 
00032                        public VerticalScaleLayer, 
00033                        public ColourScaleLayer
00034 {
00035     Q_OBJECT
00036 
00037 public:
00038     TimeValueLayer();
00039 
00040     virtual void paint(View *v, QPainter &paint, QRect rect) const;
00041 
00042     virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const;
00043     virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const;
00044 
00045     virtual QString getFeatureDescription(View *v, QPoint &) const;
00046     virtual QString getLabelPreceding(int) const;
00047 
00048     virtual bool snapToFeatureFrame(View *v, int &frame,
00049                                     int &resolution,
00050                                     SnapType snap) const;
00051     virtual bool snapToSimilarFeature(View *v, int &frame,
00052                                       int &resolution,
00053                                       SnapType snap) const;
00054 
00055     virtual void drawStart(View *v, QMouseEvent *);
00056     virtual void drawDrag(View *v, QMouseEvent *);
00057     virtual void drawEnd(View *v, QMouseEvent *);
00058 
00059     virtual void eraseStart(View *v, QMouseEvent *);
00060     virtual void eraseDrag(View *v, QMouseEvent *);
00061     virtual void eraseEnd(View *v, QMouseEvent *);
00062 
00063     virtual void editStart(View *v, QMouseEvent *);
00064     virtual void editDrag(View *v, QMouseEvent *);
00065     virtual void editEnd(View *v, QMouseEvent *);
00066 
00067     virtual bool editOpen(View *v, QMouseEvent *);
00068 
00069     virtual void moveSelection(Selection s, int newStartFrame);
00070     virtual void resizeSelection(Selection s, Selection newSize);
00071     virtual void deleteSelection(Selection s);
00072 
00073     virtual void copy(View *v, Selection s, Clipboard &to);
00074     virtual bool paste(View *v, const Clipboard &from, int frameOffset,
00075                        bool interactive);
00076 
00077     virtual const Model *getModel() const { return m_model; }
00078     void setModel(SparseTimeValueModel *model);
00079 
00080     virtual PropertyList getProperties() const;
00081     virtual QString getPropertyLabel(const PropertyName &) const;
00082     virtual QString getPropertyIconName(const PropertyName &) const;
00083     virtual PropertyType getPropertyType(const PropertyName &) const;
00084     virtual QString getPropertyGroupName(const PropertyName &) const;
00085     virtual int getPropertyRangeAndValue(const PropertyName &,
00086                                          int *min, int *max, int *deflt) const;
00087     virtual QString getPropertyValueLabel(const PropertyName &,
00088                                           int value) const;
00089     virtual void setProperty(const PropertyName &, int value);
00090 
00091     void setFillColourMap(int);
00092     int getFillColourMap() const { return m_colourMap; }
00093 
00094     enum PlotStyle {
00095         PlotPoints,
00096         PlotStems,
00097         PlotConnectedPoints,
00098         PlotLines,
00099         PlotCurve,
00100         PlotSegmentation,
00101         PlotDiscreteCurves
00102     };
00103 
00104     void setPlotStyle(PlotStyle style);
00105     PlotStyle getPlotStyle() const { return m_plotStyle; }
00106 
00107     enum VerticalScale {
00108         AutoAlignScale,
00109         LinearScale,
00110         LogScale,
00111         PlusMinusOneScale
00112     };
00113     
00114     void setVerticalScale(VerticalScale scale);
00115     VerticalScale getVerticalScale() const { return m_verticalScale; }
00116 
00117     void setDrawSegmentDivisions(bool);
00118     bool getDrawSegmentDivisions() const { return m_drawSegmentDivisions; }
00119 
00120     void setShowDerivative(bool);
00121     bool getShowDerivative() const { return m_derivative; }
00122 
00123     virtual bool isLayerScrollable(const View *v) const;
00124 
00125     virtual bool isLayerEditable() const { return true; }
00126 
00127     virtual int getCompletion(View *) const { return m_model->getCompletion(); }
00128 
00129     virtual bool needsTextLabelHeight() const {
00130         return m_plotStyle == PlotSegmentation && m_model->hasTextLabels();
00131     }
00132 
00133     virtual bool getValueExtents(float &min, float &max,
00134                                  bool &logarithmic, QString &unit) const;
00135 
00136     virtual bool getDisplayExtents(float &min, float &max) const;
00137     virtual bool setDisplayExtents(float min, float max);
00138 
00139     virtual int getVerticalZoomSteps(int &defaultStep) const;
00140     virtual int getCurrentVerticalZoomStep() const;
00141     virtual void setVerticalZoomStep(int);
00142     virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
00143 
00144     virtual void toXml(QTextStream &stream, QString indent = "",
00145                        QString extraAttributes = "") const;
00146 
00147     void setProperties(const QXmlAttributes &attributes);
00148 
00149     virtual ColourSignificance getLayerColourSignificance() const {
00150         if (m_plotStyle == PlotSegmentation) {
00151             return ColourHasMeaningfulValue;
00152         } else {
00153             return ColourDistinguishes;
00154         }
00155     }
00156 
00158     virtual int getYForValue(View *, float value) const;
00159     virtual float getValueForY(View *, int y) const;
00160     virtual QString getScaleUnits() const;
00161     virtual QColor getColourForValue(View *v, float value) const;
00162 
00163 protected:
00164     void getScaleExtents(View *, float &min, float &max, bool &log) const;
00165     bool shouldAutoAlign() const;
00166 
00167     SparseTimeValueModel::PointList getLocalPoints(View *v, int) const;
00168 
00169     virtual int getDefaultColourHint(bool dark, bool &impose);
00170 
00171     SparseTimeValueModel *m_model;
00172     bool m_editing;
00173     SparseTimeValueModel::Point m_originalPoint;
00174     SparseTimeValueModel::Point m_editingPoint;
00175     SparseTimeValueModel::EditCommand *m_editingCommand;
00176     int m_colourMap;
00177     PlotStyle m_plotStyle;
00178     VerticalScale m_verticalScale;
00179     bool m_drawSegmentDivisions;
00180     bool m_derivative;
00181 
00182     mutable float m_scaleMinimum;
00183     mutable float m_scaleMaximum;
00184 
00185     void finish(SparseTimeValueModel::EditCommand *command) {
00186         Command *c = command->finish();
00187         if (c) CommandHistory::getInstance()->addCommand(c, false);
00188     }
00189 };
00190 
00191 #endif
00192