source: trunk/examples/declarative/cppextensions/qgraphicslayouts/qgraphicsgridlayout/gridlayout.h@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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:BSD$
10** You may use this file under the terms of the BSD license as follows:
11**
12** "Redistribution and use in source and binary forms, with or without
13** modification, are permitted provided that the following conditions are
14** met:
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
20** distribution.
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
24** permission.
25**
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."
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef GRIDLAYOUT_H
42#define GRIDLAYOUT_H
43
44#include <qdeclarative.h>
45
46#include <QGraphicsGridLayout>
47#include <QGraphicsLayoutItem>
48
49class GridLayoutAttached;
50class GraphicsGridLayoutObject : public QObject, public QGraphicsGridLayout
51{
52 Q_OBJECT
53 Q_INTERFACES(QGraphicsLayout QGraphicsLayoutItem)
54
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")
61
62public:
63 GraphicsGridLayoutObject(QObject * = 0);
64 ~GraphicsGridLayoutObject();
65
66 QDeclarativeListProperty<QGraphicsLayoutItem> children() { return QDeclarativeListProperty<QGraphicsLayoutItem>(this, 0, children_append, children_count, children_at, children_clear); }
67
68 qreal spacing() const;
69 qreal contentsMargin() const;
70 void setContentsMargin(qreal);
71
72 void removeAt(int index);
73
74 static GridLayoutAttached *qmlAttachedProperties(QObject *);
75
76private slots:
77 void updateAlignment(QGraphicsLayoutItem*,Qt::Alignment);
78
79private:
80 friend class GraphicsLayoutAttached;
81
82 void addWidget(QGraphicsWidget *);
83 void clearChildren();
84 void addLayoutItem(QGraphicsLayoutItem *);
85
86 static void children_append(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, QGraphicsLayoutItem *item) {
87 static_cast<GraphicsGridLayoutObject*>(prop->object)->addLayoutItem(item);
88 }
89
90 static void children_clear(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
91 static_cast<GraphicsGridLayoutObject*>(prop->object)->clearChildren();
92 }
93
94 static int children_count(QDeclarativeListProperty<QGraphicsLayoutItem> *prop) {
95 return static_cast<GraphicsGridLayoutObject*>(prop->object)->count();
96 }
97
98 static QGraphicsLayoutItem *children_at(QDeclarativeListProperty<QGraphicsLayoutItem> *prop, int index) {
99 return static_cast<GraphicsGridLayoutObject*>(prop->object)->itemAt(index);
100 }
101
102 static QHash<QGraphicsLayoutItem*, GridLayoutAttached*> attachedProperties;
103};
104
105
106class GridLayoutAttached : public QObject
107{
108 Q_OBJECT
109
110 Q_PROPERTY(int row READ row WRITE setRow)
111 Q_PROPERTY(int column READ column WRITE setColumn)
112
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)
116
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)
121
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)
126
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)
131
132public:
133 GridLayoutAttached(QObject *parent);
134
135 int row() const { return m_row; }
136 void setRow(int r) { m_row = r; }
137
138 int column() const { return m_column; }
139 void setColumn(int c) { m_column = c; }
140
141 int rowSpan() const { return m_rowspan; }
142 void setRowSpan(int rs) { m_rowspan = rs; }
143
144 int columnSpan() const { return m_colspan; }
145 void setColumnSpan(int cs) { m_colspan = cs; }
146
147 Qt::Alignment alignment() const { return m_alignment; }
148 void setAlignment(Qt::Alignment a);
149
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; }
154
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; }
159
160 int rowPreferredHeight() const { return m_rowPrefHeight; }
161 void setRowPreferredHeight(int s) { m_rowPrefHeight = s; }
162
163 int rowMaximumHeight() const { return m_rowMaxHeight; }
164 void setRowMaximumHeight(int s) { m_rowMaxHeight = s; }
165
166 int rowMinimumHeight() const { return m_rowMinHeight; }
167 void setRowMinimumHeight(int s) { m_rowMinHeight = s; }
168
169 int rowFixedHeight() const { return m_rowFixHeight; }
170 void setRowFixedHeight(int s) { m_rowFixHeight = s; }
171
172 int columnPreferredWidth() const { return m_colPrefwidth; }
173 void setColumnPreferredWidth(int s) { m_colPrefwidth = s; }
174
175 int columnMaximumWidth() const { return m_colMaxwidth; }
176 void setColumnMaximumWidth(int s) { m_colMaxwidth = s; }
177
178 int columnMinimumWidth() const { return m_colMinwidth; }
179 void setColumnMinimumWidth(int s) { m_colMinwidth = s; }
180
181 int columnFixedWidth() const { return m_colFixwidth; }
182 void setColumnFixedWidth(int s) { m_colFixwidth = s; }
183
184signals:
185 void alignmentChanged(QGraphicsLayoutItem*, Qt::Alignment);
186
187private:
188 int m_row;
189 int m_column;
190
191 int m_rowspan;
192 int m_colspan;
193 Qt::Alignment m_alignment;
194
195 int m_rowStretch;
196 int m_colStretch;
197 int m_rowSpacing;
198 int m_colSpacing;
199
200 int m_rowPrefHeight;
201 int m_rowMaxHeight;
202 int m_rowMinHeight;
203 int m_rowFixHeight;
204
205 int m_colPrefwidth;
206 int m_colMaxwidth;
207 int m_colMinwidth;
208 int m_colFixwidth;
209};
210
211QML_DECLARE_INTERFACE(QGraphicsLayoutItem)
212QML_DECLARE_INTERFACE(QGraphicsLayout)
213QML_DECLARE_TYPE(GraphicsGridLayoutObject)
214QML_DECLARE_TYPEINFO(GraphicsGridLayoutObject, QML_HAS_ATTACHED_PROPERTIES)
215
216#endif
217
Note: See TracBrowser for help on using the repository browser.