Krita Source Code Documentation
Loading...
Searching...
No Matches
ImageShape Class Reference

#include <ImageShape.h>

+ Inheritance diagram for ImageShape:

Public Member Functions

KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
QImage image () const
 
 ImageShape ()
 
bool loadSvg (const QDomElement &element, SvgLoadingContext &context) override
 Loads data from specified svg element.
 
void paint (QPainter &painter) const override
 Paint the shape fill The class extending this one is responsible for painting itself. painter is expected to be preconfigured to work in "document" pixels.
 
 Private ()
 
 Private (const Private &rhs)
 
bool saveSvg (SvgSavingContext &context) override
 Saves data utilizing specified svg saving context.
 
void setImage (const QImage &img)
 
void setSize (const QSizeF &size) override
 Resize the shape.
 
void setViewBoxTransform (const QTransform &tf)
 
QTransform viewBoxTransform () const
 
 ~ImageShape () override
 
- Public Member Functions inherited from KoShape
QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchoranchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackgroundbackground () const
 
virtual QRectF boundingRect () const
 Get the bounding box of the shape.
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMaskclipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPathclipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
KoShapecloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
virtual bool hitTest (const QPointF &position) const
 Check if the shape is hit on position.
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual QPainterPath outline () const
 
virtual QRectF outlineRect () const
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrderpaintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainerparent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
void setSelectable (bool selectable)
 
void setShapeId (const QString &id)
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual QSizeF size () const
 Get the size of the shape in pt.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void update () const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 
- Public Member Functions inherited from SvgShape
void saveMetadata (SvgSavingContext &context)
 
virtual ~SvgShape ()
 

Public Attributes

QImage image
 
QScopedPointer< SvgUtil::PreserveAspectRatioParserratioParser
 
QTransform viewBoxTransform
 

Private Member Functions

 ImageShape (const ImageShape &rhs)
 

Private Attributes

QSharedDataPointer< Privatem_d
 

Additional Inherited Members

- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , BorderChanged ,
  ParameterChanged , ContentChanged , TextContourMarginChanged , ChildChanged ,
  ConnectionPointChanged , ClipPathChanged , ClipMaskChanged , TransparencyChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
- Static Public Member Functions inherited from KoShape
static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrderdefaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 
- Static Public Attributes inherited from KoShape
static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
virtual void shapeChanged (ChangeType type, KoShape *shape=0)
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Detailed Description

Definition at line 23 of file ImageShape.cpp.

Constructor & Destructor Documentation

◆ ImageShape() [1/2]

ImageShape::ImageShape ( )

Definition at line 40 of file ImageShape.cpp.

41 : m_d(new Private)
42{
43}
QSharedDataPointer< Private > m_d
Definition ImageShape.h:44

◆ ~ImageShape()

ImageShape::~ImageShape ( )
override

Definition at line 51 of file ImageShape.cpp.

52{
53}

◆ ImageShape() [2/2]

ImageShape::ImageShape ( const ImageShape & rhs)
private

Definition at line 45 of file ImageShape.cpp.

46 : KoShape(rhs),
47 m_d(rhs.m_d)
48{
49}
KoShape()
Constructor.
Definition KoShape.cpp:135

Member Function Documentation

◆ cloneShape()

KoShape * ImageShape::cloneShape ( ) const
overridevirtual

creates a deep copy of the shape or shape's subtree

Returns
a cloned shape

Reimplemented from KoShape.

Definition at line 55 of file ImageShape.cpp.

56{
57 return new ImageShape(*this);
58}

References ImageShape().

◆ image()

QImage ImageShape::image ( ) const

◆ loadSvg()

bool ImageShape::loadSvg ( const QDomElement & element,
SvgLoadingContext & context )
overridevirtual

Loads data from specified svg element.

Reimplemented from SvgShape.

Definition at line 105 of file ImageShape.cpp.

