diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index d76172e67..4ef53ff94 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -853,7 +853,7 @@ void GenericLayout::addView(Plasma::Containment *containment, bool forceOnPrimar int id = containment->screen(); if (!Layouts::Storage::isValid(id) && !Layouts::Storage::isValid(explicitScreen)) { - id = containment->lastScreen(); + id = containment->lastScreen(); } if (onPrimary) { @@ -1060,52 +1060,55 @@ void GenericLayout::updateLastUsedActivity() void GenericLayout::assignToLayout(Latte::View *latteView, QList containments) { - if (!m_corona) { + if (!m_corona || containments.isEmpty()) { return; } if (latteView) { m_latteViews[latteView->containment()] = latteView; - m_containments << containments; + } - for (const auto containment : containments) { - containment->config().writeEntry("layoutId", name()); + m_containments << containments; - if (latteView->containment() != containment) { - //! assign signals only to subcontainments - //! the View::setLayout() is responsible for the View::Containment signals - connect(containment, &QObject::destroyed, this, &GenericLayout::containmentDestroyed); - connect(containment, &Plasma::Applet::destroyedChanged, this, &GenericLayout::destroyedChanged); - connect(containment, &Plasma::Containment::appletCreated, this, &GenericLayout::appletCreated); - } + for (const auto containment : containments) { + containment->config().writeEntry("layoutId", name()); + + if (!latteView || (latteView && latteView->containment() != containment)) { + //! assign signals only to subcontainments + //! the View::setLayout() is responsible for the View::Containment signals + connect(containment, &QObject::destroyed, this, &GenericLayout::containmentDestroyed); + connect(containment, &Plasma::Applet::destroyedChanged, this, &GenericLayout::destroyedChanged); + connect(containment, &Plasma::Containment::appletCreated, this, &GenericLayout::appletCreated); } + } + if (latteView) { latteView->setLayout(this); - - emit viewsCountChanged(); } + emit viewsCountChanged(); + //! sync the original layout file for integrity - if (m_corona && m_corona->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { + if (m_corona->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { Layouts::Storage::self()->syncToLayoutFile(this, false); } } -QList GenericLayout::unassignFromLayout(Latte::View *latteView) +QList GenericLayout::unassignFromLayout(Plasma::Containment *latteContainment) { QList containments; - if (!m_corona) { + if (!m_corona || !latteContainment || !contains(latteContainment)) { return containments; } - containments << latteView->containment(); + containments << latteContainment; for (const auto containment : m_containments) { Plasma::Applet *parentApplet = qobject_cast(containment->parent()); //! add subcontainments from that latteView - if (parentApplet && parentApplet->containment() && parentApplet->containment() == latteView->containment()) { + if (parentApplet && parentApplet->containment() && parentApplet->containment() == latteContainment) { containments << containment; //! unassign signals only to subcontainments //! the View::setLayout() is responsible for the View::Containment signals @@ -1120,7 +1123,7 @@ QList GenericLayout::unassignFromLayout(Latte::View *latt } if (containments.size() > 0) { - m_latteViews.remove(latteView->containment()); + m_latteViews.remove(latteContainment); } //! sync the original layout file for integrity @@ -1416,7 +1419,7 @@ void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap) int screenId = containment->screen(); if (!Layouts::Storage::isValid(screenId)) { - screenId = containment->lastScreen(); + screenId = containment->lastScreen(); } if (!latteViewExists(containment) && mapContainsId(&viewsMap, containment->id())) { diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 430529c71..de2e1db89 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -142,7 +142,7 @@ public: //! Unassign that latteView from this layout (this is used for moving a latteView //! from layout to layout) and returns all the containments relevant to //! that latteView - QList unassignFromLayout(Latte::View *latteView); + QList unassignFromLayout(Plasma::Containment *latteContainment); QList viewsScreens(); diff --git a/app/layouts/manager.cpp b/app/layouts/manager.cpp index 01c08d93b..d592245f4 100644 --- a/app/layouts/manager.cpp +++ b/app/layouts/manager.cpp @@ -223,6 +223,38 @@ void Manager::loadLayoutOnStartup(QString layoutName) m_synchronizer->switchToLayout(layoutName); } +void Manager::moveView(QString originLayoutName, uint originViewId, QString destinationLayoutName) +{ + if (memoryUsage() != Latte::MemoryUsage::MultipleLayouts + || originLayoutName.isEmpty() + || destinationLayoutName.isEmpty() + || originViewId <= 0 + || originLayoutName == destinationLayoutName) { + return; + } + + auto originlayout = m_synchronizer->layout(originLayoutName); + auto destinationlayout = m_synchronizer->layout(destinationLayoutName); + + + if (!originlayout || !destinationlayout || originlayout == destinationlayout) { + return; + } + + Plasma::Containment *originviewcontainment = originlayout->containmentForId(originViewId); + Latte::View *originview = originlayout->viewForContainment(originViewId); + + if (!originviewcontainment) { + return; + } + + QList origincontainments = originlayout->unassignFromLayout(originviewcontainment); + + if (origincontainments.size() > 0) { + destinationlayout->assignToLayout(originview, origincontainments); + } +} + void Manager::loadLatteLayout(QString layoutPath) { qDebug() << " -------------------------------------------------------------------- "; diff --git a/app/layouts/manager.h b/app/layouts/manager.h index 489c840ab..707a8a55f 100644 --- a/app/layouts/manager.h +++ b/app/layouts/manager.h @@ -98,6 +98,8 @@ public: SyncedLaunchers *syncedLaunchers() const; Synchronizer *synchronizer() const; + void moveView(QString originLayoutName, uint originViewId, QString destinationLayoutName); + public slots: void showAboutDialog(); diff --git a/app/view/view.cpp b/app/view/view.cpp index 3bcb5c108..8be7de720 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -1280,23 +1280,13 @@ void View::setLayout(Layout::GenericLayout *layout) } } -void View::moveToLayout(QString layoutName) +void View::moveToLayout(QString destinationLayoutName) { if (!m_layout) { return; } - QList containments = m_layout->unassignFromLayout(this); - - Latte::Corona *latteCorona = qobject_cast(this->corona()); - - if (latteCorona && containments.size() > 0) { - Layout::GenericLayout *newlayout = latteCorona->layoutsManager()->synchronizer()->layout(layoutName); - - if (newlayout && newlayout != m_layout) { - newlayout->assignToLayout(this, containments); - } - } + m_corona->layoutsManager()->moveView(m_layout->name(), containment()->id(), destinationLayoutName); } void View::hideWindowsForSlidingOut() diff --git a/app/view/view.h b/app/view/view.h index 41a0566b7..625d30caa 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -286,7 +286,7 @@ public slots: Q_INVOKABLE void exportTemplate(); - Q_INVOKABLE void moveToLayout(QString layoutName); + Q_INVOKABLE void moveToLayout(QString destinationLayoutName); Q_INVOKABLE bool mimeContainsPlasmoid(QMimeData *mimeData, QString name);