Merge lp:~zsombi/ubuntu-ui-toolkit/labelThemingFix into lp:ubuntu-ui-toolkit/staging
- labelThemingFix
- Merge into staging
Status: | Merged |
---|---|
Approved by: | Cris Dywan |
Approved revision: | 1894 |
Merged at revision: | 1891 |
Proposed branch: | lp:~zsombi/ubuntu-ui-toolkit/labelThemingFix |
Merge into: | lp:ubuntu-ui-toolkit/staging |
Diff against target: |
578 lines (+238/-101) 7 files modified
src/Ubuntu/Components/plugin/label_p.h (+60/-0) src/Ubuntu/Components/plugin/plugin.pri (+2/-1) src/Ubuntu/Components/plugin/privates/threelabelsslot_p.cpp (+5/-5) src/Ubuntu/Components/plugin/uclabel.cpp (+108/-61) src/Ubuntu/Components/plugin/uclabel.h (+24/-30) tests/unit/tst_components/tst_label13.qml (+5/-2) tests/unit_x11/tst_components/tst_label_extras.qml (+34/-2) |
To merge this branch: | bzr merge lp:~zsombi/ubuntu-ui-toolkit/labelThemingFix |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
ubuntu-sdk-build-bot | continuous-integration | Approve | |
Cris Dywan | Approve | ||
Review via email: mp+288738@code.launchpad.net |
Commit message
Label makes sure the color alteration is known by the theming.
Description of the change
PIMPL added. Font and color properties overloaded.
Performance: no performance change
=======
Before MR:
tst_performance: PASS : tst_Performance
tst_performance: RESULT : tst_Performance
tst_performance: 3.1 msecs per iteration (total: 51, iterations: 16)
After MR:
tst_performance: PASS : tst_Performance
tst_Performance
tst_performance: 3.1 msecs per iteration (total: 51, iterations: 16)
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:1892
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:1892
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:1892
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
FAILED: Continuous integration, rev:1892
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
- 1893. By Zsombor Egri
-
fix tests, remove unrelated test
- 1894. By Zsombor Egri
-
merge staging
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
deb: https:/
SUCCESS: https:/
SUCCESS: https:/
None: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
SUCCESS: https:/
Click here to trigger a rebuild:
https:/
Cris Dywan (kalikiana) wrote : | # |
I took a moment to sort out whether the PIMPL by itself is essential to the fix - and I confirmed this in IRC - it's fair to say it doesn't magically help, but it does make things a whole lot cleaner. The real fix is in the property overrides in setFont2 and setColor2 and being able to set with and without flipping the flag. And that makes sense.
The test also looks sensible.
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote : | # |
PASSED: Continuous integration, rev:1894
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | === added file 'src/Ubuntu/Components/plugin/label_p.h' |
2 | --- src/Ubuntu/Components/plugin/label_p.h 1970-01-01 00:00:00 +0000 |
3 | +++ src/Ubuntu/Components/plugin/label_p.h 2016-03-14 18:57:32 +0000 |
4 | @@ -0,0 +1,60 @@ |
5 | +/* |
6 | + * Copyright 2016 Canonical Ltd. |
7 | + * |
8 | + * This program is free software; you can redistribute it and/or modify |
9 | + * it under the terms of the GNU Lesser General Public License as published by |
10 | + * the Free Software Foundation; version 3. |
11 | + * |
12 | + * This program is distributed in the hope that it will be useful, |
13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | + * GNU Lesser General Public License for more details. |
16 | + * |
17 | + * You should have received a copy of the GNU Lesser General Public License |
18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | + */ |
20 | + |
21 | +#ifndef LABEL_P |
22 | +#define LABEL_P |
23 | + |
24 | +#include "uclabel.h" |
25 | + |
26 | +class UCLabelPrivate |
27 | +{ |
28 | + Q_DECLARE_PUBLIC(UCLabel) |
29 | +public: |
30 | + explicit UCLabelPrivate(UCLabel *qq); |
31 | + UCLabelPrivate(UCLabel *qq, UCLabel::ColorProviderFunc func); |
32 | + |
33 | + static UCLabelPrivate *get(UCLabel *q) |
34 | + { |
35 | + return q->d_func(); |
36 | + } |
37 | + |
38 | + void init(); |
39 | + |
40 | + // slots |
41 | + void updateRenderType(); |
42 | + |
43 | + // methods |
44 | + void updatePixelSize(); |
45 | + |
46 | + // members |
47 | + enum { |
48 | + TextSizeSet = 1, |
49 | + PixelSizeSet = 2, |
50 | + ColorSet = 4 |
51 | + }; |
52 | + |
53 | + UCLabel *q_ptr; |
54 | + QFont defaultFont; |
55 | + UCLabel::ColorProviderFunc defaultColor; |
56 | + UCLabel::TextSize textSize; |
57 | + quint8 flags; |
58 | + |
59 | +protected: |
60 | + static QColor getDefaultColor(QQuickItem *item, UCTheme *theme); |
61 | +}; |
62 | + |
63 | +#endif // LABEL_P |
64 | + |
65 | |
66 | === modified file 'src/Ubuntu/Components/plugin/plugin.pri' |
67 | --- src/Ubuntu/Components/plugin/plugin.pri 2016-02-25 18:22:54 +0000 |
68 | +++ src/Ubuntu/Components/plugin/plugin.pri 2016-03-14 18:57:32 +0000 |
69 | @@ -115,7 +115,8 @@ |
70 | $$PWD/privates/ucpagewrapper.h \ |
71 | $$PWD/privates/ucpagewrapper_p.h \ |
72 | $$PWD/privates/ucpagewrapperincubator_p.h \ |
73 | - $$PWD/privates/appheaderbase.h |
74 | + $$PWD/privates/appheaderbase.h \ |
75 | + $$PWD/label_p.h |
76 | |
77 | SOURCES += $$PWD/plugin.cpp \ |
78 | $$PWD/uctheme.cpp \ |
79 | |
80 | === modified file 'src/Ubuntu/Components/plugin/privates/threelabelsslot_p.cpp' |
81 | --- src/Ubuntu/Components/plugin/privates/threelabelsslot_p.cpp 2016-01-30 10:51:22 +0000 |
82 | +++ src/Ubuntu/Components/plugin/privates/threelabelsslot_p.cpp 2016-03-14 18:57:32 +0000 |
83 | @@ -1,5 +1,5 @@ |
84 | /* |
85 | - * Copyright 2015 Canonical Ltd. |
86 | + * Copyright 2015-2016 Canonical Ltd. |
87 | * |
88 | * This program is free software; you can redistribute it and/or modify |
89 | * it under the terms of the GNU Lesser General Public License as published by |
90 | @@ -15,7 +15,7 @@ |
91 | */ |
92 | |
93 | #include "threelabelsslot_p.h" |
94 | -#include "uclabel.h" |
95 | +#include "label_p.h" |
96 | #include "ucunits.h" |
97 | #include "ucfontutils.h" |
98 | #include "uctheme.h" |
99 | @@ -148,7 +148,7 @@ |
100 | if (d->m_title == Q_NULLPTR) { |
101 | d->m_title = new UCLabel(this); |
102 | QQmlEngine::setContextForObject(d->m_title, qmlContext(this)); |
103 | - d->m_title->init(); |
104 | + UCLabelPrivate::get(d->m_title)->init(); |
105 | |
106 | QQuickAnchors *titleAnchors = QQuickItemPrivate::get(d->m_title)->anchors(); |
107 | titleAnchors->setLeft(d->left()); |
108 | @@ -193,7 +193,7 @@ |
109 | if (d->m_subtitle == Q_NULLPTR) { |
110 | d->m_subtitle = new UCLabel(getSubtitleColor, this); |
111 | QQmlEngine::setContextForObject(d->m_subtitle, qmlContext(this)); |
112 | - d->m_subtitle->init(); |
113 | + UCLabelPrivate::get(d->m_subtitle)->init(); |
114 | |
115 | QQuickAnchors *subtitleAnchors = QQuickItemPrivate::get(d->m_subtitle)->anchors(); |
116 | subtitleAnchors->setLeft(d->left()); |
117 | @@ -223,7 +223,7 @@ |
118 | if (d->m_summary == Q_NULLPTR) { |
119 | d->m_summary = new UCLabel(getSummaryColor, this); |
120 | QQmlEngine::setContextForObject(d->m_summary, qmlContext(this)); |
121 | - d->m_summary->init(); |
122 | + UCLabelPrivate::get(d->m_summary)->init(); |
123 | |
124 | QQuickAnchors *summaryAnchors = QQuickItemPrivate::get(d->m_summary)->anchors(); |
125 | summaryAnchors->setLeft(d->left()); |
126 | |
127 | === modified file 'src/Ubuntu/Components/plugin/uclabel.cpp' |
128 | --- src/Ubuntu/Components/plugin/uclabel.cpp 2016-01-30 10:51:22 +0000 |
129 | +++ src/Ubuntu/Components/plugin/uclabel.cpp 2016-03-14 18:57:32 +0000 |
130 | @@ -14,49 +14,54 @@ |
131 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
132 | */ |
133 | |
134 | -#include "uclabel.h" |
135 | +#include "label_p.h" |
136 | #include "ucfontutils.h" |
137 | #include "ucnamespace.h" |
138 | #include "ucunits.h" |
139 | #include "uctheme.h" |
140 | |
141 | -void UCLabel::updatePixelSize() |
142 | -{ |
143 | - if (m_flags & PixelSizeSet) { |
144 | +UCLabelPrivate::UCLabelPrivate(UCLabel *qq) |
145 | + : q_ptr(qq) |
146 | + , defaultColor(getDefaultColor) |
147 | + , textSize(UCLabel::Medium) |
148 | + , flags(0) |
149 | +{ |
150 | +} |
151 | + |
152 | +UCLabelPrivate::UCLabelPrivate(UCLabel *qq, UCLabel::ColorProviderFunc func) |
153 | + : q_ptr(qq) |
154 | + , defaultColor(func) |
155 | + , textSize(UCLabel::Medium) |
156 | + , flags(0) |
157 | +{ |
158 | +} |
159 | + |
160 | +void UCLabelPrivate::updatePixelSize() |
161 | +{ |
162 | + if (flags & PixelSizeSet) { |
163 | return; |
164 | } |
165 | + |
166 | + Q_Q(UCLabel); |
167 | const float sizes[] = { |
168 | UCFontUtils::xxSmallScale, UCFontUtils::xSmallScale, UCFontUtils::smallScale, |
169 | UCFontUtils::mediumScale, UCFontUtils::largeScale, UCFontUtils::xLargeScale |
170 | }; |
171 | - QFont textFont = font(); |
172 | + QFont textFont = q->font(); |
173 | textFont.setPixelSize( |
174 | - qRound(sizes[m_textSize] * UCUnits::instance()->dp(UCFontUtils::fontUnits))); |
175 | - setFont(textFont); |
176 | - // remove PixelSizeSet flag |
177 | - m_flags &= ~PixelSizeSet; |
178 | + qRound(sizes[textSize] * UCUnits::instance()->dp(UCFontUtils::fontUnits))); |
179 | + q->setFont(textFont); |
180 | } |
181 | |
182 | -void UCLabel::updateRenderType() |
183 | +void UCLabelPrivate::updateRenderType() |
184 | { |
185 | + Q_Q(UCLabel); |
186 | + QQuickText *qtext = static_cast<QQuickText*>(q); |
187 | if (UCUnits::instance()->gridUnit() <= 10) { |
188 | - QQuickText::setRenderType(QQuickText::NativeRendering); |
189 | + qtext->setRenderType(QQuickText::NativeRendering); |
190 | } else { |
191 | - QQuickText::setRenderType(QQuickText::QtRendering); |
192 | - } |
193 | -} |
194 | - |
195 | -void UCLabel::_q_updateFontFlag(const QFont &font) |
196 | -{ |
197 | - Q_UNUSED(font); |
198 | - if (m_defaultFont.pixelSize() != font.pixelSize()) { |
199 | - m_flags |= PixelSizeSet; |
200 | - } |
201 | -} |
202 | - |
203 | -void UCLabel::_q_customColor() |
204 | -{ |
205 | - m_flags |= ColorSet; |
206 | + qtext->setRenderType(QQuickText::QtRendering); |
207 | + } |
208 | } |
209 | |
210 | /*! |
211 | @@ -88,60 +93,64 @@ |
212 | UCLabel::UCLabel(QQuickItem* parent) |
213 | : QQuickText(parent) |
214 | , UCThemingExtension(this) |
215 | - , m_defaultColor(getDefaultColor) |
216 | - , m_textSize(Medium) |
217 | - , m_flags(0) |
218 | + , d_ptr(new UCLabelPrivate(this)) |
219 | { |
220 | } |
221 | |
222 | -UCLabel::UCLabel(std::function<QColor (QQuickItem*, UCTheme*)> defaultColor, QQuickItem *parent) |
223 | +UCLabel::UCLabel(ColorProviderFunc defaultColor, QQuickItem *parent) |
224 | : QQuickText(parent) |
225 | , UCThemingExtension(this) |
226 | - , m_defaultColor(defaultColor) |
227 | - , m_textSize(Medium) |
228 | - , m_flags(0) |
229 | -{ |
230 | + , d_ptr(new UCLabelPrivate(this, defaultColor)) |
231 | +{ |
232 | +} |
233 | +UCLabel::~UCLabel() |
234 | +{ |
235 | + delete d_ptr; |
236 | } |
237 | |
238 | -QColor UCLabel::getDefaultColor(QQuickItem *item, UCTheme *theme) |
239 | +QColor UCLabelPrivate::getDefaultColor(QQuickItem *item, UCTheme *theme) |
240 | { |
241 | // FIXME: replace the code below with automatic color |
242 | - // change detection based on teh item's state |
243 | + // change detection based on the item's state |
244 | const char *valueSet = item->isEnabled() ? "normal" : "disabled"; |
245 | return theme ? theme->getPaletteColor(valueSet, "backgroundText") : QColor(); |
246 | } |
247 | |
248 | void UCLabel::classBegin() |
249 | { |
250 | + Q_D(UCLabel); |
251 | QQuickText::classBegin(); |
252 | - init(); |
253 | + d->init(); |
254 | } |
255 | |
256 | -void UCLabel::init() |
257 | +void UCLabelPrivate::init() |
258 | { |
259 | - postThemeChanged(); |
260 | + Q_Q(UCLabel); |
261 | + q->postThemeChanged(); |
262 | + |
263 | updatePixelSize(); |
264 | - m_defaultFont = font(); |
265 | - m_defaultFont.setFamily("Ubuntu"); |
266 | - m_defaultFont.setWeight(QFont::Light); |
267 | - setFont(m_defaultFont); |
268 | + defaultFont = q->font(); |
269 | + defaultFont.setFamily("Ubuntu"); |
270 | + defaultFont.setWeight(QFont::Light); |
271 | + q->setFont(defaultFont); |
272 | updateRenderType(); |
273 | |
274 | - connect(UCUnits::instance(), &UCUnits::gridUnitChanged, this, &UCLabel::updateRenderType); |
275 | - connect(this, &UCLabel::fontChanged, this, &UCLabel::_q_updateFontFlag, Qt::DirectConnection); |
276 | - connect(this, &UCLabel::colorChanged, this, &UCLabel::_q_customColor, Qt::DirectConnection); |
277 | - connect(this, &UCLabel::enabledChanged, this, &UCLabel::postThemeChanged, Qt::DirectConnection); |
278 | + QObject::connect(UCUnits::instance(), SIGNAL(gridUnitChanged()), q, SLOT(updateRenderType())); |
279 | + QObject::connect(q, &UCLabel::enabledChanged, q, &UCLabel::postThemeChanged, Qt::DirectConnection); |
280 | + |
281 | + QObject::connect(q, &UCLabel::fontChanged, q, &UCLabel::fontChanged2, Qt::DirectConnection); |
282 | + QObject::connect(q, &UCLabel::colorChanged, q, &UCLabel::colorChanged2, Qt::DirectConnection); |
283 | } |
284 | |
285 | void UCLabel::postThemeChanged() |
286 | { |
287 | - if (m_flags & ColorSet) { |
288 | + Q_D(UCLabel); |
289 | + if (d->flags & UCLabelPrivate::ColorSet) { |
290 | return; |
291 | } |
292 | UCTheme *theme = getTheme(); |
293 | if (theme) { |
294 | - setColor(m_defaultColor(this, theme)); |
295 | - m_flags &= ~ColorSet; |
296 | + setColor(d->defaultColor(this, theme)); |
297 | } |
298 | } |
299 | |
300 | @@ -163,24 +172,48 @@ |
301 | * \li \b Label.XLarge - very large font size |
302 | * \endlist |
303 | */ |
304 | +UCLabel::TextSize UCLabel::textSize() const |
305 | +{ |
306 | + Q_D(const UCLabel); |
307 | + return d->textSize; |
308 | +} |
309 | void UCLabel::setTextSize(TextSize size) |
310 | { |
311 | - if (!(m_flags & TextSizeSet)) { |
312 | + Q_D(UCLabel); |
313 | + if (!(d->flags & UCLabelPrivate::TextSizeSet)) { |
314 | Q_EMIT fontSizeChanged(); |
315 | - m_flags |= TextSizeSet; |
316 | + d->flags |= UCLabelPrivate::TextSizeSet; |
317 | } |
318 | |
319 | - if (m_textSize != size) { |
320 | - m_textSize = size; |
321 | - updatePixelSize(); |
322 | + if (d->textSize != size) { |
323 | + d->textSize = size; |
324 | + d->updatePixelSize(); |
325 | Q_EMIT textSizeChanged(); |
326 | } |
327 | } |
328 | |
329 | +void UCLabel::setFont2(const QFont &font) |
330 | +{ |
331 | + Q_D(UCLabel); |
332 | + // we must restrict ourself to the pixelSize change as any font property change will |
333 | + // lead to the setter call. |
334 | + if (d->defaultFont.pixelSize() != font.pixelSize()) { |
335 | + d->flags |= UCLabelPrivate::PixelSizeSet; |
336 | + } |
337 | + QQuickText::setFont(font); |
338 | +} |
339 | + |
340 | +void UCLabel::setColor2(const QColor &color) |
341 | +{ |
342 | + Q_D(UCLabel); |
343 | + d->flags |= UCLabelPrivate::ColorSet; |
344 | + QQuickText::setColor(color); |
345 | +} |
346 | + |
347 | void UCLabel::setRenderType(RenderType renderType) |
348 | { |
349 | - disconnect(UCUnits::instance(), &UCUnits::gridUnitChanged, |
350 | - this, &UCLabel::updateRenderType); |
351 | + disconnect(UCUnits::instance(), SIGNAL(gridUnitChanged()), |
352 | + this, SLOT(updateRenderType())); |
353 | QQuickText::setRenderType(renderType); |
354 | } |
355 | |
356 | @@ -203,9 +236,20 @@ |
357 | * \li \b "x-large" - very large font size |
358 | * \endlist |
359 | */ |
360 | +QString UCLabel::fontSize() const |
361 | +{ |
362 | + Q_D(const UCLabel); |
363 | + if (d->flags & UCLabelPrivate::TextSizeSet) { |
364 | + return ""; |
365 | + } |
366 | + const char* const sizes[] = |
367 | + { "xx-small", "x-small", "small", "medium", "large", "x-large" }; |
368 | + return QString(sizes[d->textSize]); |
369 | +} |
370 | void UCLabel::setFontSize(const QString& fontSize) |
371 | { |
372 | - if (m_flags & TextSizeSet) { |
373 | + Q_D(UCLabel); |
374 | + if (d->flags & UCLabelPrivate::TextSizeSet) { |
375 | return; |
376 | } |
377 | if (fontSize.size() < 4) { |
378 | @@ -225,9 +269,12 @@ |
379 | default: { return; } |
380 | } |
381 | |
382 | - if (m_textSize != textSize) { |
383 | - m_textSize = textSize; |
384 | - updatePixelSize(); |
385 | + if (d->textSize != textSize) { |
386 | + d->textSize = textSize; |
387 | + d->updatePixelSize(); |
388 | Q_EMIT fontSizeChanged(); |
389 | } |
390 | } |
391 | + |
392 | + |
393 | +#include "moc_uclabel.cpp" |
394 | |
395 | === modified file 'src/Ubuntu/Components/plugin/uclabel.h' |
396 | --- src/Ubuntu/Components/plugin/uclabel.h 2016-01-28 11:26:21 +0000 |
397 | +++ src/Ubuntu/Components/plugin/uclabel.h 2016-03-14 18:57:32 +0000 |
398 | @@ -1,5 +1,5 @@ |
399 | /* |
400 | - * Copyright 2015 Canonical Ltd. |
401 | + * Copyright 2016 Canonical Ltd. |
402 | * |
403 | * This program is free software; you can redistribute it and/or modify |
404 | * it under the terms of the GNU Lesser General Public License as published by |
405 | @@ -22,25 +22,30 @@ |
406 | // C++ std lib for std::function declaration |
407 | #include <functional> |
408 | |
409 | +class UCLabelPrivate; |
410 | class UCLabel : public QQuickText, public UCThemingExtension |
411 | { |
412 | Q_OBJECT |
413 | Q_INTERFACES(UCThemingExtension) |
414 | Q_ENUMS(TextSize) |
415 | - Q_PROPERTY(TextSize textSize MEMBER m_textSize WRITE setTextSize NOTIFY textSizeChanged FINAL) |
416 | + Q_PROPERTY(TextSize textSize READ textSize WRITE setTextSize NOTIFY textSizeChanged FINAL) |
417 | |
418 | // Overriden from QQuickText |
419 | Q_PROPERTY(RenderType renderType READ renderType WRITE setRenderType) |
420 | + Q_PROPERTY(QFont font READ font WRITE setFont2 NOTIFY fontChanged2) |
421 | + Q_PROPERTY(QColor color READ color WRITE setColor2 NOTIFY colorChanged2) |
422 | |
423 | // Deprecated. |
424 | Q_PROPERTY(QString fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) |
425 | |
426 | public: |
427 | + |
428 | + typedef std::function<QColor (QQuickItem*, UCTheme*)> ColorProviderFunc; |
429 | + |
430 | UCLabel(QQuickItem* parent=0); |
431 | // custom constructor to create the label with a different default color provider |
432 | - UCLabel(std::function<QColor (QQuickItem*, UCTheme*)> defaultColor, QQuickItem *parent = 0); |
433 | - //QQuickTextPrivate is not exported as of 5.4.1 so we need the init here |
434 | - void init(); |
435 | + UCLabel(ColorProviderFunc defaultColor, QQuickItem *parent = 0); |
436 | + ~UCLabel(); |
437 | |
438 | enum TextSize { |
439 | XxSmall = 0, |
440 | @@ -51,19 +56,16 @@ |
441 | XLarge = 5 |
442 | }; |
443 | |
444 | + TextSize textSize() const; |
445 | void setTextSize(TextSize size); |
446 | + |
447 | + // overriden from QQuickText |
448 | + void setFont2(const QFont &font); |
449 | + void setColor2(const QColor &color); |
450 | void setRenderType(RenderType renderType); |
451 | |
452 | // Deprecated. |
453 | - QString fontSize() const |
454 | - { |
455 | - if (m_flags & TextSizeSet) { |
456 | - return ""; |
457 | - } |
458 | - const char* const sizes[] = |
459 | - { "xx-small", "x-small", "small", "medium", "large", "x-large" }; |
460 | - return QString(sizes[m_textSize]); |
461 | - } |
462 | + QString fontSize() const; |
463 | void setFontSize(const QString& fontSize); |
464 | |
465 | protected: |
466 | @@ -77,26 +79,18 @@ |
467 | Q_SIGNALS: |
468 | void textSizeChanged(); |
469 | |
470 | + // overrides |
471 | + void fontChanged2(); |
472 | + void colorChanged2(); |
473 | + |
474 | // Deprecated. |
475 | void fontSizeChanged(); |
476 | |
477 | private: |
478 | - void updatePixelSize(); |
479 | - static QColor getDefaultColor(QQuickItem *item, UCTheme *theme); |
480 | - Q_SLOT void updateRenderType(); |
481 | - Q_SLOT void _q_updateFontFlag(const QFont &font); |
482 | - Q_SLOT void _q_customColor(); |
483 | - |
484 | - enum { |
485 | - TextSizeSet = 1, |
486 | - PixelSizeSet = 2, |
487 | - ColorSet = 4 |
488 | - }; |
489 | - |
490 | - QFont m_defaultFont; |
491 | - std::function<QColor (QQuickItem *, UCTheme*)> m_defaultColor; |
492 | - TextSize m_textSize; |
493 | - quint8 m_flags; |
494 | + Q_PRIVATE_SLOT(d_func(), void updateRenderType()) |
495 | + |
496 | + UCLabelPrivate *d_ptr; |
497 | + Q_DECLARE_PRIVATE(UCLabel) |
498 | |
499 | Q_DISABLE_COPY(UCLabel) |
500 | }; |
501 | |
502 | === modified file 'tests/unit/tst_components/tst_label13.qml' |
503 | --- tests/unit/tst_components/tst_label13.qml 2016-01-26 14:46:00 +0000 |
504 | +++ tests/unit/tst_components/tst_label13.qml 2016-03-14 18:57:32 +0000 |
505 | @@ -81,8 +81,8 @@ |
506 | ]; |
507 | } |
508 | function test_fontSize_equals_textSize(data) { |
509 | - textCustom.textSize = data.size; |
510 | - fuzzyCompare(textCustom.font.pixelSize, FontUtils.sizeToPixels(data.tag), 0.999, "pixelSize differs for " + data.tag); |
511 | + textFontSize.textSize = data.size; |
512 | + fuzzyCompare(textFontSize.font.pixelSize, FontUtils.sizeToPixels(data.tag), 0.999, "pixelSize differs for " + data.tag); |
513 | } |
514 | |
515 | function test_fontWeight_data() { |
516 | @@ -161,6 +161,9 @@ |
517 | Label { |
518 | id: textCustom |
519 | } |
520 | + Label { |
521 | + id: textFontSize |
522 | + } |
523 | |
524 | Label { |
525 | id: lightLabel |
526 | |
527 | === modified file 'tests/unit_x11/tst_components/tst_label_extras.qml' |
528 | --- tests/unit_x11/tst_components/tst_label_extras.qml 2015-10-08 10:48:10 +0000 |
529 | +++ tests/unit_x11/tst_components/tst_label_extras.qml 2016-03-14 18:57:32 +0000 |
530 | @@ -36,14 +36,46 @@ |
531 | } |
532 | } |
533 | |
534 | + Component { |
535 | + id: testLabel |
536 | + Label { |
537 | + text: "Hello Dolly!" |
538 | + } |
539 | + } |
540 | + |
541 | + Loader { |
542 | + id: testLoader |
543 | + } |
544 | + |
545 | UbuntuTestCase { |
546 | name: "Label13Extras" |
547 | when: windowShown |
548 | |
549 | + function loadTest(component) { |
550 | + testLoader.sourceComponent = component; |
551 | + tryCompare(testLoader, "status", Loader.Ready, 1000); |
552 | + verify(testLoader.item); |
553 | + return testLoader.item; |
554 | + } |
555 | + |
556 | + function cleanup() { |
557 | + testLoader.sourceComponent = null; |
558 | + waitForRendering(main, 400); |
559 | + } |
560 | + |
561 | function test_label_with_button_bug1503901() { |
562 | // this should SEGFAULT on error! |
563 | - var test = labelWithButton.createObject(main); |
564 | - test.destroy(); |
565 | + loadTest(labelWithButton); |
566 | + } |
567 | + |
568 | + function test_label_color_changes_even_with_same_value_as_default_bug1555784() { |
569 | + var test = loadTest(testLabel); |
570 | + |
571 | + // override the text color with the same as the default |
572 | + test.color = theme.palette.normal.backgroundText; |
573 | + // change the color of the palette |
574 | + theme.palette.normal.backgroundText = UbuntuColors.blue; |
575 | + verify(test.color != theme.palette.normal.backgroundText); |
576 | } |
577 | } |
578 | } |
FAILED: Continuous integration, rev:1892 /jenkins. ubuntu. com/ubuntu- sdk/job/ ubuntu- ui-toolkit- ci-armhf- stable/ 475/ /jenkins. ubuntu. com/ubuntu- sdk/job/ generic- update- mp/1624/ console
https:/
Executed test runs:
None: https:/
Click here to trigger a rebuild: /jenkins. ubuntu. com/ubuntu- sdk/job/ ubuntu- ui-toolkit- ci-armhf- stable/ 475/rebuild
https:/