From 8de1fea67e4f05234690f8a72792c919b39b6b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 24 Aug 2012 15:16:30 +0200 Subject: [PATCH] Option to disable window close on menu double click in Aurorae For each theme the setting can be enabled individually with the default being enabled by default. It is completely handled inside the MenuButton QML component so each QML theme benefits from the option automatically, too. BUG: 301327 FIXED-IN: 4.10 REVIEW: 106160 --- clients/aurorae/src/qml/MenuButton.qml | 22 +++++++++++++++++++--- kcmkwin/kwindecoration/auroraeconfig.ui | 10 ++++++++++ kcmkwin/kwindecoration/decorationmodel.cpp | 19 ++++++++++++++++++- kcmkwin/kwindecoration/decorationmodel.h | 8 +++++++- kcmkwin/kwindecoration/kwindecoration.cpp | 2 ++ 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/clients/aurorae/src/qml/MenuButton.qml b/clients/aurorae/src/qml/MenuButton.qml index e2f67ecd5e..4b8401d2b6 100644 --- a/clients/aurorae/src/qml/MenuButton.qml +++ b/clients/aurorae/src/qml/MenuButton.qml @@ -18,6 +18,8 @@ import QtQuick 1.1 import org.kde.qtextracomponents 0.1 as QtExtra DecorationButton { + property bool closeOnDoubleClick: true + id: menuButton buttonType: "M" QtExtra.QIconItem { icon: decoration.icon @@ -40,7 +42,7 @@ DecorationButton { // the double click delay to ensure that it was only a single click. if (timer.running) { timer.stop(); - } else { + } else if (menuButton.closeOnDoubleClick) { timer.start(); } } @@ -59,11 +61,25 @@ DecorationButton { } onClicked: { // for right clicks we show the menu instantly - if (mouse.button == Qt.RightButton) { + // and if the option is disabled we always show menu directly + if (!menuButton.closeOnDoubleClick || mouse.button == Qt.RightButton) { decoration.menuClicked(); timer.stop(); } } - onDoubleClicked: decoration.closeWindow() + onDoubleClicked: { + if (menuButton.closeOnDoubleClick) { + decoration.closeWindow(); + } + } + } + Component.onCompleted: { + menuButton.closeOnDoubleClick = decoration.readConfig("CloseOnDoubleClickMenuButton", true); + } + Connections { + target: decoration + onConfigChanged: { + menuButton.closeOnDoubleClick = decoration.readConfig("CloseOnDoubleClickMenuButton", true); + } } } diff --git a/kcmkwin/kwindecoration/auroraeconfig.ui b/kcmkwin/kwindecoration/auroraeconfig.ui index 776214029d..96e006624b 100644 --- a/kcmkwin/kwindecoration/auroraeconfig.ui +++ b/kcmkwin/kwindecoration/auroraeconfig.ui @@ -112,6 +112,16 @@ + + + + + + + Close windows by double clicking the menu button + + + diff --git a/kcmkwin/kwindecoration/decorationmodel.cpp b/kcmkwin/kwindecoration/decorationmodel.cpp index 8ac4a3f3ed..d62d2f1657 100644 --- a/kcmkwin/kwindecoration/decorationmodel.cpp +++ b/kcmkwin/kwindecoration/decorationmodel.cpp @@ -118,6 +118,7 @@ void DecorationModel::findDecorations() data.libraryName = libName; data.type = DecorationModelData::NativeDecoration; data.borderSize = KDecorationDefines::BorderNormal; + data.closeDblClick = false; metaData(data, desktopFile); m_decorations.append(data); } @@ -141,6 +142,7 @@ void DecorationModel::findDecorations() 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.closeDblClick = config.readEntry< bool >("CloseOnDoubleClickMenuButton", true); data.comment = service->comment(); KPluginInfo info(service); data.author = info.author(); @@ -180,6 +182,7 @@ void DecorationModel::findAuroraeThemes() 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.closeDblClick = config.readEntry< bool >("CloseOnDoubleClickMenuButton", true); metaData(data, df); m_decorations.append(data); } @@ -252,6 +255,8 @@ QVariant DecorationModel::data(const QModelIndex& index, int role) const return QVariant(); case QmlMainScriptRole: return m_decorations[ index.row()].qmlPath; + case CloseOnDblClickRole: + return m_decorations[index.row()].closeDblClick; default: return QVariant(); } @@ -259,7 +264,7 @@ QVariant DecorationModel::data(const QModelIndex& index, int role) const bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, int role) { - if (!index.isValid() || (role != BorderSizeRole && role != ButtonSizeRole)) + if (!index.isValid() || (role != BorderSizeRole && role != ButtonSizeRole && role != CloseOnDblClickRole)) return QAbstractItemModel::setData(index, value, role); const DecorationModelData::DecorationType type = m_decorations[ index.row()].type; @@ -286,6 +291,18 @@ bool DecorationModel::setData(const QModelIndex& index, const QVariant& value, i regeneratePreview(index); return true; } + if (role == CloseOnDblClickRole && (type == DecorationModelData::AuroraeDecoration || type == DecorationModelData::QmlDecoration)) { + if (m_decorations[ index.row()].closeDblClick == value.toBool()) { + return false; + } + m_decorations[ index.row()].closeDblClick = value.toBool(); + KConfigGroup config(m_config, m_decorations[ index.row()].auroraeName); + config.writeEntry("CloseOnDoubleClickMenuButton", value.toBool()); + config.sync(); + emit dataChanged(index, index); + emit configChanged(m_decorations[ index.row()].auroraeName); + return true; + } return QAbstractItemModel::setData(index, value, role); } diff --git a/kcmkwin/kwindecoration/decorationmodel.h b/kcmkwin/kwindecoration/decorationmodel.h index 11bc3741dd..fe740b19ed 100644 --- a/kcmkwin/kwindecoration/decorationmodel.h +++ b/kcmkwin/kwindecoration/decorationmodel.h @@ -57,6 +57,11 @@ public: QString qmlPath; KDecorationDefines::BorderSize borderSize; KDecorationDefines::BorderSize buttonSize; + /** + * Whether the window gets closed on double clicking the Menu Button. + * Only applies for Aurorae and QML Decoration. + **/ + bool closeDblClick; static bool less(const DecorationModelData& a, const DecorationModelData& b) { return a.name < b.name; @@ -82,7 +87,8 @@ public: BorderSizeRole = Qt::UserRole + 11, BorderSizesRole = Qt::UserRole + 12, ButtonSizeRole = Qt::UserRole + 13, - QmlMainScriptRole = Qt::UserRole + 14 + QmlMainScriptRole = Qt::UserRole + 14, + CloseOnDblClickRole = Qt::UserRole + 15 }; DecorationModel(KSharedConfigPtr config, QObject* parent = 0); ~DecorationModel(); diff --git a/kcmkwin/kwindecoration/kwindecoration.cpp b/kcmkwin/kwindecoration/kwindecoration.cpp index 95e755e91e..aaa792ec40 100644 --- a/kcmkwin/kwindecoration/kwindecoration.cpp +++ b/kcmkwin/kwindecoration/kwindecoration.cpp @@ -352,9 +352,11 @@ void KWinDecorationModule::slotConfigureDecoration() dlg->setMainWidget(form); form->borderSizesCombo->setCurrentIndex(index.data(DecorationModel::BorderSizeRole).toInt()); form->buttonSizesCombo->setCurrentIndex(index.data(DecorationModel::ButtonSizeRole).toInt()); + form->closeWindowsDoubleClick->setChecked(index.data(DecorationModel::CloseOnDblClickRole).toBool()); 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); reload = true; } delete dlg;