summaryrefslogtreecommitdiffstats
path: root/examples/declarative
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-05-28 07:24:32 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-05-31 01:52:57 (GMT)
commitb64f49b7c97aa905cde93a943f56eca20475678e (patch)
treeaed83432d571c1d7936bac2afe38d5db95cbabad /examples/declarative
parentbc1d00de820abc0697e51315d8231cadbce9f9dd (diff)
downloadQt-b64f49b7c97aa905cde93a943f56eca20475678e.zip
Qt-b64f49b7c97aa905cde93a943f56eca20475678e.tar.gz
Qt-b64f49b7c97aa905cde93a943f56eca20475678e.tar.bz2
Split graphicsLayouts example into qgraphicslinearlayout and
qgraphicsgridlayout and clean up
Diffstat (limited to 'examples/declarative')
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro13
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject16
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp365
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swobin0 -> 12288 bytes
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp180
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h (renamed from examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h)227
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc (renamed from examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc)3
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp (renamed from examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp)20
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro15
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml (renamed from examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml)31
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp167
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h150
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc6
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp64
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro15
-rw-r--r--examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml68
16 files changed, 755 insertions, 585 deletions
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro
deleted file mode 100644
index e5d91b2..0000000
--- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.pro
+++ /dev/null
@@ -1,13 +0,0 @@
-TEMPLATE = app
-TARGET = graphicslayouts
-QT += declarative
-
-SOURCES += \
- graphicslayouts.cpp \
- main.cpp
-
-HEADERS += \
- graphicslayouts_p.h
-
-RESOURCES += \
- graphicslayouts.qrc
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject
deleted file mode 100644
index d4909f8..0000000
--- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicsLayouts.qmlproject
+++ /dev/null
@@ -1,16 +0,0 @@
-import QmlProject 1.0
-
-Project {
- /* Include .qml, .js, and image files from current directory and subdirectories */
- QmlFiles {
- directory: "."
- }
- JavaScriptFiles {
- directory: "."
- }
- ImageFiles {
- directory: "."
- }
- /* List of plugin directories passed to QML runtime */
- // importPaths: [ " ../exampleplugin " ]
-}
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp b/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp
deleted file mode 100644
index 40e286d..0000000
--- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.cpp
+++ /dev/null
@@ -1,365 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
-** the names of its contributors may be used to endorse or promote
-** products derived from this software without specific prior written
-** permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "graphicslayouts_p.h"
-
-#include <QtGui/qgraphicswidget.h>
-#include <QtCore/qdebug.h>
-
-QT_BEGIN_NAMESPACE
-
-LinearLayoutAttached::LinearLayoutAttached(QObject *parent)
-: QObject(parent), _stretch(1), _alignment(Qt::AlignCenter), _spacing(0)
-{
-}
-
-void LinearLayoutAttached::setStretchFactor(int f)
-{
- if (_stretch == f)
- return;
-
- _stretch = f;
- emit stretchChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _stretch);
-}
-
-void LinearLayoutAttached::setSpacing(int s)
-{
- if (_spacing == s)
- return;
-
- _spacing = s;
- emit spacingChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _spacing);
-}
-
-void LinearLayoutAttached::setAlignment(Qt::Alignment a)
-{
- if (_alignment == a)
- return;
-
- _alignment = a;
- emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment);
-}
-
-QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent)
- : QObject(parent)
-{
-}
-
-QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
-{
-Q_UNUSED(which);
-Q_UNUSED(constraint);
-return QSizeF();
-}
-
-
-QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent)
-: QObject(parent)
-{
-}
-
-QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject()
-{
-}
-
-void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item)
-{
-insertItem(index, item);
-
-//connect attached properties
-if (LinearLayoutAttached *obj = attachedProperties.value(item)) {
- setStretchFactor(item, obj->stretchFactor());
- setAlignment(item, obj->alignment());
- updateSpacing(item, obj->spacing());
- QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)),
- this, SLOT(updateStretch(QGraphicsLayoutItem*,int)));
- QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)),
- this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment)));
- QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)),
- this, SLOT(updateSpacing(QGraphicsLayoutItem*,int)));
- //### need to disconnect when widget is removed?
-}
-}
-
-//### is there a better way to do this?
-void QGraphicsLinearLayoutObject::clearChildren()
-{
-for (int i = 0; i < count(); ++i)
- removeAt(i);
-}
-
-qreal QGraphicsLinearLayoutObject::contentsMargin() const
-{
- qreal a,b,c,d;
- getContentsMargins(&a, &b, &c, &d);
- if(a==b && a==c && a==d)
- return a;
- return -1;
-}
-
-void QGraphicsLinearLayoutObject::setContentsMargin(qreal m)
-{
- setContentsMargins(m,m,m,m);
-}
-
-void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch)
-{
-QGraphicsLinearLayout::setStretchFactor(item, stretch);
-}
-
-void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing)
-{
- for(int i=0; i < count(); i++){
- if(itemAt(i) == item){ //I do not see the reverse function, which is why we must loop over all items
- QGraphicsLinearLayout::setItemSpacing(i, spacing);
- return;
- }
- }
-}
-
-void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)
-{
-QGraphicsLinearLayout::setAlignment(item, alignment);
-}
-
-QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> QGraphicsLinearLayoutObject::attachedProperties;
-LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj)
-{
-// ### This is not allowed - you must attach to any object
-if (!qobject_cast<QGraphicsLayoutItem*>(obj))
- return 0;
-LinearLayoutAttached *rv = new LinearLayoutAttached(obj);
-attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv);
-return rv;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-// QGraphicsGridLayout-related classes
-//////////////////////////////////////////////////////////////////////////////////////////////////////
-GridLayoutAttached::GridLayoutAttached(QObject *parent)
-: QObject(parent), _row(-1), _column(-1), _rowspan(1), _colspan(1), _alignment(-1), _rowstretch(-1),
- _colstretch(-1), _rowspacing(-1), _colspacing(-1), _rowprefheight(-1), _rowmaxheight(-1), _rowminheight(-1),
- _rowfixheight(-1), _colprefwidth(-1), _colmaxwidth(-1), _colminwidth(-1), _colfixwidth(-1)
-{
-}
-
-void GridLayoutAttached::setRow(int r)
-{
- if (_row == r)
- return;
-
- _row = r;
- //emit rowChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _row);
-}
-
-void GridLayoutAttached::setColumn(int c)
-{
- if (_column == c)
- return;
-
- _column = c;
- //emit columnChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _column);
-}
-
-void GridLayoutAttached::setRowSpan(int rs)
-{
- if (_rowspan == rs)
- return;
-
- _rowspan = rs;
- //emit rowSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _rowSpan);
-}
-
-void GridLayoutAttached::setColumnSpan(int cs)
-{
- if (_colspan == cs)
- return;
-
- _colspan = cs;
- //emit columnSpanChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _columnSpan);
-}
-
-void GridLayoutAttached::setAlignment(Qt::Alignment a)
-{
- if (_alignment == a)
- return;
-
- _alignment = a;
- emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), _alignment);
-}
-
-void GridLayoutAttached::setRowStretchFactor(int f)
-{
- _rowstretch = f;
-}
-
-void GridLayoutAttached::setColumnStretchFactor(int f)
-{
- _colstretch = f;
-}
-
-void GridLayoutAttached::setRowSpacing(int s)
-{
- _rowspacing = s;
-}
-
-void GridLayoutAttached::setColumnSpacing(int s)
-{
- _colspacing = s;
-}
-
-
-QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent)
-: QObject(parent)
-{
-}
-
-QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject()
-{
-}
-
-void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *wid)
-{
-//use attached properties
-if (QObject *obj = attachedProperties.value(qobject_cast<QGraphicsLayoutItem*>(wid))) {
- int row = static_cast<GridLayoutAttached *>(obj)->row();
- int column = static_cast<GridLayoutAttached *>(obj)->column();
- int rowSpan = static_cast<GridLayoutAttached *>(obj)->rowSpan();
- int columnSpan = static_cast<GridLayoutAttached *>(obj)->columnSpan();
- if (row == -1 || column == -1) {
- qWarning() << "Must set row and column for an item in a grid layout";
- return;
- }
- addItem(wid, row, column, rowSpan, columnSpan);
-}
-}
-
-void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item)
-{
-//use attached properties
-if (GridLayoutAttached *obj = attachedProperties.value(item)) {
- int row = obj->row();
- int column = obj->column();
- int rowSpan = obj->rowSpan();
- int columnSpan = obj->columnSpan();
- Qt::Alignment alignment = obj->alignment();
- if (row == -1 || column == -1) {
- qWarning() << "Must set row and column for an item in a grid layout";
- return;
- }
- if(obj->rowSpacing() != -1)
- setRowSpacing(row, obj->rowSpacing());
- if(obj->columnSpacing() != -1)
- setColumnSpacing(column, obj->columnSpacing());
- if(obj->rowStretchFactor() != -1)
- setRowStretchFactor(row, obj->rowStretchFactor());
- if(obj->columnStretchFactor() != -1)
- setColumnStretchFactor(column, obj->columnStretchFactor());
- if(obj->rowPreferredHeight() != -1)
- setRowPreferredHeight(row, obj->rowPreferredHeight());
- if(obj->rowMaximumHeight() != -1)
- setRowMaximumHeight(row, obj->rowMaximumHeight());
- if(obj->rowMinimumHeight() != -1)
- setRowMinimumHeight(row, obj->rowMinimumHeight());
- if(obj->rowFixedHeight() != -1)
- setRowFixedHeight(row, obj->rowFixedHeight());
- if(obj->columnPreferredWidth() != -1)
- setColumnPreferredWidth(row, obj->columnPreferredWidth());
- if(obj->columnMaximumWidth() != -1)
- setColumnMaximumWidth(row, obj->columnMaximumWidth());
- if(obj->columnMinimumWidth() != -1)
- setColumnMinimumWidth(row, obj->columnMinimumWidth());
- if(obj->columnFixedWidth() != -1)
- setColumnFixedWidth(row, obj->columnFixedWidth());
- addItem(item, row, column, rowSpan, columnSpan);
- if (alignment != -1)
- setAlignment(item,alignment);
- QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)),
- this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment)));
- //### need to disconnect when widget is removed?
-}
-}
-
-//### is there a better way to do this?
-void QGraphicsGridLayoutObject::clearChildren()
-{
-for (int i = 0; i < count(); ++i)
- removeAt(i);
-}
-
-qreal QGraphicsGridLayoutObject::spacing() const
-{
-if (verticalSpacing() == horizontalSpacing())
- return verticalSpacing();
-return -1; //###
-}
-
-qreal QGraphicsGridLayoutObject::contentsMargin() const
-{
- qreal a,b,c,d;
- getContentsMargins(&a, &b, &c, &d);
- if(a==b && a==c && a==d)
- return a;
- return -1;
-}
-
-void QGraphicsGridLayoutObject::setContentsMargin(qreal m)
-{
- setContentsMargins(m,m,m,m);
-}
-
-
-void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)
-{
-QGraphicsGridLayout::setAlignment(item, alignment);
-}
-
-QHash<QGraphicsLayoutItem*, GridLayoutAttached*> QGraphicsGridLayoutObject::attachedProperties;
-GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj)
-{
-// ### This is not allowed - you must attach to any object
-if (!qobject_cast<QGraphicsLayoutItem*>(obj))
- return 0;
-GridLayoutAttached *rv = new GridLayoutAttached(obj);
-attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv);
-return rv;
-}
-
-QT_END_NAMESPACE
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo
new file mode 100644
index 0000000..c742274
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/.main.cpp.swo
Binary files differ
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp
new file mode 100644
index 0000000..728c225
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "gridlayout.h"
+
+#include <QGraphicsWidget>
+#include <QDebug>
+
+GridLayoutAttached::GridLayoutAttached(QObject *parent)
+: QObject(parent), m_row(-1), m_column(-1), m_rowspan(1), m_colspan(1), m_alignment(-1), m_rowStretch(-1),
+ m_colStretch(-1), m_rowSpacing(-1), m_colSpacing(-1), m_rowPrefHeight(-1), m_rowMaxHeight(-1), m_rowMinHeight(-1),
+ m_rowFixHeight(-1), m_colPrefwidth(-1), m_colMaxwidth(-1), m_colMinwidth(-1), m_colFixwidth(-1)
+{
+}
+
+void GridLayoutAttached::setAlignment(Qt::Alignment a)
+{
+ if (m_alignment != a) {
+ m_alignment = a;
+ emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_alignment);
+ }
+}
+
+QHash<QGraphicsLayoutItem*, GridLayoutAttached*> QGraphicsGridLayoutObject::attachedProperties;
+
+QGraphicsGridLayoutObject::QGraphicsGridLayoutObject(QObject *parent)
+: QObject(parent)
+{
+}
+
+QGraphicsGridLayoutObject::~QGraphicsGridLayoutObject()
+{
+}
+
+void QGraphicsGridLayoutObject::addWidget(QGraphicsWidget *widget)
+{
+ //use attached properties
+ if (QObject *obj = attachedProperties.value(qobject_cast<QGraphicsLayoutItem*>(widget))) {
+ int row = static_cast<GridLayoutAttached *>(obj)->row();
+ int column = static_cast<GridLayoutAttached *>(obj)->column();
+ int rowSpan = static_cast<GridLayoutAttached *>(obj)->rowSpan();
+ int columnSpan = static_cast<GridLayoutAttached *>(obj)->columnSpan();
+ if (row == -1 || column == -1) {
+ qWarning() << "Must set row and column for an item in a grid layout";
+ return;
+ }
+ addItem(widget, row, column, rowSpan, columnSpan);
+ }
+}
+
+void QGraphicsGridLayoutObject::addLayoutItem(QGraphicsLayoutItem *item)
+{
+ //use attached properties
+ if (GridLayoutAttached *obj = attachedProperties.value(item)) {
+ int row = obj->row();
+ int column = obj->column();
+ int rowSpan = obj->rowSpan();
+ int columnSpan = obj->columnSpan();
+ Qt::Alignment alignment = obj->alignment();
+
+ if (row == -1 || column == -1) {
+ qWarning() << "Must set row and column for an item in a grid layout";
+ return;
+ }
+
+ if (obj->rowSpacing() != -1)
+ setRowSpacing(row, obj->rowSpacing());
+ if (obj->columnSpacing() != -1)
+ setColumnSpacing(column, obj->columnSpacing());
+ if (obj->rowStretchFactor() != -1)
+ setRowStretchFactor(row, obj->rowStretchFactor());
+ if (obj->columnStretchFactor() != -1)
+ setColumnStretchFactor(column, obj->columnStretchFactor());
+ if (obj->rowPreferredHeight() != -1)
+ setRowPreferredHeight(row, obj->rowPreferredHeight());
+ if (obj->rowMaximumHeight() != -1)
+ setRowMaximumHeight(row, obj->rowMaximumHeight());
+ if (obj->rowMinimumHeight() != -1)
+ setRowMinimumHeight(row, obj->rowMinimumHeight());
+ if (obj->rowFixedHeight() != -1)
+ setRowFixedHeight(row, obj->rowFixedHeight());
+ if (obj->columnPreferredWidth() != -1)
+ setColumnPreferredWidth(row, obj->columnPreferredWidth());
+ if (obj->columnMaximumWidth() != -1)
+ setColumnMaximumWidth(row, obj->columnMaximumWidth());
+ if (obj->columnMinimumWidth() != -1)
+ setColumnMinimumWidth(row, obj->columnMinimumWidth());
+ if (obj->columnFixedWidth() != -1)
+ setColumnFixedWidth(row, obj->columnFixedWidth());
+
+ addItem(item, row, column, rowSpan, columnSpan);
+
+ if (alignment != -1)
+ setAlignment(item, alignment);
+ QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment)),
+ this, SLOT(updateAlignment(QGraphicsLayoutItem*, Qt::Alignment)));
+ //### need to disconnect when widget is removed? Re-implement removeAt()?
+ }
+}
+
+void QGraphicsGridLayoutObject::clearChildren()
+{
+ //### do I need to delete the removed items? And/or removed them from attachedProperties?
+ while (count() > 0)
+ removeAt(count()-1);
+}
+
+qreal QGraphicsGridLayoutObject::spacing() const
+{
+ if (verticalSpacing() == horizontalSpacing())
+ return verticalSpacing();
+ return -1; //###
+}
+
+qreal QGraphicsGridLayoutObject::contentsMargin() const
+{
+ qreal a, b, c, d;
+ getContentsMargins(&a, &b, &c, &d);
+ if (a == b && a == c && a == d)
+ return a;
+ return -1;
+}
+
+void QGraphicsGridLayoutObject::setContentsMargin(qreal m)
+{
+ setContentsMargins(m, m, m, m);
+}
+
+void QGraphicsGridLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)
+{
+ QGraphicsGridLayout::setAlignment(item, alignment);
+}
+
+GridLayoutAttached *QGraphicsGridLayoutObject::qmlAttachedProperties(QObject *obj)
+{
+ // ### This is not allowed - you must attach to any object
+ if (!qobject_cast<QGraphicsLayoutItem*>(obj))
+ return 0;
+ GridLayoutAttached *rv = new GridLayoutAttached(obj);
+ attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv);
+ return rv;
+}
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h
index 7aa98df..04f0148 100644
--- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts_p.h
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h
@@ -38,78 +38,13 @@
**
****************************************************************************/
-#ifndef GRAPHICSLAYOUTS_H
-#define GRAPHICSLAYOUTS_H
+#ifndef GRIDLAYOUT_H
+#define GRIDLAYOUT_H
-#include <QtGui/QGraphicsLinearLayout>
-#include <QtGui/QGraphicsGridLayout>
#include <qdeclarative.h>
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem
-{
- Q_OBJECT
- Q_INTERFACES(QGraphicsLayoutItem)
-public:
- QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0);
-
- virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const;
-};
-
-class LinearLayoutAttached;
-class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout
-{
- Q_OBJECT
- Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem)
-
- Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children)
- Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
- Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing)
- Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin)
- Q_CLASSINFO("DefaultProperty", "children")
-public:
- QGraphicsLinearLayoutObject(QObject * = 0);
- ~QGraphicsLinearLayoutObject();
-
- QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); }
-
- static LinearLayoutAttached *qmlAttachedProperties(QObject *);
-
- qreal contentsMargin() const;
- void setContentsMargin(qreal);
-
-private Q_SLOTS:
- void updateStretch(QGraphicsLayoutItem*,int);
- void updateSpacing(QGraphicsLayoutItem*,int);
- void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment);
-
-private:
- friend class LinearLayoutAttached;
- void clearChildren();
- void insertLayoutItem(int, QGraphicsLayoutItem *);
- static QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> attachedProperties;
-
- static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) {
- static_cast<QGraphicsLinearLayoutObject*>(prop->object)->insertLayoutItem(-1, item);
- }
-
- static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
- static_cast<QGraphicsLinearLayoutObject*>(prop->object)->clearChildren();
- }
-
- static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
- return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->count();
- }
-
- static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) {
- return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->itemAt(index);
- }
-};
+#include <QGraphicsGridLayout>
+#include <QGraphicsLayoutItem>
class GridLayoutAttached;
class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout
@@ -123,6 +58,7 @@ class QGraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout
Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
Q_CLASSINFO("DefaultProperty", "children")
+
public:
QGraphicsGridLayoutObject(QObject * = 0);
~QGraphicsGridLayoutObject();
@@ -135,15 +71,15 @@ public:
static GridLayoutAttached *qmlAttachedProperties(QObject *);
-private Q_SLOTS:
+private slots:
void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment);
private:
friend class GraphicsLayoutAttached;
+
void addWidget(QGraphicsWidget *);
void clearChildren();
void addLayoutItem(QGraphicsLayoutItem *);
- static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties;
static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) {
static_cast<QGraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item);
@@ -160,53 +96,32 @@ private:
static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) {
return static_cast<QGraphicsGridLayoutObject*>(prop->object)->itemAt(index);
}
-};
-class LinearLayoutAttached : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged)
- Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
- Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
-public:
- LinearLayoutAttached(QObject *parent);
-
- int stretchFactor() const { return _stretch; }
- void setStretchFactor(int f);
- Qt::Alignment alignment() const { return _alignment; }
- void setAlignment(Qt::Alignment a);
- int spacing() const { return _spacing; }
- void setSpacing(int s);
-
-Q_SIGNALS:
- void stretchChanged(QGraphicsLayoutItem*,int);
- void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment);
- void spacingChanged(QGraphicsLayoutItem*,int);
-
-private:
- int _stretch;
- Qt::Alignment _alignment;
- int _spacing;
+ static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties;
};
+
class GridLayoutAttached : public QObject
{
Q_OBJECT
Q_PROPERTY(int row READ row WRITE setRow)
Q_PROPERTY(int column READ column WRITE setColumn)
+
Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan)
Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
+
Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor)
Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor)
Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
+
Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight)
Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight)
Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight)
Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight)
+
Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth)
Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth)
Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth)
@@ -215,88 +130,86 @@ class GridLayoutAttached : public QObject
public:
GridLayoutAttached(QObject *parent);
- int row() const { return _row; }
- void setRow(int r);
+ int row() const { return m_row; }
+ void setRow(int r) { m_row = r; }
- int column() const { return _column; }
- void setColumn(int c);
+ int column() const { return m_column; }
+ void setColumn(int c) { m_column = c; }
- int rowSpan() const { return _rowspan; }
- void setRowSpan(int rs);
+ int rowSpan() const { return m_rowspan; }
+ void setRowSpan(int rs) { m_rowspan = rs; }
- int columnSpan() const { return _colspan; }
- void setColumnSpan(int cs);
+ int columnSpan() const { return m_colspan; }
+ void setColumnSpan(int cs) { m_colspan = cs; }
- Qt::Alignment alignment() const { return _alignment; }
+ Qt::Alignment alignment() const { return m_alignment; }
void setAlignment(Qt::Alignment a);
- int rowStretchFactor() const { return _rowstretch; }
- void setRowStretchFactor(int f);
- int columnStretchFactor() const { return _colstretch; }
- void setColumnStretchFactor(int f);
+ int rowStretchFactor() const { return m_rowStretch; }
+ void setRowStretchFactor(int f) { m_rowStretch = f; }
+ int columnStretchFactor() const { return m_colStretch; }
+ void setColumnStretchFactor(int f) { m_colStretch = f; }
- int rowSpacing() const { return _rowspacing; }
- void setRowSpacing(int s);
- int columnSpacing() const { return _colspacing; }
- void setColumnSpacing(int s);
+ int rowSpacing() const { return m_rowSpacing; }
+ void setRowSpacing(int s) { m_rowSpacing = s; }
+ int columnSpacing() const { return m_colSpacing; }
+ void setColumnSpacing(int s) { m_colSpacing = s; }
- int rowPreferredHeight() const { return _rowprefheight; }
- void setRowPreferredHeight(int s) { _rowprefheight = s; }
+ int rowPreferredHeight() const { return m_rowPrefHeight; }
+ void setRowPreferredHeight(int s) { m_rowPrefHeight = s; }
- int rowMaximumHeight() const { return _rowmaxheight; }
- void setRowMaximumHeight(int s) { _rowmaxheight = s; }
+ int rowMaximumHeight() const { return m_rowMaxHeight; }
+ void setRowMaximumHeight(int s) { m_rowMaxHeight = s; }
- int rowMinimumHeight() const { return _rowminheight; }
- void setRowMinimumHeight(int s) { _rowminheight = s; }
+ int rowMinimumHeight() const { return m_rowMinHeight; }
+ void setRowMinimumHeight(int s) { m_rowMinHeight = s; }
- int rowFixedHeight() const { return _rowfixheight; }
- void setRowFixedHeight(int s) { _rowfixheight = s; }
+ int rowFixedHeight() const { return m_rowFixHeight; }
+ void setRowFixedHeight(int s) { m_rowFixHeight = s; }
- int columnPreferredWidth() const { return _colprefwidth; }
- void setColumnPreferredWidth(int s) { _colprefwidth = s; }
+ int columnPreferredWidth() const { return m_colPrefwidth; }
+ void setColumnPreferredWidth(int s) { m_colPrefwidth = s; }
- int columnMaximumWidth() const { return _colmaxwidth; }
- void setColumnMaximumWidth(int s) { _colmaxwidth = s; }
+ int columnMaximumWidth() const { return m_colMaxwidth; }
+ void setColumnMaximumWidth(int s) { m_colMaxwidth = s; }
- int columnMinimumWidth() const { return _colminwidth; }
- void setColumnMinimumWidth(int s) { _colminwidth = s; }
+ int columnMinimumWidth() const { return m_colMinwidth; }
+ void setColumnMinimumWidth(int s) { m_colMinwidth = s; }
- int columnFixedWidth() const { return _colfixwidth; }
- void setColumnFixedWidth(int s) { _colfixwidth = s; }
+ int columnFixedWidth() const { return m_colFixwidth; }
+ void setColumnFixedWidth(int s) { m_colFixwidth = s; }
-Q_SIGNALS:
- void alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment);
+signals:
+ void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment);
private:
- int _row;
- int _column;
- int _rowspan;
- int _colspan;
- Qt::Alignment _alignment;
- int _rowstretch;
- int _colstretch;
- int _rowspacing;
- int _colspacing;
- int _rowprefheight;
- int _rowmaxheight;
- int _rowminheight;
- int _rowfixheight;
- int _colprefwidth;
- int _colmaxwidth;
- int _colminwidth;
- int _colfixwidth;
+ int m_row;
+ int m_column;
+
+ int m_rowspan;
+ int m_colspan;
+ Qt::Alignment m_alignment;
+
+ int m_rowStretch;
+ int m_colStretch;
+ int m_rowSpacing;
+ int m_colSpacing;
+
+ int m_rowPrefHeight;
+ int m_rowMaxHeight;
+ int m_rowMinHeight;
+ int m_rowFixHeight;
+
+ int m_colPrefwidth;
+ int m_colMaxwidth;
+ int m_colMinwidth;
+ int m_colFixwidth;
};
-QT_END_NAMESPACE
-
QML_DECLARE_INTERFACE(QGraphicsLayoutItem)
QML_DECLARE_INTERFACE(QGraphicsLayout)
-QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject)
-QML_DECLARE_TYPE(QGraphicsLinearLayoutObject)
-QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES)
QML_DECLARE_TYPE(QGraphicsGridLayoutObject)
QML_DECLARE_TYPEINFO(QGraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES)
-QT_END_HEADER
+#endif
-#endif // GRAPHICSLAYOUTS_H
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc
index a199f8d..bdf8312 100644
--- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qrc
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.qrc
@@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
- <file>graphicslayouts.qml</file>
+ <file>qgraphicsgridlayout.qml</file>
</qresource>
</RCC>
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp
index b0a15fc..7585b23 100644
--- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/main.cpp
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/main.cpp
@@ -38,22 +38,26 @@
**
****************************************************************************/
+#include "gridlayout.h"
+
+#include <qdeclarative.h>
+#include <QDeclarativeView>
+
#include <QApplication>
-#include <QtDeclarative/qdeclarative.h>
-#include "graphicslayouts_p.h"
-#include <QtDeclarative/QDeclarativeView>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
- QDeclarativeView view;
+
qmlRegisterInterface<QGraphicsLayoutItem>("QGraphicsLayoutItem");
qmlRegisterInterface<QGraphicsLayout>("QGraphicsLayout");
- qmlRegisterType<QGraphicsLinearLayoutStretchItemObject>("GraphicsLayouts",4,7,"QGraphicsLinearLayoutStretchItem");
- qmlRegisterType<QGraphicsLinearLayoutObject>("GraphicsLayouts",4,7,"QGraphicsLinearLayout");
- qmlRegisterType<QGraphicsGridLayoutObject>("GraphicsLayouts",4,7,"QGraphicsGridLayout");
- view.setSource(QUrl(":graphicslayouts.qml"));
+ qmlRegisterType<QGraphicsGridLayoutObject>("GridLayouts",4,7,"QGraphicsGridLayout");
+
+ QDeclarativeView view;
+ view.setSource(QUrl(":qgraphicsgridlayout.qml"));
view.show();
+
return app.exec();
};
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro
new file mode 100644
index 0000000..ae6373d
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+TARGET = qgraphicsgridlayout
+QT += declarative
+
+SOURCES += \
+ gridlayout.cpp \
+ main.cpp
+
+HEADERS += \
+ gridlayout.h
+
+RESOURCES += \
+ gridlayout.qrc
+
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml
index 586f7f9..c3edf1d 100644
--- a/examples/declarative/cppextensions/qgraphicslayouts/graphicsLayouts/graphicslayouts.qml
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/qgraphicsgridlayout.qml
@@ -39,42 +39,22 @@
****************************************************************************/
import Qt 4.7
-import GraphicsLayouts 4.7
+import GridLayouts 4.7
Item {
- id: resizable
-
- width: 800
+ width: 400
height: 400
QGraphicsWidget {
- size.width: parent.width/2
- size.height: parent.height
-
- layout: QGraphicsLinearLayout {
- LayoutItem {
- minimumSize: "100x100"
- maximumSize: "300x300"
- preferredSize: "100x100"
- Rectangle { color: "yellow"; anchors.fill: parent }
- }
- LayoutItem {
- minimumSize: "100x100"
- maximumSize: "400x400"
- preferredSize: "200x200"
- Rectangle { color: "green"; anchors.fill: parent }
- }
- }
- }
- QGraphicsWidget {
- x: parent.width/2
- size.width: parent.width/2
+ size.width: parent.width
size.height: parent.height
layout: QGraphicsGridLayout {
+ objectName: "layout"
LayoutItem {
QGraphicsGridLayout.row: 0
QGraphicsGridLayout.column: 0
+ QGraphicsGridLayout.alignment: Qt.AlignLeft
minimumSize: "100x100"
maximumSize: "300x300"
preferredSize: "100x100"
@@ -115,3 +95,4 @@ Item {
}
}
}
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp
new file mode 100644
index 0000000..5cd35cb
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "linearlayout.h"
+
+#include <QGraphicsWidget>
+#include <QGraphicsLayoutItem>
+
+LinearLayoutAttached::LinearLayoutAttached(QObject *parent)
+: QObject(parent), m_stretch(1), m_alignment(Qt::AlignCenter), m_spacing(0)
+{
+}
+
+void LinearLayoutAttached::setStretchFactor(int f)
+{
+ if (m_stretch != f) {
+ m_stretch = f;
+ emit stretchChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_stretch);
+ }
+}
+
+void LinearLayoutAttached::setSpacing(int s)
+{
+ if (m_spacing != s) {
+ m_spacing = s;
+ emit spacingChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_spacing);
+ }
+}
+
+void LinearLayoutAttached::setAlignment(Qt::Alignment a)
+{
+ if (m_alignment != a) {
+ m_alignment = a;
+ emit alignmentChanged(reinterpret_cast<QGraphicsLayoutItem*>(parent()), m_alignment);
+ }
+}
+
+QGraphicsLinearLayoutStretchItemObject::QGraphicsLinearLayoutStretchItemObject(QObject *parent)
+ : QObject(parent)
+{
+}
+
+QSizeF QGraphicsLinearLayoutStretchItemObject::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
+{
+ Q_UNUSED(which);
+ Q_UNUSED(constraint);
+ return QSizeF();
+}
+
+
+QGraphicsLinearLayoutObject::QGraphicsLinearLayoutObject(QObject *parent)
+: QObject(parent)
+{
+}
+
+QGraphicsLinearLayoutObject::~QGraphicsLinearLayoutObject()
+{
+}
+
+void QGraphicsLinearLayoutObject::insertLayoutItem(int index, QGraphicsLayoutItem *item)
+{
+ insertItem(index, item);
+
+ //connect attached properties
+ if (LinearLayoutAttached *obj = attachedProperties.value(item)) {
+ setStretchFactor(item, obj->stretchFactor());
+ setAlignment(item, obj->alignment());
+ updateSpacing(item, obj->spacing());
+ QObject::connect(obj, SIGNAL(stretchChanged(QGraphicsLayoutItem*,int)),
+ this, SLOT(updateStretch(QGraphicsLayoutItem*,int)));
+ QObject::connect(obj, SIGNAL(alignmentChanged(QGraphicsLayoutItem*,Qt::Alignment)),
+ this, SLOT(updateAlignment(QGraphicsLayoutItem*,Qt::Alignment)));
+ QObject::connect(obj, SIGNAL(spacingChanged(QGraphicsLayoutItem*,int)),
+ this, SLOT(updateSpacing(QGraphicsLayoutItem*,int)));
+ //### need to disconnect when widget is removed?
+ }
+}
+
+void QGraphicsLinearLayoutObject::clearChildren()
+{
+ while (count() > 0)
+ removeAt(count()-1);
+}
+
+qreal QGraphicsLinearLayoutObject::contentsMargin() const
+{
+ qreal a, b, c, d;
+ getContentsMargins(&a, &b, &c, &d);
+ if (a == b && a == c && a == d)
+ return a;
+ return -1;
+}
+
+void QGraphicsLinearLayoutObject::setContentsMargin(qreal m)
+{
+ setContentsMargins(m, m, m, m);
+}
+
+void QGraphicsLinearLayoutObject::updateStretch(QGraphicsLayoutItem *item, int stretch)
+{
+ QGraphicsLinearLayout::setStretchFactor(item, stretch);
+}
+
+void QGraphicsLinearLayoutObject::updateSpacing(QGraphicsLayoutItem* item, int spacing)
+{
+ for (int i=0; i < count(); i++){
+ if (itemAt(i) == item) {
+ QGraphicsLinearLayout::setItemSpacing(i, spacing);
+ return;
+ }
+ }
+}
+
+void QGraphicsLinearLayoutObject::updateAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)
+{
+ QGraphicsLinearLayout::setAlignment(item, alignment);
+}
+
+QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> QGraphicsLinearLayoutObject::attachedProperties;
+LinearLayoutAttached *QGraphicsLinearLayoutObject::qmlAttachedProperties(QObject *obj)
+{
+ // ### This is not allowed - you must attach to any object
+ if (!qobject_cast<QGraphicsLayoutItem*>(obj))
+ return 0;
+ LinearLayoutAttached *rv = new LinearLayoutAttached(obj);
+ attachedProperties.insert(qobject_cast<QGraphicsLayoutItem*>(obj), rv);
+ return rv;
+}
+
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h
new file mode 100644
index 0000000..392f3f8
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef LINEARLAYOUT_H
+#define LINEARLAYOUT_H
+
+#include <qdeclarative.h>
+
+#include <QGraphicsLinearLayout>
+#include <QGraphicsLayoutItem>
+
+class QGraphicsLinearLayoutStretchItemObject : public QObject, public QGraphicsLayoutItem
+{
+ Q_OBJECT
+ Q_INTERFACES(QGraphicsLayoutItem)
+public:
+ QGraphicsLinearLayoutStretchItemObject(QObject *parent = 0);
+
+ virtual QSizeF sizeHint(Qt::SizeHint, const QSizeF &) const;
+};
+
+
+class LinearLayoutAttached;
+class QGraphicsLinearLayoutObject : public QObject, public QGraphicsLinearLayout
+{
+ Q_OBJECT
+ Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem)
+
+ Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children)
+ Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
+ Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing)
+ Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin)
+ Q_CLASSINFO("DefaultProperty", "children")
+public:
+ QGraphicsLinearLayoutObject(QObject * = 0);
+ ~QGraphicsLinearLayoutObject();
+
+ QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); }
+
+ static LinearLayoutAttached *qmlAttachedProperties(QObject *);
+
+ qreal contentsMargin() const;
+ void setContentsMargin(qreal);
+
+private slots:
+ void updateStretch(QGraphicsLayoutItem*,int);
+ void updateSpacing(QGraphicsLayoutItem*,int);
+ void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment);
+
+private:
+ friend class LinearLayoutAttached;
+
+ void clearChildren();
+ void insertLayoutItem(int, QGraphicsLayoutItem *);
+
+ static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) {
+ static_cast<QGraphicsLinearLayoutObject*>(prop->object)->insertLayoutItem(-1, item);
+ }
+
+ static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
+ static_cast<QGraphicsLinearLayoutObject*>(prop->object)->clearChildren();
+ }
+
+ static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
+ return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->count();
+ }
+
+ static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) {
+ return static_cast<QGraphicsLinearLayoutObject*>(prop->object)->itemAt(index);
+ }
+
+ static QHash<QGraphicsLayoutItem*, LinearLayoutAttached*> attachedProperties;
+};
+
+
+class LinearLayoutAttached : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int stretchFactor READ stretchFactor WRITE setStretchFactor NOTIFY stretchChanged)
+ Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
+ Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
+
+public:
+ LinearLayoutAttached(QObject *parent);
+
+ int stretchFactor() const { return m_stretch; }
+ void setStretchFactor(int f);
+ Qt::Alignment alignment() const { return m_alignment; }
+ void setAlignment(Qt::Alignment a);
+ int spacing() const { return m_spacing; }
+ void setSpacing(int s);
+
+signals:
+ void stretchChanged(QGraphicsLayoutItem*, int);
+ void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment);
+ void spacingChanged(QGraphicsLayoutItem*, int);
+
+private:
+ int m_stretch;
+ Qt::Alignment m_alignment;
+ int m_spacing;
+};
+
+QML_DECLARE_INTERFACE(QGraphicsLayoutItem)
+QML_DECLARE_INTERFACE(QGraphicsLayout)
+QML_DECLARE_TYPE(QGraphicsLinearLayoutStretchItemObject)
+QML_DECLARE_TYPE(QGraphicsLinearLayoutObject)
+QML_DECLARE_TYPEINFO(QGraphicsLinearLayoutObject, QML_HAS_ATTACHED_PROPERTIES)
+
+#endif
+
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc
new file mode 100644
index 0000000..93a3533
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/linearlayout.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>qgraphicslinearlayout.qml</file>
+</qresource>
+</RCC>
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp
new file mode 100644
index 0000000..c76e403
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/main.cpp
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "linearlayout.h"
+
+#include <qdeclarative.h>
+#include <QDeclarativeView>
+
+#include <QApplication>
+
+int main(int argc, char* argv[])
+{
+ QApplication app(argc, argv);
+
+ qmlRegisterInterface<QGraphicsLayoutItem>("QGraphicsLayoutItem");
+ qmlRegisterInterface<QGraphicsLayout>("QGraphicsLayout");
+ qmlRegisterType<QGraphicsLinearLayoutStretchItemObject>("LinearLayouts",4,7,"QGraphicsLinearLayoutStretchItem");
+ qmlRegisterType<QGraphicsLinearLayoutObject>("LinearLayouts",4,7,"QGraphicsLinearLayout");
+
+ QDeclarativeView view;
+ view.setSource(QUrl(":qgraphicslinearlayout.qml"));
+ view.show();
+
+ return app.exec();
+};
+
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro
new file mode 100644
index 0000000..79eb6ff
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.pro
@@ -0,0 +1,15 @@
+TEMPLATE = app
+TARGET = qgraphicslinearlayout
+QT += declarative
+
+SOURCES += \
+ linearlayout.cpp \
+ main.cpp
+
+HEADERS += \
+ linearlayout.h
+
+RESOURCES += \
+ linearlayout.qrc
+
+
diff --git a/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml
new file mode 100644
index 0000000..da77921
--- /dev/null
+++ b/examples/declarative/cppextensions/qgraphicslayouts/qgraphicslinearlayout/qgraphicslinearlayout.qml
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+import LinearLayouts 4.7
+
+Item {
+ width: 400
+ height: 400
+
+ QGraphicsWidget {
+ size.width: parent.width
+ size.height: parent.height
+
+ layout: QGraphicsLinearLayout {
+ LayoutItem {
+ minimumSize: "100x100"
+ maximumSize: "300x300"
+ preferredSize: "100x100"
+ Rectangle { color: "yellow"; anchors.fill: parent }
+ }
+ LayoutItem {
+ minimumSize: "100x100"
+ maximumSize: "400x400"
+ preferredSize: "200x200"
+ Rectangle { color: "green"; anchors.fill: parent }
+ }
+ }
+ }
+}
+