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

« back to all changes in this revision

Viewing changes to plugins/Ubuntu/Settings/Menus/SwitchMenu.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
 
/*
2
 
 * Copyright 2013 Canonical Ltd.
 
1
/* Copyright 2013-2016 Canonical Ltd.
3
2
 *
4
3
 * This program is free software; you can redistribute it and/or modify
5
4
 * it under the terms of the GNU Lesser General Public License as published by
15
14
 *
16
15
 * Authors:
17
16
 *      Nick Dedekind <nick.dedekind@canonical.com>
 
17
 *      Marco Trevisan <marco.trevisan@canonical.com>
18
18
 */
19
19
 
20
20
import QtQuick 2.4
23
23
StandardMenu {
24
24
    id: menu
25
25
 
26
 
    property bool checked: false
27
 
 
28
 
    onClicked: menu.checked = !menu.checked
29
 
 
30
 
    component: Component {
 
26
    property alias checked: switcher.checked
 
27
 
 
28
    function onClickedCallback() {
 
29
        checked = !checked
 
30
        menu.triggered(checked)
 
31
    }
 
32
 
 
33
    slots: [
31
34
        Switch {
32
35
            id: switcher
33
36
            objectName: "switcher"
34
 
            property bool enableCheckConnection: true
35
 
 
36
 
            Component.onCompleted: {
37
 
                checked = menu.checked;
38
 
            }
39
 
 
40
 
            // FIXME : create a bi-directional feedback component
41
 
            onCheckedChanged: {
42
 
                if (!enableCheckConnection) {
43
 
                    return;
44
 
                }
45
 
                var oldEnable = enableCheckConnection;
46
 
                enableCheckConnection = false;
47
 
 
48
 
                menu.checked = checked;
49
 
                menu.triggered(menu.checked);
50
 
 
51
 
                enableCheckConnection = oldEnable;
52
 
            }
53
 
 
54
 
            Connections {
55
 
                target: menu
56
 
                onCheckedChanged: {
57
 
                    if (!switcher.enableCheckConnection) {
58
 
                        return;
59
 
                    }
60
 
                    var oldEnable = switcher.enableCheckConnection;
61
 
                    switcher.enableCheckConnection = false;
62
 
 
63
 
                    switcher.checked = menu.checked;
64
 
 
65
 
                    switcher.enableCheckConnection = oldEnable;
66
 
                }
67
 
            }
 
37
            onClicked: menu.triggered(checked)
68
38
        }
69
 
    }
 
39
    ]
70
40
}