added all files
[ffqwlibrary] / libffqw-n810-1.0 / sources / ffscrollinglabel.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 ffscrollinglabel.h
76  * @brief Contains a necessary class declaration.
77  *
78  * @author ComArch S.A.
79  * @date 2009.08.07
80  * @version 1.1
81  *
82  * @brief A label with scrolling text.
83  */
84
85 #ifndef FFSCROLLINGLABEL_H
86 #define FFSCROLLINGLABEL_H
87
88 #include <QtGui/QWidget>
89 #include <QPainter>
90 #include <QPushButton>
91 #include <QDebug>
92 #include <QTimer>
93 #include <QResizeEvent>
94 #include <QBitmap>
95 #include <QHideEvent>
96 #include <QShowEvent>
97
98 #ifndef MAEMO
99 #include <QtDesigner/QDesignerExportWidget>
100 #endif
101
102 #include "ffabstractwidget.h"
103 #include "ffviewcache.h"
104
105 const int TIMER_DELAY = 200; ///< delay for timer responsible for scrolling
106 const QString DEFAULT_TEXT = "Default text"; ///< text printed on a label as default
107 const int DEFAULT_SCROLL_SPEED = 10; ///< number of pixels which defines step of scrolling
108 const int DEFAULT_END_SCROLL_DELAY = 10; ///< number of gaps when one of label's edge is visible
109 const int LABEL_SIZE_TINY = 6; ///< defines size of tiny label's  font
110 const int LABEL_SIZE_SMALL = 10; ///< defines size of small label's font
111 const int LABEL_SIZE_NORMAL = 12; ///< defines size of normal label's font
112 const int LABEL_SIZE_LARGE = 16; ///< defines size of large label's font
113 const int LABEL_SIZE_HUGE = 24; ///< defines size of huge label's font
114
115 /**
116  * @author ComArch S.A.
117  * @date 2009.08.07
118  * @version 1.1
119  *
120  * @brief A label with scrolling text.
121  */
122 #ifdef MAEMO
123
124 class FFScrollingLabel : public FFAbstractWidget
125 {
126         Q_OBJECT
127
128 #else
129
130 class QDESIGNER_WIDGET_EXPORT FFScrollingLabel : public FFAbstractWidget
131 {
132         Q_OBJECT
133         Q_ENUMS(Alignment)
134         Q_PROPERTY(QFont font READ font WRITE setFont)
135         Q_PROPERTY(QString text READ text WRITE setText)
136         Q_PROPERTY(bool resizable READ isResizable WRITE setResizable)
137         Q_PROPERTY(int scrollSpeed READ scrollSpeed WRITE setScrollSpeed)
138         Q_PROPERTY(int endScrollDelay READ endScrollDelay WRITE setEndScrollDelay)
139         Q_PROPERTY(QColor color READ color WRITE setColor)
140         Q_PROPERTY(bool fitToFont READ fitToFont WRITE setFitToFont)
141         Q_PROPERTY(bool smoothDisappear READ isSmoothDisappear WRITE setSmoothDisappear)
142         Q_PROPERTY(int timerDelay READ timerDelay WRITE setTimerDelay)
143         Q_PROPERTY(FFScrollingLabel::Alignment alignment READ alignment WRITE setAlignment)
144
145 #endif
146 public:
147         FFScrollingLabel(QWidget* parent = 0);
148         FFScrollingLabel(QString text, QWidget *parent = 0);
149         FFScrollingLabel(QString text, QFont font, QWidget* parent = 0);
150         virtual ~FFScrollingLabel();
151
152         enum Alignment
153         {
154                 ALIGNMENT_LEFT = 0x2000, ///< label alignment to left
155                 ALIGNMENT_RIGHT = 0x4000, ///< label alignment to right
156                 ALIGNMENT_CENTER = 0x8000 ///< label alignment to center
157         };
158
159         QFont     font() const;
160         QString   text() const;
161         bool      isResizable() const;
162         int       scrollSpeed() const;
163         int       endScrollDelay() const;
164         QColor    color() const;
165         bool      fitToFont() const;
166         bool      isSmoothDisappear() const;
167         int       timerDelay();
168         FFScrollingLabel::Alignment alignment();
169
170         void setFont(QFont font);
171         void setFont(int fontParam);
172         void setText(QString text);
173         void setResizable(bool resizable);
174         void setScrollSpeed(int scrollSpeed);
175         void setEndScrollDelay(int endScrollDelay);
176         void setColor(QColor color);
177         void setFitToFont(bool fitToFont);
178         void setScrollType(int type);
179         void setSmoothDisappear(bool smoothDisappear);
180         void setTimerDelay(int delay);
181         void setAlignment(FFScrollingLabel::Alignment alignment);
182
183         void updateView();
184
185 protected:
186         virtual void  paintEvent(QPaintEvent *event);
187         virtual void  resizeEvent(QResizeEvent *event);
188         virtual QSize sizeHint() const;
189         virtual void  hideEvent(QHideEvent* event);
190         virtual void  showEvent(QShowEvent* event);
191
192 private:
193         QPainter*       painter; ///< pointer to painter
194         QLinearGradient gradient; ///< stores gradient for label
195         QPen            pen; ///< stores pen where gradient is set
196         QString         text_; ///< stores text of label
197         QFont           font_; ///< stores font of text
198         QTimer*         timer; ///< timer used to animation
199         bool            resizable_; ///< is true when font size should change with widget's size changes.
200         QColor          color_; ///< stores color used to create gradient
201
202         int       length_; ///< length of the text
203         int       textOffset; ///< text's offset
204         int       scrollSpeed_; ///< scoll's speed
205         int       endScrollDelay_; ///< gap during one of edges is visible
206         int       endScrollDelayIterationL; ///< contains value how many times text is in stopped state on left
207         int       endScrollDelayIterationR; ///< contains value how many times text is in stopped state on right
208         bool      fitToFont_; ///< if is true the widgets height is adjusted to font size
209         QString   previousScrollType; ///< stores scrolling type
210         bool      smoothDisappear_; ///< is true when the gradient at ends is set up
211         int       timerDelay_; ///< defines how often text is repainted
212         Alignment alignment_; ///< stores text's alignment
213         int       textStartPos; ///< contains start text's posiotion
214
215         void        init(QString text, QFont font);
216         void        calcTextPos();
217         inline void changeGradient(qreal left, qreal right);
218
219 private slots:
220         void scrollSideToSide();
221 };
222
223 #endif // FFSCROLLINGLABEL_H