From d59476a0bb93c806c5dfb8bf998b50025ed4f852 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 13 Oct 2016 13:44:01 +0200 Subject: ScrollIndicator: fix documentation review findings Change-Id: Ia742b82e9aaacb35cdde5087ccb1deb977af51ed Task-number: QTBUG-55904 Reviewed-by: J-P Nurmi --- ...quickcontrols2-scrollindicator-non-attached.png | Bin 0 -> 5280 bytes ...quickcontrols2-scrollindicator-non-attached.qml | 97 +++++++++++++++++++++ src/quicktemplates2/qquickscrollindicator.cpp | 43 ++++++++- 3 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 src/imports/controls/doc/images/qtquickcontrols2-scrollindicator-non-attached.png create mode 100644 src/imports/controls/doc/snippets/qtquickcontrols2-scrollindicator-non-attached.qml (limited to 'src') diff --git a/src/imports/controls/doc/images/qtquickcontrols2-scrollindicator-non-attached.png b/src/imports/controls/doc/images/qtquickcontrols2-scrollindicator-non-attached.png new file mode 100644 index 00000000..758e0451 Binary files /dev/null and b/src/imports/controls/doc/images/qtquickcontrols2-scrollindicator-non-attached.png differ diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-scrollindicator-non-attached.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-scrollindicator-non-attached.qml new file mode 100644 index 00000000..2734f33a --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-scrollindicator-non-attached.qml @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 + +Item { + width: 200 + height: 200 + +//! [1] +Rectangle { + id: frame + clip: true + width: 160 + height: 160 + border.color: "black" + anchors.centerIn: parent + + Text { + id: content + text: "ABC" + font.pixelSize: 169 + + MouseArea { + id: mouseArea + drag.target: content + drag.minimumX: frame.width - width + drag.minimumY: frame.height - height + drag.maximumX: 0 + drag.maximumY: 0 + anchors.fill: content + } + } + + ScrollIndicator { + id: verticalIndicator + active: mouseArea.pressed + orientation: Qt.Vertical + size: frame.height / content.height + position: -content.y / content.height + anchors { top: parent.top; right: parent.right; bottom: parent.bottom } + } + + ScrollIndicator { + id: horizontalIndicator + active: mouseArea.pressed + orientation: Qt.Horizontal + size: frame.width / content.width + position: -content.x / content.width + anchors { left: parent.left; right: parent.right; bottom: parent.bottom } + } +} +//! [1] + +Component.onCompleted: { + horizontalIndicator.active = true; + verticalIndicator.active = true; +} +} diff --git a/src/quicktemplates2/qquickscrollindicator.cpp b/src/quicktemplates2/qquickscrollindicator.cpp index 968f671d..7d93215d 100644 --- a/src/quicktemplates2/qquickscrollindicator.cpp +++ b/src/quicktemplates2/qquickscrollindicator.cpp @@ -65,9 +65,12 @@ QT_BEGIN_NAMESPACE } \endcode - When ScrollIndicator is attached \l {ScrollIndicator::vertical}{vertically} or - \l {ScrollIndicator::horizontal}{horizontally} to a Flickable, the following - properties are automatically set and updated as appropriate: + \section1 Attaching ScrollIndicator to a Flickable + + \note When ScrollIndicator is attached \l {ScrollIndicator::vertical}{vertically} + or \l {ScrollIndicator::horizontal}{horizontally} to a Flickable, its geometry and + the following properties are automatically set and updated as appropriate: + \list \li \l orientation \li \l position @@ -98,6 +101,8 @@ QT_BEGIN_NAMESPACE } \endcode + \section1 Binding the Active State of Horizontal and Vertical Scroll Indicators + Horizontal and vertical scroll indicators do not share the \l active state with each other by default. In order to keep both indicators visible whilst scrolling to either direction, establish a two-way binding between the active states as @@ -105,6 +110,19 @@ QT_BEGIN_NAMESPACE \snippet qtquickcontrols2-scrollindicator-active.qml 1 + \section1 Non-attached Scroll Indicators + + It is possible to create an instance of ScrollIndicator without using the + attached property API. This is useful when the behavior of the attached + scoll indicator is not sufficient or a \l Flickable is not in use. In the + following example, horizontal and vertical scroll indicators are used to + indicate how far the user has scrolled over the text (using \l MouseArea + instead of \l Flickable): + + \snippet qtquickcontrols2-scrollindicator-non-attached.qml 1 + + \image qtquickcontrols2-scrollindicator-non-attached.png + \sa ScrollBar, {Customizing ScrollIndicator}, {Indicator Controls} */ @@ -166,6 +184,9 @@ QQuickScrollIndicatorAttached *QQuickScrollIndicator::qmlAttachedProperties(QObj This property holds the size of the indicator, scaled to \c {0.0 - 1.0}. \sa {Flickable::visibleArea.heightRatio}{Flickable::visibleArea} + + This property is automatically set when the scroll indicator is + \l {Attaching ScrollIndicator to a Flickable}{attached to a flickable}. */ qreal QQuickScrollIndicator::size() const { @@ -190,6 +211,9 @@ void QQuickScrollIndicator::setSize(qreal size) This property holds the position of the indicator, scaled to \c {0.0 - 1.0}. + This property is automatically set when the scroll indicator is + \l {Attaching ScrollIndicator to a Flickable}{attached to a flickable}. + \sa {Flickable::visibleArea.yPosition}{Flickable::visibleArea} */ qreal QQuickScrollIndicator::position() const @@ -215,6 +239,12 @@ void QQuickScrollIndicator::setPosition(qreal position) This property holds whether the indicator is active, that is, when the attached Flickable is \l {Flickable::moving}{moving}. + + It is possible to keep \l {Binding the Active State of Horizontal and Vertical Scroll Indicators} + {both horizontal and vertical indicators visible} while scrolling in either direction. + + This property is automatically set when the scroll indicator is + \l {Attaching ScrollIndicator to a Flickable}{attached to a flickable}. */ bool QQuickScrollIndicator::isActive() const { @@ -240,6 +270,9 @@ void QQuickScrollIndicator::setActive(bool active) Possible values: \value Qt.Horizontal Horizontal \value Qt.Vertical Vertical (default) + + This property is automatically set when the scroll indicator is + \l {Attaching ScrollIndicator to a Flickable}{attached to a flickable}. */ Qt::Orientation QQuickScrollIndicator::orientation() const { @@ -363,6 +396,8 @@ QQuickScrollIndicatorAttached::~QQuickScrollIndicatorAttached() ScrollIndicator.horizontal: ScrollIndicator { } } \endcode + + \sa {Attaching ScrollIndicator to a Flickable} */ QQuickScrollIndicator *QQuickScrollIndicatorAttached::horizontal() const { @@ -419,6 +454,8 @@ void QQuickScrollIndicatorAttached::setHorizontal(QQuickScrollIndicator *horizon ScrollIndicator.vertical: ScrollIndicator { } } \endcode + + \sa {Attaching ScrollIndicator to a Flickable} */ QQuickScrollIndicator *QQuickScrollIndicatorAttached::vertical() const { -- cgit v1.2.3