Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohoshovereventsgenerator.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtCore/private/qohoscommon_p.h>
5#include <optional>
6#include <render/qohoshovereventsgenerator.h>
7
9
10namespace {
11
14
16{
17public:
19 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
20 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef);
21
22 void handleQOhosMouseEvent(const QOhosMouseEvent &mouseEvent) override;
23 void handleQOhosHoverEvent(bool hovered) override;
24
25private:
26 void sendQtHoverEvent(bool isHover);
27
28 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
29 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
30
31 std::optional<QPointF> m_optCurrentLocalPosition;
32 std::optional<QPointF> m_optCurrentGlobalPosition;
33 bool m_hovered;
34};
35
37 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
38 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
41 , m_hovered(false)
42{
43}
44
46{
47 m_optCurrentLocalPosition = mouseEvent.localPosition;
48 m_optCurrentGlobalPosition = mouseEvent.globalPosition;
49
50 if (!m_hovered) {
51 sendQtHoverEvent(true);
52 m_hovered = true;
53 }
54}
55
56void QOhosHoverEventsGeneratorImpl::sendQtHoverEvent(bool isHover)
57{
58 const auto localPosition = m_optCurrentLocalPosition.value_or(fallbackLocalPositionWhenUnknown);
59 const auto globalPosition = m_optCurrentGlobalPosition.value_or(fallbackGlobalPositionWhenUnknown);
60
61 m_imEventHandlerRef.visitInQtThreadIfAlive(
62 [isHover, localPosition, globalPosition, qWindowRef = m_qWindowRef](QOhosInputMethodEventHandler &imEventHandler) {
63 QWindow *qWindow = qWindowRef.data();
64 if (qWindow != nullptr) {
65 imEventHandler.onHoverEvent(
66 QOhosHoverEvent {
67 .targetWindow = qWindow,
68 .localPosition = localPosition,
69 .globalPosition = globalPosition,
70 .isHover = isHover,
71 });
72 }
73 });
74}
75
77{
78 if (!hovered && m_hovered) {
79 sendQtHoverEvent(false);
80 m_hovered = false;
81 }
82}
83
84}
85
87
89
91 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
92 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
93{
94 return std::make_shared<QOhosHoverEventsGeneratorImpl>(qWindowRef, imEventHandlerRef);
95}
96
97QT_END_NAMESPACE
virtual ~QOhosHoverEventsGenerator()
void handleQOhosMouseEvent(const QOhosMouseEvent &mouseEvent) override
QOhosHoverEventsGeneratorImpl(QtOhos::QThreadSafeRef< QWindow > qWindowRef, QtOhos::QThreadSafeRef< QOhosInputMethodEventHandler > imEventHandlerRef)
Combined button and popup list for selecting options.
const QPointF fallbackGlobalPositionWhenUnknown
const QPointF fallbackLocalPositionWhenUnknown
std::shared_ptr< QOhosHoverEventsGenerator > makeQOhosHoverEventsGenerator(QtOhos::QThreadSafeRef< QWindow > qWindowRef, QtOhos::QThreadSafeRef< QOhosInputMethodEventHandler > imEventHandlerRef)