diff options
23 files changed, 629 insertions, 87 deletions
diff --git a/src/imports/controls/SwipeView.qml b/src/imports/controls/SwipeView.qml index 42a327a0..555775ee 100644 --- a/src/imports/controls/SwipeView.qml +++ b/src/imports/controls/SwipeView.qml @@ -46,8 +46,6 @@ T.SwipeView { implicitHeight: Math.max(background ? background.implicitHeight : 0, contentItem.implicitHeight + topPadding + bottomPadding) - Accessible.role: Accessible.PageTabList - contentItem: ListView { model: control.contentModel interactive: control.interactive diff --git a/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-non-attached.png b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-non-attached.png Binary files differnew file mode 100644 index 00000000..8817ad5c --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-scrollbar-non-attached.png diff --git a/src/imports/controls/doc/images/qtquickcontrols2-scrollindicator-non-attached.png b/src/imports/controls/doc/images/qtquickcontrols2-scrollindicator-non-attached.png Binary files differnew file mode 100644 index 00000000..758e0451 --- /dev/null +++ b/src/imports/controls/doc/images/qtquickcontrols2-scrollindicator-non-attached.png diff --git a/src/imports/controls/doc/snippets/qtquickcontrols2-scrollbar-non-attached.qml b/src/imports/controls/doc/snippets/qtquickcontrols2-scrollbar-non-attached.qml new file mode 100644 index 00000000..f80ebfe2 --- /dev/null +++ b/src/imports/controls/doc/snippets/qtquickcontrols2-scrollbar-non-attached.qml @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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: 160 + x: -hbar.position * width + y: -vbar.position * height + } + + ScrollBar { + id: vbar + hoverEnabled: true + active: hovered || pressed + orientation: Qt.Vertical + size: frame.height / content.height + anchors.top: parent.top + anchors.right: parent.right + anchors.bottom: parent.bottom + } + + ScrollBar { + id: hbar + hoverEnabled: true + active: hovered || pressed + orientation: Qt.Horizontal + size: frame.width / content.width + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + } +} +//! [1] + +Component.onCompleted: { + hbar.active = true + vbar.active = true +} +} 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/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp index fba21453..a0fcbe8c 100644 --- a/src/quicktemplates2/qquickcombobox.cpp +++ b/src/quicktemplates2/qquickcombobox.cpp @@ -130,6 +130,11 @@ QT_BEGIN_NAMESPACE \sa highlightedIndex */ +namespace { + enum Activation { NoActivate, Activate }; + enum Highlighting { NoHighlight, Highlight }; +} + class QQuickComboBoxDelegateModel : public QQmlDelegateModel { public: @@ -181,8 +186,12 @@ public: void updateCurrentText(); void incrementCurrentIndex(); void decrementCurrentIndex(); + void setCurrentIndex(int index, Activation activate); void updateHighlightedIndex(); - void setHighlightedIndex(int index); + void setHighlightedIndex(int index, Highlighting highlight); + + void keySearch(const QString &text); + int match(int start, const QString &text, Qt::MatchFlags flags) const; void createDelegateModel(); @@ -242,8 +251,7 @@ void QQuickComboBoxPrivate::itemClicked() Q_Q(QQuickComboBox); int index = delegateModel->indexOf(q->sender(), nullptr); if (index != -1) { - setHighlightedIndex(index); - emit q->highlighted(index); + setHighlightedIndex(index, Highlight); hidePopup(true); } } @@ -284,44 +292,51 @@ void QQuickComboBoxPrivate::updateCurrentText() } } +void QQuickComboBoxPrivate::setCurrentIndex(int index, Activation activate) +{ + Q_Q(QQuickComboBox); + if (currentIndex == index) + return; + + currentIndex = index; + emit q->currentIndexChanged(); + + if (componentComplete) + updateCurrentText(); + + if (activate) + emit q->activated(index); +} + void QQuickComboBoxPrivate::incrementCurrentIndex() { Q_Q(QQuickComboBox); if (isPopupVisible()) { - if (highlightedIndex < q->count() - 1) { - setHighlightedIndex(highlightedIndex + 1); - emit q->highlighted(highlightedIndex); - } + if (highlightedIndex < q->count() - 1) + setHighlightedIndex(highlightedIndex + 1, Highlight); } else { - if (currentIndex < q->count() - 1) { - q->setCurrentIndex(currentIndex + 1); - emit q->activated(currentIndex); - } + if (currentIndex < q->count() - 1) + setCurrentIndex(currentIndex + 1, Activate); } } void QQuickComboBoxPrivate::decrementCurrentIndex() { - Q_Q(QQuickComboBox); if (isPopupVisible()) { - if (highlightedIndex > 0) { - setHighlightedIndex(highlightedIndex - 1); - emit q->highlighted(highlightedIndex); - } + if (highlightedIndex > 0) + setHighlightedIndex(highlightedIndex - 1, Highlight); } else { - if (currentIndex > 0) { - q->setCurrentIndex(currentIndex - 1); - emit q->activated(currentIndex); - } + if (currentIndex > 0) + setCurrentIndex(currentIndex - 1, Activate); } } void QQuickComboBoxPrivate::updateHighlightedIndex() { - setHighlightedIndex(popup->isVisible() ? currentIndex : -1); + setHighlightedIndex(popup->isVisible() ? currentIndex : -1, NoHighlight); } -void QQuickComboBoxPrivate::setHighlightedIndex(int index) +void QQuickComboBoxPrivate::setHighlightedIndex(int index, Highlighting highlight) { Q_Q(QQuickComboBox); if (highlightedIndex == index) @@ -329,6 +344,68 @@ void QQuickComboBoxPrivate::setHighlightedIndex(int index) highlightedIndex = index; emit q->highlightedIndexChanged(); + + if (highlight) + emit q->highlighted(index); +} + +void QQuickComboBoxPrivate::keySearch(const QString &text) +{ + int index = match(currentIndex + 1, text, Qt::MatchStartsWith | Qt::MatchWrap); + if (index != -1) + setCurrentIndex(index, Activate); +} + +int QQuickComboBoxPrivate::match(int start, const QString &text, Qt::MatchFlags flags) const +{ + Q_Q(const QQuickComboBox); + uint matchType = flags & 0x0F; + bool wrap = flags & Qt::MatchWrap; + Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; + int from = start; + int to = q->count(); + + // iterates twice if wrapping + for (int i = 0; (wrap && i < 2) || (!wrap && i < 1); ++i) { + for (int idx = from; idx < to; ++idx) { + QString t = q->textAt(idx); + switch (matchType) { + case Qt::MatchExactly: + if (t == text) + return idx; + break; + case Qt::MatchRegExp: + if (QRegExp(text, cs).exactMatch(t)) + return idx; + break; + case Qt::MatchWildcard: + if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t)) + return idx; + break; + case Qt::MatchStartsWith: + if (t.startsWith(text, cs)) + return idx; + break; + case Qt::MatchEndsWith: + if (t.endsWith(text, cs)) + return idx; + break; + case Qt::MatchFixedString: + if (t.compare(text, cs) == 0) + return idx; + break; + case Qt::MatchContains: + default: + if (t.contains(text, cs)) + return idx; + break; + } + } + // prepare for the next iteration + from = 0; + to = start; + } + return -1; } void QQuickComboBoxPrivate::createDelegateModel() @@ -541,13 +618,7 @@ void QQuickComboBox::setCurrentIndex(int index) { Q_D(QQuickComboBox); d->hasCurrentIndex = true; - if (d->currentIndex == index) - return; - - d->currentIndex = index; - emit currentIndexChanged(); - if (isComponentComplete()) - d->updateCurrentText(); + d->setCurrentIndex(index, NoActivate); } /*! @@ -792,45 +863,8 @@ QString QQuickComboBox::textAt(int index) const */ int QQuickComboBox::find(const QString &text, Qt::MatchFlags flags) const { - int itemCount = count(); - uint matchType = flags & 0x0F; - Qt::CaseSensitivity cs = flags & Qt::MatchCaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; - - for (int idx = 0; idx < itemCount; ++idx) { - QString t = textAt(idx); - switch (matchType) { - case Qt::MatchExactly: - if (t == text) - return idx; - break; - case Qt::MatchRegExp: - if (QRegExp(text, cs).exactMatch(t)) - return idx; - break; - case Qt::MatchWildcard: - if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t)) - return idx; - break; - case Qt::MatchStartsWith: - if (t.startsWith(text, cs)) - return idx; - break; - case Qt::MatchEndsWith: - if (t.endsWith(text, cs)) - return idx; - break; - case Qt::MatchFixedString: - if (t.compare(text, cs) == 0) - return idx; - break; - case Qt::MatchContains: - default: - if (t.contains(text, cs)) - return idx; - break; - } - } - return -1; + Q_D(const QQuickComboBox); + return d->match(0, text, flags); } /*! @@ -873,8 +907,6 @@ void QQuickComboBox::keyPressEvent(QKeyEvent *event) { Q_D(QQuickComboBox); QQuickControl::keyPressEvent(event); - if (!d->popup) - return; switch (event->key()) { case Qt::Key_Escape: @@ -901,7 +933,25 @@ void QQuickComboBox::keyPressEvent(QKeyEvent *event) d->incrementCurrentIndex(); event->accept(); break; + case Qt::Key_Home: + if (d->isPopupVisible()) + d->setHighlightedIndex(0, Highlight); + else + d->setCurrentIndex(0, Activate); + event->accept(); + break; + case Qt::Key_End: + if (d->isPopupVisible()) + d->setHighlightedIndex(count() - 1, Highlight); + else + d->setCurrentIndex(count() - 1, Activate); + event->accept(); + break; default: + if (!event->text().isEmpty()) + d->keySearch(event->text()); + else + event->ignore(); break; } } diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index fd8d9b51..3b224698 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -2409,7 +2409,7 @@ QFont QQuickPopup::defaultFont() const #ifndef QT_NO_ACCESSIBILITY QAccessible::Role QQuickPopup::accessibleRole() const { - return QAccessible::LayeredPane; + return QAccessible::Dialog; } void QQuickPopup::accessibilityActiveChanged(bool active) diff --git a/src/quicktemplates2/qquickscrollbar.cpp b/src/quicktemplates2/qquickscrollbar.cpp index 5df4c4fb..8e6db063 100644 --- a/src/quicktemplates2/qquickscrollbar.cpp +++ b/src/quicktemplates2/qquickscrollbar.cpp @@ -65,9 +65,12 @@ QT_BEGIN_NAMESPACE } \endcode + \section1 Attaching ScrollBar to a Flickable + When ScrollBar is attached \l {ScrollBar::vertical}{vertically} or - \l {ScrollBar::horizontal}{horizontally} to a Flickable, the following - properties are automatically set and updated as appropriate: + \l {ScrollBar::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 @@ -113,6 +116,8 @@ QT_BEGIN_NAMESPACE } \endcode + \section1 Binding the Active State of Horizontal and Vertical Scroll Bars + Horizontal and vertical scroll bars do not share the \l active state with each other by default. In order to keep both bars visible whilst scrolling to either direction, establish a two-way binding between the active states @@ -120,6 +125,29 @@ QT_BEGIN_NAMESPACE \snippet qtquickcontrols2-scrollbar-active.qml 1 + \section1 Non-attached Scroll Bars + + It is possible to create an instance of ScrollBar without using the + attached property API. This is useful when the behavior of the attached + scoll bar is not sufficient or a \l Flickable is not in use. In the + following example, horizontal and vertical scroll bars are used to + scroll over the text without using \l Flickable: + + \snippet qtquickcontrols2-scrollbar-non-attached.qml 1 + + \image qtquickcontrols2-scrollbar-non-attached.png + + When using a non-attached ScrollBar, the following must be done manually: + + \list + \li Layout the scroll bar (with the \l {Item::}{x} and \l {Item::}{y} or + \l {Item::anchors}{anchor} properties, for example). + \li Set the \l size and \l position properties to determine the size and position + of the scroll bar in relation to the scrolled item. + \li Set the \l active property to determine when the scroll bar will be + visible. + \endlist + \sa ScrollIndicator, {Customizing ScrollBar}, {Indicator Controls} */ @@ -205,6 +233,9 @@ QQuickScrollBarAttached *QQuickScrollBar::qmlAttachedProperties(QObject *object) This property holds the size of the scroll bar, scaled to \c {0.0 - 1.0}. \sa {Flickable::visibleArea.heightRatio}{Flickable::visibleArea} + + This property is automatically set when the scroll bar is + \l {Attaching ScrollBar to a Flickable}{attached to a flickable}. */ qreal QQuickScrollBar::size() const { @@ -231,6 +262,9 @@ void QQuickScrollBar::setSize(qreal size) This property holds the position of the scroll bar, scaled to \c {0.0 - 1.0}. \sa {Flickable::visibleArea.yPosition}{Flickable::visibleArea} + + This property is automatically set when the scroll bar is + \l {Attaching ScrollBar to a Flickable}{attached to a flickable}. */ qreal QQuickScrollBar::position() const { @@ -279,6 +313,12 @@ void QQuickScrollBar::setStepSize(qreal step) This property holds whether the scroll bar is active, i.e. when it's \l pressed or the attached Flickable is \l {Flickable::moving}{moving}. + + It is possible to keep \l {Binding the Active State of Horizontal and Vertical Scroll Bars} + {both horizontal and vertical bars visible} while scrolling in either direction. + + This property is automatically set when the scroll bar is + \l {Attaching ScrollBar to a Flickable}{attached to a flickable}. */ bool QQuickScrollBar::isActive() const { @@ -327,6 +367,9 @@ void QQuickScrollBar::setPressed(bool pressed) Possible values: \value Qt.Horizontal Horizontal \value Qt.Vertical Vertical (default) + + This property is automatically set when the scroll bar is + \l {Attaching ScrollBar to a Flickable}{attached to a flickable}. */ Qt::Orientation QQuickScrollBar::orientation() const { @@ -572,6 +615,8 @@ QQuickScrollBarAttached::~QQuickScrollBarAttached() ScrollBar.horizontal: ScrollBar { } } \endcode + + \sa {Attaching ScrollBar to a Flickable} */ QQuickScrollBar *QQuickScrollBarAttached::horizontal() const { @@ -630,6 +675,8 @@ void QQuickScrollBarAttached::setHorizontal(QQuickScrollBar *horizontal) ScrollBar.vertical: ScrollBar { } } \endcode + + \sa {Attaching ScrollBar to a Flickable} */ QQuickScrollBar *QQuickScrollBarAttached::vertical() const { diff --git a/src/quicktemplates2/qquickscrollindicator.cpp b/src/quicktemplates2/qquickscrollindicator.cpp index d6370d2d..9f2f6eb9 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 { diff --git a/src/quicktemplates2/qquickstackview.cpp b/src/quicktemplates2/qquickstackview.cpp index c4bba4c8..d16d7b16 100644 --- a/src/quicktemplates2/qquickstackview.cpp +++ b/src/quicktemplates2/qquickstackview.cpp @@ -992,6 +992,13 @@ bool QQuickStackView::childMouseEventFilter(QQuickItem *item, QEvent *event) return window && !window->mouseGrabberItem(); } +#ifndef QT_NO_ACCESSIBILITY +QAccessible::Role QQuickStackView::accessibleRole() const +{ + return QAccessible::LayeredPane; +} +#endif + void QQuickStackAttachedPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) { Q_Q(QQuickStackAttached); diff --git a/src/quicktemplates2/qquickstackview_p.h b/src/quicktemplates2/qquickstackview_p.h index 9bf60183..7491f8f6 100644 --- a/src/quicktemplates2/qquickstackview_p.h +++ b/src/quicktemplates2/qquickstackview_p.h @@ -152,6 +152,10 @@ protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; bool childMouseEventFilter(QQuickItem *, QEvent *) override; +#ifndef QT_NO_ACCESSIBILITY + QAccessible::Role accessibleRole() const override; +#endif + private: Q_DISABLE_COPY(QQuickStackView) Q_DECLARE_PRIVATE(QQuickStackView) diff --git a/src/quicktemplates2/qquickswipeview.cpp b/src/quicktemplates2/qquickswipeview.cpp index a044169a..ef98c59b 100644 --- a/src/quicktemplates2/qquickswipeview.cpp +++ b/src/quicktemplates2/qquickswipeview.cpp @@ -192,6 +192,13 @@ void QQuickSwipeView::itemAdded(int, QQuickItem *item) item->setSize(QSizeF(d->contentItem->width(), d->contentItem->height())); } +#ifndef QT_NO_ACCESSIBILITY +QAccessible::Role QQuickSwipeView::accessibleRole() const +{ + return QAccessible::PageTabList; +} +#endif + /*! \qmlattachedproperty int QtQuick.Controls::SwipeView::index \readonly diff --git a/src/quicktemplates2/qquickswipeview_p.h b/src/quicktemplates2/qquickswipeview_p.h index e29d2b28..8c489d53 100644 --- a/src/quicktemplates2/qquickswipeview_p.h +++ b/src/quicktemplates2/qquickswipeview_p.h @@ -75,6 +75,10 @@ protected: void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void itemAdded(int index, QQuickItem *item) override; +#ifndef QT_NO_ACCESSIBILITY + QAccessible::Role accessibleRole() const override; +#endif + private: Q_DISABLE_COPY(QQuickSwipeView) Q_DECLARE_PRIVATE(QQuickSwipeView) diff --git a/tests/auto/accessibility/data/abstractbutton.qml b/tests/auto/accessibility/data/abstractbutton.qml new file mode 100644 index 00000000..368f4582 --- /dev/null +++ b/tests/auto/accessibility/data/abstractbutton.qml @@ -0,0 +1,6 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +AbstractButton { + text: "AbstractButton" +} diff --git a/tests/auto/accessibility/data/container.qml b/tests/auto/accessibility/data/container.qml new file mode 100644 index 00000000..806ebe78 --- /dev/null +++ b/tests/auto/accessibility/data/container.qml @@ -0,0 +1,4 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +Container { } diff --git a/tests/auto/accessibility/data/drawer.qml b/tests/auto/accessibility/data/drawer.qml new file mode 100644 index 00000000..12652164 --- /dev/null +++ b/tests/auto/accessibility/data/drawer.qml @@ -0,0 +1,4 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +Drawer { } diff --git a/tests/auto/accessibility/data/radiodelegate.qml b/tests/auto/accessibility/data/radiodelegate.qml new file mode 100644 index 00000000..93ccafde --- /dev/null +++ b/tests/auto/accessibility/data/radiodelegate.qml @@ -0,0 +1,6 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +RadioDelegate { + text: "RadioDelegate" +} diff --git a/tests/auto/accessibility/data/stackview.qml b/tests/auto/accessibility/data/stackview.qml new file mode 100644 index 00000000..cf3b76c2 --- /dev/null +++ b/tests/auto/accessibility/data/stackview.qml @@ -0,0 +1,4 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +StackView { } diff --git a/tests/auto/accessibility/data/swipedelegate.qml b/tests/auto/accessibility/data/swipedelegate.qml new file mode 100644 index 00000000..a8acb5e0 --- /dev/null +++ b/tests/auto/accessibility/data/swipedelegate.qml @@ -0,0 +1,6 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +SwipeDelegate { + text: "SwipeDelegate" +} diff --git a/tests/auto/accessibility/data/swipeview.qml b/tests/auto/accessibility/data/swipeview.qml new file mode 100644 index 00000000..018ab772 --- /dev/null +++ b/tests/auto/accessibility/data/swipeview.qml @@ -0,0 +1,4 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +SwipeView { } diff --git a/tests/auto/accessibility/data/tumbler.qml b/tests/auto/accessibility/data/tumbler.qml new file mode 100644 index 00000000..11c737d7 --- /dev/null +++ b/tests/auto/accessibility/data/tumbler.qml @@ -0,0 +1,4 @@ +import QtQuick 2.5 +import QtQuick.Controls 2.0 + +Tumbler { } diff --git a/tests/auto/accessibility/tst_accessibility.cpp b/tests/auto/accessibility/tst_accessibility.cpp index d61a4e7f..b4286aad 100644 --- a/tests/auto/accessibility/tst_accessibility.cpp +++ b/tests/auto/accessibility/tst_accessibility.cpp @@ -64,12 +64,17 @@ void tst_accessibility::a11y_data() QTest::addColumn<int>("role"); QTest::addColumn<QString>("text"); + QTest::newRow("AbstractButton") << "abstractbutton" << 0x0000002B << "AbstractButton"; //QAccessible::Button QTest::newRow("BusyIndicator") << "busyindicator" << 0x00000027 << ""; //QAccessible::Indicator QTest::newRow("Button") << "button" << 0x0000002B << "Button"; //QAccessible::Button QTest::newRow("CheckBox") << "checkbox" << 0x0000002C << "CheckBox"; //QAccessible::CheckBox QTest::newRow("CheckDelegate") << "checkdelegate" << 0x0000002C << "CheckDelegate"; //QAccessible::CheckBox QTest::newRow("ComboBox") << "combobox" << 0x0000002E << "ComboBox"; //QAccessible::ComboBox + QTest::newRow("Container") << "container" << 0x00000000 << ""; //QAccessible::NoRole + QTest::newRow("Control") << "control" << 0x00000000 << ""; //QAccessible::NoRole + QTest::newRow("Dial") << "dial" << 0x00000031 << ""; //QAccessible::Dial QTest::newRow("Dialog") << "dialog" << 0x00000012 << "Dialog"; //QAccessible::Dialog + QTest::newRow("Drawer") << "drawer" << 0x00000012 << ""; //QAccessible::Dialog QTest::newRow("Frame") << "frame" << 0x00000013 << ""; //QAccessible::Border QTest::newRow("GroupBox") << "groupbox" << 0x00000014 << "GroupBox"; //QAccessible::Grouping QTest::newRow("ItemDelegate") << "itemdelegate" << 0x00000022 << "ItemDelegate"; //QAccessible::ListItem @@ -79,16 +84,19 @@ void tst_accessibility::a11y_data() QTest::newRow("Page") << "page" << 0x00000025 << "Page"; //QAccessible::PageTab QTest::newRow("PageIndicator") << "pageindicator" << 0x00000027 << ""; //QAccessible::Indicator QTest::newRow("Pane") << "pane" << 0x00000010 << ""; //QAccessible::Pane - QTest::newRow("Popup") << "popup" << 0x00000080 << ""; //QAccessible::LayeredPane + QTest::newRow("Popup") << "popup" << 0x00000012 << ""; //QAccessible::Dialog QTest::newRow("ProgressBar") << "progressbar" << 0x00000030 << ""; //QAccessible::ProgressBar QTest::newRow("RadioButton") << "radiobutton" << 0x0000002D << "RadioButton"; //QAccessible::RadioButton + QTest::newRow("RadioDelegate") << "radiodelegate" << 0x0000002D << "RadioDelegate"; //QAccessible::RadioButton QTest::newRow("RangeSlider") << "rangeslider" << 0x00000033 << ""; //QAccessible::Slider QTest::newRow("RoundButton") << "roundbutton" << 0x0000002B << "RoundButton"; //QAccessible::Button QTest::newRow("ScrollBar") << "scrollbar" << 0x00000003 << ""; //QAccessible::ScrollBar QTest::newRow("ScrollIndicator") << "scrollindicator" << 0x00000027 << ""; //QAccessible::Indicator QTest::newRow("Slider") << "slider" << 0x00000033 << ""; //QAccessible::Slider QTest::newRow("SpinBox") << "spinbox" << 0x00000034 << ""; //QAccessible::SpinBox - // StackView + QTest::newRow("StackView") << "stackview" << 0x00000080 << ""; //QAccessible::LayeredPane + QTest::newRow("SwipeDelegate") << "swipedelegate" << 0x00000022 << "SwipeDelegate"; //QAccessible::ListItem + QTest::newRow("SwipeView") << "swipeview" << 0x0000003C << ""; //QAccessible::Pane QTest::newRow("Switch") << "switch" << 0x0000002B << "Switch"; //QAccessible::Button QTest::newRow("SwitchDelegate") << "switchdelegate" << 0x00000022 << "SwitchDelegate"; //QAccessible::ListItem QTest::newRow("TabBar") << "tabbar" << 0x0000003C << ""; //QAccessible::PageTabList @@ -98,11 +106,7 @@ void tst_accessibility::a11y_data() QTest::newRow("ToolBar") << "toolbar" << 0x00000016 << ""; //QAccessible::ToolBar QTest::newRow("ToolButton") << "toolbutton" << 0x0000002B << "ToolButton"; //QAccessible::Button QTest::newRow("ToolTip") << "tooltip" << 0x0000000D << "ToolTip"; //QAccessible::ToolTip - - QTest::newRow("Dial") << "dial" << 0x00000031 << ""; //QAccessible::Dial - // Drawer - // SwipeView - // Tumbler + QTest::newRow("Tumbler") << "tumbler" << 0x00000000 << ""; //QAccessible::NoRole (TODO) QTest::newRow("DayOfWeekRow") << "dayofweekrow" << 0x0 << "DayOfWeekRow"; //QAccessible::NoRole QTest::newRow("MonthGrid") << "monthgrid" << 0x0 << "MonthGrid"; //QAccessible::NoRole diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index cc0c4de3..2ba9be8f 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -432,7 +432,7 @@ TestCase { control.destroy() } - function test_keys_data() { + function test_keys_space_enter_escape_data() { return [ { tag: "space-space", key1: Qt.Key_Space, key2: Qt.Key_Space, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, { tag: "space-enter", key1: Qt.Key_Space, key2: Qt.Key_Enter, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, @@ -445,7 +445,7 @@ TestCase { ] } - function test_keys(data) { + function test_keys_space_enter_escape(data) { var control = comboBox.createObject(testCase, {model: 3}) verify(control) @@ -475,6 +475,162 @@ TestCase { control.destroy() } + function test_keys_home_end() { + var control = comboBox.createObject(testCase, {model: 5}) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + compare(control.currentIndex, 0) + compare(control.highlightedIndex, -1) + + var activatedCount = 0 + var activatedSpy = signalSpy.createObject(control, {target: control, signalName: "activated"}) + verify(activatedSpy.valid) + + var highlightedCount = 0 + var highlightedSpy = signalSpy.createObject(control, {target: control, signalName: "highlighted"}) + verify(highlightedSpy.valid) + + var currentIndexCount = 0 + var currentIndexSpy = signalSpy.createObject(control, {target: control, signalName: "currentIndexChanged"}) + verify(currentIndexSpy.valid) + + var highlightedIndexCount = 0 + var highlightedIndexSpy = signalSpy.createObject(control, {target: control, signalName: "highlightedIndexChanged"}) + verify(highlightedIndexSpy.valid) + + // end (popup closed) + keyClick(Qt.Key_End) + compare(control.currentIndex, 4) + compare(currentIndexSpy.count, ++currentIndexCount) + + compare(control.highlightedIndex, -1) + compare(highlightedIndexSpy.count, highlightedIndexCount) + + compare(activatedSpy.count, ++activatedCount) + compare(activatedSpy.signalArguments[activatedCount-1][0], 4) + + compare(highlightedSpy.count, highlightedCount) + + // repeat (no changes/signals) + keyClick(Qt.Key_End) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + // home (popup closed) + keyClick(Qt.Key_Home) + compare(control.currentIndex, 0) + compare(currentIndexSpy.count, ++currentIndexCount) + + compare(control.highlightedIndex, -1) + compare(highlightedIndexSpy.count, highlightedIndexCount) + + compare(activatedSpy.count, ++activatedCount) + compare(activatedSpy.signalArguments[activatedCount-1][0], 0) + + compare(highlightedSpy.count, highlightedCount) + + // repeat (no changes/signals) + keyClick(Qt.Key_Home) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + control.popup.open() + compare(control.highlightedIndex, 0) + compare(highlightedIndexSpy.count, ++highlightedIndexCount) + compare(highlightedSpy.count, highlightedCount) + + // end (popup open) + keyClick(Qt.Key_End) + compare(control.currentIndex, 0) + compare(currentIndexSpy.count, currentIndexCount) + + compare(control.highlightedIndex, 4) + compare(highlightedIndexSpy.count, ++highlightedIndexCount) + + compare(activatedSpy.count, activatedCount) + + compare(highlightedSpy.count, ++highlightedCount) + compare(highlightedSpy.signalArguments[highlightedCount-1][0], 4) + + // repeat (no changes/signals) + keyClick(Qt.Key_End) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + // home (popup open) + keyClick(Qt.Key_Home) + compare(control.currentIndex, 0) + compare(currentIndexSpy.count, currentIndexCount) + + compare(control.highlightedIndex, 0) + compare(highlightedIndexSpy.count, ++highlightedIndexCount) + + compare(activatedSpy.count, activatedCount) + + compare(highlightedSpy.count, ++highlightedCount) + compare(highlightedSpy.signalArguments[highlightedCount-1][0], 0) + + // repeat (no changes/signals) + keyClick(Qt.Key_Home) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + control.destroy() + } + + function test_keySearch() { + var control = comboBox.createObject(testCase, {model: ["Banana", "Coco", "Coconut", "Apple", "Cocomuffin"]}) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + compare(control.currentIndex, 0) + compare(control.currentText, "Banana") + + keyPress(Qt.Key_C) + compare(control.currentIndex, 1) + compare(control.currentText, "Coco") + + // no match + keyPress(Qt.Key_N) + compare(control.currentIndex, 1) + compare(control.currentText, "Coco") + + keyPress(Qt.Key_C) + compare(control.currentIndex, 2) + compare(control.currentText, "Coconut") + + keyPress(Qt.Key_C) + compare(control.currentIndex, 4) + compare(control.currentText, "Cocomuffin") + + // wrap + keyPress(Qt.Key_C) + compare(control.currentIndex, 1) + compare(control.currentText, "Coco") + + keyPress(Qt.Key_A) + compare(control.currentIndex, 3) + compare(control.currentText, "Apple") + + keyPress(Qt.Key_B) + compare(control.currentIndex, 0) + compare(control.currentText, "Banana") + + control.destroy() + } + function test_popup() { var control = comboBox.createObject(testCase, {model: 3}) verify(control) |