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