Settings: unify duplicated code
[lxde/liblxqt.git] / lxqtgridlayout.h
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXQt - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright: 2012 Razor team
8 * Authors:
9 * Alexander Sokoloff <sokoloff.a@gmail.com>
10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27
28
29 #ifndef LXQTGRIDLAYOUT_H
30 #define LXQTGRIDLAYOUT_H
31
32 #include <QList>
33 #include "lxqtglobals.h"
34 #include <QLayout>
35
36
37 namespace LXQt
38 {
39
40 class GridLayoutPrivate;
41
42 /**
43 The GridLayout class lays out widgets in a grid.
44 **/
45 class LXQT_API GridLayout: public QLayout
46 {
47 Q_OBJECT
48 public:
49 /**
50 This enum type is used to describe direction for this grid.
51 **/
52 enum Direction
53 {
54 LeftToRight, ///< The items are first laid out horizontally and then vertically.
55 TopToBottom ///< The items are first laid out vertically and then horizontally.
56 };
57
58 /**
59 This enum type is used to describe stretch. It contains one horizontal
60 and one vertical flags that can be combined to produce the required effect.
61 */
62 enum StretchFlag
63 {
64 NoStretch = 0, ///< No justifies items
65 StretchHorizontal = 1, ///< Justifies items in the available horizontal space
66 StretchVertical = 2 ///< Justifies items in the available vertical space
67 };
68 Q_DECLARE_FLAGS(Stretch, StretchFlag)
69
70
71
72 /**
73 Constructs a new GridLayout with parent widget, parent.
74 The layout has one row and zero column initially, and will
75 expand to left when new items are inserted.
76 **/
77 explicit GridLayout(QWidget *parent = 0);
78
79 /**
80 Destroys the grid layout. The layout's widgets aren't destroyed.
81 **/
82 ~GridLayout();
83
84 void addItem(QLayoutItem *item);
85 QLayoutItem *itemAt(int index) const;
86 QLayoutItem *takeAt(int index);
87 int count() const;
88 void invalidate();
89
90 QSize sizeHint() const;
91 void setGeometry(const QRect &geometry);
92 QRect occupiedGeometry() const;
93
94
95 /**
96 Returns the number of rows in this grid.
97 **/
98 int rowCount() const;
99
100 /**
101 Sets the number of rows in this grid. If value is 0, then rows
102 count will calculated automatically when new items are inserted.
103
104 In the most cases you should to set fixed number for one thing,
105 or for rows, or for columns.
106
107 \sa GridLayout::setColumnCount
108 **/
109 void setRowCount(int value);
110
111
112 /**
113 Returns the number of columns in this grid.
114 **/
115 int columnCount() const;
116
117 /**
118 Sets the number of columns in this grid. If value is 0, then columns
119 count will calculated automatically when new items are inserted.
120
121 In the most cases you should to set fixed number for one thing,
122 or for rows, or for columns.
123
124 \sa GridLayout::setRowCount
125 **/
126 void setColumnCount(int value);
127
128
129 /**
130 Returns the alignment of this grid.
131
132 \sa GridLayout::Direction
133 **/
134 Direction direction() const;
135
136 /**
137 Sets the direction for this grid.
138
139 \sa GridLayout::Direction
140 **/
141 void setDirection(Direction value);
142
143 /**
144 Returns the stretch flags of this grid.
145
146 \sa GridLayout::StretchFlag
147 **/
148 Stretch stretch() const;
149
150 /**
151 Sets the stretch flags for this grid.
152
153 \sa GridLayout::StretchFlag
154 **/
155 void setStretch(Stretch value);
156
157 /**
158 Moves the item at index position \param from to index position \param to.
159 If \param withAnimation set the reordering will be animated
160 **/
161 void moveItem(int from, int to, bool withAnimation = false);
162
163 /**
164 Checks if layout is currently animated after the \sa moveItem()
165 invocation.
166 **/
167 bool animatedMoveInProgress() const;
168
169 /**
170 Returns the cells' minimum size.
171 By default, this property contains a size with zero width and height.
172 **/
173 QSize cellMinimumSize() const;
174
175 /**
176 Sets the minimum size of all cells to minSize pixels.
177 **/
178 void setCellMinimumSize(QSize minSize);
179
180 /**
181 Sets the minimum height of the cells to value without
182 changing the width. Provided for convenience.
183 **/
184 void setCellMinimumHeight(int value);
185
186 /**
187 Sets the minimum width of the cells to value without
188 changing the heights. Provided for convenience.
189 **/
190 void setCellMinimumWidth(int value);
191
192
193
194 /**
195 Returns the cells' maximum size.
196 By default, this property contains a size with zero width and height.
197 **/
198 QSize cellMaximumSize() const;
199
200 /**
201 Sets the maximum size of all cells to maxSize pixels.
202 **/
203 void setCellMaximumSize(QSize maxSize);
204
205 /**
206 Sets the maximum height of the cells to value without
207 changing the width. Provided for convenience.
208 **/
209 void setCellMaximumHeight(int value);
210
211 /**
212 Sets the maximum width of the cells to value without
213 changing the heights. Provided for convenience.
214 **/
215 void setCellMaximumWidth(int value);
216
217
218
219 /**
220 Sets both the minimum and maximum sizes of the cells to size,
221 thereby preventing it from ever growing or shrinking.
222 **/
223 void setCellFixedSize(QSize size);
224
225 /**
226 Sets both the minimum and maximum height of the cells to value without
227 changing the width. Provided for convenience.
228 **/
229 void setCellFixedHeight(int value);
230
231 /**
232 Sets both the minimum and maximum width of the cells to value without
233 changing the heights. Provided for convenience.
234 **/
235 void setCellFixedWidth(int value);
236
237 private:
238 GridLayoutPrivate* const d_ptr;
239 Q_DECLARE_PRIVATE(GridLayout)
240 };
241
242 Q_DECLARE_OPERATORS_FOR_FLAGS(GridLayout::Stretch)
243
244 } // namespace LXQt
245 #endif // LXQTGRIDLAYOUT_H