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>
15#include <QtDesigner/abstractformeditor.h>
16#include <QtDesigner/qextensionmanager.h>
17#include <QtDesigner/propertysheet.h>
19#include <QtWidgets/qboxlayout.h>
20#include <QtWidgets/qlabel.h>
21#include <QtWidgets/qtoolbutton.h>
32 m_textLabel(
new QLabel(
this)),
33 m_iconLabel(
new QLabel(
this)),
34 m_button(
new QToolButton(
this))
36 m_textLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed));
37 m_iconLabel->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
38 m_button->setToolButtonStyle(Qt::ToolButtonIconOnly);
39 m_button->setIcon(createIconSet(
"resetproperty.png"_L1));
40 m_button->setIconSize(QSize(8,8));
41 m_button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
42 connect(m_button, &QAbstractButton::clicked,
this, &ResetWidget::slotClicked);
43 QLayout *layout =
new QHBoxLayout(
this);
44 layout->setContentsMargins(QMargins());
45 layout->setSpacing(m_spacing);
46 layout->addWidget(m_iconLabel);
47 layout->addWidget(m_textLabel);
48 layout->addWidget(m_button);
49 setFocusProxy(m_textLabel);
50 setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
56 layout()->setSpacing(m_spacing);
63 m_textLabel =
nullptr;
67 m_iconLabel =
nullptr;
70 QLayout *layout =
new QHBoxLayout(
this);
71 layout->setContentsMargins(QMargins());
72 layout->setSpacing(m_spacing);
73 layout->addWidget(widget);
74 layout->addWidget(m_button);
75 setFocusProxy(widget);
80 m_button->setEnabled(enabled);
86 m_textLabel->setText(text);
91 QPixmap pix = icon.pixmap(QtPropertyBrowserUtils::itemViewIconSize, devicePixelRatioF());
93 m_iconLabel->setVisible(!pix.isNull());
94 m_iconLabel->setPixmap(pix);
100 emit resetProperty(m_property);
103ResetDecorator::ResetDecorator(
const QDesignerFormEditorInterface *core, QObject *parent)
111 const auto editors = m_resetWidgetToProperty.keys();
118 this, &ResetDecorator::slotPropertyChanged);
124 this, &ResetDecorator::slotPropertyChanged);
133 const QString &propertyName)
135 const QDesignerFormWindowInterface *form = core->formWindowManager()->activeFormWindow();
138 const QDesignerFormWindowCursorInterface *cursor = form->cursor();
139 const int selectionSize = cursor->selectedWidgetCount();
140 if (selectionSize < 2)
142 for (
int i = 0; i < selectionSize; ++i) {
143 const QDesignerPropertySheetExtension *sheet =
144 qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(),
145 cursor->selectedWidget(i));
146 const int index = sheet->indexOf(propertyName);
147 if (index >= 0 && sheet->isChanged(index))
160 resetWidget =
new ResetWidget(property, parent);
163 resetWidget->setValueText(property->valueText());
164 resetWidget->setValueIcon(property->valueIcon());
165 resetWidget->setAutoFillBackground(
true);
166 connect(resetWidget, &QObject::destroyed,
this, &ResetDecorator::slotEditorDestroyed);
167 connect(resetWidget, &ResetWidget::resetProperty,
this, &ResetDecorator::resetProperty);
168 m_createdResetWidgets[property].append(resetWidget);
169 m_resetWidgetToProperty[resetWidget] = property;
173 subEditor->setParent(resetWidget);
174 resetWidget->setWidget(subEditor);
184 const auto prIt = m_createdResetWidgets.constFind(property);
185 if (prIt == m_createdResetWidgets.constEnd())
188 for (ResetWidget *widget : prIt.value()) {
189 widget->setResetEnabled(property->isModified()
190 || isModifiedInMultiSelection(m_core, property->propertyName()));
191 widget->setValueText(property->valueText());
192 widget->setValueIcon(property->valueIcon());
198 for (
auto itEditor = m_resetWidgetToProperty.cbegin(), cend = m_resetWidgetToProperty.cend(); itEditor != cend; ++itEditor) {
199 if (itEditor.key() == object) {
202 m_resetWidgetToProperty.remove(editor);
203 m_createdResetWidgets[property].removeAll(editor);
204 if (m_createdResetWidgets[property].isEmpty())
205 m_createdResetWidgets.remove(property);
The QtAbstractPropertyManager provides an interface for property managers.
void propertyChanged(QtProperty *property)
This signal is emitted whenever a property's data changes, passing a pointer to the property as param...
The QtProperty class encapsulates an instance of a property.
bool isModified() const
Returns whether the property is modified.
void connectPropertyManager(QtAbstractPropertyManager *manager)
void setSpacing(int spacing)
~ResetDecorator() override
void disconnectPropertyManager(QtAbstractPropertyManager *manager)
QWidget * editor(QWidget *subEditor, bool resettable, QtAbstractPropertyManager *manager, QtProperty *property, QWidget *parent)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static bool isModifiedInMultiSelection(const QDesignerFormEditorInterface *core, const QString &propertyName)