aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
parentc34e39cd1fd078510467536a9562e365cdae4d8f (diff)
Control: implement locale inheritance
Change-Id: I2f16141b53dd44e471050ef6901ddc480c77895f Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/templates/qquickcontrol.cpp73
-rw-r--r--src/templates/qquickcontrol_p.h3
-rw-r--r--src/templates/qquickcontrol_p_p.h5
3 files changed, 71 insertions, 10 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);
}
}
diff --git a/src/templates/qquickcontrol_p.h b/src/templates/qquickcontrol_p.h
index ea1180b1..8d4055e5 100644
--- a/src/templates/qquickcontrol_p.h
+++ b/src/templates/qquickcontrol_p.h
@@ -68,7 +68,7 @@ class Q_LABSTEMPLATES_EXPORT QQuickControl : public QQuickItem
Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding NOTIFY rightPaddingChanged FINAL)
Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding NOTIFY bottomPaddingChanged FINAL)
Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing RESET resetSpacing NOTIFY spacingChanged FINAL)
- Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged FINAL)
+ Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET resetLocale NOTIFY localeChanged FINAL)
Q_PROPERTY(bool mirrored READ isMirrored NOTIFY mirroredChanged FINAL)
Q_PROPERTY(Qt::FocusReason focusReason READ focusReason WRITE setFocusReason NOTIFY focusReasonChanged FINAL)
Q_PROPERTY(QQuickItem *background READ background WRITE setBackground NOTIFY backgroundChanged FINAL)
@@ -110,6 +110,7 @@ public:
QLocale locale() const;
void setLocale(const QLocale &locale);
+ void resetLocale();
bool isMirrored() const;
diff --git a/src/templates/qquickcontrol_p_p.h b/src/templates/qquickcontrol_p_p.h
index fff36bc0..21f6c1b1 100644
--- a/src/templates/qquickcontrol_p_p.h
+++ b/src/templates/qquickcontrol_p_p.h
@@ -102,12 +102,17 @@ public:
void resolveFont();
static QFont naturalControlFont(const QQuickItem *);
static QFont themeFont(QPlatformTheme::Font type);
+ void updateLocale(const QLocale &l, bool e);
+ static void updateLocaleRecur(QQuickItem *item, const QLocale &l);
+
+ QLocale calcLocale() const;
QFont font;
bool hasTopPadding;
bool hasLeftPadding;
bool hasRightPadding;
bool hasBottomPadding;
+ bool hasLocale;
qreal padding;
qreal topPadding;
qreal leftPadding;