added all files
[ffqwlibrary] / libffqw-1.0 / sources / ffabstractcombobox.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 /**
76  * @file ffabstractcombobox.h
77  * @brief Contains a necessary class declaration.
78  *
79  * @author ComArch S.A.
80  * @date 2009.10.9
81  * @version 1.0
82  */
83
84 #ifndef FFABSTRACTCOMBOBOX_H
85 #define FFABSTRACTCOMBOBOX_H
86
87 #include <QApplication>
88 #include <QDialog>
89 #include <QDesktopWidget>
90 #include <QWidget>
91 #include <QtGlobal>
92 #include <QGridLayout>
93
94 #include "ffabstractbutton.h"
95 #include "ffscrollarea.h"
96
97 class FFComboPopUp;
98
99 /**
100  * @author ComArch S.A.
101  * @date 2009.10.09
102  * @version 1.0
103  *
104  * @brief A class inherited by specific comboboxes
105  */
106 class FFAbstractComboBox : public QWidget
107 {
108         Q_OBJECT
109         friend class FFComboPopUp;
110
111 public:
112         FFAbstractComboBox(FFAbstractButton* activator, QWidget* parent = 0);
113         virtual ~FFAbstractComboBox();
114
115         virtual void addItem(QVariant item) = 0;
116         virtual void removeItem(int index);
117         virtual void setCurrentItem(int index);
118
119         FFAbstractButton*        activator();
120         int                      cols();
121         QList<FFAbstractButton*> items();
122         QPen                     pen();
123         int                      spacing();
124
125         void setCols(int cols);
126         void setSpacing(int spacing);
127
128 protected:
129         FFAbstractButton* activator_; ///< activator shows actual combobox's value and activate popup window
130         QPen pen_; ///< contain actual pen
131         QList<FFAbstractButton*> items_; ///<list of items
132
133         void insertItem(FFAbstractButton* item, bool autoRecreate=true);
134         virtual void setActivatorSpecs(FFAbstractButton* item) = 0;
135         virtual QVariant activatorSpecs() = 0;
136
137 private:
138         QGridLayout*  mainLayout; ///< layout of combobox
139         FFComboPopUp* popUp; ///< popup window showing all items
140         int           cols_; ///< number of columns
141
142 private slots:
143
144
145 signals:
146         void reset();
147         void activated(QVariant spec);
148         void activated(int index);
149         void itemsChanged(FFAbstractButton* button);
150 };
151
152 /**
153  * @author ComArch S.A.
154  * @date 2009.10.09
155  * @version 1.0
156  *
157  * @brief A class is used by comboboxes to show all items
158  */
159 class FFComboPopUp : public QDialog
160 {
161         Q_OBJECT
162
163         friend class FFAbstractComboBox;
164
165 public:
166
167 protected:
168         void showEvent(QShowEvent* event);
169
170 private:
171         FFComboPopUp(QWidget* parent);
172         FFAbstractComboBox* parentCB; ///<pointer to parent widget
173
174         QGridLayout*      popUpLayout; ///< layout of popup window
175         FFScrollArea*     scrollArea; ///< scrolling widget
176         QWidget*          scrollAreaWidget; ///< widget inserted on ffscrollarea
177         QGridLayout*      scrollAreaLayout; ///< layout of scrolling widget
178         FFAbstractButton* backButton; ///< button which hide popup window
179
180 private slots:
181         void recreatePopUp();
182         void registerNewItem(FFAbstractButton* newItem);
183         void accept();
184
185 signals:
186         void selected(FFAbstractButton* selectedButton);
187
188 };
189
190 #endif // FFABSTRACTCOMBOBOX_H