aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2
diff options
context:
space:
mode:
Diffstat (limited to 'src/quickcontrols2')
-rw-r--r--src/quickcontrols2/configure.json18
-rw-r--r--src/quickcontrols2/qquickattachedobject.cpp249
-rw-r--r--src/quickcontrols2/qquickattachedobject_p.h (renamed from src/quickcontrols2/qquickstyleattached_p.h)35
-rw-r--r--src/quickcontrols2/qquickchecklabel.cpp49
-rw-r--r--src/quickcontrols2/qquickchecklabel_p.h (renamed from src/quickcontrols2/qquickcolorimageprovider_p.h)21
-rw-r--r--src/quickcontrols2/qquickcolor.cpp (renamed from src/quickcontrols2/qquickcolorimageprovider.cpp)49
-rw-r--r--src/quickcontrols2/qquickcolor_p.h70
-rw-r--r--src/quickcontrols2/qquickcolorimage.cpp103
-rw-r--r--src/quickcontrols2/qquickcolorimage_p.h88
-rw-r--r--src/quickcontrols2/qquickiconimage.cpp220
-rw-r--r--src/quickcontrols2/qquickiconimage_p.h94
-rw-r--r--src/quickcontrols2/qquickiconimage_p_p.h79
-rw-r--r--src/quickcontrols2/qquickiconlabel.cpp651
-rw-r--r--src/quickcontrols2/qquickiconlabel_p.h140
-rw-r--r--src/quickcontrols2/qquickiconlabel_p_p.h113
-rw-r--r--src/quickcontrols2/qquickmnemoniclabel.cpp133
-rw-r--r--src/quickcontrols2/qquickmnemoniclabel_p.h82
-rw-r--r--src/quickcontrols2/qquickpaddedrectangle.cpp5
-rw-r--r--src/quickcontrols2/qquickproxytheme_p.h2
-rw-r--r--src/quickcontrols2/qquickstyle.cpp42
-rw-r--r--src/quickcontrols2/qquickstyle_p.h5
-rw-r--r--src/quickcontrols2/qquickstyleattached.cpp269
-rw-r--r--src/quickcontrols2/qquickstyleplugin.cpp13
-rw-r--r--src/quickcontrols2/qquickstyleplugin_p.h1
-rw-r--r--src/quickcontrols2/qquickstyleselector.cpp12
-rw-r--r--src/quickcontrols2/qquicktheme.cpp163
-rw-r--r--src/quickcontrols2/qquicktheme_p.h77
-rw-r--r--src/quickcontrols2/quickcontrols2.pri26
-rw-r--r--src/quickcontrols2/quickcontrols2.pro2
29 files changed, 2465 insertions, 346 deletions
diff --git a/src/quickcontrols2/configure.json b/src/quickcontrols2/configure.json
index 9384a52b..22a602d3 100644
--- a/src/quickcontrols2/configure.json
+++ b/src/quickcontrols2/configure.json
@@ -3,6 +3,8 @@
"commandline": {
"options": {
+ "style-fusion": { "type": "boolean", "name": "quickcontrols2-fusion" },
+ "style-imagine": { "type": "boolean", "name": "quickcontrols2-imagine" },
"style-material": { "type": "boolean", "name": "quickcontrols2-material" },
"style-universal": { "type": "boolean", "name": "quickcontrols2-universal" }
}
@@ -13,6 +15,20 @@
"label": "Default",
"output": [ "privateFeature" ]
},
+ "quickcontrols2-fusion": {
+ "label": "Fusion",
+ "purpose": "Provides the platform agnostic desktop-oriented Fusion style.",
+ "section": "Quick Controls 2",
+ "condition": "features.quickcontrols2-default",
+ "output": [ "privateFeature" ]
+ },
+ "quickcontrols2-imagine": {
+ "label": "Imagine",
+ "purpose": "Provides a style based on configurable image assets.",
+ "section": "Quick Controls 2",
+ "condition": "features.quickcontrols2-default",
+ "output": [ "privateFeature" ]
+ },
"quickcontrols2-material": {
"label": "Material",
"purpose": "Provides a style based on the Material Design guidelines.",
@@ -36,7 +52,7 @@
{
"message": "Styles",
"type": "featureList",
- "args": "quickcontrols2-default quickcontrols2-material quickcontrols2-universal"
+ "args": "quickcontrols2-default quickcontrols2-fusion quickcontrols2-imagine quickcontrols2-material quickcontrols2-universal"
}
]
}
diff --git a/src/quickcontrols2/qquickattachedobject.cpp b/src/quickcontrols2/qquickattachedobject.cpp
new file mode 100644
index 00000000..bada982e
--- /dev/null
+++ b/src/quickcontrols2/qquickattachedobject.cpp
@@ -0,0 +1,249 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickattachedobject_p.h"
+
+#include <QtQuick/qquickwindow.h>
+#include <QtQuick/private/qquickitem_p.h>
+#include <QtQuickTemplates2/private/qquickpopup_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static QQuickAttachedObject *attachedObject(const QMetaObject *type, QObject *object, bool create = false)
+{
+ if (!object)
+ return nullptr;
+ int idx = -1;
+ return qobject_cast<QQuickAttachedObject *>(qmlAttachedPropertiesObject(&idx, object, type, create));
+}
+
+static QQuickAttachedObject *findAttachedParent(const QMetaObject *type, QObject *object)
+{
+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
+ if (item) {
+ // lookup parent items and popups
+ QQuickItem *parent = item->parentItem();
+ while (parent) {
+ QQuickAttachedObject *attached = attachedObject(type, parent);
+ if (attached)
+ return attached;
+
+ QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent->parent());
+ if (popup)
+ return attachedObject(type, popup);
+
+ parent = parent->parentItem();
+ }
+
+ // fallback to item's window
+ QQuickAttachedObject *attached = attachedObject(type, item->window());
+ if (attached)
+ return attached;
+ } else {
+ // lookup popup's window
+ QQuickPopup *popup = qobject_cast<QQuickPopup *>(object);
+ if (popup)
+ return attachedObject(type, popup->popupItem()->window());
+ }
+
+ // lookup parent window
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
+ if (window) {
+ QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(window->parent());
+ if (parentWindow) {
+ QQuickAttachedObject *attached = attachedObject(type, window);
+ if (attached)
+ return attached;
+ }
+ }
+
+ // fallback to engine (global)
+ if (object) {
+ QQmlEngine *engine = qmlEngine(object);
+ if (engine) {
+ QByteArray name = QByteArray("_q_") + type->className();
+ QQuickAttachedObject *attached = engine->property(name).value<QQuickAttachedObject *>();
+ if (!attached) {
+ attached = attachedObject(type, engine, true);
+ engine->setProperty(name, QVariant::fromValue(attached));
+ }
+ return attached;
+ }
+ }
+
+ return nullptr;
+}
+
+static QList<QQuickAttachedObject *> findAttachedChildren(const QMetaObject *type, QObject *object)
+{
+ QList<QQuickAttachedObject *> children;
+
+ QQuickItem *item = qobject_cast<QQuickItem *>(object);
+ if (!item) {
+ QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
+ if (window) {
+ item = window->contentItem();
+
+ const auto windowChildren = window->children();
+ for (QObject *child : windowChildren) {
+ QQuickWindow *childWindow = qobject_cast<QQuickWindow *>(child);
+ if (childWindow) {
+ QQuickAttachedObject *attached = attachedObject(type, childWindow);
+ if (attached)
+ children += attached;
+ }
+ }
+ }
+ }
+
+ if (item) {
+ const auto childItems = item->childItems();
+ for (QQuickItem *child : childItems) {
+ QQuickAttachedObject *attached = attachedObject(type, child);
+ if (attached)
+ children += attached;
+ else
+ children += findAttachedChildren(type, child);
+ }
+ }
+
+ return children;
+}
+
+static QQuickItem *findAttachedItem(QObject *parent)
+{
+ QQuickItem *item = qobject_cast<QQuickItem *>(parent);
+ if (!item) {
+ QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent);
+ if (popup)
+ item = popup->popupItem();
+ }
+ return item;
+}
+
+QQuickAttachedObject::QQuickAttachedObject(QObject *parent) : QObject(parent)
+{
+ attachTo(parent);
+}
+
+QQuickAttachedObject::QQuickAttachedObject(QObjectPrivate &dd, QObject *parent)
+ : QObject(dd, parent)
+{
+ attachTo(parent);
+}
+
+QQuickAttachedObject::~QQuickAttachedObject()
+{
+ detachFrom(parent());
+ setAttachedParent(nullptr);
+}
+
+QList<QQuickAttachedObject *> QQuickAttachedObject::attachedChildren() const
+{
+ return m_attachedChildren;
+}
+
+QQuickAttachedObject *QQuickAttachedObject::attachedParent() const
+{
+ return m_attachedParent;
+}
+
+void QQuickAttachedObject::setAttachedParent(QQuickAttachedObject *parent)
+{
+ if (m_attachedParent != parent) {
+ QQuickAttachedObject *oldParent = m_attachedParent;
+ if (m_attachedParent)
+ m_attachedParent->m_attachedChildren.removeOne(this);
+ m_attachedParent = parent;
+ if (parent)
+ parent->m_attachedChildren.append(this);
+ attachedParentChange(parent, oldParent);
+ }
+}
+
+void QQuickAttachedObject::init()
+{
+ QQuickAttachedObject *attachedParent = findAttachedParent(metaObject(), parent());
+ if (attachedParent)
+ setAttachedParent(attachedParent);
+
+ const QList<QQuickAttachedObject *> attachedChildren = findAttachedChildren(metaObject(), parent());
+ for (QQuickAttachedObject *child : attachedChildren)
+ child->setAttachedParent(this);
+}
+
+void QQuickAttachedObject::attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent)
+{
+ Q_UNUSED(newParent);
+ Q_UNUSED(oldParent);
+}
+
+void QQuickAttachedObject::itemWindowChanged(QQuickWindow *window)
+{
+ QQuickAttachedObject *attachedParent = nullptr;
+ QQuickItem *item = qobject_cast<QQuickItem *>(sender());
+ if (item)
+ attachedParent = findAttachedParent(metaObject(), item);
+ if (!attachedParent)
+ attachedParent = attachedObject(metaObject(), window);
+ setAttachedParent(attachedParent);
+}
+
+void QQuickAttachedObject::itemParentChanged(QQuickItem *item, QQuickItem *parent)
+{
+ Q_UNUSED(parent);
+ setAttachedParent(findAttachedParent(metaObject(), item));
+}
+
+void QQuickAttachedObject::attachTo(QObject *object)
+{
+ QQuickItem *item = findAttachedItem(object);
+ if (item) {
+ connect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObject::itemWindowChanged);
+ QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent);
+ }
+}
+
+void QQuickAttachedObject::detachFrom(QObject *object)
+{
+ QQuickItem *item = findAttachedItem(object);
+ if (item) {
+ disconnect(item, &QQuickItem::windowChanged, this, &QQuickAttachedObject::itemWindowChanged);
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent);
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleattached_p.h b/src/quickcontrols2/qquickattachedobject_p.h
index ed5a5417..5d4194ef 100644
--- a/src/quickcontrols2/qquickstyleattached_p.h
+++ b/src/quickcontrols2/qquickattachedobject_p.h
@@ -34,8 +34,8 @@
**
****************************************************************************/
-#ifndef QQUICKSTYLEATTACHED_P_H
-#define QQUICKSTYLEATTACHED_P_H
+#ifndef QQUICKATTACHEDOBJECT_P_H
+#define QQUICKATTACHEDOBJECT_P_H
//
// W A R N I N G
@@ -52,43 +52,44 @@
#include <QtCore/qlist.h>
#include <QtCore/qobject.h>
#include <QtCore/qpointer.h>
-#include <QtCore/qsharedpointer.h>
#include <QtQuick/private/qquickitemchangelistener_p.h>
#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
QT_BEGIN_NAMESPACE
-class QSettings;
class QQuickWindow;
-class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStyleAttached : public QObject, public QQuickItemChangeListener
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickAttachedObject : public QObject, public QQuickItemChangeListener
{
Q_OBJECT
public:
- explicit QQuickStyleAttached(QObject *parent = nullptr);
- ~QQuickStyleAttached();
+ explicit QQuickAttachedObject(QObject *parent = nullptr);
+ ~QQuickAttachedObject();
- static QSharedPointer<QSettings> settings(const QString &group = QString());
+ QList<QQuickAttachedObject *> attachedChildren() const;
-protected:
- void init();
+ QQuickAttachedObject *attachedParent() const;
+ void setAttachedParent(QQuickAttachedObject *parent);
- QList<QQuickStyleAttached *> childStyles() const;
+protected:
+ QQuickAttachedObject(QObjectPrivate &dd, QObject *parent = nullptr);
- QQuickStyleAttached *parentStyle() const;
- void setParentStyle(QQuickStyleAttached *style);
+ void init();
- virtual void parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent);
+ virtual void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent);
void itemWindowChanged(QQuickWindow *window);
void itemParentChanged(QQuickItem *item, QQuickItem *parent) override;
private:
- QList<QQuickStyleAttached *> m_childStyles;
- QPointer<QQuickStyleAttached> m_parentStyle;
+ void attachTo(QObject *object);
+ void detachFrom(QObject *object);
+
+ QList<QQuickAttachedObject *> m_attachedChildren;
+ QPointer<QQuickAttachedObject> m_attachedParent;
};
QT_END_NAMESPACE
-#endif // QQUICKSTYLEATTACHED_P_H
+#endif // QQUICKATTACHEDOBJECT_P_H
diff --git a/src/quickcontrols2/qquickchecklabel.cpp b/src/quickcontrols2/qquickchecklabel.cpp
new file mode 100644
index 00000000..dccbf77f
--- /dev/null
+++ b/src/quickcontrols2/qquickchecklabel.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickchecklabel_p.h"
+
+QT_BEGIN_NAMESPACE
+
+QQuickCheckLabel::QQuickCheckLabel(QQuickItem *parent) :
+ QQuickText(parent)
+{
+ setHAlign(AlignLeft);
+ setVAlign(AlignVCenter);
+ setElideMode(ElideRight);
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickcolorimageprovider_p.h b/src/quickcontrols2/qquickchecklabel_p.h
index 4b7a34b9..100ef48f 100644
--- a/src/quickcontrols2/qquickcolorimageprovider_p.h
+++ b/src/quickcontrols2/qquickchecklabel_p.h
@@ -34,8 +34,8 @@
**
****************************************************************************/
-#ifndef QQUICKCOLORIMAGEPROVIDER_P_H
-#define QQUICKCOLORIMAGEPROVIDER_P_H
+#ifndef QQUICKCHECKLABEL_P_H
+#define QQUICKCHECKLABEL_P_H
//
// W A R N I N G
@@ -48,22 +48,21 @@
// We mean it.
//
-#include <QtQuick/qquickimageprovider.h>
+#include <QtQuick/private/qquicktext_p.h>
#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
QT_BEGIN_NAMESPACE
-class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImageProvider : public QQuickImageProvider
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickCheckLabel : public QQuickText
{
-public:
- QQuickColorImageProvider(const QString &path);
-
- QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
+ Q_OBJECT
-private:
- QString m_path;
+public:
+ explicit QQuickCheckLabel(QQuickItem *parent = nullptr);
};
QT_END_NAMESPACE
-#endif // QQUICKOCOLORIMAGEPROVIDER_P_H
+QML_DECLARE_TYPE(QQuickCheckLabel)
+
+#endif // QQUICKCHECKLABEL_P_H
diff --git a/src/quickcontrols2/qquickcolorimageprovider.cpp b/src/quickcontrols2/qquickcolor.cpp
index a6e941b3..66ef21b7 100644
--- a/src/quickcontrols2/qquickcolorimageprovider.cpp
+++ b/src/quickcontrols2/qquickcolor.cpp
@@ -34,47 +34,32 @@
**
****************************************************************************/
-#include "qquickcolorimageprovider_p.h"
-
-#include <QtCore/qdebug.h>
-#include <QtGui/qpainter.h>
-#include <QtGui/qguiapplication.h>
-#include <QtGui/qscreen.h>
-#include <QtGui/qicon.h>
+#include "qquickcolor_p.h"
QT_BEGIN_NAMESPACE
-QQuickColorImageProvider::QQuickColorImageProvider(const QString &path)
- : QQuickImageProvider(Image), m_path(path)
+QQuickColor::QQuickColor(QObject *parent) :
+ QObject(parent)
{
}
-QImage QQuickColorImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
+QColor QQuickColor::transparent(const QColor &color, qreal opacity) const
{
- Q_UNUSED(requestedSize);
-
- int sep = id.indexOf(QLatin1Char('/'));
- const QStringRef name = id.leftRef(sep);
- qreal dpr = qApp->primaryScreen()->devicePixelRatio();
- QString file = qt_findAtNxFile(m_path + QLatin1Char('/') + name + QLatin1String(".png"), dpr);
-
- QImage image(file);
- if (image.isNull()) {
- qWarning() << "QQuickColorImageProvider: unknown id:" << id;
- return QImage();
- }
-
- if (size)
- *size = image.size();
+ return QColor(color.red(), color.green(), color.blue(), qBound(0.0, opacity, 1.0) * 255);
+}
- const QString color = id.mid(sep + 1);
- if (!color.isEmpty()) {
- QPainter painter(&image);
- painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
- painter.fillRect(image.rect(), QColor(color));
- }
+QColor QQuickColor::blend(const QColor &a, const QColor &b, qreal factor) const
+{
+ if (factor <= 0.0)
+ return a;
+ if (factor >= 1.0)
+ return b;
- return image;
+ QColor color;
+ color.setRedF(a.redF() * (1.0 - factor) + b.redF() * factor);
+ color.setGreenF(a.greenF() * (1.0 - factor) + b.greenF() * factor);
+ color.setBlueF(a.blueF() * (1.0 - factor) + b.blueF() * factor);
+ return color;
}
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickcolor_p.h b/src/quickcontrols2/qquickcolor_p.h
new file mode 100644
index 00000000..657a9fa4
--- /dev/null
+++ b/src/quickcontrols2/qquickcolor_p.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKCOLOR_P_H
+#define QQUICKCOLOR_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qobject.h>
+#include <QtGui/qcolor.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColor : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit QQuickColor(QObject *parent = nullptr);
+
+ Q_INVOKABLE QColor transparent(const QColor &color, qreal opacity) const;
+ Q_INVOKABLE QColor blend(const QColor &a, const QColor &b, qreal factor) const;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKCOLOR_P_H
diff --git a/src/quickcontrols2/qquickcolorimage.cpp b/src/quickcontrols2/qquickcolorimage.cpp
new file mode 100644
index 00000000..9d24a156
--- /dev/null
+++ b/src/quickcontrols2/qquickcolorimage.cpp
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickcolorimage_p.h"
+
+#include <QtQuick/private/qquickimagebase_p_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickColorImage::QQuickColorImage(QQuickItem *parent)
+ : QQuickImage(parent), m_color(Qt::transparent), m_defaultColor(Qt::transparent)
+{
+}
+
+QColor QQuickColorImage::color() const
+{
+ return m_color;
+}
+
+void QQuickColorImage::setColor(const QColor &color)
+{
+ if (m_color == color)
+ return;
+
+ m_color = color;
+ if (isComponentComplete())
+ load();
+ emit colorChanged();
+}
+
+void QQuickColorImage::resetColor()
+{
+ setColor(Qt::transparent);
+}
+
+QColor QQuickColorImage::defaultColor() const
+{
+ return m_defaultColor;
+}
+
+void QQuickColorImage::setDefaultColor(const QColor &color)
+{
+ if (m_defaultColor == color)
+ return;
+
+ m_defaultColor = color;
+ emit defaultColorChanged();
+}
+
+void QQuickColorImage::resetDefaultColor()
+{
+ setDefaultColor(Qt::transparent);
+}
+
+void QQuickColorImage::pixmapChange()
+{
+ QQuickImage::pixmapChange();
+ if (m_color.alpha() > 0 && m_color != m_defaultColor) {
+ QQuickImageBasePrivate *d = static_cast<QQuickImageBasePrivate *>(QQuickItemPrivate::get(this));
+ QImage image = d->pix.image();
+ if (!image.isNull()) {
+ QPainter painter(&image);
+ painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ painter.fillRect(image.rect(), m_color);
+ d->pix.setImage(image);
+ }
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickcolorimage_p.h b/src/quickcontrols2/qquickcolorimage_p.h
new file mode 100644
index 00000000..873bc2db
--- /dev/null
+++ b/src/quickcontrols2/qquickcolorimage_p.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKCOLORIMAGE_P_H
+#define QQUICKCOLORIMAGE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/qcolor.h>
+#include <QtQuick/private/qquickimage_p.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickColorImage : public QQuickImage
+{
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ color WRITE setColor RESET resetColor NOTIFY colorChanged FINAL)
+ Q_PROPERTY(QColor defaultColor READ defaultColor WRITE setDefaultColor RESET resetDefaultColor NOTIFY defaultColorChanged FINAL)
+
+public:
+ explicit QQuickColorImage(QQuickItem *parent = nullptr);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+ void resetColor();
+
+ QColor defaultColor() const;
+ void setDefaultColor(const QColor &color);
+ void resetDefaultColor();
+
+Q_SIGNALS:
+ void colorChanged();
+ void defaultColorChanged();
+
+protected:
+ void pixmapChange() override;
+
+private:
+ QColor m_color;
+ QColor m_defaultColor;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKCOLORIMAGE_P_H
diff --git a/src/quickcontrols2/qquickiconimage.cpp b/src/quickcontrols2/qquickiconimage.cpp
new file mode 100644
index 00000000..885bc7f9
--- /dev/null
+++ b/src/quickcontrols2/qquickiconimage.cpp
@@ -0,0 +1,220 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickiconimage_p.h"
+#include "qquickiconimage_p_p.h"
+
+#include <QtCore/qmath.h>
+#include <QtQuick/private/qquickimagebase_p_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickIconImagePrivate::QQuickIconImagePrivate()
+ : color(Qt::transparent),
+ updatingIcon(false),
+ isThemeIcon(false),
+ updatingFillMode(false)
+{
+}
+
+bool QQuickIconImagePrivate::updateDevicePixelRatio(qreal targetDevicePixelRatio)
+{
+ if (isThemeIcon) {
+ devicePixelRatio = calculateDevicePixelRatio();
+ return true;
+ }
+
+ return QQuickImagePrivate::updateDevicePixelRatio(targetDevicePixelRatio);
+}
+
+void QQuickIconImagePrivate::updateIcon()
+{
+ Q_Q(QQuickIconImage);
+ // Both geometryChanged() and QQuickImageBase::sourceSizeChanged()
+ // (which we connect to updateIcon() in the constructor) can be called as a result
+ // of updateIcon() changing the various sizes, so we must check that we're not recursing.
+ if (updatingIcon)
+ return;
+
+ updatingIcon = true;
+
+ QSize size = sourcesize;
+ // If no size is specified for theme icons, it will use the smallest available size.
+ if (size.width() <= 0)
+ size.setWidth(q->width());
+ if (size.height() <= 0)
+ size.setHeight(q->height());
+
+ const qreal dpr = calculateDevicePixelRatio();
+ const QIconLoaderEngineEntry *entry = QIconLoaderEngine::entryForSize(icon, size * dpr, qCeil(dpr));
+
+ if (entry) {
+ QQmlContext *context = qmlContext(q);
+ const QUrl entryUrl = QUrl::fromLocalFile(entry->filename);
+ url = context ? context->resolvedUrl(entryUrl) : entryUrl;
+ isThemeIcon = true;
+ } else {
+ url = source;
+ isThemeIcon = false;
+ }
+ q->load();
+
+ updatingIcon = false;
+}
+
+void QQuickIconImagePrivate::updateFillMode()
+{
+ Q_Q(QQuickIconImage);
+ // If we start with a sourceSize of 28x28 and then set sourceSize.width to 24, the fillMode
+ // will change to PreserveAspectFit (because pixmapSize.width() > width()), which causes the
+ // pixmap to be reloaded at its original size of 28x28, which causes the fillMode to change
+ // to Pad (because pixmapSize.width() <= width()), and so on.
+ if (updatingFillMode)
+ return;
+
+ updatingFillMode = true;
+
+ const QSize pixmapSize = QSize(pix.width(), pix.height()) / calculateDevicePixelRatio();
+ if (pixmapSize.width() > q->width() || pixmapSize.height() > q->height())
+ q->setFillMode(QQuickImage::PreserveAspectFit);
+ else
+ q->setFillMode(QQuickImage::Pad);
+
+ updatingFillMode = false;
+}
+
+qreal QQuickIconImagePrivate::calculateDevicePixelRatio() const
+{
+ Q_Q(const QQuickIconImage);
+ return q->window() ? q->window()->effectiveDevicePixelRatio() : qApp->devicePixelRatio();
+}
+
+QQuickIconImage::QQuickIconImage(QQuickItem *parent)
+ : QQuickImage(*(new QQuickIconImagePrivate), parent)
+{
+ setFillMode(Pad);
+}
+
+QString QQuickIconImage::name() const
+{
+ Q_D(const QQuickIconImage);
+ return d->icon.iconName;
+}
+
+void QQuickIconImage::setName(const QString &name)
+{
+ Q_D(QQuickIconImage);
+ if (d->icon.iconName == name)
+ return;
+
+ d->icon = QIconLoader::instance()->loadIcon(name);
+ if (isComponentComplete())
+ d->updateIcon();
+ emit nameChanged();
+}
+
+QColor QQuickIconImage::color() const
+{
+ Q_D(const QQuickIconImage);
+ return d->color;
+}
+
+void QQuickIconImage::setColor(const QColor &color)
+{
+ Q_D(QQuickIconImage);
+ if (d->color == color)
+ return;
+
+ d->color = color;
+ if (isComponentComplete())
+ d->updateIcon();
+ emit colorChanged();
+}
+
+void QQuickIconImage::setSource(const QUrl &source)
+{
+ Q_D(QQuickIconImage);
+ if (d->source == source)
+ return;
+
+ d->source = source;
+ if (isComponentComplete())
+ d->updateIcon();
+ emit sourceChanged(source);
+}
+
+void QQuickIconImage::componentComplete()
+{
+ Q_D(QQuickIconImage);
+ QQuickImage::componentComplete();
+ d->updateIcon();
+ QObjectPrivate::connect(this, &QQuickImageBase::sourceSizeChanged, d, &QQuickIconImagePrivate::updateIcon);
+}
+
+void QQuickIconImage::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ Q_D(QQuickIconImage);
+ QQuickImage::geometryChanged(newGeometry, oldGeometry);
+ if (isComponentComplete() && newGeometry.size() != oldGeometry.size())
+ d->updateIcon();
+}
+
+void QQuickIconImage::itemChange(ItemChange change, const ItemChangeData &value)
+{
+ Q_D(QQuickIconImage);
+ if (change == ItemDevicePixelRatioHasChanged)
+ d->updateIcon();
+ QQuickImage::itemChange(change, value);
+}
+
+void QQuickIconImage::pixmapChange()
+{
+ Q_D(QQuickIconImage);
+ QQuickImage::pixmapChange();
+ d->updateFillMode();
+
+ if (d->color.alpha() > 0) {
+ QImage image = d->pix.image();
+ if (!image.isNull()) {
+ QPainter painter(&image);
+ painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
+ painter.fillRect(image.rect(), d->color);
+ d->pix.setImage(image);
+ }
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickiconimage_p.h b/src/quickcontrols2/qquickiconimage_p.h
new file mode 100644
index 00000000..b1af767e
--- /dev/null
+++ b/src/quickcontrols2/qquickiconimage_p.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKICONIMAGE_P_H
+#define QQUICKICONIMAGE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/private/qquickimage_p.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickIconImagePrivate;
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImage : public QQuickImage
+{
+ Q_OBJECT
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL)
+
+public:
+ explicit QQuickIconImage(QQuickItem *parent = nullptr);
+
+ QString name() const;
+ void setName(const QString &name);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ void setSource(const QUrl &url) override;
+
+Q_SIGNALS:
+ void nameChanged();
+ void colorChanged();
+
+protected:
+ void componentComplete() override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
+ void itemChange(ItemChange change, const ItemChangeData &value) override;
+ void pixmapChange() override;
+
+private:
+ Q_DISABLE_COPY(QQuickIconImage)
+ Q_DECLARE_PRIVATE(QQuickIconImage)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickIconImage)
+
+#endif // QQUICKICONIMAGE_P_H
diff --git a/src/quickcontrols2/qquickiconimage_p_p.h b/src/quickcontrols2/qquickiconimage_p_p.h
new file mode 100644
index 00000000..8e8012bf
--- /dev/null
+++ b/src/quickcontrols2/qquickiconimage_p_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKICONIMAGE_P_P_H
+#define QQUICKICONIMAGE_P_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/private/qquickimage_p_p.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+#include <QtGui/private/qiconloader_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconImagePrivate : public QQuickImagePrivate
+{
+ Q_DECLARE_PUBLIC(QQuickIconImage)
+
+public:
+ QQuickIconImagePrivate();
+
+ void updateIcon();
+ void updateFillMode();
+ qreal calculateDevicePixelRatio() const;
+ bool updateDevicePixelRatio(qreal targetDevicePixelRatio) override;
+
+ QUrl source;
+ QColor color;
+ QThemeIconInfo icon;
+ bool updatingIcon;
+ bool isThemeIcon;
+ bool updatingFillMode;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKICONIMAGE_P_P_H
diff --git a/src/quickcontrols2/qquickiconlabel.cpp b/src/quickcontrols2/qquickiconlabel.cpp
new file mode 100644
index 00000000..960d9905
--- /dev/null
+++ b/src/quickcontrols2/qquickiconlabel.cpp
@@ -0,0 +1,651 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickiconlabel_p.h"
+#include "qquickiconlabel_p_p.h"
+#include "qquickiconimage_p.h"
+#include "qquickmnemoniclabel_p.h"
+
+#include <QtGui/private/qguiapplication_p.h>
+#include <QtQuick/private/qquickitem_p.h>
+#include <QtQuick/private/qquicktext_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static void beginClass(QQuickItem *item)
+{
+ if (QQmlParserStatus *parserStatus = qobject_cast<QQmlParserStatus *>(item))
+ parserStatus->classBegin();
+}
+
+static void completeComponent(QQuickItem *item)
+{
+ if (QQmlParserStatus *parserStatus = qobject_cast<QQmlParserStatus *>(item))
+ parserStatus->componentComplete();
+}
+
+QQuickIconLabelPrivate::QQuickIconLabelPrivate()
+ : mirrored(false),
+ display(QQuickIconLabel::TextBesideIcon),
+ alignment(Qt::AlignCenter),
+ spacing(0),
+ topPadding(0),
+ leftPadding(0),
+ rightPadding(0),
+ bottomPadding(0),
+ image(nullptr),
+ label(nullptr)
+{
+}
+
+bool QQuickIconLabelPrivate::hasIcon() const
+{
+ return display != QQuickIconLabel::TextOnly && !icon.isEmpty();
+}
+
+bool QQuickIconLabelPrivate::hasText() const
+{
+ return display != QQuickIconLabel::IconOnly && !text.isEmpty();
+}
+
+bool QQuickIconLabelPrivate::createImage()
+{
+ Q_Q(QQuickIconLabel);
+ if (image)
+ return false;
+
+ image = new QQuickIconImage(q);
+ watchChanges(image);
+ beginClass(image);
+ image->setObjectName(QStringLiteral("image"));
+ image->setName(icon.name());
+ image->setSource(icon.source());
+ image->setSourceSize(QSize(icon.width(), icon.height()));
+ image->setColor(icon.color());
+ QQmlEngine::setContextForObject(image, qmlContext(q));
+ if (componentComplete)
+ completeComponent(image);
+ return true;
+}
+
+bool QQuickIconLabelPrivate::destroyImage()
+{
+ if (!image)
+ return false;
+
+ unwatchChanges(image);
+ delete image;
+ image = nullptr;
+ return true;
+}
+
+bool QQuickIconLabelPrivate::updateImage()
+{
+ if (!hasIcon())
+ return destroyImage();
+ return createImage();
+}
+
+void QQuickIconLabelPrivate::syncImage()
+{
+ if (!image || icon.isEmpty())
+ return;
+
+ image->setName(icon.name());
+ image->setSource(icon.source());
+ image->setSourceSize(QSize(icon.width(), icon.height()));
+ image->setColor(icon.color());
+ const int valign = alignment & Qt::AlignVertical_Mask;
+ image->setVerticalAlignment(static_cast<QQuickImage::VAlignment>(valign));
+ const int halign = alignment & Qt::AlignHorizontal_Mask;
+ image->setHorizontalAlignment(static_cast<QQuickImage::HAlignment>(halign));
+}
+
+void QQuickIconLabelPrivate::updateOrSyncImage()
+{
+ if (updateImage()) {
+ if (componentComplete) {
+ updateImplicitSize();
+ layout();
+ }
+ } else {
+ syncImage();
+ }
+}
+
+bool QQuickIconLabelPrivate::createLabel()
+{
+ Q_Q(QQuickIconLabel);
+ if (label)
+ return false;
+
+ label = new QQuickMnemonicLabel(q);
+ watchChanges(label);
+ beginClass(label);
+ label->setObjectName(QStringLiteral("label"));
+ label->setFont(font);
+ label->setColor(color);
+ label->setElideMode(QQuickText::ElideRight);
+ const int valign = alignment & Qt::AlignVertical_Mask;
+ label->setVAlign(static_cast<QQuickText::VAlignment>(valign));
+ const int halign = alignment & Qt::AlignHorizontal_Mask;
+ label->setHAlign(static_cast<QQuickText::HAlignment>(halign));
+ label->setText(text);
+ if (componentComplete)
+ completeComponent(label);
+ return true;
+}
+
+bool QQuickIconLabelPrivate::destroyLabel()
+{
+ if (!label)
+ return false;
+
+ unwatchChanges(label);
+ delete label;
+ label = nullptr;
+ return true;
+}
+
+bool QQuickIconLabelPrivate::updateLabel()
+{
+ if (!hasText())
+ return destroyLabel();
+ return createLabel();
+}
+
+void QQuickIconLabelPrivate::syncLabel()
+{
+ if (!label)
+ return;
+
+ label->setText(text);
+}
+
+void QQuickIconLabelPrivate::updateOrSyncLabel()
+{
+ if (updateLabel()) {
+ if (componentComplete) {
+ updateImplicitSize();
+ layout();
+ }
+ } else {
+ syncLabel();
+ }
+}
+
+void QQuickIconLabelPrivate::updateImplicitSize()
+{
+ Q_Q(QQuickIconLabel);
+ const bool showIcon = image && hasIcon();
+ const bool showText = label && hasText();
+ const qreal horizontalPadding = leftPadding + rightPadding;
+ const qreal verticalPadding = topPadding + bottomPadding;
+ const qreal iconImplicitWidth = showIcon ? image->implicitWidth() : 0;
+ const qreal iconImplicitHeight = showIcon ? image->implicitHeight() : 0;
+ const qreal textImplicitWidth = showText ? label->implicitWidth() : 0;
+ const qreal textImplicitHeight = showText ? label->implicitHeight() : 0;
+ const qreal effectiveSpacing = showText && showIcon && image->implicitWidth() > 0 ? spacing : 0;
+ const qreal implicitWidth = display == QQuickIconLabel::TextBesideIcon ? iconImplicitWidth + textImplicitWidth + effectiveSpacing
+ : qMax(iconImplicitWidth, textImplicitWidth);
+ const qreal implicitHeight = display == QQuickIconLabel::TextUnderIcon ? iconImplicitHeight + textImplicitHeight + effectiveSpacing
+ : qMax(iconImplicitHeight, textImplicitHeight);
+ q->setImplicitSize(implicitWidth + horizontalPadding, implicitHeight + verticalPadding);
+}
+
+// adapted from QStyle::alignedRect()
+static QRectF alignedRect(bool mirrored, Qt::Alignment alignment, const QSizeF &size, const QRectF &rectangle)
+{
+ alignment = QGuiApplicationPrivate::visualAlignment(mirrored ? Qt::RightToLeft : Qt::LeftToRight, alignment);
+ qreal x = rectangle.x();
+ qreal y = rectangle.y();
+ const qreal w = size.width();
+ const qreal h = size.height();
+ if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
+ y += rectangle.height() / 2 - h / 2;
+ else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
+ y += rectangle.height() - h;
+ if ((alignment & Qt::AlignRight) == Qt::AlignRight)
+ x += rectangle.width() - w;
+ else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
+ x += rectangle.width() / 2 - w / 2;
+ return QRectF(x, y, w, h);
+}
+
+void QQuickIconLabelPrivate::layout()
+{
+ if (!componentComplete)
+ return;
+
+ const qreal availableWidth = width - leftPadding - rightPadding;
+ const qreal availableHeight = height - topPadding - bottomPadding;
+
+ switch (display) {
+ case QQuickIconLabel::IconOnly:
+ if (image) {
+ const QRectF iconRect = alignedRect(mirrored, alignment,
+ QSizeF(qMin(image->implicitWidth(), availableWidth),
+ qMin(image->implicitHeight(), availableHeight)),
+ QRectF(leftPadding, topPadding, availableWidth, availableHeight));
+ image->setSize(iconRect.size());
+ image->setPosition(iconRect.topLeft());
+ }
+ break;
+ case QQuickIconLabel::TextOnly:
+ if (label) {
+ const QRectF textRect = alignedRect(mirrored, alignment,
+ QSizeF(qMin(label->implicitWidth(), availableWidth),
+ qMin(label->implicitHeight(), availableHeight)),
+ QRectF(leftPadding, topPadding, availableWidth, availableHeight));
+ label->setSize(textRect.size());
+ label->setPosition(textRect.topLeft());
+ }
+ break;
+
+ case QQuickIconLabel::TextUnderIcon: {
+ // Work out the sizes first, as the positions depend on them.
+ QSizeF iconSize;
+ QSizeF textSize;
+ if (image) {
+ iconSize.setWidth(qMin(image->implicitWidth(), availableWidth));
+ iconSize.setHeight(qMin(image->implicitHeight(), availableHeight));
+ }
+ qreal effectiveSpacing = 0;
+ if (label) {
+ if (!iconSize.isEmpty())
+ effectiveSpacing = spacing;
+ textSize.setWidth(qMin(label->implicitWidth(), availableWidth));
+ textSize.setHeight(qMin(label->implicitHeight(), availableHeight - iconSize.height() - effectiveSpacing));
+ }
+
+ QRectF combinedRect = alignedRect(mirrored, alignment,
+ QSizeF(qMax(iconSize.width(), textSize.width()),
+ iconSize.height() + effectiveSpacing + textSize.height()),
+ QRectF(leftPadding, topPadding, availableWidth, availableHeight));
+ if (image) {
+ QRectF iconRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignTop, iconSize, combinedRect);
+ image->setSize(iconRect.size());
+ image->setPosition(iconRect.topLeft());
+ }
+ if (label) {
+ QRectF textRect = alignedRect(mirrored, Qt::AlignHCenter | Qt::AlignBottom, textSize, combinedRect);
+ label->setSize(textRect.size());
+ label->setPosition(textRect.topLeft());
+ }
+ break;
+ }
+
+ case QQuickIconLabel::TextBesideIcon:
+ default:
+ // Work out the sizes first, as the positions depend on them.
+ QSizeF iconSize(0, 0);
+ QSizeF textSize(0, 0);
+ if (image) {
+ iconSize.setWidth(qMin(image->implicitWidth(), availableWidth));
+ iconSize.setHeight(qMin(image->implicitHeight(), availableHeight));
+ }
+ qreal effectiveSpacing = 0;
+ if (label) {
+ if (!iconSize.isEmpty())
+ effectiveSpacing = spacing;
+ textSize.setWidth(qMin(label->implicitWidth(), availableWidth - iconSize.width() - effectiveSpacing));
+ textSize.setHeight(qMin(label->implicitHeight(), availableHeight));
+ }
+
+ const QRectF combinedRect = alignedRect(mirrored, alignment,
+ QSizeF(iconSize.width() + effectiveSpacing + textSize.width(),
+ qMax(iconSize.height(), textSize.height())),
+ QRectF(leftPadding, topPadding, availableWidth, availableHeight));
+ if (image) {
+ const QRectF iconRect = alignedRect(mirrored, Qt::AlignLeft | Qt::AlignVCenter, iconSize, combinedRect);
+ image->setSize(iconRect.size());
+ image->setPosition(iconRect.topLeft());
+ }
+ if (label) {
+ const QRectF textRect = alignedRect(mirrored, Qt::AlignRight | Qt::AlignVCenter, textSize, combinedRect);
+ label->setSize(textRect.size());
+ label->setPosition(textRect.topLeft());
+ }
+ break;
+ }
+}
+
+static const QQuickItemPrivate::ChangeTypes itemChangeTypes =
+ QQuickItemPrivate::ImplicitWidth
+ | QQuickItemPrivate::ImplicitHeight
+ | QQuickItemPrivate::Destroyed;
+
+void QQuickIconLabelPrivate::watchChanges(QQuickItem *item)
+{
+ QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
+ itemPrivate->addItemChangeListener(this, itemChangeTypes);
+}
+
+void QQuickIconLabelPrivate::unwatchChanges(QQuickItem* item)
+{
+ QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
+ itemPrivate->removeItemChangeListener(this, itemChangeTypes);
+}
+
+void QQuickIconLabelPrivate::itemImplicitWidthChanged(QQuickItem *)
+{
+ updateImplicitSize();
+ layout();
+}
+
+void QQuickIconLabelPrivate::itemImplicitHeightChanged(QQuickItem *)
+{
+ updateImplicitSize();
+ layout();
+}
+
+void QQuickIconLabelPrivate::itemDestroyed(QQuickItem *item)
+{
+ unwatchChanges(item);
+ if (item == image)
+ image = nullptr;
+ else if (item == label)
+ label = nullptr;
+}
+
+QQuickIconLabel::QQuickIconLabel(QQuickItem *parent)
+ : QQuickItem(*(new QQuickIconLabelPrivate), parent)
+{
+}
+
+QQuickIconLabel::~QQuickIconLabel()
+{
+ Q_D(QQuickIconLabel);
+ if (d->image)
+ d->unwatchChanges(d->image);
+ if (d->label)
+ d->unwatchChanges(d->label);
+}
+
+QQuickIcon QQuickIconLabel::icon() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->icon;
+}
+
+void QQuickIconLabel::setIcon(const QQuickIcon &icon)
+{
+ Q_D(QQuickIconLabel);
+ if (d->icon == icon)
+ return;
+
+ d->icon = icon;
+ d->updateOrSyncImage();
+}
+
+QString QQuickIconLabel::text() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->text;
+}
+
+void QQuickIconLabel::setText(const QString text)
+{
+ Q_D(QQuickIconLabel);
+ if (d->text == text)
+ return;
+
+ d->text = text;
+ d->updateOrSyncLabel();
+}
+
+QFont QQuickIconLabel::font() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->font;
+}
+
+void QQuickIconLabel::setFont(const QFont &font)
+{
+ Q_D(QQuickIconLabel);
+ if (d->font == font)
+ return;
+
+ d->font = font;
+ if (d->label)
+ d->label->setFont(font);
+}
+
+QColor QQuickIconLabel::color() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->color;
+}
+
+void QQuickIconLabel::setColor(const QColor &color)
+{
+ Q_D(QQuickIconLabel);
+ if (d->color == color)
+ return;
+
+ d->color = color;
+ if (d->label)
+ d->label->setColor(color);
+}
+
+QQuickIconLabel::Display QQuickIconLabel::display() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->display;
+}
+
+void QQuickIconLabel::setDisplay(Display display)
+{
+ Q_D(QQuickIconLabel);
+ if (d->display == display)
+ return;
+
+ d->display = display;
+ d->updateImage();
+ d->updateLabel();
+ d->updateImplicitSize();
+ d->layout();
+}
+
+qreal QQuickIconLabel::spacing() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->spacing;
+}
+
+void QQuickIconLabel::setSpacing(qreal spacing)
+{
+ Q_D(QQuickIconLabel);
+ if (qFuzzyCompare(d->spacing, spacing))
+ return;
+
+ d->spacing = spacing;
+ if (d->image && d->label) {
+ d->updateImplicitSize();
+ d->layout();
+ }
+}
+
+bool QQuickIconLabel::isMirrored() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->mirrored;
+}
+
+void QQuickIconLabel::setMirrored(bool mirrored)
+{
+ Q_D(QQuickIconLabel);
+ if (d->mirrored == mirrored)
+ return;
+
+ d->mirrored = mirrored;
+ d->layout();
+}
+
+Qt::Alignment QQuickIconLabel::alignment() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->alignment;
+}
+
+void QQuickIconLabel::setAlignment(Qt::Alignment alignment)
+{
+ Q_D(QQuickIconLabel);
+ const int valign = alignment & Qt::AlignVertical_Mask;
+ const int halign = alignment & Qt::AlignHorizontal_Mask;
+ const uint align = (valign ? valign : Qt::AlignVCenter) | (halign ? halign : Qt::AlignHCenter);
+ if (d->alignment == align)
+ return;
+
+ d->alignment = static_cast<Qt::Alignment>(align);
+ if (d->label) {
+ d->label->setVAlign(static_cast<QQuickText::VAlignment>(valign));
+ d->label->setHAlign(static_cast<QQuickText::HAlignment>(halign));
+ }
+ if (d->image) {
+ d->image->setVerticalAlignment(static_cast<QQuickImage::VAlignment>(valign));
+ d->image->setHorizontalAlignment(static_cast<QQuickImage::HAlignment>(halign));
+ }
+ d->layout();
+}
+
+qreal QQuickIconLabel::topPadding() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->topPadding;
+}
+
+void QQuickIconLabel::setTopPadding(qreal padding)
+{
+ Q_D(QQuickIconLabel);
+ if (qFuzzyCompare(d->topPadding, padding))
+ return;
+
+ d->topPadding = padding;
+ d->updateImplicitSize();
+ d->layout();
+}
+
+void QQuickIconLabel::resetTopPadding()
+{
+ setTopPadding(0);
+}
+
+qreal QQuickIconLabel::leftPadding() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->leftPadding;
+}
+
+void QQuickIconLabel::setLeftPadding(qreal padding)
+{
+ Q_D(QQuickIconLabel);
+ if (qFuzzyCompare(d->leftPadding, padding))
+ return;
+
+ d->leftPadding = padding;
+ d->updateImplicitSize();
+ d->layout();
+}
+
+void QQuickIconLabel::resetLeftPadding()
+{
+ setLeftPadding(0);
+}
+
+qreal QQuickIconLabel::rightPadding() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->rightPadding;
+}
+
+void QQuickIconLabel::setRightPadding(qreal padding)
+{
+ Q_D(QQuickIconLabel);
+ if (qFuzzyCompare(d->rightPadding, padding))
+ return;
+
+ d->rightPadding = padding;
+ d->updateImplicitSize();
+ d->layout();
+}
+
+void QQuickIconLabel::resetRightPadding()
+{
+ setRightPadding(0);
+}
+
+qreal QQuickIconLabel::bottomPadding() const
+{
+ Q_D(const QQuickIconLabel);
+ return d->bottomPadding;
+}
+
+void QQuickIconLabel::setBottomPadding(qreal padding)
+{
+ Q_D(QQuickIconLabel);
+ if (qFuzzyCompare(d->bottomPadding, padding))
+ return;
+
+ d->bottomPadding = padding;
+ d->updateImplicitSize();
+ d->layout();
+}
+
+void QQuickIconLabel::resetBottomPadding()
+{
+ setBottomPadding(0);
+}
+
+void QQuickIconLabel::componentComplete()
+{
+ Q_D(QQuickIconLabel);
+ if (d->image)
+ completeComponent(d->image);
+ if (d->label)
+ completeComponent(d->label);
+ QQuickItem::componentComplete();
+ d->layout();
+}
+
+void QQuickIconLabel::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ Q_D(QQuickIconLabel);
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+ d->layout();
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickiconlabel_p.h b/src/quickcontrols2/qquickiconlabel_p.h
new file mode 100644
index 00000000..df79dbf2
--- /dev/null
+++ b/src/quickcontrols2/qquickiconlabel_p.h
@@ -0,0 +1,140 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKICONLABEL_P_H
+#define QQUICKICONLABEL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/qquickitem.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+#include <QtQuickTemplates2/private/qquickicon_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickIconLabelPrivate;
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickIconLabel : public QQuickItem
+{
+ Q_OBJECT
+ Q_PROPERTY(QQuickIcon icon READ icon WRITE setIcon FINAL)
+ Q_PROPERTY(QString text READ text WRITE setText FINAL)
+ Q_PROPERTY(QFont font READ font WRITE setFont FINAL)
+ Q_PROPERTY(QColor color READ color WRITE setColor FINAL)
+ Q_PROPERTY(Display display READ display WRITE setDisplay FINAL)
+ Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing FINAL)
+ Q_PROPERTY(bool mirrored READ isMirrored WRITE setMirrored FINAL)
+ Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment FINAL)
+ Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding FINAL)
+ Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding FINAL)
+ Q_PROPERTY(qreal rightPadding READ rightPadding WRITE setRightPadding RESET resetRightPadding FINAL)
+ Q_PROPERTY(qreal bottomPadding READ bottomPadding WRITE setBottomPadding RESET resetBottomPadding FINAL)
+
+public:
+ enum Display {
+ IconOnly,
+ TextOnly,
+ TextBesideIcon,
+ TextUnderIcon
+ };
+ Q_ENUM(Display)
+
+ explicit QQuickIconLabel(QQuickItem *parent = nullptr);
+ ~QQuickIconLabel();
+
+ QQuickIcon icon() const;
+ void setIcon(const QQuickIcon &icon);
+
+ QString text() const;
+ void setText(const QString text);
+
+ QFont font() const;
+ void setFont(const QFont &font);
+
+ QColor color() const;
+ void setColor(const QColor &color);
+
+ Display display() const;
+ void setDisplay(Display display);
+
+ qreal spacing() const;
+ void setSpacing(qreal spacing);
+
+ bool isMirrored() const;
+ void setMirrored(bool mirrored);
+
+ Qt::Alignment alignment() const;
+ void setAlignment(Qt::Alignment alignment);
+
+ qreal topPadding() const;
+ void setTopPadding(qreal padding);
+ void resetTopPadding();
+
+ qreal leftPadding() const;
+ void setLeftPadding(qreal padding);
+ void resetLeftPadding();
+
+ qreal rightPadding() const;
+ void setRightPadding(qreal padding);
+ void resetRightPadding();
+
+ qreal bottomPadding() const;
+ void setBottomPadding(qreal padding);
+ void resetBottomPadding();
+
+protected:
+ void componentComplete() override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
+
+private:
+ Q_DISABLE_COPY(QQuickIconLabel)
+ Q_DECLARE_PRIVATE(QQuickIconLabel)
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickIconLabel)
+
+#endif // QQUICKICONLABEL_P_H
diff --git a/src/quickcontrols2/qquickiconlabel_p_p.h b/src/quickcontrols2/qquickiconlabel_p_p.h
new file mode 100644
index 00000000..f0f4df4c
--- /dev/null
+++ b/src/quickcontrols2/qquickiconlabel_p_p.h
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKICONLABEL_P_P_H
+#define QQUICKICONLABEL_P_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/private/qquickitem_p.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+#include <QtQuickControls2/private/qquickiconlabel_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickIconImage;
+class QQuickMnemonicLabel;
+
+class QQuickIconLabelPrivate : public QQuickItemPrivate, public QQuickItemChangeListener
+{
+ Q_DECLARE_PUBLIC(QQuickIconLabel)
+
+public:
+ explicit QQuickIconLabelPrivate();
+
+ bool hasIcon() const;
+ bool hasText() const;
+
+ bool createImage();
+ bool destroyImage();
+ bool updateImage();
+ void syncImage();
+ void updateOrSyncImage();
+
+ bool createLabel();
+ bool destroyLabel();
+ bool updateLabel();
+ void syncLabel();
+ void updateOrSyncLabel();
+
+ void updateImplicitSize();
+ void layout();
+
+ void watchChanges(QQuickItem *item);
+ void unwatchChanges(QQuickItem *item);
+ void setPositioningDirty();
+
+ bool isLeftToRight() const;
+
+ void itemImplicitWidthChanged(QQuickItem *) override;
+ void itemImplicitHeightChanged(QQuickItem *) override;
+ void itemDestroyed(QQuickItem *item) override;
+
+ bool mirrored;
+ QQuickIconLabel::Display display;
+ Qt::Alignment alignment;
+ qreal spacing;
+ qreal topPadding;
+ qreal leftPadding;
+ qreal rightPadding;
+ qreal bottomPadding;
+ QFont font;
+ QColor color;
+ QString text;
+ QQuickIcon icon;
+ QQuickIconImage *image;
+ QQuickMnemonicLabel *label;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKICONLABEL_P_P_H
diff --git a/src/quickcontrols2/qquickmnemoniclabel.cpp b/src/quickcontrols2/qquickmnemoniclabel.cpp
new file mode 100644
index 00000000..9c8e9ab1
--- /dev/null
+++ b/src/quickcontrols2/qquickmnemoniclabel.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickmnemoniclabel_p.h"
+
+#include <QtQuick/private/qquicktext_p_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickMnemonicLabel::QQuickMnemonicLabel(QQuickItem *parent)
+ : QQuickText(parent),
+ m_mnemonicVisible(true)
+{
+}
+
+QString QQuickMnemonicLabel::text() const
+{
+ return m_fullText;
+}
+
+void QQuickMnemonicLabel::setText(const QString &text)
+{
+ if (m_fullText == text)
+ return;
+
+ m_fullText = text;
+ updateMnemonic();
+}
+
+bool QQuickMnemonicLabel::isMnemonicVisible() const
+{
+ return m_mnemonicVisible;
+}
+
+void QQuickMnemonicLabel::setMnemonicVisible(bool visible)
+{
+ if (m_mnemonicVisible == visible)
+ return;
+
+ m_mnemonicVisible = visible;
+ updateMnemonic();
+
+ if (isComponentComplete())
+ forceLayout();
+}
+
+static QTextLayout::FormatRange underlineRange(int start, int length = 1)
+{
+ QTextLayout::FormatRange range;
+ range.start = start;
+ range.length = length;
+ range.format.setFontUnderline(true);
+ return range;
+}
+
+// based on QPlatformTheme::removeMnemonics()
+void QQuickMnemonicLabel::updateMnemonic()
+{
+ QString text(m_fullText.size(), 0);
+ int idx = 0;
+ int pos = 0;
+ int len = m_fullText.length();
+ QVector<QTextLayout::FormatRange> formats;
+ while (len) {
+ if (m_fullText.at(pos) == QLatin1Char('&') && (len == 1 || m_fullText.at(pos + 1) != QLatin1Char('&'))) {
+ if (m_mnemonicVisible && (pos == 0 || m_fullText.at(pos - 1) != QLatin1Char('&')))
+ formats += underlineRange(pos);
+ ++pos;
+ --len;
+ if (len == 0)
+ break;
+ } else if (m_fullText.at(pos) == QLatin1Char('(') && len >= 4 &&
+ m_fullText.at(pos + 1) == QLatin1Char('&') &&
+ m_fullText.at(pos + 2) != QLatin1Char('&') &&
+ m_fullText.at(pos + 3) == QLatin1Char(')')) {
+ // a mnemonic with format "\s*(&X)"
+ if (m_mnemonicVisible) {
+ formats += underlineRange(pos + 1);
+ } else {
+ int n = 0;
+ while (idx > n && text.at(idx - n - 1).isSpace())
+ ++n;
+ idx -= n;
+ pos += 4;
+ len -= 4;
+ continue;
+ }
+ }
+ text[idx] = m_fullText.at(pos);
+ ++pos;
+ ++idx;
+ --len;
+ }
+ text.truncate(idx);
+
+ QQuickTextPrivate::get(this)->layout.setFormats(formats);
+ QQuickText::setText(text);
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickmnemoniclabel_p.h b/src/quickcontrols2/qquickmnemoniclabel_p.h
new file mode 100644
index 00000000..33bc1e08
--- /dev/null
+++ b/src/quickcontrols2/qquickmnemoniclabel_p.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKMNEMONICLABEL_P_H
+#define QQUICKMNEMONICLABEL_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/private/qquicktext_p.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickMnemonicLabel : public QQuickText
+{
+ Q_OBJECT
+ Q_PROPERTY(QString text READ text WRITE setText FINAL)
+ Q_PROPERTY(bool mnemonicVisible READ isMnemonicVisible WRITE setMnemonicVisible FINAL)
+
+public:
+ explicit QQuickMnemonicLabel(QQuickItem *parent = nullptr);
+
+ QString text() const;
+ void setText(const QString &text);
+
+ bool isMnemonicVisible() const;
+ void setMnemonicVisible(bool visible);
+
+private:
+ void updateMnemonic();
+
+ bool m_mnemonicVisible;
+ QString m_fullText;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickMnemonicLabel)
+
+#endif // QQUICKMNEMONICLABEL_P_H
diff --git a/src/quickcontrols2/qquickpaddedrectangle.cpp b/src/quickcontrols2/qquickpaddedrectangle.cpp
index 3555d6d7..f7088d54 100644
--- a/src/quickcontrols2/qquickpaddedrectangle.cpp
+++ b/src/quickcontrols2/qquickpaddedrectangle.cpp
@@ -200,7 +200,10 @@ QSGNode *QQuickPaddedRectangle::updatePaintNode(QSGNode *node, UpdatePaintNodeDa
m.translate(left, top);
transformNode->setMatrix(m);
- rectNode->setRect(boundingRect().adjusted(0, 0, -left-right, -top-bottom));
+ qreal w = qMax<qreal>(0.0, width() -left-right);
+ qreal h = qMax<qreal>(0.0, height() -top-bottom);
+
+ rectNode->setRect(QRectF(0, 0, w, h));
rectNode->update();
}
}
diff --git a/src/quickcontrols2/qquickproxytheme_p.h b/src/quickcontrols2/qquickproxytheme_p.h
index 04f800f4..2d271e8c 100644
--- a/src/quickcontrols2/qquickproxytheme_p.h
+++ b/src/quickcontrols2/qquickproxytheme_p.h
@@ -53,7 +53,7 @@
QT_BEGIN_NAMESPACE
-class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickProxyTheme : public QPlatformTheme
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickProxyTheme : public QPlatformTheme
{
public:
explicit QQuickProxyTheme(QPlatformTheme *theme = nullptr);
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index c57dc7ac..800341d7 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -36,13 +36,17 @@
#include "qquickstyle.h"
#include "qquickstyle_p.h"
-#include "qquickstyleattached_p.h"
#include <QtCore/qdir.h>
+#include <QtCore/qfile.h>
#include <QtCore/qdebug.h>
#include <QtCore/qsettings.h>
+#include <QtCore/qfileselector.h>
#include <QtCore/qlibraryinfo.h>
+#include <QtGui/qcolor.h>
+#include <QtGui/qpalette.h>
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/qpa/qplatformtheme.h>
#include <QtQml/private/qqmlmetatype_p.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlfile.h>
@@ -176,7 +180,7 @@ struct QQuickStyleSpec
setFallbackStyle(QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_FALLBACK_STYLE")), "QT_QUICK_CONTROLS_FALLBACK_STYLE");
#if QT_CONFIG(settings)
if (style.isEmpty() || fallbackStyle.isEmpty()) {
- QSharedPointer<QSettings> settings = QQuickStyleAttached::settings(QStringLiteral("Controls"));
+ QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral("Controls"));
if (settings) {
if (style.isEmpty())
style = settings->value(QStringLiteral("Style")).toString();
@@ -235,7 +239,7 @@ struct QQuickStyleSpec
{
if (configFilePath.isEmpty()) {
configFilePath = QFile::decodeName(qgetenv("QT_QUICK_CONTROLS_CONF"));
- if (!QFile::exists(configFilePath)) {
+ if (configFilePath.isEmpty() || !QFile::exists(configFilePath)) {
if (!configFilePath.isEmpty())
qWarning("QT_QUICK_CONTROLS_CONF=%s: No such file", qPrintable(configFilePath));
@@ -313,6 +317,38 @@ QString QQuickStylePrivate::configFilePath()
return styleSpec()->resolveConfigFilePath();
}
+QSharedPointer<QSettings> QQuickStylePrivate::settings(const QString &group)
+{
+#ifndef QT_NO_SETTINGS
+ const QString filePath = QQuickStylePrivate::configFilePath();
+ if (QFile::exists(filePath)) {
+ QFileSelector selector;
+ QSettings *settings = new QSettings(selector.select(filePath), QSettings::IniFormat);
+ if (!group.isEmpty())
+ settings->beginGroup(group);
+ return QSharedPointer<QSettings>(settings);
+ }
+#endif // QT_NO_SETTINGS
+ return QSharedPointer<QSettings>();
+}
+
+static bool qt_is_dark_system_theme()
+{
+ if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
+ if (const QPalette *systemPalette = theme->palette(QPlatformTheme::SystemPalette)) {
+ const QColor textColor = systemPalette->color(QPalette::WindowText);
+ return textColor.red() > 128 && textColor.blue() > 128 && textColor.green() > 128;
+ }
+ }
+ return false;
+}
+
+bool QQuickStylePrivate::isDarkSystemTheme()
+{
+ static bool dark = qt_is_dark_system_theme();
+ return dark;
+}
+
/*!
Returns the name of the application style.
diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h
index 316783c4..b92df3c2 100644
--- a/src/quickcontrols2/qquickstyle_p.h
+++ b/src/quickcontrols2/qquickstyle_p.h
@@ -49,10 +49,13 @@
//
#include <QtCore/qurl.h>
+#include <QtCore/qsharedpointer.h>
#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
QT_BEGIN_NAMESPACE
+class QSettings;
+
class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate
{
public:
@@ -62,6 +65,8 @@ public:
static void init(const QUrl &baseUrl);
static void reset();
static QString configFilePath();
+ static QSharedPointer<QSettings> settings(const QString &group = QString());
+ static bool isDarkSystemTheme();
};
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleattached.cpp b/src/quickcontrols2/qquickstyleattached.cpp
deleted file mode 100644
index b9a66169..00000000
--- a/src/quickcontrols2/qquickstyleattached.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qquickstyleattached_p.h"
-#include "qquickstyle_p.h"
-
-#include <QtCore/qfile.h>
-#include <QtCore/qsettings.h>
-#include <QtCore/qfileselector.h>
-#include <QtGui/qcolor.h>
-#include <QtGui/qpalette.h>
-#include <QtGui/private/qguiapplication_p.h>
-#include <QtGui/qpa/qplatformtheme.h>
-#include <QtQuick/qquickwindow.h>
-#include <QtQuick/private/qquickitem_p.h>
-#include <QtQuickTemplates2/private/qquickpopup_p.h>
-
-QT_BEGIN_NAMESPACE
-
-static bool isDarkSystemTheme()
-{
- if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
- if (const QPalette *systemPalette = theme->palette(QPlatformTheme::SystemPalette)) {
- const QColor textColor = systemPalette->color(QPalette::WindowText);
- return textColor.red() > 128 && textColor.blue() > 128 && textColor.green() > 128;
- }
- }
- return false;
-}
-
-Q_QUICKCONTROLS2_PRIVATE_EXPORT bool qt_is_dark_system_theme()
-{
- static bool dark = isDarkSystemTheme();
- return dark;
-}
-
-static QQuickStyleAttached *attachedStyle(const QMetaObject *type, QObject *object, bool create = false)
-{
- if (!object)
- return nullptr;
- int idx = -1;
- return qobject_cast<QQuickStyleAttached *>(qmlAttachedPropertiesObject(&idx, object, type, create));
-}
-
-static QQuickStyleAttached *findParentStyle(const QMetaObject *type, QObject *object)
-{
- QQuickItem *item = qobject_cast<QQuickItem *>(object);
- if (item) {
- // lookup parent items and popups
- QQuickItem *parent = item->parentItem();
- while (parent) {
- QQuickStyleAttached *style = attachedStyle(type, parent);
- if (style)
- return style;
-
- QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent->parent());
- if (popup)
- return attachedStyle(type, popup);
-
- parent = parent->parentItem();
- }
-
- // fallback to item's window
- QQuickStyleAttached *style = attachedStyle(type, item->window());
- if (style)
- return style;
- } else {
- // lookup popup's window
- QQuickPopup *popup = qobject_cast<QQuickPopup *>(object);
- if (popup)
- return attachedStyle(type, popup->popupItem()->window());
- }
-
- // lookup parent window
- QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
- if (window) {
- QQuickWindow *parentWindow = qobject_cast<QQuickWindow *>(window->parent());
- if (parentWindow) {
- QQuickStyleAttached *style = attachedStyle(type, window);
- if (style)
- return style;
- }
- }
-
- // fallback to engine (global)
- if (object) {
- QQmlEngine *engine = qmlEngine(object);
- if (engine) {
- QByteArray name = QByteArray("_q_") + type->className();
- QQuickStyleAttached *style = engine->property(name).value<QQuickStyleAttached*>();
- if (!style) {
- style = attachedStyle(type, engine, true);
- engine->setProperty(name, QVariant::fromValue(style));
- }
- return style;
- }
- }
-
- return nullptr;
-}
-
-static QList<QQuickStyleAttached *> findChildStyles(const QMetaObject *type, QObject *object)
-{
- QList<QQuickStyleAttached *> children;
-
- QQuickItem *item = qobject_cast<QQuickItem *>(object);
- if (!item) {
- QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
- if (window) {
- item = window->contentItem();
-
- const auto windowChildren = window->children();
- for (QObject *child : windowChildren) {
- QQuickWindow *childWindow = qobject_cast<QQuickWindow *>(child);
- if (childWindow) {
- QQuickStyleAttached *style = attachedStyle(type, childWindow);
- if (style)
- children += style;
- }
- }
- }
- }
-
- if (item) {
- const auto childItems = item->childItems();
- for (QQuickItem *child : childItems) {
- QQuickStyleAttached *style = attachedStyle(type, child);
- if (style)
- children += style;
- else
- children += findChildStyles(type, child);
- }
- }
-
- return children;
-}
-
-QQuickStyleAttached::QQuickStyleAttached(QObject *parent) : QObject(parent)
-{
- QQuickItem *item = qobject_cast<QQuickItem *>(parent);
- if (!item) {
- QQuickPopup *popup = qobject_cast<QQuickPopup *>(parent);
- if (popup)
- item = popup->popupItem();
- }
-
- if (item) {
- connect(item, &QQuickItem::windowChanged, this, &QQuickStyleAttached::itemWindowChanged);
- QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Parent);
- }
-}
-
-QQuickStyleAttached::~QQuickStyleAttached()
-{
- QQuickItem *item = qobject_cast<QQuickItem *>(parent());
- if (item) {
- disconnect(item, &QQuickItem::windowChanged, this, &QQuickStyleAttached::itemWindowChanged);
- QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Parent);
- }
-
- setParentStyle(nullptr);
-}
-
-QSharedPointer<QSettings> QQuickStyleAttached::settings(const QString &group)
-{
-#ifndef QT_NO_SETTINGS
- const QString filePath = QQuickStylePrivate::configFilePath();
- if (QFile::exists(filePath)) {
- QFileSelector selector;
- QSettings *settings = new QSettings(selector.select(filePath), QSettings::IniFormat);
- if (!group.isEmpty())
- settings->beginGroup(group);
- return QSharedPointer<QSettings>(settings);
- }
-#endif // QT_NO_SETTINGS
- return QSharedPointer<QSettings>();
-}
-
-QList<QQuickStyleAttached *> QQuickStyleAttached::childStyles() const
-{
- return m_childStyles;
-}
-
-QQuickStyleAttached *QQuickStyleAttached::parentStyle() const
-{
- return m_parentStyle;
-}
-
-void QQuickStyleAttached::setParentStyle(QQuickStyleAttached *style)
-{
- if (m_parentStyle != style) {
- QQuickStyleAttached *oldParent = m_parentStyle;
- if (m_parentStyle)
- m_parentStyle->m_childStyles.removeOne(this);
- m_parentStyle = style;
- if (style)
- style->m_childStyles.append(this);
- parentStyleChange(style, oldParent);
- }
-}
-
-void QQuickStyleAttached::init()
-{
- QQuickStyleAttached *parentStyle = findParentStyle(metaObject(), parent());
- if (parentStyle)
- setParentStyle(parentStyle);
-
- const QList<QQuickStyleAttached *> children = findChildStyles(metaObject(), parent());
- for (QQuickStyleAttached *child : children)
- child->setParentStyle(this);
-}
-
-void QQuickStyleAttached::parentStyleChange(QQuickStyleAttached *newParent, QQuickStyleAttached *oldParent)
-{
- Q_UNUSED(newParent);
- Q_UNUSED(oldParent);
-}
-
-void QQuickStyleAttached::itemWindowChanged(QQuickWindow *window)
-{
- QQuickStyleAttached *parentStyle = nullptr;
- QQuickItem *item = qobject_cast<QQuickItem *>(sender());
- if (item)
- parentStyle = findParentStyle(metaObject(), item);
- if (!parentStyle)
- parentStyle = attachedStyle(metaObject(), window);
- setParentStyle(parentStyle);
-}
-
-void QQuickStyleAttached::itemParentChanged(QQuickItem *item, QQuickItem *parent)
-{
- Q_UNUSED(parent);
- setParentStyle(findParentStyle(metaObject(), item));
-}
-
-QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp
index 1f01da52..fa8e9785 100644
--- a/src/quickcontrols2/qquickstyleplugin.cpp
+++ b/src/quickcontrols2/qquickstyleplugin.cpp
@@ -65,14 +65,23 @@ void QQuickStylePlugin::initializeEngine(QQmlEngine *engine, const char *uri)
if (!m_theme.isNull())
return;
- const QString style = name();
- if (!style.isEmpty() && style.compare(QQuickStyle::name(), Qt::CaseInsensitive) == 0) {
+ if (isCurrent()) {
m_theme.reset(createTheme());
if (m_theme)
QGuiApplicationPrivate::platform_theme = m_theme.data();
}
}
+bool QQuickStylePlugin::isCurrent() const
+{
+ QString style = QQuickStyle::name();
+ if (style.isEmpty())
+ style = QStringLiteral("Default");
+
+ const QString theme = name();
+ return theme.compare(style, Qt::CaseInsensitive) == 0;
+}
+
QString QQuickStylePlugin::name() const
{
return QString();
diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h
index cd5a77b6..9457b472 100644
--- a/src/quickcontrols2/qquickstyleplugin_p.h
+++ b/src/quickcontrols2/qquickstyleplugin_p.h
@@ -67,6 +67,7 @@ public:
void registerTypes(const char *uri) override;
void initializeEngine(QQmlEngine *engine, const char *uri) override;
+ bool isCurrent() const;
virtual QString name() const;
virtual QQuickProxyTheme *createTheme() const;
diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp
index a9e905ca..d5543c17 100644
--- a/src/quickcontrols2/qquickstyleselector.cpp
+++ b/src/quickcontrols2/qquickstyleselector.cpp
@@ -71,13 +71,21 @@ static QString ensureSlash(const QString &path)
return path + QLatin1Char('/');
}
+static QStringList prefixedPlatformSelectors(const QChar &prefix)
+{
+ QStringList selectors = QFileSelectorPrivate::platformSelectors();
+ for (int i = 0; i < selectors.count(); ++i)
+ selectors[i].prepend(prefix);
+ return selectors;
+}
+
static QStringList allSelectors(const QString &style = QString())
{
- static const QStringList platformSelectors = QFileSelectorPrivate::platformSelectors();
+ static const QStringList platformSelectors = prefixedPlatformSelectors(QLatin1Char('+'));
QStringList selectors = platformSelectors;
const QString locale = QLocale().name();
if (!locale.isEmpty())
- selectors += locale;
+ selectors += QLatin1Char('+') + locale;
if (!style.isEmpty())
selectors.prepend(style);
return selectors;
diff --git a/src/quickcontrols2/qquicktheme.cpp b/src/quickcontrols2/qquicktheme.cpp
new file mode 100644
index 00000000..06a66bfd
--- /dev/null
+++ b/src/quickcontrols2/qquicktheme.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquicktheme_p.h"
+#include "qquickstyle_p.h"
+
+#include <QtCore/qmetaobject.h>
+#include <QtCore/qsettings.h>
+
+#include <functional>
+
+QT_BEGIN_NAMESPACE
+
+#if QT_CONFIG(settings)
+static void readValue(const QSharedPointer<QSettings> &settings, const QString &name, std::function<void(const QVariant &)> setValue)
+{
+ const QVariant var = settings->value(name);
+ if (var.isValid())
+ setValue(var);
+}
+
+template <typename Enum>
+static Enum toEnumValue(const QVariant &var)
+{
+ // ### TODO: expose QFont enums to the meta object system using Q_ENUM
+ //QMetaEnum enumeration = QMetaEnum::fromType<Enum>();
+ //bool ok = false;
+ //int value = enumeration.keyToValue(var.toByteArray(), &ok);
+ //if (!ok)
+ // value = var.toInt();
+ //return static_cast<Enum>(value);
+
+ return static_cast<Enum>(var.toInt());
+}
+
+QFont *readFont(const QSharedPointer<QSettings> &settings)
+{
+ const QVariant var = settings->value(QStringLiteral("Font"));
+ if (var.isValid())
+ return new QFont(var.value<QFont>());
+
+ QFont f;
+ settings->beginGroup(QStringLiteral("Font"));
+ readValue(settings, QStringLiteral("Family"), [&f](const QVariant &var) { f.setFamily(var.toString()); });
+ readValue(settings, QStringLiteral("PointSize"), [&f](const QVariant &var) { f.setPointSizeF(var.toReal()); });
+ readValue(settings, QStringLiteral("PixelSize"), [&f](const QVariant &var) { f.setPixelSize(var.toInt()); });
+ readValue(settings, QStringLiteral("StyleHint"), [&f](const QVariant &var) { f.setStyleHint(toEnumValue<QFont::StyleHint>(var.toInt())); });
+ readValue(settings, QStringLiteral("Weight"), [&f](const QVariant &var) { f.setWeight(toEnumValue<QFont::Weight>(var)); });
+ readValue(settings, QStringLiteral("Style"), [&f](const QVariant &var) { f.setStyle(toEnumValue<QFont::Style>(var.toInt())); });
+ settings->endGroup();
+ return new QFont(f);
+}
+
+static void readColorGroup(const QSharedPointer<QSettings> &settings, QPalette::ColorGroup group, QPalette *palette)
+{
+ const QStringList keys = settings->childKeys();
+ if (keys.isEmpty())
+ return;
+
+ static const int index = QPalette::staticMetaObject.indexOfEnumerator("ColorRole");
+ Q_ASSERT(index != -1);
+ QMetaEnum metaEnum = QPalette::staticMetaObject.enumerator(index);
+
+ for (const QString &key : keys) {
+ bool ok = false;
+ int role = metaEnum.keyToValue(key.toUtf8(), &ok);
+ if (ok)
+ palette->setColor(group, static_cast<QPalette::ColorRole>(role), settings->value(key).value<QColor>());
+ }
+}
+
+static QPalette *readPalette(const QSharedPointer<QSettings> &settings)
+{
+ QPalette p;
+ settings->beginGroup(QStringLiteral("Palette"));
+ readColorGroup(settings, QPalette::All, &p);
+
+ settings->beginGroup(QStringLiteral("Normal"));
+ readColorGroup(settings, QPalette::Normal, &p);
+ settings->endGroup();
+
+ settings->beginGroup(QStringLiteral("Disabled"));
+ readColorGroup(settings, QPalette::Disabled, &p);
+ settings->endGroup();
+ return new QPalette(p);
+}
+
+#endif // QT_CONFIG(settings)
+
+QQuickTheme::QQuickTheme(const QString &style)
+ : QQuickProxyTheme()
+{
+#if QT_CONFIG(settings)
+ QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(style);
+ if (settings) {
+ m_styleFont.reset(readFont(settings));
+ m_stylePalette.reset(readPalette(settings));
+ }
+#endif
+}
+
+const QFont *QQuickTheme::font(Font type) const
+{
+ Q_UNUSED(type);
+ return m_styleFont.data();
+}
+
+const QPalette *QQuickTheme::palette(Palette type) const
+{
+ Q_UNUSED(type);
+ return m_stylePalette.data();
+}
+
+QFont QQuickTheme::resolveFont(const QFont &font) const
+{
+ if (!m_styleFont)
+ return font;
+
+ return m_styleFont->resolve(font);
+}
+
+QPalette QQuickTheme::resolvePalette(const QPalette &palette) const
+{
+ if (!m_stylePalette)
+ return palette;
+
+ return m_stylePalette->resolve(palette);
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquicktheme_p.h b/src/quickcontrols2/qquicktheme_p.h
new file mode 100644
index 00000000..098ac7f1
--- /dev/null
+++ b/src/quickcontrols2/qquicktheme_p.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKTHEME_P_H
+#define QQUICKTHEME_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuickControls2/private/qquickproxytheme_p.h>
+#include <QtCore/qscopedpointer.h>
+#include <QtGui/qfont.h>
+#include <QtGui/qpalette.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickTheme : public QQuickProxyTheme
+{
+public:
+ QQuickTheme(const QString &name);
+
+ const QFont *font(Font type = SystemFont) const override;
+ const QPalette *palette(Palette type = SystemPalette) const override;
+
+protected:
+ QFont resolveFont(const QFont &font) const;
+ QPalette resolvePalette(const QPalette &palette) const;
+
+private:
+ QScopedPointer<QFont> m_styleFont;
+ QScopedPointer<QPalette> m_stylePalette;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKTHEME_P_H
diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri
index 9be0c009..ac20b78d 100644
--- a/src/quickcontrols2/quickcontrols2.pri
+++ b/src/quickcontrols2/quickcontrols2.pri
@@ -1,30 +1,44 @@
HEADERS += \
$$PWD/qquickanimatednode_p.h \
+ $$PWD/qquickattachedobject_p.h \
+ $$PWD/qquickchecklabel_p.h \
$$PWD/qquickclippedtext_p.h \
- $$PWD/qquickcolorimageprovider_p.h \
+ $$PWD/qquickcolor_p.h \
+ $$PWD/qquickcolorimage_p.h \
+ $$PWD/qquickiconimage_p.h \
+ $$PWD/qquickiconimage_p_p.h \
+ $$PWD/qquickiconlabel_p.h \
+ $$PWD/qquickiconlabel_p_p.h \
$$PWD/qquickitemgroup_p.h \
+ $$PWD/qquickmnemoniclabel_p.h \
+ $$PWD/qquickpaddedrectangle_p.h \
$$PWD/qquickplaceholdertext_p.h \
$$PWD/qquickproxytheme_p.h \
$$PWD/qquickstyle.h \
$$PWD/qquickstyle_p.h \
- $$PWD/qquickstyleattached_p.h \
$$PWD/qquickstyleplugin_p.h \
$$PWD/qquickstyleselector_p.h \
$$PWD/qquickstyleselector_p_p.h \
- $$PWD/qquickpaddedrectangle_p.h
+ $$PWD/qquicktheme_p.h
SOURCES += \
$$PWD/qquickanimatednode.cpp \
+ $$PWD/qquickattachedobject.cpp \
+ $$PWD/qquickchecklabel.cpp \
$$PWD/qquickclippedtext.cpp \
- $$PWD/qquickcolorimageprovider.cpp \
+ $$PWD/qquickcolor.cpp \
+ $$PWD/qquickcolorimage.cpp \
+ $$PWD/qquickiconimage.cpp \
+ $$PWD/qquickiconlabel.cpp \
$$PWD/qquickitemgroup.cpp \
+ $$PWD/qquickmnemoniclabel.cpp \
+ $$PWD/qquickpaddedrectangle.cpp \
$$PWD/qquickplaceholdertext.cpp \
$$PWD/qquickproxytheme.cpp \
$$PWD/qquickstyle.cpp \
- $$PWD/qquickstyleattached.cpp \
$$PWD/qquickstyleplugin.cpp \
$$PWD/qquickstyleselector.cpp \
- $$PWD/qquickpaddedrectangle.cpp
+ $$PWD/qquicktheme.cpp
qtConfig(quick-listview):qtConfig(quick-pathview) {
HEADERS += \
diff --git a/src/quickcontrols2/quickcontrols2.pro b/src/quickcontrols2/quickcontrols2.pro
index bdad3095..8aec9953 100644
--- a/src/quickcontrols2/quickcontrols2.pro
+++ b/src/quickcontrols2/quickcontrols2.pro
@@ -7,7 +7,7 @@ QT_PRIVATE += core-private gui-private qml-private quick-private quicktemplates2
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
HEADERS += \
- $$PWD/qtquickcontrols2global.h
+ $$PWD/qtquickcontrols2global.h \
$$PWD/qtquickcontrols2global_p.h
include(quickcontrols2.pri)