SvgWidget and SvgToolButton spinning animation support
This commit is contained in:
@@ -56,6 +56,13 @@ namespace Bloom::Widgets
|
|||||||
return this->buttonHeight;
|
return this->buttonHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startSpin() {
|
||||||
|
this->svgWidget->startSpin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopSpin() {
|
||||||
|
this->svgWidget->stopSpin();
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
void childEvent(QChildEvent* childEvent) override;
|
void childEvent(QChildEvent* childEvent) override;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,28 @@ SvgWidget::SvgWidget(QWidget* parent): QFrame(parent) {
|
|||||||
this->renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatioByExpanding);
|
this->renderer.setAspectRatioMode(Qt::AspectRatioMode::KeepAspectRatioByExpanding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SvgWidget::startSpin() {
|
||||||
|
if (this->spinningAnimation == nullptr) {
|
||||||
|
this->spinningAnimation = new QPropertyAnimation(this, "angle", this);
|
||||||
|
this->spinningAnimation->setDuration(2000);
|
||||||
|
this->spinningAnimation->setStartValue(0);
|
||||||
|
this->spinningAnimation->setEndValue(360);
|
||||||
|
|
||||||
|
QObject::connect(this->spinningAnimation, &QPropertyAnimation::finished, this, [this] {
|
||||||
|
this->spinningAnimation->start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this->spinningAnimation->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SvgWidget::stopSpin() {
|
||||||
|
if (this->spinningAnimation != nullptr) {
|
||||||
|
this->spinningAnimation->stop();
|
||||||
|
this->setAngle(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SvgWidget::paintEvent(QPaintEvent* paintEvent) {
|
void SvgWidget::paintEvent(QPaintEvent* paintEvent) {
|
||||||
auto painter = QPainter(this);
|
auto painter = QPainter(this);
|
||||||
auto svgSize = this->renderer.defaultSize();
|
auto svgSize = this->renderer.defaultSize();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
namespace Bloom::Widgets
|
namespace Bloom::Widgets
|
||||||
{
|
{
|
||||||
@@ -57,12 +58,29 @@ namespace Bloom::Widgets
|
|||||||
|
|
||||||
void setAngle(int angle) {
|
void setAngle(int angle) {
|
||||||
this->angle = angle;
|
this->angle = angle;
|
||||||
|
|
||||||
|
if (this->spinningAnimation != nullptr) {
|
||||||
|
this->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] int getAngle() const {
|
[[nodiscard]] int getAngle() const {
|
||||||
return this->angle;
|
return this->angle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a spinning animation, where the widget will rotate on its center, indefinitely.
|
||||||
|
*
|
||||||
|
* This is typically used in SvgToolButton instances, where the spinning of the tool button icon indicates
|
||||||
|
* some action being in progress (see the refresh tool button in the TargetMemoryInspectionPane widget).
|
||||||
|
*/
|
||||||
|
void startSpin();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the spinning animation.
|
||||||
|
*/
|
||||||
|
void stopSpin();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* paintEvent) override;
|
void paintEvent(QPaintEvent* paintEvent) override;
|
||||||
void changeEvent(QEvent* event) override;
|
void changeEvent(QEvent* event) override;
|
||||||
@@ -74,5 +92,6 @@ namespace Bloom::Widgets
|
|||||||
int containerWidth = 0;
|
int containerWidth = 0;
|
||||||
int containerHeight = 0;
|
int containerHeight = 0;
|
||||||
int angle = 0;
|
int angle = 0;
|
||||||
|
QPropertyAnimation* spinningAnimation = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user