diff --git a/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml b/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml index 6d9c59da1..b71c8e5f5 100644 --- a/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml +++ b/kcmkwin/kwinrules/package/contents/ui/RulesEditor.qml @@ -1,267 +1,263 @@ /* * Copyright (c) 2020 Ismael Asensio * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.14 import QtQuick.Layouts 1.14 import QtQuick.Controls 2.14 as QQC2 import org.kde.kirigami 2.12 as Kirigami import org.kde.kcm 1.2 import org.kde.kitemmodels 1.0 import org.kde.kcms.kwinrules 1.0 ScrollViewKCM { id: rulesEditor property var rulesModel: kcm.rulesModel title: rulesModel.description view: ListView { id: rulesView clip: true model: enabledRulesModel delegate: RuleItemDelegate {} section { property: "section" delegate: Kirigami.ListSectionHeader { label: section } } Kirigami.PlaceholderMessage { id: hintArea visible: rulesView.count <= 4 - anchors { - top: parent.contentItem.bottom - left: parent.left - right: parent.right - bottom: parent.bottom - } + anchors.centerIn: parent + width: parent.width - (units.largeSpacing * 4) helpfulAction: QQC2.Action { text: i18n("Add Properties...") icon.name: "list-add-symbolic" onTriggered: { propertySheet.open(); } } } } // FIXME: InlineMessage.qml:241:13: QML Label: Binding loop detected for property "verticalAlignment" header: Kirigami.InlineMessage { Layout.fillWidth: true Layout.fillHeight: true text: rulesModel.warningMessage visible: text != "" } footer: RowLayout { QQC2.Button { text: checked ? i18n("Close") : i18n("Add Properties...") icon.name: checked ? "dialog-close" : "list-add-symbolic" checkable: true checked: propertySheet.sheetOpen visible: !hintArea.visible || checked onToggled: { propertySheet.sheetOpen = checked; } } Item { Layout.fillWidth: true } QQC2.Button { text: i18n("Detect Window Properties") icon.name: "edit-find" onClicked: { overlayModel.onlySuggestions = true; rulesModel.detectWindowProperties(delaySpin.value); } } QQC2.SpinBox { id: delaySpin Layout.preferredWidth: Kirigami.Units.gridUnit * 8 from: 0 to: 30 textFromValue: (value, locale) => { return (value == 0) ? i18n("Instantly") : i18np("After %1 second", "After %1 seconds", value) } } } Connections { target: rulesModel onSuggestionsChanged: { propertySheet.sheetOpen = true; } } Kirigami.OverlaySheet { id: propertySheet parent: view header: Kirigami.Heading { text: i18n("Select properties") } footer: Kirigami.SearchField { id: searchField horizontalAlignment: Text.AlignLeft } ListView { id: overlayView model: overlayModel Layout.preferredWidth: Kirigami.Units.gridUnit * 28 section { property: "section" delegate: Kirigami.ListSectionHeader { label: section } } delegate: Kirigami.AbstractListItem { id: propertyDelegate highlighted: false width: ListView.view.width RowLayout { Kirigami.Icon { source: model.icon Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium Layout.alignment: Qt.AlignVCenter } QQC2.Label { id: itemNameLabel text: model.name horizontalAlignment: Qt.AlignLeft Layout.preferredWidth: implicitWidth Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter QQC2.ToolTip { text: model.description visible: hovered && (model.description != "") } } QQC2.Label { id: suggestedLabel text: formatValue(model.suggested, model.type, model.options) horizontalAlignment: Text.AlignRight elide: Text.ElideRight opacity: 0.7 Layout.maximumWidth: propertyDelegate.width - itemNameLabel.implicitWidth - Kirigami.Units.gridUnit * 6 Layout.alignment: Qt.AlignVCenter QQC2.ToolTip { text: suggestedLabel.text visible: hovered && suggestedLabel.truncated } } QQC2.ToolButton { icon.name: (model.enabled) ? "dialog-ok-apply" : "list-add-symbolic" opacity: propertyDelegate.hovered ? 1 : 0 onClicked: propertyDelegate.clicked() Layout.preferredWidth: implicitWidth Layout.leftMargin: -Kirigami.Units.smallSpacing Layout.rightMargin: -Kirigami.Units.smallSpacing Layout.alignment: Qt.AlignVCenter } } onClicked: { model.enabled = true; if (model.suggested != null) { model.value = model.suggested; model.suggested = null; } } } } onSheetOpenChanged: { searchField.text = ""; if (sheetOpen) { searchField.forceActiveFocus(); } else { overlayModel.onlySuggestions = false; } } } function formatValue(value, type, options) { if (value == null) { return ""; } switch (type) { case RuleItem.Boolean: return value ? i18n("Yes") : i18n("No"); case RuleItem.Percentage: return i18n("%1 %", value); case RuleItem.Coordinate: var point = value.split(','); return i18nc("Coordinates (x, y)", "(%1, %2)", point[0], point[1]); case RuleItem.Option: return options.textOfValue(value); case RuleItem.FlagsOption: var selectedValue = value.toString(2).length - 1; return options.textOfValue(selectedValue); } return value; } KSortFilterProxyModel { id: enabledRulesModel sourceModel: rulesModel filterRowCallback: (source_row, source_parent) => { var index = sourceModel.index(source_row, 0, source_parent); return sourceModel.data(index, RulesModel.EnabledRole); } } KSortFilterProxyModel { id: overlayModel sourceModel: rulesModel property bool onlySuggestions: false onOnlySuggestionsChanged: { invalidateFilter(); } filterString: searchField.text.trim().toLowerCase() filterRowCallback: (source_row, source_parent) => { var index = sourceModel.index(source_row, 0, source_parent); var hasSuggestion = sourceModel.data(index, RulesModel.SuggestedValueRole) != null; var isOptional = sourceModel.data(index, RulesModel.SelectableRole); var isEnabled = sourceModel.data(index, RulesModel.EnabledRole); var showItem = hasSuggestion || (!onlySuggestions && isOptional && !isEnabled); if (!showItem) { return false; } if (filterString != "") { return sourceModel.data(index, RulesModel.NameRole).toLowerCase().includes(filterString) } return true; } } } diff --git a/kcmkwin/kwinrules/package/contents/ui/RulesList.qml b/kcmkwin/kwinrules/package/contents/ui/RulesList.qml index e41d6b318..fc486969b 100644 --- a/kcmkwin/kwinrules/package/contents/ui/RulesList.qml +++ b/kcmkwin/kwinrules/package/contents/ui/RulesList.qml @@ -1,261 +1,262 @@ /* * Copyright (c) 2020 Ismael Asensio * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.14 import QtQuick.Layouts 1.14 import QtQuick.Controls 2.14 as QQC2 import QtQml.Models 2.14 import org.kde.kcm 1.2 import org.kde.kirigami 2.12 as Kirigami ScrollViewKCM { id: rulesListKCM // FIXME: ScrollViewKCM.qml:73:13: QML Control: Binding loop detected for property "implicitHeight" implicitWidth: Kirigami.Units.gridUnit * 35 implicitHeight: Kirigami.Units.gridUnit * 25 ConfigModule.columnWidth: Kirigami.Units.gridUnit * 23 ConfigModule.buttons: ConfigModule.Apply property var selectedIndexes: [] // Manage KCM pages Connections { target: kcm onEditIndexChanged: { if (kcm.editIndex < 0) { // If no rule is being edited, hide RulesEdidor page kcm.pop(); } else if (kcm.depth < 2) { // Add the RulesEditor page if it wasn't already kcm.push("RulesEditor.qml"); } } } view: ListView { id: ruleBookView clip: true model: kcm.ruleBookModel currentIndex: kcm.editIndex delegate: Kirigami.DelegateRecycler { width: ruleBookView.width sourceComponent: ruleBookDelegate } displaced: Transition { NumberAnimation { properties: "y"; duration: Kirigami.Units.longDuration } } Kirigami.PlaceholderMessage { visible: ruleBookView.count == 0 - anchors.fill: parent + anchors.centerIn: parent + width: parent.width - (units.largeSpacing * 4) text: i18n("No rules for specific windows are currently set"); } } header: Kirigami.InlineMessage { id: exportInfo icon.source: "document-export" showCloseButton: true text: i18n("Select the rules to export") actions: [ Kirigami.Action { iconName: "object-select-symbolic" text: checked ? i18n("Unselect All") : i18n("Select All") checkable: true checked: selectedIndexes.length == ruleBookView.count onToggled: { if (checked) { selectedIndexes = [...Array(ruleBookView.count).keys()] } else { selectedIndexes = []; } } } , Kirigami.Action { iconName: "document-save" text: i18n("Save Rules") enabled: selectedIndexes.length > 0 onTriggered: { exportDialog.active = true; } } ] } footer: RowLayout { QQC2.Button { text: i18n("Add New...") icon.name: "list-add-symbolic" enabled: !exportInfo.visible onClicked: { kcm.createRule(); } } Item { Layout.fillWidth: true } QQC2.Button { text: i18n("Import...") icon.name: "document-import" enabled: !exportInfo.visible onClicked: { importDialog.active = true; } } QQC2.Button { text: checked ? i18n("Cancel Export") : i18n("Export...") icon.name: exportInfo.visible ? "dialog-cancel" : "document-export" enabled: ruleBookView.count > 0 checkable: true checked: exportInfo.visible onToggled: { selectedIndexes = [] exportInfo.visible = checked; } } } Component { id: ruleBookDelegate Kirigami.AbstractListItem { id: ruleBookItem RowLayout { //FIXME: If not used within DelegateRecycler, item goes on top of the first item when clicked Kirigami.ListItemDragHandle { visible: !exportInfo.visible listItem: ruleBookItem listView: ruleBookView onMoveRequested: { kcm.moveRule(oldIndex, newIndex); } } QQC2.TextField { id: descriptionField Layout.minimumWidth: Kirigami.Units.gridUnit * 2 Layout.fillWidth: true background: Item {} horizontalAlignment: Text.AlignLeft text: display onEditingFinished: { kcm.setRuleDescription(index, text); } Keys.onPressed: { switch (event.key) { case Qt.Key_Escape: // On key reset to model data before losing focus text = display; case Qt.Key_Enter: case Qt.Key_Return: case Qt.Key_Tab: ruleBookItem.forceActiveFocus(); event.accepted = true; break; } } MouseArea { anchors.fill: parent enabled: exportInfo.visible cursorShape: enabled ? Qt.PointingHandCursor : Qt.IBeamCursor onClicked: { itemSelectionCheck.toggle(); itemSelectionCheck.toggled(); } } } Kirigami.ActionToolBar { Layout.preferredWidth: maximumContentWidth + Kirigami.Units.smallSpacing alignment: Qt.AlignRight display: QQC2.Button.IconOnly visible: !exportInfo.visible opacity: ruleBookItem.hovered ? 1 : 0 focus: false actions: [ Kirigami.Action { text: i18n("Edit") iconName: "edit-entry" onTriggered: { kcm.editRule(index); } } , Kirigami.Action { text: i18n("Delete") iconName: "entry-delete" onTriggered: { kcm.removeRule(index); } } ] } QQC2.CheckBox { id: itemSelectionCheck visible: exportInfo.visible checked: selectedIndexes.includes(index) onToggled: { var position = selectedIndexes.indexOf(index); if (checked) { if (position < 0) { selectedIndexes.push(index); } } else { if (position >= 0) { selectedIndexes.splice(position, 1); } } selectedIndexesChanged(); } } } } } FileDialogLoader { id: importDialog title: i18n("Import Rules") isSaveDialog: false onLastFolderChanged: { exportDialog.lastFolder = lastFolder; } onFileSelected: { kcm.importFromFile(path); } } FileDialogLoader { id: exportDialog title: i18n("Export Rules") isSaveDialog: true onLastFolderChanged: { importDialog.lastFolder = lastFolder; } onFileSelected: { selectedIndexes.sort(); kcm.exportToFile(path, selectedIndexes); exportInfo.visible = false; } } }