1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
#include "abstractlayoutmanager.h"
#include "appletcontainer.h"
class AppletsLayout;
class ItemContainer;
struct Geom {
qreal x;
qreal y;
qreal width;
qreal height;
qreal rotation;
};
class GridLayoutManager : public AbstractLayoutManager
{
Q_OBJECT
public:
GridLayoutManager(AppletsLayout *layout);
~GridLayoutManager();
void layoutGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
QString serializeLayout() const override;
void parseLayout(const QString &savedLayout) override;
bool itemIsManaged(ItemContainer *item) override;
void resetLayout() override;
void resetLayoutFromConfig(const QRectF &newGeom, const QRectF &oldGeom) override;
bool restoreItem(ItemContainer *item) override;
bool isRectAvailable(const QRectF &rect) override;
protected:
// The rectangle as near as possible to the current item geometry which can fit it
QRectF nextAvailableSpace(ItemContainer *item, const QSizeF &minimumSize, AppletsLayout::PreferredLayoutDirection direction) const override;
bool assignSpaceImpl(ItemContainer *item) override;
void releaseSpaceImpl(ItemContainer *item) override;
private:
// Total cell rows
inline int rows() const;
// Total cell columns
inline int columns() const;
// Converts the item pixel-based geometry to a cellsize-based geometry
inline QRect cellBasedGeometry(const QRectF &geom) const;
// Converts the item pixel-based geometry to a cellsize-based geometry
// This is the bounding geometry, usually larger than cellBasedGeometry
inline QRect cellBasedBoundingGeometry(const QRectF &geom) const;
// true if the cell is out of the bounds of the containment
inline bool isOutOfBounds(const QPair<int, int> &cell) const;
// True if the space for the given cell is available
inline bool isCellAvailable(const QPair<int, int> &cell) const;
// Returns the qrect geometry for an item
inline QRectF itemGeometry(QQuickItem *item) const;
// The next cell given the direction
QPair<int, int> nextCell(const QPair<int, int> &cell, AppletsLayout::PreferredLayoutDirection direction) const;
// The next cell that is available given the direction
QPair<int, int> nextAvailableCell(const QPair<int, int> &cell, AppletsLayout::PreferredLayoutDirection direction) const;
// The next cell that is has something in it given the direction
QPair<int, int> nextTakenCell(const QPair<int, int> &cell, AppletsLayout::PreferredLayoutDirection direction) const;
// How many cells are available in the row starting from the given cell and direction
int freeSpaceInDirection(const QPair<int, int> &cell, AppletsLayout::PreferredLayoutDirection direction) const;
/**
* This reacts to changes in size hints by an item
*/
void adjustToItemSizeHints(ItemContainer *item);
// What is the item that occupies the point. The point is expressed in cells rather than pixels. a qpair rather a QPointF as QHash doesn't support
// identification by QPointF
QHash<QPair<int, int>, ItemContainer *> m_grid;
QHash<ItemContainer *, QSet<QPair<int, int>>> m_pointsForItem;
QHash<QString, Geom> m_parsedConfig;
};
|