Home · All Classes · Main Classes · Deprecated |
MeeGo Touch includes a set of layout management classes that are used to describe how widgets are laid out in an application's user interface. These layouts automatically position and resize widgets when the amount of available space changes, which ensures that they are consistently arranged and that the user interface as a whole remains usable.
There are two different sets of layout classes.
The first is provided by Qt, and inherited from QGraphicsLayout, including QGraphicsLinearLayout, QGraphicsGridLayout, and so on. These Qt classes provide an easy way to place items as you want.
The second set of layout classes is provided by MeeGo Touch, and they offer additional features, at the cost of slightly more overhead. The MeeGo Touch classes work in a slightly different way - there is a single MLayout to which you can add one or more policies that inherit MAbstractLayoutPolicy. This allows a single layout to have multiple policies, with one active at a given time. A different policy can be made active at any time, causing the items within the layout to move into their new position.
The multiple policies in a single MLayout do not even need to contain the same items. New items are shown and hidden as necessary (Unless the item is itself a layout, since a layout cannot be directly hidden itself. However, if a layout is inside a widget which is inside a layout, it is hidden. See Hiding a QGraphicsLayout or MLayout).
In right-to-left languages, such as Arabic, the layouts are automatically reversed. This is usually the correct behaviour. However, you can override this by directly calling QGraphicsWidget::setLayoutDirection(). For example, the calculator example has the following code snippet:
CalculatorWidget::CalculatorWidget() { mValue = 0; //Prevent the layout from changing in right-to-left. //The calculation line will still be reversed however. setLayoutDirection(Qt::LeftToRight); /* Create a MLayout attached to this widget */ MLayout *layout = new MLayout(this);
To determine the size of a widget in a layout, the layout uses the widget's QGraphicsLayoutItem::preferredSize() and its QGraphicsLayoutItem::sizePolicy() functions. The preferred size of a MWidgetController is determined as follows:
The sizes given from the first 3 steps are combined, in the above order of preference. If the height and/or width are not specified, the MWidgetView::sizeHint() function is called, with constraint parameter set to the size determined so far. The result from the view is then combined with the constraint.
Finally, if this size is still not valid, the size is combined with QGraphicsWidget::sizeHint() which in turn uses the layout's QGraphicsLayoutItem::sizeHint() function.
If you create your widget and its width depends on its height, its size policy must have set QSizePolicy::hasHeightForWidth().
Multiple policies can be assigned to a layout. It is particularly useful to have one policy in portrait mode and another policy in landscape mode. For example:
A more concrete example is given with the example calculator application.
For advanced item layout, you can place multiple layouts together. The easiest way to do this is to use a mix of MLayouts and QGraphicsLayout, and use a MLayout only when animations and multiple policies are required.
For example, if you use multiple QGraphicsLinearLayouts , you create a layout where items are placed in rows, but they do not line up vertically. For example:
Copyright © 2010 Nokia Corporation | MeeGo Touch |