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

The KisReferenceImage class represents a single reference image. More...

#include <KisReferenceImage.h>

+ Inheritance diagram for KisReferenceImage:

Classes

struct  Private
 
struct  SetSaturationCommand
 

Public Member Functions

KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
bool embed ()
 
QString filename () const
 
QImage getImage ()
 
QColor getPixel (QPointF position)
 
bool hasLocalFile ()
 
QString internalFile () const
 
 KisReferenceImage ()
 
 KisReferenceImage (const KisReferenceImage &rhs)
 
bool loadImage (KoStore *store)
 
void paint (QPainter &gc) 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.
 
qreal saturation () const
 
bool saveImage (KoStore *store) const
 
void saveXml (QDomDocument &document, QDomElement &parentElement, int id)
 
void setEmbed (bool embed)
 
void setFilename (const QString &filename)
 
void setSaturation (qreal saturation)
 
 ~KisReferenceImage ()
 
- Public Member Functions inherited from KoTosContainer
KoShapecreateTextShape (KoDocumentResourceManager *documentResources=0)
 
 KoTosContainer ()
 
virtual bool loadText (const QDomElement &element)
 
void paintComponent (QPainter &painter) const override
 Paint the component Implement this method to allow the shape to paint itself, just like the KoShape::paint() method does.
 
ResizeBehavior resizeBehavior () const
 
void setPlainText (const QString &text)
 
void setResizeBehavior (ResizeBehavior resizeBehavior)
 
void setRunThrough (short int runThrough) override
 
void setTextAlignment (Qt::Alignment alignment)
 
Qt::Alignment textAlignment () const
 
 ~KoTosContainer () override
 
- Public Member Functions inherited from KoShapeContainer
void addShape (KoShape *shape)
 
bool inheritsTransform (const KoShape *shape) const
 
bool isClipped (const KoShape *child) const
 
 KoShapeContainer (KoShapeContainerModel *model=0)
 
KoShapeContainerModelmodel () const
 
void paint (QPainter &painter) const override
 reimplemented
 
 Private (const Private &rhs, KoShapeContainer *q)
 
 Private (KoShapeContainer *q)
 
void removeShape (KoShape *shape)
 
void setClipped (const KoShape *child, bool clipping)
 
void setInheritsTransform (const KoShape *shape, bool inherit)
 
int shapeCount () const
 
ShapeInterfaceshapeInterface ()
 
QList< KoShape * > shapes () const
 
virtual void update () const
 
void update () const override
 reimplemented
 
 ~KoShapeContainer () override
 
virtual ~Private ()
 
- 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.
 
KoFilterEffectStackfilterEffectStack () const
 
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
 
int runThrough () 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 setFilterEffectStack (KoFilterEffectStack *filterEffectStack)
 Sets the new filter effect stack, removing the old one.
 
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 setShadow (KoShapeShadow *shadow)
 Sets the new shadow, removing the old one.
 
void setShapeId (const QString &id)
 
virtual void setSize (const QSizeF &size)
 Resize the shape.
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setTextRunAroundContour (TextRunAroundContour contour)
 
void setTextRunAroundDistanceBottom (qreal distance)
 
void setTextRunAroundDistanceLeft (qreal distance)
 
void setTextRunAroundDistanceRight (qreal distance)
 
void setTextRunAroundDistanceTop (qreal distance)
 
void setTextRunAroundSide (TextRunAroundSide side, RunThroughLevel runThrough=Background)
 
void setTextRunAroundThreshold (qreal threshold)
 
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)
 
KoShapeShadowshadow () const
 Returns the currently set shadow or 0 if there is no shadow set.
 
virtual QPainterPath shadowOutline () const
 
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
 
TextRunAroundContour textRunAroundContour () const
 
qreal textRunAroundDistanceBottom () const
 
qreal textRunAroundDistanceLeft () const
 
qreal textRunAroundDistanceRight () const
 
qreal textRunAroundDistanceTop () const
 
TextRunAroundSide textRunAroundSide () const
 
qreal textRunAroundThreshold () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 

Static Public Member Functions

static KisReferenceImagefromClipboard (const KisCoordinatesConverter &converter)
 
static KisReferenceImagefromFile (const QString &filename, const KisCoordinatesConverter &converter, QWidget *parent)
 
static KisReferenceImagefromPaintDevice (KisPaintDeviceSP src, const KisCoordinatesConverter &converter, QWidget *parent)
 
static KisReferenceImagefromQImage (const KisCoordinatesConverter &converter, const QImage &img)
 
static KisReferenceImagefromXml (const QDomElement &elem)
 
- 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)
 

Private Attributes

QSharedDataPointer< Privated
 

Additional Inherited Members

- Public Types inherited from KoTosContainer
enum  ResizeBehavior { TextFollowsSize , FollowTextSize , IndependentSizes , TextFollowsPreferredTextRect }
 different kinds of resizing behavior to determine how to treat text overflow More...
 
- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , ShadowChanged ,
  BorderChanged , ParameterChanged , ContentChanged , TextRunAroundChanged ,
  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 }
 
enum  RunThroughLevel { Background , Foreground }
 
enum  TextRunAroundContour { ContourBox , ContourFull , ContourOutside }
 The behavior text should do when intersecting this shape. More...
 
enum  TextRunAroundSide {
  BiggestRunAroundSide , LeftRunAroundSide , RightRunAroundSide , EnoughRunAroundSide ,
  BothRunAroundSide , NoRunAround , RunThrough
}
 The behavior text should do when intersecting this shape. More...
 
- Public Attributes inherited from KoShapeContainer
KoShapeContainerModelmodel
 
KoShapeContainer::ShapeInterface shapeInterface
 
- 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 KoTosContainer
 KoTosContainer (const KoTosContainer &rhs)
 
QRectF preferredTextRect () const
 
void setPreferredTextRect (const QRectF &rect)
 
void shapeChanged (ChangeType type, KoShape *shape=0) override
 
KoShapetextShape () const
 
- Protected Member Functions inherited from KoShapeContainer
 KoShapeContainer (const KoShapeContainer &rhs)
 
void setModel (KoShapeContainerModel *model)
 
void setModelInit (KoShapeContainerModel *model)
 
virtual void shapeCountChanged ()
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Detailed Description

The KisReferenceImage class represents a single reference image.

Definition at line 29 of file KisReferenceImage.h.

Constructor & Destructor Documentation

◆ KisReferenceImage() [1/2]

KisReferenceImage::KisReferenceImage ( )

Definition at line 148 of file KisReferenceImage.cpp.

149 : d(new Private())
150{
151 setKeepAspectRatio(true);
152}
QSharedDataPointer< Private > d
void setKeepAspectRatio(bool keepAspect)
Definition KoShape.cpp:1044

References KoShape::setKeepAspectRatio().

◆ KisReferenceImage() [2/2]

KisReferenceImage::KisReferenceImage ( const KisReferenceImage & rhs)

Definition at line 154 of file KisReferenceImage.cpp.

155 : KoTosContainer(rhs)
156 , d(rhs.d)
157{}

◆ ~KisReferenceImage()

KisReferenceImage::~KisReferenceImage ( )

Definition at line 159 of file KisReferenceImage.cpp.

160{}

Member Function Documentation

◆ cloneShape()

KoShape * KisReferenceImage::cloneShape ( ) const
overridevirtual

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

Returns
a cloned shape

Reimplemented from KoShape.

Definition at line 424 of file KisReferenceImage.cpp.

425{
426 return new KisReferenceImage(*this);
427}

References KisReferenceImage().

◆ embed()

bool KisReferenceImage::embed ( )

Definition at line 280 of file KisReferenceImage.cpp.

281{
282 return d->embed;
283}

References d.

◆ filename()

QString KisReferenceImage::filename ( ) const

Definition at line 290 of file KisReferenceImage.cpp.

291{
292 return d->externalFilename;
293}

References d.

◆ fromClipboard()

KisReferenceImage * KisReferenceImage::fromClipboard ( const KisCoordinatesConverter & converter)
static

Definition at line 185 of file KisReferenceImage.cpp.

186{
187 const auto sz = KisClipboard::instance()->clipSize();
188 KisPaintDeviceSP clip = KisClipboard::instance()->clip({0, 0, sz.width(), sz.height()}, true);
189 return fromPaintDevice(clip, converter, nullptr);
190}
static KisClipboard * instance()
QSize clipSize() const
static KisReferenceImage * fromPaintDevice(KisPaintDeviceSP src, const KisCoordinatesConverter &converter, QWidget *parent)

References KisClipboard::clip, KisClipboard::clipSize(), fromPaintDevice(), and KisClipboard::instance().

◆ fromFile()

KisReferenceImage * KisReferenceImage::fromFile ( const QString & filename,
const KisCoordinatesConverter & converter,
QWidget * parent )
static

Load a reference image from specified file. If parent is provided and the image cannot be loaded, a warning message will be displayed to user.

Returns
reference image or null if one could not be loaded

Definition at line 162 of file KisReferenceImage.cpp.

163{
164 KisReferenceImage *reference = new KisReferenceImage();
165 reference->d->externalFilename = filename;
166 bool ok = reference->d->loadFromFile();
167
168 if (ok) {
169 QRect r = QRect(QPoint(), reference->d->image.size());
170 QSizeF shapeSize = converter.imageToDocument(r).size();
171 reference->setSize(shapeSize);
172 } else {
173 delete reference;
174
175 if (parent) {
176 QMessageBox::critical(parent, i18nc("@title:window", "Krita"), i18n("Could not load %1.", filename));
177 }
178
179 return nullptr;
180 }
181
182 return reference;
183}
_Private::Traits< T >::Result imageToDocument(const T &obj) const
The KisReferenceImage class represents a single reference image.
QString filename() const
KoShapeContainer * parent
Definition KoShape_p.h:80
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:276

References d, filename(), KisCoordinatesConverter::imageToDocument(), KisReferenceImage(), KoShape::Private::parent, and KoShape::setSize().

◆ fromPaintDevice()

KisReferenceImage * KisReferenceImage::fromPaintDevice ( KisPaintDeviceSP src,
const KisCoordinatesConverter & converter,
QWidget * parent )
static

Load a reference image from specified paint device.

Returns
reference image or null if one could not be loaded

Definition at line 193 of file KisReferenceImage.cpp.

194{
195 if (!src) {
196 return nullptr;
197 }
198
199 auto *reference = new KisReferenceImage();
200 reference->d->image = src->convertToQImage(KoColorSpaceRegistry::instance()->p709SRGBProfile());
201
202 QRect r = QRect(QPoint(), reference->d->image.size());
203 QSizeF size = converter.imageToDocument(r).size();
204 reference->setSize(size);
205
206 return reference;
207}
virtual QSizeF size() const
Get the size of the shape in pt.
Definition KoShape.cpp:820
static KoColorSpaceRegistry * instance()

References KisCoordinatesConverter::imageToDocument(), KoColorSpaceRegistry::instance(), KisReferenceImage(), and KoShape::size().

◆ fromQImage()

KisReferenceImage * KisReferenceImage::fromQImage ( const KisCoordinatesConverter & converter,
const QImage & img )
static

Definition at line 209 of file KisReferenceImage.cpp.

210{
211 KisReferenceImage *reference = new KisReferenceImage();
212 bool ok = reference->d->loadFromQImage(img);
213
214 if (ok) {
215 QRect r = QRect(QPoint(), reference->d->image.size());
216 QSizeF size = converter.imageToDocument(r).size();
217 reference->setSize(size);
218 } else {
219 delete reference;
220 reference = 0;
221 }
222
223 return reference;
224}

References d, KisCoordinatesConverter::imageToDocument(), KisReferenceImage(), KoShape::setSize(), and KoShape::size().

◆ fromXml()

KisReferenceImage * KisReferenceImage::fromXml ( const QDomElement & elem)
static

Definition at line 348 of file KisReferenceImage.cpp.

