Changeset View
Changeset View
Standalone View
Standalone View
components/containmentlayoutmanager/gridlayoutmanager.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 by Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | * | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include "abstractlayoutmanager.h" | ||||
24 | #include "appletcontainer.h" | ||||
25 | | ||||
26 | class AppletsLayout; | ||||
27 | class ItemContainer; | ||||
28 | | ||||
29 | struct Geom { | ||||
30 | int x; | ||||
31 | int y; | ||||
32 | int width; | ||||
33 | int height; | ||||
34 | int rotation; | ||||
35 | }; | ||||
36 | | ||||
37 | class GridLayoutManager : public AbstractLayoutManager | ||||
38 | { | ||||
39 | Q_OBJECT | ||||
40 | | ||||
41 | public: | ||||
42 | GridLayoutManager(AppletsLayout *layout); | ||||
43 | ~GridLayoutManager(); | ||||
44 | | ||||
45 | void layoutGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; | ||||
46 | | ||||
47 | QString serializeLayout() const override; | ||||
48 | void parseLayout(const QString &savedLayout) override; | ||||
49 | | ||||
50 | bool itemIsManaged(ItemContainer *item) override; | ||||
51 | | ||||
52 | void resetLayout() override; | ||||
53 | void resetLayoutFromConfig() override; | ||||
54 | | ||||
55 | bool restoreItem(ItemContainer *item) override; | ||||
56 | | ||||
57 | bool isRectAvailable(const QRectF &rect) override; | ||||
58 | | ||||
59 | | ||||
60 | | ||||
61 | protected: | ||||
62 | // The rectangle as near as possible to the current item geometry which can fit it | ||||
63 | QRectF nextAvailableSpace(ItemContainer *item, const QSizeF &minimumSize, AppletsLayout::PreferredLayoutDirection direction) const override; | ||||
64 | | ||||
65 | bool assignSpaceImpl(ItemContainer *item) override; | ||||
66 | void releaseSpaceImpl(ItemContainer *item) override; | ||||
67 | | ||||
68 | private: | ||||
69 | // Total cell rows | ||||
70 | inline int rows() const; | ||||
71 | | ||||
72 | // Total cell columns | ||||
73 | inline int columns() const; | ||||
74 | | ||||
75 | // Converts the item pixel-based geometry to a cellsize-based geometry | ||||
76 | inline QRect cellBasedGeometry(const QRectF &geom) const; | ||||
77 | | ||||
78 | // Converts the item pixel-based geometry to a cellsize-based geometry | ||||
79 | // This is the bounding geometry, usually larger than cellBasedGeometry | ||||
80 | inline QRect cellBasedBoundingGeometry(const QRectF &geom) const; | ||||
81 | | ||||
82 | // true if the cell is out of the bounds of the containment | ||||
83 | inline bool isOutOfBounds(const QPair<int, int> &cell) const; | ||||
84 | | ||||
85 | // True if the space for the given cell is available | ||||
86 | inline bool isCellAvailable(const QPair<int, int> &cell) const; | ||||
87 | | ||||
88 | // Returns the qrect geometry for an item | ||||
89 | inline QRectF itemGeometry(QQuickItem *item) const; | ||||
90 | | ||||
91 | // The next cell given the direction | ||||
92 | QPair<int, int> nextCell(const QPair<int, int> &cell, AppletsLayout::PreferredLayoutDirection direction) const; | ||||
93 | | ||||
94 | // The next cell that is available given the direction | ||||
95 | QPair<int, int> nextAvailableCell(const QPair<int, int> &cell, AppletsLayout::PreferredLayoutDirection direction) const; | ||||
96 | | ||||
97 | // How many cells are available in the row starting from the given cell and direction | ||||
98 | int freeSpaceInDirection(const QPair<int, int> &cell, AppletsLayout::PreferredLayoutDirection direction) const; | ||||
99 | | ||||
100 | | ||||
101 | // 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 indicization by QPointF | ||||
102 | QHash <QPair<int, int>, ItemContainer *> m_grid; | ||||
103 | QHash <ItemContainer *, QSet<QPair<int, int> > > m_pointsForItem; | ||||
104 | | ||||
105 | QHash <QString, Geom> m_parsedConfig; | ||||
106 | }; | ||||
107 | |