1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00

viewsdialog:support moving between active layouts

This commit is contained in:
Michail Vourlakos 2021-04-27 01:22:29 +03:00
parent 5fd18ee0af
commit 18233dc6ee
7 changed files with 67 additions and 15 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -34,6 +34,7 @@
#include "../../layout/centrallayout.h"
#include "../../layouts/manager.h"
#include "../../layouts/synchronizer.h"
#include "../../view/view.h"
// Qt
#include <QHeaderView>
@ -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<QString, Data::View> newviewsresponses;
QHash<QString, Data::View> cuttedpastedviews;
QHash<QString, Data::View> cuttedpastedactiveviews;
//! add new views that are accepted
for(int i=0; i<newViews.rowCount(); ++i){
if (newViews[i].isMoveDestination) {
CentralLayout *originActive = originLayout(newViews[i]);
bool inmovebetweenactivelayouts = centralActive && originActive && centralActive != originActive && hasValidOriginView(newViews[i]);
if (inmovebetweenactivelayouts) {
cuttedpastedactiveviews[newViews[i].id] = newViews[i];
continue;
}
cuttedpastedviews[newViews[i].id] = newViews[i];
}
@ -460,6 +494,32 @@ void Views::save()
}
}
//! move active views between different active layouts
for (const auto vid: cuttedpastedactiveviews.keys()) {
Data::View pastedactiveview = cuttedpastedactiveviews[vid];
uint originviewid = pastedactiveview.originView().toUInt();
CentralLayout *origin = originLayout(pastedactiveview);
QString originlayoutname = origin->name();
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();

View File

@ -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);

View File

@ -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

View File

@ -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) {

View File

@ -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);