1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#include "qquickdragaxis_p.h"
4#include "qquickpointerhandler_p.h"
5#include <QtQuick/qquickitem.h>
6#include <limits>
7
8QT_BEGIN_NAMESPACE
9
10Q_LOGGING_CATEGORY(lcDragAxis, "qt.quick.pointer.dragaxis")
11
12QQuickDragAxis::QQuickDragAxis(QQuickPointerHandler *handler, const QString &propertyName, qreal initValue)
13 : QObject(handler), m_accumulatedValue(initValue), m_propertyName(propertyName)
14{
15}
16
17void QQuickDragAxis::setMinimum(qreal minimum)
18{
19 if (m_minimum == minimum)
20 return;
21
22 m_minimum = minimum;
23 emit minimumChanged();
24}
25
26void QQuickDragAxis::setMaximum(qreal maximum)
27{
28 if (m_maximum == maximum)
29 return;
30
31 m_maximum = maximum;
32 emit maximumChanged();
33}
34
35void QQuickDragAxis::setEnabled(bool enabled)
36{
37 if (m_enabled == enabled)
38 return;
39
40 m_enabled = enabled;
41 emit enabledChanged();
42}
43
44void QQuickDragAxis::onActiveChanged(bool active, qreal initActiveValue)
45{
46 m_activeValue = initActiveValue;
47 m_startValue = m_accumulatedValue;
48 qCDebug(lcDragAxis) << parent() << m_propertyName << active << ": init active" << m_activeValue
49 << "target start" << m_startValue;
50}
51
52void QQuickDragAxis::updateValue(qreal activeValue, qreal accumulatedValue, qreal delta)
53{
54 if (!m_enabled)
55 return;
56
57 m_activeValue = activeValue;
58 m_accumulatedValue = qBound(min: m_minimum, val: accumulatedValue, max: m_maximum);
59 qCDebug(lcDragAxis) << parent() << m_propertyName << "values: active" << activeValue
60 << "accumulated" << m_accumulatedValue << "delta" << delta;
61 emit activeValueChanged(delta);
62}
63
64QT_END_NAMESPACE
65
66#include "moc_qquickdragaxis_p.cpp"
67

source code of qtdeclarative/src/quick/handlers/qquickdragaxis.cpp