From 2cb7f2a3783d51dd06aa2e89329e223d3a11e25d Mon Sep 17 00:00:00 2001 From: iaom Date: Wed, 22 Nov 2023 09:08:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=E9=80=82=E9=85=8D=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E6=8E=A7=E4=BB=B6=E5=9C=86=E8=A7=92=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/control/list-labels/title-label.cpp | 18 +++++++++++++----- frontend/control/list-labels/title-label.h | 3 ++- .../stack-pages/search-page-section.cpp | 10 +++++----- .../control/stack-pages/search-page-section.h | 3 ++- frontend/view/result-view.cpp | 4 ++-- libsearch/global-settings-private.h | 2 +- libsearch/global-settings.cpp | 2 +- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/frontend/control/list-labels/title-label.cpp b/frontend/control/list-labels/title-label.cpp index a4e2c87..da499ea 100644 --- a/frontend/control/list-labels/title-label.cpp +++ b/frontend/control/list-labels/title-label.cpp @@ -21,6 +21,7 @@ #include "title-label.h" #include #include +#include #define UNFOLD_LABEL_HEIGHT 30 #define NUM_LIMIT_SHOWN_DEFAULT 5 using namespace UkuiSearch; @@ -35,7 +36,12 @@ void TitleLabel::setShowMoreLableVisible() m_showMoreLabel->setLabel(); } -void TitleLabel::initUi() { +void TitleLabel::initUi() +{ + m_radius = qApp->style()->property("normalRadius").toInt(); + connect(qApp, &QApplication::paletteChanged, this, [&]() { + m_radius = qApp->style()->property("normalRadius").toInt(); + }); this->setContentsMargins(8, 0, 0, 0); this->setFixedHeight(24); m_titleLyt = new QHBoxLayout(this); @@ -48,13 +54,15 @@ void TitleLabel::initUi() { m_titleLyt->addWidget(m_showMoreLabel); } -void TitleLabel::initConnections() { +void TitleLabel::initConnections() +{ connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &TitleLabel::showMoreClicked); connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &TitleLabel::retractClicked); } -void TitleLabel::paintEvent(QPaintEvent * event) { +void TitleLabel::paintEvent(QPaintEvent * event) +{ Q_UNUSED(event) QStyleOption opt; @@ -67,7 +75,7 @@ void TitleLabel::paintEvent(QPaintEvent * event) { p.setBrush(opt.palette.color(QPalette::Text)); p.setOpacity(0.04); p.setPen(Qt::NoPen); - p.drawRoundedRect(rect, 6, 6); + p.drawRoundedRect(rect, m_radius, m_radius); return QLabel::paintEvent(event); } @@ -76,7 +84,7 @@ void TitleLabel::onListLengthChanged(const int &length) m_showMoreLabel->setVisible(length > NUM_LIMIT_SHOWN_DEFAULT); } -void TitleLabel::lableReset() +void TitleLabel::labelReset() { m_showMoreLabel->resetLabel(); } diff --git a/frontend/control/list-labels/title-label.h b/frontend/control/list-labels/title-label.h index 0fee1b3..1929161 100644 --- a/frontend/control/list-labels/title-label.h +++ b/frontend/control/list-labels/title-label.h @@ -43,10 +43,11 @@ private: QHBoxLayout * m_titleLyt = nullptr; ShowMoreLabel * m_showMoreLabel = nullptr; + int m_radius = 6; public Q_SLOTS: void onListLengthChanged(const int &); - void lableReset(); + void labelReset(); Q_SIGNALS: void startSearch(const QString &); diff --git a/frontend/control/stack-pages/search-page-section.cpp b/frontend/control/stack-pages/search-page-section.cpp index 0c7bd8c..1bb363c 100644 --- a/frontend/control/stack-pages/search-page-section.cpp +++ b/frontend/control/stack-pages/search-page-section.cpp @@ -27,7 +27,6 @@ using namespace UkuiSearch; #define RESULT_BACKGROUND_COLOR QColor(0, 0, 0, 0) #define DETAIL_BACKGROUND_COLOR QColor(0, 0, 0, 0) #define DETAIL_WIDGET_TRANSPARENT 0.04 -#define DETAIL_WIDGET_BORDER_RADIUS 4 #define DETAIL_WIDGET_MARGINS 8,0,8,0 #define DETAIL_FRAME_MARGINS 8,0,0,0 #define DETAIL_ICON_HEIGHT 120 @@ -613,14 +612,15 @@ void DetailArea::initUi() DetailWidget::DetailWidget(QWidget *parent) : QWidget(parent) { -// initUi(); -// clear(); + m_radius = qApp->style()->property("maxRadius").toInt(); + connect(qApp, &QApplication::paletteChanged, this, [&]() { + m_radius = qApp->style()->property("maxRadius").toInt(); + }); this->setFixedWidth(368); m_mainLyt = new QVBoxLayout(this); this->setLayout(m_mainLyt); m_mainLyt->setContentsMargins(DETAIL_WIDGET_MARGINS); m_mainLyt->setAlignment(Qt::AlignHCenter); -// m_mainLyt->addStretch(); } QString escapeHtml(const QString & str) { @@ -666,7 +666,7 @@ void DetailWidget::paintEvent(QPaintEvent *event) p.setBrush(opt.palette.color(QPalette::Text)); p.setOpacity(DETAIL_WIDGET_TRANSPARENT); p.setPen(Qt::NoPen); - p.drawRoundedRect(rect, DETAIL_WIDGET_BORDER_RADIUS, DETAIL_WIDGET_BORDER_RADIUS); + p.drawRoundedRect(rect, m_radius, m_radius); return QWidget::paintEvent(event); } diff --git a/frontend/control/stack-pages/search-page-section.h b/frontend/control/stack-pages/search-page-section.h index 7773040..d81a2a2 100644 --- a/frontend/control/stack-pages/search-page-section.h +++ b/frontend/control/stack-pages/search-page-section.h @@ -118,12 +118,13 @@ public: public Q_SLOTS: void updateDetailPage(const QString &plugin_name, const SearchPluginIface::ResultInfo &info); protected: - void paintEvent(QPaintEvent *event); + void paintEvent(QPaintEvent *event) override; private: void clearLayout(QLayout *); QVBoxLayout * m_mainLyt = nullptr; QString m_currentPluginId; QWidget *m_detailPage = nullptr; + int m_radius = 8; }; class DetailArea : public QScrollArea diff --git a/frontend/view/result-view.cpp b/frontend/view/result-view.cpp index 94016d2..8d4483c 100644 --- a/frontend/view/result-view.cpp +++ b/frontend/view/result-view.cpp @@ -99,7 +99,7 @@ SearchPluginIface::ResultInfo ResultWidget::getIndexResultInfo(QModelIndex &inde void ResultWidget::resetTitleLabel() { - Q_EMIT this->m_titleLabel->lableReset(); + Q_EMIT this->m_titleLabel->labelReset(); } void ResultWidget::setTitileLableHide(bool state) @@ -177,7 +177,7 @@ void ResultWidget::initConnections() Q_EMIT this->sizeChanged(); }); connect(m_resultView, &ResultView::sendBestListData, this, &ResultWidget::sendBestListData); - connect(m_resultView, &ResultView::lableReset, m_titleLabel, &TitleLabel::lableReset); + connect(m_resultView, &ResultView::lableReset, m_titleLabel, &TitleLabel::labelReset); connect(this, &ResultWidget::resizeWidth, this, [=] (const int &size) { this->setFixedWidth(size); }); diff --git a/libsearch/global-settings-private.h b/libsearch/global-settings-private.h index 8050e12..ffbc430 100644 --- a/libsearch/global-settings-private.h +++ b/libsearch/global-settings-private.h @@ -12,7 +12,7 @@ class GlobalSettingsPrivate : public QObject Q_OBJECT public: explicit GlobalSettingsPrivate(QObject *parent = nullptr); - const QVariant getValue(const QString&); + QVariant getValue(const QString&); Q_SIGNALS: void valueChanged(const QString& key, QVariant value); diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index 7cf8ebc..bf0cf29 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -87,7 +87,7 @@ GlobalSettingsPrivate::GlobalSettingsPrivate(QObject *parent) : QObject(parent) } } -const QVariant GlobalSettingsPrivate::getValue(const QString &key) { +QVariant GlobalSettingsPrivate::getValue(const QString &key) { m_mutex.lock(); QVariant value = m_cache.value(key);