diff options
Diffstat (limited to 'src/widgets/widgets/qabstractslider.cpp')
-rw-r--r-- | src/widgets/widgets/qabstractslider.cpp | 93 |
1 files changed, 31 insertions, 62 deletions
diff --git a/src/widgets/widgets/qabstractslider.cpp b/src/widgets/widgets/qabstractslider.cpp index 2172ebc99c..4e65fbac88 100644 --- a/src/widgets/widgets/qabstractslider.cpp +++ b/src/widgets/widgets/qabstractslider.cpp @@ -1,52 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <qapplication.h> #include "qabstractslider.h" #include "qevent.h" #include "qabstractslider_p.h" #include "qdebug.h" -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) #include "qaccessible.h" #endif #include <limits.h> +#include <private/qapplication_p.h> + QT_BEGIN_NAMESPACE /*! @@ -105,7 +71,7 @@ QT_BEGIN_NAMESPACE \row \li \l sliderReleased() \li the user releases the slider. \row \li \l actionTriggered() - \li a slider action was triggerd. + \li a slider action was triggered. \row \li \l rangeChanged() \li a the range has changed. \endtable @@ -271,13 +237,13 @@ void QAbstractSliderPrivate::setSteps(int single, int page) \l value of 0. */ QAbstractSlider::QAbstractSlider(QWidget *parent) - :QWidget(*new QAbstractSliderPrivate, parent, 0) + :QWidget(*new QAbstractSliderPrivate, parent, { }) { } /*! \internal */ QAbstractSlider::QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent) - :QWidget(dd, parent, 0) + :QWidget(dd, parent, { }) { } @@ -532,18 +498,25 @@ void QAbstractSlider::setValue(int value) value = d->bound(value); if (d->value == value && d->position == value) return; + + // delay signal emission until sliderChanged() has been called + const bool emitValueChanged = (value != d->value); d->value = value; + if (d->position != value) { d->position = value; if (d->pressed) - emit sliderMoved((d->position = value)); + emit sliderMoved(d->position); } -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) QAccessibleValueChangeEvent event(this, d->value); QAccessible::updateAccessibility(&event); #endif sliderChange(SliderValueChange); - emit valueChanged(value); + + if (emitValueChanged) + emit valueChanged(value); + } /*! @@ -719,15 +692,10 @@ bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::Keyb offset_accumulated = 0; offset_accumulated += stepsToScrollF; -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC + // Don't scroll more than one page in any case: stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep); -#else - // Native UI-elements on Mac can scroll hundreds of lines at a time as - // a result of acceleration. So keep the same behaviour in Qt, and - // don't restrict stepsToScroll to certain maximum (pageStep): - stepsToScroll = int(offset_accumulated); -#endif + offset_accumulated -= int(offset_accumulated); if (stepsToScroll == 0) { // We moved less than a line, but might still have accumulated partial scroll, @@ -764,10 +732,11 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) { Q_D(QAbstractSlider); e->ignore(); - int delta = e->delta(); + bool vertical = bool(e->angleDelta().y()); + int delta = vertical ? e->angleDelta().y() : e->angleDelta().x(); if (e->inverted()) delta = -delta; - if (d->scrollByDelta(e->orientation(), e->modifiers(), delta)) + if (d->scrollByDelta(vertical ? Qt::Vertical : Qt::Horizontal, e->modifiers(), delta)) e->accept(); } @@ -815,13 +784,13 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) switch (ev->key()) { #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: - if (QApplication::keypadNavigationEnabled()) + if (QApplicationPrivate::keypadNavigationEnabled()) setEditFocus(!hasEditFocus()); else ev->ignore(); break; case Qt::Key_Back: - if (QApplication::keypadNavigationEnabled() && hasEditFocus()) { + if (QApplicationPrivate::keypadNavigationEnabled() && hasEditFocus()) { setValue(d->origValue); setEditFocus(false); } else @@ -834,7 +803,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) // In QApplication::KeypadNavigationDirectional, we want to change the slider // value if there is no left/right navigation possible and if this slider is not // inside a tab widget. - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Vertical || !hasEditFocus() @@ -842,7 +811,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) ev->ignore(); return; } - if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) + if (QApplicationPrivate::keypadNavigationEnabled() && d->orientation == Qt::Vertical) action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; else #endif @@ -854,7 +823,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) case Qt::Key_Right: #ifdef QT_KEYPAD_NAVIGATION // Same logic as in Qt::Key_Left - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Vertical || !hasEditFocus() @@ -862,7 +831,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) ev->ignore(); return; } - if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) + if (QApplicationPrivate::keypadNavigationEnabled() && d->orientation == Qt::Vertical) action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; else #endif @@ -875,7 +844,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) #ifdef QT_KEYPAD_NAVIGATION // In QApplication::KeypadNavigationDirectional, we want to change the slider // value if there is no up/down navigation possible. - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Horizontal || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { @@ -888,7 +857,7 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) case Qt::Key_Down: #ifdef QT_KEYPAD_NAVIGATION // Same logic as in Qt::Key_Up - if (QApplication::keypadNavigationEnabled() + if (QApplicationPrivate::keypadNavigationEnabled() && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder || d->orientation == Qt::Horizontal || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { |