2019-10-06 14:12:52 +08:00
|
|
|
#include "toolbutton.h"
|
|
|
|
|
2019-10-06 14:58:01 +08:00
|
|
|
#include "opacityhelper.h"
|
|
|
|
|
2019-10-06 14:12:52 +08:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QGraphicsOpacityEffect>
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
2020-07-04 13:49:12 +08:00
|
|
|
ToolButton::ToolButton(bool hoverColor, QWidget *parent)
|
2019-10-06 14:12:52 +08:00
|
|
|
: QPushButton(parent)
|
2019-10-06 14:58:01 +08:00
|
|
|
, m_opacityHelper(new OpacityHelper(this))
|
2019-10-06 14:12:52 +08:00
|
|
|
{
|
|
|
|
setFlat(true);
|
2020-07-04 13:49:12 +08:00
|
|
|
QString qss = "QPushButton {"
|
2019-10-06 14:12:52 +08:00
|
|
|
"background: transparent;"
|
2020-07-04 13:49:12 +08:00
|
|
|
"}";
|
|
|
|
if (hoverColor) {
|
|
|
|
qss += "QPushButton:hover {"
|
|
|
|
"background: red;"
|
|
|
|
"}";
|
|
|
|
}
|
|
|
|
setStyleSheet(qss);
|
2019-10-06 14:12:52 +08:00
|
|
|
}
|
|
|
|
|
2019-10-06 14:58:01 +08:00
|
|
|
void ToolButton::setOpacity(qreal opacity, bool animated)
|
2019-10-06 14:12:52 +08:00
|
|
|
{
|
2019-10-06 14:58:01 +08:00
|
|
|
m_opacityHelper->setOpacity(opacity, animated);
|
2019-10-06 14:12:52 +08:00
|
|
|
}
|