From 25ac108a7656368d0c4adfa339562fdf76768a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 25 Aug 2012 09:54:20 +0200 Subject: [PATCH] Support for custom configuration dialogs for QML decorations If the decoration package contains a ui file in ui/config.ui and and KConfigXT xml file in config/main.xml the configure dialog is extended by the custom values. For this the ui file is loaded and included in the dialog's layout. To make this possible the AuroraeConfigForm is changed to a VBoxLayout containing the so far used FormLayout. The configuration settings are loaded using Plasma's ConfigLoader and attached to the widget through a KConfigDialogManager. Marking this commit as the one which implements QML support for Aurorae themes: REVIEW: 105751 REVIEW: 105768 BUG: 303810 FIXED-IN: 4.10 --- kcmkwin/kwindecoration/CMakeLists.txt | 2 +- kcmkwin/kwindecoration/auroraeconfig.ui | 209 +++++++++++---------- kcmkwin/kwindecoration/decorationmodel.cpp | 8 + kcmkwin/kwindecoration/decorationmodel.h | 2 + kcmkwin/kwindecoration/kwindecoration.cpp | 32 ++++ 5 files changed, 148 insertions(+), 105 deletions(-) diff --git a/kcmkwin/kwindecoration/CMakeLists.txt b/kcmkwin/kwindecoration/CMakeLists.txt index 7d51e979c3..2b4d5ceca1 100644 --- a/kcmkwin/kwindecoration/CMakeLists.txt +++ b/kcmkwin/kwindecoration/CMakeLists.txt @@ -24,7 +24,7 @@ kde4_add_ui_files(kcm_kwindecoration_PART_SRCS ) kde4_add_plugin(kcm_kwindecoration ${kcm_kwindecoration_PART_SRCS}) -target_link_libraries(kcm_kwindecoration ${KDE4_KNEWSTUFF3_LIBS} kdecorations ${QT_QTDECLARATIVE_LIBRARY} ${X11_LIBRARIES}) +target_link_libraries(kcm_kwindecoration ${KDE4_KNEWSTUFF3_LIBS} kdecorations ${KDE4_PLASMA_LIBS} ${QT_QTDECLARATIVE_LIBRARY} ${QT_QTUITOOLS_LIBRARY} ${X11_LIBRARIES}) install(TARGETS kcm_kwindecoration DESTINATION ${PLUGIN_INSTALL_DIR} ) ########### install files ############### diff --git a/kcmkwin/kwindecoration/auroraeconfig.ui b/kcmkwin/kwindecoration/auroraeconfig.ui index 96e006624b..168709b0e4 100644 --- a/kcmkwin/kwindecoration/auroraeconfig.ui +++ b/kcmkwin/kwindecoration/auroraeconfig.ui @@ -6,113 +6,114 @@ 0 0 - 400 - 300 + 384 + 95 - - - QFormLayout::ExpandingFieldsGrow - - - - - Border size: - - - borderSizesCombo - - + + + + + + + Border size: + + + borderSizesCombo + + + + + + + + Tiny + + + + + Normal + + + + + Large + + + + + Very Large + + + + + Huge + + + + + Very Huge + + + + + Oversized + + + + + + + + Button size: + + + buttonSizesCombo + + + + + + + + Tiny + + + + + Normal + + + + + Large + + + + + Very Large + + + + + Huge + + + + + Very Huge + + + + + Oversized + + + + + - - - - - Tiny - - - - - Normal - - - - - Large - - - - - Very Large - - - - - Huge - - - - - Very Huge - - - - - Oversized - - - - - - - - Button size: - - - buttonSizesCombo - - - - - - - - Tiny - - - - - Normal - - - - - Large - - - - - Very Large - - - - - Huge - - - - - Very Huge - - - - - Oversized - - - - - + diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index d62d2f1657..022c80ad0c 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -457,4 +457,12 @@ QVariant DecorationModel::readConfig(const QString &themeName, const QString &ke return m_config->group(themeName).readEntry(key, defaultValue); } +void DecorationModel::notifyConfigChanged(const QModelIndex &index) +{ + if (!index.isValid()) { + return; + } + emit configChanged(m_decorations[index.row()].auroraeName); +} + } // namespace KWin diff --git a/kcmkwin/kwindecoration/decorationmodel.h b/kcmkwin/kwindecoration/decorationmodel.h index fe740b19ed..efc6d7ad72 100644 --- a/kcmkwin/kwindecoration/decorationmodel.h +++ b/kcmkwin/kwindecoration/decorationmodel.h @@ -121,6 +121,8 @@ public: Q_INVOKABLE QVariant readConfig(const QString &themeName, const QString &key, const QVariant &defaultValue = QVariant()); + void notifyConfigChanged(const QModelIndex &index); + Q_SIGNALS: void configChanged(QString themeName); public slots: diff --git a/kcmkwin/kwindecoration/kwindecoration.cpp b/kcmkwin/kwindecoration/kwindecoration.cpp index aaa792ec40..ea932705d6 100644 --- a/kcmkwin/kwindecoration/kwindecoration.cpp +++ b/kcmkwin/kwindecoration/kwindecoration.cpp @@ -43,13 +43,16 @@ #include #include #include +#include // KDE #include #include #include #include #include +#include #include +#include #include // KCModule plugin interface @@ -353,10 +356,39 @@ void KWinDecorationModule::slotConfigureDecoration() form->borderSizesCombo->setCurrentIndex(index.data(DecorationModel::BorderSizeRole).toInt()); form->buttonSizesCombo->setCurrentIndex(index.data(DecorationModel::ButtonSizeRole).toInt()); form->closeWindowsDoubleClick->setChecked(index.data(DecorationModel::CloseOnDblClickRole).toBool()); + // in case of QmlDecoration look for a config.ui in the package structure + KConfigDialogManager *configManager = NULL; + if (index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration) { + const QString packageName = index.data(DecorationModel::AuroraeNameRole).toString(); + const QString uiPath = KStandardDirs::locate("data", "kwin/decorations/" + packageName + "/contents/ui/config.ui"); + const QString configPath = KStandardDirs::locate("data", "kwin/decorations/" + packageName + "/contents/config/main.xml"); + if (!uiPath.isEmpty() && !configPath.isEmpty()) { + // load the KConfigSkeleton + QFile configFile(configPath); + KSharedConfigPtr auroraeConfig = KSharedConfig::openConfig("auroraerc"); + KConfigGroup configGroup = auroraeConfig->group(packageName); + Plasma::ConfigLoader *skeleton = new Plasma::ConfigLoader(&configGroup, &configFile, dlg); + // load the ui file + QUiLoader *loader = new QUiLoader(dlg); + QFile uiFile(uiPath); + uiFile.open(QFile::ReadOnly); + QWidget *customConfigForm = loader->load(&uiFile, form); + uiFile.close(); + form->layout()->addWidget(customConfigForm); + // connect the ui file with the skeleton + configManager = new KConfigDialogManager(customConfigForm, skeleton); + configManager->updateWidgets(); + } + } if (dlg->exec() == KDialog::Accepted) { m_model->setData(index, form->borderSizesCombo->currentIndex(), DecorationModel::BorderSizeRole); m_model->setData(index, form->buttonSizesCombo->currentIndex(), DecorationModel::ButtonSizeRole); m_model->setData(index, form->closeWindowsDoubleClick->isChecked(), DecorationModel::CloseOnDblClickRole); + if (configManager && configManager->hasChanged()) { + // we have a config manager and the settings changed + configManager->updateSettings(); + m_model->notifyConfigChanged(index); + } reload = true; } delete dlg;