melawy-plasma-plasmoid-Onze.../com.github.adhec.OnzeMenuKDE/contents/ui/ConfigGeneral.qml

285 lines
9.8 KiB
QML
Raw Normal View History

2023-04-17 20:56:22 +05:00
/***************************************************************************
* Copyright (C) 2014 by Eike Hein <hein@kde.org> *
* *
* 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) any later version. *
* *
* 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
2023-07-02 11:51:48 +05:00
import QtQuick 2.15
2023-04-17 20:56:22 +05:00
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.0
2023-07-02 11:51:48 +05:00
import QtQuick.Controls 2.5
2023-04-17 20:56:22 +05:00
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
import org.kde.draganddrop 2.0 as DragDrop
import org.kde.plasma.private.kicker 0.1 as Kicker
2023-07-02 11:51:48 +05:00
import "code/tools.js" as Tools
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kirigami 2.10 as Kirigami
2023-04-17 20:56:22 +05:00
Kirigami.FormLayout {
id: configGeneral
property string cfg_icon: plasmoid.configuration.icon
property bool cfg_useCustomButtonImage: plasmoid.configuration.useCustomButtonImage
property string cfg_customButtonImage: plasmoid.configuration.customButtonImage
property alias cfg_useExtraRunners: useExtraRunners.checked
2023-07-02 11:51:48 +05:00
property alias cfg_hideRecentDocs: hideRecentDocs.checked
property alias cfg_showRecentApps: showRecentApps.checked
2023-04-17 20:56:22 +05:00
property alias cfg_numberColumns: numberColumns.value
property alias cfg_numberRows: numberRows.value
2023-07-02 11:51:48 +05:00
2023-04-17 20:56:22 +05:00
property alias cfg_labels2lines: labels2lines.checked
property alias cfg_displayPosition: displayPosition.currentIndex
2023-07-02 11:51:48 +05:00
property alias cfg_iconSmooth: iconSmooth.checked
2023-04-17 20:56:22 +05:00
2023-07-02 11:51:48 +05:00
property alias cfg_pullupAnimation: pullupAnimation.checked
2023-04-17 20:56:22 +05:00
property string cfg_defaultSize
2023-07-02 11:51:48 +05:00
property string cfg_menuLabel: menuLabel.text
property alias cfg_textLabelFontsize: textLabelFontsize.value
2023-04-17 20:56:22 +05:00
// ----------------- Icon -----------------
Button {
Kirigami.FormData.label: i18n("Icon:")
id: iconButton
2023-07-02 11:51:48 +05:00
//Layout.minimumWidth: previewFrame.width + PlasmaCore.Units.smallSpacing * 2
2023-04-17 20:56:22 +05:00
//Layout.maximumWidth: Layout.minimumWidth
2023-07-02 11:51:48 +05:00
//Layout.minimumHeight: previewFrame.height + PlasmaCore.Units.smallSpacing * 2
2023-04-17 20:56:22 +05:00
//Layout.maximumHeight: Layout.minimumWidth
2023-07-02 11:51:48 +05:00
implicitWidth: previewFrame.width + PlasmaCore.Units.smallSpacing * 2
implicitHeight: previewFrame.height + PlasmaCore.Units.smallSpacing * 2
2023-04-17 20:56:22 +05:00
DragDrop.DropArea {
id: dropArea
property bool containsAcceptableDrag: false
anchors.fill: parent
onDragEnter: {
// Cannot use string operations (e.g. indexOf()) on "url" basic type.
var urlString = event.mimeData.url.toString();
// This list is also hardcoded in KIconDialog.
var extensions = [".png", ".xpm", ".svg", ".svgz"];
containsAcceptableDrag = urlString.indexOf("file:///") === 0 && extensions.some(function (extension) {
return urlString.indexOf(extension) === urlString.length - extension.length; // "endsWith"
});
if (!containsAcceptableDrag) {
event.ignore();
}
}
onDragLeave: containsAcceptableDrag = false
onDrop: {
if (containsAcceptableDrag) {
// Strip file:// prefix, we already verified in onDragEnter that we have only local URLs.
iconDialog.setCustomButtonImage(event.mimeData.url.toString().substr("file://".length));
}
containsAcceptableDrag = false;
}
}
KQuickAddons.IconDialog {
id: iconDialog
function setCustomButtonImage(image) {
cfg_customButtonImage = image || cfg_icon || "start-here-kde"
cfg_useCustomButtonImage = true;
}
onIconNameChanged: setCustomButtonImage(iconName);
}
// just to provide some visual feedback, cannot have checked without checkable enabled
checkable: true
checked: dropArea.containsAcceptableDrag
onClicked: {
checked = Qt.binding(function() { // never actually allow it being checked
return iconMenu.status === PlasmaComponents.DialogStatus.Open || dropArea.containsAcceptableDrag;
})
iconMenu.open(0, height)
}
PlasmaCore.FrameSvgItem {
id: previewFrame
anchors.centerIn: parent
imagePath: plasmoid.location === PlasmaCore.Types.Vertical || plasmoid.location === PlasmaCore.Types.Horizontal
? "widgets/panel-background" : "widgets/background"
2023-07-02 11:51:48 +05:00
width: PlasmaCore.Units.iconSizes.large + fixedMargins.left + fixedMargins.right
height: PlasmaCore.Units.iconSizes.large + fixedMargins.top + fixedMargins.bottom
2023-04-17 20:56:22 +05:00
PlasmaCore.IconItem {
anchors.centerIn: parent
2023-07-02 11:51:48 +05:00
width: PlasmaCore.Units.iconSizes.large
2023-04-17 20:56:22 +05:00
height: width
source: cfg_useCustomButtonImage ? cfg_customButtonImage : cfg_icon
}
}
}
// QQC Menu can only be opened at cursor position, not a random one
PlasmaComponents.ContextMenu {
id: iconMenu
visualParent: iconButton
PlasmaComponents.MenuItem {
text: i18nc("@item:inmenu Open icon chooser dialog", "Choose...")
icon: "document-open-folder"
onClicked: iconDialog.open()
}
PlasmaComponents.MenuItem {
text: i18nc("@item:inmenu Reset icon to default", "Clear Icon")
icon: "edit-clear"
onClicked: {
cfg_useCustomButtonImage = false;
}
}
}
2023-07-02 11:51:48 +05:00
Kirigami.ActionTextField {
id: menuLabel
enabled: plasmoid.formFactor !== PlasmaCore.Types.Vertical
Kirigami.FormData.label: i18nc("@label:textbox", "Text label")
text: plasmoid.configuration.menuLabel
placeholderText: i18nc("@info:placeholder", "Type here to add a text label")
onTextEdited: {
cfg_menuLabel = menuLabel.text
// This is to make sure that we always have a icon if there is no text.
// If the user remove the icon and remove the text, without this, we'll have no icon and no text.
// This is to force the icon to be there.
if (!menuLabel.text) {
cfg_icon = cfg_icon || Tools.defaultIconName
}
}
rightActions: [
Action {
icon.name: "edit-clear"
enabled: menuLabel.text !== ""
text: i18nc("@action:button", "Reset menu label")
onTriggered: {
menuLabel.clear()
cfg_menuLabel = ''
cfg_icon = cfg_icon || Tools.defaultIconName
}
}
]
}
SpinBox{
id: textLabelFontsize
from: 10
to: 50
Kirigami.FormData.label: i18n("Text label fontsize")
}
2023-04-17 20:56:22 +05:00
ComboBox {
id: displayPosition
Kirigami.FormData.label: i18n("Menu position")
model: [
i18n("Default"),
i18n("Center"),
i18n("Center bottom"),
]
onActivated: cfg_displayPosition = currentIndex
}
2023-07-02 11:51:48 +05:00
CheckBox {
id: showRecentApps
Kirigami.FormData.label: i18n("Main section")
text: i18n("Show recent applications")
}
2023-04-17 20:56:22 +05:00
CheckBox {
id: useExtraRunners
text: i18n("Expand search to bookmarks, files and emails")
2023-07-02 11:51:48 +05:00
visible: false
2023-04-17 20:56:22 +05:00
}
2023-07-02 11:51:48 +05:00
2023-04-17 20:56:22 +05:00
CheckBox {
id: labels2lines
text: i18n("Show labels in two lines")
}
2023-07-02 11:51:48 +05:00
CheckBox {
id: hideRecentDocs
text: i18n("Hide recent documents")
}
2023-04-17 20:56:22 +05:00
SpinBox{
id: numberColumns
2023-07-02 11:51:48 +05:00
from: 4
to: 10
2023-04-17 20:56:22 +05:00
Kirigami.FormData.label: i18n("Number of columns (main grid)")
}
SpinBox{
id: numberRows
2023-07-02 11:51:48 +05:00
from: 1
to: 10
2023-04-17 20:56:22 +05:00
Kirigami.FormData.label: i18n("Number of rows (main grid)")
}
2023-07-02 11:51:48 +05:00
CheckBox {
id: iconSmooth
Kirigami.FormData.label: i18n("Icons smooth")
visible: false // TODO validate
}
CheckBox {
id: pullupAnimation
Kirigami.FormData.label: i18n("Pull Up Animation")
}
2023-04-17 20:56:22 +05:00
ComboBox {
id: defaultFormatCombo
Kirigami.FormData.label: i18n("Size of icons")
2023-07-02 11:51:48 +05:00
model: Tools.formats
2023-04-17 20:56:22 +05:00
currentIndex: defaultFormatCombo.model.indexOf(cfg_defaultSize)
onActivated: cfg_defaultSize = model[index]
}
2023-07-02 11:51:48 +05:00
RowLayout{
Button {
text: i18n("Unhide all applications")
onClicked: {
plasmoid.configuration.hiddenApplications = [];
unhideAllAppsPopup.text = i18n("Unhidden!");
}
}
Label {
id: unhideAllAppsPopup
}
}
2023-04-17 20:56:22 +05:00
}