StateIcon improvements
This commit is contained in:
@@ -94,7 +94,7 @@ void IconedLabel::setDirection(IconedLabel::Direction d) {
|
|||||||
lay->setContentsMargins(0, 0, 0, 0);
|
lay->setContentsMargins(0, 0, 0, 0);
|
||||||
setLayout(lay);
|
setLayout(lay);
|
||||||
checkSpacing();
|
checkSpacing();
|
||||||
update();
|
updateGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <QDesignerFormWindowCursorInterface>
|
#include <QDesignerFormWindowCursorInterface>
|
||||||
#include <QDesignerFormWindowInterface>
|
#include <QDesignerFormWindowInterface>
|
||||||
#include <QExtensionManager>
|
#include <QExtensionManager>
|
||||||
|
#include <QTimer>
|
||||||
#include <QtCore/QtPlugin>
|
#include <QtCore/QtPlugin>
|
||||||
#include <private/qtresourceview_p.h>
|
#include <private/qtresourceview_p.h>
|
||||||
|
|
||||||
@@ -133,7 +134,14 @@ bool StateIconPlugin::isInitialized() const {
|
|||||||
|
|
||||||
|
|
||||||
QWidget * StateIconPlugin::createWidget(QWidget * parent) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,16 @@ void StateIcon::prepare() {
|
|||||||
void StateIcon::setState(int newState) {
|
void StateIcon::setState(int newState) {
|
||||||
m_state = newState;
|
m_state = newState;
|
||||||
auto cv = prepared_states.value(m_state);
|
auto cv = prepared_states.value(m_state);
|
||||||
setText(cv.first);
|
if (m_changeText) setText(cv.first);
|
||||||
setIcon(cv.second);
|
if (m_changeIcon) setIcon(cv.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StateIcon::setChangeIcon(bool newChangeIcon) {
|
||||||
|
m_changeIcon = newChangeIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void StateIcon::setChangeText(bool newChangeText) {
|
||||||
|
m_changeText = newChangeText;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class QAD_WIDGETS_EXPORT StateIcon: public IconedLabel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString rawStates READ saveStates WRITE loadStates DESIGNABLE false)
|
Q_PROPERTY(QString rawStates READ saveStates WRITE loadStates DESIGNABLE false)
|
||||||
Q_PROPERTY(int state READ state WRITE setState)
|
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:
|
public:
|
||||||
explicit StateIcon(QWidget * parent = nullptr);
|
explicit StateIcon(QWidget * parent = nullptr);
|
||||||
@@ -39,10 +41,16 @@ public:
|
|||||||
void clearStates();
|
void clearStates();
|
||||||
void addState(int st, QString text, QIcon icon);
|
void addState(int st, QString text, QIcon icon);
|
||||||
void addState(int st, QString text, QString icon_path);
|
void addState(int st, QString text, QString icon_path);
|
||||||
|
|
||||||
QList<int> allStates() const;
|
QList<int> allStates() const;
|
||||||
QString stateText(int st) const;
|
QString stateText(int st) const;
|
||||||
QString stateIcon(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; }
|
int state() const { return m_state; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -50,7 +58,8 @@ private:
|
|||||||
|
|
||||||
QMap<int, QPair<QString, QString>> src_states;
|
QMap<int, QPair<QString, QString>> src_states;
|
||||||
QMap<int, QPair<QString, QIcon>> prepared_states;
|
QMap<int, QPair<QString, QIcon>> prepared_states;
|
||||||
int m_state = 0;
|
int m_state = 0;
|
||||||
|
bool m_changeIcon = true, m_changeText = true;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setState(int newState);
|
void setState(int newState);
|
||||||
|
|||||||
Reference in New Issue
Block a user