1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the examples of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
44 #include <qdeclarative.h>
46 #include <QGraphicsGridLayout>
47 #include <QGraphicsLayoutItem>
49 class GridLayoutAttached;
50 class GraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout
53 Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem)
55 Q_PROPERTY(QDeclarativeListProperty<QGraphicsLayoutItem> children READ children)
56 Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing)
57 Q_PROPERTY(qreal contentsMargin READ contentsMargin WRITE setContentsMargin)
58 Q_PROPERTY(qreal verticalSpacing READ verticalSpacing WRITE setVerticalSpacing)
59 Q_PROPERTY(qreal horizontalSpacing READ horizontalSpacing WRITE setHorizontalSpacing)
60 Q_CLASSINFO("DefaultProperty", "children")
63 GraphicsGridLayoutObject(QObject * = 0);
64 ~GraphicsGridLayoutObject();
66 QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); }
68 qreal spacing() const;
69 qreal contentsMargin() const;
70 void setContentsMargin(qreal);
72 void removeAt(int index);
74 static GridLayoutAttached *qmlAttachedProperties(QObject *);
77 void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment);
80 friend class GraphicsLayoutAttached;
82 void addWidget(QGraphicsWidget *);
84 void addLayoutItem(QGraphicsLayoutItem *);
86 static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) {
87 static_cast<GraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item);
90 static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
91 static_cast<GraphicsGridLayoutObject*>(prop->object)->clearChildren();
94 static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
95 return static_cast<GraphicsGridLayoutObject*>(prop->object)->count();
98 static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) {
99 return static_cast<GraphicsGridLayoutObject*>(prop->object)->itemAt(index);
102 static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties;
106 class GridLayoutAttached : public QObject
110 Q_PROPERTY(int row READ row WRITE setRow)
111 Q_PROPERTY(int column READ column WRITE setColumn)
113 Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan)
114 Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan)
115 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
117 Q_PROPERTY(int rowStretchFactor READ rowStretchFactor WRITE setRowStretchFactor)
118 Q_PROPERTY(int columnStretchFactor READ columnStretchFactor WRITE setColumnStretchFactor)
119 Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing)
120 Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing)
122 Q_PROPERTY(int rowPreferredHeight READ rowPreferredHeight WRITE setRowPreferredHeight)
123 Q_PROPERTY(int rowMinimumHeight READ rowMinimumHeight WRITE setRowMinimumHeight)
124 Q_PROPERTY(int rowMaximumHeight READ rowMaximumHeight WRITE setRowMaximumHeight)
125 Q_PROPERTY(int rowFixedHeight READ rowFixedHeight WRITE setRowFixedHeight)
127 Q_PROPERTY(int columnPreferredWidth READ columnPreferredWidth WRITE setColumnPreferredWidth)
128 Q_PROPERTY(int columnMaximumWidth READ columnMaximumWidth WRITE setColumnMaximumWidth)
129 Q_PROPERTY(int columnMinimumWidth READ columnMinimumWidth WRITE setColumnMinimumWidth)
130 Q_PROPERTY(int columnFixedWidth READ columnFixedWidth WRITE setColumnFixedWidth)
133 GridLayoutAttached(QObject *parent);
135 int row() const { return m_row; }
136 void setRow(int r) { m_row = r; }
138 int column() const { return m_column; }
139 void setColumn(int c) { m_column = c; }
141 int rowSpan() const { return m_rowspan; }
142 void setRowSpan(int rs) { m_rowspan = rs; }
144 int columnSpan() const { return m_colspan; }
145 void setColumnSpan(int cs) { m_colspan = cs; }
147 Qt::Alignment alignment() const { return m_alignment; }
148 void setAlignment(Qt::Alignment a);
150 int rowStretchFactor() const { return m_rowStretch; }
151 void setRowStretchFactor(int f) { m_rowStretch = f; }
152 int columnStretchFactor() const { return m_colStretch; }
153 void setColumnStretchFactor(int f) { m_colStretch = f; }
155 int rowSpacing() const { return m_rowSpacing; }
156 void setRowSpacing(int s) { m_rowSpacing = s; }
157 int columnSpacing() const { return m_colSpacing; }
158 void setColumnSpacing(int s) { m_colSpacing = s; }
160 int rowPreferredHeight() const { return m_rowPrefHeight; }
161 void setRowPreferredHeight(int s) { m_rowPrefHeight = s; }
163 int rowMaximumHeight() const { return m_rowMaxHeight; }
164 void setRowMaximumHeight(int s) { m_rowMaxHeight = s; }
166 int rowMinimumHeight() const { return m_rowMinHeight; }
167 void setRowMinimumHeight(int s) { m_rowMinHeight = s; }
169 int rowFixedHeight() const { return m_rowFixHeight; }
170 void setRowFixedHeight(int s) { m_rowFixHeight = s; }
172 int columnPreferredWidth() const { return m_colPrefwidth; }
173 void setColumnPreferredWidth(int s) { m_colPrefwidth = s; }
175 int columnMaximumWidth() const { return m_colMaxwidth; }
176 void setColumnMaximumWidth(int s) { m_colMaxwidth = s; }
178 int columnMinimumWidth() const { return m_colMinwidth; }
179 void setColumnMinimumWidth(int s) { m_colMinwidth = s; }
181 int columnFixedWidth() const { return m_colFixwidth; }
182 void setColumnFixedWidth(int s) { m_colFixwidth = s; }
185 void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment);
193 Qt::Alignment m_alignment;
211 QML_DECLARE_INTERFACE(QGraphicsLayoutItem)
212 QML_DECLARE_INTERFACE(QGraphicsLayout)
213 QML_DECLARE_TYPE(GraphicsGridLayoutObject)
214 QML_DECLARE_TYPEINFO(GraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES)