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 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 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 <QtGui/QGraphicsLayout>
28 #include <plasma/plasma_export.h>
29 #include <plasma/plasma.h>
34 * Node layout has an advanced layouting mechanism. Every item's position
35 * is defined by two nodes - one for top-left corner, and the other one for
36 * bottom-right corner.
38 * Each node is defined by a pair of relative (xr, yr) and a pair of
39 * absolute (xa, ya) coordinates. The calculated node coordinates depend
40 * on the size and position of the NodeLayout object in the following
42 * x = layoutLeft + (xr * layoutWidth) + xa
43 * y = layoutTop + (yr * layoutHeight) + ya
45 * Alternatively, the item's position can be defined by using one node and
46 * one pair of relative coordinates (xr, yr). In that case, the item is sized
47 * following the sizeHint(). The relative coordinates (this time they are
48 * relative to the item's geometry, not the layout's) specify what point of
49 * the item will be bound to the defined node.
52 class PLASMA_EXPORT NodeLayout
: public QGraphicsLayout
{
54 class PLASMA_EXPORT NodeCoordinate
{
57 * Position is calculated:
58 * x = parentLeft + (xRelative * parentWidth) + xAbsolute
59 * y = parentTop + (yRelative * parentHeight) + yAbsolute
61 explicit NodeCoordinate(qreal xRelative
= 0, qreal yRelative
= 0, qreal xAbsolute
= 0, qreal yAbsolute
= 0);
68 static NodeCoordinate
simple(qreal x
, qreal y
, CoordinateType xType
= Relative
, CoordinateType yType
= Relative
);
74 explicit NodeLayout(QGraphicsLayoutItem
* parent
= 0);
75 virtual ~NodeLayout();
80 * Adds item at top-left corner, with automatic sizing
81 * (using sizeHint of the item)
83 void addItem (QGraphicsLayoutItem
* item
);
86 * Adds item with specified top-left and bottom right corners.
88 void addItem (QGraphicsLayoutItem
* item
,
89 NodeCoordinate topLeft
, NodeCoordinate bottomRight
);
92 * Adds item with automatic sizing turned on. xr and yr specify
93 * which point of the item is bound to node coordinate. Those
94 * are relative coordinates so (0, 0) represent top left corner,
95 * (0.5, 0.5) represent the center of the item etc.
97 void addItem (QGraphicsLayoutItem
* item
,
98 NodeCoordinate node
, qreal xr
= 0, qreal yr
= 0);
100 void removeItem (QGraphicsLayoutItem
* item
);
102 virtual int count() const;
103 virtual int indexOf(QGraphicsLayoutItem
* item
) const;
104 virtual QGraphicsLayoutItem
* itemAt(int i
) const;
105 virtual QGraphicsLayoutItem
* takeAt(int i
);
109 QSizeF
sizeHint(Qt::SizeHint which
, const QSizeF
&constraint
= QSizeF()) const;
118 #endif /* PLASMA_NODE_LAYOUT */