2 GNU GENERAL PUBLIC LICENSE
\r
3 Version 3, 29 June 2007
\r
5 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
\r
6 Everyone is permitted to copy and distribute verbatim copies
\r
7 of this license document, but changing it is not allowed.
\r
11 The GNU General Public License is a free, copyleft license for
\r
12 software and other kinds of works.
\r
14 The licenses for most software and other practical works are designed
\r
15 to take away your freedom to share and change the works. By contrast,
\r
16 the GNU General Public License is intended to guarantee your freedom to
\r
17 share and change all versions of a program--to make sure it remains free
\r
18 software for all its users. We, the Free Software Foundation, use the
\r
19 GNU General Public License for most of our software; it applies also to
\r
20 any other work released this way by its authors. You can apply it to
\r
23 When we speak of free software, we are referring to freedom, not
\r
24 price. Our General Public Licenses are designed to make sure that you
\r
25 have the freedom to distribute copies of free software (and charge for
\r
26 them if you wish), that you receive source code or can get it if you
\r
27 want it, that you can change the software or use pieces of it in new
\r
28 free programs, and that you know you can do these things.
\r
30 To protect your rights, we need to prevent others from denying you
\r
31 these rights or asking you to surrender the rights. Therefore, you have
\r
32 certain responsibilities if you distribute copies of the software, or if
\r
33 you modify it: responsibilities to respect the freedom of others.
\r
35 For example, if you distribute copies of such a program, whether
\r
36 gratis or for a fee, you must pass on to the recipients the same
\r
37 freedoms that you received. You must make sure that they, too, receive
\r
38 or can get the source code. And you must show them these terms so they
\r
41 Developers that use the GNU GPL protect your rights with two steps:
\r
42 (1) assert copyright on the software, and (2) offer you this License
\r
43 giving you legal permission to copy, distribute and/or modify it.
\r
45 For the developers' and authors' protection, the GPL clearly explains
\r
46 that there is no warranty for this free software. For both users' and
\r
47 authors' sake, the GPL requires that modified versions be marked as
\r
48 changed, so that their problems will not be attributed erroneously to
\r
49 authors of previous versions.
\r
51 Some devices are designed to deny users access to install or run
\r
52 modified versions of the software inside them, although the manufacturer
\r
53 can do so. This is fundamentally incompatible with the aim of
\r
54 protecting users' freedom to change the software. The systematic
\r
55 pattern of such abuse occurs in the area of products for individuals to
\r
56 use, which is precisely where it is most unacceptable. Therefore, we
\r
57 have designed this version of the GPL to prohibit the practice for those
\r
58 products. If such problems arise substantially in other domains, we
\r
59 stand ready to extend this provision to those domains in future versions
\r
60 of the GPL, as needed to protect the freedom of users.
\r
62 Finally, every program is threatened constantly by software patents.
\r
63 States should not allow patents to restrict development and use of
\r
64 software on general-purpose computers, but in those that do, we wish to
\r
65 avoid the special danger that patents applied to a free program could
\r
66 make it effectively proprietary. To prevent this, the GPL assures that
\r
67 patents cannot be used to render the program non-free.
\r
69 The precise terms and conditions for copying, distribution and
\r
70 modification follow.
\r
72 http://www.gnu.org/licenses/gpl-3.0.txt
\r
75 * @file ffscrollarea.cpp
\r
76 * @brief Implementation of the FFScrollArea class
\r
78 * @author ComArch S.A.
\r
83 #include "ffscrollarea.h"
\r
86 #include <QScrollBar>
\r
89 //defines view of scrollbars
\r
90 #define SCROLLBAR_STYLE " \
\r
91 QScrollBar:vertical, QScrollBar:horizontal { \
\r
92 border: 0px solid transparent; \
\r
93 background: transparent; \
\r
95 height: 5px; /* change this to 5px or more to see horizontal scrollbar */\
\r
96 margin: 2px 2px 2px 2px; \
\r
98 QScrollBar::sub-page, QScrollBar::add-page { \
\r
99 background: rgb(45,45,45); \
\r
101 QScrollBar::handle:vertical { \
\r
102 background: qlineargradient(x1:0, y1:0, x2:0, y2:1, \
\r
103 stop:0 rgba(30,30,30,0), stop: 0.1 #1d1, stop:0.9 #2e2, stop: 1 rgba(30,30,30,0)); \
\r
104 min-height: 25px; \
\r
106 QScrollBar::handle:horizontal { \
\r
107 background: qlineargradient(x1:0, y1:0, x2:1, y2:0, \
\r
108 stop:0 rgba(30,30,30,0), stop: 0.1 #1d1, stop:0.9 #2e2, stop: 1 rgba(30,30,30,0)); \
\r
111 QScrollBar::add-line, QScrollBar::sub-line { \
\r
112 border: 0px solid transparent; \
\r
115 background-color: #222; color: #ddd; \
\r
120 * Constructs FFScrollArea with parent
\r
122 FFScrollArea::FFScrollArea(QWidget* parent) :
\r
123 QScrollArea(parent)
\r
128 * A virtual destructor
\r
130 FFScrollArea::~FFScrollArea()
\r
135 * Initiates FFScrollArea class. Sets all needed fields, connections and calls.
\r
136 * It is called by the constructor.
\r
138 void FFScrollArea::init()
\r
140 //sets FFScrollArea view properties
\r
141 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
\r
142 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
\r
143 this->setFrameStyle(0);
\r
144 setStyleSheet(SCROLLBAR_STYLE);
\r
145 setStyleSheet("background-color: transparent");
\r
146 //initiates all fields with default values
\r
150 oldPos = QPointF(0, 0);
\r
151 prevPos = QPointF(0, 0);
\r
152 pos = QPointF(0, 0);
\r
153 speed = QPointF(0, 0);
\r
154 movement = QPointF(0, 0);
\r
159 slowingDownRate_ = DEFAULT_SLOWING_DOWN_RATE;
\r
160 postionSumplingTime_ = DEFAULT_POSIOTION_SUMPLING_TIME;
\r
161 kineticAnimationTime_ = DEFAULT_KINETIC_ANIMATION_TIME;
\r
162 minMotionLength_ = DEFAULT_MIN_MOTION_LENGTH;
\r
167 //connects signals and slots
\r
168 connect(&timerPos, SIGNAL(timeout()), this, SLOT(updatePos()));
\r
169 connect(&timerAnim, SIGNAL(timeout()), this, SLOT(animation()));
\r
173 * Method using to serve events. Overrides the virtual method from parent.
\r
175 * @param object is a pointer handled object
\r
176 * @param ev is a pointer to handled event
\r
179 bool FFScrollArea::eventFilter(QObject* object, QEvent* ev)
\r
181 //Does nothing when QEvent type is Paint
\r
182 if(ev->type() == QEvent::Paint)
\r
185 if(QMouseEvent* event = dynamic_cast<QMouseEvent*>(ev))
\r
187 //Serves MouseButtonPressEvent
\r
188 if(event->type() == QEvent::MouseButtonPress)
\r
192 movement = QPointF(0, 0);
\r
196 //sets started values after each press event
\r
197 x = event->globalX();
\r
198 y = event->globalY();
\r
199 prevPos = event->globalPos();
\r
200 oldPos = event->globalPos();
\r
201 speed = QPointF(0.0, 0.0);
\r
202 pos = QPointF(0.0, 0.0);
\r
204 //starts position sampling timer
\r
205 timerPos.start(postionSumplingTime_);
\r
213 //Serves MouseMoveEvent
\r
214 if(event->type() == QEvent::MouseMove)
\r
217 //sets and calculates motion parameters
\r
218 int offsetY = event->globalY() - y;
\r
219 int offsetX = event->globalX() - x;
\r
221 int valY = this->verticalScrollBar()->value() - offsetY;
\r
222 int valX = this->horizontalScrollBar()->value()
\r
225 y = event->globalY();
\r
226 x = event->globalX();
\r
228 //If motion length is shorter then minMotionLength_
\r
229 //scrollbars postion will be not set.
\r
230 if(minMotionLength_ < qAbs(movement.y())
\r
231 || minMotionLength_
\r
232 < qAbs(movement.x()))
\r
234 //sets new scrollBars' values
\r
235 this->verticalScrollBar()->setValue(valY);
\r
236 this->horizontalScrollBar()->setValue(valX);
\r
241 //Updates parameters
\r
242 movement.setY(movement.y() + qAbs(prevPos.y()
\r
243 - event->globalY()));
\r
244 movement.setX(movement.x() + qAbs(prevPos.x()
\r
245 - event->globalX()));
\r
247 prevPos = event->globalPos();
\r
249 //Serves MouseButtonReleaseEvent
\r
250 if(event->type() == QEvent::MouseButtonRelease)
\r
252 //Stops position's sampling
\r
258 object->blockSignals(true);
\r
259 object->event(event);
\r
260 object->blockSignals(false);
\r
262 //sets cursor position after
\r
263 //MouseButtonReleaseEvent
\r
264 pos.setY((float)(this->verticalScrollBar()->value()));
\r
265 pos.setX((float)(this->horizontalScrollBar()->value()));
\r
268 timerAnim.start(kineticAnimationTime_);
\r
278 //calls parent's event filter
\r
279 return QScrollArea::eventFilter(object, ev);
\r
283 * Sets widget on FFScrollArea
\r
284 * Overrides the virtual method from parent.
\r
286 * @param widget pointer to setting widget
\r
289 void FFScrollArea::setWidget(QWidget* widget)
\r
291 //calls parent method
\r
292 ((QScrollArea*)this)->setWidget(widget);
\r
293 //calls method to install EventFilter
\r
294 installFilterRecursive(widget);
\r
297 * Installs eventFilter to each widget on FFScrollArea
\r
299 * @param wdg pointer to widget to which eventFilter is installing.
\r
301 void FFScrollArea::installFilterRecursive(QWidget* wdg)
\r
305 //Installs eventFilter to current widget
\r
306 wdg->installEventFilter(this);
\r
308 //Calls installFilterRecursive to all children
\r
309 const QList<QObject*> widgets = wdg->children();
\r
310 for(int i = 0; i < widgets.length(); ++i)
\r
312 QWidget* wdg = dynamic_cast<QWidget*> (widgets.at(i));
\r
314 installFilterRecursive(wdg);
\r
318 * Updates motion's speed and cursor's position
\r
320 void FFScrollArea::updatePos()
\r
322 //sets motion's speed
\r
323 speed.setY(oldPos.y() - this->cursor().pos().y());
\r
324 speed.setX(oldPos.x() - this->cursor().pos().x());
\r
325 //sets current cursor's position
\r
326 oldPos = this->cursor().pos();
\r
331 * Method responsible for kinetic's animation.
\r
334 void FFScrollArea::animation()
\r
336 //If speed is less then 1 animations is stopped
\r
337 if(1 < qAbs(speed.x()) || 1 < qAbs(speed.y()))
\r
340 pos.setY(pos.y() + speed.y());
\r
341 pos.setX(pos.x() + speed.x());
\r
343 //sets new position on scrollbars
\r
344 this->verticalScrollBar()->setValue((int)pos.y());
\r
345 this->horizontalScrollBar()->setValue((int)pos.x());
\r
348 speed.setY(speed.y() * slowingDownRate_);
\r
349 speed.setX(speed.x() * slowingDownRate_);
\r
359 * Returns rate responsible for kinetic speed slowing
\r
361 float FFScrollArea::getSlowingDownRate() const
\r
363 return slowingDownRate_;
\r
366 * Sets rate responsible for kinetic speed slowing
\r
368 void FFScrollArea::setSlowingDownRate(float slowingDownRate_)
\r
370 this->slowingDownRate_ = slowingDownRate_;
\r
374 * Returns kinetic animation frame time in ms.
\r
376 int FFScrollArea::getKineticAnimationTime() const
\r
378 return kineticAnimationTime_;
\r
382 * Sets kinetic animation frame time in ms.
\r
384 void FFScrollArea::setKineticAnimationTime(int kineticAnimationTime_)
\r
386 this->kineticAnimationTime_ = kineticAnimationTime_;
\r
390 * Returns cursor position sampling time in ms.
\r
392 int FFScrollArea::getPostionSumplingTime() const
\r
394 return postionSumplingTime_;
\r
398 * Sets cursor position sampling time in ms.
\r
400 void FFScrollArea::setPostionSumplingTime(int postionSumplingTime_)
\r
402 this->postionSumplingTime_ = postionSumplingTime_;
\r
406 * Sets value needed to blocking signals
\r
409 void FFScrollArea::setMinMotionLength(int minMotionLength_)
\r
411 this->minMotionLength_ = minMotionLength_;
\r
415 * Returns value needed to blocking signals
\r
417 int FFScrollArea::getMinMotionLength() const
\r
419 return minMotionLength_;
\r