annotate layer/ImageLayer.h @ 303:46faec7aae12

* Phase 1 of an image layer.
author Chris Cannam
date Thu, 04 Oct 2007 16:34:11 +0000
parents
children 4b7e8da8f069
rev   line source
Chris@303 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@303 2
Chris@303 3 /*
Chris@303 4 Sonic Visualiser
Chris@303 5 An audio file viewer and annotation editor.
Chris@303 6 Centre for Digital Music, Queen Mary, University of London.
Chris@303 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@303 8
Chris@303 9 This program is free software; you can redistribute it and/or
Chris@303 10 modify it under the terms of the GNU General Public License as
Chris@303 11 published by the Free Software Foundation; either version 2 of the
Chris@303 12 License, or (at your option) any later version. See the file
Chris@303 13 COPYING included with this distribution for more information.
Chris@303 14 */
Chris@303 15
Chris@303 16 #ifndef _IMAGE_LAYER_H_
Chris@303 17 #define _IMAGE_LAYER_H_
Chris@303 18
Chris@303 19 #include "Layer.h"
Chris@303 20 #include "data/model/ImageModel.h"
Chris@303 21
Chris@303 22 #include <QObject>
Chris@303 23 #include <QColor>
Chris@303 24 #include <QImage>
Chris@303 25
Chris@303 26 #include <map>
Chris@303 27
Chris@303 28 class View;
Chris@303 29 class QPainter;
Chris@303 30
Chris@303 31 class ImageLayer : public Layer
Chris@303 32 {
Chris@303 33 Q_OBJECT
Chris@303 34
Chris@303 35 public:
Chris@303 36 ImageLayer();
Chris@303 37
Chris@303 38 virtual void paint(View *v, QPainter &paint, QRect rect) const;
Chris@303 39
Chris@303 40 virtual QString getFeatureDescription(View *v, QPoint &) const;
Chris@303 41
Chris@303 42 virtual bool snapToFeatureFrame(View *v, int &frame,
Chris@303 43 size_t &resolution,
Chris@303 44 SnapType snap) const;
Chris@303 45
Chris@303 46 virtual void drawStart(View *v, QMouseEvent *);
Chris@303 47 virtual void drawDrag(View *v, QMouseEvent *);
Chris@303 48 virtual void drawEnd(View *v, QMouseEvent *);
Chris@303 49
Chris@303 50 virtual void editStart(View *v, QMouseEvent *);
Chris@303 51 virtual void editDrag(View *v, QMouseEvent *);
Chris@303 52 virtual void editEnd(View *v, QMouseEvent *);
Chris@303 53
Chris@303 54 virtual void moveSelection(Selection s, size_t newStartFrame);
Chris@303 55 virtual void resizeSelection(Selection s, Selection newSize);
Chris@303 56 virtual void deleteSelection(Selection s);
Chris@303 57
Chris@303 58 virtual void copy(Selection s, Clipboard &to);
Chris@303 59 virtual bool paste(const Clipboard &from, int frameOffset,
Chris@303 60 bool interactive);
Chris@303 61
Chris@303 62 virtual bool editOpen(View *, QMouseEvent *); // on double-click
Chris@303 63
Chris@303 64 virtual const Model *getModel() const { return m_model; }
Chris@303 65 void setModel(ImageModel *model);
Chris@303 66
Chris@303 67 virtual PropertyList getProperties() const;
Chris@303 68 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@303 69 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@303 70 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@303 71 int *min, int *max, int *deflt) const;
Chris@303 72 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@303 73 int value) const;
Chris@303 74 virtual void setProperty(const PropertyName &, int value);
Chris@303 75
Chris@303 76 virtual ColourSignificance getLayerColourSignificance() const {
Chris@303 77 return ColourAbsent;
Chris@303 78 }
Chris@303 79
Chris@303 80 virtual bool isLayerScrollable(const View *v) const;
Chris@303 81
Chris@303 82 virtual bool isLayerEditable() const { return true; }
Chris@303 83
Chris@303 84 virtual int getCompletion(View *) const { return m_model->getCompletion(); }
Chris@303 85
Chris@303 86 virtual bool getValueExtents(float &min, float &max,
Chris@303 87 bool &logarithmic, QString &unit) const;
Chris@303 88
Chris@303 89 virtual QString toXmlString(QString indent = "",
Chris@303 90 QString extraAttributes = "") const;
Chris@303 91
Chris@303 92 virtual void setLayerDormant(const View *v, bool dormant);
Chris@303 93
Chris@303 94 void setProperties(const QXmlAttributes &attributes);
Chris@303 95
Chris@303 96 protected:
Chris@303 97 ImageModel::PointList getLocalPoints(View *v, int x, int y) const;
Chris@303 98
Chris@303 99 float getImageAspect(QString name) const;
Chris@303 100 QImage getImage(View *v, QString name, QSize maxSize) const;
Chris@303 101
Chris@303 102 //!!! how to reap no-longer-used images?
Chris@303 103
Chris@303 104 typedef std::map<QString, QImage> ImageMap;
Chris@303 105 typedef std::map<const View *, ImageMap> ViewImageMap;
Chris@303 106
Chris@303 107 static ImageMap m_images;
Chris@303 108 mutable ViewImageMap m_scaled;
Chris@303 109
Chris@303 110 ImageModel *m_model;
Chris@303 111 bool m_editing;
Chris@303 112 QPoint m_editOrigin;
Chris@303 113 ImageModel::Point m_originalPoint;
Chris@303 114 ImageModel::Point m_editingPoint;
Chris@303 115 ImageModel::EditCommand *m_editingCommand;
Chris@303 116 };
Chris@303 117
Chris@303 118 #endif
Chris@303 119