annotate layer/ImageLayer.h @ 954:17cb48115d22 osx-retina

Fix positioning of local feature illumination rectangle
author Chris Cannam
date Wed, 29 Apr 2015 13:02:57 +0100
parents 4fe7a09be0fe
children a34a2a25907c
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@305 25 #include <QMutex>
Chris@303 26
Chris@303 27 #include <map>
Chris@303 28
Chris@303 29 class View;
Chris@303 30 class QPainter;
Chris@318 31 class FileSource;
Chris@303 32
Chris@303 33 class ImageLayer : public Layer
Chris@303 34 {
Chris@303 35 Q_OBJECT
Chris@303 36
Chris@303 37 public:
Chris@303 38 ImageLayer();
Chris@305 39 virtual ~ImageLayer();
Chris@303 40
Chris@916 41 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@303 42
Chris@918 43 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
Chris@303 44
Chris@918 45 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@805 46 int &resolution,
Chris@303 47 SnapType snap) const;
Chris@303 48
Chris@918 49 virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 50 virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 51 virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *);
Chris@303 52
Chris@918 53 virtual void editStart(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 54 virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *);
Chris@918 55 virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *);
Chris@303 56
Chris@905 57 virtual void moveSelection(Selection s, sv_frame_t newStartFrame);
Chris@303 58 virtual void resizeSelection(Selection s, Selection newSize);
Chris@303 59 virtual void deleteSelection(Selection s);
Chris@303 60
Chris@918 61 virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to);
Chris@918 62 virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
Chris@303 63 bool interactive);
Chris@303 64
Chris@918 65 virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *); // on double-click
Chris@303 66
Chris@303 67 virtual const Model *getModel() const { return m_model; }
Chris@303 68 void setModel(ImageModel *model);
Chris@303 69
Chris@303 70 virtual PropertyList getProperties() const;
Chris@303 71 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@303 72 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@303 73 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@303 74 int *min, int *max, int *deflt) const;
Chris@303 75 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@303 76 int value) const;
Chris@303 77 virtual void setProperty(const PropertyName &, int value);
Chris@303 78
Chris@303 79 virtual ColourSignificance getLayerColourSignificance() const {
Chris@303 80 return ColourAbsent;
Chris@303 81 }
Chris@303 82
Chris@918 83 virtual bool isLayerScrollable(const LayerGeometryProvider *v) const;
Chris@303 84
Chris@303 85 virtual bool isLayerEditable() const { return true; }
Chris@303 86
Chris@918 87 virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); }
Chris@303 88
Chris@905 89 virtual bool getValueExtents(double &min, double &max,
Chris@303 90 bool &logarithmic, QString &unit) const;
Chris@303 91
Chris@316 92 virtual void toXml(QTextStream &stream, QString indent = "",
Chris@316 93 QString extraAttributes = "") const;
Chris@303 94
Chris@918 95 virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const { return 0; }
Chris@607 96
Chris@918 97 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
Chris@303 98
Chris@303 99 void setProperties(const QXmlAttributes &attributes);
Chris@303 100
Chris@905 101 virtual bool addImage(sv_frame_t frame, QString url); // using a command
Chris@312 102
Chris@305 103 protected slots:
Chris@464 104 void checkAddSources();
Chris@464 105 void fileSourceReady();
Chris@305 106
Chris@303 107 protected:
Chris@918 108 ImageModel::PointList getLocalPoints(LayerGeometryProvider *v, int x, int y) const;
Chris@303 109
Chris@304 110 bool getImageOriginalSize(QString name, QSize &size) const;
Chris@918 111 QImage getImage(LayerGeometryProvider *v, QString name, QSize maxSize) const;
Chris@303 112
Chris@918 113 void drawImage(LayerGeometryProvider *v, QPainter &paint, const ImageModel::Point &p,
Chris@304 114 int x, int nx) const;
Chris@304 115
Chris@303 116 //!!! how to reap no-longer-used images?
Chris@303 117
Chris@303 118 typedef std::map<QString, QImage> ImageMap;
Chris@918 119 typedef std::map<const LayerGeometryProvider *, ImageMap> ViewImageMap;
Chris@318 120 typedef std::map<QString, FileSource *> FileSourceMap;
Chris@304 121
Chris@303 122 static ImageMap m_images;
Chris@305 123 static QMutex m_imageMapMutex;
Chris@303 124 mutable ViewImageMap m_scaled;
Chris@464 125 mutable FileSourceMap m_fileSources;
Chris@305 126
Chris@305 127 QString getLocalFilename(QString img) const;
Chris@464 128 void checkAddSource(QString img) const;
Chris@303 129
Chris@303 130 ImageModel *m_model;
Chris@303 131 bool m_editing;
Chris@303 132 QPoint m_editOrigin;
Chris@303 133 ImageModel::Point m_originalPoint;
Chris@303 134 ImageModel::Point m_editingPoint;
Chris@303 135 ImageModel::EditCommand *m_editingCommand;
Chris@376 136
Chris@376 137 void finish(ImageModel::EditCommand *command) {
Chris@376 138 Command *c = command->finish();
Chris@376 139 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@376 140 }
Chris@303 141 };
Chris@303 142
Chris@303 143 #endif
Chris@303 144