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 <render/qohoshovereventsgenerator.h>
6
8
9namespace {
10
13
15{
16public:
18 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
19 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef);
20
21 void handleQOhosMouseEvent(const QOhosMouseEvent &mouseEvent) override;
22 void handleQOhosHoverEvent(bool hovered) override;
23
24private:
25 void sendQtHoverEvent(bool isHover);
26
27 QtOhos::QThreadSafeRef<QWindow> m_qWindowRef;
28 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> m_imEventHandlerRef;
29
30 QOhosOptional<QPointF> m_optCurrentLocalPosition;
31 QOhosOptional<QPointF> m_optCurrentGlobalPosition;
32 bool m_hovered;
33};
34
36 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
37 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
40 , m_hovered(false)
41{
42}
43
45{
46 m_optCurrentLocalPosition = mouseEvent.localPosition;
47 m_optCurrentGlobalPosition = mouseEvent.globalPosition;
48
49 if (!m_hovered) {
50 sendQtHoverEvent(true);
51 m_hovered = true;
52 }
53}
54
55void QOhosHoverEventsGeneratorImpl::sendQtHoverEvent(bool isHover)
56{
57 const auto localPosition = m_optCurrentLocalPosition.value_or(fallbackLocalPositionWhenUnknown);
58 const auto globalPosition = m_optCurrentGlobalPosition.value_or(fallbackGlobalPositionWhenUnknown);
59
60 m_imEventHandlerRef.visitInQtThreadIfAlive(
61 [isHover, localPosition, globalPosition, qWindowRef = m_qWindowRef](QOhosInputMethodEventHandler &imEventHandler) {
62 QWindow *qWindow = qWindowRef.data();
63 if (qWindow != nullptr) {
64 imEventHandler.onHoverEvent(
65 QOhosHoverEvent {
66 .targetWindow = qWindow,
67 .localPosition = localPosition,
68 .globalPosition = globalPosition,
69 .isHover = isHover,
70 });
71 }
72 });
73}
74
76{
77 if (!hovered && m_hovered) {
78 sendQtHoverEvent(false);
79 m_hovered = false;
80 }
81}
82
83}
84
86
88
90 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
91 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
92{
93 return std::make_shared<QOhosHoverEventsGeneratorImpl>(qWindowRef, imEventHandlerRef);
94}
95
96QT_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)