[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-games-devel
Subject: [Kde-games-devel] Fwd: KGamePopupItem patch
From: kleag () free ! fr
Date: 2007-07-15 19:03:34
Message-ID: 200707152103.34348.kleag () free ! fr
[Download RAW message or body]
Sorrey,
with the attachment this time...
---------- Forwarded Message ----------
Subject: KGamePopupItem patch
Date: Sunday 15 July 2007
From: kleag@free.fr
To: kde-games-devel@kde.org
Hello Dmitry,
I finally had time to look at KGamePopupItem. Well, I had no more a lot of
wishes... Joined patch implements two of my propositions :
- optional rounded angles ;
- possibility to replace a message by a new one
What do you think ?
Best regards,
Kleag
-------------------------------------------------------
["kgamepopupitem.patch" (text/x-patch)]
Index: kgamepopupitem.h
===================================================================
--- kgamepopupitem.h (revision 688194)
+++ kgamepopupitem.h (working copy)
@@ -20,7 +20,7 @@
#include <libkdegames_export.h>
-#include <QtGui/QGraphicsItem>
+#include <QtGui/QGraphicsPathItem>
#include <QtCore/QObject>
class KGamePopupItemPrivate;
@@ -41,18 +41,27 @@
* messageItem->showMessage("Hello, I'm a game message! How do you do?");
* \endcode
*/
-class KDEGAMES_EXPORT KGamePopupItem : public QObject, public QGraphicsItem
+class KDEGAMES_EXPORT KGamePopupItem : public QObject, public QGraphicsPathItem
{
Q_OBJECT
public:
/**
+ * Possible values for message showing mode in respect to a previous
+ * message
+ */
+ enum ReplaceMode { Leave, Replace };
+ /**
+ * Possible values for the popup angles sharpness
+ */
+ enum Sharpness { Square=0, Sharp=2, Soft=5, Softest=10 };
+ /**
* The possible places in the scene where a message can be shown
*/
enum Position { TopLeft, TopRight, BottomLeft, BottomRight };
/**
* Constructs a message item. It is hidden by default.
*/
- KGamePopupItem();
+ KGamePopupItem(QGraphicsItem * parent = 0);
/**
* Destructs a message item
*/
@@ -67,7 +76,7 @@
* @param text holds the message to show
* @param pos position on the scene where the message will appear
*/
- void showMessage( const QString& text, Position pos );
+ void showMessage( const QString& text, Position pos, ReplaceMode = Leave);
/**
* Sets the amount of time the item will stay visible on screen
* before it goes away.
@@ -127,6 +136,14 @@
* Paints item. Reimplemented from QGraphicsItem
*/
virtual void paint( QPainter* p, const QStyleOptionGraphicsItem *option, \
QWidget* widget ); + /**
+ * Sets the popup angles sharpness
+ */
+ void setSharpness( Sharpness sharpness );
+ /**
+ * @return current popup angles sharpness
+ */
+ Sharpness sharpness() const;
Q_SIGNALS:
/**
* Emitted when user clicks on a link in item
Index: kgamepopupitem.cpp
===================================================================
--- kgamepopupitem.cpp (revision 688194)
+++ kgamepopupitem.cpp (working copy)
@@ -42,9 +42,10 @@
void setOpacity(qreal opa) { m_opacity = opa; }
virtual void paint( QPainter* p, const QStyleOptionGraphicsItem *option, \
QWidget* widget ) {
+ p->save();
p->setOpacity(m_opacity);
QGraphicsTextItem::paint(p,option,widget);
- p->setOpacity(1.0);
+ p->restore();
}
private:
qreal m_opacity;
@@ -58,7 +59,8 @@
public:
KGamePopupItemPrivate()
: m_position( KGamePopupItem::BottomLeft ), m_timeout(2000),
- m_opacity(1.0), m_hoveredByMouse(false), m_textChildItem(0) {}
+ m_opacity(1.0), m_hoveredByMouse(false), m_textChildItem(0),
+ m_sharpness(KGamePopupItem::Square) {}
/**
* Timeline for animations
*/
@@ -105,10 +107,14 @@
* Background brush color
*/
QBrush m_brush;
+ /**
+ * popup angles sharpness
+ */
+ KGamePopupItem::Sharpness m_sharpness;
};
-KGamePopupItem::KGamePopupItem()
- : d(new KGamePopupItemPrivate)
+KGamePopupItem::KGamePopupItem(QGraphicsItem * parent)
+ : QGraphicsPathItem(parent), d(new KGamePopupItemPrivate)
{
hide();
d->m_textChildItem = new TextItemWithOpacity(this);
@@ -145,22 +151,33 @@
void KGamePopupItem::paint( QPainter* p, const QStyleOptionGraphicsItem *option, \
QWidget* widget ) {
- Q_UNUSED(option);
- Q_UNUSED(widget);
+ p->save();
+ setBrush( d->m_brush );
- p->setBrush( d->m_brush );
- p->setOpacity(d->m_opacity);
- p->drawRect( d->m_boundRect );
+ // sets the brush opacity
+ QColor color(brush().color());
+ color.setAlphaF(d->m_opacity);
+ brush().setColor(color);
+
+ QGraphicsPathItem::paint(p, option, widget);
p->drawPixmap( MARGIN, static_cast<int>(d->m_boundRect.height()/2) - \
d->m_iconPix.height()/2, d->m_iconPix );
-
- p->setOpacity(1.0);
+ p->restore();
}
-void KGamePopupItem::showMessage( const QString& text, Position pos )
+void KGamePopupItem::showMessage( const QString& text, Position pos, ReplaceMode \
mode ) {
if(d->m_timeLine.state() == QTimeLine::Running || d->m_timer.isActive())
+ {
+ if (mode == Replace)
+ {
+ forceHide(InstantHide);
+ }
+ else
+ {
return;// we're already showing a message
+ }
+ }
// NOTE: we blindly take first view we found. I.e. we don't support
// multiple views
@@ -183,6 +200,18 @@
h = d->m_iconPix.height() + MARGIN*2;
d->m_boundRect = QRectF(0, 0, w, h);
+ QPainterPath roundRectPath;
+ roundRectPath.moveTo(w, d->m_sharpness);
+ roundRectPath.arcTo(w-(2*d->m_sharpness), 0.0,(2*d->m_sharpness), \
(d->m_sharpness), 0.0, 90.0); + roundRectPath.lineTo(d->m_sharpness, 0.0);
+ roundRectPath.arcTo(0.0, 0.0, (2*d->m_sharpness), (2*d->m_sharpness), 90.0, \
90.0); + roundRectPath.lineTo(0.0, h-(d->m_sharpness));
+ roundRectPath.arcTo(0.0, h-(2*d->m_sharpness), 2*d->m_sharpness, \
2*d->m_sharpness, 180.0, 90.0); + roundRectPath.lineTo(w-(d->m_sharpness), h);
+ roundRectPath.arcTo(w-(2*d->m_sharpness), h-(2*d->m_sharpness), \
(2*d->m_sharpness), (2*d->m_sharpness), 270.0, 90.0); + \
roundRectPath.closeSubpath(); + setPath(roundRectPath);
+
// adjust y-pos of text item so it appears centered
d->m_textChildItem->setPos( d->m_textChildItem->x(),
d->m_boundRect.height()/2 - \
d->m_textChildItem->boundingRect().height()/2); @@ -330,4 +359,14 @@
emit linkHovered(link);
}
+void KGamePopupItem::setSharpness( Sharpness sharpness )
+{
+ d->m_sharpness = sharpness;
+}
+
+KGamePopupItem::Sharpness KGamePopupItem::sharpness() const
+{
+ return d->m_sharpness;
+}
+
#include "kgamepopupitem.moc"
_______________________________________________
kde-games-devel mailing list
kde-games-devel@kde.org
https://mail.kde.org/mailman/listinfo/kde-games-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic