| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the examples of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <QGraphicsWidget>
|
|---|
| 43 | #include <QGraphicsProxyWidget>
|
|---|
| 44 | #include <QGraphicsAnchorLayout>
|
|---|
| 45 | #include <QtGui>
|
|---|
| 46 |
|
|---|
| 47 | static QGraphicsProxyWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
|
|---|
| 48 | const QSizeF &preferred = QSize(150.0, 100.0),
|
|---|
| 49 | const QSizeF &maximum = QSizeF(200.0, 100.0),
|
|---|
| 50 | const QString &name = "0")
|
|---|
| 51 | {
|
|---|
| 52 | QGraphicsProxyWidget *w = new QGraphicsProxyWidget;
|
|---|
| 53 | w->setWidget(new QPushButton(name));
|
|---|
| 54 | w->setData(0, name);
|
|---|
| 55 | w->setMinimumSize(minimum);
|
|---|
| 56 | w->setPreferredSize(preferred);
|
|---|
| 57 | w->setMaximumSize(maximum);
|
|---|
| 58 |
|
|---|
| 59 | w->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
|---|
| 60 | return w;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | int main(int argc, char **argv)
|
|---|
| 64 | {
|
|---|
| 65 | QApplication app(argc, argv);
|
|---|
| 66 |
|
|---|
| 67 | QGraphicsScene scene;
|
|---|
| 68 | scene.setSceneRect(0, 0, 800, 480);
|
|---|
| 69 |
|
|---|
| 70 | QSizeF minSize(30, 100);
|
|---|
| 71 | QSizeF prefSize(210, 100);
|
|---|
| 72 | QSizeF maxSize(300, 100);
|
|---|
| 73 |
|
|---|
| 74 | QGraphicsProxyWidget *a = createItem(minSize, prefSize, maxSize, "A");
|
|---|
| 75 | QGraphicsProxyWidget *b = createItem(minSize, prefSize, maxSize, "B");
|
|---|
| 76 | QGraphicsProxyWidget *c = createItem(minSize, prefSize, maxSize, "C");
|
|---|
| 77 | QGraphicsProxyWidget *d = createItem(minSize, prefSize, maxSize, "D");
|
|---|
| 78 | QGraphicsProxyWidget *e = createItem(minSize, prefSize, maxSize, "E");
|
|---|
| 79 | QGraphicsProxyWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F (overflow)");
|
|---|
| 80 | QGraphicsProxyWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G (overflow)");
|
|---|
| 81 |
|
|---|
| 82 | QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
|
|---|
| 83 | l->setSpacing(0);
|
|---|
| 84 |
|
|---|
| 85 | QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
|
|---|
| 86 | w->setPos(20, 20);
|
|---|
| 87 | w->setLayout(l);
|
|---|
| 88 |
|
|---|
| 89 | // vertical
|
|---|
| 90 | QGraphicsAnchor *anchor = l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
|
|---|
| 91 | anchor = l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);
|
|---|
| 92 |
|
|---|
| 93 | anchor = l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
|
|---|
| 94 | anchor = l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
|
|---|
| 95 | anchor = l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
|
|---|
| 96 | anchor = l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);
|
|---|
| 97 |
|
|---|
| 98 | anchor = l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|---|
| 99 | anchor = l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);
|
|---|
| 100 |
|
|---|
| 101 | anchor = l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop);
|
|---|
| 102 | anchor = l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom);
|
|---|
| 103 | anchor = l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop);
|
|---|
| 104 | anchor = l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom);
|
|---|
| 105 |
|
|---|
| 106 | // horizontal
|
|---|
| 107 | anchor = l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
|
|---|
| 108 | anchor = l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
|
|---|
| 109 | anchor = l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
|
|---|
| 110 |
|
|---|
| 111 | anchor = l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
|
|---|
| 112 | anchor = l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);
|
|---|
| 113 |
|
|---|
| 114 | anchor = l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
|
|---|
| 115 | anchor = l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
|
|---|
| 116 | anchor = l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);
|
|---|
| 117 |
|
|---|
| 118 | anchor = l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft);
|
|---|
| 119 | anchor = l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft);
|
|---|
| 120 | anchor = l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight);
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | scene.addItem(w);
|
|---|
| 124 | scene.setBackgroundBrush(Qt::darkGreen);
|
|---|
| 125 | QGraphicsView view(&scene);
|
|---|
| 126 | view.show();
|
|---|
| 127 |
|
|---|
| 128 | return app.exec();
|
|---|
| 129 | }
|
|---|