aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickcontrol.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-12-17 10:46:42 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-21 16:47:55 +0000
commit8099ecb2a73832b930d217e7a957f190d49e6eb1 (patch)
treea85be2bc15760472e298788de23c14c930ee53ac /src/templates/qquickcontrol.cpp
parentc34e39cd1fd078510467536a9562e365cdae4d8f (diff)
Control: implement locale inheritance
Change-Id: I2f16141b53dd44e471050ef6901ddc480c77895f Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickcontrol.cpp')
-rw-r--r--src/templates/qquickcontrol.cpp73
1 files changed, 64 insertions, 9 deletions
diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp
index b08b70fb..97a85d4b 100644
--- a/src/templates/qquickcontrol.cpp
+++ b/src/templates/qquickcontrol.cpp
@@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE
*/
QQuickControlPrivate::QQuickControlPrivate() :
- hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false),
+ hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), hasLocale(false),
padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0), focusReason(Qt::OtherFocusReason),
background(Q_NULLPTR), contentItem(Q_NULLPTR), accessibleAttached(Q_NULLPTR)
{
@@ -361,8 +361,11 @@ void QQuickControl::itemChange(QQuickItem::ItemChange change, const QQuickItem::
{
Q_D(QQuickControl);
QQuickItem::itemChange(change, value);
- if (change == ItemParentHasChanged && isComponentComplete())
+ if (change == ItemParentHasChanged && isComponentComplete()) {
d->resolveFont();
+ if (!d->hasLocale)
+ d->locale = d->calcLocale();
+ }
}
/*!
@@ -626,13 +629,65 @@ QLocale QQuickControl::locale() const
void QQuickControl::setLocale(const QLocale &locale)
{
Q_D(QQuickControl);
- if (d->locale != locale) {
- bool wasMirrored = isMirrored();
- localeChange(locale, d->locale);
- d->locale = locale;
- emit localeChanged();
- if (wasMirrored != isMirrored())
- mirrorChange();
+ if (d->hasLocale && d->locale == locale)
+ return;
+
+ d->updateLocale(locale, true); // explicit=true
+}
+
+void QQuickControl::resetLocale()
+{
+ Q_D(QQuickControl);
+ if (!d->hasLocale)
+ return;
+
+ d->updateLocale(d->calcLocale(), false); // explicit=false
+}
+
+QLocale QQuickControlPrivate::calcLocale() const
+{
+ Q_Q(const QQuickControl);
+ QQuickItem *p = q->parentItem();
+ while (p) {
+ if (QQuickControl *qc = qobject_cast<QQuickControl *>(p))
+ return qc->locale();
+
+ QVariant v = p->property("locale");
+ if (v.isValid() && v.userType() == QMetaType::QLocale)
+ return v.toLocale();
+
+ p = p->parentItem();
+ }
+
+ return QLocale();
+}
+
+void QQuickControlPrivate::updateLocale(const QLocale &l, bool e)
+{
+ Q_Q(QQuickControl);
+ if (!e && hasLocale)
+ return;
+
+ QLocale old = q->locale();
+ hasLocale = e;
+ if (old != l) {
+ bool wasMirrored = q->isMirrored();
+ q->localeChange(l, old);
+ locale = l;
+ QQuickControlPrivate::updateLocaleRecur(q, l);
+ emit q->localeChanged();
+ if (wasMirrored != q->isMirrored())
+ q->mirrorChange();
+ }
+}
+
+void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item, const QLocale &l)
+{
+ foreach (QQuickItem *child, item->childItems()) {
+ if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
+ QQuickControlPrivate::get(control)->updateLocale(l, false);
+ else
+ updateLocaleRecur(child, l);
}
}