106{
107 const qreal x = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute("x"));
108 const qreal y = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute("y"));
109 const qreal w = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute("width"));
110 const qreal h = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute("height"));
111
112 setSize(QSizeF(w, h));
113 setPosition(QPointF(x, y));
114
115 if (w == 0.0 || h == 0.0) {
116 setVisible(false);
117 }
118
119 QString fileName = element.attribute("xlink:href");
120
121 QByteArray data;
122
123 if (fileName.startsWith("data:")) {
124
125 QRegularExpression re("data:(.+?);base64,(.+)");
126 QRegularExpressionMatch match = re.match(fileName);
127
128 data = match.captured(2).toLatin1();
129 data = QByteArray::fromBase64(data);
130 } else {
131 data = context.fetchExternalFile(fileName);
132 }
133
134 if (!data.isEmpty()) {
135 QBuffer buffer(&data);
136 m_d->image.load(&buffer, "");
137 }
138
139 const QString aspectString = element.attribute("preserveAspectRatio", "xMidYMid meet");
140 m_d->ratioParser.reset(new SvgUtil::PreserveAspectRatioParser(aspectString));
141
142 if (!m_d->image.isNull()) {
143
144 m_d->viewBoxTransform =
145 QTransform::fromScale(w / m_d->image.width(), h / m_d->image.height());
146
147 SvgUtil::parseAspectRatio(*m_d->ratioParser,
148 QRectF(QPointF(), size()),
149 QRect(QPoint(), m_d->image.size()),
150 &m_d->viewBoxTransform);
151 }
152
153 if (m_d->ratioParser->defer) {
154 // TODO:
155 }
156
157 return true;
158}
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:740
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
Definition KoShape.cpp:267
void setVisible(bool on)
Definition KoShape.cpp:795
QByteArray fetchExternalFile(const QString &url)
SvgGraphicsContext * currentGC() const
Returns the current graphics context.
KoSvgTextProperties resolvedProperties() const
These are the text properties, completely resolved, ensuring that everything is inherited and the siz...
static qreal parseUnitX(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in x-direction
Definition SvgUtil.cpp:304
static void parseAspectRatio(const PreserveAspectRatioParser &p, const QRectF &elementBounds, const QRectF &viewRect, QTransform *_viewTransform)
Definition SvgUtil.cpp:190
static qreal parseUnitY(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in y-direction
Definition SvgUtil.cpp:313
void setSize(const QSizeF &size) override
Resize the shape.

References SvgLoadingContext::currentGC(), SvgLoadingContext::fetchExternalFile(), m_d, SvgUtil::parseAspectRatio(), SvgUtil::parseUnitX(), SvgUtil::parseUnitY(), SvgLoadingContext::resolvedProperties(), KoShape::setPosition(), setSize(), KoShape::setVisible(), and KoShape::size().

◆ paint()

void ImageShape::paint ( QPainter & painter) const
overridevirtual

Paint the shape fill The class extending this one is responsible for painting itself. painter is expected to be preconfigured to work in "document" pixels.

Parameters
painterused for painting the shape

Implements KoShape.

Definition at line 60 of file ImageShape.cpp.

61{
62 KisQPainterStateSaver saver(&painter);
63
64 const QRectF myrect(QPointF(), size());
65
66 painter.setRenderHint(QPainter::SmoothPixmapTransform);
67 painter.setClipRect(QRectF(QPointF(), size()), Qt::IntersectClip);
68 painter.setTransform(m_d->viewBoxTransform, true);
69 painter.drawImage(QPoint(), m_d->image);
70}

References m_d, and KoShape::size().

◆ Private() [1/2]

ImageShape::Private ( )
inline

Definition at line 25 of file ImageShape.cpp.

25{}

◆ Private() [2/2]

ImageShape::Private ( const Private & rhs)
inline

Definition at line 26 of file ImageShape.cpp.

27 : QSharedData(),
28 image(rhs.image),
29 ratioParser(rhs.ratioParser ? new SvgUtil::PreserveAspectRatioParser(*rhs.ratioParser) : 0),
31 {
32 }
QTransform viewBoxTransform
QImage image
QScopedPointer< SvgUtil::PreserveAspectRatioParser > ratioParser

◆ saveSvg()

bool ImageShape::saveSvg ( SvgSavingContext & context)
overridevirtual

Saves data utilizing specified svg saving context.

Reimplemented from SvgShape.

Definition at line 77 of file ImageShape.cpp.

78{
79 const QString uid = context.createUID("image");
80
81 context.shapeWriter().startElement("image");
82 context.shapeWriter().addAttribute("id", uid);
84 context.shapeWriter().addAttribute("width", QString("%1px").arg(KisDomUtils::toString(size().width())));
85 context.shapeWriter().addAttribute("height", QString("%1px").arg(KisDomUtils::toString(size().height())));
86
87 QString aspectString = m_d->ratioParser? m_d->ratioParser->toString(): QString();
88 if (!aspectString.isEmpty()) {
89 context.shapeWriter().addAttribute("preserveAspectRatio", aspectString);
90 }
91
92 QBuffer buffer;
93 buffer.open(QIODevice::WriteOnly);
94 if (m_d->image.save(&buffer, "PNG")) {
95 const QString mimeType = KisMimeDatabase::mimeTypeForSuffix("*.png");
96 context.shapeWriter().addAttribute("xlink:href", "data:"+ mimeType + ";base64," + buffer.data().toBase64());
97 }
98 SvgStyleWriter::saveMetadata(this, context);
99
100 context.shapeWriter().endElement(); // image
101
102 return true;
103}
static QString mimeTypeForSuffix(const QString &suffix)
Find the mimetype for a given extension. The extension may have the form "*.xxx" or "xxx".
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:383
QString createUID(const QString &base)
Create a unique id from the specified base text.
QScopedPointer< KoXmlWriter > shapeWriter
static void saveMetadata(const KoShape *shape, SvgSavingContext &context)
static void writeTransformAttributeLazy(const QString &name, const QTransform &transform, KoXmlWriter &shapeWriter)
Writes a transform as an attribute name iff the transform is not empty.
Definition SvgUtil.cpp:124
QString toString(const QString &value)

References SvgSavingContext::createUID(), m_d, KisMimeDatabase::mimeTypeForSuffix(), SvgStyleWriter::saveMetadata(), SvgSavingContext::shapeWriter, KoShape::size(), KisDomUtils::toString(), KoShape::transformation(), and SvgUtil::writeTransformAttributeLazy().

◆ setImage()

void ImageShape::setImage ( const QImage & img)

Definition at line 160 of file ImageShape.cpp.

161{
162 if (m_d->image != img) {
163 m_d->image = img;
165 }
166}
virtual void shapeChanged(ChangeType type, KoShape *shape=0)
Definition KoShape.cpp:1059
@ ContentChanged
the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape
Definition KoShape.h:106

References KoShape::ContentChanged, m_d, and KoShape::shapeChanged().

◆ setSize()

void ImageShape::setSize ( const QSizeF & size)
overridevirtual

Resize the shape.

Parameters
sizethe new size of the shape. This is different from scaling as scaling is a so called secondary operation which is comparable to zooming in instead of changing the size of the basic shape. Easiest example of this difference is that using this method will not distort the size of pattern-fills and strokes.

Reimplemented from KoShape.

Definition at line 72 of file ImageShape.cpp.

73{
75}
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:248

References KoShape::setSize(), and KoShape::size().

◆ setViewBoxTransform()

void ImageShape::setViewBoxTransform ( const QTransform & tf)

Definition at line 173 of file ImageShape.cpp.

174{
175 if (m_d->viewBoxTransform != tf) {
176 m_d->viewBoxTransform = tf;
178 }
179}
@ GenericMatrixChange
used after the matrix was changed without knowing which property explicitly changed
Definition KoShape.h:98

References KoShape::GenericMatrixChange, m_d, and KoShape::shapeChanged().

◆ viewBoxTransform()

QTransform ImageShape::viewBoxTransform ( ) const

Member Data Documentation

◆ image

QImage ImageShape::image

Definition at line 34 of file ImageShape.cpp.

◆ m_d

QSharedDataPointer<Private> ImageShape::m_d
private

Definition at line 44 of file ImageShape.h.

◆ ratioParser

QScopedPointer<SvgUtil::PreserveAspectRatioParser> ImageShape::ratioParser

Definition at line 35 of file ImageShape.cpp.

◆ viewBoxTransform

QTransform ImageShape::viewBoxTransform

Definition at line 36 of file ImageShape.cpp.


The documentation for this class was generated from the following files: