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.
10 #ifndef _DESKTOPLAYOUT_H
11 #define _DESKTOPLAYOUT_H
13 #include <QGraphicsLayout>
19 #include "itemspace.h"
23 class DesktopLayout
: public QObject
, public QGraphicsLayout
28 DesktopLayout (QGraphicsLayoutItem
*parent
= 0);
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
38 * @param size the size initial size of the item; if invalid or not supplied,
39 * the PreferredSize hint will be used
41 void addItem(QGraphicsLayoutItem
*item
, bool pushBack
= true, const QSizeF
&size
= QSizeF());
44 * Adds a previously managed item.
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
);
53 * Sets spacing required between an item and
54 * the edge of the working area when a new item is positioned.
56 void setPlacementSpacing(qreal spacing
);
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.
63 void setScreenSpacing(qreal spacing
);
66 * Sets spacing between items when items are being pushed around.
68 void setShiftingSpacing(qreal spacing
);
71 * Sets the tolerance for temporary placement in terms of surface
72 * of the item concerned.
74 void setVisibilityTolerance(qreal part
);
77 * Sets whether the working area should always be
78 * considered the geometry of the managed widget.
81 void setAutoWorkingArea(bool value
);
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.
88 void setWorkingArea(QRectF area
);
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.
97 void setAlignment(Qt::Alignment alignment
);
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
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;
121 void movementFinished(QGraphicsItem
*);
125 class DesktopLayoutItem
128 QGraphicsLayoutItem
*item
;
129 QRectF temporaryGeometry
;
137 * The ItemSpace where items are stored and calculations are done.
138 * We use the 'user' item option as an identifier that survives
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
);