aboutsummaryrefslogtreecommitdiff
path: root/src/GraphicsButtonObject.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/GraphicsButtonObject.h')
-rw-r--r--src/GraphicsButtonObject.h59
1 files changed, 59 insertions, 0 deletions
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 <QObject>
+#include <QGraphicsPixmapItem>
+#include <QGraphicsLayoutItem>
+#include <QPixmap>
+
+/**
+ * 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