From 685fe05def77b039221edf06c74af74915d536c5 Mon Sep 17 00:00:00 2001 From: Samu Laaksonen Date: Tue, 25 Sep 2012 20:00:41 +0300 Subject: Initial code commit Added some stuff for project base - tiled sources - few Qt based classes for gfx --- src/GraphicsButtonObject.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/GraphicsButtonObject.h (limited to 'src/GraphicsButtonObject.h') diff --git a/src/GraphicsButtonObject.h b/src/GraphicsButtonObject.h new file mode 100644 index 0000000..dbbcaa3 --- /dev/null +++ b/src/GraphicsButtonObject.h @@ -0,0 +1,59 @@ +#ifndef GraphicsButtonObject_h +#define GraphicsButtonObject_h + +#include +#include +#include +#include + +/** + * Used for creating nice buttons to menus. + */ +class GraphicsButtonObject : + public QObject, + public QGraphicsPixmapItem +{ + Q_OBJECT + +public: + explicit GraphicsButtonObject(const QPixmap &releasedPixmap, + QGraphicsPixmapItem *parent = 0, + QGraphicsScene *scene = 0); + + explicit GraphicsButtonObject(QGraphicsPixmapItem *parent = 0, + QGraphicsScene *scene = 0); + + GraphicsButtonObject(const QString &str, + QGraphicsPixmapItem *parent = 0, + QGraphicsScene *scene = 0); + + ~GraphicsButtonObject(); + + /** + * Sets gfx to indicate pressed-state on button. + * @param &pixmap The pixmap used as gfx + */ + void setPressedPixmap(const QPixmap &pixmap); + + /** + * Sets gfx to indicate released/normal-state on button. + * @param &pixmap The pixmap used as gfx + */ + void setReleasedPixmap(const QPixmap &pixmap); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + +private: + QPixmap m_pressedGfx; + QPixmap m_releasedGfx; + + static QPixmap *s_tmpGfx; + static int s_ref; + +signals: + void clicked(); +}; + +#endif // GraphicsButtonObject_h -- cgit v1.2.3