From 1c0edf002a50a765a66349d733cf170f4a4024ef Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 30 Mar 2015 09:45:44 +0200 Subject: Remove SpinBox SpinBox is a desktop centric control. It won't be provided in Qt Quick Controls 2.0, but maybe later when desktop support is re-considered. Qt Quick Controls 2.0 will focus on embedded and mobile. SpinBox is still available in 1.x Change-Id: I272b030734bad58de7e5b26c522189e0c520fca5 Reviewed-by: Jari-Pekka Nurmi --- src/controls/controls.pri | 2 - src/controls/qquickabstractspinbox.cpp | 300 ------------------------ src/controls/qquickabstractspinbox_p.h | 130 ---------- src/imports/controls/SpinBox.qml | 132 ----------- src/imports/controls/controls.pro | 1 - src/imports/controls/qmldir | 1 - src/imports/controls/qtquickcontrols2plugin.cpp | 2 - tests/benchmarks/creation/tst_creation.cpp | 1 - tests/benchmarks/objects/tst_objects.cpp | 4 - 9 files changed, 573 deletions(-) delete mode 100644 src/controls/qquickabstractspinbox.cpp delete mode 100644 src/controls/qquickabstractspinbox_p.h delete mode 100644 src/imports/controls/SpinBox.qml diff --git a/src/controls/controls.pri b/src/controls/controls.pri index b613b9e7..b1d2a0ea 100644 --- a/src/controls/controls.pri +++ b/src/controls/controls.pri @@ -19,7 +19,6 @@ HEADERS += \ $$PWD/qquickabstractscrollbar_p.h \ $$PWD/qquickabstractscrollindicator_p.h \ $$PWD/qquickabstractslider_p.h \ - $$PWD/qquickabstractspinbox_p.h \ $$PWD/qquickabstractstackview_p.h \ $$PWD/qquickabstractswitch_p.h \ $$PWD/qquickabstracttabbar_p.h \ @@ -49,7 +48,6 @@ SOURCES += \ $$PWD/qquickabstractscrollbar.cpp \ $$PWD/qquickabstractscrollindicator.cpp \ $$PWD/qquickabstractslider.cpp \ - $$PWD/qquickabstractspinbox.cpp \ $$PWD/qquickabstractstackview.cpp \ $$PWD/qquickabstractswitch.cpp \ $$PWD/qquickabstracttabbar.cpp \ diff --git a/src/controls/qquickabstractspinbox.cpp b/src/controls/qquickabstractspinbox.cpp deleted file mode 100644 index 442e479c..00000000 --- a/src/controls/qquickabstractspinbox.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 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 "qquickabstractspinbox_p.h" -#include "qquickcontrol_p_p.h" - -#include - -QT_BEGIN_NAMESPACE - -class QQuickAbstractSpinBoxPrivate : public QQuickControlPrivate -{ - Q_DECLARE_PUBLIC(QQuickAbstractSpinBox) - -public: - QQuickAbstractSpinBoxPrivate() : value(0), step(1), input(Q_NULLPTR), validator(Q_NULLPTR), - upButton(Q_NULLPTR), downButton(Q_NULLPTR), pressed(QQuickAbstractSpinBox::None) { } - - void updateText(); - void updateValue(); - - qreal value; - qreal step; - QQuickTextInput *input; - QValidator *validator; - QQuickItem *upButton; - QQuickItem *downButton; - QQuickAbstractSpinBox::SubControl pressed; -}; - -void QQuickAbstractSpinBoxPrivate::updateText() -{ - if (input) { - QString text = QString::number(value); - if (validator) { - validator->fixup(text); - int cursor = input->cursorPosition(); - if (validator->validate(text, cursor) == QValidator::Acceptable) - input->setCursorPosition(cursor); - input->setText(text); - } - } -} - -void QQuickAbstractSpinBoxPrivate::updateValue() -{ - Q_Q(QQuickAbstractSpinBox); - if (validator) { - QString text = input->text(); - validator->fixup(text); - int cursor = input->cursorPosition(); - if (validator->validate(text, cursor) == QValidator::Acceptable) - q->setValue(text.toDouble()); - } -} - -QQuickAbstractSpinBox::QQuickAbstractSpinBox(QQuickItem *parent) : - QQuickControl(*(new QQuickAbstractSpinBoxPrivate), parent) -{ - setFlag(ItemIsFocusScope); - setActiveFocusOnTab(true); - setAcceptedMouseButtons(Qt::LeftButton); -} - -qreal QQuickAbstractSpinBox::value() const -{ - Q_D(const QQuickAbstractSpinBox); - return d->value; -} - -void QQuickAbstractSpinBox::setValue(qreal value) -{ - Q_D(QQuickAbstractSpinBox); - if (!qFuzzyCompare(d->value, value)) { - d->value = value; - d->updateText(); - emit valueChanged(); - } -} - -qreal QQuickAbstractSpinBox::step() const -{ - Q_D(const QQuickAbstractSpinBox); - return d->step; -} - -void QQuickAbstractSpinBox::setStep(qreal step) -{ - Q_D(QQuickAbstractSpinBox); - if (!qFuzzyCompare(d->step, step)) { - d->step = step; - emit stepChanged(); - } -} - -QQuickTextInput *QQuickAbstractSpinBox::input() const -{ - Q_D(const QQuickAbstractSpinBox); - return d->input; -} - -void QQuickAbstractSpinBox::setInput(QQuickTextInput *input) -{ - Q_D(QQuickAbstractSpinBox); - if (d->input != input) { - delete d->input; - d->input = input; - if (input) { - if (!input->parentItem()) - input->setParentItem(this); - input->setValidator(d->validator); - input->setFocus(true); - QObjectPrivate::connect(input, &QQuickTextInput::textChanged, d, &QQuickAbstractSpinBoxPrivate::updateValue); - } - emit inputChanged(); - } -} - -QValidator *QQuickAbstractSpinBox::validator() const -{ - Q_D(const QQuickAbstractSpinBox); - return d->validator; -} - -void QQuickAbstractSpinBox::setValidator(QValidator *validator) -{ - Q_D(QQuickAbstractSpinBox); - if (d->validator != validator) { - delete d->validator; - d->validator = validator; - if (d->input) - d->input->setValidator(validator); - emit validatorChanged(); - } -} - -QQuickItem *QQuickAbstractSpinBox::upButton() const -{ - Q_D(const QQuickAbstractSpinBox); - return d->upButton; -} - -void QQuickAbstractSpinBox::setUpButton(QQuickItem *button) -{ - Q_D(QQuickAbstractSpinBox); - if (d->upButton != button) { - delete d->upButton; - d->upButton = button; - if (button && !button->parentItem()) - button->setParentItem(this); - emit upButtonChanged(); - } -} - -QQuickItem *QQuickAbstractSpinBox::downButton() const -{ - Q_D(const QQuickAbstractSpinBox); - return d->downButton; -} - -void QQuickAbstractSpinBox::setDownButton(QQuickItem *button) -{ - Q_D(QQuickAbstractSpinBox); - if (d->downButton != button) { - delete d->downButton; - d->downButton = button; - if (button && !button->parentItem()) - button->setParentItem(this); - emit downButtonChanged(); - } -} - -QQuickAbstractSpinBox::SubControl QQuickAbstractSpinBox::pressed() const -{ - Q_D(const QQuickAbstractSpinBox); - return d->pressed; -} - -void QQuickAbstractSpinBox::setPressed(SubControl control) -{ - Q_D(QQuickAbstractSpinBox); - if (d->pressed != control) { - d->pressed = control; - emit pressedChanged(); - } -} - -void QQuickAbstractSpinBox::increment() -{ - Q_D(QQuickAbstractSpinBox); - setValue(d->value + d->step); -} - -void QQuickAbstractSpinBox::decrement() -{ - Q_D(QQuickAbstractSpinBox); - setValue(d->value - d->step); -} - -void QQuickAbstractSpinBox::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - case Qt::Key_Up: - increment(); - event->accept(); - break; - case Qt::Key_Down: - decrement(); - event->accept(); - break; - default: - event->ignore(); - break; - } -} - -void QQuickAbstractSpinBox::mousePressEvent(QMouseEvent *event) -{ - Q_D(QQuickAbstractSpinBox); - QQuickControl::mousePressEvent(event); - if (d->upButton && d->upButton->contains(mapToItem(d->upButton, event->pos()))) - setPressed(UpButton); - else if (d->downButton && d->downButton->contains(mapToItem(d->downButton, event->pos()))) - setPressed(DownButton); - else - setPressed(None); - event->accept(); -} - -void QQuickAbstractSpinBox::mouseMoveEvent(QMouseEvent *event) -{ - Q_D(QQuickAbstractSpinBox); - QQuickControl::mouseMoveEvent(event); - if (d->upButton && d->upButton->contains(mapToItem(d->upButton, event->pos()))) - setPressed(UpButton); - else if (d->downButton && d->downButton->contains(mapToItem(d->downButton, event->pos()))) - setPressed(DownButton); - else - setPressed(None); - event->accept(); -} - -void QQuickAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event) -{ - Q_D(QQuickAbstractSpinBox); - QQuickControl::mouseReleaseEvent(event); - if (d->pressed == UpButton) - increment(); - else if (d->pressed == DownButton) - decrement(); - setPressed(None); - event->accept(); -} - -void QQuickAbstractSpinBox::mouseUngrabEvent() -{ - setPressed(None); -} - -void QQuickAbstractSpinBox::componentComplete() -{ - Q_D(QQuickAbstractSpinBox); - QQuickControl::componentComplete(); - d->updateText(); -} - -QT_END_NAMESPACE diff --git a/src/controls/qquickabstractspinbox_p.h b/src/controls/qquickabstractspinbox_p.h deleted file mode 100644 index aac81eaa..00000000 --- a/src/controls/qquickabstractspinbox_p.h +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 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 QQUICKABSTRACTSPINBOX_P_H -#define QQUICKABSTRACTSPINBOX_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 QValidator; -class QQuickTextInput; -class QQuickAbstractSpinBoxPrivate; - -class Q_QUICKCONTROLS_EXPORT QQuickAbstractSpinBox : public QQuickControl -{ - Q_OBJECT - Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged FINAL) - Q_PROPERTY(qreal step READ step WRITE setStep NOTIFY stepChanged FINAL) - Q_PROPERTY(QQuickTextInput *input READ input WRITE setInput NOTIFY inputChanged FINAL) - Q_PROPERTY(QValidator *validator READ validator WRITE setValidator NOTIFY validatorChanged FINAL) - Q_PROPERTY(QQuickItem *upButton READ upButton WRITE setUpButton NOTIFY upButtonChanged FINAL) - Q_PROPERTY(QQuickItem *downButton READ downButton WRITE setDownButton NOTIFY downButtonChanged FINAL) - Q_PROPERTY(SubControl pressed READ pressed WRITE setPressed NOTIFY pressedChanged FINAL) - -public: - explicit QQuickAbstractSpinBox(QQuickItem *parent = Q_NULLPTR); - - qreal value() const; - void setValue(qreal value); - - qreal step() const; - void setStep(qreal step); - - QQuickTextInput *input() const; - void setInput(QQuickTextInput *input); - - QValidator *validator() const; - void setValidator(QValidator *validator); - - QQuickItem *upButton() const; - void setUpButton(QQuickItem *button); - - QQuickItem *downButton() const; - void setDownButton(QQuickItem *button); - - enum SubControl { - None, - UpButton, - DownButton - }; - Q_ENUM(SubControl) - - SubControl pressed() const; - void setPressed(SubControl control); - -public Q_SLOTS: - void increment(); - void decrement(); - -Q_SIGNALS: - void valueChanged(); - void stepChanged(); - void inputChanged(); - void validatorChanged(); - void upButtonChanged(); - void downButtonChanged(); - void pressedChanged(); - -protected: - void keyPressEvent(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 componentComplete() Q_DECL_OVERRIDE; - -private: - Q_DISABLE_COPY(QQuickAbstractSpinBox) - Q_DECLARE_PRIVATE(QQuickAbstractSpinBox) -}; - -QT_END_NAMESPACE - -#endif // QQUICKABSTRACTSPINBOX_P_H diff --git a/src/imports/controls/SpinBox.qml b/src/imports/controls/SpinBox.qml deleted file mode 100644 index 06b5629e..00000000 --- a/src/imports/controls/SpinBox.qml +++ /dev/null @@ -1,132 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Controls 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$ -** -****************************************************************************/ - -import QtQuick 2.6 -import QtQuick.Controls 2.0 - -AbstractSpinBox { - id: control - - implicitWidth: Math.max(background ? background.implicitWidth : 0, - (upButton ? upButton.implicitWidth : 0) + - (downButton ? downButton.implicitWidth : 0) + - (input ? input.implicitWidth : 0) + Style.padding * 2) - implicitHeight: Math.max(background ? background.implicitHeight : 0, - (upButton ? upButton.implicitHeight : 0), - (downButton ? downButton.implicitHeight : 0), - (input ? input.implicitHeight : 0) + Style.padding * 2) - - Accessible.role: Accessible.SpinBox - - input: TextInput { - x: upButton.width - width: parent.width - upButton.width - downButton.width - height: parent.height - - color: control.Style.textColor - selectionColor: control.Style.selectionColor - selectedTextColor: control.Style.selectedTextColor - horizontalAlignment: Qt.AlignHCenter - verticalAlignment: Qt.AlignVCenter - Keys.forwardTo: control - } - - validator: IntValidator { } - - upButton: Item { - implicitWidth: 26 - height: parent.height - x: parent.width - width - - opacity: enabled ? 1.0 : control.Style.disabledOpacity - clip: true - Rectangle { - x: -radius - width: parent.width + radius - height: parent.height - radius: control.Style.roundness - color: Qt.tint(Qt.tint(control.Style.accentColor, - control.activeFocus ? control.Style.focusColor : "transparent"), - pressed === AbstractSpinBox.UpButton ? control.Style.pressColor : "transparent") - } - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: parent.width / 3 - height: 2 - color: control.Style.selectedTextColor - } - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: 2 - height: parent.height / 3 - color: control.Style.selectedTextColor - } - } - - downButton: Item { - implicitWidth: 26 - height: parent.height - - opacity: enabled ? 1.0 : control.Style.disabledOpacity - clip: true - Rectangle { - width: parent.width + radius - height: parent.height - radius: control.Style.roundness - color: Qt.tint(Qt.tint(control.Style.accentColor, - control.activeFocus ? control.Style.focusColor : "transparent"), - pressed === AbstractSpinBox.DownButton ? control.Style.pressColor : "transparent") - } - Rectangle { - x: (parent.width - width) / 2 - y: (parent.height - height) / 2 - width: parent.width / 3 - height: 2 - color: control.Style.selectedTextColor - } - } - - background: Rectangle { - implicitWidth: 120 - radius: control.Style.roundness - border.width: control.activeFocus ? 2 : 1 - border.color: control.activeFocus ? control.Style.focusColor : control.Style.frameColor - opacity: enabled ? 1.0 : control.Style.disabledOpacity - color: input.acceptableInput ? "white" : "lightpink" - } -} diff --git a/src/imports/controls/controls.pro b/src/imports/controls/controls.pro index 98472d9f..06a947dd 100644 --- a/src/imports/controls/controls.pro +++ b/src/imports/controls/controls.pro @@ -22,7 +22,6 @@ QML_FILES = \ ScrollBar.qml \ ScrollIndicator.qml \ Slider.qml \ - SpinBox.qml \ StackView.js \ StackView.qml \ StackViewDelegate.qml \ diff --git a/src/imports/controls/qmldir b/src/imports/controls/qmldir index fcd8700d..b54df22c 100644 --- a/src/imports/controls/qmldir +++ b/src/imports/controls/qmldir @@ -14,7 +14,6 @@ RadioButton 2.0 RadioButton.qml ScrollBar 2.0 ScrollBar.qml ScrollIndicator 2.0 ScrollIndicator.qml Slider 2.0 Slider.qml -SpinBox 2.0 SpinBox.qml StackView 2.0 StackView.qml StackViewDelegate 2.0 StackViewDelegate.qml StackViewTransition 2.0 StackViewTransition.qml diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp index 22622c9f..9f232c55 100644 --- a/src/imports/controls/qtquickcontrols2plugin.cpp +++ b/src/imports/controls/qtquickcontrols2plugin.cpp @@ -50,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -96,7 +95,6 @@ void QtQuickControls2Plugin::registerTypes(const char *uri) qmlRegisterType(uri, 2, 0, "AbstractScrollBar"); qmlRegisterType(uri, 2, 0, "AbstractScrollIndicator"); qmlRegisterType(uri, 2, 0, "AbstractSlider"); - qmlRegisterType(uri, 2, 0, "AbstractSpinBox"); qmlRegisterType(uri, 2, 0, "AbstractStackView"); qmlRegisterType(uri, 2, 0, "AbstractSwitch"); qmlRegisterType(uri, 2, 0, "AbstractTabBar"); diff --git a/tests/benchmarks/creation/tst_creation.cpp b/tests/benchmarks/creation/tst_creation.cpp index 3fbbf3c3..0f542ab9 100644 --- a/tests/benchmarks/creation/tst_creation.cpp +++ b/tests/benchmarks/creation/tst_creation.cpp @@ -105,7 +105,6 @@ void tst_Creation::testControls_data() QTest::newRow("ScrollIndicator") << QByteArray("ScrollIndicator"); #endif QTest::newRow("Slider") << QByteArray("Slider"); - QTest::newRow("SpinBox") << QByteArray("SpinBox"); QTest::newRow("Switch") << QByteArray("Switch"); #ifndef QT_QUICK_CONTROLS_V1 QTest::newRow("TabBar") << QByteArray("TabBar"); diff --git a/tests/benchmarks/objects/tst_objects.cpp b/tests/benchmarks/objects/tst_objects.cpp index b798cc01..96f97bd9 100644 --- a/tests/benchmarks/objects/tst_objects.cpp +++ b/tests/benchmarks/objects/tst_objects.cpp @@ -185,10 +185,6 @@ void tst_Objects::testCount_data() << QByteArray("import QtQuick.Controls 1.3; Slider { }") << QByteArray("import QtQuick.Controls 2.0; Slider { }"); - QTest::newRow("SpinBox") - << QByteArray("import QtQuick.Controls 1.3; SpinBox { }") - << QByteArray("import QtQuick.Controls 2.0; SpinBox { }"); - QTest::newRow("StackView") << QByteArray("import QtQuick.Controls 1.3; StackView { }") << QByteArray("import QtQuick.Controls 2.0; StackView { }"); -- cgit v1.2.3