Support for config values in QML decorations
When the decoration is reset a signal is emitted that the config might have changed which the decoration can connect to for reloading its configuration. For this an invokable method is added to Aurorae allowing to read a config value which just returns the QVariant. Proper support for border sizes are added by providing the enum in DecorationOptions, so that QML themes can use the enum values to decide which border size to use. The kcm is adjusted to also support these config mechanisms and to properly load and save the border sizes for QML based themes.
This commit is contained in:
parent
13993a6efb
commit
ce2b251c9b
7 changed files with 77 additions and 8 deletions
|
@ -85,6 +85,7 @@ void AuroraeFactory::initAurorae(KConfig &conf, KConfigGroup &group)
|
|||
m_component->loadUrl(QUrl(KStandardDirs::locate("data", "kwin/aurorae/aurorae.qml")));
|
||||
m_engine->rootContext()->setContextProperty("auroraeTheme", m_theme);
|
||||
m_engine->rootContext()->setContextProperty("options", this);
|
||||
m_themeName = themeName;
|
||||
}
|
||||
|
||||
void AuroraeFactory::initQML(const KConfigGroup &group)
|
||||
|
@ -117,6 +118,7 @@ void AuroraeFactory::initQML(const KConfigGroup &group)
|
|||
m_engine->addImportPath(importPath);
|
||||
}
|
||||
m_component->loadUrl(QUrl::fromLocalFile(file));
|
||||
m_themeName = themeName;
|
||||
}
|
||||
|
||||
AuroraeFactory::~AuroraeFactory()
|
||||
|
@ -159,6 +161,7 @@ bool AuroraeFactory::reset(unsigned long changed)
|
|||
m_theme->setBorderSize((KDecorationDefines::BorderSize)themeGroup.readEntry<int>("BorderSize", KDecorationDefines::BorderNormal));
|
||||
m_theme->setButtonSize((KDecorationDefines::BorderSize)themeGroup.readEntry<int>("ButtonSize", KDecorationDefines::BorderNormal));
|
||||
}
|
||||
emit configChanged();
|
||||
return false; // need hard reset
|
||||
}
|
||||
|
||||
|
@ -248,6 +251,7 @@ AuroraeClient::AuroraeClient(KDecorationBridge *bridge, KDecorationFactory *fact
|
|||
connect(this, SIGNAL(keepAboveChanged(bool)), SIGNAL(keepAboveChangedWrapper()));
|
||||
connect(this, SIGNAL(keepBelowChanged(bool)), SIGNAL(keepBelowChangedWrapper()));
|
||||
connect(AuroraeFactory::instance(), SIGNAL(buttonsChanged()), SIGNAL(buttonsChanged()));
|
||||
connect(AuroraeFactory::instance(), SIGNAL(configChanged()), SIGNAL(configChanged()));
|
||||
}
|
||||
|
||||
AuroraeClient::~AuroraeClient()
|
||||
|
@ -556,6 +560,12 @@ void AuroraeClient::doTitlebarDblClickOperation()
|
|||
KDecorationUnstable::titlebarDblClickOperation();
|
||||
}
|
||||
|
||||
QVariant AuroraeClient::readConfig(const QString &key, const QVariant &defaultValue)
|
||||
{
|
||||
KSharedConfigPtr config = KSharedConfig::openConfig("auroraerc");
|
||||
return config->group(AuroraeFactory::instance()->currentThemeName()).readEntry(key, defaultValue);
|
||||
}
|
||||
|
||||
} // namespace Aurorae
|
||||
|
||||
extern "C"
|
||||
|
|
|
@ -61,6 +61,9 @@ public:
|
|||
QString leftButtons();
|
||||
QString rightButtons();
|
||||
bool customButtonPositions();
|
||||
const QString ¤tThemeName() const {
|
||||
return m_themeName;
|
||||
}
|
||||
|
||||
QFont activeTitleFont();
|
||||
QFont inactiveTitleFont();
|
||||
|
@ -78,6 +81,7 @@ private:
|
|||
Q_SIGNALS:
|
||||
void buttonsChanged();
|
||||
void titleFontChanged();
|
||||
void configChanged();
|
||||
|
||||
private:
|
||||
static AuroraeFactory *s_instance;
|
||||
|
@ -86,6 +90,7 @@ private:
|
|||
QDeclarativeEngine *m_engine;
|
||||
QDeclarativeComponent *m_component;
|
||||
EngineType m_engineType;
|
||||
QString m_themeName;
|
||||
};
|
||||
|
||||
class AuroraeClient : public KDecorationUnstable
|
||||
|
@ -138,6 +143,8 @@ public:
|
|||
bool isMaximized() const;
|
||||
int doubleClickInterval() const;
|
||||
|
||||
Q_INVOKABLE QVariant readConfig(const QString &key, const QVariant &defaultValue = QVariant());
|
||||
|
||||
Q_SIGNALS:
|
||||
void activeChanged();
|
||||
void captionChanged();
|
||||
|
@ -148,6 +155,11 @@ Q_SIGNALS:
|
|||
void keepAboveChangedWrapper();
|
||||
void keepBelowChangedWrapper();
|
||||
void buttonsChanged();
|
||||
/**
|
||||
* Signal emitted when the decoration's configuration might have changed.
|
||||
* A decoration could reload it's configuration when this signal is emitted.
|
||||
**/
|
||||
void configChanged();
|
||||
|
||||
public slots:
|
||||
void menuClicked();
|
||||
|
|
|
@ -51,6 +51,7 @@ namespace KWin
|
|||
class DecorationOptions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(BorderSize)
|
||||
/**
|
||||
* The decoration Object for which this set of options should be used. The decoration is
|
||||
* required to get the correct colors and fonts depending on whether the decoration represents
|
||||
|
@ -112,6 +113,15 @@ class DecorationOptions : public QObject
|
|||
**/
|
||||
Q_PROPERTY(QString titleButtonsRight READ titleButtonsRight NOTIFY titleButtonsChanged)
|
||||
public:
|
||||
enum BorderSize {
|
||||
BorderTiny, ///< Minimal borders
|
||||
BorderNormal, ///< Standard size borders, the default setting
|
||||
BorderLarge, ///< Larger borders
|
||||
BorderVeryLarge, ///< Very large borders
|
||||
BorderHuge, ///< Huge borders
|
||||
BorderVeryHuge, ///< Very huge borders
|
||||
BorderOversized ///< Oversized borders
|
||||
};
|
||||
explicit DecorationOptions(QObject *parent = 0);
|
||||
virtual ~DecorationOptions();
|
||||
|
||||
|
|
|
@ -69,6 +69,8 @@ DecorationModel::DecorationModel(KSharedConfigPtr config, QObject* parent)
|
|||
roleNames[TypeRole] = "type";
|
||||
roleNames[AuroraeNameRole] = "auroraeThemeName";
|
||||
roleNames[QmlMainScriptRole] = "mainScript";
|
||||
roleNames[BorderSizeRole] = "borderSize";
|
||||
roleNames[ButtonSizeRole] = "buttonSize";
|
||||
setRoleNames(roleNames);
|
||||
m_config = KSharedConfig::openConfig("auroraerc");
|
||||
findDecorations();
|
||||
|
@ -136,9 +138,9 @@ void DecorationModel::findDecorations()
|
|||
// not a valid QML theme
|
||||
continue;
|
||||
}
|
||||
// TODO: read proper border sizes
|
||||
data.borderSize = KDecorationDefines::BorderNormal;
|
||||
data.buttonSize = KDecorationDefines::BorderNormal;
|
||||
KConfigGroup config(m_config, data.auroraeName);
|
||||
data.borderSize = (KDecorationDefines::BorderSize)config.readEntry< int >("BorderSize", KDecorationDefines::BorderNormal);
|
||||
data.buttonSize = (KDecorationDefines::BorderSize)config.readEntry< int >("ButtonSize", KDecorationDefines::BorderNormal);
|
||||
data.comment = service->comment();
|
||||
KPluginInfo info(service);
|
||||
data.author = info.author();
|
||||
|
@ -243,7 +245,8 @@ QVariant DecorationModel::data(const QModelIndex& index, int role) const
|
|||
return sizes;
|
||||
}
|
||||
case ButtonSizeRole:
|
||||
if (m_decorations[ index.row()].type == DecorationModelData::AuroraeDecoration)
|
||||
if (m_decorations[ index.row()].type == DecorationModelData::AuroraeDecoration ||
|
||||
m_decorations[ index.row()].type == DecorationModelData::QmlDecoration)
|
||||
return static_cast< int >(m_decorations[ index.row()].buttonSize);
|
||||
else
|
||||
return QVariant();
|
||||
|
@ -259,23 +262,27 @@ bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, i
|
|||
if (!index.isValid() || (role != BorderSizeRole && role != ButtonSizeRole))
|
||||
return QAbstractItemModel::setData(index, value, role);
|
||||
|
||||
const DecorationModelData::DecorationType type = m_decorations[ index.row()].type;
|
||||
|
||||
if (role == BorderSizeRole) {
|
||||
m_decorations[ index.row()].borderSize = (KDecorationDefines::BorderSize)value.toInt();
|
||||
if (m_decorations[ index.row()].type == DecorationModelData::AuroraeDecoration) {
|
||||
if (type == DecorationModelData::AuroraeDecoration || type == DecorationModelData::QmlDecoration) {
|
||||
KConfigGroup config(m_config, m_decorations[ index.row()].auroraeName);
|
||||
config.writeEntry("BorderSize", value.toInt());
|
||||
config.sync();
|
||||
}
|
||||
emit dataChanged(index, index);
|
||||
emit configChanged(m_decorations[ index.row()].auroraeName);
|
||||
regeneratePreview(index);
|
||||
return true;
|
||||
}
|
||||
if (role == ButtonSizeRole && m_decorations[ index.row()].type == DecorationModelData::AuroraeDecoration) {
|
||||
if (role == ButtonSizeRole && (type == DecorationModelData::AuroraeDecoration || type == DecorationModelData::QmlDecoration)) {
|
||||
m_decorations[ index.row()].buttonSize = (KDecorationDefines::BorderSize)value.toInt();
|
||||
KConfigGroup config(m_config, m_decorations[ index.row()].auroraeName);
|
||||
config.writeEntry("ButtonSize", value.toInt());
|
||||
config.sync();
|
||||
emit dataChanged(index, index);
|
||||
emit configChanged(m_decorations[ index.row()].auroraeName);
|
||||
regeneratePreview(index);
|
||||
return true;
|
||||
}
|
||||
|
@ -423,9 +430,14 @@ QModelIndex DecorationModel::indexOfAuroraeName(const QString &auroraeName, cons
|
|||
|
||||
void DecorationModel::setBorderSize(const QModelIndex& index, KDecorationDefines::BorderSize size)
|
||||
{
|
||||
if (!index.isValid() || m_decorations[ index.row()].type == DecorationModelData::AuroraeDecoration)
|
||||
if (!index.isValid() || m_decorations[ index.row()].type == DecorationModelData::AuroraeDecoration || m_decorations[ index.row()].type == DecorationModelData::QmlDecoration)
|
||||
return;
|
||||
m_decorations[ index.row()].borderSize = size;
|
||||
}
|
||||
|
||||
QVariant DecorationModel::readConfig(const QString &themeName, const QString &key, const QVariant &defaultValue)
|
||||
{
|
||||
return m_config->group(themeName).readEntry(key, defaultValue);
|
||||
}
|
||||
|
||||
} // namespace KWin
|
||||
|
|
|
@ -112,6 +112,11 @@ public:
|
|||
|
||||
void regeneratePreviews(int firstIndex = 0);
|
||||
void stopPreviewGeneration();
|
||||
|
||||
Q_INVOKABLE QVariant readConfig(const QString &themeName, const QString &key, const QVariant &defaultValue = QVariant());
|
||||
|
||||
Q_SIGNALS:
|
||||
void configChanged(QString themeName);
|
||||
public slots:
|
||||
void regeneratePreview(const QModelIndex& index, const QSize& size);
|
||||
private slots:
|
||||
|
|
|
@ -98,6 +98,7 @@ KWinDecorationModule::KWinDecorationModule(QWidget* parent, const QVariantList &
|
|||
m_ui->decorationList->engine()->addImportPath(importPath);
|
||||
}
|
||||
m_ui->decorationList->rootContext()->setContextProperty("decorationModel", m_proxyModel);
|
||||
m_ui->decorationList->rootContext()->setContextProperty("decorationBaseModel", m_model);
|
||||
m_ui->decorationList->rootContext()->setContextProperty("options", m_decorationButtons);
|
||||
m_ui->decorationList->rootContext()->setContextProperty("highlightColor", m_ui->decorationList->palette().color(QPalette::Highlight));
|
||||
m_ui->decorationList->rootContext()->setContextProperty("sliderWidth", m_ui->decorationList->verticalScrollBar()->width());
|
||||
|
@ -342,7 +343,8 @@ void KWinDecorationModule::slotConfigureDecoration()
|
|||
{
|
||||
const QModelIndex index = m_proxyModel->mapToSource(m_proxyModel->index(m_ui->decorationList->rootObject()->property("currentIndex").toInt(), 0));
|
||||
bool reload = false;
|
||||
if (index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::AuroraeDecoration) {
|
||||
if (index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::AuroraeDecoration ||
|
||||
index.data(DecorationModel::TypeRole).toInt() == DecorationModelData::QmlDecoration) {
|
||||
QPointer< KDialog > dlg = new KDialog(this);
|
||||
dlg->setCaption(i18n("Decoration Options"));
|
||||
dlg->setButtons(KDialog::Ok | KDialog::Cancel);
|
||||
|
|
|
@ -20,6 +20,7 @@ Item {
|
|||
property alias active: decoration.active
|
||||
property alias source: auroraeLoader.source
|
||||
QtObject {
|
||||
signal configChanged
|
||||
id: decoration
|
||||
property bool active: false
|
||||
property string caption: display
|
||||
|
@ -43,9 +44,26 @@ Item {
|
|||
property string leftButtons: "MS"
|
||||
property string rightButtons: "HIA__X"
|
||||
function titleMouseMoved() {}
|
||||
function readConfig(key, defaultValue) {
|
||||
if (key == "BorderSize") {
|
||||
return borderSize;
|
||||
} else if (key == "ButtonSize") {
|
||||
return buttonSize;
|
||||
} else {
|
||||
return decorationBaseModel.readConfig(auroraeThemeName, key, defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loader {
|
||||
id: auroraeLoader
|
||||
anchors.fill: parent
|
||||
}
|
||||
Connections {
|
||||
target: decorationBaseModel
|
||||
onConfigChanged: {
|
||||
if (auroraeThemeName == themeName) {
|
||||
decoration.configChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue