-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
188 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "cool_progressbar.h" | ||
#include <QDebug> | ||
#include <QPainter> | ||
#include <QStyleOption> | ||
|
||
|
||
coolProgressBar::coolProgressBar(const QColor& backgroundColor, | ||
const QColor& animatedColor, | ||
int animationTimeMs, | ||
QWidget* parent) { | ||
setVisible(false); | ||
m_backgroundColor = backgroundColor; | ||
m_animatedColor = animatedColor; | ||
m_animationTimeMs = animationTimeMs; | ||
QString styleBack( | ||
" background-color: %1;" | ||
" border-radius: 1px;" | ||
" border: none;" | ||
); | ||
setStyleSheet(styleBack.arg(m_backgroundColor.name())); | ||
|
||
|
||
QWidget* movingSquare = new QWidget(this); | ||
|
||
m_movingSquare = movingSquare; | ||
QString styleMoving( | ||
" background-color: %1;" | ||
" border-radius: 1px;" | ||
" border: none;" | ||
); | ||
m_movingSquare->setStyleSheet(styleMoving.arg(m_animatedColor.name())); | ||
|
||
m_animation = new QPropertyAnimation(m_movingSquare, "geometry"); | ||
m_animation->setDuration(m_animationTimeMs); | ||
m_animation->setLoopCount(-1); | ||
} | ||
|
||
void coolProgressBar::startAnimation() { | ||
m_animation->setStartValue(QRect(-m_movingSquare->width(), | ||
m_movingSquare->y(), | ||
m_movingSquare->width(), | ||
m_movingSquare->height())); | ||
m_animation->setEndValue(QRect(width(), | ||
m_movingSquare->y(), | ||
m_movingSquare->width(), | ||
m_movingSquare->height())); | ||
m_animation->setEasingCurve(QEasingCurve::InOutCubic); | ||
m_animation->start(); | ||
setVisible(true); | ||
} | ||
|
||
void coolProgressBar::stopAnimation() { | ||
m_animation->stop(); | ||
setVisible(false); | ||
} | ||
|
||
void coolProgressBar::paintEvent(QPaintEvent* event) { | ||
QStyleOption opt; | ||
opt.init(this); | ||
QPainter p(this); | ||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); | ||
} | ||
|
||
void coolProgressBar::showEvent(QShowEvent* event) { | ||
qDebug() << width(); | ||
m_movingSquare->setGeometry(0, 0, width() / 2, height()); | ||
qDebug() << "blue - " << m_movingSquare->geometry(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef COOLPROGRESSBAR_H | ||
#define COOLPROGRESSBAR_H | ||
|
||
#include <QObject> | ||
#include <QWidget> | ||
#include <QPropertyAnimation> | ||
|
||
class coolProgressBar : public QWidget { | ||
Q_OBJECT | ||
public: | ||
explicit coolProgressBar(const QColor& backgroundColor, | ||
const QColor& animatedColor, | ||
int animationTimeMs, | ||
QWidget* parent = nullptr); | ||
public slots: | ||
void startAnimation(); | ||
void stopAnimation(); | ||
protected: | ||
void paintEvent(QPaintEvent* event) override; | ||
void showEvent(QShowEvent* event) override; | ||
private: | ||
QColor m_backgroundColor; | ||
QColor m_animatedColor; | ||
int m_animationTimeMs; | ||
QWidget* m_movingSquare; | ||
QPropertyAnimation* m_animation; | ||
}; | ||
|
||
#endif // COOLPROGRESSBAR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters