svgui  1.9
ImageLayer.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006-2007 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _IMAGE_LAYER_H_
17 #define _IMAGE_LAYER_H_
18 
19 #include "Layer.h"
20 #include "data/model/ImageModel.h"
21 
22 #include <QObject>
23 #include <QColor>
24 #include <QImage>
25 #include <QMutex>
26 
27 #include <map>
28 
29 class View;
30 class QPainter;
31 class FileSource;
32 
33 class ImageLayer : public Layer
34 {
35  Q_OBJECT
36 
37 public:
38  ImageLayer();
39  virtual ~ImageLayer();
40 
41  virtual void paint(View *v, QPainter &paint, QRect rect) const;
42 
43  virtual QString getFeatureDescription(View *v, QPoint &) const;
44 
45  virtual bool snapToFeatureFrame(View *v, int &frame,
46  int &resolution,
47  SnapType snap) const;
48 
49  virtual void drawStart(View *v, QMouseEvent *);
50  virtual void drawDrag(View *v, QMouseEvent *);
51  virtual void drawEnd(View *v, QMouseEvent *);
52 
53  virtual void editStart(View *v, QMouseEvent *);
54  virtual void editDrag(View *v, QMouseEvent *);
55  virtual void editEnd(View *v, QMouseEvent *);
56 
57  virtual void moveSelection(Selection s, int newStartFrame);
58  virtual void resizeSelection(Selection s, Selection newSize);
59  virtual void deleteSelection(Selection s);
60 
61  virtual void copy(View *v, Selection s, Clipboard &to);
62  virtual bool paste(View *v, const Clipboard &from, int frameOffset,
63  bool interactive);
64 
65  virtual bool editOpen(View *, QMouseEvent *); // on double-click
66 
67  virtual const Model *getModel() const { return m_model; }
68  void setModel(ImageModel *model);
69 
70  virtual PropertyList getProperties() const;
71  virtual QString getPropertyLabel(const PropertyName &) const;
72  virtual PropertyType getPropertyType(const PropertyName &) const;
73  virtual int getPropertyRangeAndValue(const PropertyName &,
74  int *min, int *max, int *deflt) const;
75  virtual QString getPropertyValueLabel(const PropertyName &,
76  int value) const;
77  virtual void setProperty(const PropertyName &, int value);
78 
80  return ColourAbsent;
81  }
82 
83  virtual bool isLayerScrollable(const View *v) const;
84 
85  virtual bool isLayerEditable() const { return true; }
86 
87  virtual int getCompletion(View *) const { return m_model->getCompletion(); }
88 
89  virtual bool getValueExtents(float &min, float &max,
90  bool &logarithmic, QString &unit) const;
91 
92  virtual void toXml(QTextStream &stream, QString indent = "",
93  QString extraAttributes = "") const;
94 
95  virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; }
96 
97  virtual void setLayerDormant(const View *v, bool dormant);
98 
99  void setProperties(const QXmlAttributes &attributes);
100 
101  virtual bool addImage(int frame, QString url); // using a command
102 
103 protected slots:
104  void checkAddSources();
105  void fileSourceReady();
106 
107 protected:
108  ImageModel::PointList getLocalPoints(View *v, int x, int y) const;
109 
110  bool getImageOriginalSize(QString name, QSize &size) const;
111  QImage getImage(View *v, QString name, QSize maxSize) const;
112 
113  void drawImage(View *v, QPainter &paint, const ImageModel::Point &p,
114  int x, int nx) const;
115 
117 
118  typedef std::map<QString, QImage> ImageMap;
119  typedef std::map<const View *, ImageMap> ViewImageMap;
120  typedef std::map<QString, FileSource *> FileSourceMap;
121 
123  static QMutex m_imageMapMutex;
126 
127  QString getLocalFilename(QString img) const;
128  void checkAddSource(QString img) const;
129 
130  ImageModel *m_model;
131  bool m_editing;
132  QPoint m_editOrigin;
133  ImageModel::Point m_originalPoint;
134  ImageModel::Point m_editingPoint;
135  ImageModel::EditCommand *m_editingCommand;
136 
137  void finish(ImageModel::EditCommand *command) {
138  Command *c = command->finish();
139  if (c) CommandHistory::getInstance()->addCommand(c, false);
140  }
141 };
142 
143 #endif
144 
virtual void editDrag(View *v, QMouseEvent *)
Definition: ImageLayer.cpp:663
virtual void setLayerDormant(const View *v, bool dormant)
Indicate that a layer is not currently visible in the given view and is not expected to become visibl...
Definition: ImageLayer.cpp:483
The base class for visual representations of the data found in a Model.
Definition: Layer.h:52
void checkAddSources()
Definition: ImageLayer.cpp:923
QImage getImage(View *v, QString name, QSize maxSize) const
Definition: ImageLayer.cpp:520
void drawImage(View *v, QPainter &paint, const ImageModel::Point &p, int x, int nx) const
Definition: ImageLayer.cpp:341
virtual bool getValueExtents(float &min, float &max, bool &logarithmic, QString &unit) const
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
Definition: ImageLayer.cpp:113
std::map< const View *, ImageMap > ViewImageMap
Definition: ImageLayer.h:119
virtual void drawDrag(View *v, QMouseEvent *)
Definition: ImageLayer.cpp:581
virtual void deleteSelection(Selection s)
Definition: ImageLayer.cpp:785
virtual void resizeSelection(Selection s, Selection newSize)
Definition: ImageLayer.cpp:751
FileSourceMap m_fileSources
Definition: ImageLayer.h:125
virtual void setProperty(const PropertyName &, int value)
Definition: ImageLayer.cpp:107
virtual void copy(View *v, Selection s, Clipboard &to)
Definition: ImageLayer.cpp:804
void addCommand(Command *command)
Add a command to the command history.
virtual void paint(View *v, QPainter &paint, QRect rect) const
Paint the given rectangle of this layer onto the given view using the given painter,...
Definition: ImageLayer.cpp:283
bool m_editing
Definition: ImageLayer.h:131
ColourSignificance
Definition: Layer.h:304
ImageModel::Point m_editingPoint
Definition: ImageLayer.h:134
virtual void editEnd(View *v, QMouseEvent *)
Definition: ImageLayer.cpp:683
std::map< QString, QImage > ImageMap
!! how to reap no-longer-used images?
Definition: ImageLayer.h:118
QPoint m_editOrigin
Definition: ImageLayer.h:132
std::map< QString, FileSource * > FileSourceMap
Definition: ImageLayer.h:120
virtual void drawEnd(View *v, QMouseEvent *)
Definition: ImageLayer.cpp:597
virtual QString getPropertyLabel(const PropertyName &) const
Definition: ImageLayer.cpp:81
virtual bool snapToFeatureFrame(View *v, int &frame, int &resolution, SnapType snap) const
!! too much overlap with TimeValueLayer/TimeInstantLayer/TextLayer
Definition: ImageLayer.cpp:211
bool getImageOriginalSize(QString name, QSize &size) const
!! how to reap no-longer-used images?
Definition: ImageLayer.cpp:501
virtual int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const
Definition: ImageLayer.cpp:93
virtual void drawStart(View *v, QMouseEvent *)
Definition: ImageLayer.cpp:557
ImageModel::Point m_originalPoint
Definition: ImageLayer.h:133
virtual bool addImage(int frame, QString url)
Definition: ImageLayer.cpp:622
ImageModel::EditCommand * m_editingCommand
Definition: ImageLayer.h:135
void checkAddSource(QString img) const
Definition: ImageLayer.cpp:903
void fileSourceReady()
Definition: ImageLayer.cpp:935
virtual bool paste(View *v, const Clipboard &from, int frameOffset, bool interactive)
Paste from the given clipboard onto the layer at the given frame offset.
Definition: ImageLayer.cpp:822
virtual ~ImageLayer()
Definition: ImageLayer.cpp:55
SnapType
Definition: Layer.h:157
static CommandHistory * getInstance()
virtual bool isLayerEditable() const
This should return true if the layer can be edited by the user.
Definition: ImageLayer.h:85
virtual int getCompletion(View *) const
Return the proportion of background work complete in drawing this view, as a percentage – in most cas...
Definition: ImageLayer.h:87
QString getLocalFilename(QString img) const
Definition: ImageLayer.cpp:891
virtual const Model * getModel() const
Definition: ImageLayer.h:67
void setProperties(const QXmlAttributes &attributes)
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
Definition: ImageLayer.cpp:969
virtual QString getFeatureDescription(View *v, QPoint &) const
Definition: ImageLayer.cpp:172
void setModel(ImageModel *model)
Definition: ImageLayer.cpp:64
virtual int getVerticalScaleWidth(View *, bool, QPainter &) const
Definition: ImageLayer.h:95
virtual PropertyList getProperties() const
Definition: ImageLayer.cpp:75
static ImageMap m_images
Definition: ImageLayer.h:122
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
void finish(ImageModel::EditCommand *command)
Definition: ImageLayer.h:137
virtual bool editOpen(View *, QMouseEvent *)
Open an editor on the item under the mouse (e.g.
Definition: ImageLayer.cpp:697
virtual void moveSelection(Selection s, int newStartFrame)
Definition: ImageLayer.cpp:726
virtual void editStart(View *v, QMouseEvent *)
Definition: ImageLayer.cpp:641
static QMutex m_imageMapMutex
Definition: ImageLayer.h:123
virtual bool isLayerScrollable(const View *v) const
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
Definition: ImageLayer.cpp:119
virtual QString getPropertyValueLabel(const PropertyName &, int value) const
Definition: ImageLayer.cpp:100
ImageModel::PointList getLocalPoints(View *v, int x, int y) const
Definition: ImageLayer.cpp:126
ImageModel * m_model
Definition: ImageLayer.h:130
ViewImageMap m_scaled
Definition: ImageLayer.h:124
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Convert the layer's data (though not those of the model it refers to) into XML for file output.
Definition: ImageLayer.cpp:962
virtual PropertyType getPropertyType(const PropertyName &) const
Definition: ImageLayer.cpp:87
virtual ColourSignificance getLayerColourSignificance() const
This should return the degree of meaning associated with colour in this layer.
Definition: ImageLayer.h:79