Merge lp:~zsombi/ubuntu-ui-toolkit/calculator-example into lp:ubuntu-ui-toolkit
- calculator-example
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Tim Peeters |
Approved revision: | 570 |
Merged at revision: | 577 |
Proposed branch: | lp:~zsombi/ubuntu-ui-toolkit/calculator-example |
Merge into: | lp:ubuntu-ui-toolkit |
Diff against target: |
598 lines (+550/-1) 8 files modified
examples/calculator/calculator.desktop (+8/-0) examples/calculator/calculator.pro (+18/-0) examples/calculator/calculator.qml (+126/-0) examples/calculator/calculator.qmlproject (+31/-0) examples/calculator/components/DefaultLayout.qml (+100/-0) examples/calculator/components/Functions.qml (+46/-0) examples/calculator/components/calculator.js (+219/-0) examples/examples.pro (+2/-1) |
To merge this branch: | bzr merge lp:~zsombi/ubuntu-ui-toolkit/calculator-example |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Tim Peeters | Pending | ||
Review via email:
|
Commit message
Calculator example which turns from simple calculator (phone portrait mode) into scientific one (phone landscape mode) reflecting the use of Ubuntu.Layouts.
Description of the change
- 567. By Zsombor Egri
-
makefile removed; pro-file added to fix application installation; desktop file corrected
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
- 568. By Zsombor Egri
-
license headers updated
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:568
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 569. By Zsombor Egri
-
trunk merge
- 570. By Zsombor Egri
-
memory indication added
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:570
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Tim Peeters (tpeeters) wrote : | # |
on desktop, the text is very tiny, can we scale the text with the buttons?
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Tim Peeters (tpeeters) wrote : | # |
why add this example? We have a calculator app https:/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Tim Peeters (tpeeters) wrote : | # |
why do you have a Flickable? The buttons resize to fit in the view without flicking.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Zsombor Egri (zsombi) wrote : | # |
> on desktop, the text is very tiny, can we scale the text with the buttons?
Button label cannot be enlarged only with creating a different style for it.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Zsombor Egri (zsombi) wrote : | # |
> why add this example? We have a calculator app
> https:/
As we discussed, the app we have does not forbid us to create a simplier one to illustrate what we can do with certain SDK building blocks.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Zsombor Egri (zsombi) wrote : | # |
> why do you have a Flickable? The buttons resize to fit in the view without
> flicking.
Without Flickable the content goes below the Header :(. Haven't found a better way atm to circumvent that...
Preview Diff
1 | === added directory 'examples/calculator' | |||
2 | === added file 'examples/calculator/calculator.desktop' | |||
3 | --- examples/calculator/calculator.desktop 1970-01-01 00:00:00 +0000 | |||
4 | +++ examples/calculator/calculator.desktop 2013-07-03 06:43:28 +0000 | |||
5 | @@ -0,0 +1,8 @@ | |||
6 | 1 | [Desktop Entry] | ||
7 | 2 | Name=calculator | ||
8 | 3 | Comment=My project description | ||
9 | 4 | Exec=/usr/bin/qmlscene $@ /usr/lib/ubuntu-ui-toolkit/examples/calculator/calculator.qml | ||
10 | 5 | Icon=qmlscene | ||
11 | 6 | Terminal=false | ||
12 | 7 | Type=Application | ||
13 | 8 | X-Ubuntu-Touch=true | ||
14 | 0 | 9 | ||
15 | === added file 'examples/calculator/calculator.pro' | |||
16 | --- examples/calculator/calculator.pro 1970-01-01 00:00:00 +0000 | |||
17 | +++ examples/calculator/calculator.pro 2013-07-03 06:43:28 +0000 | |||
18 | @@ -0,0 +1,18 @@ | |||
19 | 1 | TEMPLATE = subdirs | ||
20 | 2 | |||
21 | 3 | filetypes = qml png svg js qmltheme jpg qmlproject desktop wav | ||
22 | 4 | |||
23 | 5 | OTHER_FILES = "" | ||
24 | 6 | |||
25 | 7 | for(filetype, filetypes) { | ||
26 | 8 | OTHER_FILES += *.$$filetype | ||
27 | 9 | } | ||
28 | 10 | |||
29 | 11 | desktop_files.path = /usr/share/applications | ||
30 | 12 | desktop_files.files = calculator.desktop | ||
31 | 13 | |||
32 | 14 | other_files.path = /usr/lib/ubuntu-ui-toolkit/examples/calculator | ||
33 | 15 | other_files.files = $$OTHER_FILES | ||
34 | 16 | |||
35 | 17 | INSTALLS += other_files desktop_files | ||
36 | 18 | |||
37 | 0 | 19 | ||
38 | === added file 'examples/calculator/calculator.qml' | |||
39 | --- examples/calculator/calculator.qml 1970-01-01 00:00:00 +0000 | |||
40 | +++ examples/calculator/calculator.qml 2013-07-03 06:43:28 +0000 | |||
41 | @@ -0,0 +1,126 @@ | |||
42 | 1 | /* | ||
43 | 2 | * Copyright 2013 Canonical Ltd. | ||
44 | 3 | * | ||
45 | 4 | * This program is free software; you can redistribute it and/or modify | ||
46 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
47 | 6 | * the Free Software Foundation; version 3. | ||
48 | 7 | * | ||
49 | 8 | * This program is distributed in the hope that it will be useful, | ||
50 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
51 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
52 | 11 | * GNU Lesser General Public License for more details. | ||
53 | 12 | * | ||
54 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
55 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
56 | 15 | * | ||
57 | 16 | * Author: Zsombor Egri <zsombor.egri@canonical.com> | ||
58 | 17 | */ | ||
59 | 18 | |||
60 | 19 | import QtQuick 2.0 | ||
61 | 20 | import Ubuntu.Components 0.1 | ||
62 | 21 | import Ubuntu.Layouts 0.1 | ||
63 | 22 | import "components" | ||
64 | 23 | import "components/calculator.js" as Calculator | ||
65 | 24 | |||
66 | 25 | /*! | ||
67 | 26 | \brief MainView with a Label and Button elements. | ||
68 | 27 | */ | ||
69 | 28 | |||
70 | 29 | MainView { | ||
71 | 30 | id: mainView | ||
72 | 31 | // objectName for functional testing purposes (autopilot-qt5) | ||
73 | 32 | objectName: "mainView" | ||
74 | 33 | |||
75 | 34 | // Note! applicationName needs to match the .desktop filename | ||
76 | 35 | applicationName: "calculator" | ||
77 | 36 | |||
78 | 37 | /* | ||
79 | 38 | This property enables the application to change orientation | ||
80 | 39 | when the device is rotated. The default is false. | ||
81 | 40 | */ | ||
82 | 41 | automaticOrientation: true | ||
83 | 42 | |||
84 | 43 | width: units.gu(40) | ||
85 | 44 | height: units.gu(71) | ||
86 | 45 | |||
87 | 46 | property var calculator: new Calculator.Calculator(numericInput, memoryIndicator); | ||
88 | 47 | |||
89 | 48 | // default portrait layout | ||
90 | 49 | Page { | ||
91 | 50 | id: page | ||
92 | 51 | title: i18n.tr("Calculator") | ||
93 | 52 | anchors.fill: parent | ||
94 | 53 | |||
95 | 54 | Flickable { | ||
96 | 55 | anchors.fill: parent | ||
97 | 56 | contentWidth: column.width | ||
98 | 57 | contentHeight: column.height | ||
99 | 58 | Column { | ||
100 | 59 | id: column | ||
101 | 60 | width: page.width | ||
102 | 61 | height: childrenRect.height | ||
103 | 62 | spacing: units.gu(0.5) | ||
104 | 63 | TextField { | ||
105 | 64 | id: numericInput | ||
106 | 65 | anchors { | ||
107 | 66 | left: parent.left | ||
108 | 67 | right: parent.right | ||
109 | 68 | } | ||
110 | 69 | readOnly: true | ||
111 | 70 | font.pixelSize: FontUtils.sizeToPixels("x-large") | ||
112 | 71 | font.bold: true | ||
113 | 72 | horizontalAlignment: Text.AlignRight | ||
114 | 73 | height: layout.currentLayout === "landscape" ? | ||
115 | 74 | units.gu(5) : units.gu(7) | ||
116 | 75 | primaryItem: Label { | ||
117 | 76 | id: memoryIndicator | ||
118 | 77 | width: units.gu(3) | ||
119 | 78 | height: parent.height | ||
120 | 79 | text: "M" | ||
121 | 80 | fontSize: "large" | ||
122 | 81 | font.bold: true | ||
123 | 82 | } | ||
124 | 83 | } | ||
125 | 84 | |||
126 | 85 | Layouts { | ||
127 | 86 | id: layout | ||
128 | 87 | anchors { | ||
129 | 88 | left: parent.left | ||
130 | 89 | right: parent.right | ||
131 | 90 | } | ||
132 | 91 | height: page.height - numericInput.height - mainView.header.height | ||
133 | 92 | |||
134 | 93 | layouts: [ | ||
135 | 94 | ConditionalLayout { | ||
136 | 95 | name: "landscape" | ||
137 | 96 | when: mainView.width > mainView.height | ||
138 | 97 | Item { | ||
139 | 98 | anchors.fill: parent | ||
140 | 99 | Functions { | ||
141 | 100 | operations: calculator | ||
142 | 101 | anchors.fill: parent | ||
143 | 102 | anchors.rightMargin: parent.width / 2 + units.gu(0.25) | ||
144 | 103 | spacing: units.gu(0.4) | ||
145 | 104 | } | ||
146 | 105 | |||
147 | 106 | ItemLayout { | ||
148 | 107 | item: "buttons" | ||
149 | 108 | anchors.fill: parent | ||
150 | 109 | |||
151 | 110 | anchors.leftMargin: parent.width / 2 + units.gu(0.25) | ||
152 | 111 | } | ||
153 | 112 | } | ||
154 | 113 | } | ||
155 | 114 | |||
156 | 115 | ] | ||
157 | 116 | DefaultLayout { | ||
158 | 117 | anchors.fill: parent | ||
159 | 118 | anchors.margins: units.gu(0.5) | ||
160 | 119 | operations: calculator | ||
161 | 120 | spacing: (layout.currentLayout === "landscape") ? units.gu(0.4) : units.gu(2) | ||
162 | 121 | } | ||
163 | 122 | } | ||
164 | 123 | } | ||
165 | 124 | } | ||
166 | 125 | } | ||
167 | 126 | } | ||
168 | 0 | 127 | ||
169 | === added file 'examples/calculator/calculator.qmlproject' | |||
170 | --- examples/calculator/calculator.qmlproject 1970-01-01 00:00:00 +0000 | |||
171 | +++ examples/calculator/calculator.qmlproject 2013-07-03 06:43:28 +0000 | |||
172 | @@ -0,0 +1,31 @@ | |||
173 | 1 | /* File generated by Qt Creator (with Ubuntu Plugin), version 2.7.1 */ | ||
174 | 2 | |||
175 | 3 | import QmlProject 1.1 | ||
176 | 4 | |||
177 | 5 | Project { | ||
178 | 6 | mainFile: "calculator.qml" | ||
179 | 7 | |||
180 | 8 | /* Include .qml, .js, and image files from current directory and subdirectories */ | ||
181 | 9 | QmlFiles { | ||
182 | 10 | directory: "." | ||
183 | 11 | } | ||
184 | 12 | JavaScriptFiles { | ||
185 | 13 | directory: "." | ||
186 | 14 | } | ||
187 | 15 | ImageFiles { | ||
188 | 16 | directory: "." | ||
189 | 17 | } | ||
190 | 18 | Files { | ||
191 | 19 | filter: "*.desktop" | ||
192 | 20 | } | ||
193 | 21 | Files { | ||
194 | 22 | directory: "html" | ||
195 | 23 | filter: "*" | ||
196 | 24 | } | ||
197 | 25 | Files { | ||
198 | 26 | directory: "debian" | ||
199 | 27 | filter: "*" | ||
200 | 28 | } | ||
201 | 29 | /* List of plugin directories passed to QML runtime */ | ||
202 | 30 | importPaths: [ "." ,"/usr/bin","/usr/lib/*/qt5/qml" ] | ||
203 | 31 | } | ||
204 | 0 | 32 | ||
205 | === added directory 'examples/calculator/components' | |||
206 | === added file 'examples/calculator/components/DefaultLayout.qml' | |||
207 | --- examples/calculator/components/DefaultLayout.qml 1970-01-01 00:00:00 +0000 | |||
208 | +++ examples/calculator/components/DefaultLayout.qml 2013-07-03 06:43:28 +0000 | |||
209 | @@ -0,0 +1,100 @@ | |||
210 | 1 | /* | ||
211 | 2 | * Copyright 2013 Canonical Ltd. | ||
212 | 3 | * | ||
213 | 4 | * This program is free software; you can redistribute it and/or modify | ||
214 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
215 | 6 | * the Free Software Foundation; version 3. | ||
216 | 7 | * | ||
217 | 8 | * This program is distributed in the hope that it will be useful, | ||
218 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
219 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
220 | 11 | * GNU Lesser General Public License for more details. | ||
221 | 12 | * | ||
222 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
223 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
224 | 15 | * | ||
225 | 16 | * Author: Zsombor Egri <zsombor.egri@canonical.com> | ||
226 | 17 | */ | ||
227 | 18 | |||
228 | 19 | import QtQuick 2.0 | ||
229 | 20 | import Ubuntu.Components 0.1 | ||
230 | 21 | import Ubuntu.Layouts 0.1 | ||
231 | 22 | |||
232 | 23 | Item { | ||
233 | 24 | id: buttonGrid | ||
234 | 25 | Layouts.item: "buttons" | ||
235 | 26 | |||
236 | 27 | property real spacing: units.gu(0.5) | ||
237 | 28 | property real buttonHeight: (buttonGrid.height - 5 * buttonGrid.spacing) / 6 | ||
238 | 29 | property real buttonWidth: (buttonGrid.width - 3 * buttonGrid.spacing) / 4 | ||
239 | 30 | |||
240 | 31 | property var operations | ||
241 | 32 | |||
242 | 33 | property var __model: [ | ||
243 | 34 | {"label": "mc", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, | ||
244 | 35 | {"label": "m+", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, | ||
245 | 36 | {"label": "m-", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, | ||
246 | 37 | {"label": "mr", "color": "darkgray", "width" : buttonWidth, "height": buttonHeight}, | ||
247 | 38 | |||
248 | 39 | {"label": "c", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, | ||
249 | 40 | {"label": "+/-", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, | ||
250 | 41 | {"label": "/", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, | ||
251 | 42 | {"label": "*", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, | ||
252 | 43 | |||
253 | 44 | {"label": "7", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
254 | 45 | {"label": "8", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
255 | 46 | {"label": "9", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
256 | 47 | {"label": "-", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, | ||
257 | 48 | |||
258 | 49 | {"label": "4", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
259 | 50 | {"label": "5", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
260 | 51 | {"label": "6", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
261 | 52 | {"label": "+", "color": "brown", "width" : buttonWidth, "height": buttonHeight}, | ||
262 | 53 | |||
263 | 54 | {"label": "1", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
264 | 55 | {"label": "2", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
265 | 56 | {"label": "3", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
266 | 57 | {"label": "=", "color": "orange", "width" : buttonWidth, "height": buttonHeight * 2 + spacing}, | ||
267 | 58 | ] | ||
268 | 59 | property var __lastRow: [ | ||
269 | 60 | {"label": "0", "color": "#5f5f5f", "width" : 2 * buttonWidth + spacing, "height": buttonHeight}, | ||
270 | 61 | {"label": ".", "color": "#5f5f5f", "width" : buttonWidth, "height": buttonHeight}, | ||
271 | 62 | ] | ||
272 | 63 | Grid { | ||
273 | 64 | id: grid | ||
274 | 65 | spacing: buttonGrid.spacing | ||
275 | 66 | anchors.fill: parent | ||
276 | 67 | |||
277 | 68 | // memory | ||
278 | 69 | Repeater { | ||
279 | 70 | model: __model | ||
280 | 71 | delegate: Button { | ||
281 | 72 | text: modelData.label | ||
282 | 73 | color: modelData.color | ||
283 | 74 | width: modelData.width | ||
284 | 75 | height: modelData.height | ||
285 | 76 | onClicked: operations.execute(modelData.label) | ||
286 | 77 | } | ||
287 | 78 | } | ||
288 | 79 | } | ||
289 | 80 | Row { | ||
290 | 81 | anchors{ | ||
291 | 82 | top: grid.bottom | ||
292 | 83 | topMargin: -buttonHeight | ||
293 | 84 | } | ||
294 | 85 | |||
295 | 86 | spacing: buttonGrid.spacing | ||
296 | 87 | |||
297 | 88 | // memory | ||
298 | 89 | Repeater { | ||
299 | 90 | model: __lastRow | ||
300 | 91 | delegate: Button { | ||
301 | 92 | text: modelData.label | ||
302 | 93 | color: modelData.color | ||
303 | 94 | width: modelData.width | ||
304 | 95 | height: modelData.height | ||
305 | 96 | onClicked: operations.execute(modelData.label) | ||
306 | 97 | } | ||
307 | 98 | } | ||
308 | 99 | } | ||
309 | 100 | } | ||
310 | 0 | 101 | ||
311 | === added file 'examples/calculator/components/Functions.qml' | |||
312 | --- examples/calculator/components/Functions.qml 1970-01-01 00:00:00 +0000 | |||
313 | +++ examples/calculator/components/Functions.qml 2013-07-03 06:43:28 +0000 | |||
314 | @@ -0,0 +1,46 @@ | |||
315 | 1 | /* | ||
316 | 2 | * Copyright 2013 Canonical Ltd. | ||
317 | 3 | * | ||
318 | 4 | * This program is free software; you can redistribute it and/or modify | ||
319 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
320 | 6 | * the Free Software Foundation; version 3. | ||
321 | 7 | * | ||
322 | 8 | * This program is distributed in the hope that it will be useful, | ||
323 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
324 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
325 | 11 | * GNU Lesser General Public License for more details. | ||
326 | 12 | * | ||
327 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
328 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
329 | 15 | * | ||
330 | 16 | * Author: Zsombor Egri <zsombor.egri@canonical.com> | ||
331 | 17 | */ | ||
332 | 18 | |||
333 | 19 | import QtQuick 2.0 | ||
334 | 20 | import Ubuntu.Components 0.1 | ||
335 | 21 | import Ubuntu.Layouts 0.1 | ||
336 | 22 | |||
337 | 23 | Grid { | ||
338 | 24 | id: buttonGrid | ||
339 | 25 | columns: 4 | ||
340 | 26 | rows: 7 | ||
341 | 27 | spacing: units.gu(1) | ||
342 | 28 | |||
343 | 29 | property var operations | ||
344 | 30 | |||
345 | 31 | Repeater { | ||
346 | 32 | model: [ | ||
347 | 33 | "%", "1/x", "x!", "x^2", | ||
348 | 34 | "x^3", "x^y", "2^x", "sqrt", | ||
349 | 35 | "ln", "e^x", "sin()", "cos()", | ||
350 | 36 | "tan()", "cot()", "sec()", "csc()", | ||
351 | 37 | ] | ||
352 | 38 | delegate: Button { | ||
353 | 39 | text: modelData | ||
354 | 40 | width: (buttonGrid.width - 3 * buttonGrid.spacing) / 4 | ||
355 | 41 | height: (buttonGrid.height - 3 * buttonGrid.spacing) / 4 | ||
356 | 42 | onClicked: operations.execute(modelData) | ||
357 | 43 | } | ||
358 | 44 | } | ||
359 | 45 | |||
360 | 46 | } | ||
361 | 0 | 47 | ||
362 | === added file 'examples/calculator/components/calculator.js' | |||
363 | --- examples/calculator/components/calculator.js 1970-01-01 00:00:00 +0000 | |||
364 | +++ examples/calculator/components/calculator.js 2013-07-03 06:43:28 +0000 | |||
365 | @@ -0,0 +1,219 @@ | |||
366 | 1 | /* | ||
367 | 2 | * Copyright 2013 Canonical Ltd. | ||
368 | 3 | * | ||
369 | 4 | * This program is free software; you can redistribute it and/or modify | ||
370 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
371 | 6 | * the Free Software Foundation; version 3. | ||
372 | 7 | * | ||
373 | 8 | * This program is distributed in the hope that it will be useful, | ||
374 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
375 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
376 | 11 | * GNU Lesser General Public License for more details. | ||
377 | 12 | * | ||
378 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
379 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
380 | 15 | * | ||
381 | 16 | * Author: Zsombor Egri <zsombor.egri@canonical.com> | ||
382 | 17 | */ | ||
383 | 18 | |||
384 | 19 | .pragma library | ||
385 | 20 | |||
386 | 21 | function Calculator(textInput, memoryIndicator) { | ||
387 | 22 | var operationStage = 0; // 0-lvalue, 1-rvalue | ||
388 | 23 | var lvalue = 0.0; | ||
389 | 24 | var rvalue = 0.0; | ||
390 | 25 | var lastOperation = -1; | ||
391 | 26 | var memory = 0.0; | ||
392 | 27 | var clearInputNext = true; | ||
393 | 28 | |||
394 | 29 | textInput.text = lvalue; | ||
395 | 30 | memoryIndicator.visible = false; | ||
396 | 31 | |||
397 | 32 | function setValue(value) { | ||
398 | 33 | if (operationStage === 0) { | ||
399 | 34 | lvalue = parseFloat(value); | ||
400 | 35 | return lvalue; | ||
401 | 36 | } else if (operationStage === 1) { | ||
402 | 37 | rvalue = parseFloat(value); | ||
403 | 38 | return rvalue; | ||
404 | 39 | } | ||
405 | 40 | } | ||
406 | 41 | function value() { | ||
407 | 42 | return (operationStage === 0) ? lvalue : rvalue; | ||
408 | 43 | } | ||
409 | 44 | |||
410 | 45 | function clear() { | ||
411 | 46 | operationStage = 1; | ||
412 | 47 | lvalue = rvalue = 0; | ||
413 | 48 | lastOperation = -1; | ||
414 | 49 | textInput.text = 0.0; | ||
415 | 50 | } | ||
416 | 51 | function memClear() { | ||
417 | 52 | memory = 0; | ||
418 | 53 | memoryIndicator.visible = false; | ||
419 | 54 | } | ||
420 | 55 | function memRecall() { | ||
421 | 56 | if (memory <= 0) | ||
422 | 57 | return; | ||
423 | 58 | textInput.text = setValue(memory); | ||
424 | 59 | } | ||
425 | 60 | function memAdd() { | ||
426 | 61 | memory += value(); | ||
427 | 62 | textInput.text = setValue(memory); | ||
428 | 63 | memoryIndicator.visible = true; | ||
429 | 64 | } | ||
430 | 65 | function memDec() { | ||
431 | 66 | memory -= value(); | ||
432 | 67 | textInput.text = setValue(memory); | ||
433 | 68 | memoryIndicator.visible = true; | ||
434 | 69 | } | ||
435 | 70 | |||
436 | 71 | // arythmetic functions | ||
437 | 72 | function add() { | ||
438 | 73 | lvalue += rvalue; | ||
439 | 74 | } | ||
440 | 75 | function dec() { | ||
441 | 76 | lvalue -= rvalue; | ||
442 | 77 | } | ||
443 | 78 | function mul() { | ||
444 | 79 | lvalue *= rvalue; | ||
445 | 80 | } | ||
446 | 81 | function div() { | ||
447 | 82 | lvalue /= rvalue; | ||
448 | 83 | } | ||
449 | 84 | |||
450 | 85 | function sign() { | ||
451 | 86 | textInput.text = setValue(-value()); | ||
452 | 87 | } | ||
453 | 88 | |||
454 | 89 | function invert() { | ||
455 | 90 | textInput.text = setValue(1/value()); | ||
456 | 91 | } | ||
457 | 92 | function percent() { | ||
458 | 93 | textInput.text = setValue(value() / 100); | ||
459 | 94 | } | ||
460 | 95 | function sqr() { | ||
461 | 96 | textInput.text = setValue(Math.pow(value(), 2)); | ||
462 | 97 | } | ||
463 | 98 | function cube() { | ||
464 | 99 | textInput.text = setValue(Math.pow(value(), 3)); | ||
465 | 100 | } | ||
466 | 101 | function power() { | ||
467 | 102 | lvalue = Math.pow(lvalue, rvalue); | ||
468 | 103 | } | ||
469 | 104 | function powerOf2() { | ||
470 | 105 | textInput.text = setValue(Math.pow(2, value())); | ||
471 | 106 | } | ||
472 | 107 | function factorial() { | ||
473 | 108 | var rval = 1; | ||
474 | 109 | for (var i = 2; i <= value(); i++) { | ||
475 | 110 | rval *= i; | ||
476 | 111 | } | ||
477 | 112 | textInput.text = setValue(rval); | ||
478 | 113 | } | ||
479 | 114 | function sqrt() { | ||
480 | 115 | textInput.text = setValue(Math.sqrt(value())); | ||
481 | 116 | } | ||
482 | 117 | function ln() { | ||
483 | 118 | textInput.text = setValue(Math.log(value())); | ||
484 | 119 | } | ||
485 | 120 | function exp() | ||
486 | 121 | { | ||
487 | 122 | textInput.text = setValue(Math.exp(value())); | ||
488 | 123 | } | ||
489 | 124 | function sin() { | ||
490 | 125 | textInput.text = setValue(Math.sin(value())); | ||
491 | 126 | } | ||
492 | 127 | function cos() { | ||
493 | 128 | textInput.text = setValue(Math.cos(value())); | ||
494 | 129 | } | ||
495 | 130 | function tan() { | ||
496 | 131 | textInput.text = setValue(Math.tan(value())); | ||
497 | 132 | } | ||
498 | 133 | function cot() { | ||
499 | 134 | textInput.text = setValue(1/Math.tan(value())); | ||
500 | 135 | } | ||
501 | 136 | function sec() { | ||
502 | 137 | textInput.text = setValue(1/Math.cos(value())); | ||
503 | 138 | } | ||
504 | 139 | function csc() { | ||
505 | 140 | textInput.text = setValue(1/Math.sin(value())); | ||
506 | 141 | } | ||
507 | 142 | |||
508 | 143 | var operations = [ | ||
509 | 144 | {code: "+", operationFunc: add}, | ||
510 | 145 | {code: "-", operationFunc: dec}, | ||
511 | 146 | {code: "*", operationFunc: mul}, | ||
512 | 147 | {code: "/", operationFunc: div}, | ||
513 | 148 | |||
514 | 149 | {code: "+/-", controlFunc: sign}, | ||
515 | 150 | {code: "c", controlFunc: clear}, | ||
516 | 151 | |||
517 | 152 | {code: "mc", controlFunc: memClear}, | ||
518 | 153 | {code: "mr", controlFunc: memRecall}, | ||
519 | 154 | {code: "m+", controlFunc: memAdd}, | ||
520 | 155 | {code: "m-", controlFunc: memDec}, | ||
521 | 156 | |||
522 | 157 | {code: "%", controlFunc: percent}, | ||
523 | 158 | {code: "1/x", controlFunc: invert}, | ||
524 | 159 | {code: "x!", controlFunc: factorial}, | ||
525 | 160 | {code: "x^2", controlFunc: sqr}, | ||
526 | 161 | {code: "x^3", controlFunc: cube}, | ||
527 | 162 | {code: "x^y", operationFunc: power}, | ||
528 | 163 | {code: "2^x", controlFunc: powerOf2}, | ||
529 | 164 | {code: "sqrt", controlFunc: sqrt}, | ||
530 | 165 | {code: "ln", controlFunc: ln}, | ||
531 | 166 | {code: "e^x", controlFunc: exp}, | ||
532 | 167 | {code: "sin()", controlFunc: sin}, | ||
533 | 168 | {code: "cos()", controlFunc: cos}, | ||
534 | 169 | {code: "tan()", controlFunc: tan}, | ||
535 | 170 | {code: "cot()", controlFunc: cot}, | ||
536 | 171 | {code: "sec()", controlFunc: sec}, | ||
537 | 172 | {code: "csc()", controlFunc: csc}, | ||
538 | 173 | |||
539 | 174 | ]; | ||
540 | 175 | |||
541 | 176 | this.execute = function (operation) { | ||
542 | 177 | if (operation === "=") { | ||
543 | 178 | if (lastOperation > -1) { | ||
544 | 179 | operations[lastOperation].operationFunc(); | ||
545 | 180 | textInput.text = lvalue; | ||
546 | 181 | } | ||
547 | 182 | operationStage = 0; | ||
548 | 183 | clearInputNext = true; | ||
549 | 184 | } else { | ||
550 | 185 | for (var i = 0; i < operations.length; i++) { | ||
551 | 186 | if (operations[i].code === operation) { | ||
552 | 187 | if (operations[i].operationFunc) { | ||
553 | 188 | clearInputNext = true; | ||
554 | 189 | if (operations[i].singleOp) { | ||
555 | 190 | operations[i].operationFunc(); | ||
556 | 191 | return; | ||
557 | 192 | } | ||
558 | 193 | |||
559 | 194 | lastOperation = i; | ||
560 | 195 | if (operationStage === 0) { | ||
561 | 196 | operationStage = 1; | ||
562 | 197 | } else if (operationStage === 1) { | ||
563 | 198 | // evaluate and continue receiving rvalue | ||
564 | 199 | operations[i].operationFunc(lvalue, rvalue); | ||
565 | 200 | textInput.text = lvalue; | ||
566 | 201 | } | ||
567 | 202 | } else if (operations[i].controlFunc) { | ||
568 | 203 | operations[i].controlFunc(); | ||
569 | 204 | clearInputNext = true; | ||
570 | 205 | } | ||
571 | 206 | |||
572 | 207 | return; | ||
573 | 208 | } | ||
574 | 209 | } | ||
575 | 210 | |||
576 | 211 | // if no opeartion was performed, add operation to input | ||
577 | 212 | if (clearInputNext) { | ||
578 | 213 | clearInputNext = false; | ||
579 | 214 | textInput.text = ""; | ||
580 | 215 | } | ||
581 | 216 | textInput.text = setValue(textInput.text + operation); | ||
582 | 217 | } | ||
583 | 218 | } | ||
584 | 219 | } | ||
585 | 0 | 220 | ||
586 | === modified file 'examples/examples.pro' | |||
587 | --- examples/examples.pro 2013-06-26 22:55:34 +0000 | |||
588 | +++ examples/examples.pro 2013-07-03 06:43:28 +0000 | |||
589 | @@ -4,7 +4,8 @@ | |||
590 | 4 | ubuntu-ui-toolkit-gallery\ | 4 | ubuntu-ui-toolkit-gallery\ |
591 | 5 | jokes \ | 5 | jokes \ |
592 | 6 | locale \ | 6 | locale \ |
594 | 7 | unit-converter | 7 | unit-converter \ |
595 | 8 | calculator | ||
596 | 8 | 9 | ||
597 | 9 | 10 | ||
598 | 10 | #examples = jokes unit-converter | 11 | #examples = jokes unit-converter |
FAILED: Continuous integration, rev:567 jenkins. qa.ubuntu. com/job/ ubuntu- ui-toolkit- ci/257/ jenkins. qa.ubuntu. com/job/ ubuntu- ui-toolkit- saucy-amd64- ci/114/ console jenkins. qa.ubuntu. com/job/ ubuntu- ui-toolkit- saucy-armhf- ci/114/ console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ ubuntu- ui-toolkit- ci/257/ rebuild
http://