Chris@303: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@303: Chris@303: /* Chris@303: Sonic Visualiser Chris@303: An audio file viewer and annotation editor. Chris@303: Centre for Digital Music, Queen Mary, University of London. Chris@303: This file copyright 2006-2007 Chris Cannam and QMUL. Chris@303: Chris@303: This program is free software; you can redistribute it and/or Chris@303: modify it under the terms of the GNU General Public License as Chris@303: published by the Free Software Foundation; either version 2 of the Chris@303: License, or (at your option) any later version. See the file Chris@303: COPYING included with this distribution for more information. Chris@303: */ Chris@303: Chris@1407: #ifndef SV_IMAGE_LAYER_H Chris@1407: #define SV_IMAGE_LAYER_H Chris@303: Chris@303: #include "Layer.h" Chris@303: #include "data/model/ImageModel.h" Chris@303: Chris@303: #include Chris@303: #include Chris@303: #include Chris@305: #include Chris@303: Chris@303: #include Chris@303: Chris@303: class View; Chris@303: class QPainter; Chris@318: class FileSource; Chris@303: Chris@303: class ImageLayer : public Layer Chris@303: { Chris@303: Q_OBJECT Chris@303: Chris@303: public: Chris@303: ImageLayer(); Chris@305: virtual ~ImageLayer(); Chris@303: Chris@1406: void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override; Chris@303: Chris@1406: QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override; Chris@303: Chris@1406: bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, Chris@1469: int &resolution, Chris@1469: SnapType snap) const override; Chris@303: Chris@1406: void drawStart(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1406: void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1406: void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override; Chris@303: Chris@1406: void editStart(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1406: void editDrag(LayerGeometryProvider *v, QMouseEvent *) override; Chris@1406: void editEnd(LayerGeometryProvider *v, QMouseEvent *) override; Chris@303: Chris@1406: void moveSelection(Selection s, sv_frame_t newStartFrame) override; Chris@1406: void resizeSelection(Selection s, Selection newSize) override; Chris@1406: void deleteSelection(Selection s) override; Chris@303: Chris@1406: void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override; Chris@1406: bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, Chris@1406: bool interactive) override; Chris@303: Chris@1406: bool editOpen(LayerGeometryProvider *, QMouseEvent *) override; // on double-click Chris@303: Chris@1469: ModelId getModel() const override { return m_model; } Chris@1469: void setModel(ModelId model); // an ImageModel please Chris@303: Chris@1406: PropertyList getProperties() const override; Chris@1406: QString getPropertyLabel(const PropertyName &) const override; Chris@1406: PropertyType getPropertyType(const PropertyName &) const override; Chris@1406: int getPropertyRangeAndValue(const PropertyName &, Chris@1469: int *min, int *max, int *deflt) const override; Chris@1406: QString getPropertyValueLabel(const PropertyName &, Chris@1469: int value) const override; Chris@1406: void setProperty(const PropertyName &, int value) override; Chris@303: Chris@1406: ColourSignificance getLayerColourSignificance() const override { Chris@303: return ColourAbsent; Chris@303: } Chris@303: Chris@1406: bool isLayerScrollable(const LayerGeometryProvider *v) const override; Chris@303: Chris@1406: bool isLayerEditable() const override { return true; } Chris@303: Chris@1469: int getCompletion(LayerGeometryProvider *) const override; Chris@303: Chris@1406: bool getValueExtents(double &min, double &max, Chris@1469: bool &logarithmic, QString &unit) const override; Chris@303: Chris@1406: void toXml(QTextStream &stream, QString indent = "", Chris@1469: QString extraAttributes = "") const override; Chris@303: Chris@1406: int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const override { return 0; } Chris@607: Chris@1406: void setLayerDormant(const LayerGeometryProvider *v, bool dormant) override; Chris@303: Chris@1406: void setProperties(const QXmlAttributes &attributes) override; Chris@303: Chris@905: virtual bool addImage(sv_frame_t frame, QString url); // using a command Chris@312: Chris@305: protected slots: Chris@464: void checkAddSources(); Chris@464: void fileSourceReady(); Chris@305: Chris@303: protected: Chris@1438: EventVector getLocalPoints(LayerGeometryProvider *v, int x, int y) const; Chris@303: Chris@304: bool getImageOriginalSize(QString name, QSize &size) const; Chris@918: QImage getImage(LayerGeometryProvider *v, QString name, QSize maxSize) const; Chris@303: Chris@1438: void drawImage(LayerGeometryProvider *v, QPainter &paint, const Event &p, Chris@304: int x, int nx) const; Chris@304: Chris@303: //!!! how to reap no-longer-used images? Chris@303: Chris@303: typedef std::map ImageMap; Chris@918: typedef std::map ViewImageMap; Chris@318: typedef std::map FileSourceMap; Chris@304: Chris@303: static ImageMap m_images; Chris@305: static QMutex m_imageMapMutex; Chris@303: mutable ViewImageMap m_scaled; Chris@464: mutable FileSourceMap m_fileSources; Chris@305: Chris@305: QString getLocalFilename(QString img) const; Chris@464: void checkAddSource(QString img) const; Chris@303: Chris@1469: ModelId m_model; // an ImageModel Chris@303: bool m_editing; Chris@303: QPoint m_editOrigin; Chris@1438: Event m_originalPoint; Chris@1438: Event m_editingPoint; Chris@1470: ChangeEventsCommand *m_editingCommand; Chris@376: Chris@1470: void finish(ChangeEventsCommand *command) { Chris@376: Command *c = command->finish(); Chris@376: if (c) CommandHistory::getInstance()->addCommand(c, false); Chris@376: } Chris@303: }; Chris@303: Chris@303: #endif Chris@303: