File indexing completed on 2024-12-22 05:15:23

0001 /*
0002     SPDX-FileCopyrightText: 2014-2015 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "wheelinterceptor.h"
0008 
0009 #include <QCoreApplication>
0010 
0011 WheelInterceptor::WheelInterceptor(QQuickItem *parent)
0012     : QQuickItem(parent)
0013 {
0014 }
0015 
0016 WheelInterceptor::~WheelInterceptor()
0017 {
0018 }
0019 
0020 QQuickItem *WheelInterceptor::destination() const
0021 {
0022     return m_destination;
0023 }
0024 
0025 void WheelInterceptor::setDestination(QQuickItem *destination)
0026 {
0027     if (m_destination != destination) {
0028         m_destination = destination;
0029 
0030         Q_EMIT destinationChanged();
0031     }
0032 }
0033 
0034 void WheelInterceptor::wheelEvent(QWheelEvent *event)
0035 {
0036     if (m_destination) {
0037         QCoreApplication::sendEvent(m_destination, event);
0038     }
0039 
0040     Q_EMIT wheelMoved(event->angleDelta());
0041 }
0042 
0043 QQuickItem *WheelInterceptor::findWheelArea(QQuickItem *parent) const
0044 {
0045     if (!parent) {
0046         return nullptr;
0047     }
0048 
0049     const QList<QQuickItem *> childItems = parent->childItems();
0050     for (QQuickItem *child : childItems) {
0051         // HACK: ScrollView adds the WheelArea below its flickableItem with
0052         // z==-1. This is reasonable non-risky considering we know about
0053         // everything else in there, and worst case we break the mouse wheel.
0054         if (child->z() == -1) {
0055             return child;
0056         }
0057     }
0058 
0059     return nullptr;
0060 }