diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-08-19 09:46:06 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-08-19 09:46:06 (GMT) |
commit | 14c6433781fb946aab6e7f77fd190469e5fcfb94 (patch) | |
tree | 4e42d59995885b6067c6e77dad6d6cad092ee048 /examples | |
parent | 9da9e6f9bcead138297765b2782f73b68799827a (diff) | |
download | Qt-14c6433781fb946aab6e7f77fd190469e5fcfb94.zip Qt-14c6433781fb946aab6e7f77fd190469e5fcfb94.tar.gz Qt-14c6433781fb946aab6e7f77fd190469e5fcfb94.tar.bz2 |
update API to what was agreed on the API review meeting yesterday:
The changes are:
* Move enums in QGraphicsAnchorLayout::Edge to Qt::AnchorPoint.
Prefix them with Anchor since they are not edges in general.
* Rename anchor() to addAnchor()
* Rename anchorCorner() -> addCornerAnchors()
* Rename anchorWidth() -> addLeftAndRightAnchors()
* Rename anchorHeight() -> addTopAndBottomAnchors()
* Rename anchorGeometry() -> addAllAnchors()
* remove the overloads that take a spacing argument, and add
setAnchorSpacing() to accommodate for that.
* Added anchorSpacing() (implementation missing)
* Added unsetAnchorSpacing(). (implementation missing)
* made sizeHint() protected.
Updated all examples and autotest to reflect this API change.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/graphicsview/anchorlayout/main.cpp | 81 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/window.cpp | 35 | ||||
-rw-r--r-- | examples/layouts/anchorlayout/window.h | 4 |
3 files changed, 71 insertions, 49 deletions
diff --git a/examples/graphicsview/anchorlayout/main.cpp b/examples/graphicsview/anchorlayout/main.cpp index 1c87fa0..5427bbf 100644 --- a/examples/graphicsview/anchorlayout/main.cpp +++ b/examples/graphicsview/anchorlayout/main.cpp @@ -44,37 +44,60 @@ int main(int argc, char **argv) w->setLayout(l); // vertical - l->anchor(a, QGraphicsAnchorLayout::Top, l, QGraphicsAnchorLayout::Top, 0); - l->anchor(b, QGraphicsAnchorLayout::Top, l, QGraphicsAnchorLayout::Top, 0); - - l->anchor(c, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Bottom, 0); - l->anchor(c, QGraphicsAnchorLayout::Top, b, QGraphicsAnchorLayout::Bottom, 0); - l->anchor(c, QGraphicsAnchorLayout::Bottom, d, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::Bottom, e, QGraphicsAnchorLayout::Top, 0); - - l->anchor(d, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); - l->anchor(e, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); - - l->anchor(c, QGraphicsAnchorLayout::Top, f, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::VCenter, f, QGraphicsAnchorLayout::Bottom, 0); - l->anchor(f, QGraphicsAnchorLayout::Bottom, g, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::Bottom, g, QGraphicsAnchorLayout::Bottom, 0); + l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorTop, l, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorTop, l, Qt::AnchorTop, 0); + + l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, a, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, b, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, e, Qt::AnchorTop, 0); + + l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(d, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(e, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorTop, f, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom, 0); + l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop); + l->setAnchorSpacing(f, Qt::AnchorBottom, g, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorBottom, g, Qt::AnchorBottom, 0); // horizontal - l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left, 0); - l->anchor(l, QGraphicsAnchorLayout::Left, d, QGraphicsAnchorLayout::Left, 0); - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left, 0); - - l->anchor(a, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left, 0); - l->anchor(c, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); - - l->anchor(b, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); - l->anchor(e, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); - l->anchor(d, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); - - l->anchor(l, QGraphicsAnchorLayout::Left, f, QGraphicsAnchorLayout::Left, 0); - l->anchor(l, QGraphicsAnchorLayout::Left, g, QGraphicsAnchorLayout::Left, 0); - l->anchor(f, QGraphicsAnchorLayout::Right, g, QGraphicsAnchorLayout::Right, 0); + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, d, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); + + l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, c, Qt::AnchorLeft, 0); + l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(c, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + + l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(b, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(e, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(d, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + + l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, f, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, g, Qt::AnchorLeft, 0); + l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight); + l->setAnchorSpacing(f, Qt::AnchorRight, g, Qt::AnchorRight, 0); scene.addItem(w); scene.setBackgroundBrush(Qt::darkGreen); diff --git a/examples/layouts/anchorlayout/window.cpp b/examples/layouts/anchorlayout/window.cpp index d8d68e2..cab1b60 100644 --- a/examples/layouts/anchorlayout/window.cpp +++ b/examples/layouts/anchorlayout/window.cpp @@ -190,17 +190,17 @@ void Window::rebuildLayout() QGraphicsLayoutItem *startItem = layoutItemAt(m_ui.anchors->model(), i, 0); if (!startItem) continue; - QGraphicsAnchorLayout::Edge startEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint startEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; QGraphicsLayoutItem *endItem = layoutItemAt(m_ui.anchors->model(), i, 2); if (!endItem) continue; - QGraphicsAnchorLayout::Edge endEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint endEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; - m_layout->anchor(startItem, startEdge, endItem, endEdge); + m_layout->addAnchor(startItem, startEdge, endItem, endEdge); } } @@ -232,8 +232,8 @@ static const char *strEdges[] = {"Left", "VCenter", "Bottom"}; -void Window::setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, QGraphicsAnchorLayout::Edge startEdge, - QGraphicsLayoutItem *endItem, const QString &endName, QGraphicsAnchorLayout::Edge endEdge, int row /*= -1*/) +void Window::setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, Qt::AnchorPoint startEdge, + QGraphicsLayoutItem *endItem, const QString &endName, Qt::AnchorPoint endEdge, int row /*= -1*/) { if (row == -1) { row = m_ui.anchors->rowCount(); @@ -286,7 +286,7 @@ void Window::addAnchorRow() QString defaultName = defaultLayoutItem->isLayout() ? QLatin1String("layout") : defaultLayoutItem->graphicsItem()->data(0).toString(); - setAnchorData(defaultLayoutItem, defaultName, QGraphicsAnchorLayout::Right, defaultLayoutItem, defaultName, QGraphicsAnchorLayout::Left, rc); + setAnchorData(defaultLayoutItem, defaultName, Qt::AnchorRight, defaultLayoutItem, defaultName, Qt::AnchorLeft, rc); rebuildLayout(); } } @@ -324,7 +324,6 @@ bool Window::saveLayout(const QString& fileName) xml.writeAttribute(QLatin1String("id"), name); for (int p = 0; p < 3; ++p) { const char *propertyNames[] = {"minimumSize", "preferredSize", "maximumSize"}; - int b; typedef QSizeF (QGraphicsLayoutItem::*QGLISizeGetter)(void) const; QGLISizeGetter sizeGetters[] = { &QGraphicsLayoutItem::minimumSize, &QGraphicsLayoutItem::preferredSize, @@ -353,13 +352,13 @@ bool Window::saveLayout(const QString& fileName) QGraphicsLayoutItem *startItem = layoutItemAt(m_ui.anchors->model(), i, 0); if (!startItem) continue; - QGraphicsAnchorLayout::Edge startEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint startEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; QGraphicsLayoutItem *endItem = layoutItemAt(m_ui.anchors->model(), i, 2); if (!endItem) continue; - QGraphicsAnchorLayout::Edge endEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint endEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; @@ -416,24 +415,24 @@ static bool parseProperty(QXmlStreamReader *xml, QString *name, QSizeF *size) return false; } -static bool parseEdge(const QString &itemEdge, QByteArray *id, QGraphicsAnchorLayout::Edge *edge) +static bool parseEdge(const QString &itemEdge, QByteArray *id, Qt::AnchorPoint *edge) { QStringList item_edge = itemEdge.split(QLatin1Char('.')); bool ok = item_edge.count() == 2; if (ok) { QByteArray strEdge = item_edge.at(1).toAscii().toLower(); if (strEdge == "left") { - *edge = QGraphicsAnchorLayout::Left; + *edge = Qt::AnchorLeft; } else if (strEdge == "hcenter") { - *edge = QGraphicsAnchorLayout::HCenter; + *edge = Qt::AnchorHorizontalCenter; } else if (strEdge == "right") { - *edge = QGraphicsAnchorLayout::Right; + *edge = Qt::AnchorRight; } else if (strEdge == "top") { - *edge = QGraphicsAnchorLayout::Top; + *edge = Qt::AnchorTop; } else if (strEdge == "vcenter") { - *edge = QGraphicsAnchorLayout::VCenter; + *edge = Qt::AnchorVerticalCenter; } else if (strEdge == "bottom") { - *edge = QGraphicsAnchorLayout::Bottom; + *edge = Qt::AnchorBottom; } else { ok = false; } @@ -482,7 +481,7 @@ bool Window::loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout) QString first = attrs.value("first").toString(); QString second = attrs.value("second").toString(); QByteArray startID; - QGraphicsAnchorLayout::Edge startEdge; + Qt::AnchorPoint startEdge; QGraphicsLayoutItem *startItem = 0; if (parseEdge(first, &startID, &startEdge)) { if (startID == "this") { @@ -497,7 +496,7 @@ bool Window::loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout) } QByteArray endID; - QGraphicsAnchorLayout::Edge endEdge; + Qt::AnchorPoint endEdge; QGraphicsLayoutItem *endItem = 0; if (parseEdge(second, &endID, &endEdge)) { if (endID == "this") { diff --git a/examples/layouts/anchorlayout/window.h b/examples/layouts/anchorlayout/window.h index c81dbac..f87b2c9 100644 --- a/examples/layouts/anchorlayout/window.h +++ b/examples/layouts/anchorlayout/window.h @@ -36,8 +36,8 @@ private: void setItemData(const QString &name, const QSizeF &min, const QSizeF &pref, const QSizeF &max); QGraphicsLayoutItem *addItem(const QString &name = QString()); void addAnchorRow(); - void setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, QGraphicsAnchorLayout::Edge startEdge, - QGraphicsLayoutItem *endItem, const QString &endName, QGraphicsAnchorLayout::Edge endEdge, int row = -1); + void setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, Qt::AnchorPoint startEdge, + QGraphicsLayoutItem *endItem, const QString &endName, Qt::AnchorPoint endEdge, int row = -1); bool saveLayout(const QString& fileName); bool loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout); |