7#include <qdesigner_utils_p.h>
8#include <iconloader_p.h>
9#include <formwindowbase_p.h>
10#include <formwindowcursor.h>
11#include <formwindowmanager.h>
12#include <formwindow.h>
14#include <QtDesigner/abstractformeditor.h>
15#include <QtDesigner/qextensionmanager.h>
16#include <QtDesigner/propertysheet.h>
18#include <QtWidgets/qboxlayout.h>
19#include <QtWidgets/qlabel.h>
20#include <QtWidgets/qtoolbutton.h>
31 m_textLabel(
new QLabel(
this)),
32 m_iconLabel(
new QLabel(
this)),
33 m_button(
new QToolButton(
this))
35 m_textLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
36 m_iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
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::slotClicked);
42 QLayout *layout =
new QHBoxLayout(
this);
43 layout->setContentsMargins(QMargins());
44 layout->setSpacing(m_spacing);
45 layout->addWidget(m_iconLabel);
46 layout->addWidget(m_textLabel);
47 layout->addWidget(m_button);
48 setFocusProxy(m_textLabel);
49 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
55 layout()->setSpacing(m_spacing);
62 m_textLabel =
nullptr;
66 m_iconLabel =
nullptr;
69 QLayout *layout =
new QHBoxLayout(
this);
70 layout->setContentsMargins(QMargins());
71 layout->setSpacing(m_spacing);
72 layout->addWidget(widget);
73 layout->addWidget(m_button);
74 setFocusProxy(widget);
79 m_button->setEnabled(enabled);
85 m_textLabel->setText(text);
90 QPixmap pix = icon.pixmap(QSize(16, 16));
92 m_iconLabel->setVisible(!pix.isNull());
93 m_iconLabel->setPixmap(pix);
99 emit resetProperty(m_property);
102ResetDecorator::ResetDecorator(
const QDesignerFormEditorInterface *core, QObject *parent)
110 const auto editors = m_resetWidgetToProperty.keys();
116 connect(manager, &QtAbstractPropertyManager::propertyChanged,
117 this, &ResetDecorator::slotPropertyChanged);
122 disconnect(manager, &QtAbstractPropertyManager::propertyChanged,
123 this, &ResetDecorator::slotPropertyChanged);
132 const QString &propertyName)
134 const QDesignerFormWindowInterface *form = core->formWindowManager()->activeFormWindow();
137 const QDesignerFormWindowCursorInterface *cursor = form->cursor();
138 const int selectionSize = cursor->selectedWidgetCount();
139 if (selectionSize < 2)
141 for (
int i = 0; i < selectionSize; ++i) {
142 const QDesignerPropertySheetExtension *sheet =
143 qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(),
144 cursor->selectedWidget(i));
145 const int index = sheet->indexOf(propertyName);
146 if (index >= 0 && sheet->isChanged(index))
159 resetWidget =
new ResetWidget(property, parent);
161 resetWidget->setResetEnabled(property->isModified() || isModifiedInMultiSelection(m_core, property->propertyName()));
162 resetWidget->setValueText(property->valueText());
163 resetWidget->setValueIcon(property->valueIcon());
164 resetWidget->setAutoFillBackground(
true);
165 connect(resetWidget, &QObject::destroyed,
this, &ResetDecorator::slotEditorDestroyed);
166 connect(resetWidget, &ResetWidget::resetProperty,
this, &ResetDecorator::resetProperty);
167 m_createdResetWidgets[property].append(resetWidget);
168 m_resetWidgetToProperty[resetWidget] = property;
172 subEditor->setParent(resetWidget);
173 resetWidget->setWidget(subEditor);
183 const auto prIt = m_createdResetWidgets.constFind(property);
184 if (prIt == m_createdResetWidgets.constEnd())
187 for (ResetWidget *widget : prIt.value()) {
188 widget->setResetEnabled(property->isModified()
189 || isModifiedInMultiSelection(m_core, property->propertyName()));
190 widget->setValueText(property->valueText());
191 widget->setValueIcon(property->valueIcon());
197 for (
auto itEditor = m_resetWidgetToProperty.cbegin(), cend = m_resetWidgetToProperty.cend(); itEditor != cend; ++itEditor) {
198 if (itEditor.key() == object) {
201 m_resetWidgetToProperty.remove(editor);
202 m_createdResetWidgets[property].removeAll(editor);
203 if (m_createdResetWidgets[property].isEmpty())
204 m_createdResetWidgets.remove(property);
The QtAbstractPropertyManager provides an interface for property managers.
The QtProperty class encapsulates an instance of a property.
void connectPropertyManager(QtAbstractPropertyManager *manager)
void setSpacing(int spacing)
void disconnectPropertyManager(QtAbstractPropertyManager *manager)
QWidget * editor(QWidget *subEditor, bool resettable, QtAbstractPropertyManager *manager, QtProperty *property, QWidget *parent)
Auxiliary methods to store/retrieve settings.
static bool isModifiedInMultiSelection(const QDesignerFormEditorInterface *core, const QString &propertyName)