From 6a87a9933ceae1bcb88bdc4fbced68836a6f22fd Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Sun, 10 Jun 2012 21:15:22 +0300 Subject: [PATCH] Changed: #1302 Added signal 'reset bool property' for returning to default value --- .../images/resetproperty.png | Bin 0 -> 169 bytes .../qtpropertybrowser/qteditorfactory.cpp | 29 ++++++++++++++++-- .../qtpropertybrowser/qteditorfactory.h | 1 + .../qtpropertybrowser/qtpropertybrowser.qrc | 1 + .../qtpropertybrowserutils.cpp | 13 +++++++- .../qtpropertybrowserutils_p.h | 2 ++ .../qtpropertybrowser/qtpropertymanager.cpp | 5 +++ .../qtpropertybrowser/qtpropertymanager.h | 4 +++ 8 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/images/resetproperty.png diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/images/resetproperty.png b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/images/resetproperty.png new file mode 100644 index 0000000000000000000000000000000000000000..9048252ec2a51e7ee3461b72ba31fcabb2f10027 GIT binary patch literal 169 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)M!VDz;D$H~RQtAOdA+G=b|DVXfKoI@;pQ;7a z!c!9D7tA1OVDFM#)bRFI`d!AXvO1u+s;7%%2#0KP!Un;Fgaq5gCk{*~e&)l-9KQS# jBO6=3qr$;M$qWpMPuN;S?ziRvH86O(`njxgN@xNAXMir1 literal 0 HcmV?d00001 diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp index 3a1e874eb..c1a10ff0a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.cpp @@ -659,6 +659,7 @@ class QtCheckBoxFactoryPrivate : public EditorFactoryPrivate public: void slotPropertyChanged(QtProperty *property, bool value); void slotSetValue(bool value); + void slotReset(); }; void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool value) @@ -669,6 +670,7 @@ void QtCheckBoxFactoryPrivate::slotPropertyChanged(QtProperty *property, bool va QListIterator itEditor(m_createdEditors[property]); while (itEditor.hasNext()) { QtBoolEdit *editor = itEditor.next(); + editor->setStateResetButton(property->isModified()); editor->blockCheckBoxSignals(true); editor->setChecked(value); editor->blockCheckBoxSignals(false); @@ -691,6 +693,22 @@ void QtCheckBoxFactoryPrivate::slotSetValue(bool value) } } +void QtCheckBoxFactoryPrivate::slotReset() +{ + QObject *object = q_ptr->sender(); + + const QMap::ConstIterator ecend = m_editorToProperty.constEnd(); + for (QMap::ConstIterator itEditor = m_editorToProperty.constBegin(); itEditor != ecend; ++itEditor) + if (itEditor.key() == object) { + QtProperty *property = itEditor.value(); + QtBoolPropertyManager *manager = q_ptr->propertyManager(property); + if (!manager) + return; + manager->setResetProperty(property); + return; + } +} + /*! \class QtCheckBoxFactory @@ -740,8 +758,10 @@ QWidget *QtCheckBoxFactory::createEditor(QtBoolPropertyManager *manager, QtPrope QWidget *parent) { QtBoolEdit *editor = d_ptr->createEditor(property, parent); + editor->setStateResetButton(property->isModified()); editor->setChecked(manager->value(property)); + connect(editor, SIGNAL(resetProperty()), this, SLOT(slotReset())); connect(editor, SIGNAL(toggled(bool)), this, SLOT(slotSetValue(bool))); connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *))); @@ -2645,10 +2665,15 @@ QtTextEditWidget::QtTextEditWidget(QWidget *parent) : m_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); m_button->setFixedWidth(20); - setFocusProxy(m_button); - setFocusPolicy(m_button->focusPolicy()); m_button->setText(tr("...")); m_button->installEventFilter(this); + + setFocusProxy(m_button); + setFocusPolicy(m_button->focusPolicy()); + + m_defaultButton->setIcon(QIcon(":/trolltech/qtpropertybrowser/images/resetproperty.png")); + m_defaultButton->setMaximumWidth(16); + connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked())); lt->addWidget(m_button); lt->addWidget(m_defaultButton); diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h index de79a7a4a..58f64b2af 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qteditorfactory.h @@ -186,6 +186,7 @@ private: Q_PRIVATE_SLOT(d_func(), void slotPropertyChanged(QtProperty *, bool)) Q_PRIVATE_SLOT(d_func(), void slotSetValue(bool)) Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed(QObject *)) + Q_PRIVATE_SLOT(d_func(), void slotReset()) }; class QtDoubleSpinBoxFactoryPrivate; diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.qrc b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.qrc index 4f91ab782..50c2479f2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.qrc +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowser.qrc @@ -18,6 +18,7 @@ images/cursor-vsplit.png images/cursor-wait.png images/cursor-whatsthis.png + images/resetproperty.png diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils.cpp b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils.cpp index 0198c3c5f..9b482a569 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils.cpp @@ -264,6 +264,10 @@ QtBoolEdit::QtBoolEdit(QWidget *parent) : m_defaultButton(new QToolButton(this)), m_textVisible(true) { + m_defaultButton->setIcon(QIcon(":/trolltech/qtpropertybrowser/images/resetproperty.png")); + m_defaultButton->setMaximumWidth(16); + m_defaultButton->setEnabled(false); + QHBoxLayout *lt = new QHBoxLayout; if (QApplication::layoutDirection() == Qt::LeftToRight) lt->setContentsMargins(4, 0, 0, 0); @@ -271,9 +275,11 @@ QtBoolEdit::QtBoolEdit(QWidget *parent) : lt->setContentsMargins(0, 0, 4, 0); lt->addWidget(m_checkBox); lt->addWidget(m_defaultButton); - m_defaultButton->setEnabled(false); setLayout(lt); + connect(m_checkBox, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool))); + connect(m_defaultButton, SIGNAL(clicked()), this, SIGNAL(resetProperty())); + setFocusProxy(m_checkBox); m_checkBox->setText(QString()); } @@ -297,6 +303,11 @@ void QtBoolEdit::setCheckState(Qt::CheckState state) m_checkBox->setCheckState(state); } +void QtBoolEdit::setStateResetButton(bool enabled) +{ + m_defaultButton->setEnabled(enabled); +} + bool QtBoolEdit::isChecked() const { return m_checkBox->isChecked(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils_p.h b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils_p.h index 9fc851f16..66156c5d4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils_p.h +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertybrowserutils_p.h @@ -155,6 +155,7 @@ public: Qt::CheckState checkState() const; void setCheckState(Qt::CheckState state); + void setStateResetButton(bool enabled); bool isChecked() const; void setChecked(bool c); @@ -163,6 +164,7 @@ public: Q_SIGNALS: void toggled(bool); + void resetProperty(); protected: void mousePressEvent(QMouseEvent * event); diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp index fe8ea92c9..6b2d24c80 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.cpp @@ -1588,6 +1588,11 @@ void QtBoolPropertyManager::setValue(QtProperty *property, bool val) property, val); } +void QtBoolPropertyManager::setResetProperty(QtProperty *property) +{ + emit resetProperty(property); +} + /*! \reimp */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h index 21fd57d6f..958b22dc8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h +++ b/code/nel/tools/3d/object_viewer_qt/src/3rdparty/qtpropertybrowser/qtpropertymanager.h @@ -160,8 +160,12 @@ public: public Q_SLOTS: void setValue(QtProperty *property, bool val); + void setResetProperty(QtProperty *property); + Q_SIGNALS: void valueChanged(QtProperty *property, bool val); + void resetProperty(QtProperty *property); + protected: QString valueText(const QtProperty *property) const; QIcon valueIcon(const QtProperty *property) const;