mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-08 13:18:09 +03:00
add LayoutsManager::moveView function
--moveView for active layouts under MultipleLayouts becomes more generic and can be used either from onscreens and offscreens views
This commit is contained in:
parent
6362d662b7
commit
5fd18ee0af
@ -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<Plasma::Containment *> 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());
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
latteView->setLayout(this);
|
||||
|
||||
emit viewsCountChanged();
|
||||
}
|
||||
|
||||
m_containments << containments;
|
||||
|
||||
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();
|
||||
|
||||
//! 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<Plasma::Containment *> GenericLayout::unassignFromLayout(Latte::View *latteView)
|
||||
QList<Plasma::Containment *> GenericLayout::unassignFromLayout(Plasma::Containment *latteContainment)
|
||||
{
|
||||
QList<Plasma::Containment *> 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<Plasma::Applet *>(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<Plasma::Containment *> 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())) {
|
||||
|
@ -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<Plasma::Containment *> unassignFromLayout(Latte::View *latteView);
|
||||
QList<Plasma::Containment *> unassignFromLayout(Plasma::Containment *latteContainment);
|
||||
|
||||
QList<int> viewsScreens();
|
||||
|
||||
|
@ -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<Plasma::Containment *> origincontainments = originlayout->unassignFromLayout(originviewcontainment);
|
||||
|
||||
if (origincontainments.size() > 0) {
|
||||
destinationlayout->assignToLayout(originview, origincontainments);
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::loadLatteLayout(QString layoutPath)
|
||||
{
|
||||
qDebug() << " -------------------------------------------------------------------- ";
|
||||
|
@ -98,6 +98,8 @@ public:
|
||||
SyncedLaunchers *syncedLaunchers() const;
|
||||
Synchronizer *synchronizer() const;
|
||||
|
||||
void moveView(QString originLayoutName, uint originViewId, QString destinationLayoutName);
|
||||
|
||||
public slots:
|
||||
void showAboutDialog();
|
||||
|
||||
|
@ -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<Plasma::Containment *> containments = m_layout->unassignFromLayout(this);
|
||||
|
||||
Latte::Corona *latteCorona = qobject_cast<Latte::Corona *>(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()
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user