2022-06-19 16:17:38 +08:00
|
|
|
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2019-10-06 14:12:52 +08:00
|
|
|
#include "toolbutton.h"
|
|
|
|
|
2022-09-29 13:11:21 +08:00
|
|
|
#include "actionmanager.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
|
|
|
}
|
|
|
|
|
2022-09-29 13:11:21 +08:00
|
|
|
void ToolButton::setIconResourcePath(const QString &iconp)
|
|
|
|
{
|
|
|
|
this->setIcon(ActionManager::loadHidpiIcon(iconp, this->iconSize()));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|