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
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
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
25
26namespace qdesigner_internal {
27
28using namespace Qt::StringLiterals;
29
30ResetWidget::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
48void ResetWidget::setSpacing(int spacing)
49{
50 layout()->setSpacing(spacing);
51}
52
53void ResetWidget::setResetEnabled(bool enabled)
54{
55 m_button->setEnabled(enabled);
56}
57
58PropertyResetWidget::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
65void PropertyResetWidget::emitResetProperty()
66{
67 emit resetProperty(m_property);
68}
69
70static 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
91void 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
101DummyEditor::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
115void DummyEditor::setSpacing(int spacing)
116{
117 layout()->setSpacing(spacing);
118}
119
120void 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
127void 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
137QT_END_NAMESPACE
friend class QWidget
Definition qpainter.h:432
The QtProperty class encapsulates an instance of a property.
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static bool isModifiedInMultiSelection(const QDesignerFormEditorInterface *core, const QString &propertyName)