Chris@1511: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1511: Chris@1511: /* Chris@1511: Sonic Visualiser Chris@1511: An audio file viewer and annotation editor. Chris@1511: Centre for Digital Music, Queen Mary, University of London. Chris@1511: Chris@1511: This program is free software; you can redistribute it and/or Chris@1511: modify it under the terms of the GNU General Public License as Chris@1511: published by the Free Software Foundation; either version 2 of the Chris@1511: License, or (at your option) any later version. See the file Chris@1511: COPYING included with this distribution for more information. Chris@1511: */ Chris@1511: Chris@1518: #ifndef SV_BOX_LAYER_H Chris@1518: #define SV_BOX_LAYER_H Chris@1511: Chris@1511: #include "SingleColourLayer.h" Chris@1511: #include "VerticalScaleLayer.h" Chris@1511: Chris@1518: #include "data/model/BoxModel.h" Chris@1511: Chris@1511: #include Chris@1511: #include Chris@1511: Chris@1511: #include Chris@1511: Chris@1511: class View; Chris@1511: class QPainter; Chris@1511: Chris@1518: class BoxLayer : public SingleColourLayer, Chris@1511: public VerticalScaleLayer Chris@1511: { Chris@1511: Q_OBJECT Chris@1511: Chris@1511: public: Chris@1518: BoxLayer(); Chris@1511: Chris@1511: void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override; Chris@1511: Chris@1511: int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override; Chris@1511: void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override; Chris@1511: Chris@1511: QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override; Chris@1511: QString getLabelPreceding(sv_frame_t) const override; Chris@1511: Chris@1511: bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, Chris@1511: int &resolution, Chris@1547: SnapType snap, int ycoord) const override; Chris@1511: Chris@1511: void drawStart(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: Chris@1511: void eraseStart(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: void eraseDrag(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: void eraseEnd(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: Chris@1511: void editStart(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: void editDrag(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: void editEnd(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: Chris@1511: bool editOpen(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1511: Chris@1511: void moveSelection(Selection s, sv_frame_t newStartFrame) override; Chris@1511: void resizeSelection(Selection s, Selection newSize) override; Chris@1511: void deleteSelection(Selection s) override; Chris@1511: Chris@1511: void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override; Chris@1511: bool paste(LayerGeometryProvider *v, const Clipboard &from, Chris@1511: sv_frame_t frameOffset, bool interactive) override; Chris@1511: Chris@1511: ModelId getModel() const override { return m_model; } Chris@1518: void setModel(ModelId model); // a BoxModel Chris@1511: Chris@1511: PropertyList getProperties() const override; Chris@1511: QString getPropertyLabel(const PropertyName &) const override; Chris@1511: PropertyType getPropertyType(const PropertyName &) const override; Chris@1511: QString getPropertyGroupName(const PropertyName &) const override; Chris@1511: int getPropertyRangeAndValue(const PropertyName &, Chris@1511: int *min, int *max, int *deflt) const override; Chris@1511: QString getPropertyValueLabel(const PropertyName &, Chris@1511: int value) const override; Chris@1511: void setProperty(const PropertyName &, int value) override; Chris@1511: Chris@1511: enum VerticalScale { Chris@1511: AutoAlignScale, Chris@1511: LinearScale, Chris@1511: LogScale, Chris@1511: }; Chris@1511: Chris@1511: void setVerticalScale(VerticalScale scale); Chris@1511: VerticalScale getVerticalScale() const { return m_verticalScale; } Chris@1511: Chris@1511: bool isLayerScrollable(const LayerGeometryProvider *v) const override; Chris@1511: Chris@1511: bool isLayerEditable() const override { return true; } Chris@1511: Chris@1511: int getCompletion(LayerGeometryProvider *) const override; Chris@1511: Chris@1511: bool getValueExtents(double &min, double &max, Chris@1511: bool &log, QString &unit) const override; Chris@1511: Chris@1511: bool getDisplayExtents(double &min, double &max) const override; Chris@1511: Chris@1518: bool adoptExtents(double min, double max, QString unit) override; Chris@1518: Chris@1511: void toXml(QTextStream &stream, QString indent = "", Chris@1511: QString extraAttributes = "") const override; Chris@1511: Chris@1511: void setProperties(const QXmlAttributes &attributes) override; Chris@1511: Chris@1511: /// VerticalScaleLayer methods Chris@1511: int getYForValue(LayerGeometryProvider *v, double value) const override; Chris@1511: double getValueForY(LayerGeometryProvider *v, int y) const override; Chris@1511: QString getScaleUnits() const override; Chris@1511: Chris@1511: protected: Chris@1511: void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const; Chris@1511: Chris@1547: // Return the event that "most closely contains" the given Chris@1547: // coordinates, if any; or the closest event that spans the given Chris@1547: // x coordinate in the time axis; or false otherwise. This Chris@1547: // subsumes the uses of both getPointToDrag and getLocalPoints in Chris@1547: // some other layer implementations. Chris@1547: bool getLocalPoint(LayerGeometryProvider *v, int x, int y, Event &) const; Chris@1511: Chris@1511: ModelId m_model; Chris@1511: bool m_editing; Chris@1511: int m_dragPointX; Chris@1511: int m_dragPointY; Chris@1511: int m_dragStartX; Chris@1511: int m_dragStartY; Chris@1511: Event m_originalPoint; Chris@1511: Event m_editingPoint; Chris@1511: ChangeEventsCommand *m_editingCommand; Chris@1511: VerticalScale m_verticalScale; Chris@1511: Chris@1546: std::pair getRange(const Event &e) const { Chris@1546: return { e.getValue(), e.getValue() + fabsf(e.getLevel()) }; Chris@1546: } Chris@1546: Chris@1511: void finish(ChangeEventsCommand *command) { Chris@1511: Command *c = command->finish(); Chris@1511: if (c) CommandHistory::getInstance()->addCommand(c, false); Chris@1511: } Chris@1511: }; Chris@1511: Chris@1511: #endif Chris@1511: