Warning, /plasma/kwin/src/kcms/desktop/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Controls as QQC2
0009 import QtQuick.Layouts
0010 
0011 import org.kde.kcmutils as KCM
0012 import org.kde.kirigami 2.20 as Kirigami
0013 
0014 KCM.ScrollViewKCM {
0015     id: root
0016 
0017     Connections {
0018         target: kcm.desktopsModel
0019 
0020         function onReadyChanged() {
0021             rowsSpinBox.value = kcm.desktopsModel.rows;
0022         }
0023 
0024         function onRowsChanged() {
0025             rowsSpinBox.value = kcm.desktopsModel.rows;
0026         }
0027     }
0028     implicitWidth: Kirigami.Units.gridUnit * 35
0029     implicitHeight: Kirigami.Units.gridUnit * 30
0030 
0031     Component {
0032         id: desktopsListItemComponent
0033 
0034         QQC2.ItemDelegate {
0035             width: ListView.view.width
0036             down: false  // Disable press effect
0037             hoverEnabled: false
0038 
0039             contentItem: RowLayout {
0040                 QQC2.TextField {
0041                     id: nameField
0042 
0043                     background: null
0044                     leftPadding: Kirigami.Units.largeSpacing
0045                     topPadding: 0
0046                     bottomPadding: 0
0047 
0048                     Layout.fillWidth: true
0049                     Layout.fillHeight: true
0050 
0051                     text: model ? model.display : ""
0052                     verticalAlignment: Text.AlignVCenter
0053 
0054                     readOnly: true
0055 
0056                     onTextEdited: {
0057                         Qt.callLater(kcm.desktopsModel.setDesktopName, model.Id, text);
0058                     }
0059 
0060                     onEditingFinished: {
0061                         readOnly = true;
0062                     }
0063 
0064                     MouseArea {
0065                         anchors.fill: parent
0066                         enabled: nameField.readOnly
0067 
0068                         onDoubleClicked: {
0069                             renameAction.clicked();
0070                         }
0071                     }
0072                 }
0073 
0074                 Rectangle {
0075                     id: defaultIndicator
0076                     radius: width * 0.5
0077                     implicitWidth: Kirigami.Units.largeSpacing
0078                     implicitHeight: Kirigami.Units.largeSpacing
0079                     visible: kcm.defaultsIndicatorsVisible
0080                     opacity: model ? !model.IsDefault : 0.0
0081                     color: Kirigami.Theme.neutralTextColor
0082                 }
0083 
0084                 DelegateButton {
0085                     id: renameAction
0086                     enabled: model && !model.IsMissing
0087                     visible: !applyAction.visible
0088                     icon.name: "edit-rename"
0089                     text: i18nc("@info:tooltip", "Rename")
0090                     onClicked: {
0091                         nameField.readOnly = false;
0092                         nameField.selectAll();
0093                         nameField.forceActiveFocus();
0094                     }
0095                 }
0096 
0097                 DelegateButton {
0098                     id: applyAction
0099                     visible: !nameField.readOnly
0100                     icon.name: "dialog-ok-apply"
0101                     text: i18nc("@info:tooltip", "Confirm new name")
0102                     onClicked: {
0103                         nameField.readOnly = true;
0104                     }
0105                 }
0106 
0107                 DelegateButton {
0108                     enabled: model && !model.IsMissing && desktopsList.count !== 1
0109                     icon.name: "edit-delete"
0110                     text: i18nc("@info:tooltip", "Remove")
0111                     onClicked: kcm.desktopsModel.removeDesktop(model.Id)
0112                 }
0113             }
0114         }
0115     }
0116 
0117     component DelegateButton: QQC2.ToolButton {
0118         display: QQC2.AbstractButton.IconOnly
0119         QQC2.ToolTip.text: text
0120         QQC2.ToolTip.visible: hovered
0121     }
0122 
0123     header: ColumnLayout {
0124         id: messagesLayout
0125 
0126         spacing: Kirigami.Units.largeSpacing
0127 
0128         Kirigami.InlineMessage {
0129             Layout.fillWidth: true
0130 
0131             type: Kirigami.MessageType.Error
0132 
0133             text: kcm.desktopsModel.error
0134 
0135             visible: kcm.desktopsModel.error !== ""
0136         }
0137 
0138         Kirigami.InlineMessage {
0139             Layout.fillWidth: true
0140 
0141             type: Kirigami.MessageType.Information
0142 
0143             text: i18n("Virtual desktops have been changed outside this settings application. Saving now will overwrite the changes.")
0144 
0145             visible: kcm.desktopsModel.serverModified
0146         }
0147     }
0148 
0149     view: ListView {
0150         id: desktopsList
0151 
0152         clip: true
0153 
0154         model: kcm.desktopsModel.ready ? kcm.desktopsModel : null
0155 
0156         section.property: "DesktopRow"
0157         section.delegate: Kirigami.ListSectionHeader {
0158             width: desktopsList.width
0159             label: i18n("Row %1", section)
0160         }
0161 
0162         delegate: desktopsListItemComponent
0163         reuseItems: true
0164     }
0165 
0166     footer: ColumnLayout {
0167         RowLayout {
0168             QQC2.Button {
0169                 text: i18nc("@action:button", "Add")
0170                 icon.name: "list-add"
0171 
0172                 onClicked: kcm.desktopsModel.createDesktop()
0173             }
0174 
0175             Item { // Spacer
0176                 Layout.fillWidth: true
0177             }
0178 
0179             QQC2.SpinBox {
0180                 id: rowsSpinBox
0181 
0182                 from: 1
0183                 to: 20
0184                 editable: true
0185                 value: kcm.desktopsModel.rows
0186 
0187                 textFromValue: (value, locale) => i18np("1 Row", "%1 Rows", value)
0188                 valueFromText: (text, locale) => parseInt(text, 10)
0189 
0190                 onValueModified: kcm.desktopsModel.rows = value
0191 
0192                 KCM.SettingHighlighter {
0193                     highlight: kcm.desktopsModel.rows !== 2
0194                 }
0195             }
0196         }
0197 
0198         Kirigami.FormLayout {
0199 
0200             QQC2.CheckBox {
0201                 id: navWraps
0202 
0203                 Kirigami.FormData.label: i18n("Options:")
0204 
0205                 text: i18n("Navigation wraps around")
0206                 enabled: !kcm.virtualDesktopsSettings.isImmutable("rollOverDesktops")
0207                 checked: kcm.virtualDesktopsSettings.rollOverDesktops
0208                 onToggled: kcm.virtualDesktopsSettings.rollOverDesktops = checked
0209 
0210                 KCM.SettingStateBinding {
0211                     configObject: kcm.virtualDesktopsSettings
0212                     settingName: "rollOverDesktops"
0213                 }
0214             }
0215 
0216             RowLayout {
0217                 Layout.fillWidth: true
0218 
0219                 QQC2.CheckBox {
0220                     id: animationEnabled
0221                     Layout.fillWidth: true
0222 
0223                     text: i18n("Show animation when switching:")
0224 
0225                     checked: kcm.animationsModel.animationEnabled
0226 
0227                     onToggled: kcm.animationsModel.animationEnabled = checked
0228 
0229                     KCM.SettingHighlighter {
0230                         highlight: kcm.animationsModel.animationEnabled !== kcm.animationsModel.defaultAnimationEnabled
0231                     }
0232                 }
0233 
0234                 QQC2.ComboBox {
0235                     enabled: animationEnabled.checked
0236 
0237                     model: kcm.animationsModel
0238                     textRole: "NameRole"
0239                     currentIndex: kcm.animationsModel.animationIndex
0240                     onActivated: kcm.animationsModel.animationIndex = currentIndex
0241 
0242                     KCM.SettingHighlighter {
0243                         highlight: kcm.animationsModel.animationIndex !== kcm.animationsModel.defaultAnimationIndex
0244                     }
0245                 }
0246 
0247                 QQC2.Button {
0248                     enabled: animationEnabled.checked && kcm.animationsModel.currentConfigurable
0249 
0250                     icon.name: "configure"
0251 
0252                     onClicked: kcm.configureAnimation()
0253                 }
0254 
0255                 QQC2.Button {
0256                     enabled: animationEnabled.checked
0257 
0258                     icon.name: "dialog-information"
0259 
0260                     onClicked: kcm.showAboutAnimation()
0261                 }
0262 
0263                 Item {
0264                     Layout.fillWidth: true
0265                 }
0266             }
0267 
0268             RowLayout {
0269                 Layout.fillWidth: true
0270 
0271                 QQC2.CheckBox {
0272                     id: osdEnabled
0273 
0274                     text: i18n("Show on-screen display when switching:")
0275 
0276                     checked: kcm.virtualDesktopsSettings.desktopChangeOsdEnabled
0277 
0278                     onToggled: kcm.virtualDesktopsSettings.desktopChangeOsdEnabled = checked
0279 
0280                     KCM.SettingStateBinding {
0281                         configObject: kcm.virtualDesktopsSettings
0282                         settingName: "desktopChangeOsdEnabled"
0283                     }
0284                 }
0285 
0286                 QQC2.SpinBox {
0287                     id: osdDuration
0288 
0289                     from: 0
0290                     to: 10000
0291                     stepSize: 100
0292 
0293                     textFromValue: (value, locale) => i18n("%1 ms", value)
0294                     valueFromText: (text, locale) => Number.fromLocaleString(locale, text.split(" ")[0])
0295 
0296                     value: kcm.virtualDesktopsSettings.popupHideDelay
0297 
0298                     onValueModified: kcm.virtualDesktopsSettings.popupHideDelay = value
0299 
0300                     KCM.SettingStateBinding {
0301                         configObject: kcm.virtualDesktopsSettings
0302                         settingName: "popupHideDelay"
0303                         extraEnabledConditions: osdEnabled.checked
0304                     }
0305                 }
0306             }
0307 
0308             RowLayout {
0309                 Layout.fillWidth: true
0310 
0311                 Item {
0312                     Layout.preferredWidth: Kirigami.Units.gridUnit
0313                 }
0314 
0315                 QQC2.CheckBox {
0316                     id: osdTextOnly
0317                     text: i18n("Show desktop layout indicators")
0318                     checked: !kcm.virtualDesktopsSettings.textOnly
0319                     onToggled: kcm.virtualDesktopsSettings.textOnly = !checked
0320 
0321                     KCM.SettingStateBinding {
0322                         configObject: kcm.virtualDesktopsSettings
0323                         settingName: "textOnly"
0324                         extraEnabledConditions: osdEnabled.checked
0325                     }
0326                 }
0327             }
0328         }
0329     }
0330 }
0331