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