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@303: virtual void paint(View *v, QPainter &paint, QRect rect) const; Chris@303: Chris@303: virtual QString getFeatureDescription(View *v, QPoint &) const; Chris@303: Chris@303: virtual bool snapToFeatureFrame(View *v, int &frame, Chris@805: int &resolution, Chris@303: SnapType snap) const; Chris@303: Chris@303: virtual void drawStart(View *v, QMouseEvent *); Chris@303: virtual void drawDrag(View *v, QMouseEvent *); Chris@303: virtual void drawEnd(View *v, QMouseEvent *); Chris@303: Chris@303: virtual void editStart(View *v, QMouseEvent *); Chris@303: virtual void editDrag(View *v, QMouseEvent *); Chris@303: virtual void editEnd(View *v, QMouseEvent *); Chris@303: Chris@805: virtual void moveSelection(Selection s, int newStartFrame); Chris@303: virtual void resizeSelection(Selection s, Selection newSize); Chris@303: virtual void deleteSelection(Selection s); Chris@303: Chris@359: virtual void copy(View *v, Selection s, Clipboard &to); Chris@359: virtual bool paste(View *v, const Clipboard &from, int frameOffset, Chris@303: bool interactive); Chris@303: Chris@303: virtual bool editOpen(View *, 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@303: 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@303: virtual bool isLayerScrollable(const View *v) const; Chris@303: Chris@303: virtual bool isLayerEditable() const { return true; } Chris@303: Chris@303: virtual int getCompletion(View *) const { return m_model->getCompletion(); } Chris@303: Chris@303: virtual bool getValueExtents(float &min, float &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@607: virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } Chris@607: Chris@303: virtual void setLayerDormant(const View *v, bool dormant); Chris@303: Chris@303: void setProperties(const QXmlAttributes &attributes); Chris@303: Chris@806: virtual bool addImage(int 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@303: ImageModel::PointList getLocalPoints(View *v, int x, int y) const; Chris@303: Chris@304: bool getImageOriginalSize(QString name, QSize &size) const; Chris@303: QImage getImage(View *v, QString name, QSize maxSize) const; Chris@303: Chris@304: void drawImage(View *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@303: 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: