1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4// W A R N I N G
5// -------------
6//
7// This file is not part of the Qt Chart API. It exists purely as an
8// implementation detail. This header file may change from version to
9// version without notice, or even be removed.
10//
11// We mean it.
12
13#ifndef SCROLLER_P_H
14#define SCROLLER_P_H
15
16#include <QtCharts/QChartGlobal>
17#include <QtCore/QObject>
18#include <QtCore/QBasicTimer>
19#include <QtCore/QElapsedTimer>
20#include <QtCore/QPointF>
21#include <QtCharts/private/qchartglobal_p.h>
22
23QT_BEGIN_NAMESPACE
24class QGraphicsSceneMouseEvent;
25QT_END_NAMESPACE
26
27QT_BEGIN_NAMESPACE
28
29class Scroller;
30class QLegend;
31
32class Q_CHARTS_PRIVATE_EXPORT ScrollTicker : public QObject
33{
34 Q_OBJECT
35public:
36 explicit ScrollTicker(Scroller *scroller, QObject *parent = 0);
37 void start(int interval);
38 void stop();
39protected:
40 void timerEvent(QTimerEvent *event) override;
41
42private:
43 QBasicTimer m_timer;
44 Scroller *m_scroller;
45};
46
47class Q_CHARTS_PRIVATE_EXPORT Scroller
48{
49public:
50 enum State {
51 Idle,
52 Pressed,
53 Move,
54 Scroll
55 };
56
57 Scroller();
58 virtual ~Scroller();
59
60 virtual void setOffset(const QPointF &point) = 0;
61 virtual QPointF offset() const = 0;
62
63 void move(const QPointF &delta);
64 void scrollTo(const QPointF &delta);
65
66 void handleMousePressEvent(QGraphicsSceneMouseEvent *event);
67 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event);
68 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
69
70 void scrollTick();
71
72private:
73 void startTicker(int interval);
74 void stopTicker();
75
76private:
77 void calculateSpeed(const QPointF &position);
78 void lowerSpeed(QPointF &speed, qreal maxSpeed = 100);
79
80private:
81 ScrollTicker m_ticker;
82 QElapsedTimer m_timeStamp;
83 QPointF m_speed;
84 QPointF m_fraction;
85 int m_timeTresholdMin;
86 int m_timeTresholdMax;
87
88 State m_state;
89 QPointF m_pressPos;
90 QPointF m_lastPos;
91 qreal m_treshold;
92};
93
94QT_END_NAMESPACE
95
96#endif /* SCROLLER_P_H */
97

source code of qtcharts/src/charts/scroller_p.h