From 09e0e044c379a78f539400e7a4a1bbb109148639 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 20 Mar 2016 08:08:40 +0100 Subject: ProgressBar: use contentItem instead of indicator Change-Id: I8bd21b32b6f3d333c119d77b629b46fe411c06eb Reviewed-by: Mitch Curtis --- src/imports/controls/ProgressBar.qml | 16 ++++----- .../qtquickcontrols-progressbar-contentItem.png | Bin 0 -> 133 bytes .../qtquickcontrols-progressbar-indicator.png | Bin 133 -> 0 bytes .../qtquickcontrols-progressbar-contentItem.qml | 39 ++++++++++++++++++++ .../qtquickcontrols-progressbar-indicator.qml | 40 --------------------- .../controls/doc/src/qtlabscontrols-customize.qdoc | 8 ++--- src/imports/controls/material/ProgressBar.qml | 15 ++++---- .../material/qquickmaterialprogressstrip.cpp | 10 ++++-- src/imports/controls/plugins.qmltypes | 1 - src/imports/controls/qquickprogressstrip.cpp | 7 ++-- src/imports/controls/universal/ProgressBar.qml | 15 ++++---- .../universal/qquickuniversalprogressstrip.cpp | 2 ++ 12 files changed, 74 insertions(+), 79 deletions(-) create mode 100644 src/imports/controls/doc/images/qtquickcontrols-progressbar-contentItem.png delete mode 100644 src/imports/controls/doc/images/qtquickcontrols-progressbar-indicator.png create mode 100644 src/imports/controls/doc/snippets/qtquickcontrols-progressbar-contentItem.qml delete mode 100644 src/imports/controls/doc/snippets/qtquickcontrols-progressbar-indicator.qml (limited to 'src/imports/controls') diff --git a/src/imports/controls/ProgressBar.qml b/src/imports/controls/ProgressBar.qml index 795fd231..0439cbb9 100644 --- a/src/imports/controls/ProgressBar.qml +++ b/src/imports/controls/ProgressBar.qml @@ -42,17 +42,15 @@ T.ProgressBar { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - indicator ? indicator.implicitWidth : 0) + leftPadding + rightPadding + contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding + contentItem.implicitHeight + topPadding + bottomPadding) - //! [indicator] - indicator: ProgressStrip { + //! [contentItem] + contentItem: ProgressStrip { id: strip - x: control.leftPadding - y: control.topPadding + (control.availableHeight - height) / 2 - width: control.availableWidth - height: 6 + implicitHeight: 6 + implicitWidth: 116 scale: control.mirrored ? -1 : 1 progress: control.position indeterminate: control.indeterminate @@ -62,7 +60,7 @@ T.ProgressBar { running: control.visible && control.indeterminate } } - //! [indicator] + //! [contentItem] //! [background] background: Rectangle { diff --git a/src/imports/controls/doc/images/qtquickcontrols-progressbar-contentItem.png b/src/imports/controls/doc/images/qtquickcontrols-progressbar-contentItem.png new file mode 100644 index 00000000..9ce19e92 Binary files /dev/null and b/src/imports/controls/doc/images/qtquickcontrols-progressbar-contentItem.png differ diff --git a/src/imports/controls/doc/images/qtquickcontrols-progressbar-indicator.png b/src/imports/controls/doc/images/qtquickcontrols-progressbar-indicator.png deleted file mode 100644 index 9ce19e92..00000000 Binary files a/src/imports/controls/doc/images/qtquickcontrols-progressbar-indicator.png and /dev/null differ diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-progressbar-contentItem.qml b/src/imports/controls/doc/snippets/qtquickcontrols-progressbar-contentItem.qml new file mode 100644 index 00000000..0bb1b418 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols-progressbar-contentItem.qml @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Qt.labs.controls 1.0 + +ProgressBar { + value: 0.5 + Rectangle { + parent: contentItem + anchors.fill: parent + color: "transparent" + border.color: "red" + } +} diff --git a/src/imports/controls/doc/snippets/qtquickcontrols-progressbar-indicator.qml b/src/imports/controls/doc/snippets/qtquickcontrols-progressbar-indicator.qml deleted file mode 100644 index 28eb99bf..00000000 --- a/src/imports/controls/doc/snippets/qtquickcontrols-progressbar-indicator.qml +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:FDL$ -** 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 Free Documentation License Usage -** Alternatively, this file may be used under the terms of the GNU Free -** Documentation License version 1.3 as published by the Free Software -** Foundation and appearing in the file included in the packaging of -** this file. Please review the following information to ensure -** the GNU Free Documentation License version 1.3 requirements -** will be met: http://www.gnu.org/copyleft/fdl.html. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import QtQuick 2.0 -import Qt.labs.controls 1.0 - -ProgressBar { - value: 0.5 - Rectangle { - parent: indicator - width: indicator.childrenRect.width - height: indicator.height - color: "transparent" - border.color: "red" - } -} diff --git a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc index df1ba5d0..921794a5 100644 --- a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc +++ b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc @@ -280,7 +280,7 @@ \section1 Customizing ProgressBar ProgressBar consists of two visual items: \l {Control::background}{background} - and \l {ProgressBar::indicator}{indicator}. + and \l {Control::contentItem}{content item}. \section3 Background @@ -288,11 +288,11 @@ \snippet ProgressBar.qml background - \section3 Indicator + \section3 Content item - \image qtquickcontrols-progressbar-indicator.png + \image qtquickcontrols-progressbar-contentItem.png - \snippet ProgressBar.qml indicator + \snippet ProgressBar.qml contentItem \section1 Customizing RadioButton diff --git a/src/imports/controls/material/ProgressBar.qml b/src/imports/controls/material/ProgressBar.qml index 52df1660..2493da15 100644 --- a/src/imports/controls/material/ProgressBar.qml +++ b/src/imports/controls/material/ProgressBar.qml @@ -43,17 +43,14 @@ T.ProgressBar { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - indicator ? indicator.implicitWidth : 0) + leftPadding + rightPadding + contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding + contentItem.implicitHeight + topPadding + bottomPadding) - //! [indicator] - indicator: ProgressStrip { + //! [contentItem] + contentItem: ProgressStrip { id: strip - x: control.leftPadding - y: control.topPadding + (control.availableHeight - height) / 2 - width: control.availableWidth - height: 4 + implicitHeight: 4 scale: control.mirrored ? -1 : 1 indeterminate: control.indeterminate @@ -65,7 +62,7 @@ T.ProgressBar { running: control.visible && control.indeterminate } } - //! [indicator] + //! [contentItem] //! [background] background: Rectangle { diff --git a/src/imports/controls/material/qquickmaterialprogressstrip.cpp b/src/imports/controls/material/qquickmaterialprogressstrip.cpp index 34590340..1d3ffc20 100644 --- a/src/imports/controls/material/qquickmaterialprogressstrip.cpp +++ b/src/imports/controls/material/qquickmaterialprogressstrip.cpp @@ -207,9 +207,13 @@ QSGNode *QQuickMaterialProgressStrip::updatePaintNode(QSGNode *oldNode, UpdatePa { QQuickItemPrivate *d = QQuickItemPrivate::get(this); + QRectF bounds = boundingRect(); + bounds.setHeight(implicitHeight()); + bounds.moveTop((height() - bounds.height()) / 2.0); + if (!oldNode) - oldNode = new QSGSimpleRectNode(boundingRect(), Qt::transparent); - static_cast(oldNode)->setRect(boundingRect()); + oldNode = new QSGSimpleRectNode(bounds, Qt::transparent); + static_cast(oldNode)->setRect(bounds); const int count = m_indeterminate ? 2 : 1; const qreal w = m_indeterminate ? 0 : m_progress * width(); @@ -230,7 +234,7 @@ QSGNode *QQuickMaterialProgressStrip::updatePaintNode(QSGNode *oldNode, UpdatePa QSGRectangleNode *rectNode = static_cast(transformNode->firstChild()); Q_ASSERT(rectNode->type() == QSGNode::GeometryNodeType); - rectNode->setRect(QRectF(0, 0, w, height())); + rectNode->setRect(QRectF(0, bounds.y(), w, bounds.height())); rectNode->setColor(m_color); rectNode->update(); diff --git a/src/imports/controls/plugins.qmltypes b/src/imports/controls/plugins.qmltypes index 27d06b40..3df8d825 100644 --- a/src/imports/controls/plugins.qmltypes +++ b/src/imports/controls/plugins.qmltypes @@ -442,7 +442,6 @@ Module { Property { name: "position"; type: "double"; isReadonly: true } Property { name: "visualPosition"; type: "double"; isReadonly: true } Property { name: "indeterminate"; type: "bool" } - Property { name: "indicator"; type: "QQuickItem"; isPointer: true } } Component { name: "QQuickRadioButton" diff --git a/src/imports/controls/qquickprogressstrip.cpp b/src/imports/controls/qquickprogressstrip.cpp index 0fc72087..fc3596db 100644 --- a/src/imports/controls/qquickprogressstrip.cpp +++ b/src/imports/controls/qquickprogressstrip.cpp @@ -63,8 +63,6 @@ QQuickProgressStrip::QQuickProgressStrip(QQuickItem *parent) : m_indeterminate(false) { setFlag(QQuickItem::ItemHasContents); - setImplicitWidth(116); - setImplicitHeight(6); } QQuickProgressStrip::~QQuickProgressStrip() @@ -142,6 +140,7 @@ QSGNode *QQuickProgressStrip::updatePaintNode(QSGNode *oldNode, QQuickItem::Upda } Q_ASSERT(rootTransformNode->type() == QSGNode::TransformNodeType); + const qreal y = (height() - implicitHeight()) / 2; const QColor color(0x35, 0x36, 0x37); if (m_indeterminate) { if (rootTransformNode->childCount() != blocks) { @@ -167,7 +166,7 @@ QSGNode *QQuickProgressStrip::updatePaintNode(QSGNode *oldNode, QQuickItem::Upda m.translate(blockStartX(i), 0); transformNode->setMatrix(m); - rectNode->setRect(QRectF(QPointF(), QSizeF(blockWidth, height()))); + rectNode->setRect(QRectF(QPointF(0, y), QSizeF(blockWidth, implicitHeight()))); rectNode->update(); transformNode = static_cast(transformNode->nextSibling()); @@ -185,7 +184,7 @@ QSGNode *QQuickProgressStrip::updatePaintNode(QSGNode *oldNode, QQuickItem::Upda rootTransformNode->appendChildNode(rectNode); } - rectNode->setRect(QRectF(QPointF(), QSizeF(m_progress * width(), height()))); + rectNode->setRect(QRectF(QPointF(0, y), QSizeF(m_progress * width(), implicitHeight()))); rectNode->update(); } diff --git a/src/imports/controls/universal/ProgressBar.qml b/src/imports/controls/universal/ProgressBar.qml index 308b83f7..360b7896 100644 --- a/src/imports/controls/universal/ProgressBar.qml +++ b/src/imports/controls/universal/ProgressBar.qml @@ -43,17 +43,14 @@ T.ProgressBar { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - indicator ? indicator.implicitWidth : 0) + leftPadding + rightPadding + contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding + contentItem.implicitHeight + topPadding + bottomPadding) - //! [indicator] - indicator: ProgressStrip { + //! [contentItem] + contentItem: ProgressStrip { id: strip - x: control.leftPadding - y: control.topPadding + (control.availableHeight - height) / 2 - width: control.availableWidth - height: 10 + implicitHeight: 10 scale: control.mirrored ? -1 : 1 indeterminate: control.indeterminate @@ -66,7 +63,7 @@ T.ProgressBar { running: control.visible && control.indeterminate } } - //! [indicator] + //! [contentItem] //! [background] background: Rectangle { diff --git a/src/imports/controls/universal/qquickuniversalprogressstrip.cpp b/src/imports/controls/universal/qquickuniversalprogressstrip.cpp index 750970da..f23e91da 100644 --- a/src/imports/controls/universal/qquickuniversalprogressstrip.cpp +++ b/src/imports/controls/universal/qquickuniversalprogressstrip.cpp @@ -281,6 +281,8 @@ QSGNode *QQuickUniversalProgressStrip::updatePaintNode(QSGNode *oldNode, UpdateP QQuickItemPrivate *d = QQuickItemPrivate::get(this); QRectF bounds = boundingRect(); + bounds.setHeight(implicitHeight()); + bounds.moveTop((height() - bounds.height()) / 2.0); if (!m_indeterminate) bounds.setWidth(m_progress * bounds.width()); -- cgit v1.2.3