Merge lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-c++-label-conversion into lp:ubuntu-ui-toolkit/staging
- ubuntu-ui-toolkit-c++-label-conversion
- Merge into staging
Proposed by
Loïc Molinari
Status: | Work in progress |
---|---|
Proposed branch: | lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-c++-label-conversion |
Merge into: | lp:ubuntu-ui-toolkit/staging |
Diff against target: |
519 lines (+251/-87) 13 files modified
components.api (+7/-3) modules/Ubuntu/Components/Label.qml (+0/-59) modules/Ubuntu/Components/OptionSelector.qml (+1/-1) modules/Ubuntu/Components/OptionSelectorDelegate.qml (+2/-2) modules/Ubuntu/Components/TextArea.qml (+2/-2) modules/Ubuntu/Components/TextField.qml (+1/-1) modules/Ubuntu/Components/plugin/plugin.cpp (+3/-0) modules/Ubuntu/Components/plugin/plugin.pro (+2/-0) modules/Ubuntu/Components/plugin/ucfontutils.cpp (+15/-16) modules/Ubuntu/Components/plugin/ucfontutils.h (+8/-1) modules/Ubuntu/Components/plugin/uclabel.cpp (+141/-0) modules/Ubuntu/Components/plugin/uclabel.h (+69/-0) modules/Ubuntu/Components/qmldir (+0/-2) |
To merge this branch: | bzr merge lp:~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-c++-label-conversion |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Zsombor Egri | Needs Fixing | ||
Review via email: mp+253163@code.launchpad.net |
Commit message
Coverted Label item from QML to C++ for performance reasons.
Description of the change
Coverted Label item from QML to C++ for performance reasons.
To post a comment you must log in.
Revision history for this message
Loïc Molinari (loic.molinari) wrote : | # |
> You cannot hardcode the color. See old Label "color:
> Theme.palette.
> that.
Any idea on how to do that?
Revision history for this message
Loïc Molinari (loic.molinari) wrote : | # |
What about the naming of the new property adaptiveSize, good enough?
Unmerged revisions
- 1451. By Loïc Molinari
-
Converted Label from QML to C++.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'components.api' | |||
2 | --- components.api 2015-03-10 13:58:52 +0000 | |||
3 | +++ components.api 2015-03-17 09:10:46 +0000 | |||
4 | @@ -83,9 +83,6 @@ | |||
5 | 83 | Icon 1.1 | 83 | Icon 1.1 |
6 | 84 | Icon10 | 84 | Icon10 |
7 | 85 | property url source | 85 | property url source |
8 | 86 | Label 0.1 1.0 | ||
9 | 87 | Text | ||
10 | 88 | property string fontSize | ||
11 | 89 | Base 0.1 1.0 | 86 | Base 0.1 1.0 |
12 | 90 | Empty | 87 | Empty |
13 | 91 | property variant icon | 88 | property variant icon |
14 | @@ -925,6 +922,13 @@ | |||
15 | 925 | name: "UCInverseMouse" | 922 | name: "UCInverseMouse" |
16 | 926 | prototype: "UCMouse" | 923 | prototype: "UCMouse" |
17 | 927 | exports: ["InverseMouse 0.1", "InverseMouse 1.0"] | 924 | exports: ["InverseMouse 0.1", "InverseMouse 1.0"] |
18 | 925 | name: "UCLabel" | ||
19 | 926 | prototype: "QQuickText" | ||
20 | 927 | exports: ["Label 0.1", "Label 1.0", "Label 1.2"] | ||
21 | 928 | name: "AdaptiveSize" | ||
22 | 929 | Property { name: "adaptiveSize"; revision: 1; type: "AdaptiveSize" } | ||
23 | 930 | Property { name: "fontSize"; type: "string" } | ||
24 | 931 | Signal { name: "adaptiveSizeChanged"; revision: 1 } | ||
25 | 928 | name: "UCListItem" | 932 | name: "UCListItem" |
26 | 929 | prototype: "UCStyledItemBase" | 933 | prototype: "UCStyledItemBase" |
27 | 930 | exports: ["ListItem 1.2"] | 934 | exports: ["ListItem 1.2"] |
28 | 931 | 935 | ||
29 | === removed file 'modules/Ubuntu/Components/Label.qml' | |||
30 | --- modules/Ubuntu/Components/Label.qml 2015-03-03 13:47:48 +0000 | |||
31 | +++ modules/Ubuntu/Components/Label.qml 1970-01-01 00:00:00 +0000 | |||
32 | @@ -1,59 +0,0 @@ | |||
33 | 1 | /* | ||
34 | 2 | * Copyright 2012 Canonical Ltd. | ||
35 | 3 | * | ||
36 | 4 | * This program is free software; you can redistribute it and/or modify | ||
37 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
38 | 6 | * the Free Software Foundation; version 3. | ||
39 | 7 | * | ||
40 | 8 | * This program is distributed in the hope that it will be useful, | ||
41 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
42 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
43 | 11 | * GNU Lesser General Public License for more details. | ||
44 | 12 | * | ||
45 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
46 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
47 | 15 | */ | ||
48 | 16 | |||
49 | 17 | import QtQuick 2.4 | ||
50 | 18 | |||
51 | 19 | /*! | ||
52 | 20 | \qmltype Label | ||
53 | 21 | \inqmlmodule Ubuntu.Components 1.1 | ||
54 | 22 | \ingroup ubuntu | ||
55 | 23 | \brief Text with Ubuntu styling. | ||
56 | 24 | |||
57 | 25 | Example: | ||
58 | 26 | \qml | ||
59 | 27 | Rectangle { | ||
60 | 28 | color: UbuntuColors.coolGrey | ||
61 | 29 | width: units.gu(30) | ||
62 | 30 | height: units.gu(30) | ||
63 | 31 | |||
64 | 32 | Label { | ||
65 | 33 | anchors.centerIn: parent | ||
66 | 34 | text: "Hello, world!" | ||
67 | 35 | fontSize: "large" | ||
68 | 36 | } | ||
69 | 37 | } | ||
70 | 38 | \endqml | ||
71 | 39 | */ | ||
72 | 40 | Text { | ||
73 | 41 | id: label | ||
74 | 42 | |||
75 | 43 | /*! | ||
76 | 44 | The size of the text. One of the following strings (from smallest to largest): | ||
77 | 45 | \list | ||
78 | 46 | \li "xx-small" | ||
79 | 47 | \li "x-small" | ||
80 | 48 | \li "small" | ||
81 | 49 | \li "medium" | ||
82 | 50 | \li "large" | ||
83 | 51 | \li "x-large" | ||
84 | 52 | \endlist | ||
85 | 53 | Default value is "medium". | ||
86 | 54 | */ | ||
87 | 55 | property string fontSize: "medium" | ||
88 | 56 | |||
89 | 57 | font.pixelSize: FontUtils.sizeToPixels(fontSize) | ||
90 | 58 | color: Theme.palette.selected.backgroundText | ||
91 | 59 | } | ||
92 | 60 | 0 | ||
93 | === modified file 'modules/Ubuntu/Components/OptionSelector.qml' | |||
94 | --- modules/Ubuntu/Components/OptionSelector.qml 2015-03-03 13:47:48 +0000 | |||
95 | +++ modules/Ubuntu/Components/OptionSelector.qml 2015-03-17 09:10:46 +0000 | |||
96 | @@ -202,7 +202,7 @@ | |||
97 | 202 | right: parent.right | 202 | right: parent.right |
98 | 203 | } | 203 | } |
99 | 204 | 204 | ||
101 | 205 | Label { | 205 | Toolkit.Label { |
102 | 206 | id : label | 206 | id : label |
103 | 207 | 207 | ||
104 | 208 | text: optionSelector.text | 208 | text: optionSelector.text |
105 | 209 | 209 | ||
106 | === modified file 'modules/Ubuntu/Components/OptionSelectorDelegate.qml' | |||
107 | --- modules/Ubuntu/Components/OptionSelectorDelegate.qml 2015-03-03 13:47:48 +0000 | |||
108 | +++ modules/Ubuntu/Components/OptionSelectorDelegate.qml 2015-03-17 09:10:46 +0000 | |||
109 | @@ -318,10 +318,10 @@ | |||
110 | 318 | anchors { | 318 | anchors { |
111 | 319 | verticalCenter: parent.verticalCenter | 319 | verticalCenter: parent.verticalCenter |
112 | 320 | } | 320 | } |
114 | 321 | Label { | 321 | Toolkit.Label { |
115 | 322 | text: option.text === "" ? modelData : option.text | 322 | text: option.text === "" ? modelData : option.text |
116 | 323 | } | 323 | } |
118 | 324 | Label { | 324 | Toolkit.Label { |
119 | 325 | text: option.subText | 325 | text: option.subText |
120 | 326 | visible: option.subText !== "" ? true : false | 326 | visible: option.subText !== "" ? true : false |
121 | 327 | fontSize: "small" | 327 | fontSize: "small" |
122 | 328 | 328 | ||
123 | === modified file 'modules/Ubuntu/Components/TextArea.qml' | |||
124 | --- modules/Ubuntu/Components/TextArea.qml 2015-03-10 11:49:27 +0000 | |||
125 | +++ modules/Ubuntu/Components/TextArea.qml 2015-03-17 09:10:46 +0000 | |||
126 | @@ -792,10 +792,10 @@ | |||
127 | 792 | Keys.onReleased: event.accepted = (event.key === Qt.Key_Enter) || (event.key === Qt.Key_Return) | 792 | Keys.onReleased: event.accepted = (event.key === Qt.Key_Enter) || (event.key === Qt.Key_Return) |
128 | 793 | 793 | ||
129 | 794 | // holding default values | 794 | // holding default values |
131 | 795 | Label { id: fontHolder } | 795 | Ubuntu.Label { id: fontHolder } |
132 | 796 | 796 | ||
133 | 797 | //hint | 797 | //hint |
135 | 798 | Label { | 798 | Ubuntu.Label { |
136 | 799 | id: hint | 799 | id: hint |
137 | 800 | anchors { | 800 | anchors { |
138 | 801 | fill: parent | 801 | fill: parent |
139 | 802 | 802 | ||
140 | === modified file 'modules/Ubuntu/Components/TextField.qml' | |||
141 | --- modules/Ubuntu/Components/TextField.qml 2015-03-10 11:49:27 +0000 | |||
142 | +++ modules/Ubuntu/Components/TextField.qml 2015-03-17 09:10:46 +0000 | |||
143 | @@ -936,7 +936,7 @@ | |||
144 | 936 | } | 936 | } |
145 | 937 | 937 | ||
146 | 938 | // hint text | 938 | // hint text |
148 | 939 | Label { | 939 | Ubuntu.Label { |
149 | 940 | id: hint | 940 | id: hint |
150 | 941 | verticalAlignment: Text.AlignVCenter | 941 | verticalAlignment: Text.AlignVCenter |
151 | 942 | horizontalAlignment: editor.horizontalAlignment | 942 | horizontalAlignment: editor.horizontalAlignment |
152 | 943 | 943 | ||
153 | === modified file 'modules/Ubuntu/Components/plugin/plugin.cpp' | |||
154 | --- modules/Ubuntu/Components/plugin/plugin.cpp 2015-03-04 19:07:58 +0000 | |||
155 | +++ modules/Ubuntu/Components/plugin/plugin.cpp 2015-03-17 09:10:46 +0000 | |||
156 | @@ -58,6 +58,7 @@ | |||
157 | 58 | #include "uclistitemactions.h" | 58 | #include "uclistitemactions.h" |
158 | 59 | #include "uclistitemstyle.h" | 59 | #include "uclistitemstyle.h" |
159 | 60 | #include "ucserviceproperties.h" | 60 | #include "ucserviceproperties.h" |
160 | 61 | #include "uclabel.h" | ||
161 | 61 | #include "ucnamespace.h" | 62 | #include "ucnamespace.h" |
162 | 62 | 63 | ||
163 | 63 | #include <sys/types.h> | 64 | #include <sys/types.h> |
164 | @@ -156,6 +157,7 @@ | |||
165 | 156 | qmlRegisterSingletonType<UCUriHandler>(uri, major, minor, "UriHandler", registerUriHandler); | 157 | qmlRegisterSingletonType<UCUriHandler>(uri, major, minor, "UriHandler", registerUriHandler); |
166 | 157 | qmlRegisterType<UCMouse>(uri, major, minor, "Mouse"); | 158 | qmlRegisterType<UCMouse>(uri, major, minor, "Mouse"); |
167 | 158 | qmlRegisterType<UCInverseMouse>(uri, major, minor, "InverseMouse"); | 159 | qmlRegisterType<UCInverseMouse>(uri, major, minor, "InverseMouse"); |
168 | 160 | qmlRegisterType<UCLabel>(uri, major, minor, "Label"); | ||
169 | 159 | } | 161 | } |
170 | 160 | 162 | ||
171 | 161 | void UbuntuComponentsPlugin::registerTypes(const char *uri) | 163 | void UbuntuComponentsPlugin::registerTypes(const char *uri) |
172 | @@ -189,6 +191,7 @@ | |||
173 | 189 | qmlRegisterSingletonType<UCNamespace>(uri, 1, 2, "Ubuntu", registerUbuntuNamespace); | 191 | qmlRegisterSingletonType<UCNamespace>(uri, 1, 2, "Ubuntu", registerUbuntuNamespace); |
174 | 190 | qmlRegisterType<UCUbuntuShape, 1>(uri, 1, 2, "UbuntuShape"); | 192 | qmlRegisterType<UCUbuntuShape, 1>(uri, 1, 2, "UbuntuShape"); |
175 | 191 | qmlRegisterType<UCUbuntuShapeOverlay>(uri, 1, 2, "UbuntuShapeOverlay"); | 193 | qmlRegisterType<UCUbuntuShapeOverlay>(uri, 1, 2, "UbuntuShapeOverlay"); |
176 | 194 | qmlRegisterType<UCLabel, 1>(uri, 1, 2, "Label"); | ||
177 | 192 | } | 195 | } |
178 | 193 | 196 | ||
179 | 194 | void UbuntuComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) | 197 | void UbuntuComponentsPlugin::initializeEngine(QQmlEngine *engine, const char *uri) |
180 | 195 | 198 | ||
181 | === modified file 'modules/Ubuntu/Components/plugin/plugin.pro' | |||
182 | --- modules/Ubuntu/Components/plugin/plugin.pro 2015-03-04 19:07:58 +0000 | |||
183 | +++ modules/Ubuntu/Components/plugin/plugin.pro 2015-03-17 09:10:46 +0000 | |||
184 | @@ -77,6 +77,7 @@ | |||
185 | 77 | uclistitemstyle.h \ | 77 | uclistitemstyle.h \ |
186 | 78 | ucserviceproperties.h \ | 78 | ucserviceproperties.h \ |
187 | 79 | ucserviceproperties_p.h \ | 79 | ucserviceproperties_p.h \ |
188 | 80 | uclabel.h \ | ||
189 | 80 | privates/listitemdragarea.h \ | 81 | privates/listitemdragarea.h \ |
190 | 81 | privates/listitemdraghandler.h \ | 82 | privates/listitemdraghandler.h \ |
191 | 82 | ucnamespace.h | 83 | ucnamespace.h |
192 | @@ -124,6 +125,7 @@ | |||
193 | 124 | uclistitemstyle.cpp \ | 125 | uclistitemstyle.cpp \ |
194 | 125 | ucviewitemsattached.cpp \ | 126 | ucviewitemsattached.cpp \ |
195 | 126 | ucserviceproperties.cpp \ | 127 | ucserviceproperties.cpp \ |
196 | 128 | uclabel.cpp \ | ||
197 | 127 | privates/listitemdragarea.cpp \ | 129 | privates/listitemdragarea.cpp \ |
198 | 128 | privates/listitemdraghandler.cpp \ | 130 | privates/listitemdraghandler.cpp \ |
199 | 129 | ucnamespace.cpp | 131 | ucnamespace.cpp |
200 | 130 | 132 | ||
201 | === modified file 'modules/Ubuntu/Components/plugin/ucfontutils.cpp' | |||
202 | --- modules/Ubuntu/Components/plugin/ucfontutils.cpp 2015-03-03 13:47:48 +0000 | |||
203 | +++ modules/Ubuntu/Components/plugin/ucfontutils.cpp 2015-03-17 09:10:46 +0000 | |||
204 | @@ -1,5 +1,5 @@ | |||
205 | 1 | /* | 1 | /* |
207 | 2 | * Copyright 2013 Canonical Ltd. | 2 | * Copyright 2013-2015 Canonical Ltd. |
208 | 3 | * | 3 | * |
209 | 4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
210 | 5 | * it under the terms of the GNU Lesser General Public License as published by | 5 | * it under the terms of the GNU Lesser General Public License as published by |
211 | @@ -64,7 +64,7 @@ | |||
212 | 64 | */ | 64 | */ |
213 | 65 | qreal UCFontUtils::sizeToPixels(const QString &size) | 65 | qreal UCFontUtils::sizeToPixels(const QString &size) |
214 | 66 | { | 66 | { |
216 | 67 | return modularScale(size) * UCUnits::instance().dp(14); | 67 | return modularScale(size) * UCUnits::instance().dp(fontUnits); |
217 | 68 | } | 68 | } |
218 | 69 | 69 | ||
219 | 70 | /*! | 70 | /*! |
220 | @@ -82,18 +82,17 @@ | |||
221 | 82 | */ | 82 | */ |
222 | 83 | qreal UCFontUtils::modularScale(const QString &size) | 83 | qreal UCFontUtils::modularScale(const QString &size) |
223 | 84 | { | 84 | { |
238 | 85 | if (size == "xx-small") { | 85 | if (size.size() < 4) { |
239 | 86 | return 0.677; | 86 | return 0.0; |
240 | 87 | } else if (size == "x-small") { | 87 | } |
241 | 88 | return 0.804; | 88 | |
242 | 89 | } else if (size == "small") { | 89 | switch (reinterpret_cast<int*>(size.toLatin1().data())[0]) { |
243 | 90 | return 0.931; | 90 | case /*"medi"*/0x6964656d: { return mediumScale; } |
244 | 91 | } else if (size == "medium") { | 91 | case /*"larg"*/0x6772616c: { return largeScale; } |
245 | 92 | return 1.079; | 92 | case /*"smal"*/0x6c616d73: { return smallScale; } |
246 | 93 | } else if (size == "large") { | 93 | case /*"x-la"*/0x616c2d78: { return xLargeScale; } |
247 | 94 | return 1.291; | 94 | case /*"x-sm"*/0x6d732d78: { return xSmallScale; } |
248 | 95 | } else if (size == "x-large") { | 95 | case /*"xx-s"*/0x732d7878: { return xxSmallScale; } |
249 | 96 | return 1.714; | 96 | default: { return 0.0; } |
250 | 97 | } | 97 | } |
237 | 98 | return 0.0; | ||
251 | 99 | } | 98 | } |
252 | 100 | 99 | ||
253 | === modified file 'modules/Ubuntu/Components/plugin/ucfontutils.h' | |||
254 | --- modules/Ubuntu/Components/plugin/ucfontutils.h 2013-05-20 11:38:32 +0000 | |||
255 | +++ modules/Ubuntu/Components/plugin/ucfontutils.h 2015-03-17 09:10:46 +0000 | |||
256 | @@ -12,7 +12,6 @@ | |||
257 | 12 | * | 12 | * |
258 | 13 | * You should have received a copy of the GNU Lesser General Public License | 13 | * You should have received a copy of the GNU Lesser General Public License |
259 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
260 | 15 | * | ||
261 | 16 | */ | 15 | */ |
262 | 17 | 16 | ||
263 | 18 | #ifndef UCFONTUTILS_H | 17 | #ifndef UCFONTUTILS_H |
264 | @@ -23,7 +22,15 @@ | |||
265 | 23 | class UCFontUtils : public QObject | 22 | class UCFontUtils : public QObject |
266 | 24 | { | 23 | { |
267 | 25 | Q_OBJECT | 24 | Q_OBJECT |
268 | 25 | |||
269 | 26 | public: | 26 | public: |
270 | 27 | static const float fontUnits = 14.0f; | ||
271 | 28 | static const float xxSmallScale = 0.677f; | ||
272 | 29 | static const float xSmallScale = 0.804f; | ||
273 | 30 | static const float smallScale = 0.931f; | ||
274 | 31 | static const float mediumScale = 1.079f; | ||
275 | 32 | static const float largeScale = 1.291f; | ||
276 | 33 | static const float xLargeScale = 1.714f; | ||
277 | 27 | 34 | ||
278 | 28 | static UCFontUtils& instance() | 35 | static UCFontUtils& instance() |
279 | 29 | { | 36 | { |
280 | 30 | 37 | ||
281 | === added file 'modules/Ubuntu/Components/plugin/uclabel.cpp' | |||
282 | --- modules/Ubuntu/Components/plugin/uclabel.cpp 1970-01-01 00:00:00 +0000 | |||
283 | +++ modules/Ubuntu/Components/plugin/uclabel.cpp 2015-03-17 09:10:46 +0000 | |||
284 | @@ -0,0 +1,141 @@ | |||
285 | 1 | /* | ||
286 | 2 | * Copyright 2015 Canonical Ltd. | ||
287 | 3 | * | ||
288 | 4 | * This program is free software; you can redistribute it and/or modify | ||
289 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
290 | 6 | * the Free Software Foundation; version 3. | ||
291 | 7 | * | ||
292 | 8 | * This program is distributed in the hope that it will be useful, | ||
293 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
294 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
295 | 11 | * GNU Lesser General Public License for more details. | ||
296 | 12 | * | ||
297 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
298 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
299 | 15 | */ | ||
300 | 16 | |||
301 | 17 | #include "uclabel.h" | ||
302 | 18 | #include "ucfontutils.h" | ||
303 | 19 | #include "ucunits.h" | ||
304 | 20 | |||
305 | 21 | void UCLabel::updatePixelSize() | ||
306 | 22 | { | ||
307 | 23 | const float sizes[] = { | ||
308 | 24 | UCFontUtils::xxSmallScale, UCFontUtils::xSmallScale, UCFontUtils::smallScale, | ||
309 | 25 | UCFontUtils::mediumScale, UCFontUtils::largeScale, UCFontUtils::xLargeScale | ||
310 | 26 | }; | ||
311 | 27 | QFont textFont = font(); | ||
312 | 28 | textFont.setPixelSize( | ||
313 | 29 | qRound(sizes[m_adaptiveSize] * UCUnits::instance().dp(UCFontUtils::fontUnits))); | ||
314 | 30 | setFont(textFont); | ||
315 | 31 | } | ||
316 | 32 | |||
317 | 33 | /*! \qmltype Label | ||
318 | 34 | \instantiates UCLabel | ||
319 | 35 | \inqmlmodule Ubuntu.Components 1.2 | ||
320 | 36 | \ingroup ubuntu | ||
321 | 37 | \brief Extended Text item with Ubuntu styling. | ||
322 | 38 | |||
323 | 39 | Label is an extended Text item with Ubuntu styling. It exposes an additional property that | ||
324 | 40 | provides adaptive resizing based on the measurement unit. | ||
325 | 41 | |||
326 | 42 | Example: | ||
327 | 43 | \qml | ||
328 | 44 | Rectangle { | ||
329 | 45 | color: UbuntuColors.warmGrey | ||
330 | 46 | width: units.gu(30) | ||
331 | 47 | height: units.gu(30) | ||
332 | 48 | |||
333 | 49 | Label { | ||
334 | 50 | anchors.centerIn: parent | ||
335 | 51 | text: "Hello world!" | ||
336 | 52 | adaptiveSize: "large" | ||
337 | 53 | } | ||
338 | 54 | } | ||
339 | 55 | \endqml | ||
340 | 56 | */ | ||
341 | 57 | UCLabel::UCLabel(QQuickItem* parent) | ||
342 | 58 | : QQuickText(parent) | ||
343 | 59 | , m_adaptiveSize(Medium) | ||
344 | 60 | , m_flags(0) | ||
345 | 61 | { | ||
346 | 62 | // FIXME(loicm) Hard-coded selected background text from Ambiance palette. | ||
347 | 63 | setColor(QColor(qRgb(0x5d, 0x5d, 0x5d))); | ||
348 | 64 | updatePixelSize(); | ||
349 | 65 | } | ||
350 | 66 | |||
351 | 67 | /*! \qmlproperty enumeration Label::adaptiveSize | ||
352 | 68 | \since Ubuntu.Components 1.2 | ||
353 | 69 | |||
354 | 70 | This property holds an abstract size that allows adaptive resizing based on the measurement unit | ||
355 | 71 | (see Units). The default value is \c Label.Medium. | ||
356 | 72 | |||
357 | 73 | \note Setting this disables support for the deprecated \l fontSize property. | ||
358 | 74 | |||
359 | 75 | \list | ||
360 | 76 | \li \b Label.XxSmall - extremely small font size | ||
361 | 77 | \li \b Label.XSmall - very small font size | ||
362 | 78 | \li \b Label.Small - small font size | ||
363 | 79 | \li \b Label.Medium - medium font size | ||
364 | 80 | \li \b Label.Large - large font size | ||
365 | 81 | \li \b Label.XLarge - very large font size | ||
366 | 82 | \endlist | ||
367 | 83 | */ | ||
368 | 84 | void UCLabel::setAdaptiveSize(AdaptiveSize adaptiveSize) | ||
369 | 85 | { | ||
370 | 86 | if (!(m_flags & AdaptiveSizeSet)) { | ||
371 | 87 | Q_EMIT fontSizeChanged(); | ||
372 | 88 | m_flags |= AdaptiveSizeSet; | ||
373 | 89 | } | ||
374 | 90 | |||
375 | 91 | if (m_adaptiveSize != adaptiveSize) { | ||
376 | 92 | m_adaptiveSize = adaptiveSize; | ||
377 | 93 | updatePixelSize(); | ||
378 | 94 | Q_EMIT adaptiveSizeChanged(); | ||
379 | 95 | } | ||
380 | 96 | } | ||
381 | 97 | |||
382 | 98 | /*! \qmlproperty string Label::fontSize | ||
383 | 99 | \deprecated | ||
384 | 100 | |||
385 | 101 | This property holds an abstract size represented as a string that allows adaptive resizing based | ||
386 | 102 | on the measurement unit (see Units). The default value is \c "medium". | ||
387 | 103 | |||
388 | 104 | \note Use \l adaptiveSize instead. | ||
389 | 105 | |||
390 | 106 | Here is the list of allowed strings from the smallest to the largest: | ||
391 | 107 | \list | ||
392 | 108 | \li \b "xx-small" - extremely small font size | ||
393 | 109 | \li \b "x-small" - very small font size | ||
394 | 110 | \li \b "small" - small font size | ||
395 | 111 | \li \b "medium" - medium font size | ||
396 | 112 | \li \b "large" - large font size | ||
397 | 113 | \li \b "x-large" - very large font size | ||
398 | 114 | \endlist | ||
399 | 115 | */ | ||
400 | 116 | void UCLabel::setFontSize(const QString& fontSize) | ||
401 | 117 | { | ||
402 | 118 | if (m_flags & AdaptiveSizeSet) { | ||
403 | 119 | return; | ||
404 | 120 | } | ||
405 | 121 | if (fontSize.size() < 4) { | ||
406 | 122 | return; | ||
407 | 123 | } | ||
408 | 124 | |||
409 | 125 | AdaptiveSize adaptiveSize; | ||
410 | 126 | switch (reinterpret_cast<int*>(fontSize.toLatin1().data())[0]) { | ||
411 | 127 | case /*"medi"*/0x6964656d: { adaptiveSize = Medium; break; } | ||
412 | 128 | case /*"larg"*/0x6772616c: { adaptiveSize = Large; break; } | ||
413 | 129 | case /*"smal"*/0x6c616d73: { adaptiveSize = Small; break; } | ||
414 | 130 | case /*"x-la"*/0x616c2d78: { adaptiveSize = XLarge; break; } | ||
415 | 131 | case /*"x-sm"*/0x6d732d78: { adaptiveSize = XSmall; break; } | ||
416 | 132 | case /*"xx-s"*/0x732d7878: { adaptiveSize = XxSmall; break; } | ||
417 | 133 | default: { return; } | ||
418 | 134 | } | ||
419 | 135 | |||
420 | 136 | if (m_adaptiveSize != adaptiveSize) { | ||
421 | 137 | m_adaptiveSize = adaptiveSize; | ||
422 | 138 | updatePixelSize(); | ||
423 | 139 | Q_EMIT fontSizeChanged(); | ||
424 | 140 | } | ||
425 | 141 | } | ||
426 | 0 | 142 | ||
427 | === added file 'modules/Ubuntu/Components/plugin/uclabel.h' | |||
428 | --- modules/Ubuntu/Components/plugin/uclabel.h 1970-01-01 00:00:00 +0000 | |||
429 | +++ modules/Ubuntu/Components/plugin/uclabel.h 2015-03-17 09:10:46 +0000 | |||
430 | @@ -0,0 +1,69 @@ | |||
431 | 1 | /* | ||
432 | 2 | * Copyright 2015 Canonical Ltd. | ||
433 | 3 | * | ||
434 | 4 | * This program is free software; you can redistribute it and/or modify | ||
435 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
436 | 6 | * the Free Software Foundation; version 3. | ||
437 | 7 | * | ||
438 | 8 | * This program is distributed in the hope that it will be useful, | ||
439 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
440 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
441 | 11 | * GNU Lesser General Public License for more details. | ||
442 | 12 | * | ||
443 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
444 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
445 | 15 | */ | ||
446 | 16 | |||
447 | 17 | #ifndef UCLABEL_H | ||
448 | 18 | #define UCLABEL_H | ||
449 | 19 | |||
450 | 20 | #include <private/qquicktext_p.h> | ||
451 | 21 | |||
452 | 22 | class UCLabel : public QQuickText | ||
453 | 23 | { | ||
454 | 24 | Q_OBJECT | ||
455 | 25 | |||
456 | 26 | Q_ENUMS(AdaptiveSize) | ||
457 | 27 | Q_PROPERTY(AdaptiveSize adaptiveSize READ adaptiveSize WRITE setAdaptiveSize | ||
458 | 28 | NOTIFY adaptiveSizeChanged REVISION 1) | ||
459 | 29 | |||
460 | 30 | // Deprecated. | ||
461 | 31 | Q_PROPERTY(QString fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) | ||
462 | 32 | |||
463 | 33 | public: | ||
464 | 34 | UCLabel(QQuickItem* parent=0); | ||
465 | 35 | |||
466 | 36 | enum AdaptiveSize { XxSmall = 0, XSmall = 1, Small = 2, Medium = 3, Large = 4, XLarge = 5 }; | ||
467 | 37 | |||
468 | 38 | AdaptiveSize adaptiveSize() const { return m_adaptiveSize; } | ||
469 | 39 | void setAdaptiveSize(AdaptiveSize adaptiveSize); | ||
470 | 40 | |||
471 | 41 | // Deprecated. | ||
472 | 42 | QString fontSize() const { | ||
473 | 43 | if (m_flags & AdaptiveSizeSet) { return ""; } | ||
474 | 44 | const char* const sizes[] = | ||
475 | 45 | { "xx-small", "x-small", "small", "medium", "large", "x-large" }; | ||
476 | 46 | return QString(sizes[m_adaptiveSize]); | ||
477 | 47 | } | ||
478 | 48 | void setFontSize(const QString& fontSize); | ||
479 | 49 | |||
480 | 50 | Q_SIGNALS: | ||
481 | 51 | Q_REVISION(1) void adaptiveSizeChanged(); | ||
482 | 52 | |||
483 | 53 | // Deprecated. | ||
484 | 54 | void fontSizeChanged(); | ||
485 | 55 | |||
486 | 56 | private: | ||
487 | 57 | void updatePixelSize(); | ||
488 | 58 | |||
489 | 59 | enum { AdaptiveSizeSet = 1 }; | ||
490 | 60 | |||
491 | 61 | AdaptiveSize m_adaptiveSize; | ||
492 | 62 | quint8 m_flags; | ||
493 | 63 | |||
494 | 64 | Q_DISABLE_COPY(UCLabel) | ||
495 | 65 | }; | ||
496 | 66 | |||
497 | 67 | QML_DECLARE_TYPE(UCLabel) | ||
498 | 68 | |||
499 | 69 | #endif // UCLABEL_H | ||
500 | 0 | 70 | ||
501 | === modified file 'modules/Ubuntu/Components/qmldir' | |||
502 | --- modules/Ubuntu/Components/qmldir 2015-03-02 13:39:03 +0000 | |||
503 | +++ modules/Ubuntu/Components/qmldir 2015-03-17 09:10:46 +0000 | |||
504 | @@ -11,7 +11,6 @@ | |||
505 | 11 | Tab 0.1 Tab.qml | 11 | Tab 0.1 Tab.qml |
506 | 12 | TabBar 0.1 TabBar.qml | 12 | TabBar 0.1 TabBar.qml |
507 | 13 | Tabs 0.1 Tabs.qml | 13 | Tabs 0.1 Tabs.qml |
508 | 14 | Label 0.1 Label.qml | ||
509 | 15 | AbstractButton 0.1 AbstractButton.qml | 14 | AbstractButton 0.1 AbstractButton.qml |
510 | 16 | ActivityIndicator 0.1 ActivityIndicator.qml | 15 | ActivityIndicator 0.1 ActivityIndicator.qml |
511 | 17 | ProgressBar 0.1 ProgressBar10.qml | 16 | ProgressBar 0.1 ProgressBar10.qml |
512 | @@ -60,7 +59,6 @@ | |||
513 | 60 | Tab 1.0 Tab.qml | 59 | Tab 1.0 Tab.qml |
514 | 61 | TabBar 1.0 TabBar.qml | 60 | TabBar 1.0 TabBar.qml |
515 | 62 | Tabs 1.0 Tabs.qml | 61 | Tabs 1.0 Tabs.qml |
516 | 63 | Label 1.0 Label.qml | ||
517 | 64 | AbstractButton 1.0 AbstractButton.qml | 62 | AbstractButton 1.0 AbstractButton.qml |
518 | 65 | ActivityIndicator 1.0 ActivityIndicator.qml | 63 | ActivityIndicator 1.0 ActivityIndicator.qml |
519 | 66 | ProgressBar 1.0 ProgressBar10.qml | 64 | ProgressBar 1.0 ProgressBar10.qml |
You cannot hardcode the color. See old Label "color: Theme.palette. selected. backgroundText" binding is broken now, you got to fix that.
Also would be nice to see some performance measurements to see what is the gain.
Comments inline