Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickwindowinspector.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
5#include "inspecttool.h"
6
7#include <private/qquickitem_p.h>
8
10
11namespace QmlJSDebugger {
12
13/*
14 * Returns the first visible item at the given position, or 0 when no such
15 * child exists.
16 */
18 QQuickItem *overlay)
19{
20 if (item == overlay)
21 return nullptr;
22
23 if (!item->isVisible() || item->opacity() == 0.0)
24 return nullptr;
25
27 if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
28 return nullptr;
29 }
30
31 QList<QQuickItem *> children = QQuickItemPrivate::get(item)->paintOrderChildItems();
32 for (int i = children.size() - 1; i >= 0; --i) {
33 QQuickItem *child = children.at(i);
34 if (QQuickItem *betterCandidate = itemAt(child, item->mapToItem(child, pos),
35 overlay))
36 return betterCandidate;
37 }
38
40 return nullptr;
41
42 if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
43 return nullptr;
44
45 return item;
46}
47
48/*
49 * Collects all the items at the given position, from top to bottom.
50 */
52 QQuickItem *overlay, QList<QQuickItem *> &resultList)
53{
54 if (item == overlay)
55 return;
56
58 if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
59 return;
60 }
61
62 QList<QQuickItem *> children = QQuickItemPrivate::get(item)->paintOrderChildItems();
63 for (int i = children.size() - 1; i >= 0; --i) {
64 QQuickItem *child = children.at(i);
65 collectItemsAt(child, item->mapToItem(child, pos), overlay, resultList);
66 }
67
68 if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
69 return;
70
71 resultList.append(item);
72}
73
75 QObject(parent),
76 m_overlay(new QQuickItem),
77 m_window(quickWindow),
78 m_parentWindow(nullptr),
79 m_tool(nullptr)
80{
82
83 // Try to make sure the overlay is always on top
84 m_overlay->setZ(FLT_MAX);
85
86 if (QQuickItem *root = m_window->contentItem())
87 m_overlay->setParentItem(root);
88
89 m_window->installEventFilter(this);
90}
91
93{
94 if (!m_tool || obj != m_window)
96
97 switch (event->type()) {
98 case QEvent::Enter:
99 m_tool->enterEvent(static_cast<QEnterEvent*>(event));
100 return true;
101 case QEvent::Leave:
102 m_tool->leaveEvent(event);
103 return true;
105 m_tool->mousePressEvent(static_cast<QMouseEvent*>(event));
106 return true;
108 m_tool->mouseMoveEvent(static_cast<QMouseEvent*>(event));
109 return true;
111 return true;
112 case QEvent::KeyPress:
113 m_tool->keyPressEvent(static_cast<QKeyEvent*>(event));
114 return true;
116 return true;
118 m_tool->mouseDoubleClickEvent(static_cast<QMouseEvent*>(event));
119 return true;
120#if QT_CONFIG(wheelevent)
121 case QEvent::Wheel:
122 return true;
123#endif
126 case QEvent::TouchEnd:
127 m_tool->touchEvent(static_cast<QTouchEvent*>(event));
128 return true;
129 default:
130 break;
131 }
132
134}
135
136static Qt::WindowFlags fixFlags(Qt::WindowFlags flags)
137{
138 // If only the type flag is given, some other window flags are automatically assumed. When we
139 // add a flag, we need to make those explicit.
140 switch (flags) {
141 case Qt::Window:
144 case Qt::Dialog:
145 case Qt::Tool:
147 default:
148 return flags;
149 }
150}
151
153{
154 if (!m_parentWindow)
155 return;
156
157 Qt::WindowFlags flags = m_parentWindow->flags();
158 Qt::WindowFlags newFlags = appOnTop ? (fixFlags(flags) | Qt::WindowStaysOnTopHint) :
159 (flags & ~Qt::WindowStaysOnTopHint);
160 if (newFlags != flags)
161 m_parentWindow->setFlags(newFlags);
162}
163
165{
166 return m_tool != nullptr;
167}
168
170{
171 if (enabled) {
172 m_tool = new InspectTool(this, m_window);
173 } else {
174 delete m_tool;
175 m_tool = nullptr;
176 }
177}
178
180{
181 return m_window;
182}
183
185{
186 if (parentWindow) {
187 while (QWindow *w = parentWindow->parent())
188 parentWindow = w;
189 }
190
191 m_parentWindow = parentWindow;
192}
193
194QList<QQuickItem *> QQuickWindowInspector::itemsAt(const QPointF &pos) const
195{
196 QList<QQuickItem *> resultList;
197 QQuickItem *root = m_window->contentItem();
198 collectItemsAt(root, root->mapFromScene(pos), m_overlay,
199 resultList);
200 return resultList;
201}
202
204{
205 QQuickItem *root = m_window->contentItem();
206 return itemAt(root, root->mapFromScene(pos), m_overlay);
207}
208
209
210} // namespace QmlJSDebugger
211
213
214#include "moc_qquickwindowinspector.cpp"
\inmodule QtGui
Definition qevent.h:165
\inmodule QtCore
Definition qcoreevent.h:45
@ KeyRelease
Definition qcoreevent.h:65
@ MouseMove
Definition qcoreevent.h:63
@ KeyPress
Definition qcoreevent.h:64
@ MouseButtonPress
Definition qcoreevent.h:60
@ TouchUpdate
Definition qcoreevent.h:242
@ TouchBegin
Definition qcoreevent.h:241
@ MouseButtonDblClick
Definition qcoreevent.h:62
@ MouseButtonRelease
Definition qcoreevent.h:61
QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in this item's coordinate system, to item's coordinate system,...
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
qreal opacity() const
GraphicsItemFlags flags() const
Returns this item's flags.
The QKeyEvent class describes a key event.
Definition qevent.h:424
\inmodule QtGui
Definition qevent.h:196
\inmodule QtCore
Definition qobject.h:103
void installEventFilter(QObject *filterObj)
Installs an event filter filterObj on this object.
Definition qobject.cpp:2339
virtual bool eventFilter(QObject *watched, QEvent *event)
Filters events if this object has been installed as an event filter for the watched object.
Definition qobject.cpp:1555
\inmodule QtCore\reentrant
Definition qpoint.h:217
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setParentItem(QQuickItem *parent)
QPointF mapFromScene(const QPointF &point) const
Maps the given point in the scene's coordinate system to the equivalent point within this item's coor...
void setZ(qreal)
@ ItemClipsChildrenToShape
Definition qquickitem.h:130
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
QQuickItem * contentItem
\qmlattachedproperty Item Window::contentItem
\inmodule QtCore\reentrant
Definition qrect.h:484
bool contains(const QRectF &r) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qrect.cpp:1993
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
\inmodule QtGui
Definition qwindow.h:63
Qt::WindowFlags flags
the window flags of the window
Definition qwindow.h:79
void mouseDoubleClickEvent(QMouseEvent *)
void touchEvent(QTouchEvent *event)
void mousePressEvent(QMouseEvent *)
void enterEvent(QEnterEvent *)
void mouseMoveEvent(QMouseEvent *)
void keyPressEvent(QKeyEvent *)
Definition inspecttool.h:38
QQuickItem * topVisibleItemAt(const QPointF &pos) const
QList< QQuickItem * > itemsAt(const QPointF &pos) const
bool eventFilter(QObject *, QEvent *) override
Filters events if this object has been installed as an event filter for the watched object.
QQuickWindowInspector(QQuickWindow *quickWindow, QObject *parent=nullptr)
Combined button and popup list for selecting options.
static void collectItemsAt(QQuickItem *item, const QPointF &pos, QQuickItem *overlay, QList< QQuickItem * > &resultList)
static QQuickItem * itemAt(QQuickItem *item, const QPointF &pos, QQuickItem *overlay)
static Qt::WindowFlags fixFlags(Qt::WindowFlags flags)
Definition qcompare.h:63
@ Window
Definition qnamespace.h:207
@ WindowStaysOnTopHint
Definition qnamespace.h:233
@ WindowMaximizeButtonHint
Definition qnamespace.h:229
@ WindowMinimizeButtonHint
Definition qnamespace.h:228
@ Dialog
Definition qnamespace.h:208
@ Tool
Definition qnamespace.h:212
@ WindowTitleHint
Definition qnamespace.h:226
@ WindowSystemMenuHint
Definition qnamespace.h:227
@ WindowCloseButtonHint
Definition qnamespace.h:241
GLfloat GLfloat GLfloat w
[0]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbitfield flags
struct _cl_event * event
GLhandleARB obj
[2]
QObject::connect nullptr
QGraphicsItem * item
QLayoutItem * child
[0]