1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef DESKTOPINPUTSELECTIONCONTROL_P_H
5#define DESKTOPINPUTSELECTIONCONTROL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qpointer.h>
19#include <QtCore/qobject.h>
20#include <QtGui/qimage.h>
21#include <QtVirtualKeyboard/qvirtualkeyboard_global.h>
22#include <QtCore/private/qglobal_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class QMouseEvent;
27class QVirtualKeyboardInputContext;
28
29namespace QtVirtualKeyboard {
30
31class InputSelectionHandle;
32
33class Q_VIRTUALKEYBOARD_EXPORT DesktopInputSelectionControl : public QObject
34{
35 Q_OBJECT
36
37public:
38 DesktopInputSelectionControl(QObject *parent, QVirtualKeyboardInputContext *inputContext);
39 ~DesktopInputSelectionControl() {}
40
41 void createHandles();
42 void destroyHandles();
43 void setEnabled(bool enable);
44 QImage *handleImage();
45
46public Q_SLOTS:
47 void updateAnchorHandlePosition();
48 void updateCursorHandlePosition();
49 void updateVisibility();
50 void reloadGraphics();
51protected:
52 bool eventFilter(QObject *object, QEvent *event) override;
53
54private:
55 QRect anchorHandleRect() const;
56 QRect cursorHandleRect() const;
57 QRect handleRectForCursorRect(const QRectF &cursorRect) const;
58
59private:
60 QVirtualKeyboardInputContext *m_inputContext;
61 QSharedPointer<InputSelectionHandle> m_anchorSelectionHandle;
62 QSharedPointer<InputSelectionHandle> m_cursorSelectionHandle;
63 QImage m_handleImage;
64
65 enum {
66 HandleIsReleased = 0,
67 HandleIsHeld = 1,
68 HandleIsMoving = 2
69 };
70 enum HandleType {
71 AnchorHandle = 0,
72 CursorHandle = 1
73 };
74
75 unsigned m_handleState : 2;
76 unsigned m_currentDragHandle : 1;
77 unsigned m_enabled : 1;
78 unsigned m_anchorHandleVisible : 1;
79 unsigned m_cursorHandleVisible : 1;
80 unsigned m_eventFilterEnabled : 1;
81 QPoint m_otherSelectionPoint;
82 QList<QMouseEvent*> m_eventQueue;
83 QPoint m_distanceBetweenMouseAndCursor;
84 QPoint m_handleDragStartedPosition;
85 QSize m_handleWindowSize;
86};
87} // namespace QtVirtualKeyboard
88QT_END_NAMESPACE
89
90#endif // DESKTOPINPUTSELECTIONCONTROL_P_H
91

source code of qtvirtualkeyboard/src/virtualkeyboard/desktopinputselectioncontrol_p.h