~neon/project-neon/kscreen

« back to all changes in this revision

Viewing changes to plasmoid/package/contents/ui/main.qml

  • Committer: Kai Uwe Broulik
  • Date: 2018-08-25 16:19:34 UTC
  • Revision ID: git-v1:b4baa322c3610766a5a7f38e9a501a18a2e7b051
Add applet with screen layouts and presentation mode

One of LiMux client's requirements is for display configuration to be easily accessible by mouse.
The OSD cannot be accessed by mouse, so this applet offers commonly used screen layouts in an
easily accessible place.

To keep the screen on during a presentation (when the application does not do that or the user is
actually demonstrating something on the machine itself) one needs to uncheck the non-userfriendly
labeled "Enable powermanagement" check box in the battery monitor. Since this is also affects "screen
setup", it is placed in this plasmoid as well.

The widget can be placed as an always-visible plasmoid in the panel or in System Tray where it would
only show if presentation mode is enabled or more then one screen is connected.

Differential Revision: https://phabricator.kde.org/D14855

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2018 Kai Uwe Broulik <kde@broulik.de>
 
3
 *                    Work sponsored by the LiMux project of
 
4
 *                    the city of Munich.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License as
 
8
 * published by the Free Software Foundation; either version 2 of
 
9
 * the License or (at your option) version 3 or any later version
 
10
 * accepted by the membership of KDE e.V. (or its successor approved
 
11
 * by the membership of KDE e.V.), which shall act as a proxy
 
12
 * defined in Section 14 of version 3 of the license.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
 *
 
22
 */
 
23
 
 
24
import QtQuick 2.8
 
25
import QtQuick.Layouts 1.1
 
26
 
 
27
import org.kde.plasma.plasmoid 2.0
 
28
import org.kde.plasma.core 2.0 as PlasmaCore
 
29
import org.kde.plasma.components 2.0 as PlasmaComponents
 
30
import org.kde.plasma.extras 2.0 as PlasmaExtras
 
31
import org.kde.kquickcontrolsaddons 2.0
 
32
 
 
33
import org.kde.private.kscreen 1.0
 
34
 
 
35
Item {
 
36
    id: root
 
37
 
 
38
    // Only show if there's screen layouts available or the user enabled presentation mode
 
39
    Plasmoid.status: presentationModeEnabled || plasmoid.nativeInterface.connectedOutputCount > 1 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus
 
40
    Plasmoid.toolTipSubText: presentationModeEnabled ? i18n("Presentation mode is enabled") : ""
 
41
 
 
42
    readonly property string kcmName: "kcm_kscreen"
 
43
    // does this need an ellipsis?
 
44
    readonly property string kcmLabel: i18nc("Open the full display settings module", "Advanced Display Settings")
 
45
    readonly property string kcmIconName: "preferences-desktop-display-randr"
 
46
    readonly property bool kcmAllowed: KCMShell.authorize(kcmName + ".desktop").length > 0
 
47
 
 
48
    readonly property bool presentationModeEnabled: presentationModeCookie > 0
 
49
    property int presentationModeCookie: -1
 
50
 
 
51
    readonly property var screenLayouts: {
 
52
        var layouts = OsdAction.actionOrder().filter(function (layout) {
 
53
            // We don't want the "No action" item in the plasmoid
 
54
            return layout !== OsdAction.NoAction;
 
55
        });
 
56
 
 
57
        layouts.map(function (layout) {
 
58
            return {
 
59
                iconName: OsdAction.actionIconName(layout),
 
60
                label: OsdAction.actionLabel(layout),
 
61
                action: layout
 
62
            }
 
63
        });
 
64
    }
 
65
 
 
66
    PlasmaCore.DataSource {
 
67
        id: pmSource
 
68
        engine: "powermanagement"
 
69
        connectedSources: ["PowerDevil", "Inhibitions"]
 
70
 
 
71
        onSourceAdded: {
 
72
            disconnectSource(source);
 
73
            connectSource(source);
 
74
        }
 
75
        onSourceRemoved: {
 
76
            disconnectSource(source);
 
77
        }
 
78
 
 
79
        readonly property var inhibitions: {
 
80
            var inhibitions = [];
 
81
 
 
82
            var data = pmSource.data.Inhibitions;
 
83
            if (data) {
 
84
                for (var key in data) {
 
85
                    if (key === "plasmashell" || key === "plasmoidviewer") { // ignore our own inhibition
 
86
                        continue;
 
87
                    }
 
88
 
 
89
                    inhibitions.push(data[key]);
 
90
                }
 
91
            }
 
92
 
 
93
            return inhibitions;
 
94
        }
 
95
    }
 
96
 
 
97
    function action_openKcm() {
 
98
        KCMShell.open(kcmName);
 
99
    }
 
100
 
 
101
    Component.onCompleted: {
 
102
        if (kcmAllowed) {
 
103
            plasmoid.setAction("openKcm", root.kcmLabel, root.kcmIconName)
 
104
        }
 
105
    }
 
106
 
 
107
    Plasmoid.fullRepresentation: ColumnLayout {
 
108
        spacing: 0
 
109
        Layout.preferredWidth: units.gridUnit * 15
 
110
 
 
111
        ScreenLayoutSelection {
 
112
            Layout.fillWidth: true
 
113
        }
 
114
 
 
115
        PresentationModeItem {
 
116
            Layout.fillWidth: true
 
117
            Layout.topMargin: units.largeSpacing
 
118
        }
 
119
 
 
120
        // compact the layout, push settings button to the bottom
 
121
        Item {
 
122
            Layout.fillHeight: true
 
123
        }
 
124
 
 
125
        PlasmaComponents.Button {
 
126
            Layout.alignment: Qt.AlignRight
 
127
            Layout.topMargin: units.smallSpacing
 
128
            text: root.kcmLabel
 
129
            iconName: root.kcmIconName
 
130
            onClicked: action_openKcm()
 
131
        }
 
132
    }
 
133
}