Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
inspecttool.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
// Qt-Security score:significant
4
5
#
include
"inspecttool.h"
6
#
include
"highlight.h"
7
#
include
"qquickwindowinspector.h"
8
#
include
"globalinspector.h"
9
10
#
include
<
QtCore
/
QLineF
>
11
12
#
include
<
QtGui
/
QMouseEvent
>
13
#
include
<
QtGui
/
QTouchEvent
>
14
#
include
<
QtGui
/
QKeyEvent
>
15
#
include
<
QtGui
/
QGuiApplication
>
16
#
include
<
QtGui
/
QStyleHints
>
17
18
#
include
<
QtQuick
/
QQuickView
>
19
#
include
<
QtQuick
/
QQuickItem
>
20
21
QT_BEGIN_NAMESPACE
22
23
namespace
QmlJSDebugger
{
24
25
InspectTool
::InspectTool(
QQuickWindowInspector
*inspector, QQuickWindow *view) :
26
QObject(inspector),
27
m_contentItem(view->contentItem()),
28
m_touchTimestamp(0),
29
m_hoverHighlight(
new
HoverHighlight
(inspector
->
overlay
(
)
)),
30
m_lastItem(
nullptr
),
31
m_lastClickedItem(
nullptr
)
32
{
33
//Timer to display selected item's name
34
m_nameDisplayTimer.setSingleShot(
true
);
35
m_nameDisplayTimer.setInterval(QGuiApplication::styleHints()->mouseDoubleClickInterval());
36
connect(&m_nameDisplayTimer, &QTimer::timeout,
this
, &
InspectTool
::showItemName);
37
}
38
39
void
InspectTool
::
enterEvent
(QEnterEvent *)
40
{
41
m_hoverHighlight->setVisible(
true
);
42
}
43
44
void
InspectTool
::
leaveEvent
(QEvent *)
45
{
46
m_hoverHighlight->setVisible(
false
);
47
}
48
49
void
InspectTool
::
mousePressEvent
(QMouseEvent *event)
50
{
51
m_mousePosition = event->position();
52
if
(event->button() == Qt::LeftButton) {
53
selectItem();
54
m_hoverHighlight->setVisible(
false
);
55
}
56
}
57
58
void
InspectTool
::
mouseDoubleClickEvent
(QMouseEvent *event)
59
{
60
m_mousePosition = event->position();
61
if
(event->button() == Qt::LeftButton) {
62
selectNextItem();
63
m_hoverHighlight->setVisible(
false
);
64
}
65
}
66
67
void
InspectTool
::
mouseMoveEvent
(QMouseEvent *event)
68
{
69
hoverMoveEvent
(
event
)
;
70
}
71
72
void
InspectTool
::
hoverMoveEvent
(QMouseEvent *event)
73
{
74
m_mousePosition = event->position();
75
QQuickItem *item = inspector()->topVisibleItemAt(event->position().toPoint());
76
if
(!item || item == m_lastClickedItem) {
77
m_hoverHighlight->setVisible(
false
);
78
}
else
{
79
m_hoverHighlight->setItem(item);
80
m_hoverHighlight->setVisible(
true
);
81
}
82
}
83
84
void
InspectTool
::
touchEvent
(QTouchEvent *event)
85
{
86
const
auto
&touchPoints = event->points();
87
88
switch
(event->type()) {
89
case
QEvent::TouchBegin:
90
if
(touchPoints.size() == 1 && (event->touchPointStates() & QEventPoint::State::Pressed)) {
91
m_mousePosition = touchPoints.first().position();
92
m_tapEvent =
true
;
93
}
else
{
94
m_tapEvent =
false
;
95
}
96
break
;
97
case
QEvent::TouchUpdate: {
98
if
(touchPoints.size() > 1)
99
m_tapEvent =
false
;
100
else
if
((touchPoints.size() == 1) && (event->touchPointStates() & QEventPoint::State::Updated))
101
m_mousePosition = touchPoints.first().position();
102
break
;
103
}
104
case
QEvent::TouchEnd: {
105
if
(touchPoints.size() == 1 && m_tapEvent) {
106
m_tapEvent =
false
;
107
bool
doubleTap = event->timestamp() - m_touchTimestamp
108
<
static_cast
<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
109
if
(doubleTap) {
110
m_nameDisplayTimer.stop();
111
selectNextItem();
112
}
else
{
113
selectItem();
114
}
115
m_touchTimestamp = event->timestamp();
116
}
117
break
;
118
}
119
default
:
120
break
;
121
}
122
}
123
124
void
InspectTool
::selectNextItem()
125
{
126
if
(m_lastClickedItem != inspector()->topVisibleItemAt(m_mousePosition))
127
return
;
128
QList<QQuickItem*> items = inspector()->itemsAt(m_mousePosition);
129
for
(
int
i = 0; i < items.size(); i++) {
130
if
(m_lastItem == items[i]) {
131
if
(i + 1 < items.size())
132
m_lastItem = items[i+1];
133
else
134
m_lastItem = items[0];
135
globalInspector()->setSelectedItems(QList<QQuickItem*>() << m_lastItem);
136
showItemName();
137
break
;
138
}
139
}
140
}
141
142
void
InspectTool
::selectItem()
143
{
144
if
(!inspector()->topVisibleItemAt(m_mousePosition))
145
return
;
146
m_lastClickedItem = inspector()->topVisibleItemAt(m_mousePosition);
147
m_lastItem = m_lastClickedItem;
148
globalInspector()->setSelectedItems(QList<QQuickItem*>() << m_lastClickedItem);
149
if
(m_lastClickedItem == inspector()->topVisibleItemAt(m_mousePosition)) {
150
m_nameDisplayTimer.start();
151
}
else
{
152
showItemName();
153
}
154
}
155
156
void
InspectTool
::showItemName()
157
{
158
globalInspector()->showSelectedItemName(m_lastItem, m_mousePosition);
159
}
160
161
QQuickWindowInspector
*
InspectTool
::inspector()
const
162
{
163
return
static_cast
<
QQuickWindowInspector
*>(parent());
164
}
165
166
GlobalInspector
*
InspectTool
::globalInspector()
const
167
{
168
return
static_cast
<
GlobalInspector
*>(parent()->parent());
169
}
170
171
}
// namespace QmlJSDebugger
172
173
QT_END_NAMESPACE
174
175
#
include
"moc_inspecttool.cpp"
QmlJSDebugger::GlobalInspector
Definition
globalinspector.h:22
QmlJSDebugger::HoverHighlight
Definition
highlight.h:64
QmlJSDebugger::InspectTool
Definition
inspecttool.h:28
QmlJSDebugger::InspectTool::hoverMoveEvent
void hoverMoveEvent(QMouseEvent *)
Definition
inspecttool.cpp:72
QmlJSDebugger::InspectTool::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *)
Definition
inspecttool.cpp:58
QmlJSDebugger::InspectTool::touchEvent
void touchEvent(QTouchEvent *event)
Definition
inspecttool.cpp:84
QmlJSDebugger::InspectTool::leaveEvent
void leaveEvent(QEvent *)
Definition
inspecttool.cpp:44
QmlJSDebugger::InspectTool::mousePressEvent
void mousePressEvent(QMouseEvent *)
Definition
inspecttool.cpp:49
QmlJSDebugger::InspectTool::enterEvent
void enterEvent(QEnterEvent *)
Definition
inspecttool.cpp:39
QmlJSDebugger::InspectTool::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *)
Definition
inspecttool.cpp:67
QmlJSDebugger::QQuickWindowInspector
Definition
qquickwindowinspector.h:27
QmlJSDebugger::QQuickWindowInspector::overlay
QQuickItem * overlay() const
Definition
qquickwindowinspector.h:33
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QmlJSDebugger
Definition
globalinspector.cpp:48
qtdeclarative
src
plugins
qmltooling
qmldbg_inspector
inspecttool.cpp
Generated on
for Qt by
1.18.0