aboutsummaryrefslogtreecommitdiff
path: root/src/GraphicsButtonObject.h
blob: dbbcaa3e7279deaf9085ffea0e43b7e21e8c099c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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