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 ffscrollingbutton.h
76 * @brief Contains a necessary class declaration.
78 * @author ComArch S.A.
83 #include "ffscrollingbutton.h"
86 * Constructs a FFScrollingButton with a parent.
87 * Sets variable to initial values and set graphics used in widget.
89 FFScrollingButton::FFScrollingButton(QWidget* parent) :
90 FFAbstractButton(parent)
96 * Constructs a FFScrollingButton with a parent , title and description.
97 * Sets variable to initial values and sets graphics used in widget.
99 FFScrollingButton::FFScrollingButton(QString title, QString description, QWidget* parent) :
100 FFAbstractButton(parent)
103 title_->setText(title);
104 description_->setText(description);
109 * A virtual destructor.
111 FFScrollingButton::~FFScrollingButton()
117 * Initiates an object of FFScrollingButton. Sets all needed fields.
119 void FFScrollingButton::init()
122 title_ = new FFScrollingLabel(this);
123 title_->setResizable(true);
124 title_->setColor(FF_TITLE_COLOR);
127 //sets desciption's label
128 description_ = new FFScrollingLabel(this);
129 description_->setResizable(true);
130 description_->setColor(FF_DESCRIPTION_COLOR);
131 description_->show();
134 titleIndent_ = indent();
135 descriptionIndent_ = indent();
137 titleIndentTemp = indent();
138 descriptionIndentTemp = indent();
142 descriptionSwitch_ = true;
145 setTopMargin(DEFAULT_TOPBOTTOM_MARGIN);
146 setBottomMargin(DEFAULT_TOPBOTTOM_MARGIN);
149 ratio_ = DEFAULT_RATIO;
153 * Returns the text from FFScrollingLabel named title
155 QString FFScrollingButton::title() const
157 return title_->text();
161 * Returns alignment of title.
163 FFScrollingLabel::Alignment FFScrollingButton::titleAlignment() const
165 return titleWidget()->alignment();
169 * Returns title`s color.
171 QColor FFScrollingButton::titleColor() const
173 return title_->color();
177 * Returns title`s indent.
179 int FFScrollingButton::titleIndent() const
185 * Returns title`s font.
187 QFont FFScrollingButton::titleFont() const
189 return title_->font();
193 * Returns the text from FFScrollingLabel named description.
195 QString FFScrollingButton::description() const
197 return description_->text();
201 * Return alignment of description.
203 FFScrollingLabel::Alignment FFScrollingButton::descriptionAlignment() const
205 return descriptionWidget()->alignment();
209 * Return description`s color.
211 QColor FFScrollingButton::descriptionColor() const
213 return description_->color();
217 * Returns description`s indent.
219 int FFScrollingButton::descriptionIndent() const
221 return descriptionIndent_;
225 * Returns description`s font.
227 QFont FFScrollingButton::descriptionFont() const
229 return description_->font();
235 float FFScrollingButton::ratio() const
241 * Sets a text of the title.
242 * @param title Title text.
244 void FFScrollingButton::setTitle(const QString& title)
246 title_->setText(title);
251 * Sets a alignment of the title.
252 * @param alignment Title text.
254 void FFScrollingButton::setTitleAlignment(FFScrollingLabel::Alignment alignment)
256 titleWidget()->setAlignment(alignment);
261 * Sets a color of text on title.
262 * @param color Color of title.
264 void FFScrollingButton::setTitleColor(QColor color)
266 title_->setColor(color);
271 * Sets a font that will be used to print the text of the title.
272 * @param font Font style.
274 void FFScrollingButton::setTitleFont(QFont font)
276 title_->setFont(font);
281 * Sets Indent of title.
282 * @param indent Indent of title.
284 void FFScrollingButton::setTitleIndent(int indent)
286 titleIndent_ = indent;
287 titleIndentTemp = indent;
292 * Sets a text of the description.
293 * @param text Description text
295 void FFScrollingButton::setDescription(const QString& text)
297 description_->setText(text);
302 * Sets a alignment of the title.
303 * @param alignment Title text.
305 void FFScrollingButton::setDescriptionAlignment(FFScrollingLabel::Alignment alignment)
307 descriptionWidget()->setAlignment(alignment);
312 * Sets a color of text on description.
313 * @param color Color of description.
315 void FFScrollingButton::setDescriptionColor(QColor color)
317 description_->setColor(color);
322 * Sets a font that will be used to print the text of the description.
323 * @param font Font style.
325 void FFScrollingButton::setDescriptionFont(QFont font)
327 description_->setFont(font);
332 * Sets Indent of description.
333 * @param indent Indent of description.
335 void FFScrollingButton::setDescriptionIndent(int indent)
337 descriptionIndent_ = indent;
338 descriptionIndentTemp = indent;
344 * @param ratio Ratio between size of title and description.
346 void FFScrollingButton::setRatio(float ratio)
348 if(ratio >= 0.05 && ratio <= 0.95)
352 else if(ratio < 0.05)
365 * Disables title. Show/hide title.
366 * @param state State true/false to set visible of description.
368 void FFScrollingButton::disableTitle(bool state)
370 titleSwitch_ = !state;
371 title_->setVisible(titleSwitch_);
376 * Disables description. Show/hide description.
377 * @param state State true/false to set visible of description.
379 void FFScrollingButton::disableDescription(bool state)
381 descriptionSwitch_ = !state;
382 description_->setVisible(descriptionSwitch_);
387 * Returns state of title visibility. If returned value is true visibility is on.
389 bool FFScrollingButton::isDisabledTitle()
395 * Returns state of description visibility. If returned value is true visibility is on.
397 bool FFScrollingButton::isDisabledDescription()
399 return descriptionSwitch_;
403 * Repaints the view of button. Overrides the virtual method from QWidget.
404 * @param event Contains all informations about event.
406 void FFScrollingButton::paintEvent(QPaintEvent* event)
408 FFAbstractButton::paintEvent(event);
412 * Updates button`s view after changing size of the widget.
413 * Updates size of all pixmaps which need it (without corners)
414 * @param event Contains all informations about event.
416 void FFScrollingButton::resizeEvent(QResizeEvent* event)
418 FFAbstractButton::resizeEvent(event);
424 * Support mouse press event.
425 * @param event Contains all informations about event.
427 void FFScrollingButton::mousePressEvent(QMouseEvent* event)
429 FFAbstractButton::mousePressEvent(event);
433 * Support mouse release event.
434 * @param event Contains all informations about event.
436 void FFScrollingButton::mouseReleaseEvent(QMouseEvent* event)
438 FFAbstractButton::mouseReleaseEvent(event);
442 * Paints icon if it was set.
443 * @param painter is a tool to paint icon on widget.
445 void FFScrollingButton::paintIcon(QPainter* painter)
448 if(iconAlignment_ == Qt::AlignLeft)
454 move = -titleIndent_;
457 // if icon was set paint it
459 if (!icon().isNull())
461 QRect rect(0+leftMargin() + move,
463 geometry().width()-rightMargin()-leftMargin() ,
464 geometry().height()-bottomMargin()-topMargin());
466 //paint icon in button center
467 icon().paint(painter,rect,iconAlignment_,QIcon::Normal, QIcon::Off);
472 * Returns pointer to title FFScrolingLabel.
474 FFScrollingLabel* FFScrollingButton::titleWidget() const
480 * Returns pointer to description FFScrolingLabel.
482 FFScrollingLabel* FFScrollingButton::descriptionWidget() const
488 * Changes tRatio - title ratio and dRatio - description ratio to show/not show title/description.
490 void FFScrollingButton::calculateRatio()
492 if(titleSwitch_ && descriptionSwitch_) // show title and description
495 dRatio = 1.0 - ratio_;
497 else if(!titleSwitch_ && descriptionSwitch_) // show only description
502 else if(titleSwitch_ && !descriptionSwitch_) // show only title
510 * Scales title and description indent. When resize event appears and calls out scaleIndent it changes indents to fit to new size.
511 * @param oldSize Old size of widget.
512 * @param newSize New size of widget.
514 void FFScrollingButton::scaleIndent(QSize oldSize, QSize newSize)
516 float widthProportion = (float)newSize.width() / (float)oldSize.width();
518 titleIndentTemp *= widthProportion;
519 descriptionIndentTemp *= widthProportion;
521 titleIndent_ = titleIndentTemp;
522 descriptionIndent_ = descriptionIndentTemp;
526 * Recalculates geometry of labels (indent, margins etc.)
528 void FFScrollingButton::updateView()
531 int margins = topMargin() + bottomMargin() + hSpacing();
538 w = width() - 2 * descriptionIndent_ - leftMargin() - rightMargin() - iconSpace;
539 //values depend from alignment
540 if(iconAlignment() == Qt::AlignLeft)
542 xT = leftMargin() + titleIndent_ + iconSpace;
543 xD = leftMargin() + descriptionIndent_ + iconSpace;
548 xT = leftMargin() + titleIndent_;
549 xD = leftMargin() + descriptionIndent_;
551 //sets geometry of labels with texts
552 title_->setGeometry(xT,
555 (height() - margins) * tRatio);
557 description_->setGeometry(xD,
558 topMargin() + title_->size().height() + hSpacing(),
560 (height() - margins) * dRatio);
563 FFAbstractButton::updateView();
566 * Sets icon's alignment
568 void FFScrollingButton::setIconAlignment(Qt::Alignment iconAlignment)
570 switch(iconAlignment)
574 FFAbstractButton::setIconAlignment(iconAlignment);
577 qDebug() << "You can only use Qt::AlignLeft or Qt::AlignRight";
581 // ####################################################### PRIVATE