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