added all files
[ffqwlibrary] / libffqw-1.0 / sources / ffabstractbutton.h
1 /*
2           GNU GENERAL PUBLIC LICENSE
3                        Version 3, 29 June 2007
4
5  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
6  Everyone is permitted to copy and distribute verbatim copies
7  of this license document, but changing it is not allowed.
8
9                             Preamble
10
11   The GNU General Public License is a free, copyleft license for
12 software and other kinds of works.
13
14   The licenses for most software and other practical works are designed
15 to take away your freedom to share and change the works.  By contrast,
16 the GNU General Public License is intended to guarantee your freedom to
17 share and change all versions of a program--to make sure it remains free
18 software for all its users.  We, the Free Software Foundation, use the
19 GNU General Public License for most of our software; it applies also to
20 any other work released this way by its authors.  You can apply it to
21 your programs, too.
22
23   When we speak of free software, we are referring to freedom, not
24 price.  Our General Public Licenses are designed to make sure that you
25 have the freedom to distribute copies of free software (and charge for
26 them if you wish), that you receive source code or can get it if you
27 want it, that you can change the software or use pieces of it in new
28 free programs, and that you know you can do these things.
29
30   To protect your rights, we need to prevent others from denying you
31 these rights or asking you to surrender the rights.  Therefore, you have
32 certain responsibilities if you distribute copies of the software, or if
33 you modify it: responsibilities to respect the freedom of others.
34
35   For example, if you distribute copies of such a program, whether
36 gratis or for a fee, you must pass on to the recipients the same
37 freedoms that you received.  You must make sure that they, too, receive
38 or can get the source code.  And you must show them these terms so they
39 know their rights.
40
41   Developers that use the GNU GPL protect your rights with two steps:
42 (1) assert copyright on the software, and (2) offer you this License
43 giving you legal permission to copy, distribute and/or modify it.
44
45   For the developers' and authors' protection, the GPL clearly explains
46 that there is no warranty for this free software.  For both users' and
47 authors' sake, the GPL requires that modified versions be marked as
48 changed, so that their problems will not be attributed erroneously to
49 authors of previous versions.
50
51   Some devices are designed to deny users access to install or run
52 modified versions of the software inside them, although the manufacturer
53 can do so.  This is fundamentally incompatible with the aim of
54 protecting users' freedom to change the software.  The systematic
55 pattern of such abuse occurs in the area of products for individuals to
56 use, which is precisely where it is most unacceptable.  Therefore, we
57 have designed this version of the GPL to prohibit the practice for those
58 products.  If such problems arise substantially in other domains, we
59 stand ready to extend this provision to those domains in future versions
60 of the GPL, as needed to protect the freedom of users.
61
62   Finally, every program is threatened constantly by software patents.
63 States should not allow patents to restrict development and use of
64 software on general-purpose computers, but in those that do, we wish to
65 avoid the special danger that patents applied to a free program could
66 make it effectively proprietary.  To prevent this, the GPL assures that
67 patents cannot be used to render the program non-free.
68
69   The precise terms and conditions for copying, distribution and
70 modification follow.
71
72 http://www.gnu.org/licenses/gpl-3.0.txt
73 */
74 /**
75  * @file ffabstractbutton.h
76  * @brief Contains a necessary class declaration.
77  *
78  * @author ComArch S.A.
79  * @date 2009.08.03
80  * @version 1.0
81  */
82
83 #ifndef FFABSTRACTBUTTON_H
84 #define FFABSTRACTBUTTON_H
85
86 #include "ffviewcache.h"
87 #include "ffscrollinglabel.h"
88 #include <QPainter>
89 #include <QTime>
90 #include <QPen>
91
92
93 static const QString BUTTON_PATH= ":/standard/button"; ///<Path to the pixmaps used by button
94 static const Qt::Alignment DEFAULT_ICON_ALIGNMENT = Qt::AlignLeft;///<Default icon's alignment
95 /**
96  * @author ComArch S.A.
97  * @date 2009.08.03
98  * @version 1.0
99  *
100  * @brief A class responsible for margins and left indent
101  */
102 class FFAbstractButtonPrivate
103 {
104 public:
105         FFAbstractButtonPrivate();
106         virtual ~FFAbstractButtonPrivate();
107
108         void scaleMargins(QSize oldSize, QSize newSize);
109         void setMargins(int leftMargin,
110                         int rightMargin,
111                         int topMargin,
112                         int bottomMargin);
113
114 private:
115         friend class FFAbstractButton;
116
117         int leftMargin_;   ///<left margin value
118         int topMargin_;    ///<top margin value
119         int bottomMargin_; ///<bottom margin value
120         int rightMargin_;  ///<right margin value
121         int hSpacing_;     ///<horizontal spacing value
122         int vSpacing_;     ///<vertical spacing value
123
124         float leftMarginTemp;   ///<stores old left margin value
125         float topMarginTemp;    ///<stores old top margin value
126         float bottomMarginTemp; ///<stores old bottom margin value
127         float rightMarginTemp;  ///<stores old right margin value
128         float hSpacingTemp;     ///<stores old horizontal spacing value
129         float vSpacingTemp;     ///<stores old vertical spacing value
130
131         int leftIndent_;        ///<left indent value
132 };
133
134 /**
135  * @author ComArch S.A.
136  * @date 2009.08.03
137  * @version 1.0
138  *
139  * @brief A class responsible for simplest button, only with graphics
140  */
141 class FFAbstractButton : public QAbstractButton
142 {
143         Q_OBJECT
144
145 public:
146         FFAbstractButton(QWidget* parent = 0);
147         virtual ~FFAbstractButton();
148
149         int indent();
150         int leftMargin();
151         int rightMargin();
152         int topMargin();
153         int bottomMargin();
154         int hSpacing();
155         int vSpacing();
156         Qt::Alignment iconAlignment();
157         void setLeftMargin(int leftMargin);
158         void setRightMargin(int rightMargin);
159         void setTopMargin(int topMargin);
160         void setBottomMargin(int bottomMargin);
161         void setMargins(int leftMargin,
162                         int rightMargin,
163                         int topMargin,
164                         int bottomMargin);
165         void setHSpacing(int hSpacing);
166         void setVSpacing(int hSpacing);
167         void setIconAlignment(Qt::Alignment iconAlignment);
168         QPen pen();
169         void setPen(QPen pen);
170         virtual void updateView();
171
172 protected:
173         virtual void paintEvent(QPaintEvent* event);
174         virtual void resizeEvent(QResizeEvent* event);
175         virtual void mousePressEvent(QMouseEvent* event);
176         virtual void mouseReleaseEvent(QMouseEvent* event);
177
178         virtual void paintIcon(QPainter* painter);
179
180         FFAbstractButtonPrivate insideRect;     ///<stores rectangle on which button is draw
181
182         bool isClicked_;            ///<stores clicked state
183         int  iconSpace;             ///<holds space between edges of icon (icons width)
184         QPen pen_;                  ///<holds a pen then you can use later to drawing in paintEvent
185         Qt::Alignment iconAlignment_; ///<stores alignment of icon
186         void setSkin();
187
188 private:
189
190         static FFViewCache* topLeftNormal;       ///<cached top left corner view
191         FFViewCache*        topCenterNormal;     ///<cached top center view
192         static FFViewCache* topRightNormal;      ///<cached top right corner view
193         FFViewCache*        centerLeftNormal;    ///<cached left view
194         FFViewCache*        centerNormal;        ///<cached center view
195         FFViewCache*        centerRightNormal;   ///<cached right view
196         static FFViewCache* bottomLeftNormal;    ///<cached bottom left corner view
197         FFViewCache*        bottomCenterNormal;  ///<cached bottom center view
198         static FFViewCache* bottomRightNormal;   ///<cached bottom right corner view
199         static FFViewCache* topLeftClicked;      ///<cached top left corner view - clicked state
200         FFViewCache*        topCenterClicked;    ///<cached top center view - clicked state
201         static FFViewCache* topRightClicked;     ///<cached top right corner view - clicked state
202         FFViewCache*        centerLeftClicked;   ///<cached left center view - clicked state
203         FFViewCache*        centerClicked;               ///<cached center view - clicked state
204         FFViewCache*        centerRightClicked;  ///<cached right center view - clicked state
205         static FFViewCache* bottomLeftClicked;   ///<cached bottom left corner view - clicked state
206         FFViewCache*        bottomCenterClicked; ///<cached bottom center view - clicked state
207         static FFViewCache* bottomRightClicked;  ///<cached bottom right corner view - clicked state
208
209         int pixmapsPositionWidth_;  ///<stores width of center part of the button
210         int pixmapsPositionHeight_; ///<stores height of center part of the button
211
212         QString path;  ///<stores path to the pixmaps
213         static bool  staticFFViewCacheUpdated;
214         static int   minimumWidth;
215
216         void init();
217
218 signals:
219         void clicked();
220 };
221
222 #endif // FFABSTRACTBUTTON_H