##// END OF EJS Templates
Doc: Use a standard documentation config for a Qt module...
Doc: Use a standard documentation config for a Qt module - Rename index.html to qtcharts-index.html - Use the qt-module-defaults global doc template - Convert 'indexes' into 'depends' - Remove custom buildversion string - Remove Q_INVOKABLE as ignore token, it's already listed in the global config - Use a namespace consistent with the rest of Qt modules - Update examplesinstallpath to the changes introduced in Qt 5.6 packaging. - Remove unnecessary \keyword on the landing page, as it may conflict with other modules' docs. Change-Id: I5cc0ff026b02bae22a415d82e36cb945bd19ae53 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>

File last commit:

r2854:46147b040d06
r2862:b8bfb31b9099
Show More
scroller.cpp
225 lines | 5.7 KiB | text/x-c | CppLexer
Miikka Heikkinen
Updated license...
r2854 /****************************************************************************
Michal Klocek
Refactor qledgend handling...
r855 **
Miikka Heikkinen
Updated license...
r2854 ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Michal Klocek
Refactor qledgend handling...
r855 **
Miikka Heikkinen
Updated license...
r2854 ** This file is part of the Qt Charts module of the Qt Toolkit.
Michal Klocek
Refactor qledgend handling...
r855 **
Miikka Heikkinen
Updated license...
r2854 ** $QT_BEGIN_LICENSE:GPL$
Titta Heikkala
Updated license headers...
r2845 ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
Miikka Heikkinen
Updated license...
r2854 ** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
Michal Klocek
Refactor qledgend handling...
r855 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_END_LICENSE$
**
Miikka Heikkinen
Updated license...
r2854 ****************************************************************************/
Michal Klocek
Refactor qledgend handling...
r855
Titta Heikkala
Fix include syntax...
r2714 #include <private/scroller_p.h>
#include <QtCharts/QLegend>
#include <QtWidgets/QGraphicsSceneMouseEvent>
#include <QtCore/QDebug>
Michal Klocek
Refactor qledgend handling...
r855
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_BEGIN_NAMESPACE
Michal Klocek
Refactor qledgend handling...
r855
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 Scroller::Scroller()
: m_ticker(this),
sauimone
Kinetic scrolling is back for legend
r2189 m_timeTresholdMin(50),
m_timeTresholdMax(300),
sauimone
moving mouse event handling logic to scroller
r2199 m_state(Idle),
m_treshold(10)
Michal Klocek
Refactor qledgend handling...
r855 {
}
Scroller::~Scroller()
{
}
sauimone
Kinetic scrolling is back for legend
r2189 void Scroller::move(const QPointF &delta)
Michal Klocek
Refactor qledgend handling...
r855 {
switch (m_state) {
sauimone
moving mouse event handling logic to scroller
r2199 case Pressed:
sauimone
Kinetic scrolling is back for legend
r2189 m_timeStamp = QTime::currentTime();
break;
Michal Klocek
Refactor qledgend handling...
r855 case Scroll:
sauimone
Kinetic scrolling is back for legend
r2189 stopTicker();
m_timeStamp = QTime::currentTime();
break;
default:
Michal Klocek
Refactor qledgend handling...
r855 break;
}
sauimone
Kinetic scrolling is back for legend
r2189 setOffset(offset() - delta);
Michal Klocek
Refactor qledgend handling...
r855 }
sauimone
better implementation of mouse event handling in legend
r2197 void Scroller::scrollTo(const QPointF &delta)
Michal Klocek
Refactor qledgend handling...
r855 {
sauimone
Kinetic scrolling is back for legend
r2189 // Starts scrolling, if at least m_timeTresholdMin msecs has gone since timestamp
// current time is no more than m_timeTresholdMax from timestamp
Michal Klocek
Refactor qledgend handling...
r855
sauimone
Kinetic scrolling is back for legend
r2189 if ((m_timeStamp.elapsed() > m_timeTresholdMin) && (m_timeStamp.msecsTo(QTime::currentTime()) < m_timeTresholdMax)) {
// Release was quick enough. Start scrolling.
sauimone
accurate speed calculation to kinetic scrolling
r2190 qreal interval = 25;
qreal time = m_timeStamp.msecsTo(QTime::currentTime());
Marek Rosa
Replaced qFuzzyIsNull with qFuzzyCompare. Once qchart test case still uses qFuzzyIsNull becasue it started failing when qFuzzyCompare was used
r2242 if (qFuzzyCompare(time, 0)) {
sauimone
accurate speed calculation to kinetic scrolling
r2190 m_speed = delta / 5;
sauimone
minor code style fix
r2191 } else {
sauimone
accurate speed calculation to kinetic scrolling
r2190 m_speed = delta * interval / time;
sauimone
minor code style fix
r2191 }
Michal Klocek
Refactor qledgend handling...
r855
sauimone
Kinetic scrolling is back for legend
r2189 qreal fraction = qMax(qAbs(m_speed.x()), qAbs(m_speed.y()));
Marek Rosa
Replaced qFuzzyIsNull with qFuzzyCompare. Once qchart test case still uses qFuzzyIsNull becasue it started failing when qFuzzyCompare was used
r2242 if (!qFuzzyCompare(fraction, 0)) {
sauimone
Kinetic scrolling is back for legend
r2189 m_fraction.setX(qAbs(m_speed.x() / fraction));
m_fraction.setY(qAbs(m_speed.y() / fraction));
} else {
m_fraction.setX(1);
m_fraction.setY(1);
Michal Klocek
Refactor qledgend handling...
r855 }
sauimone
accurate speed calculation to kinetic scrolling
r2190 startTicker(interval);
sauimone
Kinetic scrolling is back for legend
r2189 } else {
stopTicker(); // Stop ticker, if one is running.
Michal Klocek
Refactor qledgend handling...
r855 }
}
sauimone
moving mouse event handling logic to scroller
r2199 void Scroller::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
{
stopTicker();
m_pressPos = event->screenPos();
m_lastPos = m_pressPos;
m_state = Pressed;
event->accept();
}
void Scroller::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QPointF delta = event->screenPos() - m_lastPos;
switch (m_state) {
case Pressed: {
// calculate treshold. If enough, change to move state and send out move deltas.
if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) {
m_lastPos = event->screenPos();
move(delta);
m_state = Move;
}
event->accept();
break;
}
case Move: {
m_lastPos = event->screenPos();
move(delta);
event->accept();
break;
}
case Idle:
default: {
event->ignore();
break;
}
}
}
void Scroller::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
switch (m_state) {
case Move:
{
scrollTo(m_lastPos - m_pressPos);
event->accept();
break;
}
default:
{
m_state = Idle;
event->ignore();
break;
}
}
}
sauimone
Kinetic scrolling is back for legend
r2189 void Scroller::startTicker(int interval)
sauimone
Legend can now handle clicked and do scrolling
r2183 {
sauimone
Kinetic scrolling is back for legend
r2189 m_state = Scroll;
m_ticker.start(interval);
sauimone
Legend can now handle clicked and do scrolling
r2183 }
sauimone
Kinetic scrolling is back for legend
r2189 void Scroller::stopTicker()
{
m_state = Idle;
m_ticker.stop();
}
sauimone
Legend can now handle clicked and do scrolling
r2183
Michal Klocek
Refactor qledgend handling...
r855 void Scroller::scrollTick()
{
switch (m_state) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 case Scroll:
lowerSpeed(m_speed);
sauimone
Kinetic scrolling is back for legend
r2189 setOffset(offset() - m_speed);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (m_speed == QPointF(0, 0)) {
m_state = Idle;
Michal Klocek
Refactor qledgend handling...
r855 m_ticker.stop();
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 }
break;
sauimone
moving mouse event handling logic to scroller
r2199 default:
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 qWarning() << __FUNCTION__ << "Scroller unexpected state" << m_state;
m_ticker.stop();
sauimone
Kinetic scrolling is back for legend
r2189 m_state = Idle;
Michal Klocek
Refactor qledgend handling...
r855 break;
}
}
Jani Honkonen
more coding style fixes for src-folder...
r2104 void Scroller::lowerSpeed(QPointF &speed, qreal maxSpeed)
Michal Klocek
Refactor qledgend handling...
r855 {
qreal x = qBound(-maxSpeed, speed.x(), maxSpeed);
qreal y = qBound(-maxSpeed, speed.y(), maxSpeed);
x = (x == 0) ? x :
(x > 0) ? qMax(qreal(0), x - m_fraction.x()) : qMin(qreal(0), x + m_fraction.x());
y = (y == 0) ? y :
(y > 0) ? qMax(qreal(0), y - m_fraction.y()) : qMin(qreal(0), y + m_fraction.y());
speed.setX(x);
speed.setY(y);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Jani Honkonen
more coding style fixes for src-folder...
r2104 ScrollTicker::ScrollTicker(Scroller *scroller, QObject *parent)
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 : QObject(parent),
m_scroller(scroller)
Michal Klocek
Refactor qledgend handling...
r855 {
}
void ScrollTicker::start(int interval)
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (!m_timer.isActive())
Michal Klocek
Refactor qledgend handling...
r855 m_timer.start(interval, this);
}
void ScrollTicker::stop()
{
m_timer.stop();
}
void ScrollTicker::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
m_scroller->scrollTick();
}
Michal Klocek
Krazy reported errors...
r974 #include "moc_scroller_p.cpp"
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_END_NAMESPACE