feat(frontend):适配主题的控件圆角配置

This commit is contained in:
iaom 2023-11-22 09:08:30 +08:00
parent 859d123c59
commit 2cb7f2a378
7 changed files with 26 additions and 16 deletions

View File

@ -21,6 +21,7 @@
#include "title-label.h" #include "title-label.h"
#include <QPainter> #include <QPainter>
#include <QStyleOption> #include <QStyleOption>
#include <QApplication>
#define UNFOLD_LABEL_HEIGHT 30 #define UNFOLD_LABEL_HEIGHT 30
#define NUM_LIMIT_SHOWN_DEFAULT 5 #define NUM_LIMIT_SHOWN_DEFAULT 5
using namespace UkuiSearch; using namespace UkuiSearch;
@ -35,7 +36,12 @@ void TitleLabel::setShowMoreLableVisible()
m_showMoreLabel->setLabel(); 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->setContentsMargins(8, 0, 0, 0);
this->setFixedHeight(24); this->setFixedHeight(24);
m_titleLyt = new QHBoxLayout(this); m_titleLyt = new QHBoxLayout(this);
@ -48,13 +54,15 @@ void TitleLabel::initUi() {
m_titleLyt->addWidget(m_showMoreLabel); m_titleLyt->addWidget(m_showMoreLabel);
} }
void TitleLabel::initConnections() { void TitleLabel::initConnections()
{
connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &TitleLabel::showMoreClicked); connect(m_showMoreLabel, &ShowMoreLabel::showMoreClicked, this, &TitleLabel::showMoreClicked);
connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &TitleLabel::retractClicked); connect(m_showMoreLabel, &ShowMoreLabel::retractClicked, this, &TitleLabel::retractClicked);
} }
void TitleLabel::paintEvent(QPaintEvent * event) { void TitleLabel::paintEvent(QPaintEvent * event)
{
Q_UNUSED(event) Q_UNUSED(event)
QStyleOption opt; QStyleOption opt;
@ -67,7 +75,7 @@ void TitleLabel::paintEvent(QPaintEvent * event) {
p.setBrush(opt.palette.color(QPalette::Text)); p.setBrush(opt.palette.color(QPalette::Text));
p.setOpacity(0.04); p.setOpacity(0.04);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.drawRoundedRect(rect, 6, 6); p.drawRoundedRect(rect, m_radius, m_radius);
return QLabel::paintEvent(event); return QLabel::paintEvent(event);
} }
@ -76,7 +84,7 @@ void TitleLabel::onListLengthChanged(const int &length)
m_showMoreLabel->setVisible(length > NUM_LIMIT_SHOWN_DEFAULT); m_showMoreLabel->setVisible(length > NUM_LIMIT_SHOWN_DEFAULT);
} }
void TitleLabel::lableReset() void TitleLabel::labelReset()
{ {
m_showMoreLabel->resetLabel(); m_showMoreLabel->resetLabel();
} }

View File

@ -43,10 +43,11 @@ private:
QHBoxLayout * m_titleLyt = nullptr; QHBoxLayout * m_titleLyt = nullptr;
ShowMoreLabel * m_showMoreLabel = nullptr; ShowMoreLabel * m_showMoreLabel = nullptr;
int m_radius = 6;
public Q_SLOTS: public Q_SLOTS:
void onListLengthChanged(const int &); void onListLengthChanged(const int &);
void lableReset(); void labelReset();
Q_SIGNALS: Q_SIGNALS:
void startSearch(const QString &); void startSearch(const QString &);

View File

