1 /* ColorCode, a free MasterMind clone with built in solver
2  * Copyright (C) 2009  Dirk Laebisch
3  * http://www.laebisch.com/
4  *
5  * ColorCode 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  * ColorCode 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 ColorCode. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef GRAPHICSBTN_H
20 #define GRAPHICSBTN_H
21 
22 #include <QObject>
23 #include <QGraphicsItem>
24 #include <QColor>
25 #include <QPen>
26 #include <QFont>
27 #include <QRadialGradient>
28 #include <iostream>
29 
30 class GraphicsBtn : public QObject, public QGraphicsItem
31 {
32     Q_OBJECT
33     Q_INTERFACES(QGraphicsItem)
34 
35 public:
36     GraphicsBtn();
37 
38     void SetEnabled(bool b);
39     void SetWidth(int w);
40     void SetLabel(QString str);
41     void ShowBtn(bool b);
42     void SetStatesOpacity(const qreal opOver, const qreal opOut);
43     void InvertStates();
44     void SetHoverState();
45     void SetOutState();
46     void SetPressedState();
47 
48     void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
49     QRectF boundingRect() const;
50 
51 signals:
52     void BtnPressSignal(GraphicsBtn* btn);
53 
54 protected:
55     void hoverEnterEvent(QGraphicsSceneHoverEvent* e);
56     void hoverLeaveEvent(QGraphicsSceneHoverEvent* e);
57     void mousePressEvent(QGraphicsSceneMouseEvent* e);
58     void mouseReleaseEvent(QGraphicsSceneMouseEvent* e);
59 
60     virtual void InitGraphics();
61     virtual void SetShapes();
62 
63     QString mLabel;
64     int mWidth;
65     int mLabelWidth;
66     int mYOffs;
67     qreal mOpOver;
68     qreal mOpOut;
69 
70     QRectF mRect;
71     QRectF mRectFill;
72     QRectF mIconRect;
73 
74     QBrush mFillOutBrush;
75     QBrush mFillOverBrush;
76     QBrush* mFillBrush;
77 
78     QBrush mFrameOutBrush;
79     QBrush mFrameOverBrush;
80     QBrush* mFrameBrush;
81 
82     QFont mFont;
83 };
84 
85 #endif // GRAPHICSBTN_H
86