Warning, /plasma/plasma-workspace/kcms/cursortheme/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0003
0004 SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006
0007 import QtCore
0008 import QtQuick 2.7
0009 import QtQuick.Window 2.2 // for Screen
0010 import QtQuick.Layouts 1.1
0011 import QtQuick.Controls 2.2 as QtControls
0012 import QtQuick.Dialogs 6.3 as QtDialogs
0013 import org.kde.kirigami 2.5 as Kirigami
0014 import org.kde.kwindowsystem 1.0 // for isPlatformWayland
0015 import org.kde.newstuff 1.91 as NewStuff
0016 import org.kde.kcmutils as KCM
0017
0018 import org.kde.private.kcm_cursortheme 1.0
0019
0020 KCM.GridViewKCM {
0021 id: root
0022
0023 property LaunchFeedbackDialog launchFeedbackDialog: null as LaunchFeedbackDialog
0024
0025 view.model: kcm.cursorsModel
0026 view.delegate: Delegate {}
0027 view.currentIndex: kcm.cursorThemeIndex(kcm.cursorThemeSettings.cursorTheme);
0028
0029 view.onCurrentIndexChanged: {
0030 kcm.cursorThemeSettings.cursorTheme = kcm.cursorThemeFromIndex(view.currentIndex)
0031 view.positionViewAtIndex(view.currentIndex, view.GridView.Beginning);
0032 }
0033
0034 Component.onCompleted: {
0035 view.positionViewAtIndex(view.currentIndex, GridView.Beginning);
0036 }
0037
0038 KCM.SettingStateBinding {
0039 configObject: kcm.cursorThemeSettings
0040 settingName: "cursorTheme"
0041 extraEnabledConditions: !kcm.downloadingFile
0042 }
0043
0044 DropArea {
0045 anchors.fill: parent
0046 onEntered: {
0047 if (!drag.hasUrls) {
0048 drag.accepted = false;
0049 }
0050 }
0051 onDropped: kcm.installThemeFromFile(drop.urls[0])
0052 }
0053
0054 actions: [
0055 Kirigami.Action {
0056 displayComponent: QtControls.ComboBox {
0057 id: sizeCombo
0058
0059 property int maxContentWidth: implicitContentWidth
0060 popup.width: Math.max(availableWidth, maxContentWidth)
0061
0062 model: kcm.sizesModel
0063 textRole: "display"
0064 displayText: i18n("Size: %1", currentText)
0065 currentIndex: kcm.cursorSizeIndex(kcm.cursorThemeSettings.cursorSize);
0066 onActivated: {
0067 kcm.cursorThemeSettings.cursorSize = kcm.cursorSizeFromIndex(sizeCombo.currentIndex);
0068 kcm.preferredSize = kcm.cursorSizeFromIndex(sizeCombo.currentIndex);
0069 }
0070 flat: true
0071
0072 KCM.SettingStateBinding {
0073 configObject: kcm.cursorThemeSettings
0074 settingName: "cursorSize"
0075 extraEnabledConditions: kcm.canResize
0076 }
0077
0078 delegate: QtControls.ItemDelegate {
0079 id: sizeComboDelegate
0080
0081 readonly property int size: parseInt(model.display)
0082
0083 width: parent.width
0084 highlighted: ListView.isCurrentItem
0085
0086 contentItem: RowLayout {
0087 Kirigami.Icon {
0088 source: model.decoration
0089 smooth: true
0090 // On wayland the cursor size is logical pixels, and on X11 it's physical pixels.
0091 property real devicePixelRatio: KWindowSystem.isPlatformWayland ? 1 : Screen.devicePixelRatio
0092 property size iconSize: kcm.iconSizeFromIndex(index)
0093 Layout.preferredWidth: iconSize.width / devicePixelRatio
0094 Layout.preferredHeight: iconSize.height / devicePixelRatio
0095 visible: valid && sizeComboDelegate.size > 0
0096 roundToIconSize: false
0097 }
0098
0099 QtControls.Label {
0100 Layout.alignment: Qt.AlignRight
0101 color: sizeComboDelegate.highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
0102 text: i18n("Size: %1", model[sizeCombo.textRole])
0103 textFormat: Text.PlainText
0104 elide: Text.ElideRight
0105 }
0106 }
0107 Binding {
0108 target: sizeCombo
0109 property: "maxContentWidth"
0110 value: implicitWidth
0111 when: index == sizeCombo.count - 1
0112 }
0113 }
0114 }
0115 },
0116 Kirigami.Action {
0117 text: i18nc("@action:button", "&Configure Launch Feedback…")
0118 icon.name: "preferences-desktop-launch-feedback"
0119 onTriggered: {
0120 if (root.launchFeedbackDialog === null) {
0121 const component = Qt.createComponent("LaunchFeedbackDialog.qml");
0122 root.launchFeedbackDialog = component.createObject(root, {
0123 "parent": root,
0124 });
0125 component.destroy();
0126 }
0127 root.launchFeedbackDialog.open();
0128 }
0129 },
0130 Kirigami.Action {
0131 text: i18n("&Install from File…")
0132 icon.name: "document-import"
0133 onTriggered: fileDialogLoader.active = true
0134 enabled: kcm.canInstall
0135 },
0136 NewStuff.Action {
0137 text: i18n("&Get New…")
0138 configFile: "xcursor.knsrc"
0139 onEntryEvent: function (entry, event) {
0140 if (event == NewStuff.Entry.StatusChangedEvent) {
0141 kcm.ghnsEntryChanged(entry);
0142 }
0143 }
0144 }
0145 ]
0146
0147 footer: ColumnLayout {
0148 id: footerLayout
0149
0150 Kirigami.InlineMessage {
0151 id: infoLabel
0152 Layout.fillWidth: true
0153
0154 showCloseButton: true
0155
0156 Connections {
0157 target: kcm
0158 function onShowSuccessMessage(message) {
0159 infoLabel.type = Kirigami.MessageType.Positive;
0160 infoLabel.text = message;
0161 infoLabel.visible = true;
0162 }
0163 function onShowInfoMessage(message) {
0164 infoLabel.type = Kirigami.MessageType.Information;
0165 infoLabel.text = message;
0166 infoLabel.visible = true;
0167 }
0168 function onShowErrorMessage(message) {
0169 infoLabel.type = Kirigami.MessageType.Error;
0170 infoLabel.text = message;
0171 infoLabel.visible = true;
0172 }
0173 }
0174 }
0175 }
0176
0177 Loader {
0178 id: fileDialogLoader
0179 active: false
0180 sourceComponent: QtDialogs.FileDialog {
0181 title: i18n("Open Theme")
0182 currentFolder: StandardPaths.standardLocations(StandardPaths.HomeLocation)[0]
0183 nameFilters: [ i18n("Cursor Theme Files (*.tar.gz *.tar.bz2)") ]
0184 Component.onCompleted: open()
0185 onAccepted: {
0186 kcm.installThemeFromFile(selectedFile)
0187 fileDialogLoader.active = false
0188 }
0189 onRejected: {
0190 fileDialogLoader.active = false
0191 }
0192 }
0193 }
0194 }
0195