annotate layer/RegionLayer.h @ 1521:d3ef60b6ae93 time-frequency-boxes

With duration and two values, propose a box model (value and extent)
author Chris Cannam
date Wed, 25 Sep 2019 11:09:06 +0100
parents 696e569ff21b
children e6362cf5ff1d
rev   line source
Chris@411 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@411 2
Chris@411 3 /*
Chris@411 4 Sonic Visualiser
Chris@411 5 An audio file viewer and annotation editor.
Chris@411 6 Centre for Digital Music, Queen Mary, University of London.
Chris@411 7 This file copyright 2006-2008 Chris Cannam and QMUL.
Chris@411 8
Chris@411 9 This program is free software; you can redistribute it and/or
Chris@411 10 modify it under the terms of the GNU General Public License as
Chris@411 11 published by the Free Software Foundation; either version 2 of the
Chris@411 12 License, or (at your option) any later version. See the file
Chris@411 13 COPYING included with this distribution for more information.
Chris@411 14 */
Chris@411 15
Chris@1362 16 #ifndef SV_REGION_LAYER_H
Chris@1362 17 #define SV_REGION_LAYER_H
Chris@411 18
Chris@411 19 #include "SingleColourLayer.h"
Chris@701 20 #include "VerticalScaleLayer.h"
Chris@701 21 #include "ColourScaleLayer.h"
Chris@701 22
Chris@411 23 #include "data/model/RegionModel.h"
Chris@411 24
Chris@411 25 #include <QObject>
Chris@411 26 #include <QColor>
Chris@411 27
Chris@433 28 #include <map>
Chris@433 29
Chris@411 30 class View;
Chris@411 31 class QPainter;
Chris@411 32
Chris@701 33 class RegionLayer : public SingleColourLayer,
Chris@701 34 public VerticalScaleLayer,
Chris@701 35 public ColourScaleLayer
Chris@411 36 {
Chris@411 37 Q_OBJECT
Chris@411 38
Chris@411 39 public:
Chris@411 40 RegionLayer();
Chris@411 41
Chris@1406 42 void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
Chris@411 43
Chris@1406 44 int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
Chris@1406 45 void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
Chris@701 46
Chris@1406 47 QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
Chris@1406 48 QString getLabelPreceding(sv_frame_t) const override;
Chris@411 49
Chris@1406 50 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1430 51 int &resolution,
Chris@1430 52 SnapType snap) const override;
Chris@1406 53 bool snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1430 54 int &resolution,
Chris@1430 55 SnapType snap) const override;
Chris@411 56
Chris@1406 57 void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 58 void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 59 void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@411 60
Chris@1406 61 void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 62 void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 63 void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@411 64
Chris@1406 65 void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 66 void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 67 void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@411 68
Chris@1406 69 bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@411 70
Chris@1406 71 void moveSelection(Selection s, sv_frame_t newStartFrame) override;
Chris@1406 72 void resizeSelection(Selection s, Selection newSize) override;
Chris@1406 73 void deleteSelection(Selection s) override;
Chris@411 74
Chris@1406 75 void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
Chris@1406 76 bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
Chris@1406 77 bool interactive) override;
Chris@411 78
Chris@1470 79 ModelId getModel() const override { return m_model; }
Chris@1470 80 void setModel(ModelId model); // a RegionModel
Chris@411 81
Chris@1406 82 PropertyList getProperties() const override;
Chris@1406 83 QString getPropertyLabel(const PropertyName &) const override;
Chris@1406 84 PropertyType getPropertyType(const PropertyName &) const override;
Chris@1406 85 QString getPropertyGroupName(const PropertyName &) const override;
Chris@1406 86 int getPropertyRangeAndValue(const PropertyName &,
Chris@1406 87 int *min, int *max, int *deflt) const override;
Chris@1406 88 QString getPropertyValueLabel(const PropertyName &,
Chris@1406 89 int value) const override;
Chris@1406 90 void setProperty(const PropertyName &, int value) override;
Chris@411 91
Chris@427 92 void setFillColourMap(int);
Chris@427 93 int getFillColourMap() const { return m_colourMap; }
Chris@427 94
Chris@411 95 enum VerticalScale {
Chris@411 96 AutoAlignScale,
Chris@433 97 EqualSpaced,
Chris@411 98 LinearScale,
Chris@411 99 LogScale,
Chris@411 100 };
Chris@411 101
Chris@411 102 void setVerticalScale(VerticalScale scale);
Chris@411 103 VerticalScale getVerticalScale() const { return m_verticalScale; }
Chris@411 104
Chris@412 105 enum PlotStyle {
Chris@1266 106 PlotLines,
Chris@1266 107 PlotSegmentation
Chris@412 108 };
Chris@412 109
Chris@412 110 void setPlotStyle(PlotStyle style);
Chris@412 111 PlotStyle getPlotStyle() const { return m_plotStyle; }
Chris@412 112
Chris@1406 113 bool isLayerScrollable(const LayerGeometryProvider *v) const override;
Chris@411 114
Chris@1406 115 bool isLayerEditable() const override { return true; }
Chris@411 116
Chris@1470 117 int getCompletion(LayerGeometryProvider *) const override;
Chris@411 118
Chris@1406 119 bool getValueExtents(double &min, double &max,
Chris@1406 120 bool &log, QString &unit) const override;
Chris@411 121
Chris@1406 122 bool getDisplayExtents(double &min, double &max) const override;
Chris@411 123
Chris@1406 124 void toXml(QTextStream &stream, QString indent = "",
Chris@1406 125 QString extraAttributes = "") const override;
Chris@411 126
Chris@1406 127 void setProperties(const QXmlAttributes &attributes) override;
Chris@607 128
Chris@701 129 /// VerticalScaleLayer and ColourScaleLayer methods
Chris@1406 130 int getYForValue(LayerGeometryProvider *v, double value) const override;
Chris@1406 131 double getValueForY(LayerGeometryProvider *v, int y) const override;
Chris@1406 132 QString getScaleUnits() const override;
Chris@1406 133 QColor getColourForValue(LayerGeometryProvider *v, double value) const override;
Chris@411 134
Chris@433 135 protected slots:
Chris@433 136 void recalcSpacing();
Chris@433 137
Chris@411 138 protected:
Chris@918 139 double getValueForY(LayerGeometryProvider *v, int y, int avoid) const;
Chris@918 140 void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const;
Chris@411 141
Chris@1406 142 int getDefaultColourHint(bool dark, bool &impose) override;
Chris@411 143
Chris@1428 144 EventVector getLocalPoints(LayerGeometryProvider *v, int x) const;
Chris@550 145
Chris@1428 146 bool getPointToDrag(LayerGeometryProvider *v, int x, int y, Event &) const;
Chris@411 147
Chris@1470 148 ModelId m_model;
Chris@411 149 bool m_editing;
Chris@551 150 int m_dragPointX;
Chris@551 151 int m_dragPointY;
Chris@551 152 int m_dragStartX;
Chris@551 153 int m_dragStartY;
Chris@1428 154 Event m_originalPoint;
Chris@1428 155 Event m_editingPoint;
Chris@1428 156 ChangeEventsCommand *m_editingCommand;
Chris@411 157 VerticalScale m_verticalScale;
Chris@427 158 int m_colourMap;
Chris@1362 159 bool m_colourInverted;
Chris@412 160 PlotStyle m_plotStyle;
Chris@411 161
Chris@905 162 typedef std::map<double, int> SpacingMap;
Chris@551 163
Chris@542 164 // region value -> ordering
Chris@433 165 SpacingMap m_spacingMap;
Chris@433 166
Chris@551 167 // region value -> number of regions with this value
Chris@551 168 SpacingMap m_distributionMap;
Chris@551 169
Chris@918 170 int spacingIndexToY(LayerGeometryProvider *v, int i) const;
Chris@918 171 double yToSpacingIndex(LayerGeometryProvider *v, int y) const;
Chris@542 172
Chris@1428 173 void finish(ChangeEventsCommand *command) {
Chris@411 174 Command *c = command->finish();
Chris@411 175 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@411 176 }
Chris@411 177 };
Chris@411 178
Chris@411 179 #endif
Chris@411 180