aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-12-19 17:00:15 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2017-12-21 10:00:10 +0000
commit1e33020fc02b56001d805d3d66badd41480b746d (patch)
treeb2545765e805b5d97b610ccb4acb33192d7b2a66 /src/quickcontrols2
parentda27cace5aa65c1972b746d9fc1d4507a04b5f93 (diff)
Default: eliminate internal IDs in DelayButton
An ID in the internal Text element prevented deferred execution for the whole content item. The ID was used for two reasons. First of all, it was used to propagate implicit size from the Text element to the root of the content item. Secondly, it was used to calculate clip areas to provide the same text in two different colors. This patch provides two internal C++ helpers, ItemGroup and ClippedText, that provide these functionalities without the need of using IDs in QML. At the same time we got rid of two wrapper Items and simplified some QML bindings, which results to a nice boost (18->22) in qmlbench on TX1. Task-number: QTBUG-65341 Change-Id: Icf9c09356cf5c0ed641bde537bee7291bd260057 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quickcontrols2')
-rw-r--r--src/quickcontrols2/qquickclippedtext.cpp122
-rw-r--r--src/quickcontrols2/qquickclippedtext_p.h96
-rw-r--r--src/quickcontrols2/qquickitemgroup.cpp122
-rw-r--r--src/quickcontrols2/qquickitemgroup_p.h83
-rw-r--r--src/quickcontrols2/quickcontrols2.pri4
5 files changed, 427 insertions, 0 deletions
diff --git a/src/quickcontrols2/qquickclippedtext.cpp b/src/quickcontrols2/qquickclippedtext.cpp
new file mode 100644
index 00000000..7f113592
--- /dev/null
+++ b/src/quickcontrols2/qquickclippedtext.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** 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 "qquickclippedtext_p.h"
+
+#include <QtQuick/private/qquickitem_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickClippedText::QQuickClippedText(QQuickItem *parent)
+ : QQuickText(parent),
+ m_hasClipWidth(false),
+ m_hasClipHeight(false),
+ m_clipX(0),
+ m_clipY(0),
+ m_clipWidth(0),
+ m_clipHeight(0)
+{
+}
+
+qreal QQuickClippedText::clipX() const
+{
+ return m_clipX;
+}
+
+void QQuickClippedText::setClipX(qreal x)
+{
+ if (qFuzzyCompare(x, m_clipX))
+ return;
+
+ m_clipX = x;
+ markClipDirty();
+}
+
+qreal QQuickClippedText::clipY() const
+{
+ return m_clipY;
+}
+
+void QQuickClippedText::setClipY(qreal y)
+{
+ if (qFuzzyCompare(y, m_clipY))
+ return;
+
+ m_clipY = y;
+ markClipDirty();
+}
+
+qreal QQuickClippedText::clipWidth() const
+{
+ return m_clipWidth ? m_clipWidth : width();
+}
+
+void QQuickClippedText::setClipWidth(qreal width)
+{
+ m_hasClipWidth = true;
+ if (qFuzzyCompare(width, m_clipWidth))
+ return;
+
+ m_clipWidth = width;
+ markClipDirty();
+}
+
+qreal QQuickClippedText::clipHeight() const
+{
+ return m_clipHeight ? m_clipHeight : height();
+}
+
+void QQuickClippedText::setClipHeight(qreal height)
+{
+ m_hasClipHeight = true;
+ if (qFuzzyCompare(height, m_clipHeight))
+ return;
+
+ m_clipHeight = height;
+ markClipDirty();
+}
+
+QRectF QQuickClippedText::clipRect() const
+{
+ return QRectF(clipX(), clipY(), clipWidth(), clipHeight());
+}
+
+void QQuickClippedText::markClipDirty()
+{
+ QQuickItemPrivate::get(this)->dirty(QQuickItemPrivate::Size);
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickclippedtext_p.h b/src/quickcontrols2/qquickclippedtext_p.h
new file mode 100644
index 00000000..7521525f
--- /dev/null
+++ b/src/quickcontrols2/qquickclippedtext_p.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** 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 QQUICKCLIPPEDTEXT_P_H
+#define QQUICKCLIPPEDTEXT_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 QQuickClippedText : public QQuickText
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal clipX READ clipX WRITE setClipX FINAL)
+ Q_PROPERTY(qreal clipY READ clipY WRITE setClipY FINAL)
+ Q_PROPERTY(qreal clipWidth READ clipWidth WRITE setClipWidth FINAL)
+ Q_PROPERTY(qreal clipHeight READ clipHeight WRITE setClipHeight FINAL)
+
+public:
+ explicit QQuickClippedText(QQuickItem *parent = nullptr);
+
+ qreal clipX() const;
+ void setClipX(qreal x);
+
+ qreal clipY() const;
+ void setClipY(qreal y);
+
+ qreal clipWidth() const;
+ void setClipWidth(qreal width);
+
+ qreal clipHeight() const;
+ void setClipHeight(qreal height);
+
+ QRectF clipRect() const override;
+
+private:
+ void markClipDirty();
+
+ bool m_hasClipWidth;
+ bool m_hasClipHeight;
+ qreal m_clipX;
+ qreal m_clipY;
+ qreal m_clipWidth;
+ qreal m_clipHeight;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickClippedText)
+
+#endif // QQUICKCLIPPEDTEXT_P_H
diff --git a/src/quickcontrols2/qquickitemgroup.cpp b/src/quickcontrols2/qquickitemgroup.cpp
new file mode 100644
index 00000000..1396a871
--- /dev/null
+++ b/src/quickcontrols2/qquickitemgroup.cpp
@@ -0,0 +1,122 @@
+/****************************************************************************
+**
+** 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 "qquickitemgroup_p.h"
+
+#include <QtQuick/private/qquickimplicitsizeitem_p_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickItemGroup::QQuickItemGroup(QQuickItem *parent)
+ : QQuickImplicitSizeItem(*(new QQuickImplicitSizeItemPrivate), parent)
+{
+}
+
+QQuickItemGroup::~QQuickItemGroup()
+{
+ const auto children = childItems();
+ for (QQuickItem *child : children)
+ unwatch(child);
+}
+
+void QQuickItemGroup::watch(QQuickItem *item)
+{
+ QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
+}
+
+void QQuickItemGroup::unwatch(QQuickItem *item)
+{
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
+}
+
+QSizeF QQuickItemGroup::calculateImplicitSize() const
+{
+ qreal width = 0;
+ qreal height = 0;
+ const auto children = childItems();
+ for (QQuickItem *child : children) {
+ width = qMax(width, child->implicitWidth());
+ height = qMax(height, child->implicitHeight());
+ }
+ return QSizeF(width, height);
+}
+
+void QQuickItemGroup::updateImplicitSize()
+{
+ QSizeF size = calculateImplicitSize();
+ setImplicitSize(size.width(), size.height());
+}
+
+void QQuickItemGroup::itemChange(ItemChange change, const ItemChangeData &data)
+{
+ QQuickImplicitSizeItem::itemChange(change, data);
+ switch (change) {
+ case ItemChildAddedChange:
+ watch(data.item);
+ data.item->setSize(QSizeF(width(), height()));
+ updateImplicitSize();
+ break;
+ case ItemChildRemovedChange:
+ unwatch(data.item);
+ updateImplicitSize();
+ break;
+ default:
+ break;
+ }
+}
+
+void QQuickItemGroup::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ QQuickImplicitSizeItem::geometryChanged(newGeometry, oldGeometry);
+
+ if (newGeometry.size() != oldGeometry.size()) {
+ const auto children = childItems();
+ for (QQuickItem *child : children)
+ child->setSize(newGeometry.size());
+ }
+}
+
+void QQuickItemGroup::itemImplicitWidthChanged(QQuickItem *)
+{
+ setImplicitWidth(calculateImplicitSize().width());
+}
+
+void QQuickItemGroup::itemImplicitHeightChanged(QQuickItem *)
+{
+ setImplicitHeight(calculateImplicitSize().height());
+}
+
+QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickitemgroup_p.h b/src/quickcontrols2/qquickitemgroup_p.h
new file mode 100644
index 00000000..af062d57
--- /dev/null
+++ b/src/quickcontrols2/qquickitemgroup_p.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** 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 QQUICKITEMGROUP_P_H
+#define QQUICKITEMGROUP_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/qquickimplicitsizeitem_p.h>
+#include <QtQuick/private/qquickitemchangelistener_p.h>
+#include <QtQuickControls2/private/qtquickcontrols2global_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickItemGroup : public QQuickImplicitSizeItem, protected QQuickItemChangeListener
+{
+ Q_OBJECT
+
+public:
+ explicit QQuickItemGroup(QQuickItem *parent = nullptr);
+ ~QQuickItemGroup();
+
+protected:
+ void watch(QQuickItem *item);
+ void unwatch(QQuickItem *item);
+
+ QSizeF calculateImplicitSize() const;
+ void updateImplicitSize();
+
+ void itemChange(ItemChange change, const ItemChangeData &data) override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
+
+ void itemImplicitWidthChanged(QQuickItem *item) override;
+ void itemImplicitHeightChanged(QQuickItem *item) override;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickItemGroup)
+
+#endif // QQUICKITEMGROUP_P_H
diff --git a/src/quickcontrols2/quickcontrols2.pri b/src/quickcontrols2/quickcontrols2.pri
index a618989e..9be0c009 100644
--- a/src/quickcontrols2/quickcontrols2.pri
+++ b/src/quickcontrols2/quickcontrols2.pri
@@ -1,6 +1,8 @@
HEADERS += \
$$PWD/qquickanimatednode_p.h \
+ $$PWD/qquickclippedtext_p.h \
$$PWD/qquickcolorimageprovider_p.h \
+ $$PWD/qquickitemgroup_p.h \
$$PWD/qquickplaceholdertext_p.h \
$$PWD/qquickproxytheme_p.h \
$$PWD/qquickstyle.h \
@@ -13,7 +15,9 @@ HEADERS += \
SOURCES += \
$$PWD/qquickanimatednode.cpp \
+ $$PWD/qquickclippedtext.cpp \
$$PWD/qquickcolorimageprovider.cpp \
+ $$PWD/qquickitemgroup.cpp \
$$PWD/qquickplaceholdertext.cpp \
$$PWD/qquickproxytheme.cpp \
$$PWD/qquickstyle.cpp \