From 804404f1831a019019448d15f47f9e9c4e44dc71 Mon Sep 17 00:00:00 2001 From: zhangzihao Date: Mon, 4 Jan 2021 14:21:45 +0800 Subject: [PATCH] add gsettings which key is transparency --- ...globalsettings.cpp => global-settings.cpp} | 19 ++++++++++++++++++- .../{globalsettings.h => global-settings.h} | 13 ++++++++++++- libsearch/index/blockdirs.h | 2 +- libsearch/libsearch.pro | 13 ++++++------- src/main.cpp | 2 +- src/mainwindow.cpp | 4 ++++ src/src.pro | 2 +- 7 files changed, 43 insertions(+), 12 deletions(-) rename libsearch/{globalsettings.cpp => global-settings.cpp} (68%) rename libsearch/{globalsettings.h => global-settings.h} (62%) diff --git a/libsearch/globalsettings.cpp b/libsearch/global-settings.cpp similarity index 68% rename from libsearch/globalsettings.cpp rename to libsearch/global-settings.cpp index f878741..431c097 100644 --- a/libsearch/globalsettings.cpp +++ b/libsearch/global-settings.cpp @@ -1,5 +1,7 @@ #include -#include "globalsettings.h" +#include +#include +#include "global-settings.h" static GlobalSettings *global_instance = nullptr; @@ -14,6 +16,21 @@ GlobalSettings *GlobalSettings::getInstance() GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { m_settings = new QSettings("org.ukui", "ukui-search-blockdirs", this); + //the default number of transparency in mainwindow is 0.7 + //if someone changes the num in mainwindow, here should be modified too + m_cache.insert(TRANSPARENCY_KEY, 0.7); + if (QGSettings::isSchemaInstalled(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID)) { + m_gsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this); + connect(m_gsettings, &QGSettings::changed, this, [=](const QString& key) { + if (key == TRANSPARENCY_KEY) { + m_cache.remove(TRANSPARENCY_KEY); + m_cache.insert(TRANSPARENCY_KEY, m_gsettings->get(TRANSPARENCY_KEY).toDouble()); + qApp->paletteChanged(qApp->palette()); + } + }); + } + m_cache.remove(TRANSPARENCY_KEY); + m_cache.insert(TRANSPARENCY_KEY, m_gsettings->get(TRANSPARENCY_KEY).toDouble()); } GlobalSettings::~GlobalSettings() diff --git a/libsearch/globalsettings.h b/libsearch/global-settings.h similarity index 62% rename from libsearch/globalsettings.h rename to libsearch/global-settings.h index feb5404..c943df7 100644 --- a/libsearch/globalsettings.h +++ b/libsearch/global-settings.h @@ -5,8 +5,17 @@ #include #include #include +//#include +//If use pkg_config, it wont build succes,why????????? +//My demo can build access yet. +//MouseZhangZh +#include +#include "libsearch_global.h" -class GlobalSettings : public QObject +#define CONTROL_CENTER_PERSONALISE_GSETTINGS_ID "org.ukui.control-center.personalise" +#define TRANSPARENCY_KEY "transparency" + +class LIBSEARCH_EXPORT GlobalSettings : public QObject { Q_OBJECT public: @@ -16,6 +25,7 @@ public: Q_SIGNALS: void valueChanged (const QString&); + void transparencyChanged (const double&); public Q_SLOTS: void setValue(const QString&, const QVariant&); @@ -30,6 +40,7 @@ private: ~GlobalSettings(); QSettings* m_settings; + QGSettings* m_gsettings; QMap m_cache; QMutex m_mutex; diff --git a/libsearch/index/blockdirs.h b/libsearch/index/blockdirs.h index 25114f2..ad4e25e 100644 --- a/libsearch/index/blockdirs.h +++ b/libsearch/index/blockdirs.h @@ -2,7 +2,7 @@ #define BLOCKDIRS_H #include -#include "globalsettings.h" +#include "global-settings.h" #ifndef MYTYPE #define MYTYPE diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index 33d7399..d73e673 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -1,14 +1,13 @@ -QT += core concurrent xml - +QT += core concurrent xml widgets VERSION = 0.0.1 TARGET = ukui-search TEMPLATE = lib DEFINES += LIBSEARCH_LIBRARY -PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 -CONFIG += c++11 link_pkgconfig no_keywords +PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt +CONFIG += c++11 link_pkgconfig no_keywords # The following define makes your compiler emit warnings if you use @@ -27,17 +26,17 @@ include(appsearch/appsearch.pri) include(settingsearch/settingsearch.pri)) LIBS += -L../libchinese-segmentation/ -lchinese-segmentation -LIBS += -lxapian -lgsettings-qt -lquazip5 +LIBS += -lxapian -lquazip5 SOURCES += \ file-utils.cpp \ - globalsettings.cpp \ + global-settings.cpp \ gobject-template.cpp \ libsearch.cpp HEADERS += \ file-utils.h \ - globalsettings.h \ + global-settings.h \ gobject-template.h \ libsearch_global.h \ libsearch.h diff --git a/src/main.cpp b/src/main.cpp index 89831c2..3d283e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,7 @@ #include "qt-local-peer.h" //#include "inotify-manager.h" #include "libsearch.h" -#include "globalsettings.h" +#include "global-settings.h" void centerToScreen(QWidget* widget) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b8c5b74..0deedf2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -316,6 +316,10 @@ void MainWindow::searchContent(QString searchcontent){ //使用GSetting获取当前窗口应该使用的透明度 double MainWindow::getTransparentData() { + //todo modify here!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //todo modify here!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //todo modify here!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //if you have questions, please ask iaom or MouseZhangZh if (!m_transparency_gsettings) { return 0.7; } diff --git a/src/src.pro b/src/src.pro index 6f5792e..c9bb5ba 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,4 +1,4 @@ -QT += core gui dbus svg KWindowSystem xml +QT += core gui dbus KWindowSystem xml greaterThan(QT_MAJOR_VERSION, 4): QT += widgets