src/declarative/qml/qdeclarativeengine.cpp
changeset 33 3e2da88830cd
parent 30 5dc02b23752f
child 37 758a864f9613
equal deleted inserted replaced
30:5dc02b23752f 33:3e2da88830cd
    91 #include <QtCore/qdir.h>
    91 #include <QtCore/qdir.h>
    92 #include <QtCore/qmutex.h>
    92 #include <QtCore/qmutex.h>
    93 #include <QtGui/qcolor.h>
    93 #include <QtGui/qcolor.h>
    94 #include <QtGui/qvector3d.h>
    94 #include <QtGui/qvector3d.h>
    95 #include <QtGui/qsound.h>
    95 #include <QtGui/qsound.h>
    96 #include <QGraphicsObject>
       
    97 #include <QtCore/qcryptographichash.h>
    96 #include <QtCore/qcryptographichash.h>
    98 
    97 
    99 #include <private/qobject_p.h>
    98 #include <private/qobject_p.h>
   100 #include <private/qscriptdeclarativeclass_p.h>
    99 #include <private/qscriptdeclarativeclass_p.h>
   101 
   100 
   114 QT_BEGIN_NAMESPACE
   113 QT_BEGIN_NAMESPACE
   115 
   114 
   116 /*!
   115 /*!
   117   \qmlclass QtObject QObject
   116   \qmlclass QtObject QObject
   118   \since 4.7
   117   \since 4.7
   119   \brief The QtObject element is the most basic element in QML
   118   \brief The QtObject element is the most basic element in QML.
   120 
   119 
   121   The QtObject element is a non-visual element which contains only the
   120   The QtObject element is a non-visual element which contains only the
   122   objectName property. It is useful for when you need an extremely
   121   objectName property. 
   123   lightweight element to place your own custom properties in.
   122 
       
   123   It can be useful to create a QtObject if you need an extremely
       
   124   lightweight element to enclose a set of custom properties:
       
   125 
       
   126   \snippet doc/src/snippets/declarative/qtobject.qml 0
   124 
   127 
   125   It can also be useful for C++ integration, as it is just a plain
   128   It can also be useful for C++ integration, as it is just a plain
   126   QObject. See the QObject documentation for further details.
   129   QObject. See the QObject documentation for further details.
   127 */
   130 */
   128 /*!
   131 /*!
   129   \qmlproperty string QtObject::objectName
   132   \qmlproperty string QML:QtObject::objectName
   130   This property allows you to give a name to this specific object instance.
   133   This property holds the QObject::objectName for this specific object instance.
   131 
   134 
   132   See \l{scripting.html#accessing-child-qobjects}{Accessing Child QObjects}
   135   This allows a C++ application to locate an item within a QML component
   133   in the scripting documentation for details how objectName can be used from
   136   using the QObject::findChild() method. For example, the following C++ 
   134   scripts.
   137   application locates the child \l Rectangle item and dynamically changes its
       
   138   \c color value:
       
   139 
       
   140     \qml
       
   141     // MyRect.qml
       
   142 
       
   143     import Qt 4.7
       
   144 
       
   145     Item {
       
   146         width: 200; height: 200
       
   147 
       
   148         Rectangle {
       
   149             anchors.fill: parent
       
   150             color: "red" 
       
   151             objectName: "myRect"
       
   152         }
       
   153     }
       
   154     \endqml
       
   155 
       
   156     \code
       
   157     // main.cpp
       
   158 
       
   159     QDeclarativeView view;
       
   160     view.setSource(QUrl::fromLocalFile("MyRect.qml"));
       
   161     view.show();
       
   162 
       
   163     QDeclarativeItem *item = view.rootObject()->findChild<QDeclarativeItem*>("myRect");
       
   164     if (item) 
       
   165         item->setProperty("color", QColor(Qt::yellow));
       
   166     \endcode
   135 */
   167 */
   136 
   168 
   137 struct StaticQtMetaObject : public QObject
   169 struct StaticQtMetaObject : public QObject
   138 {
   170 {
   139     static const QMetaObject *get()
   171     static const QMetaObject *get()
   150 
   182 
   151     qmlRegisterType<QDeclarativeBinding>();
   183     qmlRegisterType<QDeclarativeBinding>();
   152 }
   184 }
   153 
   185 
   154 /*!
   186 /*!
       
   187 \keyword QmlGlobalQtObject
   155 \qmlclass Qt QDeclarativeEnginePrivate
   188 \qmlclass Qt QDeclarativeEnginePrivate
   156 \brief The QML Global Qt Object
   189 \brief The QML global Qt object provides useful enums and functions from Qt.
   157 
   190 
   158 The Qt object provides useful enums and functions from Qt, for use in all QML
   191 The \c Qt object provides useful enums and functions from Qt, for use in all QML files. 
   159 files. Note that you do note create instances of this type, but instead use
   192 
   160 the members of the global "Qt" object.
   193 The \c Qt object is not a QML element; it cannot be instantiated. It is a global object 
       
   194 with enums and functions.  To use it, call the members of the global \c Qt object directly. 
       
   195 For example:
       
   196 
       
   197 \qml
       
   198 import Qt 4.7
       
   199 
       
   200 Text {
       
   201     color: Qt.rgba(255, 0, 0, 1)
       
   202     text: Qt.md5("hello, world")
       
   203 }
       
   204 \endqml
       
   205 
   161 
   206 
   162 \section1 Enums
   207 \section1 Enums
   163 
   208 
   164 The Qt object contains all enums in the Qt namespace. For example, you can
   209 The Qt object contains all enums in the Qt namespace. For example, you can
   165 access the AlignLeft member of the Qt::AlignmentFlag enum with \c Qt.AlignLeft.
   210 access the \c AlignLeft member of the \c Qt::AlignmentFlag enum with \c Qt.AlignLeft.
   166 
   211 
   167 For a full list of enums, see the \l{Qt Namespace} documentation.
   212 For a full list of enums, see the \l{Qt Namespace} documentation.
   168 
   213 
   169 \section1 Types
   214 \section1 Types
   170 The Qt object also contains helper functions for creating objects of specific
   215 The Qt object also contains helper functions for creating objects of specific
   171 data types. This is primarily useful when setting the properties of an item
   216 data types. This is primarily useful when setting the properties of an item
   172 when the property has one of the following types:
   217 when the property has one of the following types:
   173 
   218 
   174 \list
   219 \list
   175 \o Color
   220 \o \c color - use \l{QML:Qt::rgba()}{Qt.rgba()}, \l{QML:Qt::hsla()}{Qt.hsla()}, \l{QML:Qt::darker()}{Qt.darker()}, \l{QML:Qt::lighter()}{Qt.lighter()} or \l{QML:Qt::tint()}{Qt.tint()}
   176 \o Rect
   221 \o \c rect - use \l{QML:Qt::rect()}{Qt.rect()}
   177 \o Point
   222 \o \c point - use \l{QML:Qt::point()}{Qt.point()}
   178 \o Size
   223 \o \c size - use \l{QML:Qt::size()}{Qt.size()}
   179 \o Vector3D
   224 \o \c vector3d - use \l{QML:Qt::vector3d()}{Qt.vector3d()}
   180 \endlist
   225 \endlist
   181 
   226 
   182 There are also string based constructors for these types, see \l{qdeclarativebasictypes.html}{Qml Types}.
   227 There are also string based constructors for these types. See \l{qdeclarativebasictypes.html}{QML Basic Types} for more information.
   183 
   228 
   184 \section1 Date/Time Formatters
   229 \section1 Date/Time Formatters
   185 
   230 
   186 The Qt object contains several functions for formatting dates and times.
   231 The Qt object contains several functions for formatting dates and times.
   187 
   232 
   188 \list
   233 \list
   189     \o \l{Qt::formatDateTime}{string Qt.formatDateTime(datetime date, variant format)
   234     \o \l{QML:Qt::formatDateTime}{string Qt.formatDateTime(datetime date, variant format)}
   190     \o \l{Qt::formatDate}{string Qt.formatDate(datetime date, variant format)
   235     \o \l{QML:Qt::formatDate}{string Qt.formatDate(datetime date, variant format)}
   191     \o \l{Qt::formatTime}{string Qt.formatTime(datetime date, variant format)
   236     \o \l{QML:Qt::formatTime}{string Qt.formatTime(datetime date, variant format)}
   192 \endlist
   237 \endlist
   193 
   238 
   194 The format specification is described at \l{Qt::formatDateTime}{Qt.formatDateTime}.
   239 The format specification is described at \l{QML:Qt::formatDateTime}{Qt.formatDateTime}.
   195 
   240 
   196 
   241 
   197 \section1 Dynamic Object Creation
   242 \section1 Dynamic Object Creation
   198 The following functions on the global object allow you to dynamically create QML
   243 The following functions on the global object allow you to dynamically create QML
   199 items from files or strings. See \l{Dynamic Object Management} for an overview
   244 items from files or strings. See \l{Dynamic Object Management} for an overview
   200 of their use.
   245 of their use.
   201 
   246 
   202 \list
   247 \list
   203     \o \l{Qt::createComponent}{object Qt.createComponent(url)}
   248     \o \l{QML:Qt::createComponent()}{object Qt.createComponent(url)}
   204     \o \l{Qt::createQmlObject}{object Qt.createQmlObject(string qml, object parent, string filepath)}
   249     \o \l{QML:Qt::createQmlObject()}{object Qt.createQmlObject(string qml, object parent, string filepath)}
   205 \endlist
   250 \endlist
   206 */
   251 */
   207 
   252 
   208 
   253 
   209 QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
   254 QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
   210 : captureProperties(false), rootContext(0), currentExpression(0), isDebugging(false),
   255 : captureProperties(false), rootContext(0), isDebugging(false),
   211   outputWarningsToStdErr(true), contextClass(0), sharedContext(0), sharedScope(0),
   256   outputWarningsToStdErr(true), contextClass(0), sharedContext(0), sharedScope(0),
   212   objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0),
   257   objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0),
   213   inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0),
   258   inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0),
   214   inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0),
   259   inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0),
   215   typeManager(e), importDatabase(e), uniqueId(1)
   260   typeManager(e), importDatabase(e), uniqueId(1)
   223     }
   268     }
   224     globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine);
   269     globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine);
   225 }
   270 }
   226 
   271 
   227 /*!
   272 /*!
   228 \qmlmethod url Qt::resolvedUrl(url)
   273   \qmlmethod url Qt::resolvedUrl(url)
   229 This function returns \c url resolved relative to the URL of the
   274   Returns \c url resolved relative to the URL of the caller.
   230 caller.
       
   231 */
   275 */
   232 QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url)
   276 QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url)
   233 {
   277 {
   234     if (p) {
   278     if (p) {
   235         QDeclarativeContextData *ctxt = QDeclarativeEnginePrivate::get(this)->getContext(context);
   279         QDeclarativeContextData *ctxt = QDeclarativeEnginePrivate::get(this)->getContext(context);
   283         qtObject.setProperty(QLatin1String("lighter"), newFunction(QDeclarativeEnginePrivate::lighter, 1));
   327         qtObject.setProperty(QLatin1String("lighter"), newFunction(QDeclarativeEnginePrivate::lighter, 1));
   284         qtObject.setProperty(QLatin1String("darker"), newFunction(QDeclarativeEnginePrivate::darker, 1));
   328         qtObject.setProperty(QLatin1String("darker"), newFunction(QDeclarativeEnginePrivate::darker, 1));
   285         qtObject.setProperty(QLatin1String("tint"), newFunction(QDeclarativeEnginePrivate::tint, 2));
   329         qtObject.setProperty(QLatin1String("tint"), newFunction(QDeclarativeEnginePrivate::tint, 2));
   286     }
   330     }
   287 
   331 
       
   332 #ifndef QT_NO_TEXTDATE
   288     //date/time formatting
   333     //date/time formatting
   289     qtObject.setProperty(QLatin1String("formatDate"),newFunction(QDeclarativeEnginePrivate::formatDate, 2));
   334     qtObject.setProperty(QLatin1String("formatDate"),newFunction(QDeclarativeEnginePrivate::formatDate, 2));
   290     qtObject.setProperty(QLatin1String("formatTime"),newFunction(QDeclarativeEnginePrivate::formatTime, 2));
   335     qtObject.setProperty(QLatin1String("formatTime"),newFunction(QDeclarativeEnginePrivate::formatTime, 2));
   291     qtObject.setProperty(QLatin1String("formatDateTime"),newFunction(QDeclarativeEnginePrivate::formatDateTime, 2));
   336     qtObject.setProperty(QLatin1String("formatDateTime"),newFunction(QDeclarativeEnginePrivate::formatDateTime, 2));
       
   337 #endif
   292 
   338 
   293     //misc methods
   339     //misc methods
   294     qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1));
   340     qtObject.setProperty(QLatin1String("openUrlExternally"),newFunction(QDeclarativeEnginePrivate::desktopOpenUrl, 1));
   295     qtObject.setProperty(QLatin1String("fontFamilies"),newFunction(QDeclarativeEnginePrivate::fontFamilies, 0));
   341     qtObject.setProperty(QLatin1String("fontFamilies"),newFunction(QDeclarativeEnginePrivate::fontFamilies, 0));
   296     qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1));
   342     qtObject.setProperty(QLatin1String("md5"),newFunction(QDeclarativeEnginePrivate::md5, 1));
   530 
   576 
   531   Additional data that should only be available to a subset of
   577   Additional data that should only be available to a subset of
   532   component instances should be added to sub-contexts parented to the
   578   component instances should be added to sub-contexts parented to the
   533   root context.
   579   root context.
   534 */
   580 */
   535 QDeclarativeContext *QDeclarativeEngine::rootContext()
   581 QDeclarativeContext *QDeclarativeEngine::rootContext() const
   536 {
   582 {
   537     Q_D(QDeclarativeEngine);
   583     Q_D(const QDeclarativeEngine);
   538     return d->rootContext;
   584     return d->rootContext;
   539 }
   585 }
   540 
   586 
   541 /*!
   587 /*!
   542   Sets the \a factory to use for creating QNetworkAccessManager(s).
   588   Sets the \a factory to use for creating QNetworkAccessManager(s).
   606 }
   652 }
   607 
   653 
   608 /*!
   654 /*!
   609 
   655 
   610   Sets the \a provider to use for images requested via the \e
   656   Sets the \a provider to use for images requested via the \e
   611   image: url scheme, with host \a providerId.
   657   image: url scheme, with host \a providerId. The QDeclarativeEngine 
   612 
   658   takes ownership of \a provider.
   613   QDeclarativeImageProvider allows images to be provided to QML
   659 
   614   asynchronously.  The image request will be run in a low priority
   660   Image providers enable support for pixmap and threaded image
   615   thread.  This allows potentially costly image loading to be done in
   661   requests. See the QDeclarativeImageProvider documentation for details on
   616   the background, without affecting the performance of the UI.
   662   implementing and using image providers.
   617 
   663 
   618   Note that images loaded from a QDeclarativeImageProvider are cached
   664   Note that images loaded from a QDeclarativeImageProvider are cached
   619   by QPixmapCache, similar to any image loaded by QML.
   665   by QPixmapCache, similar to any image loaded by QML.
   620 
       
   621   The QDeclarativeEngine assumes ownership of the provider.
       
   622 
       
   623   This example creates a provider with id \e colors:
       
   624 
       
   625   \snippet examples/declarative/cppextensions/imageprovider/imageprovider.cpp 0
       
   626 
       
   627   \snippet examples/declarative/cppextensions/imageprovider/imageprovider-example.qml 0
       
   628 
   666 
   629   \sa removeImageProvider()
   667   \sa removeImageProvider()
   630 */
   668 */
   631 void QDeclarativeEngine::addImageProvider(const QString &providerId, QDeclarativeImageProvider *provider)
   669 void QDeclarativeEngine::addImageProvider(const QString &providerId, QDeclarativeImageProvider *provider)
   632 {
   670 {
   655 void QDeclarativeEngine::removeImageProvider(const QString &providerId)
   693 void QDeclarativeEngine::removeImageProvider(const QString &providerId)
   656 {
   694 {
   657     Q_D(QDeclarativeEngine);
   695     Q_D(QDeclarativeEngine);
   658     QMutexLocker locker(&d->mutex);
   696     QMutexLocker locker(&d->mutex);
   659     delete d->imageProviders.take(providerId);
   697     delete d->imageProviders.take(providerId);
       
   698 }
       
   699 
       
   700 QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProviderType(const QUrl &url)
       
   701 {
       
   702     QMutexLocker locker(&mutex);
       
   703     QDeclarativeImageProvider *provider = imageProviders.value(url.host());
       
   704     if (provider)
       
   705         return provider->imageType();
       
   706     return static_cast<QDeclarativeImageProvider::ImageType>(-1);
   660 }
   707 }
   661 
   708 
   662 QImage QDeclarativeEnginePrivate::getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
   709 QImage QDeclarativeEnginePrivate::getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
   663 {
   710 {
   664     QMutexLocker locker(&mutex);
   711     QMutexLocker locker(&mutex);
   665     QImage image;
   712     QImage image;
   666     QDeclarativeImageProvider *provider = imageProviders.value(url.host());
   713     QDeclarativeImageProvider *provider = imageProviders.value(url.host());
   667     if (provider)
   714     if (provider)
   668         image = provider->request(url.path().mid(1), size, req_size);
   715         image = provider->requestImage(url.path().mid(1), size, req_size);
   669     return image;
   716     return image;
       
   717 }
       
   718 
       
   719 QPixmap QDeclarativeEnginePrivate::getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
       
   720 {
       
   721     QMutexLocker locker(&mutex);
       
   722     QPixmap pixmap;
       
   723     QDeclarativeImageProvider *provider = imageProviders.value(url.host());
       
   724     if (provider)
       
   725         pixmap = provider->requestPixmap(url.path().mid(1), size, req_size);
       
   726     return pixmap;
   670 }
   727 }
   671 
   728 
   672 /*!
   729 /*!
   673   Return the base URL for this engine.  The base URL is only used to
   730   Return the base URL for this engine.  The base URL is only used to
   674   resolve components when a relative URL is passed to the
   731   resolve components when a relative URL is passed to the
  1019     Q_ASSERT(scopeNode.isValid());
  1076     Q_ASSERT(scopeNode.isValid());
  1020     Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass);
  1077     Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass);
  1021     return contextClass->contextFromValue(scopeNode);
  1078     return contextClass->contextFromValue(scopeNode);
  1022 }
  1079 }
  1023 
  1080 
       
  1081 /*!
       
  1082     Returns the QUrl associated with the script \a ctxt for the case that there is
       
  1083     no QDeclarativeContext.
       
  1084 */
       
  1085 QUrl QDeclarativeEnginePrivate::getUrl(QScriptContext *ctxt)
       
  1086 {
       
  1087     QScriptValue scopeNode = QScriptDeclarativeClass::scopeChainValue(ctxt, -3);
       
  1088     Q_ASSERT(scopeNode.isValid());
       
  1089     Q_ASSERT(QScriptDeclarativeClass::scriptClass(scopeNode) == contextClass);
       
  1090     return contextClass->urlFromValue(scopeNode);
       
  1091 }
  1024 
  1092 
  1025 QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url)
  1093 QString QDeclarativeEnginePrivate::urlToLocalFileOrQrc(const QUrl& url)
  1026 {
  1094 {
  1027     if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) {
  1095     if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) {
  1028         if (url.authority().isEmpty())
  1096         if (url.authority().isEmpty())
  1033 }
  1101 }
  1034 
  1102 
  1035 /*!
  1103 /*!
  1036 \qmlmethod object Qt::createComponent(url)
  1104 \qmlmethod object Qt::createComponent(url)
  1037 
  1105 
  1038 This function takes the URL of a QML file as its only argument. It returns
  1106 Returns a \l Component object created using the QML file at the specified \a url,
  1039 a component object which can be used to create and load that QML file.
  1107 or \c null if there was an error in creating the component.
  1040 
  1108 
  1041 Here is an example. Remember that QML files that might be loaded
  1109 Call \l {Component::createObject()}{Component.createObject()} on the returned
  1042 over the network cannot be expected to be ready immediately.
  1110 component to create an object instance of the component.
  1043 
  1111 
  1044 \snippet doc/src/snippets/declarative/componentCreation.js 0
  1112 Here is an example. Notice it checks whether the component \l{Component::status}{status} is
       
  1113 \c Component.Ready before calling \l {Component::createObject()}{createObject()}
       
  1114 in case the QML file is loaded over a network and thus is not ready immediately.
       
  1115 
       
  1116 \snippet doc/src/snippets/declarative/componentCreation.js vars
  1045 \codeline
  1117 \codeline
  1046 \snippet doc/src/snippets/declarative/componentCreation.js 1
  1118 \snippet doc/src/snippets/declarative/componentCreation.js func
  1047 
  1119 \snippet doc/src/snippets/declarative/componentCreation.js remote
  1048 If you are certain the files will be local, you could simplify to:
  1120 \snippet doc/src/snippets/declarative/componentCreation.js func-end
  1049 
  1121 \codeline
  1050 \snippet doc/src/snippets/declarative/componentCreation.js 2
  1122 \snippet doc/src/snippets/declarative/componentCreation.js finishCreation
  1051 
  1123 
  1052 The methods and properties of the \l {Component} element are defined in its own
  1124 If you are certain the QML file to be loaded is a local file, you could omit the \c finishCreation() 
  1053 page, but when using it dynamically only two methods are usually used.
  1125 function and call \l {Component::createObject()}{createObject()} immediately:
  1054  \l {Component::createObject()}{Component.createObject()} returns the created object or \c null if there is an error.
  1126 
  1055 If there is an error, \l {Component::errorString()}{Component.errorString()} describes
  1127 \snippet doc/src/snippets/declarative/componentCreation.js func
  1056 the error that occurred. Note that createObject() takes exactly one argument, which is set
  1128 \snippet doc/src/snippets/declarative/componentCreation.js local
  1057 to the parent of the created object. Graphical objects without a parent will not appear
  1129 \snippet doc/src/snippets/declarative/componentCreation.js func-end
  1058 on the scene, but if you do not wish to parent the item at this point you can safely pass
  1130 
  1059 in null.
  1131 To create a QML object from an arbitrary string of QML (instead of a file),
  1060 
  1132 use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}.
  1061 If you want to just create an arbitrary string of QML, instead of
       
  1062 loading a QML file, consider the \l{Qt.createQmlObject(string qml, object parent, string filepath)}{Qt.createQmlObject()} function.
       
  1063 */
  1133 */
  1064 
  1134 
  1065 QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QScriptEngine *engine)
  1135 QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QScriptEngine *engine)
  1066 {
  1136 {
  1067     QDeclarativeEnginePrivate *activeEnginePriv =
  1137     QDeclarativeEnginePrivate *activeEnginePriv =
  1068         static_cast<QDeclarativeScriptEngine*>(engine)->p;
  1138         static_cast<QDeclarativeScriptEngine*>(engine)->p;
  1069     QDeclarativeEngine* activeEngine = activeEnginePriv->q_func();
  1139     QDeclarativeEngine* activeEngine = activeEnginePriv->q_func();
  1070 
  1140 
  1071     QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt);
       
  1072     Q_ASSERT(context);
       
  1073 
       
  1074     if(ctxt->argumentCount() != 1) {
  1141     if(ctxt->argumentCount() != 1) {
  1075         return ctxt->throwError(QLatin1String("Qt.createComponent(): Invalid arguments"));
  1142         return ctxt->throwError(QLatin1String("Qt.createComponent(): Invalid arguments"));
  1076     }else{
  1143     } else {
       
  1144 
  1077         QString arg = ctxt->argument(0).toString();
  1145         QString arg = ctxt->argument(0).toString();
  1078         if (arg.isEmpty())
  1146         if (arg.isEmpty())
  1079             return engine->nullValue();
  1147             return engine->nullValue();
  1080         QUrl url = QUrl(context->resolvedUrl(QUrl(arg)));
  1148         QUrl url;
       
  1149         QDeclarativeContextData* context = activeEnginePriv->getContext(ctxt);
       
  1150         if (context)
       
  1151             url = QUrl(context->resolvedUrl(QUrl(arg)));
       
  1152         else
       
  1153             url = activeEnginePriv->getUrl(ctxt).resolved(QUrl(arg));
  1081         QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine);
  1154         QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine);
  1082         QDeclarativeComponentPrivate::get(c)->creationContext = context;
  1155         QDeclarativeComponentPrivate::get(c)->creationContext = context;
  1083         QDeclarativeData::get(c, true)->setImplicitDestructible();
  1156         QDeclarativeData::get(c, true)->setImplicitDestructible();
  1084         return activeEnginePriv->objectClass->newQObject(c, qMetaTypeId<QDeclarativeComponent*>());
  1157         return activeEnginePriv->objectClass->newQObject(c, qMetaTypeId<QDeclarativeComponent*>());
  1085     }
  1158     }
  1086 }
  1159 }
  1087 
  1160 
  1088 /*!
  1161 /*!
  1089 \qmlmethod object Qt::createQmlObject(string qml, object parent, string filepath)
  1162 \qmlmethod object Qt::createQmlObject(string qml, object parent, string filepath)
  1090 
  1163 
  1091 Creates a new object from the specified string of QML. It requires a
  1164 Returns a new object created from the given \a string of QML which will have the specified \a parent,
  1092 second argument, which is the id of an existing QML object to use as
  1165 or \c null if there was an error in creating the object.
  1093 the new object's parent. If a third argument is provided, this is used
  1166 
  1094 for error reporting as the filepath that the QML came from.
  1167 If \a filepath is specified, it will be used for error reporting for the created object.
  1095 
  1168 
  1096 Example (where \c targetItem is the id of an existing QML item):
  1169 Example (where \c parentItem is the id of an existing QML item):
  1097 
  1170 
  1098 \snippet doc/src/snippets/declarative/createQmlObject.qml 0
  1171 \snippet doc/src/snippets/declarative/createQmlObject.qml 0
  1099 
  1172 
  1100 This function is intended for use inside QML only. It is intended to behave
  1173 In the case of an error, a QtScript Error object is thrown. This object has an additional property,
  1101 similarly to eval, but for creating QML elements.
  1174 \c qmlErrors, which is an array of the errors encountered.
  1102 
  1175 Each object in this array has the members \c lineNumber, \c columnNumber, \c fileName and \c message.
  1103 Returns the created object, \c or null if there is an error. In the case of an
       
  1104 error, a QtScript Error object is thrown. This object has the additional property,
       
  1105 qmlErrors, which is an array of all the errors encountered when trying to execute the
       
  1106 QML. Each object in the array has the members \c lineNumber, \c columnNumber, \c fileName and \c message.
       
  1107 
  1176 
  1108 Note that this function returns immediately, and therefore may not work if
  1177 Note that this function returns immediately, and therefore may not work if
  1109 the QML loads new components. If you are trying to load a new component,
  1178 the \a qml string loads new components (that is, external QML files that have not yet been loaded).
  1110 for example from a QML file, consider the \l{Qt.createComponent(url file)}{Qt.createComponent()} function
  1179 If this is the case, consider using \l{QML:Qt::createComponent()}{Qt.createComponent()} instead.
  1111 instead. 'New components' refers to external QML files that have not yet
       
  1112 been loaded, and so it is safe to use \c Qt.createQmlObject() to load built-in
       
  1113 components.
       
  1114 */
  1180 */
  1115 
  1181 
  1116 QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine)
  1182 QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine)
  1117 {
  1183 {
  1118     QDeclarativeEnginePrivate *activeEnginePriv =
  1184     QDeclarativeEnginePrivate *activeEnginePriv =
  1192     }
  1258     }
  1193 
  1259 
  1194     Q_ASSERT(obj);
  1260     Q_ASSERT(obj);
  1195 
  1261 
  1196     obj->setParent(parentArg);
  1262     obj->setParent(parentArg);
  1197     QGraphicsObject* gobj = qobject_cast<QGraphicsObject*>(obj);
  1263 
  1198     QGraphicsObject* gparent = qobject_cast<QGraphicsObject*>(parentArg);
  1264     QList<QDeclarativePrivate::AutoParentFunction> functions = QDeclarativeMetaType::parentFunctions();
  1199     if(gobj && gparent)
  1265     for (int ii = 0; ii < functions.count(); ++ii) {
  1200         gobj->setParentItem(gparent);
  1266         if (QDeclarativePrivate::Parented == functions.at(ii)(obj, parentArg))
       
  1267             break;
       
  1268     }
  1201 
  1269 
  1202     QDeclarativeData::get(obj, true)->setImplicitDestructible();
  1270     QDeclarativeData::get(obj, true)->setImplicitDestructible();
  1203     return activeEnginePriv->objectClass->newQObject(obj, QMetaType::QObjectStar);
  1271     return activeEnginePriv->objectClass->newQObject(obj, QMetaType::QObjectStar);
  1204 }
  1272 }
  1205 
  1273 
  1215     return QScriptValue(engine, 0 != ctxt->argument(0).toQObject());
  1283     return QScriptValue(engine, 0 != ctxt->argument(0).toQObject());
  1216 }
  1284 }
  1217 
  1285 
  1218 /*!
  1286 /*!
  1219 \qmlmethod Qt::vector3d(real x, real y, real z)
  1287 \qmlmethod Qt::vector3d(real x, real y, real z)
  1220 This function returns a Vector3D with the specified \c x, \c y and \c z.
  1288 Returns a Vector3D with the specified \c x, \c y and \c z.
  1221 */
  1289 */
  1222 QScriptValue QDeclarativeEnginePrivate::vector3d(QScriptContext *ctxt, QScriptEngine *engine)
  1290 QScriptValue QDeclarativeEnginePrivate::vector3d(QScriptContext *ctxt, QScriptEngine *engine)
  1223 {
  1291 {
  1224     if(ctxt->argumentCount() != 3)
  1292     if(ctxt->argumentCount() != 3)
  1225         return ctxt->throwError(QLatin1String("Qt.vector(): Invalid arguments"));
  1293         return ctxt->throwError(QLatin1String("Qt.vector(): Invalid arguments"));
  1229     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QVector3D(x, y, z)));
  1297     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QVector3D(x, y, z)));
  1230 }
  1298 }
  1231 
  1299 
  1232 /*!
  1300 /*!
  1233 \qmlmethod string Qt::formatDate(datetime date, variant format)
  1301 \qmlmethod string Qt::formatDate(datetime date, variant format)
  1234 This function returns the string representation of \c date, formatted according to \c format.
  1302 Returns the string representation of \c date, formatted according to \c format.
  1235 */
  1303 */
       
  1304 #ifndef QT_NO_TEXTDATE
  1236 QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine)
  1305 QScriptValue QDeclarativeEnginePrivate::formatDate(QScriptContext*ctxt, QScriptEngine*engine)
  1237 {
  1306 {
  1238     int argCount = ctxt->argumentCount();
  1307     int argCount = ctxt->argumentCount();
  1239     if(argCount == 0 || argCount > 2)
  1308     if(argCount == 0 || argCount > 2)
  1240         return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid arguments"));
  1309         return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid arguments"));
  1241 
  1310 
  1242     QDate date = ctxt->argument(0).toDateTime().date();
  1311     QDate date = ctxt->argument(0).toDateTime().date();
  1243     Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
  1312     Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
  1244     if (argCount == 2) {
  1313     if (argCount == 2) {
  1245         if (ctxt->argument(1).isString()) {
  1314         QScriptValue formatArg = ctxt->argument(1);
  1246             QString format = ctxt->argument(1).toString();
  1315         if (formatArg.isString()) {
       
  1316             QString format = formatArg.toString();
  1247             return engine->newVariant(qVariantFromValue(date.toString(format)));
  1317             return engine->newVariant(qVariantFromValue(date.toString(format)));
  1248         } else if (ctxt->argument(1).isNumber()) {
  1318         } else if (formatArg.isNumber()) {
  1249             enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32());
  1319             enumFormat = Qt::DateFormat(formatArg.toUInt32());
  1250         } else {
  1320         } else {
  1251             return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid date format"));
  1321             return ctxt->throwError(QLatin1String("Qt.formatDate(): Invalid date format"));
  1252         }
  1322         }
  1253     }
  1323     }
  1254     return engine->newVariant(qVariantFromValue(date.toString(enumFormat)));
  1324     return engine->newVariant(qVariantFromValue(date.toString(enumFormat)));
  1255 }
  1325 }
  1256 
  1326 
  1257 /*!
  1327 /*!
  1258 \qmlmethod string Qt::formatTime(datetime time, variant format)
  1328 \qmlmethod string Qt::formatTime(datetime time, variant format)
  1259 This function returns the string representation of \c time, formatted according to \c format.
  1329 Returns the string representation of \c time, formatted according to \c format.
  1260 
  1330 
  1261 See Qt::formatDateTime for how to define \c format.
  1331 See Qt::formatDateTime for how to define \c format.
  1262 */
  1332 */
  1263 QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptEngine*engine)
  1333 QScriptValue QDeclarativeEnginePrivate::formatTime(QScriptContext*ctxt, QScriptEngine*engine)
  1264 {
  1334 {
  1267         return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid arguments"));
  1337         return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid arguments"));
  1268 
  1338 
  1269     QTime date = ctxt->argument(0).toDateTime().time();
  1339     QTime date = ctxt->argument(0).toDateTime().time();
  1270     Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
  1340     Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
  1271     if (argCount == 2) {
  1341     if (argCount == 2) {
  1272         if (ctxt->argument(1).isString()) {
  1342         QScriptValue formatArg = ctxt->argument(1);
  1273             QString format = ctxt->argument(1).toString();
  1343         if (formatArg.isString()) {
       
  1344             QString format = formatArg.toString();
  1274             return engine->newVariant(qVariantFromValue(date.toString(format)));
  1345             return engine->newVariant(qVariantFromValue(date.toString(format)));
  1275         } else if (ctxt->argument(1).isNumber()) {
  1346         } else if (formatArg.isNumber()) {
  1276             enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32());
  1347             enumFormat = Qt::DateFormat(formatArg.toUInt32());
  1277         } else {
  1348         } else {
  1278             return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid time format"));
  1349             return ctxt->throwError(QLatin1String("Qt.formatTime(): Invalid time format"));
  1279         }
  1350         }
  1280     }
  1351     }
  1281     return engine->newVariant(qVariantFromValue(date.toString(enumFormat)));
  1352     return engine->newVariant(qVariantFromValue(date.toString(enumFormat)));
  1282 }
  1353 }
  1283 
  1354 
  1284 /*!
  1355 /*!
  1285 \qmlmethod string Qt::formatDateTime(datetime dateTime, variant format)
  1356 \qmlmethod string Qt::formatDateTime(datetime dateTime, variant format)
  1286 This function returns the string representation of \c dateTime, formatted according to \c format.
  1357 Returns the string representation of \c dateTime, formatted according to \c format.
  1287 
  1358 
  1288 \c format for the date/time formatting functions is be specified as follows.
  1359 \c format for the date/time formatting functions is be specified as follows.
  1289 
  1360 
  1290     These expressions may be used for the date:
  1361     These expressions may be used for the date:
  1291 
  1362 
  1357         return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid arguments"));
  1428         return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid arguments"));
  1358 
  1429 
  1359     QDateTime date = ctxt->argument(0).toDateTime();
  1430     QDateTime date = ctxt->argument(0).toDateTime();
  1360     Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
  1431     Qt::DateFormat enumFormat = Qt::DefaultLocaleShortDate;
  1361     if (argCount == 2) {
  1432     if (argCount == 2) {
  1362         if (ctxt->argument(1).isString()) {
  1433         QScriptValue formatArg = ctxt->argument(1);
  1363             QString format = ctxt->argument(1).toString();
  1434         if (formatArg.isString()) {
       
  1435             QString format = formatArg.toString();
  1364             return engine->newVariant(qVariantFromValue(date.toString(format)));
  1436             return engine->newVariant(qVariantFromValue(date.toString(format)));
  1365         } else if (ctxt->argument(1).isNumber()) {
  1437         } else if (formatArg.isNumber()) {
  1366             enumFormat = Qt::DateFormat(ctxt->argument(1).toUInt32());
  1438             enumFormat = Qt::DateFormat(formatArg.toUInt32());
  1367         } else { 
  1439         } else { 
  1368             return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid datetime format"));
  1440             return ctxt->throwError(QLatin1String("Qt.formatDateTime(): Invalid datetime format"));
  1369         }
  1441         }
  1370     }
  1442     }
  1371     return engine->newVariant(qVariantFromValue(date.toString(enumFormat)));
  1443     return engine->newVariant(qVariantFromValue(date.toString(enumFormat)));
  1372 }
  1444 }
       
  1445 #endif // QT_NO_TEXTDATE
  1373 
  1446 
  1374 /*!
  1447 /*!
  1375 \qmlmethod color Qt::rgba(real red, real green, real blue, real alpha)
  1448 \qmlmethod color Qt::rgba(real red, real green, real blue, real alpha)
  1376 
  1449 
  1377 This function returns a Color with the specified \c red, \c green, \c blue and \c alpha components.
  1450 Returns a color with the specified \c red, \c green, \c blue and \c alpha components.
  1378 All components should be in the range 0-1 inclusive.
  1451 All components should be in the range 0-1 inclusive.
  1379 */
  1452 */
  1380 QScriptValue QDeclarativeEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine)
  1453 QScriptValue QDeclarativeEnginePrivate::rgba(QScriptContext *ctxt, QScriptEngine *engine)
  1381 {
  1454 {
  1382     int argCount = ctxt->argumentCount();
  1455     int argCount = ctxt->argumentCount();
  1400 }
  1473 }
  1401 
  1474 
  1402 /*!
  1475 /*!
  1403 \qmlmethod color Qt::hsla(real hue, real saturation, real lightness, real alpha)
  1476 \qmlmethod color Qt::hsla(real hue, real saturation, real lightness, real alpha)
  1404 
  1477 
  1405 This function returns a Color with the specified \c hue, \c saturation, \c lightness and \c alpha components.
  1478 Returns a color with the specified \c hue, \c saturation, \c lightness and \c alpha components.
  1406 All components should be in the range 0-1 inclusive.
  1479 All components should be in the range 0-1 inclusive.
  1407 */
  1480 */
  1408 QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine *engine)
  1481 QScriptValue QDeclarativeEnginePrivate::hsla(QScriptContext *ctxt, QScriptEngine *engine)
  1409 {
  1482 {
  1410     int argCount = ctxt->argumentCount();
  1483     int argCount = ctxt->argumentCount();
  1428 }
  1501 }
  1429 
  1502 
  1430 /*!
  1503 /*!
  1431 \qmlmethod rect Qt::rect(int x, int y, int width, int height) 
  1504 \qmlmethod rect Qt::rect(int x, int y, int width, int height) 
  1432 
  1505 
  1433 This function returns a Rect with the top-left corner at \c x, \c y and the specified \c width and \c height.
  1506 Returns a \c rect with the top-left corner at \c x, \c y and the specified \c width and \c height.
       
  1507 
       
  1508 The returned object has \c x, \c y, \c width and \c height attributes with the given values.
  1434 */
  1509 */
  1435 QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine)
  1510 QScriptValue QDeclarativeEnginePrivate::rect(QScriptContext *ctxt, QScriptEngine *engine)
  1436 {
  1511 {
  1437     if(ctxt->argumentCount() != 4)
  1512     if(ctxt->argumentCount() != 4)
  1438         return ctxt->throwError(QLatin1String("Qt.rect(): Invalid arguments"));
  1513         return ctxt->throwError(QLatin1String("Qt.rect(): Invalid arguments"));
  1448     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QRectF(x, y, w, h)));
  1523     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QRectF(x, y, w, h)));
  1449 }
  1524 }
  1450 
  1525 
  1451 /*!
  1526 /*!
  1452 \qmlmethod point Qt::point(int x, int y)
  1527 \qmlmethod point Qt::point(int x, int y)
  1453 This function returns a Point with the specified \c x and \c y coordinates.
  1528 Returns a Point with the specified \c x and \c y coordinates.
  1454 */
  1529 */
  1455 QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine)
  1530 QScriptValue QDeclarativeEnginePrivate::point(QScriptContext *ctxt, QScriptEngine *engine)
  1456 {
  1531 {
  1457     if(ctxt->argumentCount() != 2)
  1532     if(ctxt->argumentCount() != 2)
  1458         return ctxt->throwError(QLatin1String("Qt.point(): Invalid arguments"));
  1533         return ctxt->throwError(QLatin1String("Qt.point(): Invalid arguments"));
  1461     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QPointF(x, y)));
  1536     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QPointF(x, y)));
  1462 }
  1537 }
  1463 
  1538 
  1464 /*!
  1539 /*!
  1465 \qmlmethod Qt::size(int width, int height)
  1540 \qmlmethod Qt::size(int width, int height)
  1466 This function returns as Size with the specified \c width and \c height.
  1541 Returns a Size with the specified \c width and \c height.
  1467 */
  1542 */
  1468 QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine)
  1543 QScriptValue QDeclarativeEnginePrivate::size(QScriptContext *ctxt, QScriptEngine *engine)
  1469 {
  1544 {
  1470     if(ctxt->argumentCount() != 2)
  1545     if(ctxt->argumentCount() != 2)
  1471         return ctxt->throwError(QLatin1String("Qt.size(): Invalid arguments"));
  1546         return ctxt->throwError(QLatin1String("Qt.size(): Invalid arguments"));
  1474     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QSizeF(w, h)));
  1549     return QDeclarativeEnginePrivate::get(engine)->scriptValueFromVariant(qVariantFromValue(QSizeF(w, h)));
  1475 }
  1550 }
  1476 
  1551 
  1477 /*!
  1552 /*!
  1478 \qmlmethod color Qt::lighter(color baseColor, real factor)
  1553 \qmlmethod color Qt::lighter(color baseColor, real factor)
  1479 This function returns a color lighter than \c baseColor by the \c factor provided.
  1554 Returns a color lighter than \c baseColor by the \c factor provided.
  1480 
  1555 
  1481 If the factor is greater than 1.0, this functions returns a lighter color.
  1556 If the factor is greater than 1.0, this functions returns a lighter color.
  1482 Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0,
  1557 Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0,
  1483 the return color is darker, but we recommend using the Qt.darker() function for this purpose.
  1558 the return color is darker, but we recommend using the Qt.darker() function for this purpose.
  1484 If the factor is 0 or negative, the return value is unspecified.
  1559 If the factor is 0 or negative, the return value is unspecified.
  1510     return qScriptValueFromValue(engine, qVariantFromValue(color));
  1585     return qScriptValueFromValue(engine, qVariantFromValue(color));
  1511 }
  1586 }
  1512 
  1587 
  1513 /*!
  1588 /*!
  1514 \qmlmethod color Qt::darker(color baseColor, real factor)
  1589 \qmlmethod color Qt::darker(color baseColor, real factor)
  1515 This function returns a color darker than \c baseColor by the \c factor provided.
  1590 Returns a color darker than \c baseColor by the \c factor provided.
  1516 
  1591 
  1517 If the factor is greater than 1.0, this function returns a darker color.
  1592 If the factor is greater than 1.0, this function returns a darker color.
  1518 Setting factor to 3.0 returns a color that has one-third the brightness.
  1593 Setting factor to 3.0 returns a color that has one-third the brightness.
  1519 If the factor is less than 1.0, the return color is lighter, but we recommend using
  1594 If the factor is less than 1.0, the return color is lighter, but we recommend using
  1520 the Qt.lighter() function for this purpose. If the factor is 0 or negative, the return
  1595 the Qt.lighter() function for this purpose. If the factor is 0 or negative, the return
  1547     return qScriptValueFromValue(engine, qVariantFromValue(color));
  1622     return qScriptValueFromValue(engine, qVariantFromValue(color));
  1548 }
  1623 }
  1549 
  1624 
  1550 /*!
  1625 /*!
  1551 \qmlmethod bool Qt::openUrlExternally(url target)
  1626 \qmlmethod bool Qt::openUrlExternally(url target)
  1552 This function attempts to open the specified \c target url in an external application, based on the user's desktop preferences. It will return true if it succeeds, and false otherwise.
  1627 Attempts to open the specified \c target url in an external application, based on the user's desktop preferences. Returns true if it succeeds, and false otherwise.
  1553 */
  1628 */
  1554 QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e)
  1629 QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QScriptEngine *e)
  1555 {
  1630 {
  1556     if(ctxt->argumentCount() < 1)
  1631     if(ctxt->argumentCount() < 1)
  1557         return QScriptValue(e, false);
  1632         return QScriptValue(e, false);
  1562     return QScriptValue(e, ret);
  1637     return QScriptValue(e, ret);
  1563 }
  1638 }
  1564 
  1639 
  1565 /*!
  1640 /*!
  1566 \qmlmethod list<string> Qt::fontFamilies()
  1641 \qmlmethod list<string> Qt::fontFamilies()
  1567 This function returns a list of the font families available to the application.
  1642 Returns a list of the font families available to the application.
  1568 */
  1643 */
  1569 
  1644 
  1570 QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e)
  1645 QScriptValue QDeclarativeEnginePrivate::fontFamilies(QScriptContext *ctxt, QScriptEngine *e)
  1571 {
  1646 {
  1572     if(ctxt->argumentCount() != 0)
  1647     if(ctxt->argumentCount() != 0)
  1577     return p->scriptValueFromVariant(database.families());
  1652     return p->scriptValueFromVariant(database.families());
  1578 }
  1653 }
  1579 
  1654 
  1580 /*!
  1655 /*!
  1581 \qmlmethod string Qt::md5(data)
  1656 \qmlmethod string Qt::md5(data)
  1582 This function returns a hex string of the md5 hash of \c data.
  1657 Returns a hex string of the md5 hash of \c data.
  1583 */
  1658 */
  1584 QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *)
  1659 QScriptValue QDeclarativeEnginePrivate::md5(QScriptContext *ctxt, QScriptEngine *)
  1585 {
  1660 {
  1586     if (ctxt->argumentCount() != 1)
  1661     if (ctxt->argumentCount() != 1)
  1587         return ctxt->throwError(QLatin1String("Qt.md5(): Invalid arguments"));
  1662         return ctxt->throwError(QLatin1String("Qt.md5(): Invalid arguments"));
  1706 }
  1781 }
  1707 
  1782 
  1708 /*!
  1783 /*!
  1709 \qmlmethod Qt::quit()
  1784 \qmlmethod Qt::quit()
  1710 This function causes the QDeclarativeEngine::quit() signal to be emitted.
  1785 This function causes the QDeclarativeEngine::quit() signal to be emitted.
  1711 Within the \l {Qt Declarative UI Runtime}{qml} application this causes the 
  1786 Within the \l {QML Viewer}, this causes the launcher application to exit.
  1712 launcher application to exit.
       
  1713 */
  1787 */
  1714 
  1788 
  1715 QScriptValue QDeclarativeEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptEngine *e)
  1789 QScriptValue QDeclarativeEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptEngine *e)
  1716 {
  1790 {
  1717     QDeclarativeEnginePrivate *qe = get (e);
  1791     QDeclarativeEnginePrivate *qe = get (e);