aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/controls/DelayButton.qml62
-rw-r--r--src/imports/controls/qtquickcontrols2plugin.cpp4
-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
-rw-r--r--tests/auto/customization/tst_customization.cpp2
8 files changed, 452 insertions, 43 deletions
diff --git a/src/imports/controls/DelayButton.qml b/src/imports/controls/DelayButton.qml
index 4a569fcf..133b2786 100644
--- a/src/imports/controls/DelayButton.qml
+++ b/src/imports/controls/DelayButton.qml
@@ -58,55 +58,35 @@ T.DelayButton {
}
}
- contentItem: Item {
- implicitWidth: label.implicitWidth
- implicitHeight: label.implicitHeight
-
- Item {
- x: -control.leftPadding + (control.progress * control.width)
- width: (1.0 - control.progress) * control.width
- height: parent.height
-
+ contentItem: ItemGroup {
+ ClippedText {
clip: control.progress > 0
+ clipX: -control.leftPadding + control.progress * control.width
+ clipWidth: (1.0 - control.progress) * control.width
visible: control.progress < 1
- Text {
- id: label
- x: -parent.x
- width: control.availableWidth
- height: parent.height
-
- text: control.text
- font: control.font
- opacity: enabled ? 1 : 0.3
- color: control.visualFocus ? Default.focusColor : (control.down ? Default.textDarkColor : Default.textColor)
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- elide: Text.ElideRight
- }
+ text: control.text
+ font: control.font
+ opacity: enabled ? 1 : 0.3
+ color: control.visualFocus ? Default.focusColor : (control.down ? Default.textDarkColor : Default.textColor)
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ elide: Text.ElideRight
}
- Item {
- x: -control.leftPadding
- width: control.progress * control.width
- height: parent.height
-
+ ClippedText {
clip: control.progress > 0
+ clipX: -control.leftPadding
+ clipWidth: control.progress * control.width
visible: control.progress > 0
- Text {
- x: control.leftPadding
- width: control.availableWidth
- height: parent.height
-
- text: control.text
- font: control.font
- opacity: enabled ? 1 : 0.3
- color: Default.textLightColor
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- elide: Text.ElideRight
- }
+ text: control.text
+ font: control.font
+ opacity: enabled ? 1 : 0.3
+ color: Default.textLightColor
+ horizontalAlignment: Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
+ elide: Text.ElideRight
}
}
diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp
index 32270be0..e9471227 100644
--- a/src/imports/controls/qtquickcontrols2plugin.cpp
+++ b/src/imports/controls/qtquickcontrols2plugin.cpp
@@ -44,6 +44,8 @@
#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview)
#include <QtQuickControls2/private/qquicktumblerview_p.h>
#endif
+#include <QtQuickControls2/private/qquickclippedtext_p.h>
+#include <QtQuickControls2/private/qquickitemgroup_p.h>
#include "qquickdefaultbusyindicator_p.h"
#include "qquickdefaultprogressbar_p.h"
@@ -164,8 +166,10 @@ void QtQuickControls2Plugin::initializeEngine(QQmlEngine *engine, const char *ur
qmlRegisterModule(import, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2...
qmlRegisterType<QQuickDefaultBusyIndicator>(import, 2, 0, "BusyIndicatorImpl");
+ qmlRegisterType<QQuickClippedText>(import, 2, 2, "ClippedText");
qmlRegisterType<QQuickDefaultProgressBar>(import, 2, 0, "ProgressBarImpl");
qmlRegisterType<QQuickDialRing>(import, 2, 0, "DialRing");
+ qmlRegisterType<QQuickItemGroup>(import, 2, 2, "ItemGroup");
qmlRegisterType<QQuickPlaceholderText>(import, 2, 2, "PlaceholderText");
#if QT_CONFIG(quick_listview) && QT_CONFIG(quick_pathview)
qmlRegisterType<QQuickTumblerView>(import, 2, 1, "TumblerView");
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 \
diff --git a/tests/auto/customization/tst_customization.cpp b/tests/auto/customization/tst_customization.cpp
index 13527263..4c8ea72b 100644
--- a/tests/auto/customization/tst_customization.cpp
+++ b/tests/auto/customization/tst_customization.cpp
@@ -257,8 +257,6 @@ void tst_customization::creation()
QVERIFY2(qt_createdQObjects()->isEmpty(), qPrintable("unexpectedly created: " + qt_createdQObjects->join(", ")));
QVERIFY2(qt_destroyedQObjects()->isEmpty(), qPrintable("unexpectedly destroyed: " + qt_destroyedQObjects->join(", ") + " were unexpectedly destroyed"));
- QEXPECT_FAIL("Default:DelayButton", "TODO: remove internal IDs", Abort);
-
QVERIFY2(qt_destroyedParentQObjects()->isEmpty(), qPrintable("delegates/children of: " + qt_destroyedParentQObjects->join(", ") + " were unexpectedly destroyed"));
}