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

introduc fast layout manager for containment

This commit is contained in:
Michail Vourlakos 2021-03-02 19:33:24 +02:00
parent db99677f8c
commit f6df7a7df1
7 changed files with 225 additions and 76 deletions

View File

@ -663,72 +663,5 @@ void ContainmentInterface::onAppletAdded(Plasma::Applet *applet)
}
void ContainmentInterface::moveAppletsInJustifyAlignment(QQuickItem *start, QQuickItem *main, QQuickItem *end)
{
if (!start || !main || !end) {
return;
}
QList<QQuickItem *> appletlist;
appletlist << start->childItems();
appletlist << main->childItems();
appletlist << end->childItems();
bool firstSplitterFound{false};
bool secondSplitterFound{false};
int splitter1{-1};
int splitter2{-1};
for(int i=0; i<appletlist.count(); ++i) {
bool issplitter = appletlist[i]->property("isInternalViewSplitter").toBool();
if (!firstSplitterFound) {
appletlist[i]->setParentItem(start);
if (issplitter) {
firstSplitterFound = true;
splitter1 = i;
}
} else if (firstSplitterFound && !secondSplitterFound) {
if (issplitter) {
secondSplitterFound = true;
splitter2 = i;
appletlist[i]->setParentItem(end);
} else {
appletlist[i]->setParentItem(main);
}
} else if (firstSplitterFound && secondSplitterFound) {
appletlist[i]->setParentItem(end);
}
}
for(int i=0; i<appletlist.count()-1; ++i) {
QQuickItem *before = appletlist[i];
QQuickItem *after = appletlist[i+1];
if (before->parentItem() == after->parentItem()) {
before->stackBefore(after);
}
}
//! Confirm Last item of End Layout
if (end->childItems().count() > 0) {
QQuickItem *lastItem = end->childItems()[end->childItems().count()-1];
int correctpos{-1};
for(int i=0; i<appletlist.count()-1; ++i) {
if (lastItem == appletlist[i]) {
correctpos = i;
break;
}
}
if (correctpos>=0) {
lastItem->stackBefore(appletlist[correctpos+1]);
}
}
}
}
}

View File

@ -93,7 +93,6 @@ public:
public slots:
Q_INVOKABLE void deactivateApplets();
Q_INVOKABLE void toggleAppletExpanded(const int id);
Q_INVOKABLE void moveAppletsInJustifyAlignment(QQuickItem *start, QQuickItem *main, QQuickItem *end);
Q_INVOKABLE bool appletIsExpandable(const int id);
Q_INVOKABLE bool appletIsExpanded(const int id);

View File

@ -5,6 +5,7 @@ plasma_install_package(package org.kde.latte.containment)
set(containment_SRCS
plugin/types.cpp
plugin/layoutmanager.cpp
plugin/lattecontainmentplugin.cpp
)
@ -12,7 +13,8 @@ add_library(lattecontainmentplugin SHARED ${containment_SRCS})
target_link_libraries(lattecontainmentplugin
Qt5::Core
Qt5::Qml)
Qt5::Qml
Qt5::Quick)
install(TARGETS lattecontainmentplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/latte/private/containment)
install(FILES plugin/qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/latte/private/containment)

View File

@ -872,13 +872,7 @@ Item {
function moveAppletsBasedOnJustifyAlignment() {
layouter.appletsInParentChange = true;
if (latteView) {
latteView.extendedInterface.moveAppletsInJustifyAlignment(layoutsContainer.startLayout,
layoutsContainer.mainLayout,
layoutsContainer.endLayout);
}
fastLayoutManager.moveAppletsInJustifyAlignment();
layouter.appletsInParentChange = false;
}
@ -948,6 +942,12 @@ Item {
id: colorScopePalette
}
LatteContainment.LayoutManager{
id:fastLayoutManager
mainLayout: layoutsContainer.mainLayout
startLayout: layoutsContainer.startLayout
endLayout: layoutsContainer.endLayout
}
///////////////BEGIN UI elements

View File

@ -20,6 +20,7 @@
#include "lattecontainmentplugin.h"
// local
#include "layoutmanager.h"
#include "types.h"
// Qt
@ -29,5 +30,6 @@ void LatteContainmentPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.latte.private.containment"));
qmlRegisterUncreatableType<Latte::Containment::Types>(uri, 0, 1, "Types", "Latte Containment Types uncreatable");
qmlRegisterType<Latte::Containment::LayoutManager>(uri, 0, 1, "LayoutManager");
}

View File

@ -0,0 +1,147 @@
/*
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
*
*
* This file is part of Latte-Dock and is a Fork of PlasmaCore::IconItem
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "layoutmanager.h"
//Qt
namespace Latte{
namespace Containment{
LayoutManager::LayoutManager(QObject *parent)
: QObject(parent)
{
}
QQuickItem *LayoutManager::mainLayout() const
{
return m_mainLayout;
}
void LayoutManager::setMainLayout(QQuickItem *main)
{
if (main == m_mainLayout) {
return;
}
m_mainLayout = main;
emit mainLayoutChanged();
}
QQuickItem *LayoutManager::startLayout() const
{
return m_startLayout;
}
void LayoutManager::setStartLayout(QQuickItem *start)
{
if (m_startLayout == start) {
return;
}
m_startLayout = start;
emit startLayoutChanged();
}
QQuickItem *LayoutManager::endLayout() const
{
return m_endLayout;
}
void LayoutManager::setEndLayout(QQuickItem *end)
{
if (m_endLayout == end) {
return;
}
m_endLayout = end;
emit endLayoutChanged();
}
//! Actions
void LayoutManager::moveAppletsInJustifyAlignment()
{
if (!m_startLayout || !m_mainLayout || !m_endLayout) {
return;
}
QList<QQuickItem *> appletlist;
appletlist << m_startLayout->childItems();
appletlist << m_mainLayout->childItems();
appletlist << m_endLayout->childItems();
bool firstSplitterFound{false};
bool secondSplitterFound{false};
int splitter1{-1};
int splitter2{-1};
for(int i=0; i<appletlist.count(); ++i) {
bool issplitter = appletlist[i]->property("isInternalViewSplitter").toBool();
if (!firstSplitterFound) {
appletlist[i]->setParentItem(m_startLayout);
if (issplitter) {
firstSplitterFound = true;
splitter1 = i;
}
} else if (firstSplitterFound && !secondSplitterFound) {
if (issplitter) {
secondSplitterFound = true;
splitter2 = i;
appletlist[i]->setParentItem(m_endLayout);
} else {
appletlist[i]->setParentItem(m_mainLayout);
}
} else if (firstSplitterFound && secondSplitterFound) {
appletlist[i]->setParentItem(m_endLayout);
}
}
for(int i=0; i<appletlist.count()-1; ++i) {
QQuickItem *before = appletlist[i];
QQuickItem *after = appletlist[i+1];
if (before->parentItem() == after->parentItem()) {
before->stackBefore(after);
}
}
//! Confirm Last item of End Layout
if (m_endLayout->childItems().count() > 0) {
QQuickItem *lastItem = m_endLayout->childItems()[m_endLayout->childItems().count()-1];
int correctpos{-1};
for(int i=0; i<appletlist.count()-1; ++i) {
if (lastItem == appletlist[i]) {
correctpos = i;
break;
}
}
if (correctpos>=0) {
lastItem->stackBefore(appletlist[correctpos+1]);
}
}
}
}
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
*
*
* This file is part of Latte-Dock and is a Fork of PlasmaCore::IconItem
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef CONTAINMENTLAYOUTMANAGER_H
#define CONTAINMENTLAYOUTMANAGER_H
//Qt
#include <QObject>
#include <QQuickItem>
namespace Latte{
namespace Containment{
class LayoutManager : public QObject
{
Q_OBJECT
Q_PROPERTY(QQuickItem *mainLayout READ mainLayout WRITE setMainLayout NOTIFY mainLayoutChanged)
Q_PROPERTY(QQuickItem *startLayout READ startLayout WRITE setStartLayout NOTIFY startLayoutChanged)
Q_PROPERTY(QQuickItem *endLayout READ endLayout WRITE setEndLayout NOTIFY endLayoutChanged)
public:
LayoutManager(QObject *parent = nullptr);
QQuickItem *mainLayout() const;
void setMainLayout(QQuickItem *main);
QQuickItem *startLayout() const;
void setStartLayout(QQuickItem *start);
QQuickItem *endLayout() const;
void setEndLayout(QQuickItem *end);
public slots:
Q_INVOKABLE void moveAppletsInJustifyAlignment();
signals:
void mainLayoutChanged();
void startLayoutChanged();
void endLayoutChanged();
private:
QQuickItem *m_mainLayout{nullptr};
QQuickItem *m_startLayout{nullptr};
QQuickItem *m_endLayout{nullptr};
};
}
}
#endif // CONTAINMENTLAYOUTMANAGER_H