From 18233dc6ee5615f8c929a4c3548e8ba5cc07963f Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 27 Apr 2021 01:22:29 +0300 Subject: [PATCH] viewsdialog:support moving between active layouts --- app/layout/genericlayout.cpp | 3 +- app/layouts/manager.cpp | 1 - app/settings/viewsdialog/viewscontroller.cpp | 60 ++++++++++++++++++++ app/settings/viewsdialog/viewscontroller.h | 4 ++ app/view/positioner.cpp | 2 +- app/view/view.cpp | 9 --- app/view/view.h | 3 - 7 files changed, 67 insertions(+), 15 deletions(-) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 4ef53ff94..c60ad9e20 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1588,6 +1588,7 @@ void GenericLayout::updateView(const Latte::Data::View &viewData) if (view) { if (!viewMustBeDeleted) { QString scrName = Latte::Data::Screen::ONPRIMARYNAME; + QString nextlayoutname = (viewData.state() == Data::View::OriginFromLayout && !viewData.originLayout().isEmpty() ? viewData.originLayout() : QString()); if (!viewData.onPrimary) { if (m_corona->screenPool()->hasScreenId(viewData.screen)) { @@ -1598,7 +1599,7 @@ void GenericLayout::updateView(const Latte::Data::View &viewData) } view->setName(viewData.name); - view->positioner()->setNextLocation("", scrName, viewData.edge, viewData.alignment); + view->positioner()->setNextLocation(nextlayoutname, scrName, viewData.edge, viewData.alignment); return; } else { //! viewMustBeDeleted diff --git a/app/layouts/manager.cpp b/app/layouts/manager.cpp index d592245f4..8ef2ec3dc 100644 --- a/app/layouts/manager.cpp +++ b/app/layouts/manager.cpp @@ -236,7 +236,6 @@ void Manager::moveView(QString originLayoutName, uint originViewId, QString dest auto originlayout = m_synchronizer->layout(originLayoutName); auto destinationlayout = m_synchronizer->layout(destinationLayoutName); - if (!originlayout || !destinationlayout || originlayout == destinationlayout) { return; } diff --git a/app/settings/viewsdialog/viewscontroller.cpp b/app/settings/viewsdialog/viewscontroller.cpp index ebffb5493..a82f7b0f6 100644 --- a/app/settings/viewsdialog/viewscontroller.cpp +++ b/app/settings/viewsdialog/viewscontroller.cpp @@ -34,6 +34,7 @@ #include "../../layout/centrallayout.h" #include "../../layouts/manager.h" #include "../../layouts/synchronizer.h" +#include "../../view/view.h" // Qt #include @@ -382,6 +383,30 @@ int Views::viewsForRemovalCount() const return removedViews.rowCount(); } +bool Views::hasValidOriginView(const Data::View &view) +{ + bool viewidisinteger{true}; + int vid_int = view.originView().toInt(&viewidisinteger); + QString vid_str = view.originView(); + + if (vid_str.isEmpty() || !viewidisinteger || vid_int<=0) { + return false; + } + + return true; +} + +CentralLayout *Views::originLayout(const Data::View &view) +{ + QString origincurrentid = view.originLayout(); + Data::Layout originlayoutdata = m_handler->layoutsController()->originalData(origincurrentid); + + Latte::CentralLayout *originactive = m_handler->layoutsController()->isLayoutOriginal(origincurrentid) ? + m_handler->corona()->layoutsManager()->synchronizer()->centralLayout(originlayoutdata.name) : nullptr; + + return originactive; +} + void Views::save() { //! when this function is called we consider that removal has already been approved @@ -399,10 +424,19 @@ void Views::save() QHash newviewsresponses; QHash cuttedpastedviews; + QHash cuttedpastedactiveviews; //! add new views that are accepted for(int i=0; iname(); + QString destinationlayoutname = originallayout.name; + + auto view = origin->viewForContainment(originviewid); + + QString tempviewid = pastedactiveview.id; + pastedactiveview.id = QString::number(originviewid); + pastedactiveview.setState(pastedactiveview.state(), pastedactiveview.originFile(), destinationlayoutname, pastedactiveview.originView()); + + origin->updateView(pastedactiveview); + + if (view) { + //view->positioner()->setNextLocation(destinationlayoutname, QString(), Plasma::Types::Floating, Latte::Types::NoneAlignment); + } else { + //m_handler->corona()->layoutsManager()->moveView(originlayoutname, originviewid, destinationlayoutname); + } + + pastedactiveview.setState(Data::View::IsCreated, QString(), QString(), QString()); + newviewsresponses[tempviewid] = pastedactiveview; + } + //! update if ((removedViews.rowCount() > 0) || (newViews.rowCount() > 0)) { m_handler->corona()->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles(); diff --git a/app/settings/viewsdialog/viewscontroller.h b/app/settings/viewsdialog/viewscontroller.h index 7c7471e19..06a74c68f 100644 --- a/app/settings/viewsdialog/viewscontroller.h +++ b/app/settings/viewsdialog/viewscontroller.h @@ -37,6 +37,7 @@ namespace Latte { +class CentralLayout; class Corona; class ViewsDialog; @@ -96,6 +97,9 @@ signals: private: void init(); + bool hasValidOriginView(const Data::View &view); + CentralLayout *originLayout(const Data::View &view); + int rowForId(QString id) const; QString uniqueViewName(QString name); diff --git a/app/view/positioner.cpp b/app/view/positioner.cpp index 341c3498c..f60c1c210 100644 --- a/app/view/positioner.cpp +++ b/app/view/positioner.cpp @@ -980,7 +980,7 @@ void Positioner::initSignalingForLocationChangeSliding() //! LAYOUT if (!m_nextLayoutName.isEmpty()) { - m_view->moveToLayout(m_nextLayoutName); + m_corona->layoutsManager()->moveView(m_view->layout()->name(), m_view->containment()->id(), m_nextLayoutName); } //! SCREEN diff --git a/app/view/view.cpp b/app/view/view.cpp index 8be7de720..5dab5afca 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -1280,15 +1280,6 @@ void View::setLayout(Layout::GenericLayout *layout) } } -void View::moveToLayout(QString destinationLayoutName) -{ - if (!m_layout) { - return; - } - - m_corona->layoutsManager()->moveView(m_layout->name(), containment()->id(), destinationLayoutName); -} - void View::hideWindowsForSlidingOut() { if (m_primaryConfigView) { diff --git a/app/view/view.h b/app/view/view.h index 625d30caa..731f75ba2 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -285,9 +285,6 @@ public slots: Q_INVOKABLE void duplicateView(); Q_INVOKABLE void exportTemplate(); - - Q_INVOKABLE void moveToLayout(QString destinationLayoutName); - Q_INVOKABLE bool mimeContainsPlasmoid(QMimeData *mimeData, QString name); void updateAbsoluteGeometry(bool bypassChecks = false);