@ -27,7 +27,6 @@ using namespace UkuiSearch;
#define RESULT_BACKGROUND_COLOR QColor(0, 0, 0, 0) #define RESULT_BACKGROUND_COLOR QColor(0, 0, 0, 0)
#define DETAIL_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_TRANSPARENT 0.04
#define DETAIL_WIDGET_BORDER_RADIUS 4
#define DETAIL_WIDGET_MARGINS 8,0,8,0 #define DETAIL_WIDGET_MARGINS 8,0,8,0
#define DETAIL_FRAME_MARGINS 8,0,0,0 #define DETAIL_FRAME_MARGINS 8,0,0,0
#define DETAIL_ICON_HEIGHT 120 #define DETAIL_ICON_HEIGHT 120
@ -613,14 +612,15 @@ void DetailArea::initUi()
DetailWidget::DetailWidget(QWidget *parent) : QWidget(parent) DetailWidget::DetailWidget(QWidget *parent) : QWidget(parent)
{ {
// initUi(); m_radius = qApp->style()->property("maxRadius").toInt();
// clear(); connect(qApp, &QApplication::paletteChanged, this, [&]() {
m_radius = qApp->style()->property("maxRadius").toInt();
});
this->setFixedWidth(368); this->setFixedWidth(368);
m_mainLyt = new QVBoxLayout(this); m_mainLyt = new QVBoxLayout(this);
this->setLayout(m_mainLyt); this->setLayout(m_mainLyt);
m_mainLyt->setContentsMargins(DETAIL_WIDGET_MARGINS); m_mainLyt->setContentsMargins(DETAIL_WIDGET_MARGINS);
m_mainLyt->setAlignment(Qt::AlignHCenter); m_mainLyt->setAlignment(Qt::AlignHCenter);
// m_mainLyt->addStretch();
} }
QString escapeHtml(const QString & str) { QString escapeHtml(const QString & str) {
@ -666,7 +666,7 @@ void DetailWidget::paintEvent(QPaintEvent *event)
p.setBrush(opt.palette.color(QPalette::Text)); p.setBrush(opt.palette.color(QPalette::Text));
p.setOpacity(DETAIL_WIDGET_TRANSPARENT); p.setOpacity(DETAIL_WIDGET_TRANSPARENT);
p.setPen(Qt::NoPen); 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); return QWidget::paintEvent(event);
} }

View File

@ -118,12 +118,13 @@ public:
public Q_SLOTS: public Q_SLOTS:
void updateDetailPage(const QString &plugin_name, const SearchPluginIface::ResultInfo &info); void updateDetailPage(const QString &plugin_name, const SearchPluginIface::ResultInfo &info);
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event) override;
private: private:
void clearLayout(QLayout *); void clearLayout(QLayout *);
QVBoxLayout * m_mainLyt = nullptr; QVBoxLayout * m_mainLyt = nullptr;
QString m_currentPluginId; QString m_currentPluginId;
QWidget *m_detailPage = nullptr; QWidget *m_detailPage = nullptr;
int m_radius = 8;
}; };
class DetailArea : public QScrollArea class DetailArea : public QScrollArea

View File

@ -99,7 +99,7 @@ SearchPluginIface::ResultInfo ResultWidget::getIndexResultInfo(QModelIndex &inde
void ResultWidget::resetTitleLabel() void ResultWidget::resetTitleLabel()
{ {
Q_EMIT this->m_titleLabel->lableReset(); Q_EMIT this->m_titleLabel->labelReset();
} }
void ResultWidget::setTitileLableHide(bool state) void ResultWidget::setTitileLableHide(bool state)
@ -177,7 +177,7 @@ void ResultWidget::initConnections()
Q_EMIT this->sizeChanged(); Q_EMIT this->sizeChanged();
}); });
connect(m_resultView, &ResultView::sendBestListData, this, &ResultWidget::sendBestListData); 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) { connect(this, &ResultWidget::resizeWidth, this, [=] (const int &size) {
this->setFixedWidth(size); this->setFixedWidth(size);
}); });

View File

@ -12,7 +12,7 @@ class GlobalSettingsPrivate : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit GlobalSettingsPrivate(QObject *parent = nullptr); explicit GlobalSettingsPrivate(QObject *parent = nullptr);
const QVariant getValue(const QString&); QVariant getValue(const QString&);
Q_SIGNALS: Q_SIGNALS:
void valueChanged(const QString& key, QVariant value); void valueChanged(const QString& key, QVariant value);

View File

@ -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(); m_mutex.lock();
QVariant value = m_cache.value(key); QVariant value = m_cache.value(key);