2 GNU GENERAL PUBLIC LICENSE
3 Version 3, 29 June 2007
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.
11 The GNU General Public License is a free, copyleft license for
12 software and other kinds of works.
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
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.
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.
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
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.
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.
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.
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.
69 The precise terms and conditions for copying, distribution and
72 http://www.gnu.org/licenses/gpl-3.0.txt
75 * @file ffabstractcombobox.cpp
76 * @brief Implementation of the FFAbstractComboBox and FFComboPopUp class.
78 * @author ComArch S.A.
82 * This widget has activator(to open popup window) and popup window(to select item)
83 * FFAbstractComboBox and FFComboPopUp are friend classes in both directions
86 #include "ffabstractcombobox.h"
90 * @param var is an argument to round up
91 * @return value of rounded up argument
94 float roundUp(float var)
96 if(0 > ((int)var - var ))
107 * Constructs a FFAbstractButton with a parent.
108 * Sets variable to initial values.
110 FFAbstractComboBox::FFAbstractComboBox(FFAbstractButton* activator, QWidget* parent):
116 activator_ = activator;
117 activator_->setObjectName("Activator");
119 //sets layout of combobx
120 mainLayout = new QGridLayout();
121 mainLayout->setMargin(0);
122 mainLayout->setSpacing(0);
123 mainLayout->addWidget(activator_);
124 setLayout(mainLayout);
127 popUp = new FFComboPopUp(this);
128 popUp->setWindowFlags(Qt::SplashScreen);
129 popUp->setGeometry(QApplication::desktop()->geometry());
131 popUp->setWindowModality(Qt::WindowModal);
133 setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
136 connect(activator_, SIGNAL(clicked()), popUp, SLOT(exec()));
137 connect(this, SIGNAL(reset()),popUp,SLOT(recreatePopUp()));
138 connect(this, SIGNAL(itemsChanged(FFAbstractButton*)),popUp,SLOT(registerNewItem(FFAbstractButton*)));
141 * A virtual destructor of FFAbstractButton.
143 FFAbstractComboBox::~FFAbstractComboBox()
149 * Removes item from combobox
150 * @param index is a index of item
152 void FFAbstractComboBox::removeItem(int index)
154 if(items_.size()>index)
156 disconnect(items_.at(index));
157 delete items_.takeAt(index);
162 * Calls setActivatorSpecs and emits signals activated(QVariant),activated(int)
163 * @param index is a index of item
165 void FFAbstractComboBox::setCurrentItem(int index)
167 if(items_.size()>index)
169 setActivatorSpecs(items_.at(index));
170 if(!signalsBlocked())
172 emit activated(activatorSpecs());
173 emit activated(index);
178 * Returns pointer to activator
180 FFAbstractButton* FFAbstractComboBox::activator()
185 * Returns number of columns
187 int FFAbstractComboBox::cols()
192 * Returns list of items
194 QList<FFAbstractButton*> FFAbstractComboBox::items()
199 * Returns popup's layout spacing
201 int FFAbstractComboBox::spacing()
203 return popUp->scrollAreaLayout->spacing();
206 * Sets columns number
207 * @param cols a number of columns
209 void FFAbstractComboBox::setCols(int cols)
215 * Sets popup's layout spacing
216 * @param spacing a size of spacing
218 void FFAbstractComboBox::setSpacing(int spacing)
220 popUp->scrollAreaLayout->setSpacing(spacing);
224 * Adds item to combobox
225 * @param item a pointer to adding item
226 * @param autoRecreate defines if layout should be recreated automatically
228 void FFAbstractComboBox::insertItem(FFAbstractButton* item, bool autoRecreate)
231 emit itemsChanged(item);
240 * Constructs a FFComboPopUp with a parent.
241 * Sets variable to initial values.
243 FFComboPopUp::FFComboPopUp(QWidget* parent) : QDialog(parent)
246 parentCB = dynamic_cast<FFAbstractComboBox*>(parent);
247 //sets popup window's layout
248 popUpLayout = new QGridLayout();
249 popUpLayout->setMargin(0);
250 popUpLayout->setSpacing(0);
252 //sets scrollarea and scrollarea's widget
253 scrollArea = new FFScrollArea();
254 scrollArea->setWidgetResizable(true);
256 popUpLayout->addWidget(scrollArea,0,0);
257 setLayout(popUpLayout);
259 scrollAreaLayout = new QGridLayout();
260 scrollAreaLayout->setSpacing(5);
261 scrollAreaLayout->setMargin(0);
263 scrollAreaWidget = new QWidget();
264 scrollAreaWidget->setStyleSheet("background-color:black;");
266 scrollAreaWidget->setLayout(scrollAreaLayout);
267 scrollArea->setWidget(scrollAreaWidget);
270 backButton = new FFAbstractButton;
271 backButton->setMargins(0,0,5,5);
272 backButton->setIconAlignment(Qt::AlignRight);
273 backButton->setIcon(QIcon(QPixmap(":/standard/combo_colorarrow.svg")));
274 scrollAreaLayout->addWidget(backButton,0,0,1,parentCB->cols_);
277 connect(backButton,SIGNAL(clicked()),this,SLOT(reject()));
280 * Serves show event. Override method from mother class.
282 void FFComboPopUp::showEvent(QShowEvent* event)
284 // The calculation of the size of the window so that it occupied little space as possible.
289 for(int i=0; i<roundUp((float)parentCB->items_.size()/(float)parentCB->cols_); ++i)
291 // height of an element
292 itemsHeight += parentCB->items_.at(i)->minimumHeight();
294 //height of an spacing
295 itemsHeight += scrollAreaLayout->spacing();
297 itemsHeight += backButton->minimumHeight();
299 if(itemsHeight > QApplication::desktop()->geometry().height())
300 itemsHeight = QApplication::desktop()->geometry().height();
302 setGeometry(0,0,QApplication::desktop()->geometry().width(),itemsHeight);
304 QDialog::showEvent(event);
308 * Refreshes popup layout at view event
310 void FFComboPopUp::recreatePopUp()
312 // Deleting old objects
314 while((child = scrollAreaLayout->takeAt(0)) != 0)
319 // Arranging objects on the popup
320 scrollAreaLayout->addWidget(backButton,0,0,1,parentCB->cols_);
321 for(int i=0, cols=0, rows=1; i<parentCB->items_.size();++i,++cols)
323 if(cols==parentCB->cols_)
327 cols%=parentCB->cols_;
328 scrollAreaLayout->addWidget(parentCB->items_.at(i),rows,cols);
331 // Force refresh FFScrollArea (this line exist because FFScrollArea have a little imperfection - event filter problem)
332 scrollArea->setWidget(scrollAreaWidget);
335 * Connects new item signal clicked to actual widget's slot accept
337 void FFComboPopUp::registerNewItem(FFAbstractButton* newItem)
339 connect(newItem,SIGNAL(clicked()),this,SLOT(accept()));
342 * Calls setCurrentItem with widget index
344 void FFComboPopUp::accept()
346 parentCB->setCurrentItem(scrollAreaLayout->indexOf(dynamic_cast<QWidget*>(sender()))-1);
351 \fn void FFAbstractComboBox::reset()
352 *This signal is emitted when is necessary to refresh layout of popup window.
356 \fn void FFAbstractComboBox::activated(QVariant spec)
357 *This signal is emitted when option on combobox was chosen.
358 *@param spec contains specific chosen value
362 \fn void FFAbstractComboBox::activated(int index)
363 *This signal is emitted when option on combobox was chosen.
364 *@param index contains index of chosen item
369 \fn void FFComboPopUp::selected(FFAbstractButton* selectedButton)
370 *This signal is emitted when item was selected
371 *@param selectedButton pointer to selected item