From 33e0cf8a261f3756ccc2d5947fea5ad37de280d2 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 21 Oct 2024 02:00:29 +0400 Subject: [PATCH] Write widget style and icon theme to kdeglobals This allows to style applications that use KStyleManager --- CMakeLists.txt | 1 + src/qt6ct/CMakeLists.txt | 3 ++- src/qt6ct/appearancepage.cpp | 12 ++++++++++++ src/qt6ct/appearancepage.h | 4 ++++ src/qt6ct/iconthemepage.cpp | 16 ++++++++++++++++ src/qt6ct/iconthemepage.h | 4 ++++ src/qt6ct/mainwindow.cpp | 8 ++++++++ src/qt6ct/tabpage.h | 8 ++++++++ 8 files changed, 55 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c54376d..c5bc4be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000 -DUSE_WIDGETS) find_package(Qt6 REQUIRED COMPONENTS BuildInternals Core Widgets OPTIONAL_COMPONENTS QuickControls2 LinguistTools) +find_package(KF6Config) get_target_property(QT_QTPATHS_EXECUTABLE Qt6::qtpaths IMPORTED_LOCATION) diff --git a/src/qt6ct/CMakeLists.txt b/src/qt6ct/CMakeLists.txt index fb0e1f7..7efe4eb 100644 --- a/src/qt6ct/CMakeLists.txt +++ b/src/qt6ct/CMakeLists.txt @@ -31,6 +31,7 @@ if(Qt6LinguistTools_FOUND) endif() add_executable(qt6ct ${app_SRCS}) -target_link_libraries(qt6ct PRIVATE Qt6::Widgets Qt6::WidgetsPrivate qt6ct-common) +target_link_libraries(qt6ct PRIVATE Qt6::Widgets Qt6::WidgetsPrivate $ qt6ct-common) +target_compile_definitions(qt6ct PRIVATE $<$:KF_CONFIGCORE_LIB>) install(TARGETS qt6ct DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES qt6ct.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) diff --git a/src/qt6ct/appearancepage.cpp b/src/qt6ct/appearancepage.cpp index 312f188..78a0cfa 100644 --- a/src/qt6ct/appearancepage.cpp +++ b/src/qt6ct/appearancepage.cpp @@ -35,6 +35,9 @@ #include #include #include +#ifdef KF_CONFIGCORE_LIB +#include +#endif #include #include "qt6ct.h" #include "appearancepage.h" @@ -112,6 +115,15 @@ void AppearancePage::writeSettings(QSettings *settings) settings->endGroup(); } +#ifdef KF_CONFIGCORE_LIB +void AppearancePage::writeSettings(KSharedConfigPtr config) +{ + KConfigGroup group(config, "KDE"); + group.writeEntry("widgetStyle", "qt6ct-style"); + group.sync(); +} +#endif + void AppearancePage::on_styleComboBox_textActivated(const QString &text) { QStyle *style = QStyleFactory::create(text); diff --git a/src/qt6ct/appearancepage.h b/src/qt6ct/appearancepage.h index 73aefb3..d90478e 100644 --- a/src/qt6ct/appearancepage.h +++ b/src/qt6ct/appearancepage.h @@ -49,6 +49,10 @@ class AppearancePage : public TabPage void writeSettings(QSettings *settings) override; +#ifdef KF_CONFIGCORE_LIB + void writeSettings(KSharedConfigPtr config) override; +#endif + private slots: void on_styleComboBox_textActivated(const QString &text); void on_colorSchemeComboBox_activated(int); diff --git a/src/qt6ct/iconthemepage.cpp b/src/qt6ct/iconthemepage.cpp index b795000..edd4587 100644 --- a/src/qt6ct/iconthemepage.cpp +++ b/src/qt6ct/iconthemepage.cpp @@ -34,6 +34,9 @@ #include #include #include +#ifdef KF_CONFIGCORE_LIB +#include +#endif #include "qt6ct.h" #include "iconthemepage.h" #include "ui_iconthemepage.h" @@ -71,6 +74,19 @@ void IconThemePage::writeSettings(QSettings *settings) settings->setValue("Appearance/icon_theme", item->data(3, Qt::UserRole)); } +#ifdef KF_CONFIGCORE_LIB +void IconThemePage::writeSettings(KSharedConfigPtr config) +{ + QTreeWidgetItem *item = m_ui->treeWidget->currentItem(); + if(!item) + return; + + KConfigGroup group(config, "Icons"); + group.writeEntry("Theme", item->data(3, Qt::UserRole)); + group.sync(); +} +#endif + void IconThemePage::onFinished() { m_ui->treeWidget->addTopLevelItems(m_items); diff --git a/src/qt6ct/iconthemepage.h b/src/qt6ct/iconthemepage.h index 7f0ab7b..495bf7b 100644 --- a/src/qt6ct/iconthemepage.h +++ b/src/qt6ct/iconthemepage.h @@ -51,6 +51,10 @@ class IconThemePage : public TabPage void writeSettings(QSettings *settings) override; +#ifdef KF_CONFIGCORE_LIB + void writeSettings(KSharedConfigPtr config) override; +#endif + private slots: void onFinished(); diff --git a/src/qt6ct/mainwindow.cpp b/src/qt6ct/mainwindow.cpp index 51819ae..92ba956 100644 --- a/src/qt6ct/mainwindow.cpp +++ b/src/qt6ct/mainwindow.cpp @@ -91,11 +91,19 @@ void MainWindow::on_buttonBox_clicked(QAbstractButton *button) if(id == QDialogButtonBox::Ok || id == QDialogButtonBox::Apply) { QSettings settings(Qt6CT::configFile(), QSettings::IniFormat); +#ifdef KF_CONFIGCORE_LIB + KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals"); +#endif for(int i = 0; i < m_ui->tabWidget->count(); ++i) { TabPage *p = qobject_cast(m_ui->tabWidget->widget(i)); if(p) + { p->writeSettings(&settings); +#ifdef KF_CONFIGCORE_LIB + p->writeSettings(config); +#endif + } } } diff --git a/src/qt6ct/tabpage.h b/src/qt6ct/tabpage.h index 2ff8057..797a1b7 100644 --- a/src/qt6ct/tabpage.h +++ b/src/qt6ct/tabpage.h @@ -32,6 +32,10 @@ #include #include +#ifdef KF_CONFIGCORE_LIB +#include +#endif + class TabPage : public QWidget { Q_OBJECT @@ -39,6 +43,10 @@ class TabPage : public QWidget explicit TabPage(QWidget *parent = nullptr); virtual void writeSettings(QSettings *settings) = 0; + +#ifdef KF_CONFIGCORE_LIB + virtual void writeSettings(KSharedConfigPtr config) {} +#endif }; #endif // TABPAGE_H