MuseScore  3.4
Music composition and notation
image.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2002-2012 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __IMAGE_H__
14 #define __IMAGE_H__
15 
16 #include "bsymbol.h"
17 
18 namespace Ms {
19 
20 class ImageStoreItem;
21 
22 enum class ImageType : char { NONE, RASTER, SVG };
23 
24 //---------------------------------------------------------
25 // @@ Image
26 //---------------------------------------------------------
27 
28 class Image final : public BSymbol {
29  union {
30  QImage* rasterDoc;
31  QSvgRenderer* svgDoc;
32  };
34 
35  QSizeF pixel2size(const QSizeF& s) const;
36  QSizeF size2pixel(const QSizeF& s) const;
37 
38  protected:
40  QString _storePath; // the path of the img in the ImageStore
41  QString _linkPath; // the path of an external linked img
42  bool _linkIsValid; // whether _linkPath file exists or not
43  mutable QPixmap buffer;
44  QSizeF _size; // in mm or spatium units
46  bool _autoScale;
48  mutable bool _dirty;
49 
50  virtual bool isEditable() const override { return true; }
51  virtual void startEditDrag(EditData&) override;
52  virtual void editDrag(EditData& ed) override;
53  virtual QPointF gripAnchor(Grip) const override { return QPointF(); }
54 
55  public:
56  Image(Score* = 0);
57  Image(const Image&);
58  ~Image();
59  virtual Image* clone() const override { return new Image(*this); }
60  virtual ElementType type() const override { return ElementType::IMAGE; }
61  virtual void write(XmlWriter& xml) const override;
62  virtual void read(XmlReader&) override;
63  bool load(const QString& s);
64  bool loadFromData(const QString&, const QByteArray&);
65  virtual void layout() override;
66  virtual void draw(QPainter*) const override;
67 
68  void setSize(const QSizeF& s) { _size = s; }
69  QSizeF size() const { return _size; }
70  bool lockAspectRatio() const { return _lockAspectRatio; }
71  void setLockAspectRatio(bool v) { _lockAspectRatio = v; }
72  bool autoScale() const { return _autoScale; }
73  void setAutoScale(bool v) { _autoScale = v; }
74  ImageStoreItem* storeItem() const { return _storeItem; }
75  bool sizeIsSpatium() const { return _sizeIsSpatium; }
76  void setSizeIsSpatium(bool val) { _sizeIsSpatium = val; }
77 
78  QVariant getProperty(Pid ) const;
79  bool setProperty(Pid propertyId, const QVariant&);
80  QVariant propertyDefault(Pid id) const;
81 
82  QSizeF imageSize() const;
83 
84  void setImageType(ImageType);
85  ImageType getImageType() const { return imageType; }
86  bool isValid() const { return rasterDoc || svgDoc; }
87 
89  int gripsCount() const override { return 2; }
90  Grip initialEditModeGrip() const override { return Grip(1); }
91  Grip defaultGrip() const override { return Grip(1); }
92  std::vector<QPointF> gripsPositions(const EditData&) const override;
93  };
94 
95 
96 } // namespace Ms
97 #endif
98 
Definition: image.h:28
bool _autoScale
fill parent frame
Definition: image.h:46
ImageStoreItem * storeItem() const
Definition: image.h:74
Pid
Definition: property.h:62
Definition: xml.h:67
virtual ElementType type() const override
Definition: image.h:60
virtual QPointF gripAnchor(Grip) const override
Definition: image.h:53
Element::EditBehavior normalModeEditBehavior() const override
Definition: image.h:88
QImage * rasterDoc
Definition: image.h:30
bool _sizeIsSpatium
Definition: image.h:47
ImageType getImageType() const
Definition: image.h:85
QSvgRenderer * svgDoc
Definition: image.h:31
Definition: score.h:391
Grip defaultGrip() const override
Definition: image.h:91
base class for Symbol and Image
Definition: bsymbol.h:25
void setSizeIsSpatium(bool val)
Definition: image.h:76
QString _storePath
Definition: image.h:40
Definition: imageStore.h:25
bool lockAspectRatio() const
Definition: image.h:70
virtual Image * clone() const override
Definition: image.h:59
bool sizeIsSpatium() const
Definition: image.h:75
Grip initialEditModeGrip() const override
Definition: image.h:90
QSizeF _size
Definition: image.h:44
bool autoScale() const
Definition: image.h:72
Grip
Definition: element.h:43
ImageStoreItem * _storeItem
Definition: image.h:39
QSizeF size() const
Definition: image.h:69
Definition: aeolus.cpp:26
Definition: xml.h:218
virtual bool isEditable() const override
Definition: image.h:50
bool isValid() const
Definition: image.h:86
void setSize(const QSizeF &s)
Definition: image.h:68
Definition: element.h:111
QString _linkPath
Definition: image.h:41
void setAutoScale(bool v)
Definition: image.h:73
bool _linkIsValid
Definition: image.h:42
void setLockAspectRatio(bool v)
Definition: image.h:71
ElementType
Definition: types.h:34
int gripsCount() const override
Definition: image.h:89
ImageType imageType
Definition: image.h:33
ImageType
Definition: image.h:22
QPixmap buffer
cached rendering
Definition: image.h:43
bool _dirty
Definition: image.h:48
Pid propertyId(const QStringRef &s)
Definition: property.cpp:347
EditBehavior
Definition: element.h:173
bool _lockAspectRatio
Definition: image.h:45