2021-12-22 23:29:00 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
|
|
|
|
|
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import QtQuick 2.1
|
|
|
|
|
import QtQuick.Layouts 1.1
|
|
|
|
|
|
|
|
|
|
import org.kde.kirigami 2.12 as Kirigami
|
|
|
|
|
|
2023-09-05 15:34:49 +00:00
|
|
|
import org.kde.plasma.core as PlasmaCore
|
2021-12-22 23:29:00 +00:00
|
|
|
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
|
2023-03-18 19:28:17 +00:00
|
|
|
import org.kde.plasma.private.mobileshell as MobileShell
|
|
|
|
|
import org.kde.plasma.private.mobileshell.state as MobileShellState
|
2021-12-22 23:29:00 +00:00
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
|
|
|
|
|
2023-11-02 11:08:17 +00:00
|
|
|
MobileShell.BaseItem {
|
2021-12-22 23:29:00 +00:00
|
|
|
id: root
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2022-04-07 18:11:08 +00:00
|
|
|
required property bool restrictedPermissions
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
// Model interface
|
|
|
|
|
required property string text
|
|
|
|
|
required property string status
|
|
|
|
|
required property string icon
|
|
|
|
|
required property bool enabled
|
|
|
|
|
required property string settingsCommand
|
|
|
|
|
required property var toggleFunction
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2021-12-29 05:08:32 +00:00
|
|
|
signal closeRequested()
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
// set by children
|
|
|
|
|
property var iconItem
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2023-09-27 04:21:06 +00:00
|
|
|
readonly property color enabledButtonBorderColor: Qt.darker(Kirigami.Theme.highlightColor, 1.25)
|
2023-07-25 01:13:52 +00:00
|
|
|
readonly property color disabledButtonBorderColor: Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.textColor, Kirigami.Theme.backgroundColor, 0.75)
|
2023-09-27 04:21:06 +00:00
|
|
|
readonly property color enabledButtonColor: Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.highlightColor, Kirigami.Theme.backgroundColor, 0.6)
|
|
|
|
|
readonly property color enabledButtonPressedColor: Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.highlightColor, Kirigami.Theme.backgroundColor, 0.4);
|
2023-07-25 01:13:52 +00:00
|
|
|
readonly property color disabledButtonColor: Kirigami.Theme.backgroundColor
|
2021-12-22 23:29:00 +00:00
|
|
|
readonly property color disabledButtonPressedColor: Qt.darker(disabledButtonColor, 1.1)
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2022-04-07 01:55:06 +00:00
|
|
|
// scale animation on press
|
|
|
|
|
property real zoomScale: 1
|
|
|
|
|
Behavior on zoomScale {
|
|
|
|
|
NumberAnimation {
|
2025-09-11 14:13:26 +00:00
|
|
|
duration: Kirigami.Units.longDuration
|
2022-04-07 01:55:06 +00:00
|
|
|
easing.type: Easing.OutExpo
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-13 16:30:07 +00:00
|
|
|
|
|
|
|
|
transform: Scale {
|
|
|
|
|
origin.x: root.width / 2;
|
|
|
|
|
origin.y: root.height / 2;
|
2022-04-07 01:55:06 +00:00
|
|
|
xScale: root.zoomScale
|
|
|
|
|
yScale: root.zoomScale
|
|
|
|
|
}
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
function delegateClick() {
|
|
|
|
|
if (root.toggle) {
|
|
|
|
|
root.toggle();
|
|
|
|
|
} else if (root.toggleFunction) {
|
|
|
|
|
root.toggleFunction();
|
2022-04-07 18:11:08 +00:00
|
|
|
} else if (root.settingsCommand && !root.restrictedPermissions) {
|
2021-12-29 05:08:32 +00:00
|
|
|
closeRequested();
|
2024-03-10 03:50:55 +00:00
|
|
|
|
2024-07-13 16:30:07 +00:00
|
|
|
MobileShellState.ShellDBusClient.openAppLaunchAnimationWithPosition(
|
2024-03-10 03:50:55 +00:00
|
|
|
__getCurrentScreenNumber(),
|
2024-07-13 16:30:07 +00:00
|
|
|
root.icon,
|
|
|
|
|
root.text,
|
|
|
|
|
'org.kde.mobile.plasmasettings', // settings window id
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
Math.min(root.iconItem.width, root.iconItem.height));
|
2021-12-22 23:29:00 +00:00
|
|
|
MobileShell.ShellUtil.executeCommand(root.settingsCommand);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-13 16:30:07 +00:00
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
function delegatePressAndHold() {
|
2022-04-07 18:11:08 +00:00
|
|
|
if (root.settingsCommand && !root.restrictedPermissions) {
|
2021-12-29 05:08:32 +00:00
|
|
|
closeRequested();
|
2024-07-13 16:30:07 +00:00
|
|
|
MobileShellState.ShellDBusClient.openAppLaunchAnimationWithPosition(
|
2024-03-10 03:50:55 +00:00
|
|
|
__getCurrentScreenNumber(),
|
2024-07-13 16:30:07 +00:00
|
|
|
root.icon,
|
|
|
|
|
root.text,
|
|
|
|
|
'org.kde.mobile.plasmasettings', // settings window id
|
|
|
|
|
-1,
|
|
|
|
|
-1,
|
|
|
|
|
Math.min(root.iconItem.width, root.iconItem.height));
|
2021-12-22 23:29:00 +00:00
|
|
|
MobileShell.ShellUtil.executeCommand(root.settingsCommand);
|
|
|
|
|
} else if (root.toggleFunction) {
|
|
|
|
|
root.toggleFunction();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-10 03:50:55 +00:00
|
|
|
|
|
|
|
|
function __getCurrentScreenNumber() {
|
|
|
|
|
const screens = Qt.application.screens;
|
|
|
|
|
for (let i = 0; i < screens.length; i++) {
|
|
|
|
|
if (screens[i].name === Screen.name) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-12-22 23:29:00 +00:00
|
|
|
}
|