Home · All Classes · Main Classes · Deprecated |
Policy that uses the Qt grid layout engine to provide a horizontal or vertical linear layout.This class provides a policy which is similar to QGraphicsLinearLayout, with the advantage of allowing multiple policies and animation. You can use QGraphicsLinearLayout instead to slightly reduce memory overhead if these advantages are not required. More...
Inherits MAbstractLayoutPolicy.
Public Member Functions | |
MLinearLayoutPolicy (MLayout *layout, Qt::Orientation orientation) | |
virtual | ~MLinearLayoutPolicy () |
qreal | spacing () const |
virtual void | setSpacing (qreal spacing) |
void | setItemSpacing (int index, qreal spacing) |
qreal | itemSpacing (int index) const |
Qt::Orientation | orientation () const |
void | setOrientation (Qt::Orientation orientation) |
virtual void | addItem (QGraphicsLayoutItem *item) |
void | addItem (QGraphicsLayoutItem *item, Qt::Alignment alignment) |
virtual void | insertItem (int index, QGraphicsLayoutItem *item) |
void | insertItem (int index, QGraphicsLayoutItem *item, Qt::Alignment alignment) |
void | addStretch (int stretch=1) |
void | insertStretch (int index, int stretch=1) |
int | stretchFactor (QGraphicsLayoutItem *item) const |
void | setStretchFactor (QGraphicsLayoutItem *item, int stretch) |
Qt::Alignment | alignment (QGraphicsLayoutItem *item) const |
void | setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment) |
void | setNotifyWidgetsOfLayoutPositionEnabled (bool enabled) |
bool | isNotifyWidgetsOfLayoutPositionEnabled () const |
Policy that uses the Qt grid layout engine to provide a horizontal or vertical linear layout.
This class provides a policy which is similar to QGraphicsLinearLayout, with the advantage of allowing multiple policies and animation. You can use QGraphicsLinearLayout instead to slightly reduce memory overhead if these advantages are not required.
The following example adds items to the linear layout policy:
/* Create a MLayout that we set the policy for */ MLayout *layout = new MLayout; MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(layout, Qt::Vertical); policy->setSpacing(10); /* Add 3 items to the policy, arranging them vertically stacked on top of each other */ for (int i = 0; i < 3; ++i) { MLabel *label = new MLabel(QString("Item %1").arg(i + 1)); policy->addItem(label); label->setObjectName("item"); label->setAlignment(Qt::AlignCenter); }
The result, with appropriate CSS styling, looks like:
If you do not need animations or multiple policies, you can use QGraphicsLinearLayout for same effect in less code. For example:
/* Create a linear layout */ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); layout->setSpacing(10); /* Add 3 items to the layout, arranging them vertically stacked on top of each other */ for (int i = 0; i < 3; ++i) { MLabel *label = new MLabel(QString("Item %1").arg(i + 1)); layout->addItem(label); label->setObjectName("item"); label->setAlignment(Qt::AlignCenter); }
MLinearLayoutPolicy::MLinearLayoutPolicy | ( | MLayout * | layout, | |
Qt::Orientation | orientation | |||
) | [explicit] |
Constructs a linear layout policy.
The initial orientation
is required by the constructor, but can be changed at any time with setOrientation().
layout | The layout to associate with. | |
orientation | The orientation to use for this layout. |
MLinearLayoutPolicy::~MLinearLayoutPolicy | ( | ) | [virtual] |
Destroys the linear layout policy.
void MLinearLayoutPolicy::addItem | ( | QGraphicsLayoutItem * | item | ) | [virtual] |
Add an item to the end of the linear layout policy.
This adds the given item to the end of the linear layout policy, using the default alignment of 0.
Equivalent to:
insertItem(item, -1);
Note that the order of the items in the policy is independent of the order of the items in the MLayout.
item | The item to add. |
Reimplemented from MAbstractLayoutPolicy.
void MLinearLayoutPolicy::addItem | ( | QGraphicsLayoutItem * | item, | |
Qt::Alignment | alignment | |||
) |
Add an item to the end of the linear layout policy with the given alignment.
This adds the given item to the end of the linear layout policy, using the given alignment
Equivalent to:
insertItem(item, -1, alignment);
Note that the order of the items in the policy is independent of the order of the items in the MLayout.
void MLinearLayoutPolicy::addStretch | ( | int | stretch = 1 |
) | [inline] |
Add a stretch with the given stretch factor.
This convenience function is equivalent to calling
insertStretch(-1, stretch).
Adding a stretch does not increase the count() of the policy, cannot be refderenced by itemAt(), and cannot be removed.
Qt::Alignment MLinearLayoutPolicy::alignment | ( | QGraphicsLayoutItem * | item | ) | const |
Returns the alignment for item. The default alignment is Qt::AlignCenter.
The alignment decides how the item is positioned within its assigned space in the case where there's more space available in the layout than the widgets can occupy.
void MLinearLayoutPolicy::insertItem | ( | int | index, | |
QGraphicsLayoutItem * | item | |||
) | [virtual] |
Insert an item in the policy at the given index.
Inserts item
into the layout
at index, or before any item that is currently at index
.
Note that the order of the items in the policy is independent of the order of the items in the MLayout.
item | The item to insert. | |
index | The index to place the item |
Reimplemented from MAbstractLayoutPolicy.
void MLinearLayoutPolicy::insertItem | ( | int | index, | |
QGraphicsLayoutItem * | item, | |||
Qt::Alignment | alignment | |||
) |
Insert an item in the policy at the given index with the given alignment.
Inserts item
into the layout
at index, or before any item that is currently at index
.
Note that the order of the items in the policy is independent of the order of the items in the MLayout.
void MLinearLayoutPolicy::insertStretch | ( | int | index, | |
int | stretch = 1 | |||
) |
Inserts a stretch of stretch at index, or before any item that is currently at index.
Adding a stretch does not increase the count() of the policy, cannot be refderenced by itemAt(), and cannot be removed.
bool MLinearLayoutPolicy::isNotifyWidgetsOfLayoutPositionEnabled | ( | ) | const |
Returns true if positioning is enabled, false if positioning is disabled.
qreal MLinearLayoutPolicy::itemSpacing | ( | int | index | ) | const |
Get the spacing after the item at the given index
.
This overrides any spacing set by setSpacing().
index | The position of the item to get the spacing after. |
Qt::Orientation MLinearLayoutPolicy::orientation | ( | ) | const |
Returns the layout orientation.
void MLinearLayoutPolicy::setAlignment | ( | QGraphicsLayoutItem * | item, | |
Qt::Alignment | alignment | |||
) |
Sets the alignment of item to alignment. If item's alignment changes, the layout is automatically invalidated.
void MLinearLayoutPolicy::setItemSpacing | ( | int | index, | |
qreal | spacing | |||
) |
Set the spacing after the item at index
.
This overrides any spacing set by setSpacing().
index | The position of the item to set the spacing after. | |
spacing | The spacing to use. |
void MLinearLayoutPolicy::setNotifyWidgetsOfLayoutPositionEnabled | ( | bool | enabled | ) |
Enable/disable automatic setting of the layout position for the items inside the layout.
void MLinearLayoutPolicy::setOrientation | ( | Qt::Orientation | orientation | ) |
Change the layout policy orientation to orientation.
Changing the policy orientation will automatically invalidate the policy and invalidate the layout if this policy is the current layout policy.
void MLinearLayoutPolicy::setSpacing | ( | qreal | spacing | ) | [virtual] |
Set the spacing. The spacing is the distance between the items.
Reimplemented from MAbstractLayoutPolicy.
void MLinearLayoutPolicy::setStretchFactor | ( | QGraphicsLayoutItem * | item, | |
int | stretch | |||
) |
Sets the stretch factor for item to stretch.
If an item's stretch factor changes, this function will invalidate the layout. Setting stretch to 0 removes the stretch factor from the item, and is effectively equivalent to setting stretch to 1.
qreal MLinearLayoutPolicy::spacing | ( | ) | const |
Get the spacing. The spacing is the distance between the items.
Note that in the CSS file, the attributes are horizontal-spacing and vertical-spacing. The appropriate spacing is used depending on whether the linear layout is horizontal or vertical. The horizontal and vertical spacing can also be set individually with setHorizontalSpacing() and setVerticalSpacing()
int MLinearLayoutPolicy::stretchFactor | ( | QGraphicsLayoutItem * | item | ) | const |
Returns the stretch factor for item.
The default stretch factor is 0, meaning that the item has no assigned stretch factor.
Copyright © 2010 Nokia Corporation | MeeGo Touch |