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
formwindow_widgetstack.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant reason:default
4
5
#
include
"formwindow_widgetstack.h"
6
#
include
<
QtDesigner
/
abstractformwindowtool
.
h
>
7
8
#
include
<
QtWidgets
/
qstackedlayout
.
h
>
9
#
include
<
QtWidgets
/
qboxlayout
.
h
>
10
#
include
<
QtWidgets
/
qwidget
.
h
>
11
12
#
include
<
QtGui
/
qevent
.
h
>
13
#
include
<
QtGui
/
qaction
.
h
>
14
15
#
include
<
QtCore
/
qdebug
.
h
>
16
17
QT_BEGIN_NAMESPACE
18
19
using
namespace
Qt::StringLiterals;
20
21
namespace
qdesigner_internal
{
22
23
FormWindowWidgetStack
::FormWindowWidgetStack(QObject *parent) :
24
QObject(parent),
25
m_formContainer(
new
QWidget),
26
m_formContainerLayout(
new
QStackedLayout),
27
m_layout(
new
QStackedLayout)
28
{
29
m_layout->setContentsMargins(QMargins());
30
m_layout->setSpacing(0);
31
m_layout->setStackingMode(QStackedLayout::StackAll);
32
33
// We choose a QStackedLayout as immediate layout for
34
// the form windows as it ignores the sizePolicy of
35
// its child (for example, Fixed would cause undesired side effects).
36
m_formContainerLayout->setContentsMargins(QMargins());
37
m_formContainer->setObjectName(u"formContainer"_s);
38
m_formContainer->setLayout(m_formContainerLayout);
39
m_formContainerLayout->setStackingMode(QStackedLayout::StackAll);
40
// System settings might have different background colors, autofill them
41
// (affects for example mainwindow status bars)
42
m_formContainer->setAutoFillBackground(
true
);
43
}
44
45
FormWindowWidgetStack
::~
FormWindowWidgetStack
() =
default
;
46
47
int
FormWindowWidgetStack
::
count
()
const
48
{
49
return
m_tools.size();
50
}
51
52
QDesignerFormWindowToolInterface *
FormWindowWidgetStack
::
currentTool
()
const
53
{
54
return
tool
(
currentIndex
(
)
)
;
55
}
56
57
void
FormWindowWidgetStack
::
setCurrentTool
(
int
index)
58
{
59
const
int
cnt =
count
(
)
;
60
if
(index < 0 || index >= cnt) {
61
qDebug(
"FormWindowWidgetStack::setCurrentTool(): invalid index: %d"
, index);
62
return
;
63
}
64
65
const
int
cur =
currentIndex
(
)
;
66
if
(index == cur)
67
return
;
68
69
if
(cur != -1)
70
m_tools.at(cur)->deactivated();
71
72
73
m_layout->setCurrentIndex(index);
74
// Show the widget editor and the current tool
75
for
(
int
i = 0; i < cnt; i++)
76
m_tools.at(i)->editor()->setVisible(i == 0 || i == index);
77
78
QDesignerFormWindowToolInterface *tool = m_tools.at(index);
79
tool->activated();
80
81
emit currentToolChanged(index);
82
}
83
84
void
FormWindowWidgetStack
::
setSenderAsCurrentTool
()
85
{
86
QDesignerFormWindowToolInterface *tool =
nullptr
;
87
QAction *action = qobject_cast<QAction*>(sender());
88
if
(action ==
nullptr
) {
89
qDebug(
"FormWindowWidgetStack::setSenderAsCurrentTool(): sender is not a QAction"
);
90
return
;
91
}
92
93
for
(QDesignerFormWindowToolInterface *t : std::as_const(m_tools)) {
94
if
(action == t->action()) {
95
tool = t;
96
break
;
97
}
98
}
99
100
if
(tool ==
nullptr
) {
101
qDebug(
"FormWindowWidgetStack::setSenderAsCurrentTool(): unknown tool"
);
102
return
;
103
}
104
105
setCurrentTool
(
tool
)
;
106
}
107
108
int
FormWindowWidgetStack
::
indexOf
(QDesignerFormWindowToolInterface *tool)
const
109
{
110
return
m_tools.indexOf(tool);
111
}
112
113
void
FormWindowWidgetStack
::
setCurrentTool
(QDesignerFormWindowToolInterface *tool)
114
{
115
int
index =
indexOf
(
tool
)
;
116
if
(index == -1) {
117
qDebug(
"FormWindowWidgetStack::setCurrentTool(): unknown tool"
);
118
return
;
119
}
120
121
setCurrentTool
(
index
)
;
122
}
123
124
void
FormWindowWidgetStack
::
setMainContainer
(
QWidget
*w)
125
{
126
// This code is triggered once by the formwindow and
127
// by integrations doing "revert to saved". Anything changing?
128
const
int
previousCount = m_formContainerLayout->count();
129
QWidget
*previousMainContainer = previousCount
130
? m_formContainerLayout->itemAt(0)->widget() :
nullptr
;
131
if
(previousMainContainer == w)
132
return
;
133
// Swap
134
if
(previousCount)
135
delete
m_formContainerLayout->takeAt(0);
136
if
(w)
137
m_formContainerLayout->addWidget(w);
138
}
139
140
void
FormWindowWidgetStack
::addTool(QDesignerFormWindowToolInterface *tool)
141
{
142
if
(
QWidget
*w = tool->editor()) {
143
w->setVisible(m_layout->count() == 0);
// Initially only form editor is visible
144
m_layout->addWidget(w);
145
}
else
{
146
// The form editor might not have a tool initially, use dummy. Assert on anything else
147
Q_ASSERT(m_tools.isEmpty());
148
m_layout->addWidget(m_formContainer);
149
}
150
151
m_tools.append(tool);
152
153
connect(tool->action(), &QAction::triggered,
154
this
, &
FormWindowWidgetStack
::
setSenderAsCurrentTool
);
155
}
156
157
QDesignerFormWindowToolInterface *
FormWindowWidgetStack
::
tool
(
int
index)
const
158
{
159
if
(index < 0 || index >=
count
(
)
)
160
return
nullptr
;
161
162
return
m_tools.at(index);
163
}
164
165
int
FormWindowWidgetStack
::
currentIndex
()
const
166
{
167
return
m_layout->currentIndex();
168
}
169
170
QWidget
*
FormWindowWidgetStack
::
defaultEditor
()
const
171
{
172
if
(m_tools.isEmpty())
173
return
nullptr
;
174
175
return
m_tools.at(0)->editor();
176
}
177
178
QLayout
*
FormWindowWidgetStack
::
layout
()
const
179
{
180
return
m_layout;
181
}
182
183
}
// namespace qdesigner_internal
184
185
QT_END_NAMESPACE
QPainter::QWidget
friend class QWidget
Definition
qpainter.h:432
qdesigner_internal::FormWindowWidgetStack
Definition
formwindow_widgetstack.h:22
qdesigner_internal::FormWindowWidgetStack::currentTool
QDesignerFormWindowToolInterface * currentTool() const
Definition
formwindow_widgetstack.cpp:52
qdesigner_internal::FormWindowWidgetStack::setCurrentTool
void setCurrentTool(int index)
Definition
formwindow_widgetstack.cpp:57
qdesigner_internal::FormWindowWidgetStack::setSenderAsCurrentTool
void setSenderAsCurrentTool()
Definition
formwindow_widgetstack.cpp:84
qdesigner_internal::FormWindowWidgetStack::tool
QDesignerFormWindowToolInterface * tool(int index) const
Definition
formwindow_widgetstack.cpp:157
qdesigner_internal::FormWindowWidgetStack::~FormWindowWidgetStack
~FormWindowWidgetStack() override
qdesigner_internal::FormWindowWidgetStack::currentIndex
int currentIndex() const
Definition
formwindow_widgetstack.cpp:165
qdesigner_internal::FormWindowWidgetStack::layout
QLayout * layout() const
Definition
formwindow_widgetstack.cpp:178
qdesigner_internal::FormWindowWidgetStack::setMainContainer
void setMainContainer(QWidget *w=nullptr)
Definition
formwindow_widgetstack.cpp:124
qdesigner_internal::FormWindowWidgetStack::setCurrentTool
void setCurrentTool(QDesignerFormWindowToolInterface *tool)
Definition
formwindow_widgetstack.cpp:113
qdesigner_internal::FormWindowWidgetStack::defaultEditor
QWidget * defaultEditor() const
Definition
formwindow_widgetstack.cpp:170
qdesigner_internal::FormWindowWidgetStack::count
int count() const
Definition
formwindow_widgetstack.cpp:47
qdesigner_internal::FormWindowWidgetStack::indexOf
int indexOf(QDesignerFormWindowToolInterface *tool) const
Definition
formwindow_widgetstack.cpp:108
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qdesigner_internal
Auxiliary methods to store/retrieve settings.
Definition
buddyeditor.cpp:67
qttools
src
designer
src
components
formeditor
formwindow_widgetstack.cpp
Generated on
for Qt by
1.18.0