~ci-train-bot/ubuntu-settings-components/ubuntu-settings-components-ubuntu-zesty-2022

« back to all changes in this revision

Viewing changes to plugins/Ubuntu/Settings/Menus/CheckableMenu.qml

  • Committer: Bileto Bot
  • Date: 2016-10-24 11:32:00 UTC
  • mfrom: (146.3.110 slots-layout)
  • Revision ID: ci-train-bot@canonical.com-20161024113200-85dvkl9m1o0msi5i
* Menus: rewrite components using ListItemLayout's and SlotsLayout's
* Bump revision to 0.10, as per Components removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2013 Canonical Ltd.
 
2
 * Copyright 2013-2016 Canonical Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU Lesser General Public License as published by
15
15
 *
16
16
 * Authors:
17
17
 *      Nick Dedekind <nick.dedekind@canonical.com>
 
18
 *      Marco Trevisan <marco.trevisan@canonical.com>
18
19
 */
19
20
 
20
21
import QtQuick 2.4
21
 
import Ubuntu.Components 1.3 as Components
22
 
import Ubuntu.Components.ListItems 1.3 as ListItem
 
22
import Ubuntu.Components 1.3
23
23
 
24
 
ListItem.Empty {
 
24
BaseLayoutMenu {
25
25
    id: menu
26
26
 
27
 
    property alias text: label.text
28
 
    property bool checked: false
29
 
 
30
 
    onClicked: menu.checked = !menu.checked
31
 
 
32
 
    Components.CheckBox {
 
27
    property alias checked: checkbox.checked
 
28
 
 
29
    function onClickedCallback() {
 
30
        checked = !checked
 
31
        menu.triggered(checked)
 
32
    }
 
33
 
 
34
    slots: CheckBox {
33
35
        id: checkbox
34
36
        objectName: "checkbox"
35
 
        property bool enableCheckConnection: true
36
 
 
37
 
        anchors {
38
 
            left: parent.left
39
 
            leftMargin: menu.__contentsMargins
40
 
            verticalCenter: parent.verticalCenter
41
 
        }
42
 
 
43
 
        Component.onCompleted: {
44
 
            checked = menu.checked;
45
 
        }
46
 
 
47
 
        // FIXME : create a bi-directional feedback component
48
 
        onCheckedChanged: {
49
 
            if (!enableCheckConnection) {
50
 
                return;
51
 
            }
52
 
            var oldEnable = enableCheckConnection;
53
 
            enableCheckConnection = false;
54
 
 
55
 
            menu.checked = checked;
56
 
            menu.triggered(menu.checked);
57
 
 
58
 
            enableCheckConnection = oldEnable;
59
 
        }
60
 
 
61
 
        Connections {
62
 
            target: menu
63
 
            onCheckedChanged: {
64
 
                if (!checkbox.enableCheckConnection) {
65
 
                    return;
66
 
                }
67
 
                var oldEnable = checkbox.enableCheckConnection;
68
 
                checkbox.enableCheckConnection = false;
69
 
 
70
 
                checkbox.checked = menu.checked;
71
 
 
72
 
                checkbox.enableCheckConnection = oldEnable;
73
 
            }
74
 
        }
75
 
    }
76
 
 
77
 
    Components.Label {
78
 
        id: label
79
 
        anchors {
80
 
            left: checkbox.right
81
 
            leftMargin: menu.__contentsMargins
82
 
            right: parent.right
83
 
            rightMargin: menu.__contentsMargins
84
 
            verticalCenter: parent.verticalCenter
85
 
        }
86
 
        elide: Text.ElideRight
 
37
        onClicked: menu.triggered(checked)
 
38
        SlotsLayout.padding.trailing: units.gu(2.0)
 
39
        SlotsLayout.position: SlotsLayout.Leading
87
40
    }
88
41
}