MenuDelegate.qml 2.13 KB
Newer Older
1
/*
Nicolas Fella's avatar
Nicolas Fella committed
2
 * SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
3
 *
Nicolas Fella's avatar
Nicolas Fella committed
4
 * SPDX-License-Identifier: GPL-2.0-or-later
5
6
7
8
9
10
 */

import QtQuick 2.10
import QtQuick.Controls 2.10
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PC3
11
import org.kde.kirigami 2.12 as Kirigami
12
13
14
15
16
17
18
19
20
21
22
23

AbstractButton {
    id: controlRoot

    hoverEnabled: true

    enum State {
        Rest,
        Hover,
        Down
    }

24
25
26
    Kirigami.MnemonicData.controlType: Kirigami.MnemonicData.SecondaryControl
    Kirigami.MnemonicData.label: controlRoot.text

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    leftPadding: rest.margins.left
    topPadding: rest.margins.top
    rightPadding: rest.margins.right
    bottomPadding: rest.margins.bottom

    background: Item {
        id: background

        property int state: {
            if (controlRoot.down) {
                return MenuDelegate.State.Down
            } else if (controlRoot.hovered) {
                return MenuDelegate.State.Hover
            }
            return MenuDelegate.State.Rest
        }

        PlasmaCore.FrameSvgItem {
            id: rest
            anchors.fill: parent
            visible: background.state == MenuDelegate.State.Rest
            imagePath: "widgets/menubaritem"
            prefix: "normal"
        }
        PlasmaCore.FrameSvgItem {
            id: hover
            anchors.fill: parent
            visible: background.state == MenuDelegate.State.Hover
            imagePath: "widgets/menubaritem"
            prefix: "hover"
        }
        PlasmaCore.FrameSvgItem {
            id: down
            anchors.fill: parent
            visible: background.state == MenuDelegate.State.Down
            imagePath: "widgets/menubaritem"
            prefix: "pressed"
        }
    }

    contentItem: PC3.Label {
68
        text: controlRoot.Kirigami.MnemonicData.richTextLabel
69
70
71
72
        // Kirigami.Theme.highlightedTextColor returns different colors
        // depending on window focus, which does not apply to this applet
        // instead, we use palette.highlightedText here, which returns consistent result
        color: background.state == MenuDelegate.State.Rest ? palette.windowText : palette.highlightedText
73
74
    }
}