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 <QtGui/private/qhighdpiscaling_p.h>
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 QOhosOptional<QPointF> m_optCurrentLocalPosition;
32 QOhosOptional<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.valueOr(fallbackLocalPositionWhenUnknown);
59 const auto globalPosition = m_optCurrentGlobalPosition.valueOr(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 auto *platformScreen = static_cast<QOhosPlatformScreen *>(qWindow->screen()->handle());
66 const auto scaledLocalPosition = QHighDpi::toNative(localPosition, platformScreen->pixelScalingCoefficient());
67 const auto scaledGlobalPosition = QHighDpi::toNative(globalPosition, platformScreen->pixelScalingCoefficient());
68 imEventHandler.onHoverEvent(isHover, scaledLocalPosition, scaledGlobalPosition, qWindow);
69 }
70 });
71}
72
74{
75 if (!hovered && m_hovered) {
76 sendQtHoverEvent(false);
77 m_hovered = false;
78 }
79}
80
81}
82
84
86
88 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
89 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
90{
91 return std::make_shared<QOhosHoverEventsGeneratorImpl>(qWindowRef, imEventHandlerRef);
92}
93
94QT_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)