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
resetdecorator.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 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
"resetdecorator.h"
6
#
include
"qtpropertybrowser_p.h"
7
#
include
"qtpropertybrowserutils_p.h"
8
9
#
include
<
qdesigner_utils_p
.
h
>
10
#
include
<
iconloader_p
.
h
>
11
#
include
<
formwindowbase_p
.
h
>
12
#
include
<
formwindowcursor
.
h
>
13
#
include
<
formwindowmanager
.
h
>
14
#
include
<
formwindow
.
h
>
15
16
#
include
<
QtDesigner
/
abstractformeditor
.
h
>
17
#
include
<
QtDesigner
/
qextensionmanager
.
h
>
18
#
include
<
QtDesigner
/
propertysheet
.
h
>
19
20
#
include
<
QtWidgets
/
qboxlayout
.
h
>
21
#
include
<
QtWidgets
/
qlabel
.
h
>
22
#
include
<
QtWidgets
/
qtoolbutton
.
h
>
23
24
QT_BEGIN_NAMESPACE
25
26
namespace
qdesigner_internal
{
27
28
using
namespace
Qt
::
StringLiterals
;
29
30
ResetWidget
::ResetWidget(
QWidget
*editor,
QWidget
*parent)
31
: QWidget(parent), m_button(
new
QToolButton(
this
))
32
{
33
QLayout *layout =
new
QHBoxLayout(
this
);
34
layout->setContentsMargins(QMargins());
35
layout->addWidget(editor);
36
37
m_button->setToolButtonStyle(Qt::ToolButtonIconOnly);
38
m_button->setIcon(createIconSet(
"resetproperty.png"_L1
));
39
m_button->setIconSize(QSize(8,8));
40
m_button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
41
connect(m_button, &QAbstractButton::clicked,
this
, &ResetWidget::reset);
42
layout->addWidget(m_button);
43
setFocusProxy(editor);
44
setAutoFillBackground(
true
);
// Hide value icon/text
45
setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
46
}
47
48
void
ResetWidget
::
setSpacing
(
int
spacing)
49
{
50
layout()->setSpacing(spacing);
51
}
52
53
void
ResetWidget
::setResetEnabled(
bool
enabled)
54
{
55
m_button->setEnabled(enabled);
56
}
57
58
PropertyResetWidget
::PropertyResetWidget(
const
QDesignerFormEditorInterface *core,
59
QtProperty
*property,
QWidget
*editor,
QWidget
*parent)
60
:
ResetWidget
(editor, parent), m_core(core), m_property(property)
61
{
62
connect(
this
, &ResetWidget::reset,
this
, &PropertyResetWidget::emitResetProperty);
63
}
64
65
void
PropertyResetWidget
::emitResetProperty()
66
{
67
emit resetProperty(m_property);
68
}
69
70
static
inline
bool
isModifiedInMultiSelection
(
const
QDesignerFormEditorInterface *core,
71
const
QString &propertyName)
72
{
73
const
QDesignerFormWindowInterface *form = core->formWindowManager()->activeFormWindow();
74
if
(!form)
75
return
false
;
76
const
QDesignerFormWindowCursorInterface *cursor = form->cursor();
77
const
int
selectionSize = cursor->selectedWidgetCount();
78
if
(selectionSize < 2)
79
return
false
;
80
for
(
int
i = 0; i < selectionSize; ++i) {
81
const
QDesignerPropertySheetExtension *sheet =
82
qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(),
83
cursor->selectedWidget(i));
84
const
int
index = sheet->indexOf(propertyName);
85
if
(index >= 0 && sheet->isChanged(index))
86
return
true
;
87
}
88
return
false
;
89
}
90
91
void
PropertyResetWidget
::propertyChanged(
QtProperty
*property)
92
{
93
if
(property == m_property) {
94
// Update the resettable state as the user edits or resets.
95
const
bool
resettable = m_property->isModified()
96
|| isModifiedInMultiSelection(m_core, m_property->propertyName());
97
setResetEnabled(resettable);
98
}
99
}
100
101
DummyEditor
::DummyEditor(
QtProperty
*property,
QWidget
*parent)
102
: QWidget(parent),
103
m_property(property),
104
m_textLabel(
new
QLabel(
this
)),
105
m_iconLabel(
new
QLabel(
this
))
106
{
107
m_textLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
108
m_iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
109
QLayout *layout =
new
QHBoxLayout(
this
);
110
layout->setContentsMargins({});
111
layout->addWidget(m_iconLabel);
112
layout->addWidget(m_textLabel);
113
}
114
115
void
DummyEditor
::
setSpacing
(
int
spacing)
116
{
117
layout()->setSpacing(spacing);
118
}
119
120
void
DummyEditor
::setValueIcon(
const
QIcon &icon)
121
{
122
QPixmap pix = icon.pixmap(QtPropertyBrowserUtils::itemViewIconSize, devicePixelRatioF());
123
m_iconLabel->setVisible(!pix.isNull());
124
m_iconLabel->setPixmap(pix);
125
}
126
127
void
DummyEditor
::propertyChanged(
QtProperty
*property)
128
{
129
if
(m_property == property) {
130
m_textLabel->setText(property->valueText());
131
setValueIcon(property->valueIcon());
132
}
133
}
134
135
}
// namespace qdesigner_internal
136
137
QT_END_NAMESPACE
QPainter::QWidget
friend class QWidget
Definition
qpainter.h:432
QtProperty
The QtProperty class encapsulates an instance of a property.
Definition
qtpropertybrowser_p.h:29
qdesigner_internal::DummyEditor
Definition
resetdecorator.h:65
qdesigner_internal::DummyEditor::setSpacing
void setSpacing(int spacing)
Definition
resetdecorator.cpp:115
qdesigner_internal::PropertyResetWidget
Definition
resetdecorator.h:41
qdesigner_internal::ResetWidget
Definition
resetdecorator.h:23
qdesigner_internal::ResetWidget::setSpacing
void setSpacing(int spacing)
Definition
resetdecorator.cpp:48
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
qdesigner_internal::isModifiedInMultiSelection
static bool isModifiedInMultiSelection(const QDesignerFormEditorInterface *core, const QString &propertyName)
Definition
resetdecorator.cpp:70
qttools
src
designer
src
components
propertyeditor
resetdecorator.cpp
Generated on
for Qt by
1.18.0