2
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library/Lesser General Public License
6
* version 2, or (at your option) any later version, as published by the
7
* Free Software Foundation
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 General Public License for more details
14
* You should have received a copy of the GNU Library/Lesser 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.
20
#ifndef PLASMA_NODE_LAYOUT
21
#define PLASMA_NODE_LAYOUT
23
#include <QtCore/QMap>
26
#include <plasma/plasma_export.h>
27
#include <plasma/plasma.h>
28
#include <plasma/widgets/layout.h>
33
* Node layout has an advanced layouting mechanism. Every item's position
34
* is defined by two nodes - one for top-left corner, and the other one for
35
* bottom-right corner.
37
* Each node is defined by a pair of relative (xr, yr) and a pair of
38
* absolute (xa, ya) coordinates. The calculated node coordinates depend
39
* on the size and position of the NodeLayout object in the following
41
* x = layoutLeft + (xr * layoutWidth) + xa
42
* y = layoutTop + (yr * layoutHeight) + ya
44
* Alternatively, the item's position can be defined by using one node and
45
* one pair of relative coordinates (xr, yr). In that case, the item is sized
46
* following the sizeHint(). The relative coordinates (this time they are
47
* relative to the item's geometry, not the layout's) specify what point of
48
* the item will be bound to the defined node.
51
class PLASMA_EXPORT NodeLayout : public Layout {
53
class PLASMA_EXPORT NodeCoordinate {
56
* Position is calculated:
57
* x = parentLeft + (xRelative * parentWidth) + xAbsolute
58
* y = parentTop + (yRelative * parentHeight) + yAbsolute
60
NodeCoordinate(qreal xRelative = 0, qreal yRelative = 0, qreal xAbsolute = 0, qreal yAbsolute = 0);
67
static NodeCoordinate simple(qreal x, qreal y, CoordinateType xType = Relative, CoordinateType yType = Relative);
74
virtual Qt::Orientations expandingDirections() const;
76
explicit NodeLayout(LayoutItem * parent = 0);
77
virtual ~NodeLayout();
79
virtual QRectF geometry() const;
80
void setGeometry(const QRectF& geometry);
82
QSizeF sizeHint() const;
85
* Adds item at top-left corner, with automatic sizing
86
* (using sizeHint of the item)
88
void addItem (LayoutItem * item);
91
* Adds item with specified top-left and bottom right corners.
93
void addItem (LayoutItem * item,
94
NodeCoordinate topLeft, NodeCoordinate bottomRight);
97
* Adds item with automatic sizing turned on. xr and yr specify
98
* which point of the item is bound to node coordinate. Those
99
* are relative coordinates so (0, 0) represent top left corner,
100
* (0.5, 0.5) represent the center of the item etc.
102
void addItem (LayoutItem * item,
103
NodeCoordinate node, qreal xr = 0, qreal yr = 0);
105
void removeItem (LayoutItem * item);
107
virtual int count() const;
108
virtual int indexOf(LayoutItem * item) const;
109
virtual LayoutItem * itemAt(int i) const;
110
virtual LayoutItem * takeAt(int i);
119
#endif /* PLASMA_NODE_LAYOUT */