Rename Qt Quick-specific classes to QQuick*
[profile/ivi/qtdeclarative.git] / src / declarative / items / qquickitemsmodule.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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 <private/qquickshadereffectsource_p.h>
76 //#include <private/qquickpincharea_p.h>
77 #include <private/qquickcanvasitem_p.h>
78 #include <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
84 static QDeclarativePrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject *parent)
85 {
86     QQuickItem *item = qobject_cast<QQuickItem *>(obj);
87     if (!item)
88         return QDeclarativePrivate::IncompatibleObject;
89
90     QQuickItem *parentItem = qobject_cast<QQuickItem *>(parent);
91     if (!parentItem)
92         return QDeclarativePrivate::IncompatibleParent;
93
94     item->setParentItem(parentItem);
95     return QDeclarativePrivate::Parented;
96 }
97
98 static void qt_quickitems_defineModule(const char *uri, int major, int minor)
99 {
100     QDeclarativePrivate::RegisterAutoParent autoparent = { 0, &qquickitem_autoParent };
101     QDeclarativePrivate::qmlregister(QDeclarativePrivate::AutoParentRegistration, &autoparent);
102
103 #ifdef QT_NO_MOVIE
104     qmlRegisterTypeNotAvailable(uri,major,minor,"AnimatedImage", qApp->translate("QQuickAnimatedImage","Qt was built without support for QMovie"));
105 #else
106     qmlRegisterType<QQuickAnimatedImage>(uri,major,minor,"AnimatedImage");
107 #endif
108     qmlRegisterType<QQuickBorderImage>(uri,major,minor,"BorderImage");
109     qmlRegisterType<QQuickColumn>(uri,major,minor,"Column");
110     qmlRegisterType<QQuickFlickable>(uri,major,minor,"Flickable");
111     qmlRegisterType<QQuickFlipable>(uri,major,minor,"Flipable");
112     qmlRegisterType<QQuickFlow>(uri,major,minor,"Flow");
113 //    qmlRegisterType<QDeclarativeFocusPanel>(uri,major,minor,"FocusPanel");
114     qmlRegisterType<QQuickFocusScope>(uri,major,minor,"FocusScope");
115     qmlRegisterType<QQuickGradient>(uri,major,minor,"Gradient");
116     qmlRegisterType<QQuickGradientStop>(uri,major,minor,"GradientStop");
117     qmlRegisterType<QQuickGrid>(uri,major,minor,"Grid");
118     qmlRegisterType<QQuickGridView>(uri,major,minor,"GridView");
119     qmlRegisterType<QQuickImage>(uri,major,minor,"Image");
120     qmlRegisterType<QQuickItem>(uri,major,minor,"Item");
121     qmlRegisterType<QQuickListView>(uri,major,minor,"ListView");
122     qmlRegisterType<QQuickLoader>(uri,major,minor,"Loader");
123     qmlRegisterType<QQuickMouseArea>(uri,major,minor,"MouseArea");
124     qmlRegisterType<QDeclarativePath>(uri,major,minor,"Path");
125     qmlRegisterType<QDeclarativePathAttribute>(uri,major,minor,"PathAttribute");
126     qmlRegisterType<QDeclarativePathCubic>(uri,major,minor,"PathCubic");
127     qmlRegisterType<QDeclarativePathLine>(uri,major,minor,"PathLine");
128     qmlRegisterType<QDeclarativePathPercent>(uri,major,minor,"PathPercent");
129     qmlRegisterType<QDeclarativePathQuad>(uri,major,minor,"PathQuad");
130     qmlRegisterType<QDeclarativePathCatmullRomCurve>("QtQuick",2,0,"PathCurve");
131     qmlRegisterType<QDeclarativePathArc>("QtQuick",2,0,"PathArc");
132     qmlRegisterType<QDeclarativePathSvg>("QtQuick",2,0,"PathSvg");
133     qmlRegisterType<QQuickPathView>(uri,major,minor,"PathView");
134     qmlRegisterUncreatableType<QQuickBasePositioner>(uri,major,minor,"Positioner",
135                                                   QStringLiteral("Positioner is an abstract type that is only available as an attached property."));
136 #ifndef QT_NO_VALIDATOR
137     qmlRegisterType<QIntValidator>(uri,major,minor,"IntValidator");
138     qmlRegisterType<QDoubleValidator>(uri,major,minor,"DoubleValidator");
139     qmlRegisterType<QRegExpValidator>(uri,major,minor,"RegExpValidator");
140 #endif
141     qmlRegisterType<QQuickRectangle>(uri,major,minor,"Rectangle");
142     qmlRegisterType<QQuickRepeater>(uri,major,minor,"Repeater");
143     qmlRegisterType<QQuickRow>(uri,major,minor,"Row");
144     qmlRegisterType<QQuickTranslate>(uri,major,minor,"Translate");
145     qmlRegisterType<QQuickRotation>(uri,major,minor,"Rotation");
146     qmlRegisterType<QQuickScale>(uri,major,minor,"Scale");
147     qmlRegisterType<QQuickText>(uri,major,minor,"Text");
148     qmlRegisterType<QQuickTextEdit>(uri,major,minor,"TextEdit");
149     qmlRegisterType<QQuickTextInput>(uri,major,minor,"TextInput");
150     qmlRegisterType<QQuickViewSection>(uri,major,minor,"ViewSection");
151     qmlRegisterType<QQuickVisualDataModel>(uri,major,minor,"VisualDataModel");
152     qmlRegisterType<QQuickVisualDataGroup>(uri,major,minor,"VisualDataGroup");
153     qmlRegisterType<QQuickVisualItemModel>(uri,major,minor,"VisualItemModel");
154
155     qmlRegisterType<QQuickAnchors>();
156     qmlRegisterType<QQuickKeyEvent>();
157     qmlRegisterType<QQuickMouseEvent>();
158     qmlRegisterType<QQuickTransform>();
159     qmlRegisterType<QDeclarativePathElement>();
160     qmlRegisterType<QDeclarativeCurve>();
161     qmlRegisterType<QQuickScaleGrid>();
162     qmlRegisterType<QQuickTextLine>();
163 #ifndef QT_NO_VALIDATOR
164     qmlRegisterType<QValidator>();
165 #endif
166     qmlRegisterType<QQuickVisualModel>();
167     qmlRegisterType<QQuickPen>();
168     qmlRegisterType<QQuickFlickableVisibleArea>();
169     qRegisterMetaType<QQuickAnchorLine>("QQuickAnchorLine");
170
171     qmlRegisterUncreatableType<QQuickKeyNavigationAttached>(uri,major,minor,"KeyNavigation",QQuickKeyNavigationAttached::tr("KeyNavigation is only available via attached properties"));
172     qmlRegisterUncreatableType<QQuickKeysAttached>(uri,major,minor,"Keys",QQuickKeysAttached::tr("Keys is only available via attached properties"));
173     qmlRegisterUncreatableType<QQuickLayoutMirroringAttached>(uri,major,minor,"LayoutMirroring", QQuickLayoutMirroringAttached::tr("LayoutMirroring is only available via attached properties"));
174
175     qmlRegisterType<QQuickPinchArea>(uri,major,minor,"PinchArea");
176     qmlRegisterType<QQuickPinch>(uri,major,minor,"Pinch");
177     qmlRegisterType<QQuickPinchEvent>();
178
179     qmlRegisterType<QQuickShaderEffectItem>("QtQuick", 2, 0, "ShaderEffectItem"); // TODO: Remove after grace period.
180     qmlRegisterType<QQuickShaderEffect>("QtQuick", 2, 0, "ShaderEffect");
181     qmlRegisterType<QQuickShaderEffectSource>("QtQuick", 2, 0, "ShaderEffectSource");
182     qmlRegisterUncreatableType<QQuickShaderEffectMesh>("QtQuick", 2, 0, "ShaderEffectMesh", QQuickShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh."));
183     qmlRegisterType<QQuickGridMesh>("QtQuick", 2, 0, "GridMesh");
184
185     qmlRegisterUncreatableType<QQuickPaintedItem>("QtQuick", 2, 0, "PaintedItem", QQuickPaintedItem::tr("Cannot create instance of abstract class PaintedItem"));
186
187     qmlRegisterType<QQuickCanvasItem>("QtQuick", 2, 0, "Canvas");
188
189     qmlRegisterType<QQuickSprite>("QtQuick", 2, 0, "Sprite");
190     qmlRegisterType<QQuickSpriteImage>("QtQuick", 2, 0, "SpriteImage");
191
192     qmlRegisterType<QQuickParentChange>(uri, major, minor,"ParentChange");
193     qmlRegisterType<QQuickAnchorChanges>(uri, major, minor,"AnchorChanges");
194     qmlRegisterType<QQuickAnchorSet>();
195     qmlRegisterType<QQuickAnchorAnimation>(uri, major, minor,"AnchorAnimation");
196     qmlRegisterType<QQuickParentAnimation>(uri, major, minor,"ParentAnimation");
197     qmlRegisterType<QQuickPathAnimation>("QtQuick",2,0,"PathAnimation");
198     qmlRegisterType<QDeclarativePathInterpolator>("QtQuick",2,0,"PathInterpolator");
199
200     qmlRegisterType<QQuickDropArea>("QtQuick", 2, 0, "DropArea");
201     qmlRegisterType<QQuickDropEvent>();
202     qmlRegisterType<QQuickDropAreaDrag>();
203     qmlRegisterUncreatableType<QQuickDrag>("QtQuick", 2, 0, "Drag", QQuickDragAttached::tr("Drag is only available via attached properties"));
204 }
205
206 void QQuickItemsModule::defineModule()
207 {
208     static bool initialized = false;
209     if (initialized)
210         return;
211     initialized = true;
212
213     // XXX todo -  Remove before final integration...
214     QByteArray mode = qgetenv("QMLSCENE_IMPORT_NAME");
215     QByteArray name = "QtQuick";
216     int majorVersion = 2;
217     int minorVersion = 0;
218     if (mode == "quick1") {
219         majorVersion = 1;
220     } else if (mode == "qt") {
221         name = "Qt";
222         majorVersion = 4;
223         minorVersion = 7;
224     }
225
226     qt_quickitems_defineModule(name, majorVersion, minorVersion);
227 }
228