|
|
|
@ -20,7 +20,10 @@
|
|
|
|
|
|
|
|
|
|
#include "layoutmanager.h"
|
|
|
|
|
|
|
|
|
|
//Qt
|
|
|
|
|
//! Plasma
|
|
|
|
|
#include <Plasma>
|
|
|
|
|
|
|
|
|
|
const int CHILDFOUNDID = 11;
|
|
|
|
|
|
|
|
|
|
namespace Latte{
|
|
|
|
|
namespace Containment{
|
|
|
|
@ -30,6 +33,41 @@ LayoutManager::LayoutManager(QObject *parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QObject *LayoutManager::plasmoid() const
|
|
|
|
|
{
|
|
|
|
|
return m_plasmoid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LayoutManager::setPlasmoid(QObject *plasmoid)
|
|
|
|
|
{
|
|
|
|
|
if (m_plasmoid == plasmoid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_plasmoid = plasmoid;
|
|
|
|
|
|
|
|
|
|
if (m_plasmoid) {
|
|
|
|
|
m_configuration = qobject_cast<QQmlPropertyMap *>(m_plasmoid->property("configuration").value<QObject *>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit plasmoidChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QQuickItem *LayoutManager::rootItem() const
|
|
|
|
|
{
|
|
|
|
|
return m_rootItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LayoutManager::setRootItem(QQuickItem *root)
|
|
|
|
|
{
|
|
|
|
|
if (m_rootItem == root) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_rootItem = root;
|
|
|
|
|
emit rootItemChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QQuickItem *LayoutManager::mainLayout() const
|
|
|
|
|
{
|
|
|
|
|
return m_mainLayout;
|
|
|
|
@ -75,7 +113,125 @@ void LayoutManager::setEndLayout(QQuickItem *end)
|
|
|
|
|
emit endLayoutChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QQuickItem *LayoutManager::metrics() const
|
|
|
|
|
{
|
|
|
|
|
return m_metrics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LayoutManager::setMetrics(QQuickItem *metrics)
|
|
|
|
|
{
|
|
|
|
|
if (m_metrics == metrics) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_metrics = metrics;
|
|
|
|
|
emit metricsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Actions
|
|
|
|
|
|
|
|
|
|
bool LayoutManager::insertAtLayoutCoordinates(QQuickItem *layout, QQuickItem *item, int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (!layout || !item || !m_plasmoid) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool horizontal = (m_plasmoid->property("formFactor").toInt() != Plasma::Types::Vertical);
|
|
|
|
|
bool vertical = !horizontal;
|
|
|
|
|
int rowspacing = qMax(0, layout->property("rowSpacing").toInt());
|
|
|
|
|
int columnspacing = qMax(0, layout->property("columnSpacing").toInt());
|
|
|
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
|
y = layout->height() / 2;
|
|
|
|
|
} else {
|
|
|
|
|
x = layout->width() / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! child renamed at hovered
|
|
|
|
|
QQuickItem *hovered = layout->childAt(x, y);
|
|
|
|
|
|
|
|
|
|
//if we got a place inside the space between 2 applets, we have to find it manually
|
|
|
|
|
if (!hovered) {
|
|
|
|
|
int size = layout->childItems().count();
|
|
|
|
|
if (horizontal) {
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
QQuickItem *candidate = layout->childItems()[i];
|
|
|
|
|
int right = candidate->x() + candidate->width() + rowspacing;
|
|
|
|
|
if (x>=candidate->x() && x<right) {
|
|
|
|
|
hovered = candidate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
QQuickItem *candidate = layout->childItems()[i];
|
|
|
|
|
int bottom = candidate->y() + candidate->height() + columnspacing;
|
|
|
|
|
if (y>=candidate->y() && y<bottom) {
|
|
|
|
|
hovered = candidate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hovered == item && item->parentItem() == layout) {
|
|
|
|
|
//! already hovered and in correct position
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hovered) {
|
|
|
|
|
QQuickItem *totals = m_metrics->property("totals").value<QQuickItem *>();
|
|
|
|
|
float neededspace = 1.5 * (m_metrics->property("iconSize").toFloat() + totals->property("lengthEdge").toFloat());
|
|
|
|
|
|
|
|
|
|
if ( ((vertical && ((y-neededspace) <= layout->height()) && (y>=0))
|
|
|
|
|
|| (horizontal && ((x-neededspace) <= layout->width()) && (x>=0)))
|
|
|
|
|
&& layout->childItems().count()>0) {
|
|
|
|
|
//! last item
|
|
|
|
|
qDebug() << "org.kde.latte << last item ..";
|
|
|
|
|
hovered = layout->childItems()[layout->childItems().count()-1];
|
|
|
|
|
} else if ( ((vertical && (y >= -neededspace) && (y<=neededspace)))
|
|
|
|
|
|| (horizontal && (x >= -neededspace) && (x<=neededspace))
|
|
|
|
|
&& layout->childItems().count()>0) {
|
|
|
|
|
//! first item
|
|
|
|
|
qDebug() << "org.kde.latte << first item ..";
|
|
|
|
|
hovered = layout->childItems()[0];
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item->setParentItem(layout);
|
|
|
|
|
|
|
|
|
|
if ((vertical && y < (hovered->y() + hovered->height()/2)) ||
|
|
|
|
|
(horizontal && x < hovered->x() + hovered->width()/2)) {
|
|
|
|
|
item->stackBefore(hovered);
|
|
|
|
|
} else {
|
|
|
|
|
item->stackAfter(hovered);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LayoutManager::insertAtCoordinates(QQuickItem *item, const int &x, const int &y)
|
|
|
|
|
{
|
|
|
|
|
bool result{false};
|
|
|
|
|
|
|
|
|
|
QPointF startPos = m_startLayout->mapFromItem(m_rootItem, QPointF(x, y));
|
|
|
|
|
result = insertAtLayoutCoordinates(m_startLayout, item, startPos.x(), startPos.y());
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
QPointF endPos = m_endLayout->mapFromItem(m_rootItem, QPointF(x, y));
|
|
|
|
|
result = insertAtLayoutCoordinates(m_endLayout, item, endPos.x(), endPos.y());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
QPointF mainPos = m_mainLayout->mapFromItem(m_rootItem, QPointF(x, y));
|
|
|
|
|
//! in javascript direct insertAtCoordinates was usedd ???
|
|
|
|
|
result = insertAtLayoutCoordinates(m_mainLayout, item, mainPos.x(), mainPos.y());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LayoutManager::moveAppletsInJustifyAlignment()
|
|
|
|
|
{
|
|
|
|
|
if (!m_startLayout || !m_mainLayout || !m_endLayout) {
|
|
|
|
|