| 1 | // Copyright (C) 2016 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 | |
| 4 | #include "qmltapsensor_p.h" |
| 5 | #include <QtSensors/QTapSensor> |
| 6 | |
| 7 | /*! |
| 8 | \qmltype TapSensor |
| 9 | //! \nativetype QmlTapSensor |
| 10 | \ingroup qml-sensors_type |
| 11 | \inqmlmodule QtSensors |
| 12 | \since QtSensors 5.0 |
| 13 | \inherits Sensor |
| 14 | \brief The TapSensor element reports tap and double tap events |
| 15 | along the X, Y and Z axes. |
| 16 | \internal |
| 17 | |
| 18 | The TapSensor element reports tap and double tap events |
| 19 | along the X, Y and Z axes. |
| 20 | |
| 21 | This element wraps the QTapSensor class. Please see the documentation for |
| 22 | QTapSensor for details. |
| 23 | |
| 24 | \sa TapReading |
| 25 | */ |
| 26 | |
| 27 | QmlTapSensor::QmlTapSensor(QObject *parent) |
| 28 | : QmlSensor(parent) |
| 29 | , m_sensor(new QTapSensor(this)) |
| 30 | { |
| 31 | connect(sender: m_sensor, SIGNAL(returnDoubleTapEventsChanged(bool)), |
| 32 | receiver: this, SIGNAL(returnDoubleTapEventsChanged(bool))); |
| 33 | } |
| 34 | |
| 35 | QmlTapSensor::~QmlTapSensor() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | QmlSensorReading *QmlTapSensor::createReading() const |
| 40 | { |
| 41 | return new QmlTapSensorReading(m_sensor); |
| 42 | } |
| 43 | |
| 44 | QSensor *QmlTapSensor::sensor() const |
| 45 | { |
| 46 | return m_sensor; |
| 47 | } |
| 48 | |
| 49 | /*! |
| 50 | \qmlproperty bool TapSensor::returnDoubleTapEvents |
| 51 | This property holds a value indicating if double tap events should be reported. |
| 52 | |
| 53 | Please see QTapSensor::returnDoubleTapEvents for information about this property. |
| 54 | */ |
| 55 | |
| 56 | bool QmlTapSensor::returnDoubleTapEvents() const |
| 57 | { |
| 58 | return m_sensor->returnDoubleTapEvents(); |
| 59 | } |
| 60 | |
| 61 | void QmlTapSensor::setReturnDoubleTapEvents(bool ret) |
| 62 | { |
| 63 | m_sensor->setReturnDoubleTapEvents(ret); |
| 64 | } |
| 65 | |
| 66 | /*! |
| 67 | \qmltype TapReading |
| 68 | //! \nativetype QmlTapSensorReading |
| 69 | \ingroup qml-sensors_reading |
| 70 | \inqmlmodule QtSensors |
| 71 | \since QtSensors 5.0 |
| 72 | \inherits SensorReading |
| 73 | \brief The TapReading element holds the most recent TapSensor reading. |
| 74 | \internal |
| 75 | |
| 76 | The TapReading element holds the most recent TapSensor reading. |
| 77 | |
| 78 | This element wraps the QTapReading class. Please see the documentation for |
| 79 | QTapReading for details. |
| 80 | |
| 81 | This element cannot be directly created. |
| 82 | */ |
| 83 | |
| 84 | QmlTapSensorReading::QmlTapSensorReading(QTapSensor *sensor) |
| 85 | : m_sensor(sensor) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | QmlTapSensorReading::~QmlTapSensorReading() |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | /*! |
| 94 | \qmlproperty TapDirection TapReading::tapDirection |
| 95 | This property holds the direction of the tap. |
| 96 | |
| 97 | Please see QTapReading::tapDirection for information about this property. |
| 98 | |
| 99 | Note that TapDirection constants are exposed through the TapReading class. |
| 100 | \code |
| 101 | TapSensor { |
| 102 | onReadingChanged: { |
| 103 | if ((reading.tapDirection & TapReading.X_Both)) |
| 104 | // do something |
| 105 | } |
| 106 | } |
| 107 | \endcode |
| 108 | */ |
| 109 | |
| 110 | QTapReading::TapDirection QmlTapSensorReading::tapDirection() const |
| 111 | { |
| 112 | return m_tapDirection; |
| 113 | } |
| 114 | |
| 115 | QBindable<QTapReading::TapDirection> QmlTapSensorReading::bindableTapDirection() const |
| 116 | { |
| 117 | return &m_tapDirection; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | /*! |
| 122 | \qmlproperty bool TapReading::doubleTap |
| 123 | This property holds a value indicating if there was a single or double tap. |
| 124 | |
| 125 | Please see QTapReading::doubleTap for information about this property. |
| 126 | */ |
| 127 | |
| 128 | bool QmlTapSensorReading::isDoubleTap() const |
| 129 | { |
| 130 | return m_isDoubleTap; |
| 131 | } |
| 132 | |
| 133 | QBindable<bool> QmlTapSensorReading::bindableDoubleTap() const |
| 134 | { |
| 135 | return &m_isDoubleTap; |
| 136 | } |
| 137 | |
| 138 | QSensorReading *QmlTapSensorReading::reading() const |
| 139 | { |
| 140 | return const_cast<QTapSensor*>(m_sensor)->reading(); |
| 141 | } |
| 142 | |
| 143 | void QmlTapSensorReading::readingUpdate() |
| 144 | { |
| 145 | m_tapDirection = m_sensor->reading()->tapDirection(); |
| 146 | m_isDoubleTap = m_sensor->reading()->isDoubleTap(); |
| 147 | } |
| 148 | |