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
qwaylandquickoutput.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// Copyright (C) 2017 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
8
10
11QWaylandQuickOutput::QWaylandQuickOutput()
12{
13}
14
15QWaylandQuickOutput::QWaylandQuickOutput(QWaylandCompositor *compositor, QWindow *window)
16 : QWaylandOutput(compositor, window)
17{
18}
19
20void QWaylandQuickOutput::initialize()
21{
22 QWaylandOutput::initialize();
23
24 QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(window());
25 if (!quickWindow) {
26 qWarning("Initialization error: Could not locate QQuickWindow on initializing QWaylandQuickOutput %p.\n", this);
27 return;
28 }
29 connect(quickWindow, &QQuickWindow::beforeSynchronizing,
30 this, &QWaylandQuickOutput::updateStarted,
31 Qt::DirectConnection);
32
33 connect(quickWindow, &QQuickWindow::afterRendering,
34 this, &QWaylandQuickOutput::doFrameCallbacks);
35}
36
37void QWaylandQuickOutput::classBegin()
38{
39}
40
41void QWaylandQuickOutput::componentComplete()
42{
43 if (!compositor()) {
44 for (QObject *p = parent(); p != nullptr; p = p->parent()) {
45 if (auto c = qobject_cast<QWaylandCompositor *>(p)) {
46 setCompositor(c);
47 break;
48 }
49 }
50 }
51}
52
53void QWaylandQuickOutput::update()
54{
55 if (!m_updateScheduled) {
56 //don't qobject_cast since we have verified the type in initialize
57 static_cast<QQuickWindow *>(window())->update();
58 m_updateScheduled = true;
59 }
60}
61
62/*!
63 * \qmlproperty bool QtWayland.Compositor::WaylandOutput::automaticFrameCallback
64 *
65 * This property holds whether the WaylandOutput automatically sends frame
66 * callbacks when rendering.
67 *
68 * The default is true.
69 */
70
71/*!
72 * \property QWaylandQuickOutput::automaticFrameCallback
73 *
74 * This property holds whether the QWaylandQuickOutput automatically sends frame
75 * callbacks when rendering.
76 *
77 * When \c true, frame callbacks are sent automatically after each frame is
78 * rendered; when \c false, frame callbacks must be sent manually.
79 *
80 * The default is \c true.
81 */
82bool QWaylandQuickOutput::automaticFrameCallback() const
83{
84 return m_automaticFrameCallback;
85}
86
87void QWaylandQuickOutput::setAutomaticFrameCallback(bool automatic)
88{
89 if (m_automaticFrameCallback == automatic)
90 return;
91
92 m_automaticFrameCallback = automatic;
93 automaticFrameCallbackChanged();
94}
95
96static QQuickItem* clickableItemAtPosition(QQuickItem *rootItem, const QPointF &position)
97{
98 if (!rootItem->isEnabled() || !rootItem->isVisible())
99 return nullptr;
100
101 QList<QQuickItem *> paintOrderItems = QQuickItemPrivate::get(rootItem)->paintOrderChildItems();
102 auto negativeZStart = paintOrderItems.crend();
103 for (auto it = paintOrderItems.crbegin(); it != paintOrderItems.crend(); ++it) {
104 if ((*it)->z() < 0) {
105 negativeZStart = it;
106 break;
107 }
108 QQuickItem *item = clickableItemAtPosition(*it, rootItem->mapToItem(*it, position));
109 if (item)
110 return item;
111 }
112
113 if (rootItem->contains(position) && rootItem->acceptedMouseButtons() != Qt::NoButton)
114 return rootItem;
115
116 for (auto it = negativeZStart; it != paintOrderItems.crend(); ++it) {
117 QQuickItem *item = clickableItemAtPosition(*it, rootItem->mapToItem(*it, position));
118 if (item)
119 return item;
120 }
121
122 return nullptr;
123}
124
125QQuickItem *QWaylandQuickOutput::pickClickableItem(const QPointF &position)
126{
127 QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(window());
128 if (!quickWindow)
129 return nullptr;
130
131 return clickableItemAtPosition(quickWindow->contentItem(), position);
132}
133
134/*!
135 * \internal
136 */
137void QWaylandQuickOutput::updateStarted()
138{
139 m_updateScheduled = false;
140
141 if (!compositor())
142 return;
143
144 frameStarted();
145}
146
147void QWaylandQuickOutput::doFrameCallbacks()
148{
149 if (m_automaticFrameCallback)
150 sendFrameCallbacks();
151}
152QT_END_NAMESPACE
153
154#include "moc_qwaylandquickoutput.cpp"
Combined button and popup list for selecting options.
static QQuickItem * clickableItemAtPosition(QQuickItem *rootItem, const QPointF &position)