You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
5.1 KiB
147 lines
5.1 KiB
/* |
|
SPDX-FileCopyrightText: 2013 Heena Mahour <heena393@gmail.com> |
|
SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org> |
|
SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de> |
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later |
|
*/ |
|
import QtQuick 2.15 |
|
import QtQuick.Layouts 1.15 |
|
import QtQuick.Controls 2.15 |
|
// Deliberately imported after QtQuick to avoid missing restoreMode property in Binding. Fix in Qt 6. |
|
import QtQml 2.15 |
|
|
|
import org.kde.plasma.plasmoid 2.0 |
|
import org.kde.kquickcontrolsaddons 2.0 // For KCMShell |
|
import org.kde.plasma.core 2.0 as PlasmaCore |
|
import org.kde.plasma.components 3.0 as PlasmaComponents3 |
|
import org.kde.plasma.private.appmenu 1.0 as AppMenuPrivate |
|
import org.kde.kirigami 2.5 as Kirigami |
|
|
|
Item { |
|
id: root |
|
|
|
readonly property bool vertical: Plasmoid.formFactor === PlasmaCore.Types.Vertical |
|
readonly property bool view: Plasmoid.configuration.compactView |
|
readonly property bool menuAvailable: appMenuModel.menuAvailable |
|
|
|
readonly property bool kcmAuthorized: KCMShell.authorize(["style.desktop"]).length > 0 |
|
|
|
onViewChanged: { |
|
Plasmoid.nativeInterface.view = view; |
|
} |
|
|
|
Plasmoid.constraintHints: PlasmaCore.Types.CanFillArea |
|
Plasmoid.preferredRepresentation: (Plasmoid.configuration.compactView) ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation |
|
|
|
Plasmoid.compactRepresentation: PlasmaComponents3.ToolButton { |
|
readonly property int fakeIndex: 0 |
|
Layout.fillWidth: false |
|
Layout.fillHeight: false |
|
Layout.minimumWidth: implicitWidth |
|
Layout.maximumWidth: implicitWidth |
|
enabled: menuAvailable |
|
checkable: menuAvailable && Plasmoid.nativeInterface.currentIndex === fakeIndex |
|
checked: checkable |
|
icon.name: "application-menu" |
|
|
|
display: PlasmaComponents3.AbstractButton.IconOnly |
|
text: Plasmoid.title |
|
Accessible.description: Plasmoid.toolTipSubText |
|
|
|
onClicked: Plasmoid.nativeInterface.trigger(this, 0); |
|
} |
|
|
|
Plasmoid.fullRepresentation: GridLayout { |
|
id: buttonGrid |
|
|
|
Plasmoid.status: { |
|
if (menuAvailable && Plasmoid.nativeInterface.currentIndex > -1 && buttonRepeater.count > 0) { |
|
return PlasmaCore.Types.NeedsAttentionStatus; |
|
} else { |
|
//when we're not enabled set to active to show the configure button |
|
return buttonRepeater.count > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.HiddenStatus; |
|
} |
|
} |
|
|
|
Layout.minimumWidth: implicitWidth |
|
Layout.minimumHeight: implicitHeight |
|
|
|
flow: root.vertical ? GridLayout.TopToBottom : GridLayout.LeftToRight |
|
rowSpacing: 0 |
|
columnSpacing: 0 |
|
|
|
Binding { |
|
target: plasmoid.nativeInterface |
|
property: "buttonGrid" |
|
value: buttonGrid |
|
restoreMode: Binding.RestoreNone |
|
} |
|
|
|
Connections { |
|
target: Plasmoid.nativeInterface |
|
function onRequestActivateIndex(index: int) { |
|
const button = buttonRepeater.itemAt(index); |
|
if (button) { |
|
button.activated(); |
|
} |
|
} |
|
} |
|
|
|
Connections { |
|
target: Plasmoid.self |
|
function onActivated() { |
|
const button = buttonRepeater.itemAt(0); |
|
if (button) { |
|
button.activated(); |
|
} |
|
} |
|
} |
|
|
|
// So we can show mnemonic underlines only while Alt is pressed |
|
PlasmaCore.DataSource { |
|
id: keystateSource |
|
engine: "keystate" |
|
connectedSources: ["Alt"] |
|
} |
|
|
|
PlasmaComponents3.ToolButton { |
|
id: noMenuPlaceholder |
|
visible: buttonRepeater.count === 0 |
|
text: Plasmoid.title |
|
Layout.fillWidth: root.vertical |
|
Layout.fillHeight: !root.vertical |
|
} |
|
|
|
Repeater { |
|
id: buttonRepeater |
|
model: appMenuModel.visible ? appMenuModel : null |
|
|
|
MenuDelegate { |
|
readonly property int buttonIndex: index |
|
|
|
Layout.fillWidth: root.vertical |
|
Layout.fillHeight: !root.vertical |
|
text: activeMenu |
|
// TODO: Alt and other modifiers might be unavailable on Wayland |
|
Kirigami.MnemonicData.active: keystateSource.data.Alt !== undefined && keystateSource.data.Alt.Pressed |
|
|
|
down: pressed || Plasmoid.nativeInterface.currentIndex === index |
|
visible: text !== "" && model.activeActions.visible |
|
|
|
menuIsOpen: Plasmoid.nativeInterface.currentIndex !== -1 |
|
onActivated: Plasmoid.nativeInterface.trigger(this, index) |
|
} |
|
} |
|
} |
|
|
|
AppMenuPrivate.AppMenuModel { |
|
id: appMenuModel |
|
containmentStatus: Plasmoid.nativeInterface.containment.status |
|
screenGeometry: Plasmoid.screenGeometry |
|
onRequestActivateIndex: Plasmoid.nativeInterface.requestActivateIndex(index) |
|
Component.onCompleted: { |
|
Plasmoid.nativeInterface.model = appMenuModel; |
|
} |
|
} |
|
}
|
|
|