349{
350 auto *reference = new KisReferenceImage();
351
352 const QString &src = elem.attribute("src");
353
354 if (src.startsWith("file://")) {
355 reference->d->externalFilename = src.mid(7);
356 reference->d->embed = false;
357 } else {
358 reference->d->internalFilename = src;
359 reference->d->embed = true;
360 }
361
362 qreal width = KisDomUtils::toDouble(elem.attribute("width", "100"));
363 qreal height = KisDomUtils::toDouble(elem.attribute("height", "100"));
364 reference->setSize(QSizeF(width, height));
365 reference->setKeepAspectRatio(elem.attribute("keepAspectRatio", "true").toLower() == "true");
366
367 auto transform = SvgTransformParser(elem.attribute("transform")).transform();
368 reference->setTransformation(transform);
369
370 qreal opacity = KisDomUtils::toDouble(elem.attribute("opacity", "1"));
371 reference->setTransparency(1.0 - opacity);
372
373 qreal saturation = KisDomUtils::toDouble(elem.attribute("saturation", "1"));
374 reference->setSaturation(saturation);
375
376 return reference;
377}
QTransform transform() const
return the current matrix that contains the rotation/scale/position of this shape
Definition KoShape.cpp:1145
QTransform transform() const
double toDouble(const QString &str, bool *ok=nullptr)

References KisReferenceImage(), saturation(), KisDomUtils::toDouble(), KoShape::transform(), and SvgTransformParser::transform().

◆ getImage()

QImage KisReferenceImage::getImage ( )

Definition at line 419 of file KisReferenceImage.cpp.

420{
421 return d->image;
422}

References d.

◆ getPixel()

QColor KisReferenceImage::getPixel ( QPointF position)

Definition at line 306 of file KisReferenceImage.cpp.

307{
308 if (transparency() == 1.0) return Qt::transparent;
309
310 const QSizeF shapeSize = size();
311 const QTransform scale = QTransform::fromScale(d->image.width() / shapeSize.width(), d->image.height() / shapeSize.height());
312
313 const QTransform transform = absoluteTransformation().inverted() * scale;
314 const QPointF localPosition = position * transform;
315
316 if (d->cachedImage.isNull()) {
317 d->updateCache();
318 }
319
320 return d->cachedImage.pixelColor(localPosition.toPoint());
321}
QTransform absoluteTransformation() const
Definition KoShape.cpp:382
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
Definition KoShape.cpp:237
qreal transparency(bool recursive=false) const
Definition KoShape.cpp:730
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825

References KoShape::absoluteTransformation(), d, KoShape::position(), KoShape::scale(), KoShape::size(), KoShape::transform(), and KoShape::transparency().

◆ hasLocalFile()

bool KisReferenceImage::hasLocalFile ( )

Definition at line 285 of file KisReferenceImage.cpp.

286{
287 return !d->externalFilename.isEmpty();
288}

References d.

◆ internalFile()

QString KisReferenceImage::internalFile ( ) const

Definition at line 295 of file KisReferenceImage.cpp.

296{
297 return d->internalFilename;
298}

References d.

◆ loadImage()

bool KisReferenceImage::loadImage ( KoStore * store)

Definition at line 397 of file KisReferenceImage.cpp.

398{
399 if (!d->embed) {
400 return d->loadFromFile();
401 }
402
403 if (!store->open(d->internalFilename)) {
404 return false;
405 }
406
407 KoStoreDevice storeDev(store);
408 if (!storeDev.open(QIODevice::ReadOnly)) {
409 return false;
410 }
411
412 if (!d->image.load(&storeDev, "PNG")) {
413 return false;
414 }
415
416 return store->close();
417}
bool close()
Definition KoStore.cpp:156
bool open(const QString &name)
Definition KoStore.cpp:109

References KoStore::close(), d, KoStore::open(), and KoStoreDevice::open().

◆ paint()

void KisReferenceImage::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 226 of file KisReferenceImage.cpp.

227{
228 if (!parent()) return;
229
230 gc.save();
231
232 QSizeF shapeSize = size();
233 // scale and rotation done by the user (excluding zoom)
234 QTransform transform = QTransform::fromScale(shapeSize.width() / d->image.width(), shapeSize.height() / d->image.height());
235
236 if (d->cachedImage.isNull()) {
237 // detach the data
238 const_cast<KisReferenceImage*>(this)->d->updateCache();
239 }
240
241 qreal scale;
242 // scale from the highDPI display
243 QTransform devicePixelRatioFTransform = QTransform::fromScale(gc.device()->devicePixelRatioF(), gc.device()->devicePixelRatioF());
244 // all three transformations: scale and rotation done by the user, scale from highDPI display, and zoom + rotation of the view
245 // order: zoom/rotation of the view; scale to high res; scale and rotation done by the user
246 QImage prescaled = d->mipmap.getClosestWithoutWorkaroundBorder(transform * devicePixelRatioFTransform * gc.transform(), &scale);
247 transform.scale(1.0 / scale, 1.0 / scale);
248
249 if (scale > 1.0) {
250 // enlarging should be done without smooth transformation
251 // so the user can see pixels just as they are painted
252 gc.setRenderHints(QPainter::Antialiasing);
253 } else {
254 gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
255 }
256 gc.setClipRect(QRectF(QPointF(), shapeSize), Qt::IntersectClip);
257 gc.setTransform(transform, true);
258 gc.drawImage(QPoint(), prescaled);
259
260 gc.restore();
261}

