add gsettings which key is transparency

This commit is contained in:
zhangzihao 2021-01-04 14:21:45 +08:00
parent bcc226a650
commit 804404f183
7 changed files with 43 additions and 12 deletions

View File

@ -1,5 +1,7 @@
#include <QtConcurrent>
#include "globalsettings.h"
#include <QApplication>
#include <QPalette>
#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()

View File

@ -5,8 +5,17 @@
#include <QSettings>
#include <QMutex>
#include <QVector>
//#include <QGSettings>
//If use pkg_config, it wont build succes,why?????????
//My demo can build access yet.
//MouseZhangZh
#include <QGSettings/QGSettings>
#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<QString, QVariant> m_cache;
QMutex m_mutex;

View File

@ -2,7 +2,7 @@
#define BLOCKDIRS_H
#include <QObject>
#include "globalsettings.h"
#include "global-settings.h"
#ifndef MYTYPE
#define MYTYPE

View File

@ -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

View File

@ -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) {

View File

@ -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;
}

View File

@ -1,4 +1,4 @@
QT += core gui dbus svg KWindowSystem xml
QT += core gui dbus KWindowSystem xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets