not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / containments / desktop / desktoplayout.h
blob8c893b0e05d5666cf61716b0a53e68d6f717a960
1 /*
2 Copyright (c) 2008 Ambroz Bizjak <ambro@b4ever.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 */
10 #ifndef _DESKTOPLAYOUT_H
11 #define _DESKTOPLAYOUT_H
13 #include <QGraphicsLayout>
14 #include <QHash>
15 #include <QMap>
16 #include <QList>
17 #include <QObject>
19 #include "itemspace.h"
21 class QGraphicsItem;
23 class DesktopLayout : public QObject, public QGraphicsLayout
25 Q_OBJECT
27 public:
28 DesktopLayout (QGraphicsLayoutItem *parent = 0);
30 /**
31 * Adds a new item.
32 * The item will be automatically positioned.
34 * @param item the item to add
35 * @param pushBack if the item should attempt to always be in its preferred position;
36 * if false, it will only move when pushed by other items or edges
37 * of the working area
38 * @param size the size initial size of the item; if invalid or not supplied,
39 * the PreferredSize hint will be used
40 **/
41 void addItem(QGraphicsLayoutItem *item, bool pushBack = true, const QSizeF &size = QSizeF());
43 /**
44 * Adds a previously managed item.
45 **/
46 void addItem(QGraphicsLayoutItem *item, bool pushBack, const QRectF &preferredGeom, const QRectF &lastGeom = QRectF());
48 bool getPushBack(int index);
49 QRectF getPreferredGeometry(int index);
50 QRectF getLastGeometry(int index);
52 /**
53 * Sets spacing required between an item and
54 * the edge of the working area when a new item is positioned.
55 **/
56 void setPlacementSpacing(qreal spacing);
58 /**
59 * Sets spacing between an item and the edge of
60 * the working area when items are being pushed around
61 * and when an item is moved by the user.
62 **/
63 void setScreenSpacing(qreal spacing);
65 /**
66 * Sets spacing between items when items are being pushed around.
67 **/
68 void setShiftingSpacing(qreal spacing);
70 /**
71 * Sets the tolerance for temporary placement in terms of surface
72 * of the item concerned.
73 **/
74 void setVisibilityTolerance(qreal part);
76 /**
77 * Sets whether the working area should always be
78 * considered the geometry of the managed widget.
79 * Default is on.
80 **/
81 void setAutoWorkingArea(bool value);
83 /**
84 * Sets the area of the widget where items can be displayed.
85 * If you turned off auto working area, you have to use
86 * this function to adjust it manually every time it changes.
87 **/
88 void setWorkingArea(QRectF area);
90 /**
91 * Sets the alignment.
92 * This defines the sides of the working area where items are
93 * pushed inside in case the working area shrinks.
94 * Default is Qt::AlignTop|Qt::AlignLeft which pushes items on
95 * the right and the bottom sides.
96 **/
97 void setAlignment(Qt::Alignment alignment);
99 /**
100 * Enables or disables temporary placement.
102 void setTemporaryPlacement(bool enabled);
105 * Checks if the specified item's geometry has been changed externally
106 * and sets its preferred position to the current position.
107 * Call this when an item has been manually moved or resized.
109 void itemGeometryChanged(QGraphicsLayoutItem *layoutItem);
111 // inherited from QGraphicsLayout
112 int count() const;
113 QGraphicsLayoutItem *itemAt(int index) const;
114 void removeAt(int index);
116 // inherited from QGraphicsLayoutItem
117 void setGeometry(const QRectF &rect);
118 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
120 private slots:
121 void movementFinished(QGraphicsItem*);
123 private:
125 class DesktopLayoutItem
127 public:
128 QGraphicsLayoutItem *item;
129 QRectF temporaryGeometry;
132 int newItemKey();
134 // layout status
137 * The ItemSpace where items are stored and calculations are done.
138 * We use the 'user' item option as an identifier that survives
139 * regrouping.
141 ItemSpace itemSpace;
144 * Item-specific data that cannot be stored in the ItemSpace.
145 * Maps integer IDs in the 'user' item field to their local data.
147 QMap<int, DesktopLayoutItem> items;
149 QHash<QGraphicsItem*, int> m_animatingItems;
150 QPointF workingStart;
152 // layout configuration
154 bool autoWorkingArea;
155 bool temporaryPlacement;
157 qreal visibilityTolerance;
159 // item manipulation functions
160 void performTemporaryPlacement(int group, int itemInGroup);
161 void revertTemporaryPlacement(int group, int itemInGroup);
163 bool m_activated;
166 #endif