Moved disabled SVG widget functionality to SvgWidget class
This commit is contained in:
@@ -22,15 +22,6 @@ namespace Bloom::Widgets
|
||||
int buttonWidth = 0;
|
||||
int buttonHeight = 0;
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent* event) override {
|
||||
if (event->type() == QEvent::EnabledChange && this->disabledSvgWidget != nullptr) {
|
||||
auto enabled = this->isEnabled();
|
||||
this->svgWidget->setVisible(enabled);
|
||||
this->disabledSvgWidget->setVisible(!enabled);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
explicit SvgToolButton(QWidget* parent): QToolButton(parent) {
|
||||
this->setButtonWidth(10);
|
||||
@@ -46,31 +37,17 @@ namespace Bloom::Widgets
|
||||
}
|
||||
|
||||
void setDisabledSvgFilePath(const QString& disabledSvgFilePath) {
|
||||
if (this->disabledSvgWidget == nullptr) {
|
||||
this->disabledSvgWidget = new SvgWidget(this);
|
||||
this->disabledSvgWidget->setContainerWidth(this->buttonWidth);
|
||||
this->disabledSvgWidget->setContainerHeight(this->buttonHeight);
|
||||
}
|
||||
|
||||
this->disabledSvgWidget->setSvgFilePath(disabledSvgFilePath);
|
||||
this->svgWidget->setDisabledSvgFilePath(disabledSvgFilePath);
|
||||
}
|
||||
|
||||
[[nodiscard]] QString getDisabledSvgFilePath() const {
|
||||
if (this->disabledSvgWidget != nullptr) {
|
||||
return this->disabledSvgWidget->getSvgFilePath();
|
||||
}
|
||||
|
||||
return QString();
|
||||
return this->svgWidget->getDisabledSvgFilePath();
|
||||
}
|
||||
|
||||
void setButtonWidth(int buttonWidth) {
|
||||
this->buttonWidth = buttonWidth;
|
||||
this->setFixedWidth(buttonWidth);
|
||||
this->svgWidget->setContainerWidth(buttonWidth);
|
||||
|
||||
if (this->disabledSvgWidget != nullptr) {
|
||||
this->disabledSvgWidget->setContainerWidth(buttonWidth);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] int getButtonWidth() const {
|
||||
@@ -81,10 +58,6 @@ namespace Bloom::Widgets
|
||||
this->buttonHeight = buttonHeight;
|
||||
this->setFixedHeight(buttonHeight);
|
||||
this->svgWidget->setContainerHeight(buttonHeight);
|
||||
|
||||
if (this->disabledSvgWidget != nullptr) {
|
||||
this->disabledSvgWidget->setContainerHeight(buttonHeight);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] int getButtonHeight() const {
|
||||
|
||||
@@ -41,3 +41,16 @@ void SvgWidget::paintEvent(QPaintEvent* paintEvent) {
|
||||
svgSize.height()
|
||||
));
|
||||
}
|
||||
|
||||
void SvgWidget::changeEvent(QEvent* event) {
|
||||
if (event->type() == QEvent::EnabledChange && !this->disabledSvgFilePath.isEmpty()) {
|
||||
if (!this->isEnabled()) {
|
||||
this->renderer.load(this->disabledSvgFilePath);
|
||||
|
||||
} else {
|
||||
this->renderer.load(this->svgFilePath);
|
||||
}
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QFrame>
|
||||
#include <QSvgRenderer>
|
||||
#include <QString>
|
||||
#include <QEvent>
|
||||
#include <QSize>
|
||||
|
||||
namespace Bloom::Widgets
|
||||
@@ -11,6 +12,7 @@ namespace Bloom::Widgets
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString svgFilePath READ getSvgFilePath WRITE setSvgFilePath DESIGNABLE true)
|
||||
Q_PROPERTY(QString disabledSvgFilePath READ getDisabledSvgFilePath WRITE setDisabledSvgFilePath DESIGNABLE true)
|
||||
Q_PROPERTY(int containerWidth READ getContainerWidth WRITE setContainerWidth DESIGNABLE true)
|
||||
Q_PROPERTY(int containerHeight READ getContainerHeight WRITE setContainerHeight DESIGNABLE true)
|
||||
Q_PROPERTY(int angle READ getAngle WRITE setAngle DESIGNABLE true)
|
||||
@@ -18,12 +20,14 @@ namespace Bloom::Widgets
|
||||
private:
|
||||
QSvgRenderer renderer = new QSvgRenderer(this);
|
||||
QString svgFilePath;
|
||||
QString disabledSvgFilePath;
|
||||
int containerWidth = 0;
|
||||
int containerHeight = 0;
|
||||
int angle = 0;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* paintEvent) override;
|
||||
void changeEvent(QEvent* event) override;
|
||||
|
||||
public:
|
||||
explicit SvgWidget(QWidget* parent);
|
||||
@@ -37,6 +41,14 @@ namespace Bloom::Widgets
|
||||
return this->svgFilePath;
|
||||
}
|
||||
|
||||
void setDisabledSvgFilePath(const QString& disabledSvgFilePath) {
|
||||
this->disabledSvgFilePath = disabledSvgFilePath;
|
||||
}
|
||||
|
||||
[[nodiscard]] QString getDisabledSvgFilePath() const {
|
||||
return this->disabledSvgFilePath;
|
||||
}
|
||||
|
||||
void setContainerWidth(int containerWidth) {
|
||||
this->containerWidth = containerWidth;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user