2021-07-31 16:12:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "action-label.h"
|
|
|
|
#define ACTION_NORMAL_COLOR QColor(55, 144, 250, 255)
|
|
|
|
#define ACTION_HOVER_COLOR QColor(64, 169, 251, 255)
|
|
|
|
#define ACTION_PRESS_COLOR QColor(41, 108, 217, 255)
|
2021-12-14 14:43:35 +08:00
|
|
|
using namespace UkuiSearch;
|
2022-07-06 14:29:05 +08:00
|
|
|
ActionLabel::ActionLabel(const QString &action, const QString &key, QWidget *parent) : KBorderlessButton(parent)
|
2021-07-31 16:12:04 +08:00
|
|
|
{
|
|
|
|
m_action = action;
|
|
|
|
m_key = key;
|
|
|
|
this->initUi();
|
|
|
|
this->installEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionLabel::initUi()
|
|
|
|
{
|
|
|
|
this->setText(m_action);
|
2022-07-06 14:29:05 +08:00
|
|
|
// QPalette pal = palette();
|
|
|
|
// pal.setColor(QPalette::WindowText, ACTION_NORMAL_COLOR);
|
|
|
|
// pal.setColor(QPalette::Light, ACTION_HOVER_COLOR);
|
|
|
|
// pal.setColor(QPalette::Dark, ACTION_PRESS_COLOR);
|
|
|
|
// this->setPalette(pal);
|
|
|
|
// this->setForegroundRole(QPalette::WindowText);
|
2021-07-31 16:12:04 +08:00
|
|
|
this->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ActionLabel::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
if (watched == this) {
|
2022-07-06 14:29:05 +08:00
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
2021-07-31 16:12:04 +08:00
|
|
|
Q_EMIT this->actionTriggered(m_action);
|
2022-07-06 14:29:05 +08:00
|
|
|
return false;
|
2021-07-31 16:12:04 +08:00
|
|
|
}
|
|
|
|
}
|
2022-07-06 14:29:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
// if (watched == this) {
|
|
|
|
// if(event->type() == QEvent::MouseButtonPress) {
|
|
|
|
// this->setForegroundRole(QPalette::Dark);
|
|
|
|
// return true;
|
|
|
|
// } else if(event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
// Q_EMIT this->actionTriggered(m_action);
|
|
|
|
// this->setForegroundRole(QPalette::Light);
|
|
|
|
// return true;
|
|
|
|
// } else if(event->type() == QEvent::Enter) {
|
|
|
|
// this->setForegroundRole(QPalette::Light);
|
|
|
|
// return true;
|
|
|
|
// } else if(event->type() == QEvent::Leave) {
|
|
|
|
// this->setForegroundRole(QPalette::WindowText);
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
return KBorderlessButton::eventFilter(watched, event);
|
2021-07-31 16:12:04 +08:00
|
|
|
}
|