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 SV_TIME_INSTANT_LAYER_H 17 #define SV_TIME_INSTANT_LAYER_H 18 19 #include "SingleColourLayer.h" 20 #include "data/model/SparseOneDimensionalModel.h" 21 22 #include <QObject> 23 #include <QColor> 24 25 class View; 26 class QPainter; 27 28 class TimeInstantLayer : public SingleColourLayer 29 { 30 Q_OBJECT 31 32 public: 33 TimeInstantLayer(); 34 virtual ~TimeInstantLayer(); 35 36 void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override; 37 38 QString getLabelPreceding(sv_frame_t) const override; 39 QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override; 40 41 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, 42 int &resolution, 43 SnapType snap, int ycoord) const override; 44 45 void drawStart(LayerGeometryProvider *v, QMouseEvent *) override; 46 void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override; 47 void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override; 48 49 void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override; 50 void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override; 51 void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override; 52 53 void editStart(LayerGeometryProvider *v, QMouseEvent *) override; 54 void editDrag(LayerGeometryProvider *v, QMouseEvent *) override; 55 void editEnd(LayerGeometryProvider *v, QMouseEvent *) override; 56 57 bool editOpen(LayerGeometryProvider *, QMouseEvent *) override; 58 59 void moveSelection(Selection s, sv_frame_t newStartFrame) override; 60 void resizeSelection(Selection s, Selection newSize) override; 61 void deleteSelection(Selection s) override; 62 63 void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override; 64 bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, 65 bool interactive) override; 66 67 ModelId getModel() const override { return m_model; } 68 void setModel(ModelId model); // a SparseOneDimensionalModel 69 70 PropertyList getProperties() const override; 71 QString getPropertyLabel(const PropertyName &) const override; 72 PropertyType getPropertyType(const PropertyName &) const override; 73 int getPropertyRangeAndValue(const PropertyName &, 74 int *min, int *max, int *deflt) const override; 75 QString getPropertyValueLabel(const PropertyName &, 76 int value) const override; 77 void setProperty(const PropertyName &, int value) override; 78 79 enum PlotStyle { 80 PlotInstants, 81 PlotSegmentation 82 }; 83 84 void setPlotStyle(PlotStyle style); 85 PlotStyle getPlotStyle() const { return m_plotStyle; } 86 87 bool isLayerScrollable(const LayerGeometryProvider *v) const override; 88 89 bool isLayerEditable() const override { return true; } 90 91 int getCompletion(LayerGeometryProvider *) const override; 92 93 bool needsTextLabelHeight() const override; 94 95 bool getValueExtents(double &, double &, bool &, QString &) const override { 96 return false; 97 } 98 99 void toXml(QTextStream &stream, QString indent = "", 100 QString extraAttributes = "") const override; 101 102 void setProperties(const QXmlAttributes &attributes) override; 103 104 ColourSignificance getLayerColourSignificance() const override { 105 if (m_plotStyle == PlotSegmentation) { 106 return ColourHasMeaningfulValue; 107 } else { 108 return ColourDistinguishes; 109 } 110 } 111 112 int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const override { return 0; } 113 114 protected: 115 EventVector getLocalPoints(LayerGeometryProvider *v, int) const; 116 117 int getDefaultColourHint(bool dark, bool &impose) override; 118 119 bool clipboardAlignmentDiffers(LayerGeometryProvider *v, const Clipboard &) const; 120 121 ModelId m_model; 122 bool m_editing; 123 Event m_editingPoint; 124 ChangeEventsCommand *m_editingCommand; 125 PlotStyle m_plotStyle; 126 127 void finish(ChangeEventsCommand *command) { 128 Command *c = command->finish(); 129 if (c) CommandHistory::getInstance()->addCommand(c, false); 130 } 131 }; 132 133 #endif 134 135