diff --git a/components/containmentlayoutmanager/appletslayout.cpp b/components/containmentlayoutmanager/appletslayout.cpp index 7e3bdea4e..6ac980175 100644 --- a/components/containmentlayoutmanager/appletslayout.cpp +++ b/components/containmentlayoutmanager/appletslayout.cpp @@ -370,12 +370,13 @@ void AppletsLayout::showPlaceHolderAt(const QRectF &geom) m_placeHolder->setProperty("opacity", 1); } -void AppletsLayout::showPlaceHolderForItem(QQuickItem *item) +void AppletsLayout::showPlaceHolderForItem(ItemContainer *item) { if (!m_placeHolder) { return; } + m_placeHolder->setPreferredLayoutDirection(item->preferredLayoutDirection()); m_placeHolder->setPosition(item->position()); m_placeHolder->setSize(item->size()); diff --git a/components/containmentlayoutmanager/appletslayout.h b/components/containmentlayoutmanager/appletslayout.h index 43a6d16fb..781f2e007 100644 --- a/components/containmentlayoutmanager/appletslayout.h +++ b/components/containmentlayoutmanager/appletslayout.h @@ -130,7 +130,7 @@ public: Q_INVOKABLE void save(); Q_INVOKABLE void showPlaceHolderAt(const QRectF &geom); - Q_INVOKABLE void showPlaceHolderForItem(QQuickItem *item); + Q_INVOKABLE void showPlaceHolderForItem(ItemContainer *item); Q_INVOKABLE void hidePlaceHolder(); Q_INVOKABLE bool isRectAvailable(qreal x, qreal y, qreal width, qreal height); diff --git a/components/containmentlayoutmanager/gridlayoutmanager.cpp b/components/containmentlayoutmanager/gridlayoutmanager.cpp index 7574882c6..fb8a126bc 100644 --- a/components/containmentlayoutmanager/gridlayoutmanager.cpp +++ b/components/containmentlayoutmanager/gridlayoutmanager.cpp @@ -412,6 +412,42 @@ QPair GridLayoutManager::nextAvailableCell(const QPair &cell return QPair(-1, -1); } +QPair GridLayoutManager::nextTakenCell(const QPair &cell, AppletsLayout::PreferredLayoutDirection direction) const +{ + QPair nCell = cell; + while (!isOutOfBounds(nCell)) { + nCell = nextCell(nCell, direction); + + if (isOutOfBounds(nCell)) { + switch (direction) { + case AppletsLayout::AppletsLayout::BottomToTop: + nCell.first = rows() - 1; + --nCell.second; + break; + case AppletsLayout::AppletsLayout::TopToBottom: + nCell.first = 0; + ++nCell.second; + break; + case AppletsLayout::AppletsLayout::RightToLeft: + --nCell.first; + nCell.second = columns() - 1; + break; + case AppletsLayout::AppletsLayout::LeftToRight: + default: + ++nCell.first; + nCell.second = 0; + break; + } + } + + if (!isCellAvailable(nCell)) { + return nCell; + } + } + + return QPair(-1, -1); +} + int GridLayoutManager::freeSpaceInDirection(const QPair &cell, AppletsLayout::PreferredLayoutDirection direction) const { QPair nCell = cell; @@ -447,11 +483,11 @@ QRectF GridLayoutManager::nextAvailableSpace(ItemContainer *item, const QSizeF & cell.first += itemCellGeom.height(); } - while (!isOutOfBounds(cell)) { + if (!isCellAvailable(cell)) { + cell = nextAvailableCell(cell, direction); + } - if (!isCellAvailable(cell)) { - cell = nextAvailableCell(cell, direction); - } + while (!isOutOfBounds(cell)) { if (direction == AppletsLayout::LeftToRight || direction == AppletsLayout::RightToLeft) { partialSize = QSize(INT_MAX, 0); @@ -494,7 +530,7 @@ QRectF GridLayoutManager::nextAvailableSpace(ItemContainer *item, const QSizeF & width, height); } } else { - cell.first = currentRow + 1; + cell = nextAvailableCell(nextTakenCell(cell, direction), direction); } } else if (direction == AppletsLayout::TopToBottom || direction == AppletsLayout::BottomToTop) { @@ -538,7 +574,7 @@ QRectF GridLayoutManager::nextAvailableSpace(ItemContainer *item, const QSizeF & width, height); } } else { - cell.second = currentColumn + 1; + cell = nextAvailableCell(nextTakenCell(cell, direction), direction); } } } diff --git a/components/containmentlayoutmanager/gridlayoutmanager.h b/components/containmentlayoutmanager/gridlayoutmanager.h index a5f1b0cd4..0c5a7810e 100644 --- a/components/containmentlayoutmanager/gridlayoutmanager.h +++ b/components/containmentlayoutmanager/gridlayoutmanager.h @@ -94,6 +94,9 @@ private: // The next cell that is available given the direction QPair nextAvailableCell(const QPair &cell, AppletsLayout::PreferredLayoutDirection direction) const; + // The next cell that is has something in it given the direction + QPair nextTakenCell(const QPair &cell, AppletsLayout::PreferredLayoutDirection direction) const; + // How many cells are available in the row starting from the given cell and direction int freeSpaceInDirection(const QPair &cell, AppletsLayout::PreferredLayoutDirection direction) const;