00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _IMAGE_LAYER_H_
00017 #define _IMAGE_LAYER_H_
00018
00019 #include "Layer.h"
00020 #include "data/model/ImageModel.h"
00021
00022 #include <QObject>
00023 #include <QColor>
00024 #include <QImage>
00025 #include <QMutex>
00026
00027 #include <map>
00028
00029 class View;
00030 class QPainter;
00031 class FileSource;
00032
00033 class ImageLayer : public Layer
00034 {
00035 Q_OBJECT
00036
00037 public:
00038 ImageLayer();
00039 virtual ~ImageLayer();
00040
00041 virtual void paint(View *v, QPainter &paint, QRect rect) const;
00042
00043 virtual QString getFeatureDescription(View *v, QPoint &) const;
00044
00045 virtual bool snapToFeatureFrame(View *v, int &frame,
00046 size_t &resolution,
00047 SnapType snap) const;
00048
00049 virtual void drawStart(View *v, QMouseEvent *);
00050 virtual void drawDrag(View *v, QMouseEvent *);
00051 virtual void drawEnd(View *v, QMouseEvent *);
00052
00053 virtual void editStart(View *v, QMouseEvent *);
00054 virtual void editDrag(View *v, QMouseEvent *);
00055 virtual void editEnd(View *v, QMouseEvent *);
00056
00057 virtual void moveSelection(Selection s, size_t newStartFrame);
00058 virtual void resizeSelection(Selection s, Selection newSize);
00059 virtual void deleteSelection(Selection s);
00060
00061 virtual void copy(View *v, Selection s, Clipboard &to);
00062 virtual bool paste(View *v, const Clipboard &from, int frameOffset,
00063 bool interactive);
00064
00065 virtual bool editOpen(View *, QMouseEvent *);
00066
00067 virtual const Model *getModel() const { return m_model; }
00068 void setModel(ImageModel *model);
00069
00070 virtual PropertyList getProperties() const;
00071 virtual QString getPropertyLabel(const PropertyName &) const;
00072 virtual PropertyType getPropertyType(const PropertyName &) const;
00073 virtual int getPropertyRangeAndValue(const PropertyName &,
00074 int *min, int *max, int *deflt) const;
00075 virtual QString getPropertyValueLabel(const PropertyName &,
00076 int value) const;
00077 virtual void setProperty(const PropertyName &, int value);
00078
00079 virtual ColourSignificance getLayerColourSignificance() const {
00080 return ColourAbsent;
00081 }
00082
00083 virtual bool isLayerScrollable(const View *v) const;
00084
00085 virtual bool isLayerEditable() const { return true; }
00086
00087 virtual int getCompletion(View *) const { return m_model->getCompletion(); }
00088
00089 virtual bool getValueExtents(float &min, float &max,
00090 bool &logarithmic, QString &unit) const;
00091
00092 virtual void toXml(QTextStream &stream, QString indent = "",
00093 QString extraAttributes = "") const;
00094
00095 virtual void setLayerDormant(const View *v, bool dormant);
00096
00097 void setProperties(const QXmlAttributes &attributes);
00098
00099 virtual bool addImage(long frame, QString url);
00100
00101 protected slots:
00102 void checkAddRemotes();
00103 void remoteFileReady();
00104
00105 protected:
00106 ImageModel::PointList getLocalPoints(View *v, int x, int y) const;
00107
00108 bool getImageOriginalSize(QString name, QSize &size) const;
00109 QImage getImage(View *v, QString name, QSize maxSize) const;
00110
00111 void drawImage(View *v, QPainter &paint, const ImageModel::Point &p,
00112 int x, int nx) const;
00113
00115
00116 typedef std::map<QString, QImage> ImageMap;
00117 typedef std::map<const View *, ImageMap> ViewImageMap;
00118 typedef std::map<QString, FileSource *> FileSourceMap;
00119
00120 static ImageMap m_images;
00121 static QMutex m_imageMapMutex;
00122 mutable ViewImageMap m_scaled;
00123 mutable FileSourceMap m_remoteFiles;
00124
00125 QString getLocalFilename(QString img) const;
00126 void checkAddRemote(QString img) const;
00127
00128 ImageModel *m_model;
00129 bool m_editing;
00130 QPoint m_editOrigin;
00131 ImageModel::Point m_originalPoint;
00132 ImageModel::Point m_editingPoint;
00133 ImageModel::EditCommand *m_editingCommand;
00134 };
00135
00136 #endif
00137