diff --git a/libs/widgets/iconedlabel.cpp b/libs/widgets/iconedlabel.cpp index 49b2c6d..9ae322b 100644 --- a/libs/widgets/iconedlabel.cpp +++ b/libs/widgets/iconedlabel.cpp @@ -94,7 +94,7 @@ void IconedLabel::setDirection(IconedLabel::Direction d) { lay->setContentsMargins(0, 0, 0, 0); setLayout(lay); checkSpacing(); - update(); + updateGeometry(); } diff --git a/libs/widgets/plugin/stateiconplugin.cpp b/libs/widgets/plugin/stateiconplugin.cpp index 07acb19..a74b236 100644 --- a/libs/widgets/plugin/stateiconplugin.cpp +++ b/libs/widgets/plugin/stateiconplugin.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -133,7 +134,14 @@ bool StateIconPlugin::isInitialized() const { QWidget * StateIconPlugin::createWidget(QWidget * parent) { - return new StateIcon(parent); + auto * ret = new StateIcon(parent); + QDesignerFormWindowInterface * formWindow = QDesignerFormWindowInterface::findFormWindow(parent); + if (formWindow) { + connect(formWindow, &QDesignerFormWindowInterface::resourceFilesChanged, ret, [ret] { + QTimer::singleShot(0, ret, [ret] { ret->loadStates(ret->saveStates()); }); + }); + } + return ret; } diff --git a/libs/widgets/stateicon.cpp b/libs/widgets/stateicon.cpp index 81c54ef..62b6ba5 100644 --- a/libs/widgets/stateicon.cpp +++ b/libs/widgets/stateicon.cpp @@ -72,6 +72,16 @@ void StateIcon::prepare() { void StateIcon::setState(int newState) { m_state = newState; auto cv = prepared_states.value(m_state); - setText(cv.first); - setIcon(cv.second); + if (m_changeText) setText(cv.first); + if (m_changeIcon) setIcon(cv.second); +} + + +void StateIcon::setChangeIcon(bool newChangeIcon) { + m_changeIcon = newChangeIcon; +} + + +void StateIcon::setChangeText(bool newChangeText) { + m_changeText = newChangeText; } diff --git a/libs/widgets/stateicon.h b/libs/widgets/stateicon.h index db3812b..bd20508 100644 --- a/libs/widgets/stateicon.h +++ b/libs/widgets/stateicon.h @@ -30,6 +30,8 @@ class QAD_WIDGETS_EXPORT StateIcon: public IconedLabel { Q_OBJECT Q_PROPERTY(QString rawStates READ saveStates WRITE loadStates DESIGNABLE false) Q_PROPERTY(int state READ state WRITE setState) + Q_PROPERTY(bool changeIcon READ isChangeIcon WRITE setChangeIcon) + Q_PROPERTY(bool changeText READ isChangeText WRITE setChangeText) public: explicit StateIcon(QWidget * parent = nullptr); @@ -39,10 +41,16 @@ public: void clearStates(); void addState(int st, QString text, QIcon icon); void addState(int st, QString text, QString icon_path); + QList allStates() const; QString stateText(int st) const; QString stateIcon(int st) const; + bool isChangeIcon() const { return m_changeIcon; } + void setChangeIcon(bool newChangeIcon); + bool isChangeText() const { return m_changeText; } + void setChangeText(bool newChangeText); + int state() const { return m_state; } private: @@ -50,7 +58,8 @@ private: QMap> src_states; QMap> prepared_states; - int m_state = 0; + int m_state = 0; + bool m_changeIcon = true, m_changeText = true; public slots: void setState(int newState);