2021-05-22 21:29:43 +08:00
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2020, 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: zhangjiaping <zhangjiaping@kylinos.cn>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include "show-more-label.h"
|
2023-09-01 17:30:21 +08:00
|
|
|
|
#include "icon-loader.h"
|
2021-05-22 21:29:43 +08:00
|
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QDebug>
|
2021-08-05 15:37:58 +08:00
|
|
|
|
#include <QIcon>
|
2021-12-14 14:43:35 +08:00
|
|
|
|
using namespace UkuiSearch;
|
2021-05-22 21:29:43 +08:00
|
|
|
|
ShowMoreLabel::ShowMoreLabel(QWidget *parent) : QWidget(parent) {
|
|
|
|
|
initUi();
|
|
|
|
|
m_timer = new QTimer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShowMoreLabel::resetLabel() {
|
|
|
|
|
m_isOpen = false;
|
2023-09-01 17:30:21 +08:00
|
|
|
|
m_iconLabel->setPixmap(IconLoader::loadIconQt("ukui-down-symbolic", QIcon(":/res/icons/ukui-down-symbolic.svg")).pixmap(QSize(16, 16)));
|
2021-10-20 16:30:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShowMoreLabel::setLabel()
|
|
|
|
|
{
|
|
|
|
|
m_isOpen = true;
|
2023-09-01 17:30:21 +08:00
|
|
|
|
m_iconLabel->setPixmap(IconLoader::loadIconQt("ukui-up-symbolic", QIcon(":/res/icons/ukui-up-symbolic.svg")).pixmap(QSize(16, 16)));
|
2021-05-22 21:29:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ShowMoreLabel::getExpanded 获取当前是否是展开状态
|
|
|
|
|
* @return true已展开,false已收起
|
|
|
|
|
*/
|
|
|
|
|
bool ShowMoreLabel::getExpanded() {
|
|
|
|
|
return m_isOpen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShowMoreLabel::initUi() {
|
|
|
|
|
QPalette pal = palette();
|
|
|
|
|
pal.setColor(QPalette::WindowText, QColor(55, 144, 250, 255));
|
|
|
|
|
m_layout = new QHBoxLayout(this);
|
|
|
|
|
m_layout->setContentsMargins(0, 0, 0, 6);
|
2021-10-20 16:30:20 +08:00
|
|
|
|
m_iconLabel = new QLabel(this);
|
2023-09-01 17:30:21 +08:00
|
|
|
|
m_iconLabel->setPixmap(IconLoader::loadIconQt("ukui-down-symbolic", QIcon(":/res/icons/ukui-down-symbolic.svg")).pixmap(QSize(16, 16)));
|
2021-10-20 16:30:20 +08:00
|
|
|
|
m_iconLabel->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
m_iconLabel->installEventFilter(this);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
// m_loadingIconLabel = new QLabel(this); //使用图片显示加载状态时,取消此label的注释
|
|
|
|
|
// m_loadingIconLabel->setFixedSize(18, 18);
|
|
|
|
|
// m_loadingIconLabel->hide();
|
2021-08-05 15:37:58 +08:00
|
|
|
|
m_layout->setAlignment(Qt::AlignRight | Qt::AlignTop);
|
2021-10-20 16:30:20 +08:00
|
|
|
|
m_layout->addWidget(m_iconLabel);
|
|
|
|
|
m_iconLabel->setPalette(pal);
|
|
|
|
|
m_iconLabel->setCursor(QCursor(Qt::PointingHandCursor));
|
2023-07-11 10:58:24 +08:00
|
|
|
|
m_iconLabel->setProperty("useIconHighlightEffect", 0x02);
|
2022-05-19 17:54:03 +08:00
|
|
|
|
m_iconLabel->setProperty("iconHighlightEffectMode", 1);
|
2021-05-22 21:29:43 +08:00
|
|
|
|
// m_layout->addWidget(m_loadingIconLabel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ShowMoreLabel::eventFilter(QObject *watched, QEvent *event) {
|
2021-10-20 16:30:20 +08:00
|
|
|
|
if(watched == m_iconLabel) {
|
2021-05-22 21:29:43 +08:00
|
|
|
|
if(event->type() == QEvent::MouseButtonPress) {
|
|
|
|
|
if(! m_timer->isActive()) {
|
|
|
|
|
if(!m_isOpen) {
|
2023-09-01 17:30:21 +08:00
|
|
|
|
m_iconLabel->setPixmap(IconLoader::loadIconQt("ukui-up-symbolic", QIcon(":/res/icons/ukui-up-symbolic.svg")).pixmap(QSize(16, 16)));
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_isOpen = true;
|
|
|
|
|
Q_EMIT this->showMoreClicked();
|
|
|
|
|
} else {
|
2023-09-01 17:30:21 +08:00
|
|
|
|
m_iconLabel->setPixmap(IconLoader::loadIconQt("ukui-down-symbolic", QIcon(":/res/icons/ukui-down-symbolic.svg")).pixmap(QSize(16, 16)));
|
2021-05-22 21:29:43 +08:00
|
|
|
|
m_isOpen = false;
|
|
|
|
|
Q_EMIT this->retractClicked();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::eventFilter(watched, event);
|
|
|
|
|
}
|