diff --git a/frontend/control/list-labels/show-more-label.cpp b/frontend/control/list-labels/show-more-label.cpp index 49c4b40..9c6002d 100644 --- a/frontend/control/list-labels/show-more-label.cpp +++ b/frontend/control/list-labels/show-more-label.cpp @@ -21,7 +21,7 @@ #include "show-more-label.h" #include #include - +#include using namespace Zeeker; ShowMoreLabel::ShowMoreLabel(QWidget *parent) : QWidget(parent) { initUi(); @@ -30,7 +30,7 @@ ShowMoreLabel::ShowMoreLabel(QWidget *parent) : QWidget(parent) { void ShowMoreLabel::resetLabel() { m_isOpen = false; - m_textLabel->setText(tr("Show More...")); + m_textLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16))); } /** @@ -47,13 +47,13 @@ void ShowMoreLabel::initUi() { m_layout = new QHBoxLayout(this); m_layout->setContentsMargins(0, 0, 0, 6); m_textLabel = new QLabel(this); - m_textLabel->setText(tr("Show More...")); + m_textLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16))); m_textLabel->setCursor(QCursor(Qt::PointingHandCursor)); m_textLabel->installEventFilter(this); // m_loadingIconLabel = new QLabel(this); //使用图片显示加载状态时,取消此label的注释 // m_loadingIconLabel->setFixedSize(18, 18); // m_loadingIconLabel->hide(); - m_layout->setAlignment(Qt::AlignRight); + m_layout->setAlignment(Qt::AlignRight | Qt::AlignTop); m_layout->addWidget(m_textLabel); m_textLabel->setPalette(pal); m_textLabel->setCursor(QCursor(Qt::PointingHandCursor)); @@ -65,11 +65,11 @@ bool ShowMoreLabel::eventFilter(QObject *watched, QEvent *event) { if(event->type() == QEvent::MouseButtonPress) { if(! m_timer->isActive()) { if(!m_isOpen) { - m_textLabel->setText(tr("Retract")); + m_textLabel->setPixmap(QIcon::fromTheme("pan-up-symbolic").pixmap(QSize(16, 16))); m_isOpen = true; Q_EMIT this->showMoreClicked(); } else { - m_textLabel->setText(tr("Show More...")); + m_textLabel->setPixmap(QIcon::fromTheme("pan-down-symbolic").pixmap(QSize(16, 16))); m_isOpen = false; Q_EMIT this->retractClicked(); } diff --git a/frontend/control/list-labels/title-label.cpp b/frontend/control/list-labels/title-label.cpp index 2d36495..aaf2956 100644 --- a/frontend/control/list-labels/title-label.cpp +++ b/frontend/control/list-labels/title-label.cpp @@ -21,14 +21,29 @@ #include "title-label.h" #include #include - +#define UNFOLD_LABEL_HEIGHT 30 +#define NUM_LIMIT_SHOWN_DEFAULT 5 using namespace Zeeker; TitleLabel::TitleLabel(QWidget * parent) : QLabel(parent) { - this->setContentsMargins(8, 0, 0, 0); - this->setFixedHeight(24); + initUi(); + initConnections(); } -TitleLabel::~TitleLabel() { +void TitleLabel::initUi() { + this->setContentsMargins(8, 0, 0, 0); + this->setFixedHeight(24); + m_titleLyt = new QHBoxLayout(this); + this->setLayout(m_titleLyt); + m_showMoreLabel = new ShowMoreLabel(this); + m_showMoreLabel->setFixedHeight(UNFOLD_LABEL_HEIGHT); + m_showMoreLabel->hide(); + m_titleLyt->addStretch(); + m_titleLyt->addWidget(m_showMoreLabel); +} + +void TitleLabel::initConnections() { + connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &TitleLabel::showMoreClicked); + connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &TitleLabel::retractClicked); } @@ -48,3 +63,8 @@ void TitleLabel::paintEvent(QPaintEvent * event) { p.drawRoundedRect(rect, 6, 6); return QLabel::paintEvent(event); } + +void TitleLabel::onListLengthChanged(const int &length) +{ + m_showMoreLabel->setVisible(length >= NUM_LIMIT_SHOWN_DEFAULT); +} diff --git a/frontend/control/list-labels/title-label.h b/frontend/control/list-labels/title-label.h index 791189d..bd4bfbf 100644 --- a/frontend/control/list-labels/title-label.h +++ b/frontend/control/list-labels/title-label.h @@ -22,15 +22,34 @@ #define TITLELABEL_H #include +#include "show-more-label.h" +#include namespace Zeeker { class TitleLabel : public QLabel { + Q_OBJECT public: TitleLabel(QWidget * parent = nullptr); - ~TitleLabel(); + ~TitleLabel() = default; protected: void paintEvent(QPaintEvent *); + +private: + void initUi(); + void initConnections(); + + QHBoxLayout * m_titleLyt = nullptr; + ShowMoreLabel * m_showMoreLabel = nullptr; + +public Q_SLOTS: + void onListLengthChanged(const int &); + +Q_SIGNALS: + void startSearch(const QString &); + void stopSearch(); + void showMoreClicked(); + void retractClicked(); }; } diff --git a/frontend/view/best-list-view.cpp b/frontend/view/best-list-view.cpp index b86f228..7b65a53 100644 --- a/frontend/view/best-list-view.cpp +++ b/frontend/view/best-list-view.cpp @@ -20,6 +20,7 @@ BestListView::BestListView(QWidget *parent) : QTreeView(parent) m_style_delegate = new ResultViewDelegate(this); this->setItemDelegate(m_style_delegate); } + bool BestListView::isSelected() { return m_is_selected; @@ -187,9 +188,7 @@ void BestListWidget::reduceListSlot() void BestListWidget::onListLengthChanged(const int &length) { this->setVisible(length > 0); - m_showMoreLabel->setVisible(length > NUM_LIMIT_SHOWN_DEFAULT); - int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0; - int whole_height = this->isVisible() ? (m_bestListView->showHeight() + TITLE_HEIGHT + show_more_height) : 0; + int whole_height = this->isVisible() ? (m_bestListView->showHeight() + TITLE_HEIGHT) : 0; this->setFixedHeight(whole_height); Q_EMIT this->sizeChanged(); } @@ -207,37 +206,25 @@ void BestListWidget::initUi() m_bestListView = new BestListView(this); - m_showMoreLabel = new ShowMoreLabel(this); - m_showMoreLabel->setFixedHeight(UNFOLD_LABEL_HEIGHT); - m_showMoreLabel->hide(); - m_mainLyt->addWidget(m_titleLabel); m_mainLyt->addWidget(m_bestListView); - m_mainLyt->addWidget(m_showMoreLabel); this->setFixedHeight(m_bestListView->height() + TITLE_HEIGHT); } void BestListWidget::initConnections() { connect(this, &BestListWidget::startSearch, m_bestListView, &BestListView::startSearch); - connect(this, &BestListWidget::startSearch, this, [ = ]() { - m_showMoreLabel->resetLabel(); - }); - //connect(this, &BestListWidget::stopSearch, m_bestListView, &BestListView::stopSearch); - connect(this, &BestListWidget::stopSearch, this, [ = ]() { - m_showMoreLabel->resetLabel(); - m_bestListView->setExpanded(false); - }); + connect(this, &BestListWidget::startSearch, m_titleLabel, &TitleLabel::startSearch); + connect(this, &BestListWidget::stopSearch, m_titleLabel, &TitleLabel::stopSearch); connect(this, &BestListWidget::sendBestListData, m_bestListView, &BestListView::sendBestListData); connect(m_bestListView, &BestListView::currentRowChanged, this, &BestListWidget::currentRowChanged); connect(this, &BestListWidget::clearSelectedRow, m_bestListView, &BestListView::clearSelectedRow); - connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &BestListWidget::expandListSlot); - connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &BestListWidget::reduceListSlot); + connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &BestListWidget::expandListSlot); + connect(m_titleLabel, &TitleLabel::retractClicked, this, &BestListWidget::reduceListSlot); connect(m_bestListView, &BestListView::listLengthChanged, this, &BestListWidget::onListLengthChanged); connect(m_bestListView, &BestListView::rowClicked, this, &BestListWidget::rowClicked); connect(qApp, &QApplication::paletteChanged, this, [ = ]() { - int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0; - int whole_height = this->isVisible() ? m_bestListView->showHeight() + TITLE_HEIGHT + show_more_height : 0; + int whole_height = this->isVisible() ? m_bestListView->showHeight() + TITLE_HEIGHT : 0; this->setFixedHeight(whole_height); Q_EMIT this->sizeChanged(); }); diff --git a/frontend/view/best-list-view.h b/frontend/view/best-list-view.h index d6a7060..f01dcb4 100644 --- a/frontend/view/best-list-view.h +++ b/frontend/view/best-list-view.h @@ -71,7 +71,6 @@ private: QVBoxLayout * m_mainLyt = nullptr; TitleLabel * m_titleLabel = nullptr; BestListView * m_bestListView = nullptr; - ShowMoreLabel * m_showMoreLabel = nullptr; Q_SIGNALS: void startSearch(const QString &); diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index 5dac241..e9820a9 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -46,9 +46,7 @@ void ResultWidget::reduceListSlot() void ResultWidget::onListLengthChanged(const int &length) { this->setVisible(length > 0); - m_showMoreLabel->setVisible(length >= NUM_LIMIT_SHOWN_DEFAULT); - int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0; - int whole_height = this->isVisible() ? m_resultView->showHeight() + TITLE_HEIGHT + show_more_height : 0; + int whole_height = this->isVisible() ? m_resultView->showHeight() + TITLE_HEIGHT : 0; this->setFixedHeight(whole_height); Q_EMIT this->sizeChanged(); } @@ -66,36 +64,26 @@ void ResultWidget::initUi() m_resultView = new ResultView(m_plugin_id, this); - m_showMoreLabel = new ShowMoreLabel(this); - m_showMoreLabel->setFixedHeight(UNFOLD_LABEL_HEIGHT); - m_showMoreLabel->hide(); - m_mainLyt->addWidget(m_titleLabel); m_mainLyt->addWidget(m_resultView); - m_mainLyt->addWidget(m_showMoreLabel); this->setFixedHeight(m_resultView->height() + TITLE_HEIGHT); } void ResultWidget::initConnections() { connect(this, &ResultWidget::startSearch, m_resultView, &ResultView::startSearch); - connect(this, &ResultWidget::startSearch, this, [ = ]() { - m_showMoreLabel->resetLabel(); - }); + connect(this, &ResultWidget::startSearch, m_titleLabel, &TitleLabel::startSearch); connect(this, &ResultWidget::stopSearch, m_resultView, &ResultView::stopSearch); - connect(this, &ResultWidget::stopSearch, this, [ = ]() { - m_showMoreLabel->resetLabel(); - m_resultView->setExpanded(false); - }); + connect(this, &ResultWidget::stopSearch, m_titleLabel, &TitleLabel::stopSearch); connect(m_resultView, &ResultView::currentRowChanged, this, &ResultWidget::currentRowChanged); connect(this, &ResultWidget::clearSelectedRow, m_resultView, &ResultView::clearSelectedRow); - connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &ResultWidget::expandListSlot); - connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &ResultWidget::reduceListSlot); + connect(m_titleLabel, &TitleLabel::showMoreClicked, this, &ResultWidget::expandListSlot); + connect(m_titleLabel, &TitleLabel::retractClicked, this, &ResultWidget::reduceListSlot); connect(m_resultView, &ResultView::listLengthChanged, this, &ResultWidget::onListLengthChanged); + connect(m_resultView, &ResultView::listLengthChanged, m_titleLabel, &TitleLabel::onListLengthChanged); connect(m_resultView, &ResultView::rowClicked, this, &ResultWidget::rowClicked); connect(qApp, &QApplication::paletteChanged, this, [ = ]() { - int show_more_height = m_showMoreLabel->isVisible() ? UNFOLD_LABEL_HEIGHT : 0; - int whole_height = this->isVisible() ? m_resultView->showHeight() + TITLE_HEIGHT + show_more_height : 0; + int whole_height = this->isVisible() ? m_resultView->showHeight() + TITLE_HEIGHT : 0; this->setFixedHeight(whole_height); Q_EMIT this->sizeChanged(); }); @@ -241,7 +229,6 @@ void ResultView::mousePressEvent(QMouseEvent *event) void ResultView::initConnections() { -// connect(this, &ResultView::startSearch, m_model, &SearchResultModel::startSearch); connect(this, &ResultView::startSearch, [ = ](const QString &keyword) { m_style_delegate->setSearchKeyword(keyword); m_model->startSearch(keyword); diff --git a/frontend/view/result-view.h b/frontend/view/result-view.h index c129f11..6e4f88c 100644 --- a/frontend/view/result-view.h +++ b/frontend/view/result-view.h @@ -73,7 +73,6 @@ private: QVBoxLayout * m_mainLyt = nullptr; TitleLabel * m_titleLabel = nullptr; ResultView * m_resultView = nullptr; - ShowMoreLabel * m_showMoreLabel = nullptr; Q_SIGNALS: void startSearch(const QString &);