~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to libs/plasma/widgets/nodelayout.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-31 19:16:54 UTC
  • Revision ID: james.westby@ubuntu.com-20071031191654-xuof6e1jg6uxqaze
Tags: 3.95.0-0ubuntu1~gutsy1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
 
3
 *
 
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
 
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 General Public License for more details
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#ifndef PLASMA_NODE_LAYOUT
 
21
#define PLASMA_NODE_LAYOUT
 
22
 
 
23
#include <QtCore/QMap>
 
24
#include <cmath>
 
25
 
 
26
#include <plasma/plasma_export.h>
 
27
#include <plasma/plasma.h>
 
28
#include <plasma/widgets/layout.h>
 
29
 
 
30
namespace Plasma {
 
31
 
 
32
/**
 
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.
 
36
 * 
 
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
 
40
 * manner:
 
41
 *   x = layoutLeft + (xr * layoutWidth)  + xa
 
42
 *   y = layoutTop  + (yr * layoutHeight) + ya
 
43
 *
 
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.
 
49
 */
 
50
 
 
51
class PLASMA_EXPORT NodeLayout : public Layout {
 
52
public:
 
53
    class PLASMA_EXPORT NodeCoordinate {
 
54
    public:
 
55
        /**
 
56
         * Position is calculated:
 
57
         * x = parentLeft + (xRelative * parentWidth)  + xAbsolute
 
58
         * y = parentTop  + (yRelative * parentHeight) + yAbsolute
 
59
         */
 
60
        NodeCoordinate(qreal xRelative = 0, qreal yRelative = 0, qreal xAbsolute = 0, qreal yAbsolute = 0);
 
61
 
 
62
        enum CoordinateType {
 
63
            Relative = 0,
 
64
            Absolute = 1,
 
65
            InnerRelative = 2 };
 
66
 
 
67
        static NodeCoordinate simple(qreal x, qreal y, CoordinateType xType = Relative, CoordinateType yType = Relative);
 
68
 
 
69
        float xr, xa;
 
70
        float yr, ya;
 
71
    };
 
72
 
 
73
    // reimplemented
 
74
    virtual Qt::Orientations expandingDirections() const;
 
75
 
 
76
    explicit NodeLayout(LayoutItem * parent = 0);
 
77
    virtual ~NodeLayout();
 
78
 
 
79
    virtual QRectF geometry() const;
 
80
    void setGeometry(const QRectF& geometry);
 
81
 
 
82
    QSizeF sizeHint() const;
 
83
 
 
84
    /**
 
85
     * Adds item at top-left corner, with automatic sizing
 
86
     * (using sizeHint of the item)
 
87
     */
 
88
    void addItem (LayoutItem * item);
 
89
 
 
90
    /**
 
91
     * Adds item with specified top-left and bottom right corners.
 
92
     */
 
93
    void addItem (LayoutItem * item,
 
94
            NodeCoordinate topLeft, NodeCoordinate bottomRight);
 
95
 
 
96
    /**
 
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.
 
101
     */
 
102
    void addItem (LayoutItem * item,
 
103
            NodeCoordinate node, qreal xr = 0, qreal yr = 0);
 
104
 
 
105
    void removeItem (LayoutItem * item);
 
106
 
 
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);
 
111
 
 
112
private:
 
113
    class Private;
 
114
    Private * const d;
 
115
};
 
116
 
 
117
}
 
118
 
 
119
#endif /* PLASMA_NODE_LAYOUT */