From 00e1cd1046010b9ce963442a3823a2cac24029de Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 8 Sep 2015 09:36:21 +0200 Subject: Extras: merge C++ lib to the QML plugin Change-Id: Idbbe9e0cf1b5b34027035a417fade7b0091da8c5 Reviewed-by: J-P Nurmi --- src/extras/doc/images/.directory | 4 - .../doc/images/qtquickextras2-dial-background.png | Bin 3286 -> 0 bytes .../doc/images/qtquickextras2-dial-handle.png | Bin 3538 -> 0 bytes .../images/qtquickextras2-tumbler-background.png | Bin 1025 -> 0 bytes .../images/qtquickextras2-tumbler-contentItem.png | Bin 1025 -> 0 bytes .../doc/images/qtquickextras2-tumbler-delegate.png | Bin 1047 -> 0 bytes .../doc/images/qtquickextras2-tumbler-wrap.gif | Bin 38931 -> 0 bytes src/extras/doc/qtquickextras2.qdocconf | 48 -- src/extras/doc/src/qtquickextras2-customize.qdoc | 82 ---- src/extras/doc/src/qtquickextras2-index.qdoc | 49 -- src/extras/doc/src/qtquickextras2-overview.qdoc | 53 -- src/extras/doc/src/qtquickextras2.qdoc | 44 -- src/extras/extras.pri | 13 - src/extras/extras.pro | 16 - src/extras/qquickdial.cpp | 527 -------------------- src/extras/qquickdial_p.h | 143 ------ src/extras/qquickdrawer.cpp | 388 --------------- src/extras/qquickdrawer_p.h | 115 ----- src/extras/qquickswipeview.cpp | 192 -------- src/extras/qquickswipeview_p.h | 92 ---- src/extras/qquicktumbler.cpp | 535 --------------------- src/extras/qquicktumbler_p.h | 147 ------ src/extras/qtquickextrasglobal_p.h | 67 --- src/imports/extras/doc/images/.directory | 4 + .../doc/images/qtquickextras2-dial-background.png | Bin 0 -> 3286 bytes .../doc/images/qtquickextras2-dial-handle.png | Bin 0 -> 3538 bytes .../images/qtquickextras2-tumbler-background.png | Bin 0 -> 1025 bytes .../images/qtquickextras2-tumbler-contentItem.png | Bin 0 -> 1025 bytes .../doc/images/qtquickextras2-tumbler-delegate.png | Bin 0 -> 1047 bytes .../doc/images/qtquickextras2-tumbler-wrap.gif | Bin 0 -> 38931 bytes src/imports/extras/doc/qtquickextras2.qdocconf | 47 ++ .../extras/doc/src/qtquickextras2-customize.qdoc | 82 ++++ .../extras/doc/src/qtquickextras2-index.qdoc | 49 ++ .../extras/doc/src/qtquickextras2-overview.qdoc | 53 ++ src/imports/extras/doc/src/qtquickextras2.qdoc | 44 ++ src/imports/extras/extras.pri | 17 + src/imports/extras/extras.pro | 18 +- src/imports/extras/qquickdial.cpp | 527 ++++++++++++++++++++ src/imports/extras/qquickdial_p.h | 142 ++++++ src/imports/extras/qquickdrawer.cpp | 388 +++++++++++++++ src/imports/extras/qquickdrawer_p.h | 114 +++++ src/imports/extras/qquickswipeview.cpp | 192 ++++++++ src/imports/extras/qquickswipeview_p.h | 91 ++++ src/imports/extras/qquicktumbler.cpp | 535 +++++++++++++++++++++ src/imports/extras/qquicktumbler_p.h | 146 ++++++ src/imports/extras/qtquickextras2plugin.cpp | 8 +- src/src.pro | 4 +- 47 files changed, 2445 insertions(+), 2531 deletions(-) delete mode 100644 src/extras/doc/images/.directory delete mode 100644 src/extras/doc/images/qtquickextras2-dial-background.png delete mode 100644 src/extras/doc/images/qtquickextras2-dial-handle.png delete mode 100644 src/extras/doc/images/qtquickextras2-tumbler-background.png delete mode 100644 src/extras/doc/images/qtquickextras2-tumbler-contentItem.png delete mode 100644 src/extras/doc/images/qtquickextras2-tumbler-delegate.png delete mode 100644 src/extras/doc/images/qtquickextras2-tumbler-wrap.gif delete mode 100644 src/extras/doc/qtquickextras2.qdocconf delete mode 100644 src/extras/doc/src/qtquickextras2-customize.qdoc delete mode 100644 src/extras/doc/src/qtquickextras2-index.qdoc delete mode 100644 src/extras/doc/src/qtquickextras2-overview.qdoc delete mode 100644 src/extras/doc/src/qtquickextras2.qdoc delete mode 100644 src/extras/extras.pri delete mode 100644 src/extras/extras.pro delete mode 100644 src/extras/qquickdial.cpp delete mode 100644 src/extras/qquickdial_p.h delete mode 100644 src/extras/qquickdrawer.cpp delete mode 100644 src/extras/qquickdrawer_p.h delete mode 100644 src/extras/qquickswipeview.cpp delete mode 100644 src/extras/qquickswipeview_p.h delete mode 100644 src/extras/qquicktumbler.cpp delete mode 100644 src/extras/qquicktumbler_p.h delete mode 100644 src/extras/qtquickextrasglobal_p.h create mode 100644 src/imports/extras/doc/images/.directory create mode 100644 src/imports/extras/doc/images/qtquickextras2-dial-background.png create mode 100644 src/imports/extras/doc/images/qtquickextras2-dial-handle.png create mode 100644 src/imports/extras/doc/images/qtquickextras2-tumbler-background.png create mode 100644 src/imports/extras/doc/images/qtquickextras2-tumbler-contentItem.png create mode 100644 src/imports/extras/doc/images/qtquickextras2-tumbler-delegate.png create mode 100644 src/imports/extras/doc/images/qtquickextras2-tumbler-wrap.gif create mode 100644 src/imports/extras/doc/qtquickextras2.qdocconf create mode 100644 src/imports/extras/doc/src/qtquickextras2-customize.qdoc create mode 100644 src/imports/extras/doc/src/qtquickextras2-index.qdoc create mode 100644 src/imports/extras/doc/src/qtquickextras2-overview.qdoc create mode 100644 src/imports/extras/doc/src/qtquickextras2.qdoc create mode 100644 src/imports/extras/extras.pri create mode 100644 src/imports/extras/qquickdial.cpp create mode 100644 src/imports/extras/qquickdial_p.h create mode 100644 src/imports/extras/qquickdrawer.cpp create mode 100644 src/imports/extras/qquickdrawer_p.h create mode 100644 src/imports/extras/qquickswipeview.cpp create mode 100644 src/imports/extras/qquickswipeview_p.h create mode 100644 src/imports/extras/qquicktumbler.cpp create mode 100644 src/imports/extras/qquicktumbler_p.h (limited to 'src') diff --git a/src/extras/doc/images/.directory b/src/extras/doc/images/.directory deleted file mode 100644 index 7d49c166..00000000 --- a/src/extras/doc/images/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -Timestamp=2015,7,13,18,47,2 -Version=3 -ViewMode=1 diff --git a/src/extras/doc/images/qtquickextras2-dial-background.png b/src/extras/doc/images/qtquickextras2-dial-background.png deleted file mode 100644 index 38fad583..00000000 Binary files a/src/extras/doc/images/qtquickextras2-dial-background.png and /dev/null differ diff --git a/src/extras/doc/images/qtquickextras2-dial-handle.png b/src/extras/doc/images/qtquickextras2-dial-handle.png deleted file mode 100644 index e6fd8cdc..00000000 Binary files a/src/extras/doc/images/qtquickextras2-dial-handle.png and /dev/null differ diff --git a/src/extras/doc/images/qtquickextras2-tumbler-background.png b/src/extras/doc/images/qtquickextras2-tumbler-background.png deleted file mode 100644 index aa736615..00000000 Binary files a/src/extras/doc/images/qtquickextras2-tumbler-background.png and /dev/null differ diff --git a/src/extras/doc/images/qtquickextras2-tumbler-contentItem.png b/src/extras/doc/images/qtquickextras2-tumbler-contentItem.png deleted file mode 100644 index aa736615..00000000 Binary files a/src/extras/doc/images/qtquickextras2-tumbler-contentItem.png and /dev/null differ diff --git a/src/extras/doc/images/qtquickextras2-tumbler-delegate.png b/src/extras/doc/images/qtquickextras2-tumbler-delegate.png deleted file mode 100644 index 77c51efd..00000000 Binary files a/src/extras/doc/images/qtquickextras2-tumbler-delegate.png and /dev/null differ diff --git a/src/extras/doc/images/qtquickextras2-tumbler-wrap.gif b/src/extras/doc/images/qtquickextras2-tumbler-wrap.gif deleted file mode 100644 index 2a7e435d..00000000 Binary files a/src/extras/doc/images/qtquickextras2-tumbler-wrap.gif and /dev/null differ diff --git a/src/extras/doc/qtquickextras2.qdocconf b/src/extras/doc/qtquickextras2.qdocconf deleted file mode 100644 index 2faa6b26..00000000 --- a/src/extras/doc/qtquickextras2.qdocconf +++ /dev/null @@ -1,48 +0,0 @@ -include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) - -project = QtQuickExtras2 -description = Qt Quick Extras 2 Reference Documentation -version = $QT_VERSION - -qhp.projects = QtQuickExtras2 - -qhp.QtQuickExtras2.file = qtquickextras2.qhp -qhp.QtQuickExtras2.namespace = org.qt-project.qtquickextras2.$QT_VERSION_TAG -qhp.QtQuickExtras2.virtualFolder = qtquickextras2 -qhp.QtQuickExtras2.indexTitle = Qt Quick Extras 2 -qhp.QtQuickExtras2.indexRoot = - -qhp.QtQuickExtras2.filterAttributes = qtquickextras2 $QT_VERSION qtrefdoc -qhp.QtQuickExtras2.customFilters.Qt.name = QtQuickExtras2 $QT_VERSION -qhp.QtQuickExtras2.customFilters.Qt.filterAttributes = qtquickextras2 $QT_VERSION - -qhp.QtQuickExtras2.subprojects = qtquickextras2qmltypes - -qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.title = Extras 2 QML Types -qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.indexTitle = Qt Quick Extras 2 QML Types -qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.selectors = qmlclass -qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.sortPages = true - -depends = qtcore qtgui qtdoc qtqml qtquick qtquicklayouts qtquickdialogs qtquickcontrols2 - -# Specify the install path under QT_INSTALL_EXAMPLES -# Examples will be installed under quick/extras - 'extras' subdirectory -# is given as part of \example commands -exampledirs += ../../../examples/quick/extras \ - ../../imports/extras -examplesinstallpath = quick/extras - -headerdirs += ../ -sourcedirs += ../ - -imagedirs += images - -navigation.landingpage = "Qt Quick Extras 2" -navigation.qmltypespage = "Qt Quick Extras 2 QML Types" - -tagfile = qtquickextras2.tags - -# Specify a QML module suffix, applied to html filenames, to avoid -# clashes with Qt Quick Extras 1 documentation. -outputsuffixes = QML -outputsuffixes.QML = 2 diff --git a/src/extras/doc/src/qtquickextras2-customize.qdoc b/src/extras/doc/src/qtquickextras2-customize.qdoc deleted file mode 100644 index fc04fe1f..00000000 --- a/src/extras/doc/src/qtquickextras2-customize.qdoc +++ /dev/null @@ -1,82 +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$ -** -****************************************************************************/ - -/*! - \page qtquickextras2-customize.html - \title Customizing Qt Quick Extras 2 - \brief A set of UI controls to create user interfaces in Qt Quick - - Qt Quick Controls consist of a hierarchy (tree) of items. In order to - provide a custom look and feel, the default implementation of each item - can be replaced with a custom one. The following snippets present the - default implementations of various items. These can be used as a starting - point to implement a custom look and feel. - - \sa {Customizing Qt Quick Controls 2} - - \section1 Customizing Dial - - Dial consists of two visual items: \l {Control::background}{background} - and \l {Dial::handle}{handle}. - - \section3 Background - - \image qtquickextras2-dial-background.png - - \snippet Dial.qml background - - \section3 Indicator - - \image qtquickextras2-dial-handle.png - - \snippet Dial.qml handle - - \section1 Customizing Tumbler - - Tumbler consists of three visual items: - \l {Control::background}{background}, - \l {Control::contentItem}{contentItem}, and - \l {Tumbler::delegate}{delegate}. - - \section3 Background - - \image qtquickextras2-tumbler-background.png - - Tumbler has no background item by default. - - \section3 Content Item - - \image qtquickextras2-tumbler-contentItem.png - - \snippet Tumbler.qml contentItem - - \section3 Delegate - - \image qtquickextras2-tumbler-delegate.png - - \snippet Tumbler.qml delegate -*/ diff --git a/src/extras/doc/src/qtquickextras2-index.qdoc b/src/extras/doc/src/qtquickextras2-index.qdoc deleted file mode 100644 index 53712e22..00000000 --- a/src/extras/doc/src/qtquickextras2-index.qdoc +++ /dev/null @@ -1,49 +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$ -** -****************************************************************************/ - -/*! - \page qtquickextras2-index.html - \title Qt Quick Extras 2 - - \brief The Qt Quick Extras 2 module provides a set of specialized UI - controls for Qt Quick. - - The Qt Quick Extras 2 module provides a set of controls that can be used to - build interfaces in Qt Quick. - - The module is new in Qt 5.6. - - Visit the \l{Qt Quick Extras 2 Overview} page to get started. - - \section1 Related Information - - \list - \li \l{Qt Quick} - \li \l{Qt Quick Extras 2 Overview} - \li \l{Qt Quick Extras 2 QML Types}{Qt Quick Extras 2 QML Types} - \endlist -*/ diff --git a/src/extras/doc/src/qtquickextras2-overview.qdoc b/src/extras/doc/src/qtquickextras2-overview.qdoc deleted file mode 100644 index 9776e1de..00000000 --- a/src/extras/doc/src/qtquickextras2-overview.qdoc +++ /dev/null @@ -1,53 +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$ -** -****************************************************************************/ - -/*! - \page qtquickextras2-overview.html - \title Qt Quick Extras 2 Overview - \brief A set of UI controls to create user interfaces in Qt Quick - - The Qt Quick Extras 2 module provides a set of UI controls to create user - interfaces in Qt Quick. - - \section1 Getting Started - - TODO - - \section1 Customization - - Qt Quick Controls consist of a hierarchy (tree) of items. In order to - provide a custom look and feel, the default implementation of each can be - replaced with a custom item. For examples of how do this, see - \l {Customizing Qt Quick Extras 2}. - - \section1 Related Information - - \list - \li \l{Qt Quick} - \li \l{Qt Quick Controls 2} - \endlist -*/ diff --git a/src/extras/doc/src/qtquickextras2.qdoc b/src/extras/doc/src/qtquickextras2.qdoc deleted file mode 100644 index 74dbd778..00000000 --- a/src/extras/doc/src/qtquickextras2.qdoc +++ /dev/null @@ -1,44 +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$ -** -****************************************************************************/ - -/*! - \qmlmodule QtQuick.Extras 2.0 - \title Qt Quick Extras 2 QML Types - \ingroup qmlmodules - \brief Provides QML types for user interfaces. - - The \l{Qt Quick Extras 2} module provides QML types for creating user - interfaces. These QML types work in conjunction with \l{Qt Quick}, - \l{Qt Quick Layouts} and \l{Qt Quick Controls 2}. - - The QML types can be imported into your application using the - following import statement in your .qml file. - - \badcode - import QtQuick.Extras 2.0 - \endcode -*/ diff --git a/src/extras/extras.pri b/src/extras/extras.pri deleted file mode 100644 index 684fd6e5..00000000 --- a/src/extras/extras.pri +++ /dev/null @@ -1,13 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/qquickdial_p.h \ - $$PWD/qquickdrawer_p.h \ - $$PWD/qquickswipeview_p.h \ - $$PWD/qquicktumbler_p.h - -SOURCES += \ - $$PWD/qquickdial.cpp \ - $$PWD/qquickdrawer.cpp \ - $$PWD/qquickswipeview.cpp \ - $$PWD/qquicktumbler.cpp diff --git a/src/extras/extras.pro b/src/extras/extras.pro deleted file mode 100644 index 49a82277..00000000 --- a/src/extras/extras.pro +++ /dev/null @@ -1,16 +0,0 @@ -TARGET = QtQuickExtras -MODULE = quickextras2 -CONFIG += internal_module - -QT += quick -QT += core-private gui-private qml-private quick-private quickcontrols2-private - -DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII - -QMAKE_DOCS = $$PWD/doc/qtquickextras2.qdocconf - -HEADERS += \ - $$PWD/qtquickextrasglobal_p.h - -include(extras.pri) -load(qt_module) diff --git a/src/extras/qquickdial.cpp b/src/extras/qquickdial.cpp deleted file mode 100644 index fe196659..00000000 --- a/src/extras/qquickdial.cpp +++ /dev/null @@ -1,527 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 "qquickdial_p.h" - -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmltype Dial - \inherits Control - \instantiates QQuickDial - \inqmlmodule QtQuick.Extras - \ingroup sliders - \brief A circular dial that is rotated to set a value. - - The Dial is similar to a traditional dial knob that is found on devices - such as stereos or industrial equipment. It allows the user to specify a - value within a range. - - The value of the dial is set with the \l value property. The range is - set with the \l from and \l to properties. - - The dial can be manipulated with a keyboard. It supports the following - actions: - - \table - \header \li \b {Action} \li \b {Key} - \row \li Decrease \l value by \l stepSize \li \c Qt.Key_Left - \row \li Decrease \l value by \l stepSize \li \c Qt.Key_Down - \row \li Set \l value to \l from \li \c Qt.Key_Home - \row \li Increase \l value by \l stepSize \li \c Qt.Key_Right - \row \li Increase \l value by \l stepSize \li \c Qt.Key_Up - \row \li Set \l value to \l to \li \c Qt.Key_End - \endtable - - \sa {Customizing Dial} -*/ - -static const qreal startAngle = -140; -static const qreal endAngle = 140; - -class QQuickDialPrivate : public QQuickControlPrivate -{ - Q_DECLARE_PUBLIC(QQuickDial) - -public: - QQuickDialPrivate() : - from(0), - to(1), - value(0), - position(0), - angle(startAngle), - stepSize(0), - pressed(false), - snapMode(QQuickDial::NoSnap), - handle(Q_NULLPTR) - { - } - - qreal valueAt(qreal position) const; - qreal snapPosition(qreal position) const; - qreal positionAt(const QPoint &point) const; - void setPosition(qreal position); - void updatePosition(); - - qreal from; - qreal to; - qreal value; - qreal position; - qreal angle; - qreal stepSize; - bool pressed; - QPoint pressPoint; - QQuickDial::SnapMode snapMode; - QQuickItem *handle; -}; - -qreal QQuickDialPrivate::valueAt(qreal position) const -{ - return from + (to - from) * position; -} - -qreal QQuickDialPrivate::snapPosition(qreal position) const -{ - if (qFuzzyIsNull(stepSize)) - return position; - return qRound(position / stepSize) * stepSize; -} - -qreal QQuickDialPrivate::positionAt(const QPoint &point) const -{ - qreal yy = height / 2.0 - point.y(); - qreal xx = point.x() - width / 2.0; - qreal angle = (xx || yy) ? atan2(yy, xx) : 0; - - if (angle < M_PI / -2) - angle = angle + M_PI * 2; - - qreal normalizedAngle = (M_PI * 4 / 3 - angle) / (M_PI * 10 / 6); - return normalizedAngle; -} - -void QQuickDialPrivate::setPosition(qreal pos) -{ - Q_Q(QQuickDial); - pos = qBound(0.0, pos, 1.0); - if (!qFuzzyCompare(position, pos)) { - position = pos; - - angle = startAngle + position * qAbs(endAngle - startAngle); - - emit q->positionChanged(); - emit q->angleChanged(); - } -} - -void QQuickDialPrivate::updatePosition() -{ - qreal pos = 0; - if (!qFuzzyCompare(from, to)) - pos = (value - from) / (to - from); - setPosition(pos); -} - -QQuickDial::QQuickDial(QQuickItem *parent) : - QQuickControl(*(new QQuickDialPrivate), parent) -{ - setActiveFocusOnTab(true); - setAcceptedMouseButtons(Qt::LeftButton); -} - -/*! - \qmlproperty real QtQuickExtras2::Dial::from - - This property holds the starting value for the range. The default value is \c 0.0. - - \sa to, value -*/ -qreal QQuickDial::from() const -{ - Q_D(const QQuickDial); - return d->from; -} - -void QQuickDial::setFrom(qreal from) -{ - Q_D(QQuickDial); - if (!qFuzzyCompare(d->from, from)) { - d->from = from; - emit fromChanged(); - if (isComponentComplete()) { - setValue(d->value); - d->updatePosition(); - } - } -} - -/*! - \qmlproperty real QtQuickExtras2::Dial::to - - This property holds the end value for the range. The default value is - \c 1.0. - - \sa from, value -*/ -qreal QQuickDial::to() const -{ - Q_D(const QQuickDial); - return d->to; -} - -void QQuickDial::setTo(qreal to) -{ - Q_D(QQuickDial); - if (!qFuzzyCompare(d->to, to)) { - d->to = to; - emit toChanged(); - if (isComponentComplete()) { - setValue(d->value); - d->updatePosition(); - } - } -} - -/*! - \qmlproperty real QtQuickExtras2::Dial::value - - This property holds the value in the range \c from - \c to. The default - value is \c 0.0. - - Unlike the \l position property, the \c value is not updated while the - handle is dragged. The value is updated after the value has been chosen - and the dial has been released. - - \sa position -*/ -qreal QQuickDial::value() const -{ - Q_D(const QQuickDial); - return d->value; -} - -void QQuickDial::setValue(qreal value) -{ - Q_D(QQuickDial); - if (isComponentComplete()) - value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to); - - if (!qFuzzyCompare(d->value, value)) { - d->value = value; - d->updatePosition(); - emit valueChanged(); - } -} - -/*! - \qmlproperty real QtQuickExtras2::Dial::position - - This property holds the logical position of the handle. - - The position is defined as a percentage of the control's angle range (the - range within which the handle can be moved) scaled to \c {0.0 - 1.0}. - Unlike the \l value property, the \c position is continuously updated while - the handle is dragged. - - \sa value, angle -*/ -qreal QQuickDial::position() const -{ - Q_D(const QQuickDial); - return d->position; -} - -/*! - \qmlproperty real QtQuickExtras2::Dial::angle \readonly - - This property holds the angle of the handle. - - Like the \l position property, angle is continuously updated while the - handle is dragged. - - \sa position -*/ -qreal QQuickDial::angle() const -{ - Q_D(const QQuickDial); - return d->angle; -} - -/*! - \qmlproperty real QtQuickExtras2::Dial::stepSize - - This property holds the step size. The default value is \c 0.0. - - \sa snapMode, increase(), decrease() -*/ -qreal QQuickDial::stepSize() const -{ - Q_D(const QQuickDial); - return d->stepSize; -} - -void QQuickDial::setStepSize(qreal step) -{ - Q_D(QQuickDial); - if (!qFuzzyCompare(d->stepSize, step)) { - d->stepSize = step; - emit stepSizeChanged(); - } -} - -/*! - \qmlproperty enumeration QtQuickExtras2::Dial::snapMode - - This property holds the snap mode. - - The snap mode works with the \l stepSize to allow the handle to snap to - certain points along the dial. - - Possible values: - \list - \li \c Dial.NoSnap (default) - The dial does not snap. - \li \c Dial.SnapAlways - The dial snaps while the handle is dragged. - \li \c Dial.SnapOnRelease - The dial does not snap while being dragged, but only after the handle is released. - \endlist - - \sa stepSize -*/ -QQuickDial::SnapMode QQuickDial::snapMode() const -{ - Q_D(const QQuickDial); - return d->snapMode; -} - -void QQuickDial::setSnapMode(SnapMode mode) -{ - Q_D(QQuickDial); - if (d->snapMode != mode) { - d->snapMode = mode; - emit snapModeChanged(); - } -} - -/*! - \qmlproperty bool QtQuickExtras2::Dial::pressed - - This property holds whether the dial is pressed. - - The dial will be pressed when either the mouse is pressed over it, or a key - such as \c Qt.Key_Left is held down. If you'd prefer not to have the dial - be pressed upon key presses (due to styling reasons, for example), you can - use the \l {Keys}{Keys attached property}: - - \code - Dial { - Keys.onLeftPressed: {} - } - \endcode - - This will result in pressed only being \c true upon mouse presses. -*/ -bool QQuickDial::isPressed() const -{ - Q_D(const QQuickDial); - return d->pressed; -} - -void QQuickDial::setPressed(bool pressed) -{ - Q_D(QQuickDial); - if (d->pressed != pressed) { - d->pressed = pressed; - emit pressedChanged(); - } -} - -/*! - \qmlmethod void QtQuickExtras2::Dial::increase() - - Increases the value by \l stepSize, or \c 0.1 if stepSize is not defined. - - \sa stepSize -*/ -void QQuickDial::increase() -{ - Q_D(QQuickDial); - qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; - setValue(d->value + step); -} - -/*! - \qmlmethod void QtQuickExtras2::Dial::decrease() - - Decreases the value by \l stepSize, or \c 0.1 if stepSize is not defined. - - \sa stepSize -*/ -void QQuickDial::decrease() -{ - Q_D(QQuickDial); - qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; - setValue(d->value - step); -} - -/*! - \qmlproperty component QtQuickExtras2::Dial::handle - - This property holds the handle of the dial. - - The handle acts as a visual indicator of the position of the dial. - - \sa {Customizing Dial} -*/ -QQuickItem *QQuickDial::handle() const -{ - Q_D(const QQuickDial); - return d->handle; -} - -void QQuickDial::setHandle(QQuickItem *handle) -{ - Q_D(QQuickDial); - if (handle != d->handle) { - d->handle = handle; - if (d->handle && !d->handle->parentItem()) - d->handle->setParentItem(this); - emit handleChanged(); - } -} - -void QQuickDial::keyPressEvent(QKeyEvent *event) -{ - Q_D(QQuickDial); - if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Down) { - setPressed(true); - if (isMirrored()) - increase(); - else - decrease(); - } else if (event->key() == Qt::Key_Right || event->key() == Qt::Key_Up) { - setPressed(true); - if (isMirrored()) - decrease(); - else - increase(); - } else if (event->key() == Qt::Key_Home) { - setPressed(true); - setValue(isMirrored() ? d->to : d->from); - } else if (event->key() == Qt::Key_End) { - setPressed(true); - setValue(isMirrored() ? d->from : d->to); - } else { - event->ignore(); - QQuickControl::keyPressEvent(event); - } -} - -void QQuickDial::keyReleaseEvent(QKeyEvent *event) -{ - QQuickControl::keyReleaseEvent(event); - setPressed(false); -} - -void QQuickDial::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickDial); - QQuickControl::mousePressEvent(event); - d->pressPoint = event->pos(); - setPressed(true); -} - -void QQuickDial::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickDial); - QQuickControl::mouseMoveEvent(event); - if (!keepMouseGrab()) { - bool overXDragThreshold = QQuickWindowPrivate::dragOverThreshold(event->pos().x() - d->pressPoint.x(), Qt::XAxis, event); - setKeepMouseGrab(overXDragThreshold); - - if (!overXDragThreshold) { - bool overYDragThreshold = QQuickWindowPrivate::dragOverThreshold(event->pos().y() - d->pressPoint.y(), Qt::YAxis, event); - setKeepMouseGrab(overYDragThreshold); - } - } - if (keepMouseGrab()) { - qreal pos = d->positionAt(event->pos()); - if (d->snapMode == SnapAlways) - pos = d->snapPosition(pos); - d->setPosition(pos); - } -} - -void QQuickDial::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickDial); - QQuickControl::mouseReleaseEvent(event); - d->pressPoint = QPoint(); - if (keepMouseGrab()) { - qreal pos = d->positionAt(event->pos()); - if (d->snapMode != NoSnap) - pos = d->snapPosition(pos); - setValue(d->valueAt(pos)); - setKeepMouseGrab(false); - } - setPressed(false); -} - -void QQuickDial::mouseUngrabEvent() -{ - Q_D(QQuickDial); - QQuickControl::mouseUngrabEvent(); - d->pressPoint = QPoint(); - setPressed(false); -} - -void QQuickDial::mirrorChange() -{ - QQuickControl::mirrorChange(); - emit angleChanged(); -} - -void QQuickDial::componentComplete() -{ - Q_D(QQuickDial); - QQuickControl::componentComplete(); - setValue(d->value); - d->updatePosition(); -} - -QT_END_NAMESPACE diff --git a/src/extras/qquickdial_p.h b/src/extras/qquickdial_p.h deleted file mode 100644 index 3d14ea4e..00000000 --- a/src/extras/qquickdial_p.h +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 QQUICKDIAL_H -#define QQUICKDIAL_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 -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickDialAttached; -class QQuickDialPrivate; - -class Q_QUICKEXTRAS_EXPORT QQuickDial : public QQuickControl -{ - Q_OBJECT - Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged FINAL) - Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged FINAL) - Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) - Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL) - Q_PROPERTY(qreal angle READ angle NOTIFY angleChanged FINAL) - Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) - Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) - Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL) - Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) - -public: - explicit QQuickDial(QQuickItem *parent = Q_NULLPTR); - - qreal from() const; - void setFrom(qreal from); - - qreal to() const; - void setTo(qreal to); - - qreal value() const; - void setValue(qreal value); - - qreal position() const; - - qreal angle() const; - - qreal stepSize() const; - void setStepSize(qreal step); - - enum SnapMode { - NoSnap, - SnapAlways, - SnapOnRelease - }; - Q_ENUM(SnapMode) - - SnapMode snapMode() const; - void setSnapMode(SnapMode mode); - - bool isPressed() const; - void setPressed(bool pressed); - - QQuickItem *handle() const; - void setHandle(QQuickItem *handle); - -public Q_SLOTS: - void increase(); - void decrease(); - -Q_SIGNALS: - void fromChanged(); - void toChanged(); - void valueChanged(); - void positionChanged(); - void angleChanged(); - void stepSizeChanged(); - void snapModeChanged(); - void pressedChanged(); - void handleChanged(); - -protected: - void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; - void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseUngrabEvent() Q_DECL_OVERRIDE; - void mirrorChange() Q_DECL_OVERRIDE; - void componentComplete() Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QQuickDial) - Q_DECLARE_PRIVATE(QQuickDial) -}; - -Q_DECLARE_TYPEINFO(QQuickDial, Q_COMPLEX_TYPE); - -QT_END_NAMESPACE - -#endif // QQUICKDIAL_H diff --git a/src/extras/qquickdrawer.cpp b/src/extras/qquickdrawer.cpp deleted file mode 100644 index 7c61688a..00000000 --- a/src/extras/qquickdrawer.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 "qquickdrawer_p.h" - -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickDrawerPrivate : public QQuickControlPrivate -{ - Q_DECLARE_PUBLIC(QQuickDrawer) - -public: - QQuickDrawerPrivate() : edge(Qt::LeftEdge), offset(0), position(0), - content(Q_NULLPTR), animation(Q_NULLPTR) { } - - void updateContent(); - bool handleMousePressEvent(QQuickItem *item, QMouseEvent *event); - bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event); - bool handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event); - - Qt::Edge edge; - qreal offset; - qreal position; - QPointF pressPoint; - QQuickItem *content; - QQuickPropertyAnimation *animation; -}; - -void QQuickDrawerPrivate::updateContent() -{ - Q_Q(QQuickDrawer); - if (!content) - return; - - switch (edge) { - case Qt::LeftEdge: - content->setX((position - 1.0) * content->width()); - break; - case Qt::RightEdge: - content->setX(q->width() + - position * content->width()); - break; - case Qt::TopEdge: - content->setY((position - 1.0) * content->height()); - break; - case Qt::BottomEdge: - content->setY(q->height() + - position * content->height()); - break; - } -} - -bool QQuickDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *event) -{ - Q_Q(QQuickDrawer); - pressPoint = q->mapFromItem(item, event->pos()); - - if (qFuzzyIsNull(position)) { - // only accept pressing at drag margins when fully closed - switch (edge) { - case Qt::LeftEdge: - event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(event->x(), Qt::XAxis, event)); - break; - case Qt::RightEdge: - event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(q->width() - event->x(), Qt::XAxis, event)); - break; - case Qt::TopEdge: - event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(event->y(), Qt::YAxis, event)); - break; - case Qt::BottomEdge: - event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(q->height() - event->y(), Qt::YAxis, event)); - break; - } - offset = 0; - } else { - event->accept(); - offset = q->positionAt(pressPoint) - position; - } - - return item == q; -} - -bool QQuickDrawerPrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event) -{ - Q_Q(QQuickDrawer); - QPointF movePoint = q->mapFromItem(item, event->pos()); - - if (!q->keepMouseGrab()) { - bool overThreshold = false; - if (edge == Qt::LeftEdge || edge == Qt::RightEdge) - overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event); - else - overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event); - - if (window && overThreshold) { - QQuickItem *grabber = q->window()->mouseGrabberItem(); - if (!grabber || !grabber->keepMouseGrab()) { - q->grabMouse(); - q->setKeepMouseGrab(overThreshold); - } - } - } - - if (q->keepMouseGrab()) - q->setPosition(q->positionAt(event->pos()) - offset); - event->accept(); - - return q->keepMouseGrab(); -} - -bool QQuickDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event) -{ - Q_Q(QQuickDrawer); - bool wasGrabbed = q->keepMouseGrab(); - if (wasGrabbed) { -// int startDragVelocity = QGuiApplication::styleHints()->startDragVelocity(); -// if (startDragVelocity && QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity) { -// QVector2D velocity = QGuiApplicationPrivate::mouseEventVelocity(event); -// qreal vel = (edge == Qt::LeftEdge || edge == Qt::RightEdge) ? velocity.x() : velocity.y(); -// qDebug() << vel << "vs." << startDragVelocity; -// } - if (position < 0.3) { - q->close(); - } else if (position > 0.7) { - q->open(); - } else { - switch (edge) { - case Qt::LeftEdge: - if (event->x() - pressPoint.x() > 0) - q->open(); - else - q->close(); - break; - case Qt::RightEdge: - if (event->x() - pressPoint.x() < 0) - q->open(); - else - q->close(); - break; - case Qt::TopEdge: - if (event->y() - pressPoint.y() > 0) - q->open(); - else - q->close(); - break; - case Qt::BottomEdge: - if (event->y() - pressPoint.y() < 0) - q->open(); - else - q->close(); - break; - } - } - q->setKeepMouseGrab(false); - } else { - if (item == q) - emit q->clicked(); - } - pressPoint = QPoint(); - event->accept(); - return wasGrabbed; -} - -QQuickDrawer::QQuickDrawer(QQuickItem *parent) : - QQuickControl(*(new QQuickDrawerPrivate), parent) -{ - setZ(1); - setFiltersChildMouseEvents(true); - setAcceptedMouseButtons(Qt::LeftButton); -} - -Qt::Edge QQuickDrawer::edge() const -{ - Q_D(const QQuickDrawer); - return d->edge; -} - -void QQuickDrawer::setEdge(Qt::Edge edge) -{ - Q_D(QQuickDrawer); - if (d->edge != edge) { - d->edge = edge; - if (isComponentComplete()) - d->updateContent(); - emit edgeChanged(); - } -} - -qreal QQuickDrawer::position() const -{ - Q_D(const QQuickDrawer); - return d->position; -} - -void QQuickDrawer::setPosition(qreal position) -{ - Q_D(QQuickDrawer); - position = qBound(0.0, position, 1.0); - if (!qFuzzyCompare(d->position, position)) { - d->position = position; - if (isComponentComplete()) - d->updateContent(); - emit positionChanged(); - } -} - -QQuickItem *QQuickDrawer::contentItem() const -{ - Q_D(const QQuickDrawer); - return d->content; -} - -void QQuickDrawer::setContentItem(QQuickItem *item) -{ - Q_D(QQuickDrawer); - if (d->content != item) { - delete d->content; - d->content = item; - if (item) - item->setParentItem(this); - if (isComponentComplete()) - d->updateContent(); - emit contentItemChanged(); - } -} - -QQuickPropertyAnimation *QQuickDrawer::animation() const -{ - Q_D(const QQuickDrawer); - return d->animation; -} - -void QQuickDrawer::setAnimation(QQuickPropertyAnimation *animation) -{ - Q_D(QQuickDrawer); - if (d->animation != animation) { - delete d->animation; - d->animation = animation; - if (animation) { - animation->setTargetObject(this); - animation->setProperty(QStringLiteral("position")); - } - emit animationChanged(); - } -} - -void QQuickDrawer::open() -{ - Q_D(QQuickDrawer); - if (d->animation) { - d->animation->stop(); - d->animation->setFrom(d->position); - d->animation->setTo(1.0); - d->animation->start(); - } else { - setPosition(1.0); - } -} - -void QQuickDrawer::close() -{ - Q_D(QQuickDrawer); - if (d->animation) { - d->animation->stop(); - d->animation->setFrom(d->position); - d->animation->setTo(0.0); - d->animation->start(); - } else { - setPosition(0.0); - } -} - -bool QQuickDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event) -{ - Q_D(QQuickDrawer); - switch (event->type()) { - case QEvent::MouseButtonPress: - return d->handleMousePressEvent(child, static_cast(event)); - case QEvent::MouseMove: - return d->handleMouseMoveEvent(child, static_cast(event)); - case QEvent::MouseButtonRelease: - return d->handleMouseReleaseEvent(child, static_cast(event)); - default: - return false; - } -} - -void QQuickDrawer::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickDrawer); - QQuickControl::mousePressEvent(event); - d->handleMousePressEvent(this, event); -} - -void QQuickDrawer::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickDrawer); - QQuickControl::mouseMoveEvent(event); - d->handleMouseMoveEvent(this, event); -} - -void QQuickDrawer::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickDrawer); - QQuickControl::mouseReleaseEvent(event); - d->handleMouseReleaseEvent(this, event); -} - -void QQuickDrawer::mouseUngrabEvent() -{ - Q_D(QQuickDrawer); - QQuickControl::mouseUngrabEvent(); - d->pressPoint = QPoint(); -} - -void QQuickDrawer::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickDrawer); - QQuickControl::geometryChanged(newGeometry, oldGeometry); - if (isComponentComplete()) - d->updateContent(); -} - -void QQuickDrawer::componentComplete() -{ - Q_D(QQuickDrawer); - QQuickControl::componentComplete(); - d->updateContent(); -} - -qreal QQuickDrawer::positionAt(const QPointF &point) const -{ - Q_D(const QQuickDrawer); - if (!d->content) - return 0.0; - - switch (d->edge) { - case Qt::TopEdge: - return point.y() / d->content->height(); - case Qt::LeftEdge: - return point.x() / d->content->width(); - case Qt::RightEdge: - return (width() - point.x()) / d->content->width(); - case Qt::BottomEdge: - return (height() - point.y()) / d->content->height(); - default: - return 0; - } -} - -QT_END_NAMESPACE diff --git a/src/extras/qquickdrawer_p.h b/src/extras/qquickdrawer_p.h deleted file mode 100644 index 59b76a10..00000000 --- a/src/extras/qquickdrawer_p.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 QQUICKDRAWER_P_H -#define QQUICKDRAWER_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 -#include - -QT_BEGIN_NAMESPACE - -class QQuickPropertyAnimation; -class QQuickDrawerPrivate; - -class Q_QUICKEXTRAS_EXPORT QQuickDrawer : public QQuickControl -{ - Q_OBJECT - Q_PROPERTY(Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged FINAL) - Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) - Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) - // TODO: make this a proper transition - Q_PROPERTY(QQuickPropertyAnimation *animation READ animation WRITE setAnimation NOTIFY animationChanged FINAL) - Q_CLASSINFO("DefaultProperty", "contentItem") - -public: - explicit QQuickDrawer(QQuickItem *parent = Q_NULLPTR); - - Qt::Edge edge() const; - void setEdge(Qt::Edge edge); - - qreal position() const; - void setPosition(qreal position); - - QQuickItem *contentItem() const; - void setContentItem(QQuickItem *item); - - QQuickPropertyAnimation *animation() const; - void setAnimation(QQuickPropertyAnimation *animation); - -public Q_SLOTS: - void open(); - void close(); - -Q_SIGNALS: - void clicked(); - void edgeChanged(); - void positionChanged(); - void contentItemChanged(); - void animationChanged(); - -protected: - bool childMouseEventFilter(QQuickItem *child, QEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseUngrabEvent() Q_DECL_OVERRIDE; - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; - void componentComplete() Q_DECL_OVERRIDE; - - virtual qreal positionAt(const QPointF &point) const; - -private: - Q_DISABLE_COPY(QQuickDrawer) - Q_DECLARE_PRIVATE(QQuickDrawer) -}; - -Q_DECLARE_TYPEINFO(QQuickDrawer, Q_COMPLEX_TYPE); - -QT_END_NAMESPACE - -#endif // QQUICKDRAWER_P_H diff --git a/src/extras/qquickswipeview.cpp b/src/extras/qquickswipeview.cpp deleted file mode 100644 index c359a983..00000000 --- a/src/extras/qquickswipeview.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 "qquickswipeview_p.h" - -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmltype SwipeView - \inherits Container - \instantiates QQuickSwipeView - \inqmlmodule QtQuick.Extras - \ingroup navigation - \brief A swipe view control. - - TODO -*/ - -class QQuickSwipeViewPrivate : public QQuickContainerPrivate -{ - Q_DECLARE_PUBLIC(QQuickSwipeView) - -public: - QQuickSwipeViewPrivate() : currentIndex(-1), updatingCurrent(false) { } - - void resizeItem(QQuickItem *item); - void resizeItems(); - void _q_updateCurrent(); - - void insertItem(int index, QQuickItem *item) Q_DECL_OVERRIDE; - void moveItem(int from, int to) Q_DECL_OVERRIDE; - void removeItem(int index, QQuickItem *item) Q_DECL_OVERRIDE; - - int currentIndex; - bool updatingCurrent; -}; - -void QQuickSwipeViewPrivate::resizeItems() -{ - Q_Q(QQuickSwipeView); - const int count = q->count(); - for (int i = 0; i < count; ++i) { - QQuickItem *item = itemAt(i); - if (item) - item->setSize(QSizeF(contentItem->width(), contentItem->height())); - } -} - -void QQuickSwipeViewPrivate::_q_updateCurrent() -{ - Q_Q(QQuickSwipeView); - if (!updatingCurrent) - q->setCurrentIndex(contentItem ? contentItem->property("currentIndex").toInt() : -1); -} - -void QQuickSwipeViewPrivate::insertItem(int index, QQuickItem *item) -{ - Q_Q(QQuickSwipeView); - if (q->isComponentComplete()) - item->setSize(QSizeF(contentItem->width(), contentItem->height())); - - QQuickContainerPrivate::insertItem(index, item); - - if (contentModel->count() == 1 && currentIndex == -1) - q->setCurrentIndex(index); -} - -void QQuickSwipeViewPrivate::moveItem(int from, int to) -{ - Q_Q(QQuickSwipeView); - QQuickContainerPrivate::moveItem(from, to); - - updatingCurrent = true; - if (from == currentIndex) - q->setCurrentIndex(to); - else if (from < currentIndex && to >= currentIndex) - q->setCurrentIndex(currentIndex - 1); - else if (from > currentIndex && to <= currentIndex) - q->setCurrentIndex(currentIndex + 1); - updatingCurrent = false; -} - -void QQuickSwipeViewPrivate::removeItem(int index, QQuickItem *item) -{ - Q_Q(QQuickSwipeView); - bool currentChanged = false; - if (index == currentIndex) { - q->setCurrentIndex(currentIndex - 1); - } else if (index < currentIndex) { - --currentIndex; - currentChanged = true; - } - - QQuickContainerPrivate::removeItem(index, item); - - if (currentChanged) - emit q->currentIndexChanged(); -} - -QQuickSwipeView::QQuickSwipeView(QQuickItem *parent) : - QQuickContainer(*(new QQuickSwipeViewPrivate), parent) -{ - setFlag(ItemIsFocusScope); - setActiveFocusOnTab(true); -} - -/*! - \qmlproperty int QtQuickControls2::SwipeView::currentIndex - - TODO -*/ -int QQuickSwipeView::currentIndex() const -{ - Q_D(const QQuickSwipeView); - return d->currentIndex; -} - -void QQuickSwipeView::setCurrentIndex(int index) -{ - Q_D(QQuickSwipeView); - if (d->currentIndex != index) { - d->currentIndex = index; - emit currentIndexChanged(); - emit currentItemChanged(); - } -} - -/*! - \qmlproperty Item QtQuickControls2::SwipeView::currentItem - - TODO -*/ -QQuickItem *QQuickSwipeView::currentItem() const -{ - Q_D(const QQuickSwipeView); - return itemAt(d->currentIndex); -} - -void QQuickSwipeView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickSwipeView); - QQuickContainer::geometryChanged(newGeometry, oldGeometry); - d->resizeItems(); -} - -void QQuickSwipeView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) -{ - QQuickContainer::contentItemChange(newItem, oldItem); - if (oldItem) - disconnect(oldItem, SIGNAL(currentIndexChanged()), this, SLOT(_q_updateCurrent())); - if (newItem) - connect(newItem, SIGNAL(currentIndexChanged()), this, SLOT(_q_updateCurrent())); -} - -QT_END_NAMESPACE - -#include "moc_qquickswipeview_p.cpp" diff --git a/src/extras/qquickswipeview_p.h b/src/extras/qquickswipeview_p.h deleted file mode 100644 index c314204e..00000000 --- a/src/extras/qquickswipeview_p.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 QQUICKSWIPEVIEW_P_H -#define QQUICKSWIPEVIEW_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 -#include - -QT_BEGIN_NAMESPACE - -class QQuickSwipeViewPrivate; - -class Q_QUICKEXTRAS_EXPORT QQuickSwipeView : public QQuickContainer -{ - Q_OBJECT - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) - Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) - -public: - explicit QQuickSwipeView(QQuickItem *parent = Q_NULLPTR); - - int currentIndex() const; - QQuickItem *currentItem() const; - -public Q_SLOTS: - void setCurrentIndex(int index); - -Q_SIGNALS: - void currentIndexChanged(); - void currentItemChanged(); - -protected: - void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE; - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QQuickSwipeView) - Q_DECLARE_PRIVATE(QQuickSwipeView) - - Q_PRIVATE_SLOT(d_func(), void _q_updateCurrent()) -}; - -Q_DECLARE_TYPEINFO(QQuickSwipeView, Q_COMPLEX_TYPE); - -QT_END_NAMESPACE - -#endif // QQUICKSWIPEVIEW_P_H diff --git a/src/extras/qquicktumbler.cpp b/src/extras/qquicktumbler.cpp deleted file mode 100644 index 53a8af8f..00000000 --- a/src/extras/qquicktumbler.cpp +++ /dev/null @@ -1,535 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 "qquicktumbler_p.h" - -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmltype Tumbler - \inherits Control - \instantiates QQuickTumbler - \inqmlmodule QtQuick.Extras - \ingroup containers - \brief A spinnable wheel of items that can be selected. - - \code - Tumbler { - model: 5 - } - \endcode - - \section1 Non-wrapping Tumbler - - The default contentItem of Tumbler is a \l PathView, which wraps when it - reaches the top and bottom. To achieve a non-wrapping Tumbler, use ListView - as the contentItem: - - \snippet tst_tumbler.qml contentItem - - \image qtquickextras2-tumbler-wrap.gif -*/ - -class QQuickTumblerPrivate : public QQuickControlPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickTumbler) - -public: - QQuickTumblerPrivate() : - delegate(Q_NULLPTR), - visibleItemCount(3) - { - } - - ~QQuickTumblerPrivate() - { - } - - QVariant model; - QQmlComponent *delegate; - int visibleItemCount; - - void _q_updateItemHeights(); - void _q_updateItemWidths(); - - void itemChildAdded(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; - void itemChildRemoved(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; -}; - -static QList contentItemChildItems(QQuickItem *contentItem) -{ - if (!contentItem) - return QList(); - - // PathView has no contentItem property, but ListView does. - QQuickFlickable *flickable = qobject_cast(contentItem); - return flickable ? flickable->contentItem()->childItems() : contentItem->childItems(); -} - -namespace { - static inline qreal delegateHeight(const QQuickTumbler *tumbler) - { - return tumbler->availableHeight() / tumbler->visibleItemCount(); - } - - enum ContentItemType { - UnsupportedContentItemType, - PathViewContentItem, - ListViewContentItem - }; - - static inline QQuickItem *actualContentItem(QQuickItem *rootContentItem, ContentItemType contentType) - { - if (contentType == PathViewContentItem) - return rootContentItem; - else if (contentType == ListViewContentItem) - return qobject_cast(rootContentItem)->contentItem(); - - return Q_NULLPTR; - } - - static inline ContentItemType contentItemType(QQuickItem *rootContentItem) - { - if (rootContentItem->inherits("QQuickPathView")) - return PathViewContentItem; - else if (rootContentItem->inherits("QQuickListView")) - return ListViewContentItem; - - return UnsupportedContentItemType; - } - - static inline ContentItemType contentItemTypeFromDelegate(QQuickItem *delegateItem) - { - if (delegateItem->parentItem()->inherits("QQuickPathView")) { - return PathViewContentItem; - } else if (delegateItem->parentItem()->parentItem() - && delegateItem->parentItem()->parentItem()->inherits("QQuickListView")) { - return ListViewContentItem; - } - - return UnsupportedContentItemType; - } -} - -void QQuickTumblerPrivate::_q_updateItemHeights() -{ - // Can't use our own private padding members here, as the padding property might be set, - // which doesn't affect them, only their getters. - Q_Q(const QQuickTumbler); - const qreal itemHeight = delegateHeight(q); - foreach (QQuickItem *childItem, contentItemChildItems(contentItem)) - childItem->setHeight(itemHeight); -} - -void QQuickTumblerPrivate::_q_updateItemWidths() -{ - Q_Q(const QQuickTumbler); - const qreal availableWidth = q->availableWidth(); - foreach (QQuickItem *childItem, contentItemChildItems(contentItem)) - childItem->setWidth(availableWidth); -} - -void QQuickTumblerPrivate::itemChildAdded(QQuickItem *, QQuickItem *) -{ - _q_updateItemWidths(); - _q_updateItemHeights(); -} - -void QQuickTumblerPrivate::itemChildRemoved(QQuickItem *, QQuickItem *) -{ - _q_updateItemWidths(); - _q_updateItemHeights(); -} - -QQuickTumbler::QQuickTumbler(QQuickItem *parent) : - QQuickControl(*(new QQuickTumblerPrivate), parent) -{ - setActiveFocusOnTab(true); - - connect(this, SIGNAL(leftPaddingChanged()), this, SLOT(_q_updateItemWidths())); - connect(this, SIGNAL(rightPaddingChanged()), this, SLOT(_q_updateItemWidths())); - connect(this, SIGNAL(topPaddingChanged()), this, SLOT(_q_updateItemHeights())); - connect(this, SIGNAL(bottomPaddingChanged()), this, SLOT(_q_updateItemHeights())); -} - -QQuickTumbler::~QQuickTumbler() -{ -} - -/*! - \qmlproperty variant QtQuickExtras2::Tumbler::model - - This property holds the model that provides data for this tumbler. -*/ -QVariant QQuickTumbler::model() const -{ - Q_D(const QQuickTumbler); - return d->model; -} - -void QQuickTumbler::setModel(const QVariant &model) -{ - Q_D(QQuickTumbler); - if (model != d->model) { - d->model = model; - emit modelChanged(); - } -} - -/*! - \qmlproperty int QtQuickExtras2::Tumbler::count - - This property holds the number of items in the model. -*/ -int QQuickTumbler::count() const -{ - Q_D(const QQuickTumbler); - return d->contentItem->property("count").toInt(); -} - -/*! - \qmlproperty int QtQuickExtras2::Tumbler::currentIndex - - This property holds the index of the current item. -*/ -int QQuickTumbler::currentIndex() const -{ - Q_D(const QQuickTumbler); - return d->contentItem ? d->contentItem->property("currentIndex").toInt() : -1; -} - -void QQuickTumbler::setCurrentIndex(int currentIndex) -{ - Q_D(QQuickTumbler); - d->contentItem->setProperty("currentIndex", currentIndex); -} - -/*! - \qmlproperty Item QtQuickExtras2::Tumbler::currentItem - - This property holds the item at the current index. -*/ -QQuickItem *QQuickTumbler::currentItem() const -{ - Q_D(const QQuickTumbler); - return d->contentItem ? d->contentItem->property("currentItem").value() : Q_NULLPTR; -} - -/*! - \qmlproperty component QtQuickExtras2::Tumbler::delegate - - This property holds the delegate used to display each item. -*/ -QQmlComponent *QQuickTumbler::delegate() const -{ - Q_D(const QQuickTumbler); - return d->delegate; -} - -void QQuickTumbler::setDelegate(QQmlComponent *delegate) -{ - Q_D(QQuickTumbler); - if (delegate != d->delegate) { - d->delegate = delegate; - emit delegateChanged(); - } -} - -/*! - \qmlproperty int QtQuickExtras2::Tumbler::visibleItemCount - - This property holds the number of items visible in the tumbler. It must be - an odd number, as the current item is always vertically centered. -*/ -int QQuickTumbler::visibleItemCount() const -{ - Q_D(const QQuickTumbler); - return d->visibleItemCount; -} - -void QQuickTumbler::setVisibleItemCount(int visibleItemCount) -{ - Q_D(QQuickTumbler); - if (visibleItemCount != d->visibleItemCount) { - d->visibleItemCount = visibleItemCount; - d->_q_updateItemHeights(); - emit visibleItemCountChanged(); - } -} - -QQuickTumblerAttached *QQuickTumbler::qmlAttachedProperties(QObject *object) -{ - QQuickItem *delegateItem = qobject_cast(object); - if (!delegateItem) { - qWarning() << "Tumbler: attached properties of Tumbler must be accessed from within a delegate item"; - return Q_NULLPTR; - } - - return new QQuickTumblerAttached(delegateItem); -} - -void QQuickTumbler::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickTumbler); - - QQuickControl::geometryChanged(newGeometry, oldGeometry); - - d->_q_updateItemHeights(); - - if (newGeometry.width() != oldGeometry.width()) - d->_q_updateItemWidths(); -} - -void QQuickTumbler::componentComplete() -{ - Q_D(QQuickTumbler); - QQuickControl::componentComplete(); - d->_q_updateItemHeights(); - d->_q_updateItemWidths(); -} - -void QQuickTumbler::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) -{ - Q_D(QQuickTumbler); - - QQuickControl::contentItemChange(newItem, oldItem); - - // Since we use the currentIndex of the contentItem directly, we must - // ensure that we keep track of the currentIndex so it doesn't get lost - // between contentItem changes. - const int previousCurrentIndex = currentIndex(); - - if (oldItem) { - disconnect(oldItem, SIGNAL(currentIndexChanged()), this, SIGNAL(currentIndexChanged())); - disconnect(oldItem, SIGNAL(currentItemChanged()), this, SIGNAL(currentItemChanged())); - disconnect(oldItem, SIGNAL(countChanged()), this, SIGNAL(countChanged())); - - ContentItemType oldContentItemType = contentItemType(oldItem); - QQuickItem *actualOldContentItem = actualContentItem(oldItem, oldContentItemType); - QQuickItemPrivate *actualContentItemPrivate = QQuickItemPrivate::get(actualOldContentItem); - actualContentItemPrivate->removeItemChangeListener(d, QQuickItemPrivate::Children); - } - - if (newItem) { - ContentItemType contentType = contentItemType(newItem); - if (contentType == UnsupportedContentItemType) { - qWarning() << "Tumbler: contentItems other than PathView and ListView are not supported"; - return; - } - - connect(newItem, SIGNAL(currentIndexChanged()), this, SIGNAL(currentIndexChanged())); - connect(newItem, SIGNAL(currentItemChanged()), this, SIGNAL(currentItemChanged())); - connect(newItem, SIGNAL(countChanged()), this, SIGNAL(countChanged())); - - QQuickItem *actualNewContentItem = actualContentItem(newItem, contentType); - QQuickItemPrivate *actualContentItemPrivate = QQuickItemPrivate::get(actualNewContentItem); - actualContentItemPrivate->addItemChangeListener(d, QQuickItemPrivate::Children); - - // If the previous currentIndex is -1, it means we had no contentItem previously. - if (previousCurrentIndex != -1) { - // Can't call setCurrentIndex here, as contentItemChange() is - // called *before* the contentItem is set. - newItem->setProperty("currentIndex", previousCurrentIndex); - } - } -} - -void QQuickTumbler::keyPressEvent(QKeyEvent *event) -{ - Q_D(QQuickTumbler); - - QQuickControl::keyPressEvent(event); - - if (event->isAutoRepeat()) - return; - - if (event->key() == Qt::Key_Up) { - QMetaObject::invokeMethod(d->contentItem, "decrementCurrentIndex"); - } else if (event->key() == Qt::Key_Down) { - QMetaObject::invokeMethod(d->contentItem, "incrementCurrentIndex"); - } -} - -class QQuickTumblerAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener -{ - Q_DECLARE_PUBLIC(QQuickTumblerAttached) -public: - QQuickTumblerAttachedPrivate(QQuickItem *delegateItem) : - tumbler(Q_NULLPTR), - index(-1), - displacement(1) - { - if (!delegateItem->parentItem()) { - qWarning() << "Tumbler: attached properties must be accessed from within a delegate item that has a parent"; - return; - } - - QVariant indexContextProperty = qmlContext(delegateItem)->contextProperty(QStringLiteral("index")); - if (!indexContextProperty.isValid()) { - qWarning() << "Tumbler: attempting to access attached property on item without an \"index\" property"; - return; - } - - index = indexContextProperty.toInt(); - const ContentItemType contentItemType = contentItemTypeFromDelegate(delegateItem); - if (contentItemType == UnsupportedContentItemType) - return; - - // ListView has an "additional" content item. - tumbler = qobject_cast(contentItemType == PathViewContentItem - ? delegateItem->parentItem()->parentItem() : delegateItem->parentItem()->parentItem()->parentItem()); - Q_ASSERT(tumbler); - } - - ~QQuickTumblerAttachedPrivate() { - } - - void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; - void itemChildAdded(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; - void itemChildRemoved(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; - - void _q_calculateDisplacement(); - - // The Tumbler that contains the delegate. Required to calculated the displacement. - QQuickTumbler *tumbler; - // The index of the delegate. Used to calculate the displacement. - int index; - // The displacement for our delegate. - qreal displacement; -}; - -void QQuickTumblerAttachedPrivate::itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &) -{ - _q_calculateDisplacement(); -} - -void QQuickTumblerAttachedPrivate::itemChildAdded(QQuickItem *, QQuickItem *) -{ - _q_calculateDisplacement(); -} - -void QQuickTumblerAttachedPrivate::itemChildRemoved(QQuickItem *item, QQuickItem *child) -{ - _q_calculateDisplacement(); - - if (parent == child) { - // The child that was removed from the contentItem was the delegate - // that our properties are attached to. If we don't remove the change - // listener, the contentItem will attempt to notify a destroyed - // listener, causing a crash. - - // item is the "actual content item" of Tumbler's contentItem, i.e. a PathView or ListView.contentItem - QQuickItemPrivate *p = QQuickItemPrivate::get(item); - p->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Children); - } -} - -void QQuickTumblerAttachedPrivate::_q_calculateDisplacement() -{ - const int previousDisplacement = displacement; - displacement = 0; - - // This can happen in tests, so it may happen in normal usage too. - if (tumbler->count() == 0) - return; - - ContentItemType contentType = contentItemType(tumbler->contentItem()); - if (contentType == UnsupportedContentItemType) - return; - - qreal offset = 0; - - if (contentType == PathViewContentItem) { - offset = tumbler->contentItem()->property("offset").toReal(); - - displacement = tumbler->count() - index - offset; - int halfVisibleItems = tumbler->visibleItemCount() / 2 + 1; - if (displacement > halfVisibleItems) - displacement -= tumbler->count(); - else if (displacement < -halfVisibleItems) - displacement += tumbler->count(); - } else { - const qreal contentY = tumbler->contentItem()->property("contentY").toReal(); - const qreal delegateH = delegateHeight(tumbler); - const qreal preferredHighlightBegin = tumbler->contentItem()->property("preferredHighlightBegin").toReal(); - // Tumbler's displacement goes from negative at the top to positive towards the bottom, so we must switch this around. - const qreal reverseDisplacement = (contentY + preferredHighlightBegin) / delegateH; - displacement = reverseDisplacement - index; - } - - Q_Q(QQuickTumblerAttached); - if (displacement != previousDisplacement) - emit q->displacementChanged(); -} - -QQuickTumblerAttached::QQuickTumblerAttached(QQuickItem *delegateItem) : - QObject(*(new QQuickTumblerAttachedPrivate(delegateItem)), delegateItem) -{ - Q_D(QQuickTumblerAttached); - if (d->tumbler) { - QQuickItem *rootContentItem = d->tumbler->contentItem(); - const ContentItemType contentType = contentItemType(rootContentItem); - QQuickItemPrivate *p = QQuickItemPrivate::get(actualContentItem(rootContentItem, contentType)); - p->addItemChangeListener(d, QQuickItemPrivate::Geometry | QQuickItemPrivate::Children); - - const char *contentItemSignal = contentType == PathViewContentItem - ? SIGNAL(offsetChanged()) : SIGNAL(contentYChanged()); - connect(d->tumbler->contentItem(), contentItemSignal, this, SLOT(_q_calculateDisplacement())); - } -} - -QQuickTumblerAttached::~QQuickTumblerAttached() -{ -} - -QQuickTumbler *QQuickTumblerAttached::tumbler() const -{ - Q_D(const QQuickTumblerAttached); - return d->tumbler; -} - -qreal QQuickTumblerAttached::displacement() const -{ - Q_D(const QQuickTumblerAttached); - return d->displacement; -} - -QT_END_NAMESPACE - -#include "moc_qquicktumbler_p.cpp" diff --git a/src/extras/qquicktumbler_p.h b/src/extras/qquicktumbler_p.h deleted file mode 100644 index ecefad18..00000000 --- a/src/extras/qquicktumbler_p.h +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 QQUICKTUMBLER_H -#define QQUICKTUMBLER_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 -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class QQuickTumblerAttached; -class QQuickTumblerPrivate; - -class Q_QUICKEXTRAS_EXPORT QQuickTumbler : public QQuickControl -{ - Q_OBJECT - Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL) - Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) - Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) - Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) - Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) - Q_PROPERTY(int visibleItemCount READ visibleItemCount WRITE setVisibleItemCount NOTIFY visibleItemCountChanged FINAL) - -public: - explicit QQuickTumbler(QQuickItem *parent = Q_NULLPTR); - ~QQuickTumbler(); - - QVariant model() const; - void setModel(const QVariant &model); - - int count() const; - - int currentIndex() const; - void setCurrentIndex(int currentIndex); - QQuickItem *currentItem() const; - - QQmlComponent *delegate() const; - void setDelegate(QQmlComponent *delegate); - - int visibleItemCount() const; - void setVisibleItemCount(int visibleItemCount); - - static QQuickTumblerAttached *qmlAttachedProperties(QObject *object); - -Q_SIGNALS: - void modelChanged(); - void countChanged(); - void currentIndexChanged(); - void currentItemChanged(); - void delegateChanged(); - void visibleItemCountChanged(); - -protected: - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; - void componentComplete() Q_DECL_OVERRIDE; - void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QQuickTumbler) - Q_DECLARE_PRIVATE(QQuickTumbler) - - Q_PRIVATE_SLOT(d_func(), void _q_updateItemWidths()) - Q_PRIVATE_SLOT(d_func(), void _q_updateItemHeights()) -}; - -Q_DECLARE_TYPEINFO(QQuickTumbler, Q_COMPLEX_TYPE); - -class QQuickTumblerAttachedPrivate; - -class Q_QUICKEXTRAS_EXPORT QQuickTumblerAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QQuickTumbler *tumbler READ tumbler CONSTANT) - Q_PROPERTY(qreal displacement READ displacement NOTIFY displacementChanged FINAL) - -public: - explicit QQuickTumblerAttached(QQuickItem *delegateItem); - ~QQuickTumblerAttached(); - - QQuickTumbler *tumbler() const; - qreal displacement() const; - -Q_SIGNALS: - void displacementChanged(); - -private: - Q_DISABLE_COPY(QQuickTumblerAttached) - Q_DECLARE_PRIVATE(QQuickTumblerAttached) - - Q_PRIVATE_SLOT(d_func(), void _q_calculateDisplacement()) -}; - -Q_DECLARE_TYPEINFO(QQuickTumblerAttached, Q_COMPLEX_TYPE); - -QT_END_NAMESPACE - -QML_DECLARE_TYPEINFO(QQuickTumbler, QML_HAS_ATTACHED_PROPERTIES) - -#endif // QQUICKTUMBLER_H diff --git a/src/extras/qtquickextrasglobal_p.h b/src/extras/qtquickextrasglobal_p.h deleted file mode 100644 index 1c9e54eb..00000000 --- a/src/extras/qtquickextrasglobal_p.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Extras 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 QTQUICKEXTRASGLOBAL_P_H -#define QTQUICKEXTRASGLOBAL_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 - -QT_BEGIN_NAMESPACE - -#ifndef QT_STATIC -# if defined(QT_BUILD_QUICKEXTRAS2_LIB) -# define Q_QUICKEXTRAS_EXPORT Q_DECL_EXPORT -# else -# define Q_QUICKEXTRAS_EXPORT Q_DECL_IMPORT -# endif -#else -# define Q_QUICKEXTRAS_EXPORT -#endif - -QT_END_NAMESPACE - -#endif // QTQUICKEXTRASGLOBAL_P_H diff --git a/src/imports/extras/doc/images/.directory b/src/imports/extras/doc/images/.directory new file mode 100644 index 00000000..7d49c166 --- /dev/null +++ b/src/imports/extras/doc/images/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2015,7,13,18,47,2 +Version=3 +ViewMode=1 diff --git a/src/imports/extras/doc/images/qtquickextras2-dial-background.png b/src/imports/extras/doc/images/qtquickextras2-dial-background.png new file mode 100644 index 00000000..38fad583 Binary files /dev/null and b/src/imports/extras/doc/images/qtquickextras2-dial-background.png differ diff --git a/src/imports/extras/doc/images/qtquickextras2-dial-handle.png b/src/imports/extras/doc/images/qtquickextras2-dial-handle.png new file mode 100644 index 00000000..e6fd8cdc Binary files /dev/null and b/src/imports/extras/doc/images/qtquickextras2-dial-handle.png differ diff --git a/src/imports/extras/doc/images/qtquickextras2-tumbler-background.png b/src/imports/extras/doc/images/qtquickextras2-tumbler-background.png new file mode 100644 index 00000000..aa736615 Binary files /dev/null and b/src/imports/extras/doc/images/qtquickextras2-tumbler-background.png differ diff --git a/src/imports/extras/doc/images/qtquickextras2-tumbler-contentItem.png b/src/imports/extras/doc/images/qtquickextras2-tumbler-contentItem.png new file mode 100644 index 00000000..aa736615 Binary files /dev/null and b/src/imports/extras/doc/images/qtquickextras2-tumbler-contentItem.png differ diff --git a/src/imports/extras/doc/images/qtquickextras2-tumbler-delegate.png b/src/imports/extras/doc/images/qtquickextras2-tumbler-delegate.png new file mode 100644 index 00000000..77c51efd Binary files /dev/null and b/src/imports/extras/doc/images/qtquickextras2-tumbler-delegate.png differ diff --git a/src/imports/extras/doc/images/qtquickextras2-tumbler-wrap.gif b/src/imports/extras/doc/images/qtquickextras2-tumbler-wrap.gif new file mode 100644 index 00000000..2a7e435d Binary files /dev/null and b/src/imports/extras/doc/images/qtquickextras2-tumbler-wrap.gif differ diff --git a/src/imports/extras/doc/qtquickextras2.qdocconf b/src/imports/extras/doc/qtquickextras2.qdocconf new file mode 100644 index 00000000..622c7d05 --- /dev/null +++ b/src/imports/extras/doc/qtquickextras2.qdocconf @@ -0,0 +1,47 @@ +include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf) + +project = QtQuickExtras2 +description = Qt Quick Extras 2 Reference Documentation +version = $QT_VERSION + +qhp.projects = QtQuickExtras2 + +qhp.QtQuickExtras2.file = qtquickextras2.qhp +qhp.QtQuickExtras2.namespace = org.qt-project.qtquickextras2.$QT_VERSION_TAG +qhp.QtQuickExtras2.virtualFolder = qtquickextras2 +qhp.QtQuickExtras2.indexTitle = Qt Quick Extras 2 +qhp.QtQuickExtras2.indexRoot = + +qhp.QtQuickExtras2.filterAttributes = qtquickextras2 $QT_VERSION qtrefdoc +qhp.QtQuickExtras2.customFilters.Qt.name = QtQuickExtras2 $QT_VERSION +qhp.QtQuickExtras2.customFilters.Qt.filterAttributes = qtquickextras2 $QT_VERSION + +qhp.QtQuickExtras2.subprojects = qtquickextras2qmltypes + +qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.title = Extras 2 QML Types +qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.indexTitle = Qt Quick Extras 2 QML Types +qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.selectors = qmlclass +qhp.QtQuickExtras2.subprojects.qtquickextras2qmltypes.sortPages = true + +depends = qtcore qtgui qtdoc qtqml qtquick qtquicklayouts qtquickdialogs qtquickcontrols2 + +# Specify the install path under QT_INSTALL_EXAMPLES +# Examples will be installed under quick/extras - 'extras' subdirectory +# is given as part of \example commands +exampledirs += ../ ../../../../examples/quick/extras +examplesinstallpath = quick/extras + +headerdirs += ../ +sourcedirs += ../ + +imagedirs += images + +navigation.landingpage = "Qt Quick Extras 2" +navigation.qmltypespage = "Qt Quick Extras 2 QML Types" + +tagfile = qtquickextras2.tags + +# Specify a QML module suffix, applied to html filenames, to avoid +# clashes with Qt Quick Extras 1 documentation. +outputsuffixes = QML +outputsuffixes.QML = 2 diff --git a/src/imports/extras/doc/src/qtquickextras2-customize.qdoc b/src/imports/extras/doc/src/qtquickextras2-customize.qdoc new file mode 100644 index 00000000..fc04fe1f --- /dev/null +++ b/src/imports/extras/doc/src/qtquickextras2-customize.qdoc @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/*! + \page qtquickextras2-customize.html + \title Customizing Qt Quick Extras 2 + \brief A set of UI controls to create user interfaces in Qt Quick + + Qt Quick Controls consist of a hierarchy (tree) of items. In order to + provide a custom look and feel, the default implementation of each item + can be replaced with a custom one. The following snippets present the + default implementations of various items. These can be used as a starting + point to implement a custom look and feel. + + \sa {Customizing Qt Quick Controls 2} + + \section1 Customizing Dial + + Dial consists of two visual items: \l {Control::background}{background} + and \l {Dial::handle}{handle}. + + \section3 Background + + \image qtquickextras2-dial-background.png + + \snippet Dial.qml background + + \section3 Indicator + + \image qtquickextras2-dial-handle.png + + \snippet Dial.qml handle + + \section1 Customizing Tumbler + + Tumbler consists of three visual items: + \l {Control::background}{background}, + \l {Control::contentItem}{contentItem}, and + \l {Tumbler::delegate}{delegate}. + + \section3 Background + + \image qtquickextras2-tumbler-background.png + + Tumbler has no background item by default. + + \section3 Content Item + + \image qtquickextras2-tumbler-contentItem.png + + \snippet Tumbler.qml contentItem + + \section3 Delegate + + \image qtquickextras2-tumbler-delegate.png + + \snippet Tumbler.qml delegate +*/ diff --git a/src/imports/extras/doc/src/qtquickextras2-index.qdoc b/src/imports/extras/doc/src/qtquickextras2-index.qdoc new file mode 100644 index 00000000..53712e22 --- /dev/null +++ b/src/imports/extras/doc/src/qtquickextras2-index.qdoc @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/*! + \page qtquickextras2-index.html + \title Qt Quick Extras 2 + + \brief The Qt Quick Extras 2 module provides a set of specialized UI + controls for Qt Quick. + + The Qt Quick Extras 2 module provides a set of controls that can be used to + build interfaces in Qt Quick. + + The module is new in Qt 5.6. + + Visit the \l{Qt Quick Extras 2 Overview} page to get started. + + \section1 Related Information + + \list + \li \l{Qt Quick} + \li \l{Qt Quick Extras 2 Overview} + \li \l{Qt Quick Extras 2 QML Types}{Qt Quick Extras 2 QML Types} + \endlist +*/ diff --git a/src/imports/extras/doc/src/qtquickextras2-overview.qdoc b/src/imports/extras/doc/src/qtquickextras2-overview.qdoc new file mode 100644 index 00000000..9776e1de --- /dev/null +++ b/src/imports/extras/doc/src/qtquickextras2-overview.qdoc @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/*! + \page qtquickextras2-overview.html + \title Qt Quick Extras 2 Overview + \brief A set of UI controls to create user interfaces in Qt Quick + + The Qt Quick Extras 2 module provides a set of UI controls to create user + interfaces in Qt Quick. + + \section1 Getting Started + + TODO + + \section1 Customization + + Qt Quick Controls consist of a hierarchy (tree) of items. In order to + provide a custom look and feel, the default implementation of each can be + replaced with a custom item. For examples of how do this, see + \l {Customizing Qt Quick Extras 2}. + + \section1 Related Information + + \list + \li \l{Qt Quick} + \li \l{Qt Quick Controls 2} + \endlist +*/ diff --git a/src/imports/extras/doc/src/qtquickextras2.qdoc b/src/imports/extras/doc/src/qtquickextras2.qdoc new file mode 100644 index 00000000..74dbd778 --- /dev/null +++ b/src/imports/extras/doc/src/qtquickextras2.qdoc @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +/*! + \qmlmodule QtQuick.Extras 2.0 + \title Qt Quick Extras 2 QML Types + \ingroup qmlmodules + \brief Provides QML types for user interfaces. + + The \l{Qt Quick Extras 2} module provides QML types for creating user + interfaces. These QML types work in conjunction with \l{Qt Quick}, + \l{Qt Quick Layouts} and \l{Qt Quick Controls 2}. + + The QML types can be imported into your application using the + following import statement in your .qml file. + + \badcode + import QtQuick.Extras 2.0 + \endcode +*/ diff --git a/src/imports/extras/extras.pri b/src/imports/extras/extras.pri new file mode 100644 index 00000000..859ed07e --- /dev/null +++ b/src/imports/extras/extras.pri @@ -0,0 +1,17 @@ +QML_FILES = \ + Dial.qml \ + Drawer.qml \ + SwipeView.qml \ + Tumbler.qml + +HEADERS += \ + $$PWD/qquickdial_p.h \ + $$PWD/qquickdrawer_p.h \ + $$PWD/qquickswipeview_p.h \ + $$PWD/qquicktumbler_p.h + +SOURCES += \ + $$PWD/qquickdial.cpp \ + $$PWD/qquickdrawer.cpp \ + $$PWD/qquickswipeview.cpp \ + $$PWD/qquicktumbler.cpp diff --git a/src/imports/extras/extras.pro b/src/imports/extras/extras.pro index 5aa6f04e..1046cec4 100644 --- a/src/imports/extras/extras.pro +++ b/src/imports/extras/extras.pro @@ -3,21 +3,21 @@ TARGETPATH = QtQuick/Extras.2 IMPORT_VERSION = 2.0 QT += qml quick -QT += core-private gui-private qml-private quick-private quickcontrols2-private quickextras2-private +QT += core-private gui-private qml-private quick-private quickcontrols2-private + +QMAKE_DOCS = $$PWD/doc/qtquickextras2.qdocconf + +DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +INCLUDEPATH += $$PWD OTHER_FILES += \ qmldir -QML_FILES = \ - Dial.qml \ - Drawer.qml \ - SwipeView.qml \ - Tumbler.qml - SOURCES += \ $$PWD/qtquickextras2plugin.cpp +include(extras.pri) + CONFIG += no_cxx_module load(qml_plugin) - -DISTFILES += diff --git a/src/imports/extras/qquickdial.cpp b/src/imports/extras/qquickdial.cpp new file mode 100644 index 00000000..fe196659 --- /dev/null +++ b/src/imports/extras/qquickdial.cpp @@ -0,0 +1,527 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 "qquickdial_p.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Dial + \inherits Control + \instantiates QQuickDial + \inqmlmodule QtQuick.Extras + \ingroup sliders + \brief A circular dial that is rotated to set a value. + + The Dial is similar to a traditional dial knob that is found on devices + such as stereos or industrial equipment. It allows the user to specify a + value within a range. + + The value of the dial is set with the \l value property. The range is + set with the \l from and \l to properties. + + The dial can be manipulated with a keyboard. It supports the following + actions: + + \table + \header \li \b {Action} \li \b {Key} + \row \li Decrease \l value by \l stepSize \li \c Qt.Key_Left + \row \li Decrease \l value by \l stepSize \li \c Qt.Key_Down + \row \li Set \l value to \l from \li \c Qt.Key_Home + \row \li Increase \l value by \l stepSize \li \c Qt.Key_Right + \row \li Increase \l value by \l stepSize \li \c Qt.Key_Up + \row \li Set \l value to \l to \li \c Qt.Key_End + \endtable + + \sa {Customizing Dial} +*/ + +static const qreal startAngle = -140; +static const qreal endAngle = 140; + +class QQuickDialPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickDial) + +public: + QQuickDialPrivate() : + from(0), + to(1), + value(0), + position(0), + angle(startAngle), + stepSize(0), + pressed(false), + snapMode(QQuickDial::NoSnap), + handle(Q_NULLPTR) + { + } + + qreal valueAt(qreal position) const; + qreal snapPosition(qreal position) const; + qreal positionAt(const QPoint &point) const; + void setPosition(qreal position); + void updatePosition(); + + qreal from; + qreal to; + qreal value; + qreal position; + qreal angle; + qreal stepSize; + bool pressed; + QPoint pressPoint; + QQuickDial::SnapMode snapMode; + QQuickItem *handle; +}; + +qreal QQuickDialPrivate::valueAt(qreal position) const +{ + return from + (to - from) * position; +} + +qreal QQuickDialPrivate::snapPosition(qreal position) const +{ + if (qFuzzyIsNull(stepSize)) + return position; + return qRound(position / stepSize) * stepSize; +} + +qreal QQuickDialPrivate::positionAt(const QPoint &point) const +{ + qreal yy = height / 2.0 - point.y(); + qreal xx = point.x() - width / 2.0; + qreal angle = (xx || yy) ? atan2(yy, xx) : 0; + + if (angle < M_PI / -2) + angle = angle + M_PI * 2; + + qreal normalizedAngle = (M_PI * 4 / 3 - angle) / (M_PI * 10 / 6); + return normalizedAngle; +} + +void QQuickDialPrivate::setPosition(qreal pos) +{ + Q_Q(QQuickDial); + pos = qBound(0.0, pos, 1.0); + if (!qFuzzyCompare(position, pos)) { + position = pos; + + angle = startAngle + position * qAbs(endAngle - startAngle); + + emit q->positionChanged(); + emit q->angleChanged(); + } +} + +void QQuickDialPrivate::updatePosition() +{ + qreal pos = 0; + if (!qFuzzyCompare(from, to)) + pos = (value - from) / (to - from); + setPosition(pos); +} + +QQuickDial::QQuickDial(QQuickItem *parent) : + QQuickControl(*(new QQuickDialPrivate), parent) +{ + setActiveFocusOnTab(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +/*! + \qmlproperty real QtQuickExtras2::Dial::from + + This property holds the starting value for the range. The default value is \c 0.0. + + \sa to, value +*/ +qreal QQuickDial::from() const +{ + Q_D(const QQuickDial); + return d->from; +} + +void QQuickDial::setFrom(qreal from) +{ + Q_D(QQuickDial); + if (!qFuzzyCompare(d->from, from)) { + d->from = from; + emit fromChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); + } + } +} + +/*! + \qmlproperty real QtQuickExtras2::Dial::to + + This property holds the end value for the range. The default value is + \c 1.0. + + \sa from, value +*/ +qreal QQuickDial::to() const +{ + Q_D(const QQuickDial); + return d->to; +} + +void QQuickDial::setTo(qreal to) +{ + Q_D(QQuickDial); + if (!qFuzzyCompare(d->to, to)) { + d->to = to; + emit toChanged(); + if (isComponentComplete()) { + setValue(d->value); + d->updatePosition(); + } + } +} + +/*! + \qmlproperty real QtQuickExtras2::Dial::value + + This property holds the value in the range \c from - \c to. The default + value is \c 0.0. + + Unlike the \l position property, the \c value is not updated while the + handle is dragged. The value is updated after the value has been chosen + and the dial has been released. + + \sa position +*/ +qreal QQuickDial::value() const +{ + Q_D(const QQuickDial); + return d->value; +} + +void QQuickDial::setValue(qreal value) +{ + Q_D(QQuickDial); + if (isComponentComplete()) + value = d->from > d->to ? qBound(d->to, value, d->from) : qBound(d->from, value, d->to); + + if (!qFuzzyCompare(d->value, value)) { + d->value = value; + d->updatePosition(); + emit valueChanged(); + } +} + +/*! + \qmlproperty real QtQuickExtras2::Dial::position + + This property holds the logical position of the handle. + + The position is defined as a percentage of the control's angle range (the + range within which the handle can be moved) scaled to \c {0.0 - 1.0}. + Unlike the \l value property, the \c position is continuously updated while + the handle is dragged. + + \sa value, angle +*/ +qreal QQuickDial::position() const +{ + Q_D(const QQuickDial); + return d->position; +} + +/*! + \qmlproperty real QtQuickExtras2::Dial::angle \readonly + + This property holds the angle of the handle. + + Like the \l position property, angle is continuously updated while the + handle is dragged. + + \sa position +*/ +qreal QQuickDial::angle() const +{ + Q_D(const QQuickDial); + return d->angle; +} + +/*! + \qmlproperty real QtQuickExtras2::Dial::stepSize + + This property holds the step size. The default value is \c 0.0. + + \sa snapMode, increase(), decrease() +*/ +qreal QQuickDial::stepSize() const +{ + Q_D(const QQuickDial); + return d->stepSize; +} + +void QQuickDial::setStepSize(qreal step) +{ + Q_D(QQuickDial); + if (!qFuzzyCompare(d->stepSize, step)) { + d->stepSize = step; + emit stepSizeChanged(); + } +} + +/*! + \qmlproperty enumeration QtQuickExtras2::Dial::snapMode + + This property holds the snap mode. + + The snap mode works with the \l stepSize to allow the handle to snap to + certain points along the dial. + + Possible values: + \list + \li \c Dial.NoSnap (default) - The dial does not snap. + \li \c Dial.SnapAlways - The dial snaps while the handle is dragged. + \li \c Dial.SnapOnRelease - The dial does not snap while being dragged, but only after the handle is released. + \endlist + + \sa stepSize +*/ +QQuickDial::SnapMode QQuickDial::snapMode() const +{ + Q_D(const QQuickDial); + return d->snapMode; +} + +void QQuickDial::setSnapMode(SnapMode mode) +{ + Q_D(QQuickDial); + if (d->snapMode != mode) { + d->snapMode = mode; + emit snapModeChanged(); + } +} + +/*! + \qmlproperty bool QtQuickExtras2::Dial::pressed + + This property holds whether the dial is pressed. + + The dial will be pressed when either the mouse is pressed over it, or a key + such as \c Qt.Key_Left is held down. If you'd prefer not to have the dial + be pressed upon key presses (due to styling reasons, for example), you can + use the \l {Keys}{Keys attached property}: + + \code + Dial { + Keys.onLeftPressed: {} + } + \endcode + + This will result in pressed only being \c true upon mouse presses. +*/ +bool QQuickDial::isPressed() const +{ + Q_D(const QQuickDial); + return d->pressed; +} + +void QQuickDial::setPressed(bool pressed) +{ + Q_D(QQuickDial); + if (d->pressed != pressed) { + d->pressed = pressed; + emit pressedChanged(); + } +} + +/*! + \qmlmethod void QtQuickExtras2::Dial::increase() + + Increases the value by \l stepSize, or \c 0.1 if stepSize is not defined. + + \sa stepSize +*/ +void QQuickDial::increase() +{ + Q_D(QQuickDial); + qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; + setValue(d->value + step); +} + +/*! + \qmlmethod void QtQuickExtras2::Dial::decrease() + + Decreases the value by \l stepSize, or \c 0.1 if stepSize is not defined. + + \sa stepSize +*/ +void QQuickDial::decrease() +{ + Q_D(QQuickDial); + qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; + setValue(d->value - step); +} + +/*! + \qmlproperty component QtQuickExtras2::Dial::handle + + This property holds the handle of the dial. + + The handle acts as a visual indicator of the position of the dial. + + \sa {Customizing Dial} +*/ +QQuickItem *QQuickDial::handle() const +{ + Q_D(const QQuickDial); + return d->handle; +} + +void QQuickDial::setHandle(QQuickItem *handle) +{ + Q_D(QQuickDial); + if (handle != d->handle) { + d->handle = handle; + if (d->handle && !d->handle->parentItem()) + d->handle->setParentItem(this); + emit handleChanged(); + } +} + +void QQuickDial::keyPressEvent(QKeyEvent *event) +{ + Q_D(QQuickDial); + if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Down) { + setPressed(true); + if (isMirrored()) + increase(); + else + decrease(); + } else if (event->key() == Qt::Key_Right || event->key() == Qt::Key_Up) { + setPressed(true); + if (isMirrored()) + decrease(); + else + increase(); + } else if (event->key() == Qt::Key_Home) { + setPressed(true); + setValue(isMirrored() ? d->to : d->from); + } else if (event->key() == Qt::Key_End) { + setPressed(true); + setValue(isMirrored() ? d->from : d->to); + } else { + event->ignore(); + QQuickControl::keyPressEvent(event); + } +} + +void QQuickDial::keyReleaseEvent(QKeyEvent *event) +{ + QQuickControl::keyReleaseEvent(event); + setPressed(false); +} + +void QQuickDial::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickDial); + QQuickControl::mousePressEvent(event); + d->pressPoint = event->pos(); + setPressed(true); +} + +void QQuickDial::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickDial); + QQuickControl::mouseMoveEvent(event); + if (!keepMouseGrab()) { + bool overXDragThreshold = QQuickWindowPrivate::dragOverThreshold(event->pos().x() - d->pressPoint.x(), Qt::XAxis, event); + setKeepMouseGrab(overXDragThreshold); + + if (!overXDragThreshold) { + bool overYDragThreshold = QQuickWindowPrivate::dragOverThreshold(event->pos().y() - d->pressPoint.y(), Qt::YAxis, event); + setKeepMouseGrab(overYDragThreshold); + } + } + if (keepMouseGrab()) { + qreal pos = d->positionAt(event->pos()); + if (d->snapMode == SnapAlways) + pos = d->snapPosition(pos); + d->setPosition(pos); + } +} + +void QQuickDial::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickDial); + QQuickControl::mouseReleaseEvent(event); + d->pressPoint = QPoint(); + if (keepMouseGrab()) { + qreal pos = d->positionAt(event->pos()); + if (d->snapMode != NoSnap) + pos = d->snapPosition(pos); + setValue(d->valueAt(pos)); + setKeepMouseGrab(false); + } + setPressed(false); +} + +void QQuickDial::mouseUngrabEvent() +{ + Q_D(QQuickDial); + QQuickControl::mouseUngrabEvent(); + d->pressPoint = QPoint(); + setPressed(false); +} + +void QQuickDial::mirrorChange() +{ + QQuickControl::mirrorChange(); + emit angleChanged(); +} + +void QQuickDial::componentComplete() +{ + Q_D(QQuickDial); + QQuickControl::componentComplete(); + setValue(d->value); + d->updatePosition(); +} + +QT_END_NAMESPACE diff --git a/src/imports/extras/qquickdial_p.h b/src/imports/extras/qquickdial_p.h new file mode 100644 index 00000000..6e3f4e6a --- /dev/null +++ b/src/imports/extras/qquickdial_p.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 QQUICKDIAL_H +#define QQUICKDIAL_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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickDialAttached; +class QQuickDialPrivate; + +class QQuickDial : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(qreal from READ from WRITE setFrom NOTIFY fromChanged FINAL) + Q_PROPERTY(qreal to READ to WRITE setTo NOTIFY toChanged FINAL) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) + Q_PROPERTY(qreal position READ position NOTIFY positionChanged FINAL) + Q_PROPERTY(qreal angle READ angle NOTIFY angleChanged FINAL) + Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL) + Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) + Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL) + Q_PROPERTY(QQuickItem *handle READ handle WRITE setHandle NOTIFY handleChanged FINAL) + +public: + explicit QQuickDial(QQuickItem *parent = Q_NULLPTR); + + qreal from() const; + void setFrom(qreal from); + + qreal to() const; + void setTo(qreal to); + + qreal value() const; + void setValue(qreal value); + + qreal position() const; + + qreal angle() const; + + qreal stepSize() const; + void setStepSize(qreal step); + + enum SnapMode { + NoSnap, + SnapAlways, + SnapOnRelease + }; + Q_ENUM(SnapMode) + + SnapMode snapMode() const; + void setSnapMode(SnapMode mode); + + bool isPressed() const; + void setPressed(bool pressed); + + QQuickItem *handle() const; + void setHandle(QQuickItem *handle); + +public Q_SLOTS: + void increase(); + void decrease(); + +Q_SIGNALS: + void fromChanged(); + void toChanged(); + void valueChanged(); + void positionChanged(); + void angleChanged(); + void stepSizeChanged(); + void snapModeChanged(); + void pressedChanged(); + void handleChanged(); + +protected: + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseUngrabEvent() Q_DECL_OVERRIDE; + void mirrorChange() Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickDial) + Q_DECLARE_PRIVATE(QQuickDial) +}; + +Q_DECLARE_TYPEINFO(QQuickDial, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKDIAL_H diff --git a/src/imports/extras/qquickdrawer.cpp b/src/imports/extras/qquickdrawer.cpp new file mode 100644 index 00000000..7c61688a --- /dev/null +++ b/src/imports/extras/qquickdrawer.cpp @@ -0,0 +1,388 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 "qquickdrawer_p.h" + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickDrawerPrivate : public QQuickControlPrivate +{ + Q_DECLARE_PUBLIC(QQuickDrawer) + +public: + QQuickDrawerPrivate() : edge(Qt::LeftEdge), offset(0), position(0), + content(Q_NULLPTR), animation(Q_NULLPTR) { } + + void updateContent(); + bool handleMousePressEvent(QQuickItem *item, QMouseEvent *event); + bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event); + bool handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event); + + Qt::Edge edge; + qreal offset; + qreal position; + QPointF pressPoint; + QQuickItem *content; + QQuickPropertyAnimation *animation; +}; + +void QQuickDrawerPrivate::updateContent() +{ + Q_Q(QQuickDrawer); + if (!content) + return; + + switch (edge) { + case Qt::LeftEdge: + content->setX((position - 1.0) * content->width()); + break; + case Qt::RightEdge: + content->setX(q->width() + - position * content->width()); + break; + case Qt::TopEdge: + content->setY((position - 1.0) * content->height()); + break; + case Qt::BottomEdge: + content->setY(q->height() + - position * content->height()); + break; + } +} + +bool QQuickDrawerPrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *event) +{ + Q_Q(QQuickDrawer); + pressPoint = q->mapFromItem(item, event->pos()); + + if (qFuzzyIsNull(position)) { + // only accept pressing at drag margins when fully closed + switch (edge) { + case Qt::LeftEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(event->x(), Qt::XAxis, event)); + break; + case Qt::RightEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(q->width() - event->x(), Qt::XAxis, event)); + break; + case Qt::TopEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(event->y(), Qt::YAxis, event)); + break; + case Qt::BottomEdge: + event->setAccepted(!QQuickWindowPrivate::dragOverThreshold(q->height() - event->y(), Qt::YAxis, event)); + break; + } + offset = 0; + } else { + event->accept(); + offset = q->positionAt(pressPoint) - position; + } + + return item == q; +} + +bool QQuickDrawerPrivate::handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event) +{ + Q_Q(QQuickDrawer); + QPointF movePoint = q->mapFromItem(item, event->pos()); + + if (!q->keepMouseGrab()) { + bool overThreshold = false; + if (edge == Qt::LeftEdge || edge == Qt::RightEdge) + overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.x() - pressPoint.x(), Qt::XAxis, event); + else + overThreshold = QQuickWindowPrivate::dragOverThreshold(movePoint.y() - pressPoint.y(), Qt::YAxis, event); + + if (window && overThreshold) { + QQuickItem *grabber = q->window()->mouseGrabberItem(); + if (!grabber || !grabber->keepMouseGrab()) { + q->grabMouse(); + q->setKeepMouseGrab(overThreshold); + } + } + } + + if (q->keepMouseGrab()) + q->setPosition(q->positionAt(event->pos()) - offset); + event->accept(); + + return q->keepMouseGrab(); +} + +bool QQuickDrawerPrivate::handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event) +{ + Q_Q(QQuickDrawer); + bool wasGrabbed = q->keepMouseGrab(); + if (wasGrabbed) { +// int startDragVelocity = QGuiApplication::styleHints()->startDragVelocity(); +// if (startDragVelocity && QGuiApplicationPrivate::mouseEventCaps(event) & QTouchDevice::Velocity) { +// QVector2D velocity = QGuiApplicationPrivate::mouseEventVelocity(event); +// qreal vel = (edge == Qt::LeftEdge || edge == Qt::RightEdge) ? velocity.x() : velocity.y(); +// qDebug() << vel << "vs." << startDragVelocity; +// } + if (position < 0.3) { + q->close(); + } else if (position > 0.7) { + q->open(); + } else { + switch (edge) { + case Qt::LeftEdge: + if (event->x() - pressPoint.x() > 0) + q->open(); + else + q->close(); + break; + case Qt::RightEdge: + if (event->x() - pressPoint.x() < 0) + q->open(); + else + q->close(); + break; + case Qt::TopEdge: + if (event->y() - pressPoint.y() > 0) + q->open(); + else + q->close(); + break; + case Qt::BottomEdge: + if (event->y() - pressPoint.y() < 0) + q->open(); + else + q->close(); + break; + } + } + q->setKeepMouseGrab(false); + } else { + if (item == q) + emit q->clicked(); + } + pressPoint = QPoint(); + event->accept(); + return wasGrabbed; +} + +QQuickDrawer::QQuickDrawer(QQuickItem *parent) : + QQuickControl(*(new QQuickDrawerPrivate), parent) +{ + setZ(1); + setFiltersChildMouseEvents(true); + setAcceptedMouseButtons(Qt::LeftButton); +} + +Qt::Edge QQuickDrawer::edge() const +{ + Q_D(const QQuickDrawer); + return d->edge; +} + +void QQuickDrawer::setEdge(Qt::Edge edge) +{ + Q_D(QQuickDrawer); + if (d->edge != edge) { + d->edge = edge; + if (isComponentComplete()) + d->updateContent(); + emit edgeChanged(); + } +} + +qreal QQuickDrawer::position() const +{ + Q_D(const QQuickDrawer); + return d->position; +} + +void QQuickDrawer::setPosition(qreal position) +{ + Q_D(QQuickDrawer); + position = qBound(0.0, position, 1.0); + if (!qFuzzyCompare(d->position, position)) { + d->position = position; + if (isComponentComplete()) + d->updateContent(); + emit positionChanged(); + } +} + +QQuickItem *QQuickDrawer::contentItem() const +{ + Q_D(const QQuickDrawer); + return d->content; +} + +void QQuickDrawer::setContentItem(QQuickItem *item) +{ + Q_D(QQuickDrawer); + if (d->content != item) { + delete d->content; + d->content = item; + if (item) + item->setParentItem(this); + if (isComponentComplete()) + d->updateContent(); + emit contentItemChanged(); + } +} + +QQuickPropertyAnimation *QQuickDrawer::animation() const +{ + Q_D(const QQuickDrawer); + return d->animation; +} + +void QQuickDrawer::setAnimation(QQuickPropertyAnimation *animation) +{ + Q_D(QQuickDrawer); + if (d->animation != animation) { + delete d->animation; + d->animation = animation; + if (animation) { + animation->setTargetObject(this); + animation->setProperty(QStringLiteral("position")); + } + emit animationChanged(); + } +} + +void QQuickDrawer::open() +{ + Q_D(QQuickDrawer); + if (d->animation) { + d->animation->stop(); + d->animation->setFrom(d->position); + d->animation->setTo(1.0); + d->animation->start(); + } else { + setPosition(1.0); + } +} + +void QQuickDrawer::close() +{ + Q_D(QQuickDrawer); + if (d->animation) { + d->animation->stop(); + d->animation->setFrom(d->position); + d->animation->setTo(0.0); + d->animation->start(); + } else { + setPosition(0.0); + } +} + +bool QQuickDrawer::childMouseEventFilter(QQuickItem *child, QEvent *event) +{ + Q_D(QQuickDrawer); + switch (event->type()) { + case QEvent::MouseButtonPress: + return d->handleMousePressEvent(child, static_cast(event)); + case QEvent::MouseMove: + return d->handleMouseMoveEvent(child, static_cast(event)); + case QEvent::MouseButtonRelease: + return d->handleMouseReleaseEvent(child, static_cast(event)); + default: + return false; + } +} + +void QQuickDrawer::mousePressEvent(QMouseEvent *event) +{ + Q_D(QQuickDrawer); + QQuickControl::mousePressEvent(event); + d->handleMousePressEvent(this, event); +} + +void QQuickDrawer::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QQuickDrawer); + QQuickControl::mouseMoveEvent(event); + d->handleMouseMoveEvent(this, event); +} + +void QQuickDrawer::mouseReleaseEvent(QMouseEvent *event) +{ + Q_D(QQuickDrawer); + QQuickControl::mouseReleaseEvent(event); + d->handleMouseReleaseEvent(this, event); +} + +void QQuickDrawer::mouseUngrabEvent() +{ + Q_D(QQuickDrawer); + QQuickControl::mouseUngrabEvent(); + d->pressPoint = QPoint(); +} + +void QQuickDrawer::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickDrawer); + QQuickControl::geometryChanged(newGeometry, oldGeometry); + if (isComponentComplete()) + d->updateContent(); +} + +void QQuickDrawer::componentComplete() +{ + Q_D(QQuickDrawer); + QQuickControl::componentComplete(); + d->updateContent(); +} + +qreal QQuickDrawer::positionAt(const QPointF &point) const +{ + Q_D(const QQuickDrawer); + if (!d->content) + return 0.0; + + switch (d->edge) { + case Qt::TopEdge: + return point.y() / d->content->height(); + case Qt::LeftEdge: + return point.x() / d->content->width(); + case Qt::RightEdge: + return (width() - point.x()) / d->content->width(); + case Qt::BottomEdge: + return (height() - point.y()) / d->content->height(); + default: + return 0; + } +} + +QT_END_NAMESPACE diff --git a/src/imports/extras/qquickdrawer_p.h b/src/imports/extras/qquickdrawer_p.h new file mode 100644 index 00000000..2a45f5b1 --- /dev/null +++ b/src/imports/extras/qquickdrawer_p.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 QQUICKDRAWER_P_H +#define QQUICKDRAWER_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 + +QT_BEGIN_NAMESPACE + +class QQuickPropertyAnimation; +class QQuickDrawerPrivate; + +class QQuickDrawer : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(Qt::Edge edge READ edge WRITE setEdge NOTIFY edgeChanged FINAL) + Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL) + Q_PROPERTY(QQuickItem *contentItem READ contentItem WRITE setContentItem NOTIFY contentItemChanged FINAL) + // TODO: make this a proper transition + Q_PROPERTY(QQuickPropertyAnimation *animation READ animation WRITE setAnimation NOTIFY animationChanged FINAL) + Q_CLASSINFO("DefaultProperty", "contentItem") + +public: + explicit QQuickDrawer(QQuickItem *parent = Q_NULLPTR); + + Qt::Edge edge() const; + void setEdge(Qt::Edge edge); + + qreal position() const; + void setPosition(qreal position); + + QQuickItem *contentItem() const; + void setContentItem(QQuickItem *item); + + QQuickPropertyAnimation *animation() const; + void setAnimation(QQuickPropertyAnimation *animation); + +public Q_SLOTS: + void open(); + void close(); + +Q_SIGNALS: + void clicked(); + void edgeChanged(); + void positionChanged(); + void contentItemChanged(); + void animationChanged(); + +protected: + bool childMouseEventFilter(QQuickItem *child, QEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mouseUngrabEvent() Q_DECL_OVERRIDE; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + + virtual qreal positionAt(const QPointF &point) const; + +private: + Q_DISABLE_COPY(QQuickDrawer) + Q_DECLARE_PRIVATE(QQuickDrawer) +}; + +Q_DECLARE_TYPEINFO(QQuickDrawer, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKDRAWER_P_H diff --git a/src/imports/extras/qquickswipeview.cpp b/src/imports/extras/qquickswipeview.cpp new file mode 100644 index 00000000..c359a983 --- /dev/null +++ b/src/imports/extras/qquickswipeview.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 "qquickswipeview_p.h" + +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype SwipeView + \inherits Container + \instantiates QQuickSwipeView + \inqmlmodule QtQuick.Extras + \ingroup navigation + \brief A swipe view control. + + TODO +*/ + +class QQuickSwipeViewPrivate : public QQuickContainerPrivate +{ + Q_DECLARE_PUBLIC(QQuickSwipeView) + +public: + QQuickSwipeViewPrivate() : currentIndex(-1), updatingCurrent(false) { } + + void resizeItem(QQuickItem *item); + void resizeItems(); + void _q_updateCurrent(); + + void insertItem(int index, QQuickItem *item) Q_DECL_OVERRIDE; + void moveItem(int from, int to) Q_DECL_OVERRIDE; + void removeItem(int index, QQuickItem *item) Q_DECL_OVERRIDE; + + int currentIndex; + bool updatingCurrent; +}; + +void QQuickSwipeViewPrivate::resizeItems() +{ + Q_Q(QQuickSwipeView); + const int count = q->count(); + for (int i = 0; i < count; ++i) { + QQuickItem *item = itemAt(i); + if (item) + item->setSize(QSizeF(contentItem->width(), contentItem->height())); + } +} + +void QQuickSwipeViewPrivate::_q_updateCurrent() +{ + Q_Q(QQuickSwipeView); + if (!updatingCurrent) + q->setCurrentIndex(contentItem ? contentItem->property("currentIndex").toInt() : -1); +} + +void QQuickSwipeViewPrivate::insertItem(int index, QQuickItem *item) +{ + Q_Q(QQuickSwipeView); + if (q->isComponentComplete()) + item->setSize(QSizeF(contentItem->width(), contentItem->height())); + + QQuickContainerPrivate::insertItem(index, item); + + if (contentModel->count() == 1 && currentIndex == -1) + q->setCurrentIndex(index); +} + +void QQuickSwipeViewPrivate::moveItem(int from, int to) +{ + Q_Q(QQuickSwipeView); + QQuickContainerPrivate::moveItem(from, to); + + updatingCurrent = true; + if (from == currentIndex) + q->setCurrentIndex(to); + else if (from < currentIndex && to >= currentIndex) + q->setCurrentIndex(currentIndex - 1); + else if (from > currentIndex && to <= currentIndex) + q->setCurrentIndex(currentIndex + 1); + updatingCurrent = false; +} + +void QQuickSwipeViewPrivate::removeItem(int index, QQuickItem *item) +{ + Q_Q(QQuickSwipeView); + bool currentChanged = false; + if (index == currentIndex) { + q->setCurrentIndex(currentIndex - 1); + } else if (index < currentIndex) { + --currentIndex; + currentChanged = true; + } + + QQuickContainerPrivate::removeItem(index, item); + + if (currentChanged) + emit q->currentIndexChanged(); +} + +QQuickSwipeView::QQuickSwipeView(QQuickItem *parent) : + QQuickContainer(*(new QQuickSwipeViewPrivate), parent) +{ + setFlag(ItemIsFocusScope); + setActiveFocusOnTab(true); +} + +/*! + \qmlproperty int QtQuickControls2::SwipeView::currentIndex + + TODO +*/ +int QQuickSwipeView::currentIndex() const +{ + Q_D(const QQuickSwipeView); + return d->currentIndex; +} + +void QQuickSwipeView::setCurrentIndex(int index) +{ + Q_D(QQuickSwipeView); + if (d->currentIndex != index) { + d->currentIndex = index; + emit currentIndexChanged(); + emit currentItemChanged(); + } +} + +/*! + \qmlproperty Item QtQuickControls2::SwipeView::currentItem + + TODO +*/ +QQuickItem *QQuickSwipeView::currentItem() const +{ + Q_D(const QQuickSwipeView); + return itemAt(d->currentIndex); +} + +void QQuickSwipeView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickSwipeView); + QQuickContainer::geometryChanged(newGeometry, oldGeometry); + d->resizeItems(); +} + +void QQuickSwipeView::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) +{ + QQuickContainer::contentItemChange(newItem, oldItem); + if (oldItem) + disconnect(oldItem, SIGNAL(currentIndexChanged()), this, SLOT(_q_updateCurrent())); + if (newItem) + connect(newItem, SIGNAL(currentIndexChanged()), this, SLOT(_q_updateCurrent())); +} + +QT_END_NAMESPACE + +#include "moc_qquickswipeview_p.cpp" diff --git a/src/imports/extras/qquickswipeview_p.h b/src/imports/extras/qquickswipeview_p.h new file mode 100644 index 00000000..718eccea --- /dev/null +++ b/src/imports/extras/qquickswipeview_p.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 QQUICKSWIPEVIEW_P_H +#define QQUICKSWIPEVIEW_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 + +QT_BEGIN_NAMESPACE + +class QQuickSwipeViewPrivate; + +class QQuickSwipeView : public QQuickContainer +{ + Q_OBJECT + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) + Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) + +public: + explicit QQuickSwipeView(QQuickItem *parent = Q_NULLPTR); + + int currentIndex() const; + QQuickItem *currentItem() const; + +public Q_SLOTS: + void setCurrentIndex(int index); + +Q_SIGNALS: + void currentIndexChanged(); + void currentItemChanged(); + +protected: + void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE; + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickSwipeView) + Q_DECLARE_PRIVATE(QQuickSwipeView) + + Q_PRIVATE_SLOT(d_func(), void _q_updateCurrent()) +}; + +Q_DECLARE_TYPEINFO(QQuickSwipeView, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +#endif // QQUICKSWIPEVIEW_P_H diff --git a/src/imports/extras/qquicktumbler.cpp b/src/imports/extras/qquicktumbler.cpp new file mode 100644 index 00000000..53a8af8f --- /dev/null +++ b/src/imports/extras/qquicktumbler.cpp @@ -0,0 +1,535 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 "qquicktumbler_p.h" + +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmltype Tumbler + \inherits Control + \instantiates QQuickTumbler + \inqmlmodule QtQuick.Extras + \ingroup containers + \brief A spinnable wheel of items that can be selected. + + \code + Tumbler { + model: 5 + } + \endcode + + \section1 Non-wrapping Tumbler + + The default contentItem of Tumbler is a \l PathView, which wraps when it + reaches the top and bottom. To achieve a non-wrapping Tumbler, use ListView + as the contentItem: + + \snippet tst_tumbler.qml contentItem + + \image qtquickextras2-tumbler-wrap.gif +*/ + +class QQuickTumblerPrivate : public QQuickControlPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickTumbler) + +public: + QQuickTumblerPrivate() : + delegate(Q_NULLPTR), + visibleItemCount(3) + { + } + + ~QQuickTumblerPrivate() + { + } + + QVariant model; + QQmlComponent *delegate; + int visibleItemCount; + + void _q_updateItemHeights(); + void _q_updateItemWidths(); + + void itemChildAdded(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; + void itemChildRemoved(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; +}; + +static QList contentItemChildItems(QQuickItem *contentItem) +{ + if (!contentItem) + return QList(); + + // PathView has no contentItem property, but ListView does. + QQuickFlickable *flickable = qobject_cast(contentItem); + return flickable ? flickable->contentItem()->childItems() : contentItem->childItems(); +} + +namespace { + static inline qreal delegateHeight(const QQuickTumbler *tumbler) + { + return tumbler->availableHeight() / tumbler->visibleItemCount(); + } + + enum ContentItemType { + UnsupportedContentItemType, + PathViewContentItem, + ListViewContentItem + }; + + static inline QQuickItem *actualContentItem(QQuickItem *rootContentItem, ContentItemType contentType) + { + if (contentType == PathViewContentItem) + return rootContentItem; + else if (contentType == ListViewContentItem) + return qobject_cast(rootContentItem)->contentItem(); + + return Q_NULLPTR; + } + + static inline ContentItemType contentItemType(QQuickItem *rootContentItem) + { + if (rootContentItem->inherits("QQuickPathView")) + return PathViewContentItem; + else if (rootContentItem->inherits("QQuickListView")) + return ListViewContentItem; + + return UnsupportedContentItemType; + } + + static inline ContentItemType contentItemTypeFromDelegate(QQuickItem *delegateItem) + { + if (delegateItem->parentItem()->inherits("QQuickPathView")) { + return PathViewContentItem; + } else if (delegateItem->parentItem()->parentItem() + && delegateItem->parentItem()->parentItem()->inherits("QQuickListView")) { + return ListViewContentItem; + } + + return UnsupportedContentItemType; + } +} + +void QQuickTumblerPrivate::_q_updateItemHeights() +{ + // Can't use our own private padding members here, as the padding property might be set, + // which doesn't affect them, only their getters. + Q_Q(const QQuickTumbler); + const qreal itemHeight = delegateHeight(q); + foreach (QQuickItem *childItem, contentItemChildItems(contentItem)) + childItem->setHeight(itemHeight); +} + +void QQuickTumblerPrivate::_q_updateItemWidths() +{ + Q_Q(const QQuickTumbler); + const qreal availableWidth = q->availableWidth(); + foreach (QQuickItem *childItem, contentItemChildItems(contentItem)) + childItem->setWidth(availableWidth); +} + +void QQuickTumblerPrivate::itemChildAdded(QQuickItem *, QQuickItem *) +{ + _q_updateItemWidths(); + _q_updateItemHeights(); +} + +void QQuickTumblerPrivate::itemChildRemoved(QQuickItem *, QQuickItem *) +{ + _q_updateItemWidths(); + _q_updateItemHeights(); +} + +QQuickTumbler::QQuickTumbler(QQuickItem *parent) : + QQuickControl(*(new QQuickTumblerPrivate), parent) +{ + setActiveFocusOnTab(true); + + connect(this, SIGNAL(leftPaddingChanged()), this, SLOT(_q_updateItemWidths())); + connect(this, SIGNAL(rightPaddingChanged()), this, SLOT(_q_updateItemWidths())); + connect(this, SIGNAL(topPaddingChanged()), this, SLOT(_q_updateItemHeights())); + connect(this, SIGNAL(bottomPaddingChanged()), this, SLOT(_q_updateItemHeights())); +} + +QQuickTumbler::~QQuickTumbler() +{ +} + +/*! + \qmlproperty variant QtQuickExtras2::Tumbler::model + + This property holds the model that provides data for this tumbler. +*/ +QVariant QQuickTumbler::model() const +{ + Q_D(const QQuickTumbler); + return d->model; +} + +void QQuickTumbler::setModel(const QVariant &model) +{ + Q_D(QQuickTumbler); + if (model != d->model) { + d->model = model; + emit modelChanged(); + } +} + +/*! + \qmlproperty int QtQuickExtras2::Tumbler::count + + This property holds the number of items in the model. +*/ +int QQuickTumbler::count() const +{ + Q_D(const QQuickTumbler); + return d->contentItem->property("count").toInt(); +} + +/*! + \qmlproperty int QtQuickExtras2::Tumbler::currentIndex + + This property holds the index of the current item. +*/ +int QQuickTumbler::currentIndex() const +{ + Q_D(const QQuickTumbler); + return d->contentItem ? d->contentItem->property("currentIndex").toInt() : -1; +} + +void QQuickTumbler::setCurrentIndex(int currentIndex) +{ + Q_D(QQuickTumbler); + d->contentItem->setProperty("currentIndex", currentIndex); +} + +/*! + \qmlproperty Item QtQuickExtras2::Tumbler::currentItem + + This property holds the item at the current index. +*/ +QQuickItem *QQuickTumbler::currentItem() const +{ + Q_D(const QQuickTumbler); + return d->contentItem ? d->contentItem->property("currentItem").value() : Q_NULLPTR; +} + +/*! + \qmlproperty component QtQuickExtras2::Tumbler::delegate + + This property holds the delegate used to display each item. +*/ +QQmlComponent *QQuickTumbler::delegate() const +{ + Q_D(const QQuickTumbler); + return d->delegate; +} + +void QQuickTumbler::setDelegate(QQmlComponent *delegate) +{ + Q_D(QQuickTumbler); + if (delegate != d->delegate) { + d->delegate = delegate; + emit delegateChanged(); + } +} + +/*! + \qmlproperty int QtQuickExtras2::Tumbler::visibleItemCount + + This property holds the number of items visible in the tumbler. It must be + an odd number, as the current item is always vertically centered. +*/ +int QQuickTumbler::visibleItemCount() const +{ + Q_D(const QQuickTumbler); + return d->visibleItemCount; +} + +void QQuickTumbler::setVisibleItemCount(int visibleItemCount) +{ + Q_D(QQuickTumbler); + if (visibleItemCount != d->visibleItemCount) { + d->visibleItemCount = visibleItemCount; + d->_q_updateItemHeights(); + emit visibleItemCountChanged(); + } +} + +QQuickTumblerAttached *QQuickTumbler::qmlAttachedProperties(QObject *object) +{ + QQuickItem *delegateItem = qobject_cast(object); + if (!delegateItem) { + qWarning() << "Tumbler: attached properties of Tumbler must be accessed from within a delegate item"; + return Q_NULLPTR; + } + + return new QQuickTumblerAttached(delegateItem); +} + +void QQuickTumbler::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_D(QQuickTumbler); + + QQuickControl::geometryChanged(newGeometry, oldGeometry); + + d->_q_updateItemHeights(); + + if (newGeometry.width() != oldGeometry.width()) + d->_q_updateItemWidths(); +} + +void QQuickTumbler::componentComplete() +{ + Q_D(QQuickTumbler); + QQuickControl::componentComplete(); + d->_q_updateItemHeights(); + d->_q_updateItemWidths(); +} + +void QQuickTumbler::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) +{ + Q_D(QQuickTumbler); + + QQuickControl::contentItemChange(newItem, oldItem); + + // Since we use the currentIndex of the contentItem directly, we must + // ensure that we keep track of the currentIndex so it doesn't get lost + // between contentItem changes. + const int previousCurrentIndex = currentIndex(); + + if (oldItem) { + disconnect(oldItem, SIGNAL(currentIndexChanged()), this, SIGNAL(currentIndexChanged())); + disconnect(oldItem, SIGNAL(currentItemChanged()), this, SIGNAL(currentItemChanged())); + disconnect(oldItem, SIGNAL(countChanged()), this, SIGNAL(countChanged())); + + ContentItemType oldContentItemType = contentItemType(oldItem); + QQuickItem *actualOldContentItem = actualContentItem(oldItem, oldContentItemType); + QQuickItemPrivate *actualContentItemPrivate = QQuickItemPrivate::get(actualOldContentItem); + actualContentItemPrivate->removeItemChangeListener(d, QQuickItemPrivate::Children); + } + + if (newItem) { + ContentItemType contentType = contentItemType(newItem); + if (contentType == UnsupportedContentItemType) { + qWarning() << "Tumbler: contentItems other than PathView and ListView are not supported"; + return; + } + + connect(newItem, SIGNAL(currentIndexChanged()), this, SIGNAL(currentIndexChanged())); + connect(newItem, SIGNAL(currentItemChanged()), this, SIGNAL(currentItemChanged())); + connect(newItem, SIGNAL(countChanged()), this, SIGNAL(countChanged())); + + QQuickItem *actualNewContentItem = actualContentItem(newItem, contentType); + QQuickItemPrivate *actualContentItemPrivate = QQuickItemPrivate::get(actualNewContentItem); + actualContentItemPrivate->addItemChangeListener(d, QQuickItemPrivate::Children); + + // If the previous currentIndex is -1, it means we had no contentItem previously. + if (previousCurrentIndex != -1) { + // Can't call setCurrentIndex here, as contentItemChange() is + // called *before* the contentItem is set. + newItem->setProperty("currentIndex", previousCurrentIndex); + } + } +} + +void QQuickTumbler::keyPressEvent(QKeyEvent *event) +{ + Q_D(QQuickTumbler); + + QQuickControl::keyPressEvent(event); + + if (event->isAutoRepeat()) + return; + + if (event->key() == Qt::Key_Up) { + QMetaObject::invokeMethod(d->contentItem, "decrementCurrentIndex"); + } else if (event->key() == Qt::Key_Down) { + QMetaObject::invokeMethod(d->contentItem, "incrementCurrentIndex"); + } +} + +class QQuickTumblerAttachedPrivate : public QObjectPrivate, public QQuickItemChangeListener +{ + Q_DECLARE_PUBLIC(QQuickTumblerAttached) +public: + QQuickTumblerAttachedPrivate(QQuickItem *delegateItem) : + tumbler(Q_NULLPTR), + index(-1), + displacement(1) + { + if (!delegateItem->parentItem()) { + qWarning() << "Tumbler: attached properties must be accessed from within a delegate item that has a parent"; + return; + } + + QVariant indexContextProperty = qmlContext(delegateItem)->contextProperty(QStringLiteral("index")); + if (!indexContextProperty.isValid()) { + qWarning() << "Tumbler: attempting to access attached property on item without an \"index\" property"; + return; + } + + index = indexContextProperty.toInt(); + const ContentItemType contentItemType = contentItemTypeFromDelegate(delegateItem); + if (contentItemType == UnsupportedContentItemType) + return; + + // ListView has an "additional" content item. + tumbler = qobject_cast(contentItemType == PathViewContentItem + ? delegateItem->parentItem()->parentItem() : delegateItem->parentItem()->parentItem()->parentItem()); + Q_ASSERT(tumbler); + } + + ~QQuickTumblerAttachedPrivate() { + } + + void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void itemChildAdded(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; + void itemChildRemoved(QQuickItem *, QQuickItem *) Q_DECL_OVERRIDE; + + void _q_calculateDisplacement(); + + // The Tumbler that contains the delegate. Required to calculated the displacement. + QQuickTumbler *tumbler; + // The index of the delegate. Used to calculate the displacement. + int index; + // The displacement for our delegate. + qreal displacement; +}; + +void QQuickTumblerAttachedPrivate::itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &) +{ + _q_calculateDisplacement(); +} + +void QQuickTumblerAttachedPrivate::itemChildAdded(QQuickItem *, QQuickItem *) +{ + _q_calculateDisplacement(); +} + +void QQuickTumblerAttachedPrivate::itemChildRemoved(QQuickItem *item, QQuickItem *child) +{ + _q_calculateDisplacement(); + + if (parent == child) { + // The child that was removed from the contentItem was the delegate + // that our properties are attached to. If we don't remove the change + // listener, the contentItem will attempt to notify a destroyed + // listener, causing a crash. + + // item is the "actual content item" of Tumbler's contentItem, i.e. a PathView or ListView.contentItem + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + p->removeItemChangeListener(this, QQuickItemPrivate::Geometry | QQuickItemPrivate::Children); + } +} + +void QQuickTumblerAttachedPrivate::_q_calculateDisplacement() +{ + const int previousDisplacement = displacement; + displacement = 0; + + // This can happen in tests, so it may happen in normal usage too. + if (tumbler->count() == 0) + return; + + ContentItemType contentType = contentItemType(tumbler->contentItem()); + if (contentType == UnsupportedContentItemType) + return; + + qreal offset = 0; + + if (contentType == PathViewContentItem) { + offset = tumbler->contentItem()->property("offset").toReal(); + + displacement = tumbler->count() - index - offset; + int halfVisibleItems = tumbler->visibleItemCount() / 2 + 1; + if (displacement > halfVisibleItems) + displacement -= tumbler->count(); + else if (displacement < -halfVisibleItems) + displacement += tumbler->count(); + } else { + const qreal contentY = tumbler->contentItem()->property("contentY").toReal(); + const qreal delegateH = delegateHeight(tumbler); + const qreal preferredHighlightBegin = tumbler->contentItem()->property("preferredHighlightBegin").toReal(); + // Tumbler's displacement goes from negative at the top to positive towards the bottom, so we must switch this around. + const qreal reverseDisplacement = (contentY + preferredHighlightBegin) / delegateH; + displacement = reverseDisplacement - index; + } + + Q_Q(QQuickTumblerAttached); + if (displacement != previousDisplacement) + emit q->displacementChanged(); +} + +QQuickTumblerAttached::QQuickTumblerAttached(QQuickItem *delegateItem) : + QObject(*(new QQuickTumblerAttachedPrivate(delegateItem)), delegateItem) +{ + Q_D(QQuickTumblerAttached); + if (d->tumbler) { + QQuickItem *rootContentItem = d->tumbler->contentItem(); + const ContentItemType contentType = contentItemType(rootContentItem); + QQuickItemPrivate *p = QQuickItemPrivate::get(actualContentItem(rootContentItem, contentType)); + p->addItemChangeListener(d, QQuickItemPrivate::Geometry | QQuickItemPrivate::Children); + + const char *contentItemSignal = contentType == PathViewContentItem + ? SIGNAL(offsetChanged()) : SIGNAL(contentYChanged()); + connect(d->tumbler->contentItem(), contentItemSignal, this, SLOT(_q_calculateDisplacement())); + } +} + +QQuickTumblerAttached::~QQuickTumblerAttached() +{ +} + +QQuickTumbler *QQuickTumblerAttached::tumbler() const +{ + Q_D(const QQuickTumblerAttached); + return d->tumbler; +} + +qreal QQuickTumblerAttached::displacement() const +{ + Q_D(const QQuickTumblerAttached); + return d->displacement; +} + +QT_END_NAMESPACE + +#include "moc_qquicktumbler_p.cpp" diff --git a/src/imports/extras/qquicktumbler_p.h b/src/imports/extras/qquicktumbler_p.h new file mode 100644 index 00000000..bda2a020 --- /dev/null +++ b/src/imports/extras/qquicktumbler_p.h @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Extras 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 QQUICKTUMBLER_H +#define QQUICKTUMBLER_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 +#include +#include + +QT_BEGIN_NAMESPACE + +class QQuickTumblerAttached; +class QQuickTumblerPrivate; + +class QQuickTumbler : public QQuickControl +{ + Q_OBJECT + Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL) + Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) + Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) + Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) + Q_PROPERTY(int visibleItemCount READ visibleItemCount WRITE setVisibleItemCount NOTIFY visibleItemCountChanged FINAL) + +public: + explicit QQuickTumbler(QQuickItem *parent = Q_NULLPTR); + ~QQuickTumbler(); + + QVariant model() const; + void setModel(const QVariant &model); + + int count() const; + + int currentIndex() const; + void setCurrentIndex(int currentIndex); + QQuickItem *currentItem() const; + + QQmlComponent *delegate() const; + void setDelegate(QQmlComponent *delegate); + + int visibleItemCount() const; + void setVisibleItemCount(int visibleItemCount); + + static QQuickTumblerAttached *qmlAttachedProperties(QObject *object); + +Q_SIGNALS: + void modelChanged(); + void countChanged(); + void currentIndexChanged(); + void currentItemChanged(); + void delegateChanged(); + void visibleItemCountChanged(); + +protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; + void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(QQuickTumbler) + Q_DECLARE_PRIVATE(QQuickTumbler) + + Q_PRIVATE_SLOT(d_func(), void _q_updateItemWidths()) + Q_PRIVATE_SLOT(d_func(), void _q_updateItemHeights()) +}; + +Q_DECLARE_TYPEINFO(QQuickTumbler, Q_COMPLEX_TYPE); + +class QQuickTumblerAttachedPrivate; + +class QQuickTumblerAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickTumbler *tumbler READ tumbler CONSTANT) + Q_PROPERTY(qreal displacement READ displacement NOTIFY displacementChanged FINAL) + +public: + explicit QQuickTumblerAttached(QQuickItem *delegateItem); + ~QQuickTumblerAttached(); + + QQuickTumbler *tumbler() const; + qreal displacement() const; + +Q_SIGNALS: + void displacementChanged(); + +private: + Q_DISABLE_COPY(QQuickTumblerAttached) + Q_DECLARE_PRIVATE(QQuickTumblerAttached) + + Q_PRIVATE_SLOT(d_func(), void _q_calculateDisplacement()) +}; + +Q_DECLARE_TYPEINFO(QQuickTumblerAttached, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickTumbler, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQUICKTUMBLER_H diff --git a/src/imports/extras/qtquickextras2plugin.cpp b/src/imports/extras/qtquickextras2plugin.cpp index a17ae159..8b1ebb50 100644 --- a/src/imports/extras/qtquickextras2plugin.cpp +++ b/src/imports/extras/qtquickextras2plugin.cpp @@ -36,10 +36,10 @@ #include -#include -#include -#include -#include +#include "qquickdial_p.h" +#include "qquickdrawer_p.h" +#include "qquickswipeview_p.h" +#include "qquicktumbler_p.h" QT_BEGIN_NAMESPACE diff --git a/src/src.pro b/src/src.pro index cc6f0111..ff2ae30b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,8 +1,6 @@ TEMPLATE = subdirs SUBDIRS += \ controls \ - extras \ imports -extras.depends = controls -imports.depends = controls extras +imports.depends = controls -- cgit v1.2.3