~zsombi/ubuntu-ui-toolkit/listitemSelectModeBugs

« back to all changes in this revision

Viewing changes to examples/ubuntu-ui-toolkit-gallery/MainPage.qml

  • Committer: Zsombor Egri
  • Date: 2015-11-16 06:35:05 UTC
  • mfrom: (1664.1.1 listitemSelectModeBugs)
  • Revision ID: zsombor.egri@canonical.com-20151116063505-cwn2qfks7qzk10g9
re-sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 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
 
 
17
import QtQuick 2.4
 
18
import Ubuntu.Components 1.3
 
19
 
 
20
Page {
 
21
    id: mainPage
 
22
    title: "Ubuntu UI Toolkit"
 
23
 
 
24
    header: PageHeader {
 
25
        title: mainPage.title
 
26
        flickable: layout.columns === 1 ? widgetList : null
 
27
        trailingActionBar.actions: [
 
28
            Action {
 
29
                text: i18n.tr('Right to Left')
 
30
                iconName: 'flash-on'
 
31
                visible: !gallery.rtl
 
32
                onTriggered: gallery.rtl = !gallery.rtl
 
33
            },
 
34
            Action {
 
35
                text: i18n.tr('Left to Right')
 
36
                iconName: 'flash-off'
 
37
                visible: gallery.rtl
 
38
                onTriggered: gallery.rtl = !gallery.rtl
 
39
            },
 
40
            Action {
 
41
                text: i18n.tr('Use dark theme')
 
42
                iconName: 'torch-on'
 
43
                visible: gallery.theme.name == 'Ubuntu.Components.Themes.Ambiance'
 
44
                onTriggered: gallery.theme.name = 'Ubuntu.Components.Themes.SuruDark'
 
45
            },
 
46
            Action {
 
47
                text: i18n.tr('Use light theme')
 
48
                iconName: 'torch-off'
 
49
                visible: gallery.theme.name == 'Ubuntu.Components.Themes.SuruDark'
 
50
                onTriggered: gallery.theme.name = 'Ubuntu.Components.Themes.Ambiance'
 
51
            },
 
52
            Action {
 
53
                text: i18n.tr('About')
 
54
                iconName: "info"
 
55
                onTriggered: mainPage.pageStack.addPageToCurrentColumn(mainPage, Qt.resolvedUrl("About.qml"))
 
56
            },
 
57
            Action {
 
58
                text: i18n.tr("Deactivate mouse")
 
59
                iconName: "non-starred"
 
60
                visible: QuickUtils.mouseAttached
 
61
                onTriggered: QuickUtils.mouseAttached = false
 
62
            },
 
63
            Action {
 
64
                text: i18n.tr("Activate mouse")
 
65
                iconName: "starred"
 
66
                visible: !QuickUtils.mouseAttached
 
67
                onTriggered: QuickUtils.mouseAttached = true
 
68
            }
 
69
        ]
 
70
    }
 
71
 
 
72
    onActiveChanged: {
 
73
        if (layout.columns < 2) {
 
74
            widgetList.currentIndex = -1;
 
75
        }
 
76
        if (active) {
 
77
            widgetList.openPage();
 
78
        }
 
79
    }
 
80
 
 
81
    UbuntuListView {
 
82
        id: widgetList
 
83
        objectName: "widgetList"
 
84
        anchors {
 
85
            fill: parent
 
86
            topMargin: mainPage.header.flickable ? 0 : mainPage.header.height
 
87
        }
 
88
 
 
89
        model: WidgetsModel {}
 
90
        currentIndex: -1
 
91
 
 
92
        onCurrentIndexChanged: openPage()
 
93
 
 
94
        function openPage() {
 
95
            if (!mainPage.active || currentIndex < 0) return;
 
96
            var modelData = model.get(currentIndex);
 
97
            var source = Qt.resolvedUrl(modelData.source);
 
98
            mainPage.pageStack.addPageToNextColumn(mainPage, source, {title: modelData.label});
 
99
        }
 
100
 
 
101
        delegate: ListItem {
 
102
            objectName: model.objectName
 
103
            contentItem {
 
104
                anchors.leftMargin: units.gu(2)
 
105
                anchors.rightMargin: units.gu(2)
 
106
            }
 
107
            enabled: source != ""
 
108
            // Used by Autopilot
 
109
            property string text: label
 
110
            onClicked: widgetList.currentIndex = index
 
111
            Label {
 
112
                id: labelItem
 
113
                anchors {
 
114
                    fill: parent
 
115
                    rightMargin: units.gu(4)
 
116
                }
 
117
                text: label
 
118
                verticalAlignment: Text.AlignVCenter
 
119
            }
 
120
            Icon {
 
121
                name: "next"
 
122
                width: units.gu(2)
 
123
                height: units.gu(2)
 
124
                anchors {
 
125
                    verticalCenter: parent.verticalCenter
 
126
                    right: parent.right
 
127
                }
 
128
            }
 
129
        }
 
130
        highlight: Rectangle {
 
131
            color: theme.palette.selected.background
 
132
        }
 
133
        highlightMoveDuration: 0
 
134
    }
 
135
 
 
136
    BottomEdgeHint {
 
137
        flickable: widgetList
 
138
        text: i18n.tr('About')
 
139
        iconName: "info"
 
140
        onClicked: mainPage.pageStack.addPageToCurrentColumn(mainPage, Qt.resolvedUrl("About.qml"))
 
141
    }
 
142
}