diff --git a/kickerplugin.cpp b/kickerplugin.cpp index 1ad9e352d..d31043a9f 100644 --- a/kickerplugin.cpp +++ b/kickerplugin.cpp @@ -1,49 +1,51 @@ /*************************************************************************** * Copyright (C) 2014 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "kickerplugin.h" #include "abstractmodel.h" #include "draghelper.h" #include "fullscreenwindow.h" #include "funnelmodel.h" #include "processrunner.h" #include "rootmodel.h" #include "runnermodel.h" #include "submenu.h" #include "systemsettings.h" +#include "wheelinterceptor.h" #include "windowsystem.h" #include void KickerPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.kicker")); qmlRegisterType(); qmlRegisterType(uri, 0, 1, "DragHelper"); qmlRegisterType(uri, 0, 1, "FullScreenWindow"); qmlRegisterType(uri, 0, 1, "FunnelModel"); qmlRegisterType(uri, 0, 1, "ProcessRunner"); qmlRegisterType(uri, 0, 1, "RootModel"); qmlRegisterType(uri, 0, 1, "RunnerModel"); qmlRegisterType(uri, 0, 1, "SubMenu"); qmlRegisterType(uri, 0, 1, "SystemSettings"); + qmlRegisterType(uri, 0, 1, "WheelInterceptor"); qmlRegisterType(uri, 0, 1, "WindowSystem"); } diff --git a/kickerplugin.cpp b/wheelinterceptor.cpp similarity index 53% copy from kickerplugin.cpp copy to wheelinterceptor.cpp index 1ad9e352d..7d82fc0f3 100644 --- a/kickerplugin.cpp +++ b/wheelinterceptor.cpp @@ -1,49 +1,70 @@ /*************************************************************************** - * Copyright (C) 2014 by Eike Hein * + * Copyright (C) 2014-2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ -#include "kickerplugin.h" -#include "abstractmodel.h" -#include "draghelper.h" -#include "fullscreenwindow.h" -#include "funnelmodel.h" -#include "processrunner.h" -#include "rootmodel.h" -#include "runnermodel.h" -#include "submenu.h" -#include "systemsettings.h" -#include "windowsystem.h" - -#include - -void KickerPlugin::registerTypes(const char *uri) +#include "wheelinterceptor.h" + +#include + +WheelInterceptor::WheelInterceptor(QQuickItem *parent) : QQuickItem(parent) +{ +} + +WheelInterceptor::~WheelInterceptor() { - Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.kicker")); - - qmlRegisterType(); - - qmlRegisterType(uri, 0, 1, "DragHelper"); - qmlRegisterType(uri, 0, 1, "FullScreenWindow"); - qmlRegisterType(uri, 0, 1, "FunnelModel"); - qmlRegisterType(uri, 0, 1, "ProcessRunner"); - qmlRegisterType(uri, 0, 1, "RootModel"); - qmlRegisterType(uri, 0, 1, "RunnerModel"); - qmlRegisterType(uri, 0, 1, "SubMenu"); - qmlRegisterType(uri, 0, 1, "SystemSettings"); - qmlRegisterType(uri, 0, 1, "WindowSystem"); } + +QQuickItem* WheelInterceptor::destination() const +{ + return m_destination; +} + +void WheelInterceptor::setDestination(QQuickItem *destination) +{ + if (m_destination != destination) { + m_destination = destination; + + emit destinationChanged(); + } +} + +void WheelInterceptor::wheelEvent(QWheelEvent* event) +{ + if (m_destination) { + QCoreApplication::sendEvent(m_destination, event); + } +} + +QQuickItem *WheelInterceptor::findWheelArea(QQuickItem *parent) const +{ + if (!parent) { + return nullptr; + } + + foreach(QQuickItem *child, parent->childItems()) { + // HACK: ScrollView adds the WheelArea below its flickableItem with + // z==-1. This is reasonable non-risky considering we know about + // everything else in there, and worst case we break the mouse wheel. + if (child->z() == -1) { + return child; + } + } + + return nullptr; +} + diff --git a/kickerplugin.cpp b/wheelinterceptor.h similarity index 54% copy from kickerplugin.cpp copy to wheelinterceptor.h index 1ad9e352d..375f8ac2c 100644 --- a/kickerplugin.cpp +++ b/wheelinterceptor.h @@ -1,49 +1,51 @@ -/*************************************************************************** - * Copyright (C) 2014 by Eike Hein * +/************************************************************************** + * Copyright (C) 2014-2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ -#include "kickerplugin.h" -#include "abstractmodel.h" -#include "draghelper.h" -#include "fullscreenwindow.h" -#include "funnelmodel.h" -#include "processrunner.h" -#include "rootmodel.h" -#include "runnermodel.h" -#include "submenu.h" -#include "systemsettings.h" -#include "windowsystem.h" - -#include - -void KickerPlugin::registerTypes(const char *uri) +#ifndef WHEELINTERCEPTOR_H +#define WHEELINTERCEPTOR_H + +#include +#include + +class WheelInterceptor : public QQuickItem { - Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.kicker")); - - qmlRegisterType(); - - qmlRegisterType(uri, 0, 1, "DragHelper"); - qmlRegisterType(uri, 0, 1, "FullScreenWindow"); - qmlRegisterType(uri, 0, 1, "FunnelModel"); - qmlRegisterType(uri, 0, 1, "ProcessRunner"); - qmlRegisterType(uri, 0, 1, "RootModel"); - qmlRegisterType(uri, 0, 1, "RunnerModel"); - qmlRegisterType(uri, 0, 1, "SubMenu"); - qmlRegisterType(uri, 0, 1, "SystemSettings"); - qmlRegisterType(uri, 0, 1, "WindowSystem"); -} + Q_OBJECT + + Q_PROPERTY(QQuickItem* destination READ destination WRITE setDestination NOTIFY destinationChanged) + + public: + WheelInterceptor(QQuickItem *parent = 0); + ~WheelInterceptor(); + + QQuickItem *destination() const; + void setDestination(QQuickItem *destination); + + Q_INVOKABLE QQuickItem *findWheelArea(QQuickItem *parent) const; + + Q_SIGNALS: + void destinationChanged() const; + + protected: + void wheelEvent(QWheelEvent *event); + + private: + QPointer m_destination; +}; + +#endif