From 84a4a2ed1b17dd8d73404f52af032b959aada8b1 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 22 Jun 2010 12:23:25 +1000 Subject: Allow QT_TR_NOOP (as a no-op) in ListModel values. Task-number: QTBUG-11403 --- src/declarative/util/qdeclarativelistmodel.cpp | 13 +++++++++---- .../qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp | 10 +++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index ff83227..9ed21a6 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -81,8 +81,8 @@ QDeclarativeListModelParser::ListInstruction *QDeclarativeListModelParser::ListM Roles (properties) must begin with a lower-case letter. The above example defines a ListModel containing three elements, with the roles "name" and "cost". - Values must be simple constants - either strings (quoted), bools (true, false), numbers, - or enum values (like Text.AlignHCenter). + Values must be simple constants - either strings (quoted and optionally within a call to QT_TR_NOOP), + bools (true, false), numbers, or enum values (like Text.AlignHCenter). The defined model can be used in views such as ListView: @@ -620,8 +620,13 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser QByteArray script = variant.asScript().toUtf8(); int v = evaluateEnum(script); if (v<0) { - error(prop, QDeclarativeListModel::tr("ListElement: cannot use script for property value")); - return false; + if (script.startsWith("QT_TR_NOOP(\"") && script.endsWith("\")")) { + d[0] = char(QDeclarativeParser::Variant::String); + d += script.mid(12,script.length()-14); + } else { + error(prop, QDeclarativeListModel::tr("ListElement: cannot use script for property value")); + return false; + } } else { d[0] = char(QDeclarativeParser::Variant::Number); d += QByteArray::number(v); diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp index b3b6c20..3d66733 100644 --- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp +++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp @@ -48,6 +48,7 @@ #include #include +#include #include "../../../shared/util.h" @@ -124,14 +125,17 @@ void tst_qdeclarativelistmodel::waitForWorker(QDeclarativeItem *item) void tst_qdeclarativelistmodel::static_i18n() { QString expect = QString::fromUtf8("na\303\257ve"); - QString componentStr = "import Qt 4.7\nListModel { ListElement { prop1: \""+expect+"\" } }"; + + QString componentStr = "import Qt 4.7\nListModel { ListElement { prop1: \""+expect+"\"; prop2: QT_TR_NOOP(\""+expect+"\") } }"; QDeclarativeEngine engine; QDeclarativeComponent component(&engine); component.setData(componentStr.toUtf8(), QUrl::fromLocalFile("")); QDeclarativeListModel *obj = qobject_cast(component.create()); QVERIFY(obj != 0); - QString prop = obj->get(0).property(QLatin1String("prop1")).toString(); - QCOMPARE(prop,expect); + QString prop1 = obj->get(0).property(QLatin1String("prop1")).toString(); + QCOMPARE(prop1,expect); + QString prop2 = obj->get(0).property(QLatin1String("prop2")).toString(); + QCOMPARE(prop2,expect); // (no, not translated, QT_TR_NOOP is a no-op) delete obj; } -- cgit v0.12 From 800b1ad057d97f90555af3c94f08a935526373cf Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 22 Jun 2010 13:12:49 +1000 Subject: Doc --- src/declarative/qml/qdeclarativeinclude.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp index 388f252..c29005a 100644 --- a/src/declarative/qml/qdeclarativeinclude.cpp +++ b/src/declarative/qml/qdeclarativeinclude.cpp @@ -172,6 +172,29 @@ void QDeclarativeInclude::callback(QScriptEngine *engine, QScriptValue &callback } } +/*! +\qmlmethod object Qt::include(url, callback) + +Include another JavaScript file. This method can only be used from within JavaScript files, +and not regular QML files. + +Qt.include() returns an object that describes the status of the operation. The object has +a single property, \c {status} that is set to one of the following values: + +\table +\header \o Symbol \o Value \o Description +\row \o result.OK \o 0 \o The include completed successfully. +\row \o result.LOADING \o 1 \o Data is being loaded from the network. +\row \o result.NETWORK_ERROR \o 2 \o A network error occurred while fetching the url. +\row \o result.EXCEPTION \o 3 \o A JavaScript exception occurred while executing the included code. +An additional \c exception property will be set in this case. +\endtable + +The return object's properties will be updated as the operation progresses. + +If provided, \a callback is invoked when the operation completes. The callback is passed +the same object as is returned from the Qt.include() call. +*/ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *engine) { if (ctxt->argumentCount() == 0) @@ -184,7 +207,7 @@ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *e return ctxt->throwError(QLatin1String("Qt.include(): Can only be called from JavaScript files")); QString urlString = ctxt->argument(0).toString(); - QUrl url(ctxt->argument(0).toString()); + QUrl url(urlString); if (url.isRelative()) { url = QUrl(contextUrl).resolved(url); urlString = url.toString(); -- cgit v0.12 From 32b871a275983f39093fe8b35c38332772fbf58a Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 22 Jun 2010 16:31:59 +1000 Subject: Add demo thumbnails to Examples/Demos index to make it more interesting --- doc/src/declarative/examples.qdoc | 109 ++++++++++++++++-------- doc/src/images/qml-calculator-example-small.png | Bin 0 -> 16575 bytes doc/src/images/qml-flickr-demo-small.png | Bin 0 -> 40934 bytes doc/src/images/qml-minehunt-demo-small.png | Bin 0 -> 26977 bytes doc/src/images/qml-photoviewer-demo-small.png | Bin 0 -> 35633 bytes doc/src/images/qml-rssnews-demo-small.png | Bin 0 -> 19489 bytes doc/src/images/qml-samegame-demo-small.png | Bin 0 -> 36596 bytes doc/src/images/qml-snake-demo-small.png | Bin 0 -> 17895 bytes doc/src/images/qml-twitter-demo-small.png | Bin 0 -> 19807 bytes doc/src/images/qml-webbrowser-demo-small.png | Bin 0 -> 20924 bytes 10 files changed, 74 insertions(+), 35 deletions(-) create mode 100644 doc/src/images/qml-calculator-example-small.png create mode 100644 doc/src/images/qml-flickr-demo-small.png create mode 100644 doc/src/images/qml-minehunt-demo-small.png create mode 100644 doc/src/images/qml-photoviewer-demo-small.png create mode 100644 doc/src/images/qml-rssnews-demo-small.png create mode 100644 doc/src/images/qml-samegame-demo-small.png create mode 100644 doc/src/images/qml-snake-demo-small.png create mode 100644 doc/src/images/qml-twitter-demo-small.png create mode 100644 doc/src/images/qml-webbrowser-demo-small.png diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index dcd0362..f127ed1 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -45,29 +45,82 @@ \brief Building UI's with QML \ingroup all-examples -\section1 Running the examples -You can find many simple examples in the \c examples/declarative -sub-directory that show how to use various aspects of QML. In addition, the -\c demos/declarative sub-directory contains more sophisticated demos of large -applications. These demos are intended to show integrated functionality -rather than being instructive on specific elements. +Qt includes a set of examples and demos that show how to use various aspects +of QML. The examples are small demonstrations of particular QML components, +while the demos contain more complete and functional applications. To run the examples and demos, you can use Qt Creator or the included \l {Qt Declarative UI Runtime}{qmlviewer} -command-line application. It has some useful options, revealed by: +command-line application. For example, from your build directory, run: \code - bin/qmlviewer -help + bin/qmlviewer $QTDIR/demos/declarative/samegame/samegame.qml \endcode -For example, from your build directory, run: -\code - bin/qmlviewer $QTDIR/demos/declarative/samegame/samegame.qml -\endcode +\section1 Demos + +The QML demos integrate a variety of features to demonstrate how QML +can be used to produce sophisticated interfaces and applications: + + +\table +\row + +\o +\l{demos/declarative/calculator}{Calculator} +\image qml-calculator-example-small.png + +\o +\l{demos/declarative/flickr}{Flickr Mobile} +\image qml-flickr-demo-small.png + +\o +\l{demos/declarative/minehunt}{Minehunt} +\image qml-minehunt-demo-small.png + +\row + +\o +\l{demos/declarative/photoviewer}{Photo Viewer} +\image qml-photoviewer-demo-small.png + +\o +\l{demos/declarative/rssnews}{RSS News Reader} +\image qml-rssnews-demo-small.png + +\o +\l{demos/declarative/samegame}{Same Game} +\image qml-samegame-demo-small.png + +\row + +\o +\l{demos/declarative/snake}{Snake} +\image qml-snake-demo-small.png + +\o +\l{demos/declarative/twitter}{Twitter} +\image qml-twitter-demo-small.png + +\o +\l{demos/declarative/webbrowser}{Web Browser} +\image qml-webbrowser-demo-small.png + +\endtable + +The demos can be found in Qt's \c demos/declarative directory. + \section1 Examples +The QML examples are small, simple applications that show how to use a particular +QML component or feature. If you are new +to QML, you may also find the \l{QML Tutorial}{Hello World} and +\l {QML Advanced Tutorial}{Same Game} tutorials useful. + +The examples can be found in Qt's \c examples/declarative directory. + \section2 Animation \list \o \l{declarative/animation/basics}{Basics} @@ -116,6 +169,15 @@ For example, from your build directory, run: \o \l{declarative/ui-components/tabwidget}{Tab widget} \endlist +\section2 Toys +\list +\o \l{declarative/toys/clocks}{Clocks} +\o \l{declarative/toys/corkboards}{Corkboards} +\o \l{declarative/toys/dynamicscene}{Dynamic Scene} +\o \l{declarative/toys/tic-tac-toe}{Tic Tac Toe} +\o \l{declarative/toys/tvtennis}{TV Tennis} +\endlist + \section2 Models and Views \list \o \l{declarative/modelviews/gridview}{GridView} @@ -128,15 +190,6 @@ For example, from your build directory, run: \o \l{declarative/modelviews/webview}{WebView} \endlist -\section2 Toys -\list -\o \l{declarative/toys/clocks}{Clocks} -\o \l{declarative/toys/corkboards}{Corkboards} -\o \l{declarative/toys/dynamicscene}{Dynamic Scene} -\o \l{declarative/toys/tic-tac-toe}{Tic Tac Toe} -\o \l{declarative/toys/tvtennis}{TV Tennis} -\endlist - \section2 XML \list \o \l{declarative/xml/xmlhttprequest}{XmlHttpRequest} @@ -169,20 +222,6 @@ For example, from your build directory, run: \endlist -\section1 Demos - -\list -\o \l{demos/declarative/calculator}{Calculator} -\o \l{demos/declarative/flickr}{Flickr Mobile} -\o \l{demos/declarative/minehunt}{Minehunt} -\o \l{demos/declarative/photoviewer}{Photo Viewer} -\o \l{demos/declarative/rssnews}{RSS News Reader} -\o \l{demos/declarative/samegame}{Same Game} -\o \l{demos/declarative/snake}{Snake} -\o \l{demos/declarative/twitter}{Twitter} -\o \l{demos/declarative/webbrowser}{Web Browser} -\endlist - \section1 Labs \list diff --git a/doc/src/images/qml-calculator-example-small.png b/doc/src/images/qml-calculator-example-small.png new file mode 100644 index 0000000..9e0370f Binary files /dev/null and b/doc/src/images/qml-calculator-example-small.png differ diff --git a/doc/src/images/qml-flickr-demo-small.png b/doc/src/images/qml-flickr-demo-small.png new file mode 100644 index 0000000..370ffcf Binary files /dev/null and b/doc/src/images/qml-flickr-demo-small.png differ diff --git a/doc/src/images/qml-minehunt-demo-small.png b/doc/src/images/qml-minehunt-demo-small.png new file mode 100644 index 0000000..e5badac Binary files /dev/null and b/doc/src/images/qml-minehunt-demo-small.png differ diff --git a/doc/src/images/qml-photoviewer-demo-small.png b/doc/src/images/qml-photoviewer-demo-small.png new file mode 100644 index 0000000..b16fb4e Binary files /dev/null and b/doc/src/images/qml-photoviewer-demo-small.png differ diff --git a/doc/src/images/qml-rssnews-demo-small.png b/doc/src/images/qml-rssnews-demo-small.png new file mode 100644 index 0000000..451a420 Binary files /dev/null and b/doc/src/images/qml-rssnews-demo-small.png differ diff --git a/doc/src/images/qml-samegame-demo-small.png b/doc/src/images/qml-samegame-demo-small.png new file mode 100644 index 0000000..ec9ad76 Binary files /dev/null and b/doc/src/images/qml-samegame-demo-small.png differ diff --git a/doc/src/images/qml-snake-demo-small.png b/doc/src/images/qml-snake-demo-small.png new file mode 100644 index 0000000..23a7b3b Binary files /dev/null and b/doc/src/images/qml-snake-demo-small.png differ diff --git a/doc/src/images/qml-twitter-demo-small.png b/doc/src/images/qml-twitter-demo-small.png new file mode 100644 index 0000000..b55ceba Binary files /dev/null and b/doc/src/images/qml-twitter-demo-small.png differ diff --git a/doc/src/images/qml-webbrowser-demo-small.png b/doc/src/images/qml-webbrowser-demo-small.png new file mode 100644 index 0000000..6c5d57d Binary files /dev/null and b/doc/src/images/qml-webbrowser-demo-small.png differ -- cgit v0.12 From ff956977c4236c33062e3246ac254fcc7b98e779 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 22 Jun 2010 16:47:21 +1000 Subject: qmldir no longer necessary --- examples/declarative/keyinteraction/focus/Core/qmldir | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 examples/declarative/keyinteraction/focus/Core/qmldir diff --git a/examples/declarative/keyinteraction/focus/Core/qmldir b/examples/declarative/keyinteraction/focus/Core/qmldir deleted file mode 100644 index e25d63c..0000000 --- a/examples/declarative/keyinteraction/focus/Core/qmldir +++ /dev/null @@ -1,4 +0,0 @@ -ContextMenu ContextMenu.qml -GridMenu GridMenu.qml -ListViews ListViews.qml -ListViewDelegate ListViewDelegate.qml -- cgit v0.12 From f07c1a7a2bf1065760db5197b835fd5e67cd1f1e Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 22 Jun 2010 16:49:34 +1000 Subject: Remove transparent.qml example for now, until QTBUG-11591 is fixed --- .../declarative/modelviews/webview/transparent.qml | 55 ---------------------- 1 file changed, 55 deletions(-) delete mode 100644 examples/declarative/modelviews/webview/transparent.qml diff --git a/examples/declarative/modelviews/webview/transparent.qml b/examples/declarative/modelviews/webview/transparent.qml deleted file mode 100644 index 92c1578..0000000 --- a/examples/declarative/modelviews/webview/transparent.qml +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor -** the names of its contributors may be used to endorse or promote -** products derived from this software without specific prior written -** permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt 4.7 -import org.webkit 1.0 - -// The WebView background is transparent -// if the HTML does not specify a background -Rectangle { - color: "green" - width: web.width - height: web.height - - WebView { - id: web - html: "Hello World!" - } -} -- cgit v0.12 From 70aab1578e1822f4571f7b13841603fc4ceef0f6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 22 Jun 2010 16:54:02 +1000 Subject: Handle TextInput inputMethodEvent() properly Follow the pattern of other text input classes and QML key handling classes. --- .../graphicsitems/qdeclarativetextinput.cpp | 19 +++++++++++++++++-- .../graphicsitems/qdeclarativetextinput_p.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 9e5dfb5..ec14c78 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -913,6 +913,22 @@ void QDeclarativeTextInput::keyPressEvent(QKeyEvent* ev) QDeclarativePaintedItem::keyPressEvent(ev); } +void QDeclarativeTextInput::inputMethodEvent(QInputMethodEvent *ev) +{ + Q_D(QDeclarativeTextInput); + inputMethodPreHandler(ev); + if (ev->isAccepted()) + return; + if (d->control->isReadOnly()) { + ev->ignore(); + } else { + d->control->processInputMethodEvent(ev); + updateSize(); + } + if (!ev->isAccepted()) + QDeclarativePaintedItem::inputMethodEvent(ev); +} + /*! \overload Handles the given mouse \a event. @@ -993,6 +1009,7 @@ bool QDeclarativeTextInput::event(QEvent* ev) switch(ev->type()){ case QEvent::KeyPress: case QEvent::KeyRelease://###Should the control be doing anything with release? + case QEvent::InputMethod: case QEvent::GraphicsSceneMousePress: case QEvent::GraphicsSceneMouseMove: case QEvent::GraphicsSceneMouseRelease: @@ -1000,8 +1017,6 @@ bool QDeclarativeTextInput::event(QEvent* ev) break; default: handled = d->control->processEvent(ev); - if (ev->type() == QEvent::InputMethod) - updateSize(); } if(!handled) handled = QDeclarativePaintedItem::event(ev); diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h index 03f55ae..6934da4 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h @@ -222,6 +222,7 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void keyPressEvent(QKeyEvent* ev); + void inputMethodEvent(QInputMethodEvent *); bool event(QEvent *e); void focusInEvent(QFocusEvent *event); -- cgit v0.12