Merge lp:~zsombi/ubuntu-ui-toolkit/theming-attached into lp:ubuntu-ui-toolkit/staging
- theming-attached
- Merge into staging
Status: | Rejected |
---|---|
Rejected by: | Cris Dywan |
Proposed branch: | lp:~zsombi/ubuntu-ui-toolkit/theming-attached |
Merge into: | lp:ubuntu-ui-toolkit/staging |
Diff against target: |
777 lines (+379/-209) 9 files modified
components.api (+2/-1) src/Ubuntu/Components/plugin/plugin.cpp (+2/-1) src/Ubuntu/Components/plugin/plugin.pri (+4/-2) src/Ubuntu/Components/plugin/ucstyleditembase.cpp (+21/-184) src/Ubuntu/Components/plugin/ucstyleditembase.h (+1/-3) src/Ubuntu/Components/plugin/ucstyleditembase_p.h (+7/-14) src/Ubuntu/Components/plugin/uctheme.cpp (+4/-4) src/Ubuntu/Components/plugin/ucthemingattached.cpp (+257/-0) src/Ubuntu/Components/plugin/ucthemingattached.h (+81/-0) |
To merge this branch: | bzr merge lp:~zsombi/ubuntu-ui-toolkit/theming-attached |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Needs Fixing | |
Cris Dywan | Approve | ||
Review via email: mp+266317@code.launchpad.net |
Commit message
Detaching theming management from StyledItem to be reused in other cpp types.
Description of the change
Zsombor Egri (zsombi) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1583
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1584. By Zsombor Egri
-
segfault fixed
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1584
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
Cris Dywan (kalikiana) wrote : | # |
As discussed, there is no effective change in functionality in StyledItemBase so it's already covered by unit tests. We won't really know if it exposes the theming correctly until we have the first real word user of it, which is going to be the Label in C++ which can't currently inherit from StyledItemBase, so this should be the prerequisite branch.
- 1585. By Zsombor Egri
-
staging sync
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1585
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
- 1586. By Zsombor Egri
-
simplifying the use of theming
- 1587. By Zsombor Egri
-
staging sync
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1587
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
Unmerged revisions
- 1587. By Zsombor Egri
-
staging sync
- 1586. By Zsombor Egri
-
simplifying the use of theming
- 1585. By Zsombor Egri
-
staging sync
- 1584. By Zsombor Egri
-
segfault fixed
- 1583. By Zsombor Egri
-
renaming styling to theming
- 1582. By Zsombor Egri
-
API file fixed
- 1581. By Zsombor Egri
-
staging merge
- 1580. By Zsombor Egri
-
separation completed
- 1579. By Zsombor Egri
-
staging sync
Preview Diff
1 | === modified file 'components.api' | |||
2 | --- components.api 2015-08-04 20:07:41 +0000 | |||
3 | +++ components.api 2015-08-06 18:06:52 +0000 | |||
4 | @@ -878,7 +878,7 @@ | |||
5 | 878 | Ubuntu.Components.StateSaver 1.0 0.1: QtObject | 878 | Ubuntu.Components.StateSaver 1.0 0.1: QtObject |
6 | 879 | Ubuntu.Components.StyleHints 1.3: QtObject | 879 | Ubuntu.Components.StyleHints 1.3: QtObject |
7 | 880 | property bool ignoreUnknownProperties | 880 | property bool ignoreUnknownProperties |
9 | 881 | Ubuntu.Components.StyledItem 1.3 1.3 1.1 1.0 0.1: Item | 881 | Ubuntu.Components.StyledItem 1.3 1.1 1.0 0.1: Item |
10 | 882 | property bool activeFocusOnPress 1.3 | 882 | property bool activeFocusOnPress 1.3 |
11 | 883 | function bool requestFocus(Qt.FocusReason reason) 1.3 | 883 | function bool requestFocus(Qt.FocusReason reason) 1.3 |
12 | 884 | function bool requestFocus() 1.3 | 884 | function bool requestFocus() 1.3 |
13 | @@ -1238,6 +1238,7 @@ | |||
14 | 1238 | UCStateSaverAttached: QtObject | 1238 | UCStateSaverAttached: QtObject |
15 | 1239 | property bool enabled | 1239 | property bool enabled |
16 | 1240 | property string properties | 1240 | property string properties |
17 | 1241 | UCThemingAttached: QtObject | ||
18 | 1241 | Ubuntu.Components.UCUnits 1.0 0.1: QtObject | 1242 | Ubuntu.Components.UCUnits 1.0 0.1: QtObject |
19 | 1242 | property float gridUnit | 1243 | property float gridUnit |
20 | 1243 | function float dp(float value) | 1244 | function float dp(float value) |
21 | 1244 | 1245 | ||
22 | === modified file 'src/Ubuntu/Components/plugin/plugin.cpp' | |||
23 | --- src/Ubuntu/Components/plugin/plugin.cpp 2015-07-23 11:49:38 +0000 | |||
24 | +++ src/Ubuntu/Components/plugin/plugin.cpp 2015-08-06 18:06:52 +0000 | |||
25 | @@ -22,6 +22,7 @@ | |||
26 | 22 | 22 | ||
27 | 23 | #include "plugin.h" | 23 | #include "plugin.h" |
28 | 24 | #include "uctheme.h" | 24 | #include "uctheme.h" |
29 | 25 | #include "ucthemingattached.h" | ||
30 | 25 | #include "ucdeprecatedtheme.h" | 26 | #include "ucdeprecatedtheme.h" |
31 | 26 | 27 | ||
32 | 27 | #include <QtQml/QQmlContext> | 28 | #include <QtQml/QQmlContext> |
33 | @@ -208,11 +209,11 @@ | |||
34 | 208 | qmlRegisterType<UCUbuntuShapeOverlay>(uri, 1, 2, "UbuntuShapeOverlay"); | 209 | qmlRegisterType<UCUbuntuShapeOverlay>(uri, 1, 2, "UbuntuShapeOverlay"); |
35 | 209 | 210 | ||
36 | 210 | // register 1.3 API | 211 | // register 1.3 API |
37 | 212 | qmlRegisterType<UCThemingAttached>(); | ||
38 | 211 | qmlRegisterType<UCListItem13>(uri, 1, 3, "ListItem"); | 213 | qmlRegisterType<UCListItem13>(uri, 1, 3, "ListItem"); |
39 | 212 | qmlRegisterType<UCTheme>(uri, 1, 3, "ThemeSettings"); | 214 | qmlRegisterType<UCTheme>(uri, 1, 3, "ThemeSettings"); |
40 | 213 | qmlRegisterType<UCStyledItemBase, 2>(uri, 1, 3, "StyledItem"); | 215 | qmlRegisterType<UCStyledItemBase, 2>(uri, 1, 3, "StyledItem"); |
41 | 214 | qmlRegisterSingletonType<UCNamespaceV13>(uri, 1, 3, "Ubuntu", registerUbuntuNamespace13); | 216 | qmlRegisterSingletonType<UCNamespaceV13>(uri, 1, 3, "Ubuntu", registerUbuntuNamespace13); |
42 | 215 | qmlRegisterType<UCStyledItemBase, 2>(uri, 1, 3, "StyledItem"); | ||
43 | 216 | qmlRegisterCustomType<UCStyleHints>(uri, 1, 3, "StyleHints", new UCStyleHintsParser); | 217 | qmlRegisterCustomType<UCStyleHints>(uri, 1, 3, "StyleHints", new UCStyleHintsParser); |
44 | 217 | qmlRegisterType<UCAction, 1>(uri, 1, 3, "Action"); | 218 | qmlRegisterType<UCAction, 1>(uri, 1, 3, "Action"); |
45 | 218 | qmlRegisterType<UCUbuntuShape, 2>(uri, 1, 3, "UbuntuShape"); | 219 | qmlRegisterType<UCUbuntuShape, 2>(uri, 1, 3, "UbuntuShape"); |
46 | 219 | 220 | ||
47 | === modified file 'src/Ubuntu/Components/plugin/plugin.pri' | |||
48 | --- src/Ubuntu/Components/plugin/plugin.pri 2015-07-30 09:57:45 +0000 | |||
49 | +++ src/Ubuntu/Components/plugin/plugin.pri 2015-08-06 18:06:52 +0000 | |||
50 | @@ -76,7 +76,8 @@ | |||
51 | 76 | $$PWD/ucnamespace.h \ | 76 | $$PWD/ucnamespace.h \ |
52 | 77 | $$PWD/ucdeprecatedtheme.h \ | 77 | $$PWD/ucdeprecatedtheme.h \ |
53 | 78 | $$PWD/ucdefaulttheme.h \ | 78 | $$PWD/ucdefaulttheme.h \ |
55 | 79 | $$PWD/ucstylehints.h | 79 | $$PWD/ucstylehints.h \ |
56 | 80 | $$PWD/ucthemingattached.h | ||
57 | 80 | 81 | ||
58 | 81 | SOURCES += $$PWD/plugin.cpp \ | 82 | SOURCES += $$PWD/plugin.cpp \ |
59 | 82 | $$PWD/uctheme.cpp \ | 83 | $$PWD/uctheme.cpp \ |
60 | @@ -125,7 +126,8 @@ | |||
61 | 125 | $$PWD/ucnamespace.cpp \ | 126 | $$PWD/ucnamespace.cpp \ |
62 | 126 | $$PWD/ucdeprecatedtheme.cpp \ | 127 | $$PWD/ucdeprecatedtheme.cpp \ |
63 | 127 | $$PWD/ucdefaulttheme.cpp \ | 128 | $$PWD/ucdefaulttheme.cpp \ |
65 | 128 | $$PWD/ucstylehints.cpp | 129 | $$PWD/ucstylehints.cpp \ |
66 | 130 | $$PWD/ucthemingattached.cpp | ||
67 | 129 | 131 | ||
68 | 130 | # adapters | 132 | # adapters |
69 | 131 | SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp | 133 | SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp |
70 | 132 | 134 | ||
71 | === modified file 'src/Ubuntu/Components/plugin/ucstyleditembase.cpp' | |||
72 | --- src/Ubuntu/Components/plugin/ucstyleditembase.cpp 2015-07-29 11:41:16 +0000 | |||
73 | +++ src/Ubuntu/Components/plugin/ucstyleditembase.cpp 2015-08-06 18:06:52 +0000 | |||
74 | @@ -18,18 +18,16 @@ | |||
75 | 18 | 18 | ||
76 | 19 | #include "ucstyleditembase.h" | 19 | #include "ucstyleditembase.h" |
77 | 20 | #include "ucstyleditembase_p.h" | 20 | #include "ucstyleditembase_p.h" |
78 | 21 | #include "ucthemingattached.h" | ||
79 | 21 | #include "uctheme.h" | 22 | #include "uctheme.h" |
80 | 22 | #include "ucstylehints.h" | 23 | #include "ucstylehints.h" |
81 | 23 | #include <QtQml/QQmlEngine> | 24 | #include <QtQml/QQmlEngine> |
82 | 24 | #include <QtQuick/private/qquickanchors_p.h> | 25 | #include <QtQuick/private/qquickanchors_p.h> |
83 | 25 | 26 | ||
84 | 26 | UCStyledItemBasePrivate::UCStyledItemBasePrivate() | 27 | UCStyledItemBasePrivate::UCStyledItemBasePrivate() |
88 | 27 | : activeFocusOnPress(false) | 28 | : styleComponent(0) |
86 | 28 | , styleComponent(0) | ||
87 | 29 | , styleItemContext(0) | ||
89 | 30 | , styleItem(0) | 29 | , styleItem(0) |
92 | 31 | , theme(0) | 30 | , activeFocusOnPress(false) |
91 | 32 | , parentStyledItem(0) | ||
93 | 33 | { | 31 | { |
94 | 34 | } | 32 | } |
95 | 35 | 33 | ||
96 | @@ -41,10 +39,6 @@ | |||
97 | 41 | { | 39 | { |
98 | 42 | Q_Q(UCStyledItemBase); | 40 | Q_Q(UCStyledItemBase); |
99 | 43 | q->setFlag(QQuickItem::ItemIsFocusScope); | 41 | q->setFlag(QQuickItem::ItemIsFocusScope); |
100 | 44 | QObject::connect(&UCTheme::defaultTheme(), SIGNAL(nameChanged()), | ||
101 | 45 | q, SLOT(_q_reloadStyle())); | ||
102 | 46 | QObject::connect(&UCTheme::defaultTheme(), SIGNAL(versionChanged()), | ||
103 | 47 | q, SLOT(_q_reloadStyle())); | ||
104 | 48 | } | 42 | } |
105 | 49 | 43 | ||
106 | 50 | 44 | ||
107 | @@ -455,75 +449,14 @@ | |||
108 | 455 | */ | 449 | */ |
109 | 456 | UCTheme *UCStyledItemBasePrivate::getTheme() const | 450 | UCTheme *UCStyledItemBasePrivate::getTheme() const |
110 | 457 | { | 451 | { |
117 | 458 | if (theme) { | 452 | return theming ? theming->getTheme() : &UCTheme::defaultTheme(); |
112 | 459 | return theme; | ||
113 | 460 | } else if (!parentStyledItem.isNull()) { | ||
114 | 461 | return UCStyledItemBasePrivate::get(parentStyledItem)->getTheme(); | ||
115 | 462 | } | ||
116 | 463 | return &UCTheme::defaultTheme(); | ||
118 | 464 | } | 453 | } |
119 | 465 | void UCStyledItemBasePrivate::setTheme(UCTheme *newTheme) | 454 | void UCStyledItemBasePrivate::setTheme(UCTheme *newTheme) |
120 | 466 | { | 455 | { |
123 | 467 | Q_Q(UCStyledItemBase); | 456 | if (theming && !theming->setTheme(newTheme)) { |
122 | 468 | if (theme == newTheme) { | ||
124 | 469 | return; | 457 | return; |
125 | 470 | } | 458 | } |
126 | 471 | 459 | ||
127 | 472 | // preform pre-theme change tasks | ||
128 | 473 | preThemeChanged(); | ||
129 | 474 | |||
130 | 475 | // disconnect from the previous set | ||
131 | 476 | UCTheme *connectedSet = theme ? | ||
132 | 477 | theme : | ||
133 | 478 | (!parentStyledItem ? &UCTheme::defaultTheme() : NULL); | ||
134 | 479 | if (connectedSet) { | ||
135 | 480 | QObject::disconnect(connectedSet, SIGNAL(nameChanged()), | ||
136 | 481 | q, SLOT(_q_reloadStyle())); | ||
137 | 482 | QObject::disconnect(connectedSet, SIGNAL(versionChanged()), | ||
138 | 483 | q, SLOT(_q_reloadStyle())); | ||
139 | 484 | } | ||
140 | 485 | |||
141 | 486 | UCTheme *prevSet = theme; | ||
142 | 487 | |||
143 | 488 | // resolve new theme | ||
144 | 489 | if (theme && newTheme) { | ||
145 | 490 | // no need to redo the parentStack, simply set the theme and leave | ||
146 | 491 | theme = newTheme; | ||
147 | 492 | } else { | ||
148 | 493 | theme = newTheme; | ||
149 | 494 | if (!newTheme) { | ||
150 | 495 | // redo the parent chanin | ||
151 | 496 | disconnectTillItem(0); | ||
152 | 497 | connectParents(0); | ||
153 | 498 | } | ||
154 | 499 | } | ||
155 | 500 | |||
156 | 501 | // connect to the new set | ||
157 | 502 | connectedSet = theme ? | ||
158 | 503 | theme : | ||
159 | 504 | (!parentStyledItem ? &UCTheme::defaultTheme() : NULL); | ||
160 | 505 | if (connectedSet) { | ||
161 | 506 | QObject::connect(connectedSet, SIGNAL(nameChanged()), | ||
162 | 507 | q, SLOT(_q_reloadStyle())); | ||
163 | 508 | QObject::connect(connectedSet, SIGNAL(versionChanged()), | ||
164 | 509 | q, SLOT(_q_reloadStyle())); | ||
165 | 510 | } | ||
166 | 511 | // detach previous set and attach the new one | ||
167 | 512 | if (prevSet) { | ||
168 | 513 | Q_EMIT prevSet->parentThemeChanged(); | ||
169 | 514 | } | ||
170 | 515 | if (theme) { | ||
171 | 516 | // re-parent theme to make sure we have it | ||
172 | 517 | // for the entire lifetime of the styled item | ||
173 | 518 | theme->setParent(q); | ||
174 | 519 | Q_EMIT theme->parentThemeChanged(); | ||
175 | 520 | } | ||
176 | 521 | |||
177 | 522 | // perform post-theme changes, update internal styling | ||
178 | 523 | postThemeChanged(); | ||
179 | 524 | |||
180 | 525 | Q_EMIT q->themeChanged(); | ||
181 | 526 | |||
182 | 527 | // perform style reload | 460 | // perform style reload |
183 | 528 | if (!styleComponent) { | 461 | if (!styleComponent) { |
184 | 529 | preStyleChanged(); | 462 | preStyleChanged(); |
185 | @@ -533,102 +466,22 @@ | |||
186 | 533 | } | 466 | } |
187 | 534 | void UCStyledItemBasePrivate::resetTheme() | 467 | void UCStyledItemBasePrivate::resetTheme() |
188 | 535 | { | 468 | { |
285 | 536 | setTheme(NULL); | 469 | theming->setTheme(Q_NULLPTR); |
286 | 537 | } | 470 | } |
287 | 538 | 471 | ||
288 | 539 | // link/unlink all ascendant items until we reach a StyledItem, returns true if the | 472 | |
289 | 540 | // theme change signal emission is justified | 473 | void UCStyledItemBase::classBegin() |
290 | 541 | bool UCStyledItemBasePrivate::connectParents(QQuickItem *fromItem) | 474 | { |
291 | 542 | { | 475 | QQuickItem::classBegin(); |
292 | 543 | Q_Q(UCStyledItemBase); | 476 | |
293 | 544 | QQuickItem *item = fromItem ? fromItem : parentItem; | 477 | Q_D(UCStyledItemBase); |
294 | 545 | while (item) { | 478 | // attach theming |
295 | 546 | // push the item onto the stack | 479 | d->theming = UCThemingAttached::attachTheming(this); |
296 | 547 | parentStack.push(QPointer<QQuickItem>(item)); | 480 | if (d->theming) { |
297 | 548 | UCStyledItemBase *styledItem = qobject_cast<UCStyledItemBase*>(item); | 481 | d->theming->setListener(d); |
298 | 549 | if (styledItem) { | 482 | connect(d->theming.data(), SIGNAL(themeChanged()), |
299 | 550 | // this is the closest StyledItem, connect its themeChanged() signal | 483 | this, SLOT(_q_reloadStyle())); |
300 | 551 | QObject::connect(styledItem, SIGNAL(themeChanged()), | 484 | } |
205 | 552 | q, SLOT(_q_parentStyleChanged()), Qt::DirectConnection); | ||
206 | 553 | // set the current style set to the one in the parent's one if differs | ||
207 | 554 | return setParentStyled(styledItem); | ||
208 | 555 | } else { | ||
209 | 556 | // connect to the item's parentChanged() signal so we can detect when the parent changes | ||
210 | 557 | QObject::connect(item, SIGNAL(parentChanged(QQuickItem*)), | ||
211 | 558 | q, SLOT(_q_ascendantChanged(QQuickItem*)), Qt::DirectConnection); | ||
212 | 559 | } | ||
213 | 560 | item = item->parentItem(); | ||
214 | 561 | } | ||
215 | 562 | return false; | ||
216 | 563 | } | ||
217 | 564 | |||
218 | 565 | // set the used parent styled item's style; returns true if the parent styled got changed | ||
219 | 566 | bool UCStyledItemBasePrivate::setParentStyled(UCStyledItemBase *styledItem) | ||
220 | 567 | { | ||
221 | 568 | if (parentStyledItem == styledItem) { | ||
222 | 569 | return false; | ||
223 | 570 | } | ||
224 | 571 | parentStyledItem = styledItem; | ||
225 | 572 | if (theme) { | ||
226 | 573 | Q_EMIT theme->parentThemeChanged(); | ||
227 | 574 | } | ||
228 | 575 | return (theme == NULL); | ||
229 | 576 | } | ||
230 | 577 | |||
231 | 578 | // disconnect parent stack till item is reached; all the stack if item == 0 | ||
232 | 579 | void UCStyledItemBasePrivate::disconnectTillItem(QQuickItem *item) | ||
233 | 580 | { | ||
234 | 581 | Q_Q(UCStyledItemBase); | ||
235 | 582 | while (!parentStack.isEmpty() && item != parentStack.top()) { | ||
236 | 583 | QPointer<QQuickItem> stackItem = parentStack.pop(); | ||
237 | 584 | // the topmost item can be the only one which is a StyledItem | ||
238 | 585 | UCStyledItemBase *styledItem = qobject_cast<UCStyledItemBase*>(stackItem.data()); | ||
239 | 586 | if (styledItem) { | ||
240 | 587 | QObject::disconnect(styledItem, SIGNAL(themeChanged()), | ||
241 | 588 | q, SLOT(_q_parentStyleChanged())); | ||
242 | 589 | } else if (!stackItem.isNull()) { | ||
243 | 590 | QObject::disconnect(stackItem.data(), SIGNAL(parentChanged(QQuickItem*)), | ||
244 | 591 | q, SLOT(_q_ascendantChanged(QQuickItem*))); | ||
245 | 592 | } | ||
246 | 593 | } | ||
247 | 594 | } | ||
248 | 595 | |||
249 | 596 | // captures ascendant change signal, the sender is the one which counts! | ||
250 | 597 | void UCStyledItemBasePrivate::_q_ascendantChanged(QQuickItem *ascendant) | ||
251 | 598 | { | ||
252 | 599 | Q_Q(UCStyledItemBase); | ||
253 | 600 | QQuickItem *sender = static_cast<QQuickItem*>(q->sender()); | ||
254 | 601 | if (!sender) { | ||
255 | 602 | // cannot detect the sender, leave! | ||
256 | 603 | return; | ||
257 | 604 | } | ||
258 | 605 | if (ascendant) { | ||
259 | 606 | // disconnect from the previous ones | ||
260 | 607 | disconnectTillItem(sender); | ||
261 | 608 | parentStyledItem.clear(); | ||
262 | 609 | // traverse ascendants till we reach a StyledItem or root and push them into the stack | ||
263 | 610 | if (connectParents(ascendant)) { | ||
264 | 611 | Q_EMIT q->themeChanged(); | ||
265 | 612 | } | ||
266 | 613 | } | ||
267 | 614 | } | ||
268 | 615 | |||
269 | 616 | // syncs the ascendant StyledItem's style | ||
270 | 617 | void UCStyledItemBasePrivate::_q_parentStyleChanged() | ||
271 | 618 | { | ||
272 | 619 | // do not trigger themeChanged() on this item if we have a | ||
273 | 620 | // custom one, but resolve its eventual parent change! | ||
274 | 621 | if (theme) { | ||
275 | 622 | Q_EMIT theme->parentThemeChanged(); | ||
276 | 623 | return; | ||
277 | 624 | } | ||
278 | 625 | Q_Q(UCStyledItemBase); | ||
279 | 626 | UCStyledItemBase *styledItem = static_cast<UCStyledItemBase*>(q->sender()); | ||
280 | 627 | if (!styledItem) { | ||
281 | 628 | return; | ||
282 | 629 | } | ||
283 | 630 | setParentStyled(styledItem); | ||
284 | 631 | Q_EMIT q->themeChanged(); | ||
301 | 632 | } | 485 | } |
302 | 633 | 486 | ||
303 | 634 | void UCStyledItemBase::componentComplete() | 487 | void UCStyledItemBase::componentComplete() |
304 | @@ -667,20 +520,4 @@ | |||
305 | 667 | return QQuickItem::childMouseEventFilter(child, event); | 520 | return QQuickItem::childMouseEventFilter(child, event); |
306 | 668 | } | 521 | } |
307 | 669 | 522 | ||
308 | 670 | // catch parent change event so we can lookup for the parent chain theme | ||
309 | 671 | void UCStyledItemBase::itemChange(ItemChange change, const ItemChangeData &data) | ||
310 | 672 | { | ||
311 | 673 | QQuickItem::itemChange(change, data); | ||
312 | 674 | if (change == ItemParentHasChanged) { | ||
313 | 675 | Q_D(UCStyledItemBase); | ||
314 | 676 | // clean stack | ||
315 | 677 | d->disconnectTillItem(0); | ||
316 | 678 | // make sure we reset parent StyledItem | ||
317 | 679 | d->parentStyledItem.clear(); | ||
318 | 680 | // build the stack - if possible | ||
319 | 681 | d->connectParents(0); | ||
320 | 682 | Q_EMIT themeChanged(); | ||
321 | 683 | } | ||
322 | 684 | } | ||
323 | 685 | |||
324 | 686 | #include "moc_ucstyleditembase.cpp" | 523 | #include "moc_ucstyleditembase.cpp" |
325 | 687 | 524 | ||
326 | === modified file 'src/Ubuntu/Components/plugin/ucstyleditembase.h' | |||
327 | --- src/Ubuntu/Components/plugin/ucstyleditembase.h 2015-06-02 12:37:41 +0000 | |||
328 | +++ src/Ubuntu/Components/plugin/ucstyleditembase.h 2015-08-06 18:06:52 +0000 | |||
329 | @@ -53,16 +53,14 @@ | |||
330 | 53 | protected: | 53 | protected: |
331 | 54 | UCStyledItemBase(UCStyledItemBasePrivate &, QQuickItem *parent); | 54 | UCStyledItemBase(UCStyledItemBasePrivate &, QQuickItem *parent); |
332 | 55 | 55 | ||
333 | 56 | void classBegin(); | ||
334 | 56 | void componentComplete(); | 57 | void componentComplete(); |
335 | 57 | void mousePressEvent(QMouseEvent *event); | 58 | void mousePressEvent(QMouseEvent *event); |
336 | 58 | bool childMouseEventFilter(QQuickItem *child, QEvent *event); | 59 | bool childMouseEventFilter(QQuickItem *child, QEvent *event); |
337 | 59 | void itemChange(ItemChange, const ItemChangeData &); | ||
338 | 60 | 60 | ||
339 | 61 | private: | 61 | private: |
340 | 62 | Q_DECLARE_PRIVATE(UCStyledItemBase) | 62 | Q_DECLARE_PRIVATE(UCStyledItemBase) |
341 | 63 | Q_PRIVATE_SLOT(d_func(), void _q_styleResized()) | 63 | Q_PRIVATE_SLOT(d_func(), void _q_styleResized()) |
342 | 64 | Q_PRIVATE_SLOT(d_func(), void _q_ascendantChanged(QQuickItem*)) | ||
343 | 65 | Q_PRIVATE_SLOT(d_func(), void _q_parentStyleChanged()) | ||
344 | 66 | Q_PRIVATE_SLOT(d_func(), void _q_reloadStyle()) | 64 | Q_PRIVATE_SLOT(d_func(), void _q_reloadStyle()) |
345 | 67 | }; | 65 | }; |
346 | 68 | 66 | ||
347 | 69 | 67 | ||
348 | === modified file 'src/Ubuntu/Components/plugin/ucstyleditembase_p.h' | |||
349 | --- src/Ubuntu/Components/plugin/ucstyleditembase_p.h 2015-06-02 12:37:41 +0000 | |||
350 | +++ src/Ubuntu/Components/plugin/ucstyleditembase_p.h 2015-08-06 18:06:52 +0000 | |||
351 | @@ -21,10 +21,11 @@ | |||
352 | 21 | 21 | ||
353 | 22 | #include <QtQuick/private/qquickitem_p.h> | 22 | #include <QtQuick/private/qquickitem_p.h> |
354 | 23 | #include "ucstyleditembase.h" | 23 | #include "ucstyleditembase.h" |
355 | 24 | #include "ucthemingattached.h" | ||
356 | 24 | 25 | ||
357 | 25 | class QQuickMouseArea; | 26 | class QQuickMouseArea; |
358 | 26 | class UCStyledItemBase; | 27 | class UCStyledItemBase; |
360 | 27 | class UCStyledItemBasePrivate : public QQuickItemPrivate | 28 | class UCStyledItemBasePrivate : public QQuickItemPrivate, public UCThemeChangeListener |
361 | 28 | { | 29 | { |
362 | 29 | Q_DECLARE_PUBLIC(UCStyledItemBase) | 30 | Q_DECLARE_PUBLIC(UCStyledItemBase) |
363 | 30 | public: | 31 | public: |
364 | @@ -35,8 +36,6 @@ | |||
365 | 35 | 36 | ||
366 | 36 | void _q_reloadStyle(); | 37 | void _q_reloadStyle(); |
367 | 37 | void _q_styleResized(); | 38 | void _q_styleResized(); |
368 | 38 | void _q_ascendantChanged(QQuickItem *ascendant); | ||
369 | 39 | void _q_parentStyleChanged(); | ||
370 | 40 | 39 | ||
371 | 41 | UCStyledItemBasePrivate(); | 40 | UCStyledItemBasePrivate(); |
372 | 42 | virtual ~UCStyledItemBasePrivate(); | 41 | virtual ~UCStyledItemBasePrivate(); |
373 | @@ -61,25 +60,19 @@ | |||
374 | 61 | void setTheme(UCTheme *theme); | 60 | void setTheme(UCTheme *theme); |
375 | 62 | void resetTheme(); | 61 | void resetTheme(); |
376 | 63 | 62 | ||
379 | 64 | virtual void preThemeChanged(){} | 63 | void preThemeChanged(){} |
380 | 65 | virtual void postThemeChanged(){} | 64 | void postThemeChanged(){} |
381 | 66 | 65 | ||
382 | 67 | public: | 66 | public: |
383 | 68 | bool activeFocusOnPress:1; | ||
384 | 69 | QString styleDocument; | 67 | QString styleDocument; |
385 | 68 | QPointer<UCThemingAttached> theming; | ||
386 | 69 | QPointer<QQmlContext> styleItemContext; | ||
387 | 70 | QQmlComponent *styleComponent; | 70 | QQmlComponent *styleComponent; |
388 | 71 | QPointer<QQmlContext> styleItemContext; | ||
389 | 72 | QQuickItem *styleItem; | 71 | QQuickItem *styleItem; |
392 | 73 | UCTheme *theme; | 72 | bool activeFocusOnPress:1; |
391 | 74 | QPointer<UCStyledItemBase> parentStyledItem; | ||
393 | 75 | 73 | ||
394 | 76 | protected: | 74 | protected: |
395 | 77 | QStack< QPointer<QQuickItem> > parentStack; | ||
396 | 78 | |||
397 | 79 | void connectStyleSizeChanges(bool attach); | 75 | void connectStyleSizeChanges(bool attach); |
398 | 80 | bool connectParents(QQuickItem *fromItem); | ||
399 | 81 | bool setParentStyled(UCStyledItemBase *styledItem); | ||
400 | 82 | void disconnectTillItem(QQuickItem *item); | ||
401 | 83 | }; | 76 | }; |
402 | 84 | 77 | ||
403 | 85 | #endif // UCSTYLEDITEMBASE_P_H | 78 | #endif // UCSTYLEDITEMBASE_P_H |
404 | 86 | 79 | ||
405 | === modified file 'src/Ubuntu/Components/plugin/uctheme.cpp' | |||
406 | --- src/Ubuntu/Components/plugin/uctheme.cpp 2015-07-20 12:56:17 +0000 | |||
407 | +++ src/Ubuntu/Components/plugin/uctheme.cpp 2015-08-06 18:06:52 +0000 | |||
408 | @@ -24,6 +24,7 @@ | |||
409 | 24 | #include "i18n.h" | 24 | #include "i18n.h" |
410 | 25 | #include "ucfontutils.h" | 25 | #include "ucfontutils.h" |
411 | 26 | #include "ucstyleditembase_p.h" | 26 | #include "ucstyleditembase_p.h" |
412 | 27 | #include "ucthemingattached.h" | ||
413 | 27 | 28 | ||
414 | 28 | #include <QtQml/qqml.h> | 29 | #include <QtQml/qqml.h> |
415 | 29 | #include <QtQml/qqmlinfo.h> | 30 | #include <QtQml/qqmlinfo.h> |
416 | @@ -422,10 +423,9 @@ | |||
417 | 422 | */ | 423 | */ |
418 | 423 | UCTheme *UCTheme::parentTheme() | 424 | UCTheme *UCTheme::parentTheme() |
419 | 424 | { | 425 | { |
424 | 425 | UCStyledItemBase *owner = qobject_cast<UCStyledItemBase*>(parent()); | 426 | UCThemingAttached *theming = itemTheming(static_cast<QQuickItem*>(parent())); |
425 | 426 | UCStyledItemBasePrivate *pOwner = owner ? UCStyledItemBasePrivate::get(owner) : NULL; | 427 | if (theming && theming->m_theme == this && theming->m_parentTheming) { |
426 | 427 | if (pOwner && pOwner->theme == this && pOwner->parentStyledItem) { | 428 | return theming->m_parentTheming->getTheme(); |
423 | 428 | return UCStyledItemBasePrivate::get(pOwner->parentStyledItem)->getTheme(); | ||
427 | 429 | } | 429 | } |
428 | 430 | return NULL; | 430 | return NULL; |
429 | 431 | } | 431 | } |
430 | 432 | 432 | ||
431 | === added file 'src/Ubuntu/Components/plugin/ucthemingattached.cpp' | |||
432 | --- src/Ubuntu/Components/plugin/ucthemingattached.cpp 1970-01-01 00:00:00 +0000 | |||
433 | +++ src/Ubuntu/Components/plugin/ucthemingattached.cpp 2015-08-06 18:06:52 +0000 | |||
434 | @@ -0,0 +1,257 @@ | |||
435 | 1 | /* | ||
436 | 2 | * Copyright 2015 Canonical Ltd. | ||
437 | 3 | * | ||
438 | 4 | * This program is free software; you can redistribute it and/or modify | ||
439 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
440 | 6 | * the Free Software Foundation; version 3. | ||
441 | 7 | * | ||
442 | 8 | * This program is distributed in the hope that it will be useful, | ||
443 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
444 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
445 | 11 | * GNU Lesser General Public License for more details. | ||
446 | 12 | * | ||
447 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
448 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
449 | 15 | * | ||
450 | 16 | * Author: Zsombor Egri <zsombor.egri@canonical.com> | ||
451 | 17 | */ | ||
452 | 18 | |||
453 | 19 | #include "ucthemingattached.h" | ||
454 | 20 | #include <QtQuick/QQuickItem> | ||
455 | 21 | #include "uctheme.h" | ||
456 | 22 | |||
457 | 23 | /* | ||
458 | 24 | * UCThemingAttached is an attached object to all themable components. It is used | ||
459 | 25 | * internally by those components which need theme access thru the theme property. | ||
460 | 26 | * Components which want to use this should do the following: | ||
461 | 27 | * - attach the object in classBegin() function | ||
462 | 28 | * - expose a theme property | ||
463 | 29 | * - getter should use the getTheme() attached function | ||
464 | 30 | * - setter/reset should use the setTheme() attached function | ||
465 | 31 | * - themeChanged() signal must be connected to the property change signal | ||
466 | 32 | * | ||
467 | 33 | * The theme change is notified through listener callbacks. Registering listener | ||
468 | 34 | * is not mandatory. | ||
469 | 35 | */ | ||
470 | 36 | |||
471 | 37 | UCThemingAttached *itemTheming(QQuickItem *item) | ||
472 | 38 | { | ||
473 | 39 | return qobject_cast<UCThemingAttached*>( | ||
474 | 40 | qmlAttachedPropertiesObject<UCThemingAttached>(item, false)); | ||
475 | 41 | } | ||
476 | 42 | |||
477 | 43 | UCThemingAttached::UCThemingAttached(QObject *parent) | ||
478 | 44 | : QObject(parent) | ||
479 | 45 | , m_theme(Q_NULLPTR) | ||
480 | 46 | , m_listener(Q_NULLPTR) | ||
481 | 47 | , m_ownerItem(static_cast<QQuickItem*>(parent)) | ||
482 | 48 | { | ||
483 | 49 | } | ||
484 | 50 | |||
485 | 51 | UCThemingAttached *UCThemingAttached::qmlAttachedProperties(QObject *owner) | ||
486 | 52 | { | ||
487 | 53 | UCThemingAttached *theming = new UCThemingAttached(owner); | ||
488 | 54 | // the theme is the default one at this stage, so connect all the necessary signals | ||
489 | 55 | // owner must have theme signal | ||
490 | 56 | theming->connectThemeSignals(theming->getTheme(), true); | ||
491 | 57 | // connect parentChanged of owner to know when its parent is changed | ||
492 | 58 | connect(theming->m_ownerItem, &QQuickItem::parentChanged, | ||
493 | 59 | theming, &UCThemingAttached::itemParentChanged, Qt::DirectConnection); | ||
494 | 60 | return theming; | ||
495 | 61 | } | ||
496 | 62 | |||
497 | 63 | UCThemingAttached *UCThemingAttached::attachTheming(QObject *owner) | ||
498 | 64 | { | ||
499 | 65 | return qobject_cast<UCThemingAttached*>( | ||
500 | 66 | qmlAttachedPropertiesObject<UCThemingAttached>(owner, true)); | ||
501 | 67 | } | ||
502 | 68 | |||
503 | 69 | void UCThemingAttached::connectThemeSignals(UCTheme *theme, bool connect) | ||
504 | 70 | { | ||
505 | 71 | if (connect) { | ||
506 | 72 | QObject::connect(theme, SIGNAL(nameChanged()), this, SIGNAL(themeChanged()), Qt::DirectConnection); | ||
507 | 73 | QObject::connect(theme, SIGNAL(versionChanged()), this, SIGNAL(themeChanged()), Qt::DirectConnection); | ||
508 | 74 | } else { | ||
509 | 75 | QObject::disconnect(theme, SIGNAL(nameChanged()), this, SIGNAL(themeChanged())); | ||
510 | 76 | QObject::disconnect(theme, SIGNAL(versionChanged()), this, SIGNAL(themeChanged())); | ||
511 | 77 | } | ||
512 | 78 | } | ||
513 | 79 | |||
514 | 80 | // link/unlink all ascendant items until we reach a StyledItem, returns true if the | ||
515 | 81 | // theme change signal emission is justified | ||
516 | 82 | bool UCThemingAttached::connectParents(QQuickItem *fromItem) | ||
517 | 83 | { | ||
518 | 84 | QQuickItem *item = fromItem ? fromItem : m_ownerItem->parentItem(); | ||
519 | 85 | while (item) { | ||
520 | 86 | // push the item onto the stack | ||
521 | 87 | m_parentStack.push(QPointer<QQuickItem>(item)); | ||
522 | 88 | UCThemingAttached *styling = itemTheming(item); | ||
523 | 89 | if (styling) { | ||
524 | 90 | // this is the closest StyledItem, connect its themeChanged() signal | ||
525 | 91 | QObject::connect(styling, SIGNAL(themeChanged()), | ||
526 | 92 | this, SLOT(parentStyleChanged()), Qt::DirectConnection); | ||
527 | 93 | // set the current style set to the one in the parent's one if differs | ||
528 | 94 | return setParentStyled(styling); | ||
529 | 95 | } else { | ||
530 | 96 | // connect to the item's parentChanged() signal so we can detect when the parent changes | ||
531 | 97 | QObject::connect(item, SIGNAL(parentChanged(QQuickItem*)), | ||
532 | 98 | this, SLOT(ascendantChanged(QQuickItem*)), Qt::DirectConnection); | ||
533 | 99 | } | ||
534 | 100 | item = item->parentItem(); | ||
535 | 101 | } | ||
536 | 102 | return false; | ||
537 | 103 | } | ||
538 | 104 | |||
539 | 105 | // disconnect parent stack till item is reached; all the stack if item == 0 | ||
540 | 106 | void UCThemingAttached::disconnectTillItem(QQuickItem *item) | ||
541 | 107 | { | ||
542 | 108 | while (!m_parentStack.isEmpty() && item != m_parentStack.top()) { | ||
543 | 109 | QPointer<QQuickItem> stackItem = m_parentStack.pop(); | ||
544 | 110 | // the topmost item can be the only one which is a StyledItem | ||
545 | 111 | UCThemingAttached *styling = itemTheming(stackItem.data()); | ||
546 | 112 | if (styling) { | ||
547 | 113 | QObject::disconnect(styling, SIGNAL(themeChanged()), | ||
548 | 114 | this, SLOT(parentStyleChanged())); | ||
549 | 115 | // clear parent styling as well | ||
550 | 116 | if (styling == m_parentTheming) { | ||
551 | 117 | m_parentTheming.clear(); | ||
552 | 118 | } | ||
553 | 119 | } else if (!stackItem.isNull()) { | ||
554 | 120 | QObject::disconnect(stackItem.data(), SIGNAL(parentChanged(QQuickItem*)), | ||
555 | 121 | this, SLOT(ascendantChanged(QQuickItem*))); | ||
556 | 122 | } | ||
557 | 123 | } | ||
558 | 124 | } | ||
559 | 125 | |||
560 | 126 | // set the used parent styled item's style; returns true if the parent styled got changed | ||
561 | 127 | bool UCThemingAttached::setParentStyled(UCThemingAttached *newStyling) | ||
562 | 128 | { | ||
563 | 129 | if (m_parentTheming == newStyling) { | ||
564 | 130 | return false; | ||
565 | 131 | } | ||
566 | 132 | m_parentTheming = newStyling; | ||
567 | 133 | if (m_theme) { | ||
568 | 134 | Q_EMIT themeChanged(); | ||
569 | 135 | } | ||
570 | 136 | return (m_theme == NULL); | ||
571 | 137 | } | ||
572 | 138 | |||
573 | 139 | UCTheme *UCThemingAttached::getTheme() | ||
574 | 140 | { | ||
575 | 141 | if (m_theme) { | ||
576 | 142 | return m_theme; | ||
577 | 143 | } else if (!m_parentTheming.isNull()) { | ||
578 | 144 | return m_parentTheming->getTheme(); | ||
579 | 145 | } | ||
580 | 146 | return &UCTheme::defaultTheme(); | ||
581 | 147 | } | ||
582 | 148 | |||
583 | 149 | bool UCThemingAttached::setTheme(UCTheme *newTheme) | ||
584 | 150 | { | ||
585 | 151 | if (m_theme == newTheme) { | ||
586 | 152 | return false; | ||
587 | 153 | } | ||
588 | 154 | |||
589 | 155 | // preform pre-theme change tasks | ||
590 | 156 | if (m_listener) { | ||
591 | 157 | m_listener->preThemeChanged(); | ||
592 | 158 | } | ||
593 | 159 | |||
594 | 160 | // disconnect from the previous set | ||
595 | 161 | UCTheme *connectedSet = m_theme ? | ||
596 | 162 | m_theme : | ||
597 | 163 | (!m_parentTheming ? &UCTheme::defaultTheme() : NULL); | ||
598 | 164 | if (connectedSet) { | ||
599 | 165 | connectThemeSignals(connectedSet, false); | ||
600 | 166 | } | ||
601 | 167 | |||
602 | 168 | UCTheme *prevSet = m_theme; | ||
603 | 169 | |||
604 | 170 | // resolve new theme | ||
605 | 171 | if (m_theme && newTheme) { | ||
606 | 172 | // no need to redo the parentStack, simply set the theme and leave | ||
607 | 173 | m_theme = newTheme; | ||
608 | 174 | } else { | ||
609 | 175 | m_theme = newTheme; | ||
610 | 176 | if (!newTheme) { | ||
611 | 177 | // redo the parent chanin | ||
612 | 178 | disconnectTillItem(0); | ||
613 | 179 | connectParents(0); | ||
614 | 180 | } | ||
615 | 181 | } | ||
616 | 182 | |||
617 | 183 | // connect to the new set | ||
618 | 184 | connectedSet = m_theme ? | ||
619 | 185 | m_theme : | ||
620 | 186 | (!m_parentTheming ? &UCTheme::defaultTheme() : NULL); | ||
621 | 187 | if (connectedSet) { | ||
622 | 188 | connectThemeSignals(connectedSet, true); | ||
623 | 189 | } | ||
624 | 190 | // detach previous set and attach the new one | ||
625 | 191 | if (prevSet) { | ||
626 | 192 | Q_EMIT prevSet->parentThemeChanged(); | ||
627 | 193 | } | ||
628 | 194 | if (m_theme) { | ||
629 | 195 | // re-parent theme to make sure we have it | ||
630 | 196 | // for the entire lifetime of the styled item | ||
631 | 197 | m_theme->setParent(parent()); | ||
632 | 198 | Q_EMIT m_theme->parentThemeChanged(); | ||
633 | 199 | } | ||
634 | 200 | |||
635 | 201 | // perform post-theme changes, update internal styling | ||
636 | 202 | if (m_listener) { | ||
637 | 203 | m_listener->postThemeChanged(); | ||
638 | 204 | } | ||
639 | 205 | |||
640 | 206 | Q_EMIT themeChanged(); | ||
641 | 207 | return true; | ||
642 | 208 | } | ||
643 | 209 | |||
644 | 210 | // lookup for the parent chain theme | ||
645 | 211 | void UCThemingAttached::itemParentChanged() | ||
646 | 212 | { | ||
647 | 213 | // clean stack | ||
648 | 214 | disconnectTillItem(0); | ||
649 | 215 | // make sure we reset parent StyledItem | ||
650 | 216 | m_parentTheming.clear(); | ||
651 | 217 | // build the stack - if possible | ||
652 | 218 | connectParents(0); | ||
653 | 219 | Q_EMIT themeChanged(); | ||
654 | 220 | } | ||
655 | 221 | |||
656 | 222 | // captures ascendant change signal, the sender is the one which counts! | ||
657 | 223 | void UCThemingAttached::ascendantChanged(QQuickItem *ascendant) | ||
658 | 224 | { | ||
659 | 225 | QQuickItem *sender = static_cast<QQuickItem*>(this->sender()); | ||
660 | 226 | if (!sender) { | ||
661 | 227 | // cannot detect the sender, leave! | ||
662 | 228 | return; | ||
663 | 229 | } | ||
664 | 230 | if (ascendant) { | ||
665 | 231 | // disconnect from the previous ones | ||
666 | 232 | disconnectTillItem(sender); | ||
667 | 233 | m_parentTheming.clear(); | ||
668 | 234 | // traverse ascendants till we reach a StyledItem or root and push them into the stack | ||
669 | 235 | if (connectParents(ascendant)) { | ||
670 | 236 | Q_EMIT themeChanged(); | ||
671 | 237 | } | ||
672 | 238 | } | ||
673 | 239 | } | ||
674 | 240 | |||
675 | 241 | // syncs the ascendant styled item's styles | ||
676 | 242 | void UCThemingAttached::parentStyleChanged() | ||
677 | 243 | { | ||
678 | 244 | // do not trigger themeChanged() on this item if we have a | ||
679 | 245 | // custom one, but resolve its eventual parent change! | ||
680 | 246 | if (m_theme) { | ||
681 | 247 | Q_EMIT m_theme->parentThemeChanged(); | ||
682 | 248 | return; | ||
683 | 249 | } | ||
684 | 250 | |||
685 | 251 | UCThemingAttached *styling = static_cast<UCThemingAttached*>(sender()); | ||
686 | 252 | if (!styling) { | ||
687 | 253 | return; | ||
688 | 254 | } | ||
689 | 255 | setParentStyled(styling); | ||
690 | 256 | Q_EMIT themeChanged(); | ||
691 | 257 | } | ||
692 | 0 | 258 | ||
693 | === added file 'src/Ubuntu/Components/plugin/ucthemingattached.h' | |||
694 | --- src/Ubuntu/Components/plugin/ucthemingattached.h 1970-01-01 00:00:00 +0000 | |||
695 | +++ src/Ubuntu/Components/plugin/ucthemingattached.h 2015-08-06 18:06:52 +0000 | |||
696 | @@ -0,0 +1,81 @@ | |||
697 | 1 | /* | ||
698 | 2 | * Copyright 2015 Canonical Ltd. | ||
699 | 3 | * | ||
700 | 4 | * This program is free software; you can redistribute it and/or modify | ||
701 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
702 | 6 | * the Free Software Foundation; version 3. | ||
703 | 7 | * | ||
704 | 8 | * This program is distributed in the hope that it will be useful, | ||
705 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
706 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
707 | 11 | * GNU Lesser General Public License for more details. | ||
708 | 12 | * | ||
709 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
710 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
711 | 15 | * | ||
712 | 16 | * Author: Zsombor Egri <zsombor.egri@canonical.com> | ||
713 | 17 | */ | ||
714 | 18 | |||
715 | 19 | #ifndef UCTHEMINGATTACHED_H | ||
716 | 20 | #define UCTHEMINGATTACHED_H | ||
717 | 21 | |||
718 | 22 | #include <QtCore/QObject> | ||
719 | 23 | #include <QtCore/QPointer> | ||
720 | 24 | #include <QtQml> | ||
721 | 25 | |||
722 | 26 | class UCTheme; | ||
723 | 27 | class QQuickItem; | ||
724 | 28 | |||
725 | 29 | class UCThemeChangeListener { | ||
726 | 30 | public: | ||
727 | 31 | virtual void preThemeChanged() = 0; | ||
728 | 32 | virtual void postThemeChanged() = 0; | ||
729 | 33 | }; | ||
730 | 34 | |||
731 | 35 | class UCThemingAttached : public QObject | ||
732 | 36 | { | ||
733 | 37 | Q_OBJECT | ||
734 | 38 | public: | ||
735 | 39 | explicit UCThemingAttached(QObject *parent = 0); | ||
736 | 40 | |||
737 | 41 | static UCThemingAttached *qmlAttachedProperties(QObject *owner); | ||
738 | 42 | static UCThemingAttached *attachTheming(QObject *owner); | ||
739 | 43 | |||
740 | 44 | void setListener(UCThemeChangeListener *listener) | ||
741 | 45 | { | ||
742 | 46 | m_listener = listener; | ||
743 | 47 | } | ||
744 | 48 | UCTheme *getTheme(); | ||
745 | 49 | bool setTheme(UCTheme *theme); | ||
746 | 50 | |||
747 | 51 | Q_SIGNALS: | ||
748 | 52 | void themeChanged(); | ||
749 | 53 | |||
750 | 54 | public Q_SLOTS: | ||
751 | 55 | |||
752 | 56 | void ascendantChanged(QQuickItem *ascendant); | ||
753 | 57 | void parentStyleChanged(); | ||
754 | 58 | void itemParentChanged(); | ||
755 | 59 | |||
756 | 60 | protected: | ||
757 | 61 | friend class UCTheme; | ||
758 | 62 | |||
759 | 63 | QStack< QPointer<QQuickItem> > m_parentStack; | ||
760 | 64 | QPointer<UCThemingAttached> m_parentTheming; | ||
761 | 65 | UCTheme *m_theme; | ||
762 | 66 | UCThemeChangeListener *m_listener; | ||
763 | 67 | QQuickItem *m_ownerItem; | ||
764 | 68 | |||
765 | 69 | void connectThemeSignals(UCTheme *theme, bool connect); | ||
766 | 70 | |||
767 | 71 | bool connectParents(QQuickItem *fromItem); | ||
768 | 72 | void disconnectTillItem(QQuickItem *item); | ||
769 | 73 | bool setParentStyled(UCThemingAttached *newStyling); | ||
770 | 74 | |||
771 | 75 | }; | ||
772 | 76 | QML_DECLARE_TYPEINFO(UCThemingAttached, QML_HAS_ATTACHED_PROPERTIES) | ||
773 | 77 | |||
774 | 78 | UCThemingAttached *itemTheming(QQuickItem *item); | ||
775 | 79 | |||
776 | 80 | |||
777 | 81 | #endif // UCTHEMINGATTACHED_H |
StyledItem was registered twice with the revision 2, so the 1.3 appeared twice in the API file. I fixed that as well.