summaryrefslogtreecommitdiffstats
path: root/src/graphs3d/input/qgraphsinputhandler_p.h
blob: 8c0a59d18378a17bec6d495e6b7018897deca034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

//
//  W A R N I N G
//  -------------
//
// This file is not part of the QtGraphs API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.

#ifndef QGRAPHSINPUTHANDLER_P_H
#define QGRAPHSINPUTHANDLER_P_H

#include <QtQuick/qquickitem.h>

QT_BEGIN_NAMESPACE

class QQuickGraphsItem;
class QQuickTapHandler;
class QQuickDragHandler;
class QQuickPinchHandler;
class QQuickWheelHandler;
class QQuickWheelEvent;

class QGraphsInputHandler : public QQuickItem
{
    Q_OBJECT

public:
    QGraphsInputHandler(QQuickItem *parent = nullptr);

    ~QGraphsInputHandler() override;

    void setGraphsItem(QQuickGraphsItem *item);
    QPoint pendingPoint() { return m_pendingPoint; }

    void setZoomEnabled(bool enable);
    bool isZoomEnabled();
    void setZoomAtTargetEnabled(bool enable);
    bool isZoomAtTargetEnabled();
    void setRotationEnabled(bool enable);
    bool isRotationEnabled();
    void setSelectionEnabled(bool enable);
    bool isSelectionEnabled();

    void setDefaultInputHandler();
    void unsetDefaultInputHandler();
    void unsetDefaultTapHandler();
    void unsetDefaultDragHandler();
    void unsetDefaultWheelHandler();
    void unsetDefaultPinchHandler();
    void setDragButton(Qt::MouseButtons button);

    void onTapped();
    void onTranslationChanged(QVector2D delta);
    void onGrabChanged(QPointingDevice::GrabTransition transition, QEventPoint point);
    void onWheel(QQuickWheelEvent *event);
    void onPinchScaleChanged(qreal delta);

    Q_SIGNAL void mouseMove(QPoint mousePos);

protected:
    void hoverMoveEvent(QHoverEvent *event) override;

private:
    bool m_zoomEnabled;
    bool m_zoomAtTarget;
    bool m_rotationEnabled;
    bool m_selectionEnabled;
    QPoint m_pendingPoint;
    qreal m_pinchDiff;

    QQuickTapHandler *m_tapHandler;
    QQuickPinchHandler *m_pinchHandler;
    QQuickWheelHandler *m_wheelHandler;
    QQuickDragHandler *m_dragHandler;

    QQuickGraphsItem *m_graphsItem;
};

QT_END_NAMESPACE

#endif // QGRAPHSINPUTHANDLER_P_H