Update to 5.0.0-beta1
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickgridview_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKGRIDVIEW_P_H
43 #define QQUICKGRIDVIEW_P_H
44
45 #include "qquickitemview_p.h"
46
47 #include <private/qqmlguard_p.h>
48
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53 class QQuickVisualModel;
54 class QQuickGridViewAttached;
55 class QQuickGridViewPrivate;
56 class Q_AUTOTEST_EXPORT QQuickGridView : public QQuickItemView
57 {
58     Q_OBJECT
59     Q_DECLARE_PRIVATE(QQuickGridView)
60
61     Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
62     Q_PROPERTY(qreal cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
63     Q_PROPERTY(qreal cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)
64
65     Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
66
67     Q_ENUMS(SnapMode)
68     Q_ENUMS(Flow)
69     Q_CLASSINFO("DefaultProperty", "data")
70
71 public:
72     enum Flow {
73         FlowLeftToRight = LeftToRight,
74         FlowTopToBottom = TopToBottom
75     };
76
77     QQuickGridView(QQuickItem *parent=0);
78     ~QQuickGridView();
79
80     virtual void setHighlightFollowsCurrentItem(bool);
81     virtual void setHighlightMoveDuration(int);
82
83     Flow flow() const;
84     void setFlow(Flow);
85
86     qreal cellWidth() const;
87     void setCellWidth(qreal);
88
89     qreal cellHeight() const;
90     void setCellHeight(qreal);
91
92     enum SnapMode { NoSnap, SnapToRow, SnapOneRow };
93     SnapMode snapMode() const;
94     void setSnapMode(SnapMode mode);
95
96     static QQuickGridViewAttached *qmlAttachedProperties(QObject *);
97
98 public Q_SLOTS:
99     void moveCurrentIndexUp();
100     void moveCurrentIndexDown();
101     void moveCurrentIndexLeft();
102     void moveCurrentIndexRight();
103
104 Q_SIGNALS:
105     void cellWidthChanged();
106     void cellHeightChanged();
107     void highlightMoveDurationChanged();
108     void flowChanged();
109     void snapModeChanged();
110
111 protected:
112     virtual void viewportMoved(Qt::Orientations);
113     virtual void keyPressEvent(QKeyEvent *);
114     virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
115     virtual void initItem(int index, QQuickItem *item);
116 };
117
118 class QQuickGridViewAttached : public QQuickItemViewAttached
119 {
120     Q_OBJECT
121 public:
122     QQuickGridViewAttached(QObject *parent)
123         : QQuickItemViewAttached(parent), m_view(0) {}
124     ~QQuickGridViewAttached() {}
125
126     Q_PROPERTY(QQuickGridView *view READ view NOTIFY viewChanged)
127     QQuickGridView *view() { return m_view; }
128     void setView(QQuickGridView *view) {
129         if (view != m_view) {
130             m_view = view;
131             emit viewChanged();
132         }
133     }
134
135 Q_SIGNALS:
136     void viewChanged();
137
138 public:
139     QQmlGuard<QQuickGridView> m_view;
140 };
141
142
143 QT_END_NAMESPACE
144
145 QML_DECLARE_TYPE(QQuickGridView)
146 QML_DECLARE_TYPEINFO(QQuickGridView, QML_HAS_ATTACHED_PROPERTIES)
147
148 QT_END_HEADER
149
150 #endif // QQUICKGRIDVIEW_P_H