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

« back to all changes in this revision

Viewing changes to examples/Printers.qml

  • Committer: Bileto Bot
  • Date: 2017-01-23 23:56:12 UTC
  • mfrom: (176.2.39 printer-components)
  • Revision ID: ci-train-bot@canonical.com-20170123235612-ugmiiaddrk817pfe
* packaging: suggest cups, depend on libcups2-dev
* adds cups bindings for printer/job management

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2017 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
 * Authored by Jonas G. Drange <jonas.drange@canonical.com>
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import QtQuick.Layouts 1.1
 
21
import Ubuntu.Components 1.3
 
22
import Ubuntu.Components.Popups 1.3
 
23
import Ubuntu.Components.ListItems 1.3 as ListItems
 
24
import Ubuntu.Settings.Components 0.1
 
25
import Ubuntu.Settings.Printers 0.1
 
26
 
 
27
MainView {
 
28
    width: units.gu(50)
 
29
    height: units.gu(90)
 
30
 
 
31
    Component {
 
32
        id: printerPage
 
33
 
 
34
        Page {
 
35
            visible: false
 
36
            property var printer
 
37
            header: PageHeader {
 
38
               title: printer.name
 
39
               flickable: printerFlickable
 
40
            }
 
41
 
 
42
            Flickable {
 
43
                id: printerFlickable
 
44
                anchors.fill: parent
 
45
 
 
46
                Column {
 
47
                    spacing: units.gu(2)
 
48
                    anchors {
 
49
                        top: parent.top
 
50
                        topMargin: units.gu(2)
 
51
                        left: parent.left
 
52
                        right: parent.right
 
53
                    }
 
54
 
 
55
                    Label {
 
56
                        anchors {
 
57
                            left: parent.left
 
58
                            right: parent.right
 
59
                            margins: units.gu(2)
 
60
                        }
 
61
                        text: "Description"
 
62
                    }
 
63
 
 
64
                    ListItems.SingleControl {
 
65
                        anchors {
 
66
                            left: parent.left
 
67
                            right: parent.right
 
68
                        }
 
69
 
 
70
                        control: TextField {
 
71
                           anchors {
 
72
                                margins: units.gu(1)
 
73
                                left: parent.left
 
74
                                right: parent.right
 
75
 
 
76
                            }
 
77
                            text: printer.description
 
78
                            onTextChanged: printer.description = text
 
79
                        }
 
80
                    }
 
81
 
 
82
 
 
83
                    ListItems.ValueSelector {
 
84
                        anchors {
 
85
                            left: parent.left
 
86
                            right: parent.right
 
87
                        }
 
88
                        enabled: values.length > 1
 
89
                        text: "Duplex"
 
90
                        values: printer.supportedDuplexModes
 
91
                        onSelectedIndexChanged: printer.duplexMode = selectedIndex
 
92
                        Component.onCompleted: {
 
93
                            if (enabled) {
 
94
                                selectedIndex = printer.duplexMode
 
95
                            }
 
96
                        }
 
97
                    }
 
98
 
 
99
                    ListItems.ValueSelector {
 
100
                        anchors {
 
101
                            left: parent.left
 
102
                            right: parent.right
 
103
                        }
 
104
                        text: "Page size"
 
105
                        values: printer.supportedPageSizes
 
106
                        onSelectedIndexChanged: printer.pageSize = selectedIndex
 
107
                        Component.onCompleted: selectedIndex = printer.supportedPageSizes.indexOf(printer.pageSize)
 
108
                    }
 
109
 
 
110
                    ListItems.ValueSelector {
 
111
                        anchors {
 
112
                            left: parent.left
 
113
                            right: parent.right
 
114
                        }
 
115
                        visible: printer.supportedColorModels.length
 
116
                        text: "Color model"
 
117
                        values: printer.supportedColorModels
 
118
                        enabled: values.length > 1
 
119
                        onSelectedIndexChanged: printer.colorModel = selectedIndex
 
120
                        Component.onCompleted: {
 
121
                            if (enabled)
 
122
                                selectedIndex = printer.colorModel
 
123
                        }
 
124
                    }
 
125
 
 
126
                    ListItems.ValueSelector {
 
127
                        anchors {
 
128
                            left: parent.left
 
129
                            right: parent.right
 
130
                        }
 
131
                        visible: printer.supportedPrintQualities.length
 
132
                        text: "Quality"
 
133
                        values: printer.supportedPrintQualities
 
134
                        enabled: values.length > 1
 
135
                        onSelectedIndexChanged: printer.printQuality = selectedIndex
 
136
                        Component.onCompleted: {
 
137
                            if (enabled)
 
138
                                selectedIndex = printer.printQuality
 
139
                        }
 
140
                    }
 
141
                }
 
142
            }
 
143
        }
 
144
    }
 
145
 
 
146
    PageStack {
 
147
        id: pageStack
 
148
 
 
149
        Component.onCompleted: push(printersPage)
 
150
 
 
151
        Page {
 
152
            id: printersPage
 
153
            header: PageHeader {
 
154
                title: "Printers"
 
155
                flickable: printerList
 
156
            }
 
157
            visible: false
 
158
 
 
159
            ListView {
 
160
                id: printerList
 
161
                anchors { fill: parent }
 
162
                model: Printers.allPrintersWithPdf
 
163
                delegate: ListItem {
 
164
                    height: modelLayout.height + (divider.visible ? divider.height : 0)
 
165
                    ListItemLayout {
 
166
                        id: modelLayout
 
167
                        title.text: displayName
 
168
                        title.font.bold: model.default
 
169
                        subtitle.text: description
 
170
 
 
171
                        Icon {
 
172
                            id: icon
 
173
                            width: height
 
174
                            height: units.gu(2.5)
 
175
                            name: "printer-symbolic"
 
176
                            SlotsLayout.position: SlotsLayout.First
 
177
                        }
 
178
 
 
179
                        ProgressionSlot {}
 
180
                    }
 
181
                    onClicked: pageStack.push(printerPage, { printer: model })
 
182
                    Component.onCompleted: console.log("printer", model.name)
 
183
                }
 
184
            }
 
185
        }
 
186
    }
 
187
}