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             };
33       ImageType imageType;
34 
35       QSizeF pixel2size(const QSizeF& s) const;
36       QSizeF size2pixel(const QSizeF& s) const;
37 
38    protected:
39       ImageStoreItem* _storeItem;
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;       ///< cached rendering
44       QSizeF _size;                 // in mm or spatium units
45       bool _lockAspectRatio;
46       bool _autoScale;              ///< fill parent frame
47       bool _sizeIsSpatium;
48       mutable bool _dirty;
49 
isEditable()50       bool isEditable() const override { return true; }
51       void startEditDrag(EditData&) override;
52       void editDrag(EditData& ed) override;
gripAnchorLines(Grip)53       QVector<QLineF> gripAnchorLines(Grip) const override { return QVector<QLineF>(); }
54 
55    public:
56       Image(Score* = 0);
57       Image(const Image&);
58       ~Image();
59 
clone()60       Image* clone() const override     { return new Image(*this); }
type()61       ElementType type() const override { return ElementType::IMAGE; }
62       void write(XmlWriter& xml) const override;
63       void read(XmlReader&) override;
64       bool load(const QString& s);
65       bool loadFromData(const QString&, const QByteArray&);
66       void layout() override;
67       void draw(QPainter*) const override;
68 
setSize(const QSizeF & s)69       void setSize(const QSizeF& s)      { _size = s;    }
size()70       QSizeF size() const                { return _size; }
lockAspectRatio()71       bool lockAspectRatio() const       { return _lockAspectRatio; }
setLockAspectRatio(bool v)72       void setLockAspectRatio(bool v)    { _lockAspectRatio = v;  }
autoScale()73       bool autoScale() const             { return _autoScale;     }
setAutoScale(bool v)74       void setAutoScale(bool v)          { _autoScale = v;        }
storeItem()75       ImageStoreItem* storeItem() const  { return _storeItem;     }
sizeIsSpatium()76       bool sizeIsSpatium() const         { return _sizeIsSpatium; }
setSizeIsSpatium(bool val)77       void setSizeIsSpatium(bool val)    { _sizeIsSpatium = val;  }
78 
79       QVariant getProperty(Pid ) const override;
80       bool setProperty(Pid propertyId, const QVariant&) override;
81       QVariant propertyDefault(Pid id) const override;
82 
83       QSizeF imageSize() const;
84 
85       void setImageType(ImageType);
getImageType()86       ImageType getImageType() const { return imageType; }
isValid()87       bool isValid() const           { return rasterDoc || svgDoc; }
88 
normalModeEditBehavior()89       Element::EditBehavior normalModeEditBehavior() const override { return Element::EditBehavior::Edit; }
gripsCount()90       int gripsCount() const override { return 2; }
initialEditModeGrip()91       Grip initialEditModeGrip() const override { return Grip(1); }
defaultGrip()92       Grip defaultGrip() const override { return Grip(1); }
93       std::vector<QPointF> gripsPositions(const EditData&) const override;
94       };
95 
96 
97 }     // namespace Ms
98 #endif
99 
100