References d, KoShape::Private::parent, KoShape::scale(), KoShape::size(), and KoShape::transform().

◆ saturation()

qreal KisReferenceImage::saturation ( ) const

Definition at line 269 of file KisReferenceImage.cpp.

270{
271 return d->saturation;
272}

References d.

◆ saveImage()

bool KisReferenceImage::saveImage ( KoStore * store) const

Definition at line 379 of file KisReferenceImage.cpp.

380{
381 if (!d->embed) return true;
382
383 if (!store->open(d->internalFilename)) {
384 return false;
385 }
386
387 bool saved = false;
388
389 KoStoreDevice storeDev(store);
390 if (storeDev.open(QIODevice::WriteOnly)) {
391 saved = d->image.save(&storeDev, "PNG");
392 }
393
394 return store->close() && saved;
395}

References KoStore::close(), d, KoStore::open(), and KoStoreDevice::open().

◆ saveXml()

void KisReferenceImage::saveXml ( QDomDocument & document,
QDomElement & parentElement,
int id )

Definition at line 323 of file KisReferenceImage.cpp.

324{
325 d->id = id;
326
327 QDomElement element = document.createElement("referenceimage");
328
329 if (d->embed) {
330 d->internalFilename = QString("reference_images/%1.png").arg(id);
331 }
332
333 const QString src = d->embed ? d->internalFilename : (QString("file://") + d->externalFilename);
334 element.setAttribute("src", src);
335
336 const QSizeF &shapeSize = size();
337 element.setAttribute("width", KisDomUtils::toString(shapeSize.width()));
338 element.setAttribute("height", KisDomUtils::toString(shapeSize.height()));
339 element.setAttribute("keepAspectRatio", keepAspectRatio() ? "true" : "false");
340 element.setAttribute("transform", SvgUtil::transformToString(transform()));
341
342 element.setAttribute("opacity", KisDomUtils::toString(1.0 - transparency()));
343 element.setAttribute("saturation", KisDomUtils::toString(d->saturation));
344
345 parentElement.appendChild(element);
346}
bool keepAspectRatio() const
Definition KoShape.cpp:1052
static QString transformToString(const QTransform &transform)
Converts specified transformation to a string.
Definition SvgUtil.cpp:104
QString toString(const QString &value)

References d, KoShape::keepAspectRatio(), KoShape::size(), KisDomUtils::toString(), KoShape::transform(), SvgUtil::transformToString(), and KoShape::transparency().

◆ setEmbed()

void KisReferenceImage::setEmbed ( bool embed)

Definition at line 274 of file KisReferenceImage.cpp.

275{
276 KIS_SAFE_ASSERT_RECOVER_RETURN(embed || !d->externalFilename.isEmpty());
277 d->embed = embed;
278}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References d, embed(), and KIS_SAFE_ASSERT_RECOVER_RETURN.

◆ setFilename()

void KisReferenceImage::setFilename ( const QString & filename)

Definition at line 301 of file KisReferenceImage.cpp.

302{
303 d->externalFilename = filename;
304}

References d, and filename().

◆ setSaturation()

void KisReferenceImage::setSaturation ( qreal saturation)

Definition at line 263 of file KisReferenceImage.cpp.

264{
265 d->saturation = saturation;
266 d->cachedImage = QImage();
267}

References d, and saturation().

Member Data Documentation

◆ d

QSharedDataPointer<Private> KisReferenceImage::d
private

Definition at line 89 of file KisReferenceImage.h.


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