-
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
19 changed files
with
997 additions
and
61 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "animated_button.h" | ||
#include <QTimer> | ||
#include <QDebug> | ||
#include <QPropertyAnimation> | ||
|
||
QString buttonStyle( | ||
"QPushButton {" | ||
" background-color: %1;" | ||
" border: none;" | ||
" color:white;" // text color | ||
" text-align: center;" | ||
" font-size: 13px;" | ||
" border-radius: 14px;" | ||
"}" | ||
); | ||
|
||
|
||
AnimatedButton::AnimatedButton(const QString& text, QColor startColor, QColor endColor, QWidget* parent) : QPushButton(text, parent) { | ||
setStyleSheet(buttonStyle.arg(startColor.name())); | ||
m_startColor = startColor; | ||
m_endColor = endColor; | ||
connect(this, &QPushButton::pressed, this, &AnimatedButton::animateButtonPress); | ||
connect(this, &QPushButton::released, this, &AnimatedButton::animateButtonRelease); | ||
} | ||
|
||
void AnimatedButton::enterEvent(QEvent* event) { | ||
QPropertyAnimation* animation = new QPropertyAnimation(this, "backgroundColor"); | ||
animation->setDuration(250); | ||
animation->setStartValue(m_startColor); | ||
animation->setEndValue(m_endColor); | ||
animation->start(QAbstractAnimation::DeleteWhenStopped); | ||
QPushButton::enterEvent(event); | ||
QPushButton::enterEvent(event); | ||
} | ||
|
||
void AnimatedButton::leaveEvent(QEvent* event) { | ||
QPropertyAnimation* animation = new QPropertyAnimation(this, "backgroundColor"); | ||
animation->setDuration(250); | ||
animation->setStartValue(m_endColor); | ||
animation->setEndValue(m_startColor); | ||
animation->start(QAbstractAnimation::DeleteWhenStopped); | ||
QPushButton::leaveEvent(event); | ||
} | ||
|
||
void AnimatedButton::animateButtonPress() { | ||
QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry"); | ||
animation->setDuration(100); | ||
animation->setStartValue(geometry()); | ||
animation->setEndValue(QRect(m_originalGeometry.x(), m_originalGeometry.y() + 5, | ||
m_originalGeometry.width(), m_originalGeometry.height())); | ||
animation->start(QAbstractAnimation::DeleteWhenStopped); | ||
} | ||
|
||
void AnimatedButton::animateButtonRelease() { | ||
QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry"); | ||
animation->setDuration(100); | ||
animation->setStartValue(geometry()); | ||
animation->setEndValue(m_originalGeometry); | ||
animation->start(QAbstractAnimation::DeleteWhenStopped); | ||
} | ||
|
||
|
||
void AnimatedButton::setOriginalGeometry(const QRect& newOriginalGeometry) { | ||
m_originalGeometry = newOriginalGeometry; | ||
} | ||
|
||
QColor AnimatedButton::backgroundColor() const { | ||
return m_backgroundColor; | ||
} | ||
|
||
void AnimatedButton::setBackgroundColor(const QColor& color) { | ||
m_backgroundColor = color; | ||
setStyleSheet(buttonStyle.arg(color.name())); | ||
} |
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,42 @@ | ||
#ifndef ANIMATED_BUTTON_H | ||
#define ANIMATED_BUTTON_H | ||
#include <QApplication> | ||
#include <QPushButton> | ||
#include <QPropertyAnimation> | ||
#include <QGraphicsColorizeEffect> | ||
#include <QEvent> | ||
|
||
class AnimatedButton : public QPushButton { | ||
Q_OBJECT | ||
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) | ||
|
||
public: | ||
AnimatedButton(const QString& text, QColor startColor, QColor endColor, QWidget* parent = nullptr); | ||
|
||
void setOriginalGeometry(const QRect& newOriginalGeometry); | ||
|
||
QColor backgroundColor() const; | ||
|
||
void setBackgroundColor(const QColor& color); | ||
|
||
protected: | ||
void enterEvent(QEvent* event) override; | ||
|
||
void leaveEvent(QEvent* event) override; | ||
|
||
private slots: | ||
void animateButtonPress(); | ||
|
||
void animateButtonRelease(); | ||
|
||
private: | ||
QColor m_startColor; | ||
QColor m_endColor; | ||
QColor m_backgroundColor; | ||
QRect m_originalGeometry; | ||
}; | ||
|
||
|
||
|
||
|
||
#endif // ANIMATED_BUTTON_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
"dd/MM/yyyy hh:mm", | ||
"yyyy/MM/dd hh:mm:ss", | ||
"yyyy.MM.dd_hh:mm:ss", | ||
"yyyy/MM/dd hh_mm_ss" | ||
] |
Oops, something went wrong.