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@303: #ifndef _IMAGE_LAYER_H_ Chris@303: #define _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@916: virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; Chris@303: Chris@918: virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; Chris@303: Chris@918: virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, Chris@1266: int &resolution, Chris@1266: SnapType snap) const; Chris@303: Chris@918: virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); Chris@918: virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); Chris@918: virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); Chris@303: Chris@918: virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); Chris@918: virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); Chris@918: virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); Chris@303: Chris@905: virtual void moveSelection(Selection s, sv_frame_t newStartFrame); Chris@303: virtual void resizeSelection(Selection s, Selection newSize); Chris@303: virtual void deleteSelection(Selection s); Chris@303: Chris@918: virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); Chris@918: virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, Chris@303: bool interactive); Chris@303: Chris@918: virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *); // on double-click Chris@303: Chris@303: virtual const Model *getModel() const { return m_model; } Chris@303: void setModel(ImageModel *model); Chris@303: Chris@303: virtual PropertyList getProperties() const; Chris@303: virtual QString getPropertyLabel(const PropertyName &) const; Chris@303: virtual PropertyType getPropertyType(const PropertyName &) const; Chris@303: virtual int getPropertyRangeAndValue(const PropertyName &, Chris@303: int *min, int *max, int *deflt) const; Chris@303: virtual QString getPropertyValueLabel(const PropertyName &, Chris@1266: int value) const; Chris@303: virtual void setProperty(const PropertyName &, int value); Chris@303: Chris@303: virtual ColourSignificance getLayerColourSignificance() const { Chris@303: return ColourAbsent; Chris@303: } Chris@303: Chris@918: virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; Chris@303: Chris@303: virtual bool isLayerEditable() const { return true; } Chris@303: Chris@918: virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } Chris@303: Chris@905: virtual bool getValueExtents(double &min, double &max, Chris@303: bool &logarithmic, QString &unit) const; Chris@303: Chris@316: virtual void toXml(QTextStream &stream, QString indent = "", Chris@316: QString extraAttributes = "") const; Chris@303: Chris@918: virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const { return 0; } Chris@607: Chris@918: virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant); Chris@303: Chris@303: void setProperties(const QXmlAttributes &attributes); 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@918: ImageModel::PointList 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@918: void drawImage(LayerGeometryProvider *v, QPainter &paint, const ImageModel::Point &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@303: ImageModel *m_model; Chris@303: bool m_editing; Chris@303: QPoint m_editOrigin; Chris@303: ImageModel::Point m_originalPoint; Chris@303: ImageModel::Point m_editingPoint; Chris@303: ImageModel::EditCommand *m_editingCommand; Chris@376: Chris@376: void finish(ImageModel::EditCommand *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: