Skip to content

Commit

Permalink
Write widget style and icon theme to kdeglobals
Browse files Browse the repository at this point in the history
This allows to style applications that use KStyleManager
  • Loading branch information
ilya-fedin committed Oct 21, 2024
1 parent 7492e37 commit 5addef0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion src/qt6ct/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_NAME_IF_EXISTS:KF6::ConfigCore> qt6ct-common)
target_compile_definitions(qt6ct PRIVATE $<$<TARGET_EXISTS:KF6::ConfigCore>:KF_CONFIGCORE_LIB>)
install(TARGETS qt6ct DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES qt6ct.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
11 changes: 11 additions & 0 deletions src/qt6ct/appearancepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <QMenu>
#include <QIcon>
#include <QStringList>
#ifdef KF_CONFIGCORE_LIB
#include <KSharedConfig>
#include <KConfigGroup>
#endif
#include <qpa/qplatformthemefactory_p.h>
#include "qt6ct.h"
#include "appearancepage.h"
Expand Down Expand Up @@ -110,6 +114,13 @@ void AppearancePage::writeSettings(QSettings *settings)
settings->setValue("color_scheme_path", m_ui->colorSchemeComboBox->currentData().toString());
settings->setValue("standard_dialogs", m_ui->dialogComboBox->currentData().toString());
settings->endGroup();

#ifdef KF_CONFIGCORE_LIB
KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals");
KConfigGroup group(config, "KDE");
group.writeEntry("widgetStyle", "qt6ct-style");
group.sync();
#endif
}

void AppearancePage::on_styleComboBox_textActivated(const QString &text)
Expand Down
17 changes: 15 additions & 2 deletions src/qt6ct/iconthemepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <QProgressBar>
#include <QMetaObject>
#include <QThread>
#ifdef KF_CONFIGCORE_LIB
#include <KSharedConfig>
#include <KConfigGroup>
#endif
#include "qt6ct.h"
#include "iconthemepage.h"
#include "ui_iconthemepage.h"
Expand Down Expand Up @@ -67,8 +71,17 @@ IconThemePage::~IconThemePage()
void IconThemePage::writeSettings(QSettings *settings)
{
QTreeWidgetItem *item = m_ui->treeWidget->currentItem();
if(item)
settings->setValue("Appearance/icon_theme", item->data(3, Qt::UserRole));
if(!item)
return;

settings->setValue("Appearance/icon_theme", item->data(3, Qt::UserRole));

#ifdef KF_CONFIGCORE_LIB
KSharedConfigPtr config = KSharedConfig::openConfig("kdeglobals");
KConfigGroup group(config, "Icons");
group.writeEntry("Theme", item->data(3, Qt::UserRole));
group.sync();
#endif
}

void IconThemePage::onFinished()
Expand Down

0 comments on commit 5addef0

Please sign in to comment.