Home · All Classes · Main Classes · Deprecated |
Freestyle layout policy. More...
Inherits MAbstractLayoutPolicy.
Public Member Functions | |
MFreestyleLayoutPolicy (MLayout *layout) | |
virtual | ~MFreestyleLayoutPolicy () |
virtual void | addItem (QGraphicsLayoutItem *item) |
void | addItemAtGeometry (QGraphicsLayoutItem *item, const QRectF &geom) |
void | moveItemTo (QGraphicsLayoutItem *item, const QRectF &geom) |
Protected Member Functions | |
virtual void | relayout () |
Freestyle layout policy.
This policy arranges the items as much as possible according to the user's wishes but avoids any overlap. The height is computed as needed.
The following example adds items to the freestyle layout policy in a circle shape:
/* Create a MLayout that we set the policy for */ MLayout *layout = new MLayout; MFreestyleLayoutPolicy *policy = new MFreestyleLayoutPolicy(layout); policy->setSpacing(10); MApplicationWindow window; MApplicationPage page; /* Attach the layout to the page */ page.centralWidget()->setLayout(layout); page.appear(&window); window.show(); int n = 20; for (int i = 0; i < n; ++i) { MLabel *label = new MLabel(QString("Item %1").arg(i + 1)); label->setObjectName("item"); //Place the items in an ellipse with the width and height of the page int center_x = label->preferredWidth() / 2 + (page.geometry().width() - label->preferredWidth()) / 2 * (1 - cos(2 * 3.13 * i / n)); int center_y = 25 + (page.geometry().height() - 50) / 3 * (1 - sin(2 * 3.13 * i / n)); policy->addItemAtGeometry(label, QRect(center_x - label->preferredWidth() / 2, center_y - label->preferredHeight() / 2, label->preferredWidth(), label->preferredHeight())); label->setAlignment(Qt::AlignCenter); }
The result, with appropriate CSS styling, looks like:
MFreestyleLayoutPolicy::MFreestyleLayoutPolicy | ( | MLayout * | layout | ) | [explicit] |
Constructs a freestyle layout policy.
MFreestyleLayoutPolicy::~MFreestyleLayoutPolicy | ( | ) | [virtual] |
Destroys the freestyle layout policy.
void MFreestyleLayoutPolicy::addItem | ( | QGraphicsLayoutItem * | item | ) | [virtual] |
Add an item to the top left hand corner in the freestyle layout.
If the new item overlaps any existing items, the existing items will be moved out of the way.
The item will be given its preferredSize.
item | The item to add. |
Reimplemented from MAbstractLayoutPolicy.
void MFreestyleLayoutPolicy::addItemAtGeometry | ( | QGraphicsLayoutItem * | item, | |
const QRectF & | geom | |||
) |
Add an item at a specific geometry in the freestyle layout.
If the new item overlaps any existing items, the existing items will be moved out of the way.
item | The item to add. | |
geom | The geometry where to add the item. |
void MFreestyleLayoutPolicy::moveItemTo | ( | QGraphicsLayoutItem * | item, | |
const QRectF & | geom | |||
) |
Move an item to the given geometry.
The given item will be animated to the given geometry, if possible, moving any overlapping items out of the way, if possible.
void MFreestyleLayoutPolicy::relayout | ( | ) | [protected, virtual] |
Callback triggered when a relayout is required.
This method is triggered whenever complete relayout is required (e.g. when the layout itself is resized).
All affected items are computed and the layout is triggered to update the information.
You must override this method in your custom policies.
Implements MAbstractLayoutPolicy.
Copyright © 2010 Nokia Corporation | MeeGo Touch |