KGameRenderedGraphicsObject Class

A QGraphicsObject which displays pixmaps from a KGameRenderer. More...

Header: #include <KGameRenderedGraphicsObject>
Inherits: QGraphicsObject and KGameRendererClient

Properties

Public Functions

KGameRenderedGraphicsObject(KGameGraphicsViewRenderer *renderer, const QString &spriteKey, QGraphicsItem *parent = nullptr)
QSizeF fixedSize() const
QPointF offset() const
QGraphicsView *primaryView() const
void setFixedSize(QSizeF size)
void setOffset(QPointF offset)
void setOffset(qreal x, qreal y)
void setPrimaryView(QGraphicsView *view)

Detailed Description

This item displays a pixmap which is retrieved from a KGameRenderer, and is updated automatically when the KGameRenderer changes the theme.

The item has built-in handling for animated sprites (i.e. those with multiple frames). It is a QGraphicsObject and exposes a "frame" property, so you can easily run the animation by plugging in a QPropertyAnimation.

Modes of operation

By default, this item behaves just like a QGraphicsPixmapItem. The size of its bounding rect is equal to the size of the pixmap, i.e. the renderSize().

However, the KGameRenderedGraphicsObject has a second mode of operation, which is enabled by setting a "primary view". (This can be done automatically via KGameGraphicsViewRenderer::setDefaultPrimaryView.)

If such a primary view is set, the following happens:

  • The renderSize of the pixmap is automatically determined from the painting requests received from the primary view (manual calls to setRenderSize() are unnecessary and need to be avoided).
  • The size of the item's boundingRect() is independent of the renderSize(). The default fixedSize() is 1x1, which means that the item's bounding rect is the unit square (moved by the configured offset()).

Property Documentation

frame : int

Frame number.

Member Function Documentation

KGameRenderedGraphicsObject::KGameRenderedGraphicsObject(KGameGraphicsViewRenderer *renderer, const QString &spriteKey, QGraphicsItem *parent = nullptr)

Creates a new KGameRenderedGraphicsObject which renders the sprite with the given spriteKey as provided by the given renderer, with parent parent.

QSizeF KGameRenderedGraphicsObject::fixedSize() const

Returns the fixed size of this item, or (-1, -1) if this item has no primary view.

See also setFixedSize().

QPointF KGameRenderedGraphicsObject::offset() const

Returns the item's offset, which defines the point of the top-left corner of the bounding rect, in local coordinates.

See also setOffset().

QGraphicsView *KGameRenderedGraphicsObject::primaryView() const

Returns a pointer to the current primary view, or 0 if no primary view has been set (which is the default).

See also setPrimaryView().

void KGameRenderedGraphicsObject::setFixedSize(QSizeF size)

Sets the fixed size of this item, that is, the guaranteed size of the item, to size. This works only when a primary view has been set.

See also fixedSize().

void KGameRenderedGraphicsObject::setOffset(QPointF offset)

Sets the item's offset, which defines the point of the top-left corner of the bounding rect, in local coordinates.

See also offset().

void KGameRenderedGraphicsObject::setOffset(qreal x, qreal y)

Sets the item's offset, which defines the point of the top-left corner of the bounding rect, to x, y, in local coordinates.

This is an overloaded function.

void KGameRenderedGraphicsObject::setPrimaryView(QGraphicsView *view)

Sets the primary view of this item to view. (See class documentation for what the primary view does.) Pass a null pointer to just disconnect from the current primary view. The fixed size is then reset to (-1, -1). If a primary view is set, the fixed size is initialized to (1, 1).

Warning: While a primary view is set, avoid any manual calls to setRenderSize().

See also primaryView() and Modes of operation.