annotate layer/ImageLayer.h @ 1619:36634b427d61

Fix wrongly-written test which made the mapping alignments line up wrongly in some cases where adjacent panes were related (but, because of this test, the alignment view thought they were not)
author Chris Cannam
date Tue, 18 Aug 2020 14:49:36 +0100
parents 6616e1899daa
children
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@1407 16 #ifndef SV_IMAGE_LAYER_H
Chris@1407 17 #define SV_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@1406 41 void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
Chris@303 42
Chris@1406 43 QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
Chris@303 44
Chris@1406 45 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1469 46 int &resolution,
Chris@1547 47 SnapType snap, int ycoord) const override;
Chris@303 48
Chris@1406 49 void drawStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 50 void drawDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 51 void drawEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@303 52
Chris@1406 53 void editStart(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 54 void editDrag(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@1406 55 void editEnd(LayerGeometryProvider *v, QMouseEvent *) override;
Chris@303 56
Chris@1406 57 void moveSelection(Selection s, sv_frame_t newStartFrame) override;
Chris@1406 58 void resizeSelection(Selection s, Selection newSize) override;
Chris@1406 59 void deleteSelection(Selection s) override;
Chris@303 60
Chris@1406 61 void copy(LayerGeometryProvider *v, Selection s, Clipboard &to) override;
Chris@1406 62 bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset,
Chris@1406 63 bool interactive) override;
Chris@303 64
Chris@1406 65 bool editOpen(LayerGeometryProvider *, QMouseEvent *) override; // on double-click
Chris@303 66
Chris@1469 67 ModelId getModel() const override { return m_model; }
Chris@1469 68 void setModel(ModelId model); // an ImageModel please
Chris@303 69
Chris@1406 70 PropertyList getProperties() const override;
Chris@1406 71 QString getPropertyLabel(const PropertyName &) const override;
Chris@1406 72 PropertyType getPropertyType(const PropertyName &) const override;
Chris@1406 73 int getPropertyRangeAndValue(const PropertyName &,
Chris@1469 74 int *min, int *max, int *deflt) const override;
Chris@1406 75 QString getPropertyValueLabel(const PropertyName &,
Chris@1469 76 int value) const override;
Chris@1406 77 void setProperty(const PropertyName &, int value) override;
Chris@303 78
Chris@1406 79 ColourSignificance getLayerColourSignificance() const override {
Chris@303 80 return ColourAbsent;
Chris@303 81 }
Chris@303 82
Chris@1406 83 bool isLayerScrollable(const LayerGeometryProvider *v) const override;
Chris@303 84
Chris@1406 85 bool isLayerEditable() const override { return true; }
Chris@303 86
Chris@1469 87 int getCompletion(LayerGeometryProvider *) const override;
Chris@303 88
Chris@1406 89 bool getValueExtents(double &min, double &max,
Chris@1469 90 bool &logarithmic, QString &unit) const override;
Chris@303 91
Chris@1406 92 void toXml(QTextStream &stream, QString indent = "",
Chris@1469 93 QString extraAttributes = "") const override;
Chris@303 94
Chris@1406 95 int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const override { return 0; }
Chris@607 96
Chris@1406 97 void setLayerDormant(const LayerGeometryProvider *v, bool dormant) override;
Chris@303 98
Chris@1406 99 void setProperties(const QXmlAttributes &attributes) override;
Chris@303 100
Chris@1608 101 static bool isImageFileSupported(QString url); // based on extension alone
Chris@1608 102
Chris@905 103 virtual bool addImage(sv_frame_t frame, QString url); // using a command
Chris@312 104
Chris@305 105 protected slots:
Chris@464 106 void checkAddSources();
Chris@464 107 void fileSourceReady();
Chris@305 108
Chris@303 109 protected:
Chris@1438 110 EventVector getLocalPoints(LayerGeometryProvider *v, int x, int y) const;
Chris@303 111
Chris@304 112 bool getImageOriginalSize(QString name, QSize &size) const;
Chris@918 113 QImage getImage(LayerGeometryProvider *v, QString name, QSize maxSize) const;
Chris@303 114
Chris@1438 115 void drawImage(LayerGeometryProvider *v, QPainter &paint, const Event &p,
Chris@304 116 int x, int nx) const;
Chris@304 117
Chris@303 118 //!!! how to reap no-longer-used images?
Chris@303 119
Chris@303 120 typedef std::map<QString, QImage> ImageMap;
Chris@918 121 typedef std::map<const LayerGeometryProvider *, ImageMap> ViewImageMap;
Chris@318 122 typedef std::map<QString, FileSource *> FileSourceMap;
Chris@304 123
Chris@303 124 static ImageMap m_images;
Chris@1608 125 static FileSourceMap m_fileSources;
Chris@1608 126 static QMutex m_staticMutex;
Chris@1608 127
Chris@303 128 mutable ViewImageMap m_scaled;
Chris@305 129
Chris@1608 130 static QString getLocalFilename(QString img);
Chris@1608 131 static void checkAddSource(QString img, bool synchronise);
Chris@1608 132 void checkAddSourceAndConnect(QString img);
Chris@303 133
Chris@1469 134 ModelId m_model; // an ImageModel
Chris@303 135 bool m_editing;
Chris@303 136 QPoint m_editOrigin;
Chris@1438 137 Event m_originalPoint;
Chris@1438 138 Event m_editingPoint;
Chris@1470 139 ChangeEventsCommand *m_editingCommand;
Chris@376 140
Chris@1470 141 void finish(ChangeEventsCommand *command) {
Chris@376 142 Command *c = command->finish();
Chris@376 143 if (c) CommandHistory::getInstance()->addCommand(c, false);
Chris@376 144 }
Chris@303 145 };
Chris@303 146
Chris@303 147 #endif
Chris@303 148