From ba9233684ee32ceffc1eb8b546c8b3ce16b699f4 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 28 Dec 2020 23:36:28 +0200 Subject: [PATCH] view:separate parabolic c++ code from view --The parabolic effect c++ part of View now leaves in its own class --- app/view/CMakeLists.txt | 1 + app/view/parabolic.cpp | 128 ++++++++++++++++++ app/view/parabolic.h | 69 ++++++++++ app/view/view.cpp | 75 +--------- app/view/view.h | 17 +-- .../contents/ui/abilities/ParabolicEffect.qml | 2 +- .../privates/ParabolicEffectPrivate.qml | 10 +- 7 files changed, 218 insertions(+), 84 deletions(-) create mode 100644 app/view/parabolic.cpp create mode 100644 app/view/parabolic.h diff --git a/app/view/CMakeLists.txt b/app/view/CMakeLists.txt index 8cee4a6fa..e698b201b 100644 --- a/app/view/CMakeLists.txt +++ b/app/view/CMakeLists.txt @@ -5,6 +5,7 @@ set(lattedock-app_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/effects.cpp ${CMAKE_CURRENT_SOURCE_DIR}/padding.cpp ${CMAKE_CURRENT_SOURCE_DIR}/panelshadows.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/parabolic.cpp ${CMAKE_CURRENT_SOURCE_DIR}/positioner.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tasksmodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/view.cpp diff --git a/app/view/parabolic.cpp b/app/view/parabolic.cpp new file mode 100644 index 000000000..f14906a71 --- /dev/null +++ b/app/view/parabolic.cpp @@ -0,0 +1,128 @@ +/* +* Copyright 2020 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see . +*/ + +#include "parabolic.h" + +// local +#include "view.h" + +// Qt +#include + +namespace Latte { +namespace ViewPart { + +Parabolic::Parabolic(Latte::View *parent) + : QObject(parent), + m_view(parent) +{ + m_parabolicItemNullifier.setInterval(100); + m_parabolicItemNullifier.setSingleShot(true); + connect(&m_parabolicItemNullifier, &QTimer::timeout, this, [&]() { + setCurrentParabolicItem(nullptr); + }); + + connect(this, &Parabolic::currentParabolicItemChanged, this, &Parabolic::onCurrentParabolicItemChanged); + + connect(m_view, &View::eventTriggered, this, &Parabolic::onEvent); +} + +Parabolic::~Parabolic() +{ +} + +QQuickItem *Parabolic::currentParabolicItem() const +{ + return m_currentParabolicItem; +} + +void Parabolic::setCurrentParabolicItem(QQuickItem *item) +{ + if (m_currentParabolicItem == item) { + return; + } + + if (item && m_currentParabolicItem) { + QMetaObject::invokeMethod(item, "parabolicExited", Qt::QueuedConnection); + } + + m_currentParabolicItem = item; + emit currentParabolicItemChanged(); +} + +void Parabolic::onEvent(QEvent *e) +{ + if (!e) { + return; + } + + switch (e->type()) { + + case QEvent::Leave: + setCurrentParabolicItem(nullptr); + break; + case QEvent::MouseMove: + if (auto me = dynamic_cast(e)) { + if (m_currentParabolicItem) { + QPointF internal = m_currentParabolicItem->mapFromScene(me->windowPos()); + + if (m_currentParabolicItem->contains(internal)) { + m_parabolicItemNullifier.stop(); + //! sending move event to parabolic item + QMetaObject::invokeMethod(m_currentParabolicItem, + "parabolicMove", + Qt::QueuedConnection, + Q_ARG(qreal, internal.x()), + Q_ARG(qreal, internal.y())); + } else { + m_lastOrphanParabolicMove = me->windowPos(); + //! clearing parabolic item + m_parabolicItemNullifier.start(); + } + } else { + m_lastOrphanParabolicMove = me->windowPos(); + } + } + default: + break; + } + +} + +void Parabolic::onCurrentParabolicItemChanged() +{ + m_parabolicItemNullifier.stop(); + + if (m_currentParabolicItem != nullptr) { + QPointF internal = m_currentParabolicItem->mapFromScene(m_lastOrphanParabolicMove); + + if (m_currentParabolicItem->contains(internal)) { + //! sending enter event to parabolic item + QMetaObject::invokeMethod(m_currentParabolicItem, + "parabolicEntered", + Qt::QueuedConnection, + Q_ARG(qreal, internal.x()), + Q_ARG(qreal, internal.y())); + } + } +} + +} +} + diff --git a/app/view/parabolic.h b/app/view/parabolic.h new file mode 100644 index 000000000..8b5a23afb --- /dev/null +++ b/app/view/parabolic.h @@ -0,0 +1,69 @@ +/* +* Copyright 2020 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see . +*/ + +#ifndef VIEWPARABOLIC_H +#define VIEWPARABOLIC_H + +// Qt +#include +#include +#include +#include +#include + +namespace Latte { +class View; +} + +namespace Latte { +namespace ViewPart { + +class Parabolic: public QObject +{ + Q_OBJECT + + Q_PROPERTY(QQuickItem *currentItem READ currentParabolicItem WRITE setCurrentParabolicItem NOTIFY currentParabolicItemChanged) + +public: + Parabolic(Latte::View *parent); + virtual ~Parabolic(); + + QQuickItem *currentParabolicItem() const; + void setCurrentParabolicItem(QQuickItem *item); + +signals: + void currentParabolicItemChanged(); + +private slots: + void onCurrentParabolicItemChanged(); + void onEvent(QEvent *e); + +private: + QPointer m_view; + + QPointF m_lastOrphanParabolicMove; + QQuickItem *m_currentParabolicItem{nullptr}; + + QTimer m_parabolicItemNullifier; +}; + +} +} + +#endif diff --git a/app/view/view.cpp b/app/view/view.cpp index 0ab4436bf..1999a9699 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -79,7 +79,8 @@ View::View(Plasma::Corona *corona, QScreen *targetScreen, bool byPassWM) m_contextMenu(new ViewPart::ContextMenu(this)), m_effects(new ViewPart::Effects(this)), m_interface(new ViewPart::ContainmentInterface(this)), - m_padding(new ViewPart::Padding(this)) + m_padding(new ViewPart::Padding(this)), + m_parabolic(new ViewPart::Parabolic(this)) { //! needs to be created after Effects because it catches some of its signals //! and avoid a crash from View::winId() at the same time @@ -112,12 +113,6 @@ View::View(Plasma::Corona *corona, QScreen *targetScreen, bool byPassWM) connect(m_contextMenu, &ViewPart::ContextMenu::menuChanged, this, &View::updateTransientWindowsTracking); - m_parabolicItemNullifier.setInterval(100); - m_parabolicItemNullifier.setSingleShot(true); - connect(&m_parabolicItemNullifier, &QTimer::timeout, this, [&]() { - setCurrentParabolicItem(nullptr); - }); - connect(this, &View::containmentChanged , this, [ &, byPassWM]() { qDebug() << "dock view c++ containment changed 1..."; @@ -325,8 +320,6 @@ void View::init(Plasma::Containment *plasma_containment) connect(m_interface, &ViewPart::ContainmentInterface::hasExpandedAppletChanged, this, &View::verticalUnityViewHasFocus); - connect(this, &View::currentParabolicItemChanged, this, &View::onCurrentParabolicItemChanged); - //! View sends this signal in order to avoid crashes from ViewPart::Indicator when the view is recreated connect(m_corona->indicatorFactory(), &Latte::Indicator::Factory::indicatorChanged, this, [&](const QString &indicatorId) { emit indicatorPluginChanged(indicatorId); @@ -1281,25 +1274,6 @@ void View::setColorizer(QQuickItem *colorizer) emit colorizerChanged(); } -QQuickItem *View::currentParabolicItem() const -{ - return m_currentParabolicItem; -} - -void View::setCurrentParabolicItem(QQuickItem *item) -{ - if (m_currentParabolicItem == item) { - return; - } - - if (item && m_currentParabolicItem) { - QMetaObject::invokeMethod(item, "parabolicExited", Qt::QueuedConnection); - } - - m_currentParabolicItem = item; - emit currentParabolicItemChanged(); -} - ViewPart::Effects *View::effects() const { return m_effects; @@ -1325,6 +1299,11 @@ ViewPart::Padding *View::padding() const return m_padding; } +ViewPart::Parabolic *View::parabolic() const +{ + return m_parabolic; +} + ViewPart::Positioner *View::positioner() const { return m_positioner; @@ -1379,7 +1358,6 @@ bool View::event(QEvent *e) case QEvent::Leave: m_containsMouse = false; setContainsDrag(false); - setCurrentParabolicItem(nullptr); break; case QEvent::DragEnter: @@ -1435,27 +1413,6 @@ bool View::event(QEvent *e) case QEvent::MouseMove: if (auto me = dynamic_cast(e)) { - - if (m_currentParabolicItem) { - QPointF internal = m_currentParabolicItem->mapFromScene(me->windowPos()); - - if (m_currentParabolicItem->contains(internal)) { - m_parabolicItemNullifier.stop(); - //! sending move event to parabolic item - QMetaObject::invokeMethod(m_currentParabolicItem, - "parabolicMove", - Qt::QueuedConnection, - Q_ARG(qreal, internal.x()), - Q_ARG(qreal, internal.y())); - } else { - m_lastOrphanParabolicMove = me->windowPos(); - //! clearing parabolic item - m_parabolicItemNullifier.start(); - } - } else { - m_lastOrphanParabolicMove = me->windowPos(); - } - //! adjust event by taking into account paddings if (m_padding && !m_padding->isEmpty() @@ -1586,24 +1543,6 @@ bool View::event(QEvent *e) return ContainmentView::event(adjustedevent); } -void View::onCurrentParabolicItemChanged() -{ - m_parabolicItemNullifier.stop(); - - if (m_currentParabolicItem != nullptr) { - QPointF internal = m_currentParabolicItem->mapFromScene(m_lastOrphanParabolicMove); - - if (m_currentParabolicItem->contains(internal)) { - //! sending enter event to parabolic item - QMetaObject::invokeMethod(m_currentParabolicItem, - "parabolicEntered", - Qt::QueuedConnection, - Q_ARG(qreal, internal.x()), - Q_ARG(qreal, internal.y())); - } - } -} - void View::updateSinkedEventsGeometry() { if (m_inDelete || !m_padding) { diff --git a/app/view/view.h b/app/view/view.h index e88c99aa2..ed212f526 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -26,6 +26,7 @@ #include "containmentinterface.h" #include "effects.h" #include "padding.h" +#include "parabolic.h" #include "positioner.h" #include "visibilitymanager.h" #include "indicator/indicator.h" @@ -117,13 +118,13 @@ class View : public PlasmaQuick::ContainmentView Q_PROPERTY(float offset READ offset WRITE setOffset NOTIFY offsetChanged) Q_PROPERTY(QQuickItem *colorizer READ colorizer WRITE setColorizer NOTIFY colorizerChanged) - Q_PROPERTY(QQuickItem *currentParabolicItem READ currentParabolicItem WRITE setCurrentParabolicItem NOTIFY currentParabolicItemChanged) Q_PROPERTY(Latte::Layout::GenericLayout *layout READ layout WRITE setLayout NOTIFY layoutChanged) Q_PROPERTY(Latte::ViewPart::Effects *effects READ effects NOTIFY effectsChanged) Q_PROPERTY(Latte::ViewPart::ContainmentInterface *extendedInterface READ extendedInterface NOTIFY extendedInterfaceChanged) Q_PROPERTY(Latte::ViewPart::Indicator *indicator READ indicator NOTIFY indicatorChanged) Q_PROPERTY(Latte::ViewPart::Padding *padding READ padding NOTIFY paddingChanged) + Q_PROPERTY(Latte::ViewPart::Parabolic *parabolic READ parabolic NOTIFY parabolicChanged) Q_PROPERTY(Latte::ViewPart::Positioner *positioner READ positioner NOTIFY positionerChanged) Q_PROPERTY(Latte::ViewPart::VisibilityManager *visibility READ visibility NOTIFY visibilityChanged) Q_PROPERTY(Latte::ViewPart::WindowsTracker *windowsTracker READ windowsTracker NOTIFY windowsTrackerChanged) @@ -232,9 +233,6 @@ public: QQuickItem *colorizer() const; void setColorizer(QQuickItem *colorizer); - QQuickItem *currentParabolicItem() const; - void setCurrentParabolicItem(QQuickItem *item); - QQuickView *configView(); ViewPart::Effects *effects() const; @@ -242,6 +240,7 @@ public: ViewPart::ContainmentInterface *extendedInterface() const; ViewPart::Indicator *indicator() const; ViewPart::Padding *padding() const; + ViewPart::Parabolic *parabolic() const; ViewPart::Positioner *positioner() const; ViewPart::VisibilityManager *visibility() const; ViewPart::WindowsTracker *windowsTracker() const; @@ -302,7 +301,6 @@ signals: void configWindowGeometryChanged(); // is called from config windows void containsDragChanged(); void contextMenuIsShownChanged(); - void currentParabolicItemChanged(); void dockLocationChanged(); void editThicknessChanged(); void effectsChanged(); @@ -328,6 +326,7 @@ signals: void offsetChanged(); void onPrimaryChanged(); void paddingChanged(); + void parabolicChanged(); void positionerChanged(); void screenEdgeMarginChanged(); void screenEdgeMarginEnabledChanged(); @@ -362,8 +361,6 @@ private slots: void addTransientWindow(QWindow *window); void removeTransientWindow(const bool &visible); - void onCurrentParabolicItemChanged(); - void updateSinkedEventsGeometry(); //! workaround in order for top panels to be always on top @@ -434,15 +431,10 @@ private: int m_releaseGrab_x; int m_releaseGrab_y; - QTimer m_parabolicItemNullifier; - Layout::GenericLayout *m_layout{nullptr}; QQuickItem *m_colorizer{nullptr}; - QPointF m_lastOrphanParabolicMove; - QQuickItem *m_currentParabolicItem{nullptr}; - QPointer m_appletConfigView; QPointer m_primaryConfigView; @@ -451,6 +443,7 @@ private: QPointer m_indicator; QPointer m_interface; QPointer m_padding; + QPointer m_parabolic; QPointer m_positioner; QPointer m_visibility; QPointer m_windowsTracker; diff --git a/containment/package/contents/ui/abilities/ParabolicEffect.qml b/containment/package/contents/ui/abilities/ParabolicEffect.qml index db9b58348..2f8442c2e 100644 --- a/containment/package/contents/ui/abilities/ParabolicEffect.qml +++ b/containment/package/contents/ui/abilities/ParabolicEffect.qml @@ -33,5 +33,5 @@ Ability.ParabolicEffectPrivate { restoreZoomIsBlocked: (view && view.contextMenuIsShown) || (applets.parabolic.restoreZoomIsBlocked) - currentParabolicItem: view ? view.currentParabolicItem : null + currentParabolicItem: view ? view.parabolic.currentItem : null } diff --git a/containment/package/contents/ui/abilities/privates/ParabolicEffectPrivate.qml b/containment/package/contents/ui/abilities/privates/ParabolicEffectPrivate.qml index cce9db76a..125a809d9 100644 --- a/containment/package/contents/ui/abilities/privates/ParabolicEffectPrivate.qml +++ b/containment/package/contents/ui/abilities/privates/ParabolicEffectPrivate.qml @@ -65,9 +65,13 @@ AbilityHost.ParabolicEffect { parabolic.startRestoreZoomTimer(); } } + } - onCurrentParabolicItemChanged: { - if (!parabolic.view.currentParabolicItem) { + Connections { + target: view ? view.parabolic : null + ignoreUnknownSignals : true + onCurrentItemChanged: { + if (!view.parabolic.currentItem) { parabolic.startRestoreZoomTimer(); } } @@ -90,7 +94,7 @@ AbilityHost.ParabolicEffect { } function setCurrentParabolicItem(item) { - parabolic.view.currentParabolicItem = item; + view.parabolic.currentItem = item; } function applyParabolicEffect(index, currentMousePosition, center) {