More documentation about importing LocalStorage module from Javascript
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitemsmodule.cpp
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 QtDeclarative 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 #include "qquickitemsmodule_p.h"
43
44 #include "qquickitem.h"
45 #include "qquickitem_p.h"
46 #include "qquickevents_p_p.h"
47 #include "qquickrectangle_p.h"
48 #include "qquickfocusscope_p.h"
49 #include "qquicktext_p.h"
50 #include "qquicktextinput_p.h"
51 #include "qquicktextedit_p.h"
52 #include "qquickimage_p.h"
53 #include "qquickborderimage_p.h"
54 #include "qquickscalegrid_p_p.h"
55 #include "qquickmousearea_p.h"
56 #include "qquickpincharea_p.h"
57 #include "qquickflickable_p.h"
58 #include "qquickflickable_p_p.h"
59 #include "qquicklistview_p.h"
60 #include "qquickvisualitemmodel_p.h"
61 #include "qquickvisualdatamodel_p.h"
62 #include "qquickgridview_p.h"
63 #include "qquickpathview_p.h"
64 #include "qquickitemviewtransition_p.h"
65 #include <private/qdeclarativepath_p.h>
66 #include <private/qdeclarativepathinterpolator_p.h>
67 #include "qquickpositioners_p.h"
68 #include "qquickrepeater_p.h"
69 #include "qquickloader_p.h"
70 #include "qquickanimatedimage_p.h"
71 #include "qquickflipable_p.h"
72 #include "qquicktranslate_p.h"
73 #include "qquickstateoperations_p.h"
74 #include "qquickanimation_p.h"
75 #include <private/qquickshadereffect_p.h>
76 #include <QtQuick/private/qquickshadereffectsource_p.h>
77 //#include <private/qquickpincharea_p.h>
78 #include <QtQuick/private/qquickcanvasitem_p.h>
79 #include <QtQuick/private/qquickcontext2d_p.h>
80 #include "qquicksprite_p.h"
81 #include "qquickspritesequence_p.h"
82 #include "qquickanimatedsprite_p.h"
83 #include "qquickdrag_p.h"
84 #include "qquickdroparea_p.h"
85 #include "qquickmultipointtoucharea_p.h"
86 #include <private/qdeclarativemetatype_p.h>
87 #include <QtQuick/private/qquickaccessibleattached_p.h>
88
89 static QDeclarativePrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject *parent)
90 {
91     QQuickItem *item = qobject_cast<QQuickItem *>(obj);
92     if (!item)
93         return QDeclarativePrivate::IncompatibleObject;
94
95     QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent);
96     if (!parentItem)
97         return QDeclarativePrivate::IncompatibleParent;
98
99     item->setParentItem(parentItem);
100     return QDeclarativePrivate::Parented;
101 }
102
103 static bool compareQQuickAnchorLines(const void *p1, const void *p2)
104 {
105     const QQuickAnchorLine &l1 = *static_cast<const QQuickAnchorLine*>(p1);
106     const QQuickAnchorLine &l2 = *static_cast<const QQuickAnchorLine*>(p2);
107     return l1 == l2;
108 }
109
110 static void qt_quickitems_defineModule(const char *uri, int major, int minor)
111 {
112     QDeclarativePrivate::RegisterAutoParent autoparent = { 0, &qquickitem_autoParent };
113     QDeclarativePrivate::qmlregister(QDeclarativePrivate::AutoParentRegistration, &autoparent);
114     QQuickItemPrivate::registerAccessorProperties();
115
116 #ifdef QT_NO_MOVIE
117     qmlRegisterTypeNotAvailable(uri,major,minor,"AnimatedImage", qApp->translate("QQuickAnimatedImage","Qt was built without support for QMovie"));
118 #else
119     qmlRegisterType<QQuickAnimatedImage>(uri,major,minor,"AnimatedImage");
120 #endif
121     qmlRegisterType<QQuickBorderImage>(uri,major,minor,"BorderImage");
122     qmlRegisterType<QQuickColumn>(uri,major,minor,"Column");
123     qmlRegisterType<QQuickFlickable>(uri,major,minor,"Flickable");
124     qmlRegisterType<QQuickFlipable>(uri,major,minor,"Flipable");
125     qmlRegisterType<QQuickFlow>(uri,major,minor,"Flow");
126 //    qmlRegisterType<QDeclarativeFocusPanel>(uri,major,minor,"FocusPanel");
127     qmlRegisterType<QQuickFocusScope>(uri,major,minor,"FocusScope");
128     qmlRegisterType<QQuickGradient>(uri,major,minor,"Gradient");
129     qmlRegisterType<QQuickGradientStop>(uri,major,minor,"GradientStop");
130     qmlRegisterType<QQuickGrid>(uri,major,minor,"Grid");
131     qmlRegisterType<QQuickGridView>(uri,major,minor,"GridView");
132     qmlRegisterType<QQuickImage>(uri,major,minor,"Image");
133     qmlRegisterType<QQuickItem>(uri,major,minor,"Item");
134     qmlRegisterType<QQuickListView>(uri,major,minor,"ListView");
135     qmlRegisterType<QQuickLoader>(uri,major,minor,"Loader");
136     qmlRegisterType<QQuickMouseArea>(uri,major,minor,"MouseArea");
137     qmlRegisterType<QDeclarativePath>(uri,major,minor,"Path");
138     qmlRegisterType<QDeclarativePathAttribute>(uri,major,minor,"PathAttribute");
139     qmlRegisterType<QDeclarativePathCubic>(uri,major,minor,"PathCubic");
140     qmlRegisterType<QDeclarativePathLine>(uri,major,minor,"PathLine");
141     qmlRegisterType<QDeclarativePathPercent>(uri,major,minor,"PathPercent");
142     qmlRegisterType<QDeclarativePathQuad>(uri,major,minor,"PathQuad");
143     qmlRegisterType<QDeclarativePathCatmullRomCurve>("QtQuick",2,0,"PathCurve");
144     qmlRegisterType<QDeclarativePathArc>("QtQuick",2,0,"PathArc");
145     qmlRegisterType<QDeclarativePathSvg>("QtQuick",2,0,"PathSvg");
146     qmlRegisterType<QQuickPathView>(uri,major,minor,"PathView");
147     qmlRegisterUncreatableType<QQuickBasePositioner>(uri,major,minor,"Positioner",
148                                                   QStringLiteral("Positioner is an abstract type that is only available as an attached property."));
149 #ifndef QT_NO_VALIDATOR
150     qmlRegisterType<QQuickIntValidator>(uri,major,minor,"IntValidator");
151     qmlRegisterType<QQuickDoubleValidator>(uri,major,minor,"DoubleValidator");
152     qmlRegisterType<QRegExpValidator>(uri,major,minor,"RegExpValidator");
153 #endif
154     qmlRegisterType<QQuickRectangle>(uri,major,minor,"Rectangle");
155     qmlRegisterType<QQuickRepeater>(uri,major,minor,"Repeater");
156     qmlRegisterType<QQuickRow>(uri,major,minor,"Row");
157     qmlRegisterType<QQuickTranslate>(uri,major,minor,"Translate");
158     qmlRegisterType<QQuickRotation>(uri,major,minor,"Rotation");
159     qmlRegisterType<QQuickScale>(uri,major,minor,"Scale");
160     qmlRegisterType<QQuickText>(uri,major,minor,"Text");
161     qmlRegisterType<QQuickTextEdit>(uri,major,minor,"TextEdit");
162     qmlRegisterType<QQuickTextInput>(uri,major,minor,"TextInput");
163     qmlRegisterType<QQuickViewSection>(uri,major,minor,"ViewSection");
164     qmlRegisterType<QQuickVisualDataModel>(uri,major,minor,"VisualDataModel");
165     qmlRegisterType<QQuickVisualDataGroup>(uri,major,minor,"VisualDataGroup");
166     qmlRegisterType<QQuickVisualItemModel>(uri,major,minor,"VisualItemModel");
167
168     qmlRegisterType<QQuickItemLayer>();
169     qmlRegisterType<QQuickAnchors>();
170     qmlRegisterType<QQuickKeyEvent>();
171     qmlRegisterType<QQuickMouseEvent>();
172     qmlRegisterType<QQuickTransform>();
173     qmlRegisterType<QDeclarativePathElement>();
174     qmlRegisterType<QDeclarativeCurve>();
175     qmlRegisterType<QQuickScaleGrid>();
176     qmlRegisterType<QQuickTextLine>();
177 #ifndef QT_NO_VALIDATOR
178     qmlRegisterType<QValidator>();
179 #endif
180     qmlRegisterType<QQuickVisualModel>();
181     qmlRegisterType<QQuickPen>();
182     qmlRegisterType<QQuickFlickableVisibleArea>();
183     qRegisterMetaType<QQuickAnchorLine>("QQuickAnchorLine");
184     QDeclarativeMetaType::setQQuickAnchorLineCompareFunction(compareQQuickAnchorLines);
185
186     qmlRegisterUncreatableType<QQuickKeyNavigationAttached>(uri,major,minor,"KeyNavigation",QQuickKeyNavigationAttached::tr("KeyNavigation is only available via attached properties"));
187     qmlRegisterUncreatableType<QQuickKeysAttached>(uri,major,minor,"Keys",QQuickKeysAttached::tr("Keys is only available via attached properties"));
188     qmlRegisterUncreatableType<QQuickLayoutMirroringAttached>(uri,major,minor,"LayoutMirroring", QQuickLayoutMirroringAttached::tr("LayoutMirroring is only available via attached properties"));
189     qmlRegisterUncreatableType<QQuickViewTransitionAttached>(uri,major,minor,"ViewTransition",QQuickViewTransitionAttached::tr("ViewTransition is only available via attached properties"));
190
191     qmlRegisterType<QQuickPinchArea>(uri,major,minor,"PinchArea");
192     qmlRegisterType<QQuickPinch>(uri,major,minor,"Pinch");
193     qmlRegisterType<QQuickPinchEvent>();
194
195     qmlRegisterType<QQuickShaderEffect>("QtQuick", 2, 0, "ShaderEffect");
196     qmlRegisterType<QQuickShaderEffectSource>("QtQuick", 2, 0, "ShaderEffectSource");
197     qmlRegisterUncreatableType<QQuickShaderEffectMesh>("QtQuick", 2, 0, "ShaderEffectMesh", QQuickShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh."));
198     qmlRegisterType<QQuickGridMesh>("QtQuick", 2, 0, "GridMesh");
199
200     qmlRegisterUncreatableType<QQuickPaintedItem>("QtQuick", 2, 0, "PaintedItem", QQuickPaintedItem::tr("Cannot create instance of abstract class PaintedItem"));
201
202     qmlRegisterType<QQuickCanvasItem>("QtQuick", 2, 0, "Canvas");
203
204     qmlRegisterType<QQuickSprite>("QtQuick", 2, 0, "Sprite");
205     qmlRegisterType<QQuickAnimatedSprite>("QtQuick", 2, 0, "AnimatedSprite");
206     qmlRegisterType<QQuickSpriteSequence>("QtQuick", 2, 0, "SpriteSequence");
207     qmlRegisterType<QQuickSpriteSequence>("QtQuick", 2, 0, "SpriteImage");//Deprecation in progress
208
209     qmlRegisterType<QQuickParentChange>(uri, major, minor,"ParentChange");
210     qmlRegisterType<QQuickAnchorChanges>(uri, major, minor,"AnchorChanges");
211     qmlRegisterType<QQuickAnchorSet>();
212     qmlRegisterType<QQuickAnchorAnimation>(uri, major, minor,"AnchorAnimation");
213     qmlRegisterType<QQuickParentAnimation>(uri, major, minor,"ParentAnimation");
214     qmlRegisterType<QQuickPathAnimation>("QtQuick",2,0,"PathAnimation");
215     qmlRegisterType<QDeclarativePathInterpolator>("QtQuick",2,0,"PathInterpolator");
216
217     qmlRegisterType<QQuickDropArea>("QtQuick", 2, 0, "DropArea");
218     qmlRegisterType<QQuickDropEvent>();
219     qmlRegisterType<QQuickDropAreaDrag>();
220     qmlRegisterUncreatableType<QQuickDrag>("QtQuick", 2, 0, "Drag", QQuickDragAttached::tr("Drag is only available via attached properties"));
221
222     qmlRegisterType<QQuickMultiPointTouchArea>("QtQuick", 2, 0, "MultiPointTouchArea");
223     qmlRegisterType<QQuickTouchPoint>("QtQuick", 2, 0, "TouchPoint");
224     qmlRegisterType<QQuickGrabGestureEvent>();
225
226 #ifndef QT_NO_ACCESSIBILITY
227     qmlRegisterUncreatableType<QQuickAccessibleAttached>("QtQuick", 2, 0, "Accessible",QQuickAccessibleAttached::tr("Accessible is only available via attached properties"));
228 #endif
229 }
230
231 void QQuickItemsModule::defineModule()
232 {
233     static bool initialized = false;
234     if (initialized)
235         return;
236     initialized = true;
237
238     QByteArray name = "QtQuick";
239     int majorVersion = 2;
240     int minorVersion = 0;
241
242     qt_quickitems_defineModule(name, majorVersion, minorVersion);
243 }
244