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 33e0cf8
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
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)
12 changes: 12 additions & 0 deletions src/qt6ct/appearancepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <QMenu>
#include <QIcon>
#include <QStringList>
#ifdef KF_CONFIGCORE_LIB
#include <KConfigGroup>
#endif
#include <qpa/qplatformthemefactory_p.h>
#include "qt6ct.h"
#include "appearancepage.h"
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/qt6ct/appearancepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/qt6ct/iconthemepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include <QProgressBar>
#include <QMetaObject>
#include <QThread>
#ifdef KF_CONFIGCORE_LIB
#include <KConfigGroup>
#endif
#include "qt6ct.h"
#include "iconthemepage.h"
#include "ui_iconthemepage.h"
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/qt6ct/iconthemepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 8 additions & 0 deletions src/qt6ct/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TabPage*>(m_ui->tabWidget->widget(i));
if(p)
{
p->writeSettings(&settings);
#ifdef KF_CONFIGCORE_LIB
p->writeSettings(config);
#endif
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/qt6ct/tabpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@
#include <QWidget>
#include <QSettings>

#ifdef KF_CONFIGCORE_LIB
#include <KSharedConfig>
#endif

class TabPage : public QWidget
{
Q_OBJECT
public:
explicit TabPage(QWidget *parent = nullptr);

virtual void writeSettings(QSettings *settings) = 0;

#ifdef KF_CONFIGCORE_LIB
virtual void writeSettings(KSharedConfigPtr config) {}
#endif
};

#endif // TABPAGE_H

0 comments on commit 33e0cf8

Please sign in to comment.