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
This commit is contained in:
Martin Gräßlin 2012-08-25 09:54:20 +02:00
parent 8de1fea67e
commit 25ac108a76
5 changed files with 148 additions and 105 deletions

View file

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

View file

@ -6,113 +6,114 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>384</width>
<height>95</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Border size:</string>
</property>
<property name="buddy">
<cstring>borderSizesCombo</cstring>
</property>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Border size:</string>
</property>
<property name="buddy">
<cstring>borderSizesCombo</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KComboBox" name="borderSizesCombo">
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Tiny</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Normal</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Very Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Very Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Oversized</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Button size:</string>
</property>
<property name="buddy">
<cstring>buttonSizesCombo</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KComboBox" name="buttonSizesCombo">
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Tiny</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Normal</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Very Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Very Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Oversized</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="KComboBox" name="borderSizesCombo">
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Tiny</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Normal</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Very Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Very Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Oversized</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Button size:</string>
</property>
<property name="buddy">
<cstring>buttonSizesCombo</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KComboBox" name="buttonSizesCombo">
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Tiny</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Normal</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Very Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Very Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Oversized</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item>
<widget class="QCheckBox" name="closeWindowsDoubleClick">
<property name="toolTip">
<string extracomment="Check this option if you want windows to be closed when you double click the menu button."/>

View file

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

View file

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

View file

@ -43,13 +43,16 @@
#include <QtGui/QSortFilterProxyModel>
#include <QtGui/QGraphicsObject>
#include <QtGui/QScrollBar>
#include <QUiLoader>
// KDE
#include <KAboutData>
#include <KDialog>
#include <KLocale>
#include <KNS3/DownloadDialog>
#include <KDE/KStandardDirs>
#include <KDE/KConfigDialogManager>
#include <KPluginFactory>
#include <Plasma/ConfigLoader>
#include <qdeclarative.h>
// 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;