KGamePopupItem Class
QGraphicsItem to show short popup messages which do not interrupt the gameplay. More...
| Header: | #include <KGamePopupItem> |
| Inherits: | QObject and QGraphicsItem |
Public Types
| enum | HideType { InstantHide, AnimatedHide } |
| enum | Position { TopLeft, TopRight, BottomLeft, BottomRight, Center } |
| enum | ReplaceMode { LeavePrevious, ReplacePrevious } |
| enum | Sharpness { Square, Sharp, Soft, Softest } |
Public Functions
| KGamePopupItem(QGraphicsItem *parent = nullptr) | |
| virtual | ~KGamePopupItem() override |
| void | forceHide(KGamePopupItem::HideType type = AnimatedHide) |
| bool | hidesOnMouseClick() const |
| qreal | messageOpacity() const |
| int | messageTimeout() const |
| void | setBackgroundBrush(const QBrush &brush) |
| void | setHideOnMouseClick(bool hide) |
| void | setMessageIcon(const QPixmap &pix) |
| void | setMessageOpacity(qreal opacity) |
| void | setMessageTimeout(int msec) |
| void | setSharpness(KGamePopupItem::Sharpness sharpness) |
| void | setTextColor(const QColor &color) |
| KGamePopupItem::Sharpness | sharpness() const |
| void | showMessage(const QString &text, KGamePopupItem::Position pos, KGamePopupItem::ReplaceMode mode = LeavePrevious) |
Reimplemented Public Functions
| virtual QRectF | boundingRect() const override |
| virtual void | paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget) override |
Signals
| void | hidden() |
| void | linkActivated(const QString &link) |
| void | linkHovered(const QString &link) |
Private Slots
| void | animationFrame(int) |
| void | hideMe() |
| void | onLinkHovered(const QString &) |
| void | onTextItemClicked() |
| void | playHideAnimation() |
Detailed Description
QGraphicsItem capable of showing short popup messages which do not interrupt the gameplay. Message can stay on screen for specified amount of time and automatically hide after (unless user hovers it with mouse).
Example of use:
KGamePopupItem *messageItem = new KGamePopupItem();
myGraphicsScene->addItem(messageItem);
...
messageItem->setMessageTimeout( 3000 ); // 3 sec
messageItem->showMessage("Hello, I'm a game message! How do you do?", BottomLeft);
Member Type Documentation
enum KGamePopupItem::HideType
Used to specify how to hide in forceHide() - instantly or animatedly
| Constant | Value | Description |
|---|---|---|
KGamePopupItem::InstantHide | 0 | Hide instantly |
KGamePopupItem::AnimatedHide | 1 | Hide animatedly |
enum KGamePopupItem::Position
The possible places in the scene where a message can be shown.
| Constant | Value | Description |
|---|---|---|
KGamePopupItem::TopLeft | 0 | Top left of the scene |
KGamePopupItem::TopRight | 1 | Top right of the scene |
KGamePopupItem::BottomLeft | 2 | Bottom left of the scene |
KGamePopupItem::BottomRight | 3 | Bottom right of the scene |
KGamePopupItem::Center | 4 | Center of the scene |
enum KGamePopupItem::ReplaceMode
Possible values for message showing mode in respect to a previous message.
| Constant | Value | Description |
|---|---|---|
KGamePopupItem::LeavePrevious | 0 | Leaves the previous message in place. |
KGamePopupItem::ReplacePrevious | 1 | Replaces the previous message. |
enum KGamePopupItem::Sharpness
Possible values for the popup angles sharpness.
| Constant | Value |
|---|---|
KGamePopupItem::Square | 0 |
KGamePopupItem::Sharp | 2 |
KGamePopupItem::Soft | 5 |
KGamePopupItem::Softest | 10 |
Member Function Documentation
[explicit] KGamePopupItem::KGamePopupItem(QGraphicsItem *parent = nullptr)
Constructs a message item with parent parent. It is hidden by default.
[override virtual noexcept] KGamePopupItem::~KGamePopupItem()
Destructs a message item
[private slot] void KGamePopupItem::animationFrame(int)
[override virtual] QRectF KGamePopupItem::boundingRect() const
Reimplements: QGraphicsItem::boundingRect() const.
Returns the outer bounds of this item.
See also QGraphicsItem::boundingRect.
void KGamePopupItem::forceHide(KGamePopupItem::HideType type = AnimatedHide)
Requests the item to be hidden immediately, with HideType type.
[signal] void KGamePopupItem::hidden()
Emitted when the popup finishes hiding. This includes hiding caused by both timeouts and mouse clicks.
[private slot] void KGamePopupItem::hideMe()
bool KGamePopupItem::hidesOnMouseClick() const
Returns whether this popup item hides on mouse click.
[signal] void KGamePopupItem::linkActivated(const QString &link)
Emitted when user clicks on a link link in this item.
[signal] void KGamePopupItem::linkHovered(const QString &link)
Emitted when user hovers a link link in this item.
qreal KGamePopupItem::messageOpacity() const
Returns current message opacity.
See also setMessageOpacity().
int KGamePopupItem::messageTimeout() const
Returns the message timeout that is currently set. Defaults to 2000ms.
See also setMessageTimeout().
[private slot] void KGamePopupItem::onLinkHovered(const QString &)
[private slot] void KGamePopupItem::onTextItemClicked()
[override virtual] void KGamePopupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *widget)
Reimplements: QGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget).
Paints the contents of this item, in local coordinates, using painter p with option, optionally onto widget.
See also QGraphicsItem::paint.
[private slot] void KGamePopupItem::playHideAnimation()
void KGamePopupItem::setBackgroundBrush(const QBrush &brush)
Sets the brush used to paint item background to brush. By default system-default brush is used.
See also KColorScheme.
void KGamePopupItem::setHideOnMouseClick(bool hide)
Sets whether to hide this popup item on mouse click to hide. By default a mouse click will cause an item to hide
void KGamePopupItem::setMessageIcon(const QPixmap &pix)
Sets custom pixmap pix to show instead of default icon on the left.
void KGamePopupItem::setMessageOpacity(qreal opacity)
Sets the message opacity from 0 (fully transparent) to 1 (fully opaque). For example 0.5 is half transparent. It defaults to 1.0.
See also messageOpacity().
void KGamePopupItem::setMessageTimeout(int msec)
Sets the amount of time the item will stay visible on screen before it goes away to msec milliseconds. If item is hovered with mouse it will hide only after user moves the mouse away.
If msec is 0, the message will stay visible until it gets explicitly hidden by forceHide().
See also messageTimeout().
void KGamePopupItem::setSharpness(KGamePopupItem::Sharpness sharpness)
Sets the popup angles sharpness to sharpness.
See also sharpness().
void KGamePopupItem::setTextColor(const QColor &color)
Sets the default color for unformatted text to color. By default system-default color is used.
See also KColorScheme.
KGamePopupItem::Sharpness KGamePopupItem::sharpness() const
Returns current popup angles sharpness.
See also setSharpness().
void KGamePopupItem::showMessage(const QString &text, KGamePopupItem::Position pos, KGamePopupItem::ReplaceMode mode = LeavePrevious)
Shows the message text. item will appear at specified pos of the scene using simple animation. Item will be automatically hidden after timeout set in setMessageTimeOut() passes. If item is hovered with mouse it won't hide until user moves the mouse away.
Note that if pos is Center, message animation will be of fade in/out type, rather than slide in/out.
mode how to handle an already shown message by this item: either leave it and ignore the new one or replace it