From f4ea89dec8457173a20534f6208d2d3ef9cdf9cc Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Wed, 12 May 2021 15:58:38 +0800 Subject: [PATCH] Uniform window icon & optimize code. --- libsearch/global-settings.cpp | 3 ++- libsearch/global-settings.h | 2 ++ src/content-widget.cpp | 1 - src/control/highlight-item-delegate.cpp | 2 -- src/control/highlight-item-delegate.h | 1 + src/control/home-page-item.cpp | 1 - src/create-index-ask-dialog.cpp | 7 +++++-- src/create-index-ask-dialog.h | 2 ++ src/main.cpp | 2 ++ src/mainwindow.cpp | 6 +++++- src/settings-widget.cpp | 6 +++++- 11 files changed, 24 insertions(+), 9 deletions(-) diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index da596c2..e38d12e 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -19,7 +19,6 @@ * */ #include -#include #include #include "global-settings.h" @@ -83,6 +82,8 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { qApp->paletteChanged(qApp->palette()); m_cache.remove(FONT_SIZE_KEY); m_cache.insert(FONT_SIZE_KEY, m_theme_gsettings->get(FONT_SIZE_KEY).toDouble()); + } else if (key == ICON_THEME_KEY) { + qApp->paletteChanged(qApp->palette()); } }); m_cache.remove(STYLE_NAME_KEY); diff --git a/libsearch/global-settings.h b/libsearch/global-settings.h index 6f97f2a..fbe7433 100644 --- a/libsearch/global-settings.h +++ b/libsearch/global-settings.h @@ -33,6 +33,7 @@ #include #include #include +#include #include "libsearch_global.h" #define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise" @@ -40,6 +41,7 @@ #define THEME_GSETTINGS_ID "org.ukui.style" #define STYLE_NAME_KEY "styleName" #define FONT_SIZE_KEY "systemFontSize" +#define ICON_THEME_KEY "iconThemeName" #define INDEX_DATABASE_STATE "index_database_state" #define CONTENT_INDEX_DATABASE_STATE "content_index_database_state" #define INDEX_GENERATOR_NORMAL_EXIT "index_generator_normal_exit" diff --git a/src/content-widget.cpp b/src/content-widget.cpp index 7d9f335..532c6c6 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include "config-file.h" using namespace Zeeker; diff --git a/src/control/highlight-item-delegate.cpp b/src/control/highlight-item-delegate.cpp index a11d3c3..c57e1e3 100644 --- a/src/control/highlight-item-delegate.cpp +++ b/src/control/highlight-item-delegate.cpp @@ -20,12 +20,10 @@ */ #include "highlight-item-delegate.h" #include -#include #include #include #include #include -#include "global-settings.h" using namespace Zeeker; HighlightItemDelegate::HighlightItemDelegate(QObject *parent) : QStyledItemDelegate(parent) { diff --git a/src/control/highlight-item-delegate.h b/src/control/highlight-item-delegate.h index 81a0527..cc71b72 100644 --- a/src/control/highlight-item-delegate.h +++ b/src/control/highlight-item-delegate.h @@ -22,6 +22,7 @@ #define HIGHLIGHTITEMDELEGATE_H #include +#include "global-settings.h" namespace Zeeker { class HighlightItemDelegate : public QStyledItemDelegate { diff --git a/src/control/home-page-item.cpp b/src/control/home-page-item.cpp index 5177a6d..5fe596d 100644 --- a/src/control/home-page-item.cpp +++ b/src/control/home-page-item.cpp @@ -26,7 +26,6 @@ #include #include #include -#include using namespace Zeeker; HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path) : QWidget(parent) { diff --git a/src/create-index-ask-dialog.cpp b/src/create-index-ask-dialog.cpp index 1fc2e76..78d43e1 100644 --- a/src/create-index-ask-dialog.cpp +++ b/src/create-index-ask-dialog.cpp @@ -20,11 +20,10 @@ */ #include "create-index-ask-dialog.h" -#include using namespace Zeeker; CreateIndexAskDialog::CreateIndexAskDialog(QWidget *parent) : QDialog(parent) { - this->setWindowIcon(QIcon::fromTheme("kylin-search")); +// this->setWindowIcon(QIcon::fromTheme("kylin-search")); this->setWindowTitle(tr("ukui-search")); initUi(); @@ -46,6 +45,10 @@ void CreateIndexAskDialog::initUi() { m_iconLabel = new QLabel(m_titleFrame); m_iconLabel->setFixedSize(24, 24); m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(24, 24))); + //主题改变时,更新自定义标题栏的图标 + connect(qApp, &QApplication::paletteChanged, this, [ = ]() { + m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(24, 24))); + }); m_titleLabel = new QLabel(m_titleFrame); m_titleLabel->setText(tr("Search")); m_closeBtn = new QPushButton(m_titleFrame); diff --git a/src/create-index-ask-dialog.h b/src/create-index-ask-dialog.h index bf360fc..4719181 100644 --- a/src/create-index-ask-dialog.h +++ b/src/create-index-ask-dialog.h @@ -30,6 +30,8 @@ #include #include #include +#include +#include namespace Zeeker { class CreateIndexAskDialog : public QDialog { diff --git a/src/main.cpp b/src/main.cpp index cca0d2a..e7203e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "qt-single-application.h" #include "qt-local-peer.h" //#include "inotify-manager.h" @@ -268,6 +269,7 @@ int main(int argc, char *argv[]) { //set main window to the center of screen MainWindow *w = new MainWindow; + qApp->setWindowIcon(QIcon::fromTheme("kylin-search")); // centerToScreen(w); // w->moveToPanel(); centerToScreen(w); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bca3a05..0e7ecca 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -58,7 +58,7 @@ MainWindow::MainWindow(QWidget *parent) : // this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); // this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); - this->setWindowIcon(QIcon::fromTheme("kylin-search")); +// this->setWindowIcon(QIcon::fromTheme("kylin-search")); this->setAttribute(Qt::WA_TranslucentBackground, true); this->setAutoFillBackground(false); this->setFocusPolicy(Qt::StrongFocus); @@ -189,6 +189,10 @@ void MainWindow::initUi() { m_iconLabel = new QLabel(m_titleFrame); m_iconLabel->setFixedSize(24, 24); m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(24, 24))); + //主题改变时,更新自定义标题栏的图标 + connect(qApp, &QApplication::paletteChanged, this, [ = ]() { + m_iconLabel->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(24, 24))); + }); m_titleLabel = new QLabel(m_titleFrame); m_titleLabel->setText(tr("Search")); m_menuBtn = new QPushButton(m_titleFrame); diff --git a/src/settings-widget.cpp b/src/settings-widget.cpp index b9b47f8..f3b164c 100644 --- a/src/settings-widget.cpp +++ b/src/settings-widget.cpp @@ -32,7 +32,7 @@ using namespace Zeeker; extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent) { - this->setWindowIcon(QIcon::fromTheme("kylin-search")); +// this->setWindowIcon(QIcon::fromTheme("kylin-search")); this->setWindowTitle(tr("ukui-search-settings")); // this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); // this->setAttribute(Qt::WA_TranslucentBackground); @@ -70,6 +70,10 @@ void SettingsWidget::initUi() { m_titleFrame->setLayout(m_titleLyt); m_titleIcon = new QLabel(m_titleFrame); m_titleIcon->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(24, 24))); + //主题改变时,更新自定义标题栏的图标 + connect(qApp, &QApplication::paletteChanged, this, [ = ]() { + m_titleIcon->setPixmap(QIcon::fromTheme("kylin-search").pixmap(QSize(24, 24))); + }); m_titleLabel = new QLabel(m_titleFrame); m_titleLabel->setText(tr("Search")); m_closeBtn = new QPushButton(m_titleFrame);