Provides a geometry manager for subwidgets More...
#include <geomgr.h>
The GeoMgr class provides a geometry manager based on the gravity principle also found in the X-window system. Rather than using grid-like layout and stretch parameters, it uses gravity settings for two opposite corners of each subwidget called the northwest and southeast control points. The top of the subwidget is defined as the north side of the widget.
For each subwidget the gravity mode of the two control points can be set. The modes have the following effect:
Gravity mode
If, for example, for a subwidget both control points are set to North gravity, the subwidget will keep both its northwest and its southeast corners at a constant distance to the north side of its parent. If the parent is made higher, the subwidget will not move or resize. If the parent is made wider, the subwidget will be linearly moved and scaled. Only gravity is not enough to accomplish all desired effects. You might wish to move a subwidget like a pushbutton in such a way that it keeps the same relative position (the center for instance) in its parent. This would be accomplished by setting the gravity of both control points to None. Unfortunately, this would resize the pushbutton also. This may be undesired. To accomodate this, one more attribute can be set for the layout information of a subwidget. This is the ResizeMode. It can have the following values: RESIZE_ALL, RESIZE_X, RESIZE_Y, RESIZE_NONE.
The geometry manager needs to be activated by calling the init() member function after it has been constructed. This creates a list of LayoutInfo entries. One entry is created for each direct descendant of the parent. The gravity mode of both control points is set to NO_GRAV and the resize mode is set to RESIZE_ALL. In effect, everything scales linearly. Only direct descendants are included in the list of subwidgets that are managed by the geometry manager. If you have subwidgets which themselves have children, the you should add a second geometry manager to that subwidget (see example).
Warning: If you add new widgets to the parent of the geometry manager, you should call init() again. Otherwise, these widgets will not be included in the geometry management.
Warning: You should only change gravity modes and/or resize modes after calling init().
Code example:
#include <geomgr.h> class MyClass: public QWidget { public: .... private: GeoMgr *mainMgr; GeoMgr *subMgr; QFrame *backFrame; QPushButton *quitBut, *frameBut; } MyClass::MyClass(QWidget *parent, const char *name) : QWidget(parent, name) { backFrame = new QFrame(this); .... quitBut = new QPushButton(this); .... frameBut = new QPushButton(backFrame); mainMgr = new GeoMgr(this); // manages children of MyClass mainMgr->init(); subMgr = new GeoMgr(backFrame); // manages the children of the frame subMgr->init(); }
Constructs a new geometry manager which will be attached to parent. The geometry manager installs itself as the event filter for its parent so it can intercept any resizeEvents. The manager is not yet active.
Destroys a geometry manager.
Initializes the geometry manager. Every time new widgets are added to the parent, this member should be called. If it is not called, the newly added widgets will not be managed. Each time init() is called, the layout information of each subwidget will be reset to the default values of NO_GRAV, NO_GRAV and RESIZE_ALL.
Init() gets a list of child widgets. The GeoMgr manages only the subwidgets in the first degree. You can, however, install additional Geometry managers for each of the subwidgets. For each subwidget, a LayoutInfo structure is created with default values (linear scaling). The entries can be modified.
See also: setNWGrav(), setSEGrav(), setLayoutInfo()
Sets the gravity mode of the Northwest control point of the widget pointed to by target. If target cannot be found, 0 is returned.
Sets the gravity mode of the Southeast control point of the widget pointed to by target. If target cannot be found, 0 is returned.
Sets the resize mode of the widget pointed to by target. If target cannot be found, 0 is returned.
Sets the layout info of the widget pointed to by target. If target cannot be found, 0 is returned.
Returns the layout info of the widget pointed to by target. If target cannot be found, 0 is returned. The gravity modes and resize mode are returned in the arguments.
[private]
Processes events sent to the parent. Only resizeEvents are processed by the geometry manager. All other events are dispatched to the parent normally.
[private]
Goes through the list of subwidgets under geometry control and calls layoutWidget(LayoutInfo *, QSize &, QSize &) for each of them.
[private]
Calculate the new position and size of a single widget based on the gravity modes, resize mode and the old and new size of the parent.
[private]
Looks up a widget in the list of subwidgets under geometry control. If target cannot be found, a null pointer is returned.
[private]
The target of which the child geometry should be managed
[private]
A list of LayouInfo of child widgets under geometry management
[private]
Activity flag