1
/********************************************************************************
2
**
3
**  GNU General Public License Usage
4
**
5
**  This program is free software: you can redistribute it and/or modify
6
**  it under the terms of the GNU General Public License as published by
7
**  the Free Software Foundation, either version 3 of the License, or
8
**  (at your option) any later version.
9
**
10
**  This program is distributed in the hope that it will be useful,
11
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
**  GNU General Public License for more details.
14
**
15
**  You should have received a copy of the GNU General Public License
16
**  along with this program. If not, see <http://www.gnu.org/licenses/>.
17
**
18
********************************************************************************/
19
20
#ifndef BUTTON_H
21
#define BUTTON_H
22
23
#include <QGraphicsItem>
24
#include <QObject>
25
#include <QPainter>
26
#include <QGraphicsSceneMouseEvent>
27
28
class Button : public QObject, public QGraphicsItem
29
{
30
    Q_OBJECT
31
    Q_INTERFACES(QGraphicsItem)
32
33
public:
34
    Button(QGraphicsItem *parent = 0);
35
    Button(const QString normal, const QString pressed = "",
36
           QGraphicsItem *parent = 0);
37
38
    QRectF boundingRect() const;
39
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
40
               QWidget *widget = 0);
41
    void setPixmap(const QString normal, const QString pressed = "");
42
43
signals:
44
    void clicked();
45
46
protected:
47
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
48
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
49
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
50
51
private:
52
    QPixmap m_normal;
53
    QPixmap m_pressed;
54
    bool m_isPressed;
55
};
56
57
#endif