Warning, /plasma/plasma-simplemenu/package/contents/ui/ConfigGeneral.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2014 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.0
0008 import QtQuick.Controls 1.0
0009 import QtQuick.Dialogs 1.2
0010 import QtQuick.Layouts 1.0
0011 
0012 import org.kde.plasma.core 2.0 as PlasmaCore
0013 import org.kde.plasma.components 2.0 as PlasmaComponents
0014 
0015 import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
0016 import org.kde.draganddrop 2.0 as DragDrop
0017 
0018 import org.kde.plasma.private.kicker 0.1 as Kicker
0019 
0020 Item {
0021     id: configGeneral
0022 
0023     width: childrenRect.width
0024     height: childrenRect.height
0025 
0026     property string cfg_icon: plasmoid.configuration.icon
0027     property bool cfg_useCustomButtonImage: plasmoid.configuration.useCustomButtonImage
0028     property string cfg_customButtonImage: plasmoid.configuration.customButtonImage
0029 
0030     property alias cfg_appNameFormat: appNameFormat.currentIndex
0031     property alias cfg_switchCategoriesOnHover: switchCategoriesOnHover.checked
0032 
0033     property alias cfg_useExtraRunners: useExtraRunners.checked
0034 
0035     ColumnLayout {
0036         anchors.left: parent.left
0037 
0038         RowLayout {
0039             spacing: units.smallSpacing
0040 
0041             Label {
0042                 text: i18n("Icon:")
0043             }
0044 
0045             Button {
0046                 id: iconButton
0047                 Layout.minimumWidth: previewFrame.width + units.smallSpacing * 2
0048                 Layout.maximumWidth: Layout.minimumWidth
0049                 Layout.minimumHeight: previewFrame.height + units.smallSpacing * 2
0050                 Layout.maximumHeight: Layout.minimumWidth
0051 
0052                 DragDrop.DropArea {
0053                     id: dropArea
0054 
0055                     property bool containsAcceptableDrag: false
0056 
0057                     anchors.fill: parent
0058 
0059                     onDragEnter: {
0060                         // Cannot use string operations (e.g. indexOf()) on "url" basic type.
0061                         var urlString = event.mimeData.url.toString();
0062 
0063                         // This list is also hardcoded in KIconDialog.
0064                         var extensions = [".png", ".xpm", ".svg", ".svgz"];
0065                         containsAcceptableDrag = urlString.indexOf("file:///") === 0 && extensions.some(function (extension) {
0066                             return urlString.indexOf(extension) === urlString.length - extension.length; // "endsWith"
0067                         });
0068 
0069                         if (!containsAcceptableDrag) {
0070                             event.ignore();
0071                         }
0072                     }
0073                     onDragLeave: containsAcceptableDrag = false
0074 
0075                     onDrop: {
0076                         if (containsAcceptableDrag) {
0077                             // Strip file:// prefix, we already verified in onDragEnter that we have only local URLs.
0078                             iconDialog.setCustomButtonImage(event.mimeData.url.toString().substr("file://".length));
0079                         }
0080                         containsAcceptableDrag = false;
0081                     }
0082                 }
0083 
0084                 KQuickAddons.IconDialog {
0085                     id: iconDialog
0086 
0087                     function setCustomButtonImage(image) {
0088                         cfg_customButtonImage = image || cfg_icon || "start-here-kde"
0089                         cfg_useCustomButtonImage = true;
0090                     }
0091 
0092                     onIconNameChanged: setCustomButtonImage(iconName);
0093                 }
0094 
0095                 // just to provide some visual feedback, cannot have checked without checkable enabled
0096                 checkable: true
0097                 checked: dropArea.containsAcceptableDrag
0098                 onClicked: {
0099                     checked = Qt.binding(function() { // never actually allow it being checked
0100                         return iconMenu.status === PlasmaComponents.DialogStatus.Open || dropArea.containsAcceptableDrag;
0101                     })
0102 
0103                     iconMenu.open(0, height)
0104                 }
0105 
0106                 PlasmaCore.FrameSvgItem {
0107                     id: previewFrame
0108                     anchors.centerIn: parent
0109                     imagePath: plasmoid.location === PlasmaCore.Types.Vertical || plasmoid.location === PlasmaCore.Types.Horizontal
0110                             ? "widgets/panel-background" : "widgets/background"
0111                     width: units.iconSizes.large + fixedMargins.left + fixedMargins.right
0112                     height: units.iconSizes.large + fixedMargins.top + fixedMargins.bottom
0113 
0114                     PlasmaCore.IconItem {
0115                         anchors.centerIn: parent
0116                         width: units.iconSizes.large
0117                         height: width
0118                         source: cfg_useCustomButtonImage ? cfg_customButtonImage : cfg_icon
0119                     }
0120                 }
0121             }
0122 
0123             // QQC Menu can only be opened at cursor position, not a random one
0124             PlasmaComponents.ContextMenu {
0125                 id: iconMenu
0126                 visualParent: iconButton
0127 
0128                 PlasmaComponents.MenuItem {
0129                     text: i18nc("@item:inmenu Open icon chooser dialog", "Choose...")
0130                     icon: "document-open-folder"
0131                     onClicked: iconDialog.open()
0132                 }
0133                 PlasmaComponents.MenuItem {
0134                     text: i18nc("@item:inmenu Reset icon to default", "Clear Icon")
0135                     icon: "edit-clear"
0136                     onClicked: {
0137                         cfg_useCustomButtonImage = false;
0138                     }
0139                 }
0140             }
0141         }
0142 
0143         GroupBox {
0144             Layout.fillWidth: true
0145 
0146             title: i18n("Behavior")
0147 
0148             flat: true
0149 
0150             ColumnLayout {
0151                 RowLayout {
0152                     Label {
0153                         text: i18n("Show applications as:")
0154                     }
0155 
0156                     ComboBox {
0157                         id: appNameFormat
0158 
0159                         Layout.fillWidth: true
0160 
0161                         model: [i18n("Name only"), i18n("Description only"), i18n("Name (Description)"), i18n("Description (Name)")]
0162                     }
0163                 }
0164 
0165                 CheckBox {
0166                     id: switchCategoriesOnHover
0167 
0168                     text: i18n("Switch categories on hover")
0169                 }
0170             }
0171         }
0172 
0173         GroupBox {
0174             Layout.fillWidth: true
0175 
0176             title: i18n("Search")
0177 
0178             flat: true
0179 
0180             ColumnLayout {
0181                 CheckBox {
0182                     id: useExtraRunners
0183 
0184                     text: i18n("Expand search to bookmarks, files and emails")
0185                 }
0186             }
0187         }
0188     }
0189 }