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

« back to all changes in this revision

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

  • Committer: Bileto Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2016-11-16 18:53:22 UTC
  • mfrom: (146.6.6 radio-menuitem)
  • Revision ID: ci-train-bot@canonical.com-20161116185322-k6wy39nbvcasieam
RadioMenu: add menu item for creating radio items

In this case the component has a quite different look in pointer mode compared to touch mode, since
the bullet has to be placed in the middle of the leading padding space when using pointer.
Instead in touch-mode it behaves like any other icon or action item.

Approved by: Lukáš Tinkl, Unity8 CI Bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *      Marco Trevisan <marco.trevisan@canonical.com>
 
18
 */
 
19
 
 
20
import QtQuick 2.4
 
21
import Ubuntu.Components 1.3
 
22
 
 
23
BaseLayoutMenu {
 
24
    id: menu
 
25
 
 
26
    property alias checked: bullet.visible
 
27
 
 
28
    function onClickedCallback() {
 
29
        checked = true
 
30
        menu.triggered(checked)
 
31
    }
 
32
 
 
33
    slots: Item {
 
34
        id: container
 
35
        width: menuStyle.iconSize
 
36
        height: width
 
37
        anchors.verticalCenter: parent.verticalCenter
 
38
        SlotsLayout.overrideVerticalPositioning: true
 
39
        SlotsLayout.position: SlotsLayout.Leading
 
40
 
 
41
        states: State {
 
42
           name: "pointer";
 
43
           when: menu.pointerMode
 
44
 
 
45
           PropertyChanges {
 
46
                target: menu.layout
 
47
                padding.leading: 0
 
48
           }
 
49
           PropertyChanges {
 
50
                target: container
 
51
                width: menuStyle.padding.leading + units.gu(1)
 
52
                SlotsLayout.padding.leading: 0
 
53
                SlotsLayout.padding.trailing: 0
 
54
           }
 
55
           PropertyChanges {
 
56
                target: menu.layout.mainSlot
 
57
                SlotsLayout.padding.leading: 0
 
58
           }
 
59
        }
 
60
 
 
61
        Rectangle {
 
62
            id: bullet
 
63
            objectName: "bullet"
 
64
            anchors.centerIn: parent
 
65
            visible: false
 
66
            width: visible ? units.gu(0.8) : 0
 
67
            height: width
 
68
            radius: width/2
 
69
            color: menu.foregroundColor
 
70
            opacity: visible ? 1.0 : 0.0
 
71
            Behavior on opacity { UbuntuNumberAnimation {} }
 
72
            Behavior on width { UbuntuNumberAnimation {} }
 
73
        }
 
74
    }
 
75
}