OsdSelector.qml 3.79 KB
Newer Older
1
2
/*
 * Copyright 2017 Daniel Vrátil <dvratil@kde.org>
Daniel Vrátil's avatar
Daniel Vrátil committed
3
 *
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 * 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, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.5
import QtQuick.Window 2.2

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

25
26
import org.kde.KScreen 1.0

27
28
29
30
Item {
    id: root
    property QtObject rootItem

31
    signal clicked(int actionId)
32
33
34
35
36
37
38
39
40
41

    height: Math.min(units.gridUnit * 15, Screen.desktopAvailableHeight / 5)
    width: buttonRow.width

    PlasmaComponents.ButtonRow {
        id: buttonRow

        exclusive: false

        height: parent.height - label.height - ((units.smallSpacing/2) * 3)
Daniel Vrátil's avatar
Daniel Vrátil committed
42
        width: (actionRepeater.count * height) + ((actionRepeater.count - 1) * buttonRow.spacing);
43
44
45
46
47

        Repeater {
            id: actionRepeater
            model: [
                    {
Sebastian Kügler's avatar
Sebastian Kügler committed
48
                        iconSource: "osd-shutd-laptop",
Daniel Vrátil's avatar
Daniel Vrátil committed
49
                        label: i18n("Switch to external screen"),
50
                        action: OsdAction.SwitchToExternal
51
52
                    },
                    {
Sebastian Kügler's avatar
Sebastian Kügler committed
53
                        iconSource: "osd-shutd-screen",
Daniel Vrátil's avatar
Daniel Vrátil committed
54
                        label: i18n("Switch to laptop screen"),
55
                        action: OsdAction.SwitchToInternal
56
57
58
                    },
                    {
                        iconSource: "osd-duplicate",
Daniel Vrátil's avatar
Daniel Vrátil committed
59
                        label: i18n("Unify outputs"),
60
                        action: OsdAction.Clonse
61
62
63
                    },
                    {
                        iconSource: "osd-sbs-left",
Daniel Vrátil's avatar
Daniel Vrátil committed
64
                        label: i18n("Extend to left"),
65
                        action: OsdAction.ExtendLeft
66
67
68
                    },
                    {
                        iconSource: "osd-sbs-sright",
Daniel Vrátil's avatar
Daniel Vrátil committed
69
                        label: i18n("Extend to right"),
70
                        action: OsdAction.ExtendRight
71
72
73
                    },
                    {
                        iconSource: "dialog-cancel",
Daniel Vrátil's avatar
Daniel Vrátil committed
74
                        label: i18n("Leave unchanged"),
75
                        action: OsdAction.NoAction
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
                    }
            ]
            delegate: PlasmaComponents.Button {
                PlasmaCore.IconItem {
                    source: modelData.iconSource
                    height: buttonRow.height - ((units.smallSpacing / 2) * 3)
                    width: height
                    anchors.centerIn: parent
                }
                height: parent.height
                width: height

                onHoveredChanged: rootItem.infoText = (hovered ? modelData.label : "")

                onClicked: root.clicked(modelData.action)
            }
        }
    }

    // TODO: keep? remove?
    PlasmaExtras.Heading {
        id: label
        anchors {
            bottom: parent.bottom
            left: parent.left
            right: parent.right
            margins: Math.floor(units.smallSpacing / 2)
        }

        text: rootItem.infoText
        horizontalAlignment: Text.AlignHCenter
        wrapMode: Text.WordWrap
        maximumLineCount: 2
        elide: Text.ElideLeft
        minimumPointSize: theme.defaultFont.pointSize
        fontSizeMode: Text.HorizontalFit
    }

    Component.onCompleted: print("OsdSelector loaded...");
}