From 7280a42c2591609d574ad407189a491f06f04f9d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 5 Feb 2016 12:35:34 +0100 Subject: CheckBox: migrate from label to contentItem Change-Id: Ie35fc6a9a5424c6f002480fc461b7cd5fe84753b Reviewed-by: Mitch Curtis --- src/imports/controls/CheckBox.qml | 20 +++++------ .../images/qtlabscontrols-checkbox-contentItem.png | Bin 0 -> 2582 bytes .../doc/images/qtlabscontrols-checkbox-label.png | Bin 2582 -> 0 bytes .../qtlabscontrols-checkbox-contentItem.qml | 38 +++++++++++++++++++++ .../doc/snippets/qtlabscontrols-checkbox-label.qml | 38 --------------------- .../controls/doc/src/qtlabscontrols-customize.qdoc | 8 ++--- src/imports/controls/material/CheckBox.qml | 20 +++++------ src/imports/controls/universal/CheckBox.qml | 20 +++++------ tests/auto/controls/data/tst_checkbox.qml | 2 +- 9 files changed, 67 insertions(+), 79 deletions(-) create mode 100644 src/imports/controls/doc/images/qtlabscontrols-checkbox-contentItem.png delete mode 100644 src/imports/controls/doc/images/qtlabscontrols-checkbox-label.png create mode 100644 src/imports/controls/doc/snippets/qtlabscontrols-checkbox-contentItem.qml delete mode 100644 src/imports/controls/doc/snippets/qtlabscontrols-checkbox-label.qml diff --git a/src/imports/controls/CheckBox.qml b/src/imports/controls/CheckBox.qml index 4b7af3b1..52061681 100644 --- a/src/imports/controls/CheckBox.qml +++ b/src/imports/controls/CheckBox.qml @@ -41,13 +41,11 @@ T.CheckBox { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - (label ? label.implicitWidth : 0) + - (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? spacing : 0) + leftPadding + rightPadding) + contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - Math.max(label ? label.implicitHeight : 0, + Math.max(contentItem.implicitHeight, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) - baselineOffset: label ? label.y + label.baselineOffset : 0 + baselineOffset: contentItem.y + contentItem.baselineOffset padding: 6 spacing: 6 @@ -81,12 +79,10 @@ T.CheckBox { } //! [indicator] - //! [label] - label: Text { - x: control.mirrored ? control.leftPadding : (indicator.x + indicator.width + control.spacing) - y: control.topPadding - width: control.availableWidth - indicator.width - control.spacing - height: control.availableHeight + //! [contentItem] + contentItem: Text { + leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0 + rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0 text: control.text font: control.font @@ -96,5 +92,5 @@ T.CheckBox { horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } - //! [label] + //! [contentItem] } diff --git a/src/imports/controls/doc/images/qtlabscontrols-checkbox-contentItem.png b/src/imports/controls/doc/images/qtlabscontrols-checkbox-contentItem.png new file mode 100644 index 00000000..d5a1ef2e Binary files /dev/null and b/src/imports/controls/doc/images/qtlabscontrols-checkbox-contentItem.png differ diff --git a/src/imports/controls/doc/images/qtlabscontrols-checkbox-label.png b/src/imports/controls/doc/images/qtlabscontrols-checkbox-label.png deleted file mode 100644 index d5a1ef2e..00000000 Binary files a/src/imports/controls/doc/images/qtlabscontrols-checkbox-label.png and /dev/null differ diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-checkbox-contentItem.qml b/src/imports/controls/doc/snippets/qtlabscontrols-checkbox-contentItem.qml new file mode 100644 index 00000000..bef150a3 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtlabscontrols-checkbox-contentItem.qml @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** 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 + +CheckBox { + text: "CheckBox" + Rectangle { + anchors.fill: contentItem + color: "transparent" + border.color: "red" + } +} diff --git a/src/imports/controls/doc/snippets/qtlabscontrols-checkbox-label.qml b/src/imports/controls/doc/snippets/qtlabscontrols-checkbox-label.qml deleted file mode 100644 index fcb3a49d..00000000 --- a/src/imports/controls/doc/snippets/qtlabscontrols-checkbox-label.qml +++ /dev/null @@ -1,38 +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 - -CheckBox { - text: "CheckBox" - Rectangle { - anchors.fill: label - 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 0cda2dd9..bc901cea 100644 --- a/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc +++ b/src/imports/controls/doc/src/qtlabscontrols-customize.qdoc @@ -75,7 +75,7 @@ \section1 Customizing CheckBox CheckBox consists of three visual items: \l {Control::background}{background}, - \l {AbstractButton::label}{label} and \l {AbstractButton::indicator}{indicator}. + \l {Control::contentItem}{contentItem} and \l {AbstractButton::indicator}{indicator}. \section3 Background @@ -83,11 +83,11 @@ CheckBox has no background item by default. - \section3 Label + \section3 Content item - \image qtlabscontrols-checkbox-label.png + \image qtlabscontrols-checkbox-contentItem.png - \snippet CheckBox.qml label + \snippet CheckBox.qml contentItem \section3 Indicator diff --git a/src/imports/controls/material/CheckBox.qml b/src/imports/controls/material/CheckBox.qml index 88a8a3fc..abaf571d 100644 --- a/src/imports/controls/material/CheckBox.qml +++ b/src/imports/controls/material/CheckBox.qml @@ -43,13 +43,11 @@ T.CheckBox { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - (label ? label.implicitWidth : 0) + - (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? spacing : 0) + leftPadding + rightPadding) + contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - Math.max(label ? label.implicitHeight : 0, + Math.max(contentItem.implicitHeight, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) - baselineOffset: label ? label.y + label.baselineOffset : 0 + baselineOffset: contentItem.y + contentItem.baselineOffset spacing: 8 topPadding: 14 @@ -144,12 +142,10 @@ T.CheckBox { } //! [indicator] - //! [label] - label: Text { - x: control.mirrored ? control.leftPadding : (indicator.x + indicator.width + control.spacing) - y: control.topPadding - width: control.availableWidth - indicator.width - control.spacing - height: control.availableHeight + //! [contentItem] + contentItem: Text { + leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0 + rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0 text: control.text font: control.font @@ -159,5 +155,5 @@ T.CheckBox { horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter } - //! [label] + //! [contentItem] } diff --git a/src/imports/controls/universal/CheckBox.qml b/src/imports/controls/universal/CheckBox.qml index 07321a9c..5c645301 100644 --- a/src/imports/controls/universal/CheckBox.qml +++ b/src/imports/controls/universal/CheckBox.qml @@ -42,13 +42,11 @@ T.CheckBox { id: control implicitWidth: Math.max(background ? background.implicitWidth : 0, - (label ? label.implicitWidth : 0) + - (indicator ? indicator.implicitWidth : 0) + - (label && indicator ? spacing : 0) + leftPadding + rightPadding) + contentItem.implicitWidth + leftPadding + rightPadding) implicitHeight: Math.max(background ? background.implicitHeight : 0, - Math.max(label ? label.implicitHeight : 0, + Math.max(contentItem.implicitHeight, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding) - baselineOffset: label ? label.y + label.baselineOffset : 0 + baselineOffset: contentItem ? contentItem.y + contentItem.baselineOffset : 0 padding: 6 spacing: 8 @@ -92,12 +90,10 @@ T.CheckBox { } //! [indicator] - //! [label] - label: Text { - x: control.mirrored ? control.leftPadding : (indicator.x + indicator.width + control.spacing) - y: control.topPadding - width: control.availableWidth - indicator.width - control.spacing - height: control.availableHeight + //! [contentItem] + contentItem: Text { + leftPadding: control.indicator && !control.mirrored ? control.indicator.width + control.spacing : 0 + rightPadding: control.indicator && control.mirrored ? control.indicator.width + control.spacing : 0 text: control.text font: control.font @@ -109,5 +105,5 @@ T.CheckBox { color: !control.enabled ? control.Universal.baseLowColor : control.Universal.baseHighColor } - //! [label] + //! [contentItem] } diff --git a/tests/auto/controls/data/tst_checkbox.qml b/tests/auto/controls/data/tst_checkbox.qml index 4efc7223..7e0c88e4 100644 --- a/tests/auto/controls/data/tst_checkbox.qml +++ b/tests/auto/controls/data/tst_checkbox.qml @@ -421,7 +421,7 @@ TestCase { function test_baseline() { var control = checkBox.createObject(testCase) verify(control) - compare(control.baselineOffset, control.label.y + control.label.baselineOffset) + compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) control.destroy() } } -- cgit v1.2.3