From 3d769613d5efc642ebfd8d5fe7c149834132fe65 Mon Sep 17 00:00:00 2001 From: David Boddie Date: Mon, 24 Jan 2011 15:09:14 +0100 Subject: Doc: Fixed the syntax of QML code snippets. --- src/declarative/graphicsitems/qdeclarativeitem.cpp | 44 +++++++++++--------- .../graphicsitems/qdeclarativepositioners.cpp | 10 +++-- .../graphicsitems/qdeclarativerectangle.cpp | 5 ++- src/declarative/graphicsitems/qdeclarativetext.cpp | 35 ++++++++++++---- .../graphicsitems/qdeclarativetextinput.cpp | 4 +- src/declarative/util/qdeclarativestategroup.cpp | 48 +++++++++++++--------- src/declarative/util/qdeclarativexmllistmodel.cpp | 13 +++--- 7 files changed, 101 insertions(+), 58 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index e915bea..a99d918 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -2124,16 +2124,18 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const \o \image declarative-anchors_example.png \o Text anchored to Image, horizontally centered and vertically below, with a margin. \qml - Image { - id: pic - // ... - } - Text { - id: label - anchors.horizontalCenter: pic.horizontalCenter - anchors.top: pic.bottom - anchors.topMargin: 5 - // ... + Item { + Image { + id: pic + // ... + } + Text { + id: label + anchors.horizontalCenter: pic.horizontalCenter + anchors.top: pic.bottom + anchors.topMargin: 5 + // ... + } } \endqml \row @@ -2143,16 +2145,18 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const property of both defaults to 0. \qml - Image { - id: pic - // ... - } - Text { - id: label - anchors.left: pic.right - anchors.leftMargin: 5 - // ... - } + Item { + Image { + id: pic + // ... + } + Text { + id: label + anchors.left: pic.right + anchors.leftMargin: 5 + // ... + } + } \endqml \endtable diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index 4e049c7..e0bd2ff 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -364,9 +364,13 @@ void QDeclarativeBasePositioner::finishApplyTransitions() \qml Column { spacing: 2 - add: ... - move: ... - ... + add: Transition { + // Define an animation for adding a new item... + } + move: Transition { + // Define an animation for moving items within the column... + } + // ... } \endqml diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp index 403f12c..d962919 100644 --- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp +++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp @@ -60,7 +60,10 @@ QT_BEGIN_NAMESPACE Example: \qml - Rectangle { border.width: 2; border.color: "red" ... } + Rectangle { + border.width: 2 + border.color: "red" + } \endqml */ diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 2f3c8e5..79aa18d 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -558,11 +558,24 @@ QPixmap QDeclarativeTextPrivate::drawOutline(const QPixmap &source, const QPixma \brief The Text item allows you to add formatted text to a scene. \inherits Item - A Text item can display both plain and rich text. For example: + Text items can display both plain and rich text. For example, red text with + a specific font and size can be defined like this: \qml - Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" } - Text { text: "Hello World!" } + Text { + text: "Hello World!" + font.family: "Helvetica" + font.pointSize: 24 + color: "red" + } + \endqml + + Rich text is defined using HTML-style markup: + + \qml + Text { + text: "Hello World!" + } \endqml \image declarative-text.png @@ -789,12 +802,20 @@ void QDeclarativeText::setText(const QString &n) The text color. + An example of green text defined using hexadecimal notation: \qml - //green text using hexadecimal notation - Text { color: "#00FF00"; ... } + Text { + color: "#00FF00" + text: "green text" + } + \endqml - //steelblue text using SVG color name - Text { color: "steelblue"; ... } + An example of steel blue text defined using an SVG color name: + \qml + Text { + color: "steelblue" + text: "blue text" + } \endqml */ QColor QDeclarativeText::color() const diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 57a2177..cb308f4 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -520,10 +520,10 @@ void QDeclarativeTextInput::select(int start, int end) It is equivalent to the following snippet, but is faster and easier to use. - \qml + \js myTextInput.text.toString().substring(myTextInput.selectionStart, myTextInput.selectionEnd); - \endqml + \endjs */ QString QDeclarativeTextInput::selectedText() const { diff --git a/src/declarative/util/qdeclarativestategroup.cpp b/src/declarative/util/qdeclarativestategroup.cpp index 7aeea12..f1d0997 100644 --- a/src/declarative/util/qdeclarativestategroup.cpp +++ b/src/declarative/util/qdeclarativestategroup.cpp @@ -102,10 +102,10 @@ public: id: myStateGroup states: State { name: "state1" - ... + // ... } transitions: Transition { - ... + // ... } } @@ -140,11 +140,15 @@ QList QDeclarativeStateGroup::states() const \qml StateGroup { - states: [ - State { ... }, - State { ... } - ... - ] + states: [ + State { + // State definition... + }, + State { + // ... + } + // Other states... + ] } \endqml @@ -197,11 +201,15 @@ void QDeclarativeStateGroupPrivate::clear_states(QDeclarativeListProperty QDeclarativeStateGroup::transit This property is often used in scripts to change between states. For example: - \qml - function toggle() { - if (button.state == 'On') - button.state = 'Off'; - else - button.state = 'On'; - } - \endqml + \js + function toggle() { + if (button.state == 'On') + button.state = 'Off'; + else + button.state = 'On'; + } + \endjs If the state group is in its base state (i.e. no explicit state has been set), \c state will be a blank string. Likewise, you can return a diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 7da4ecd..c582df1 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -90,8 +90,11 @@ typedef QPair QDeclarativeXmlListRange; \qml XmlListModel { id: xmlModel - ... - XmlRole { name: "title"; query: "title/string()" } + // ... + XmlRole { + name: "title" + query: "title/string()" + } } ListView { @@ -792,9 +795,9 @@ void QDeclarativeXmlListModel::setNamespaceDeclarations(const QString &declarati This will access the \c title value for the first item in the model: - \qml - var title = model.get(0).title; - \endqml + \js + var title = model.get(0).title; + \endjs */ QScriptValue QDeclarativeXmlListModel::get(int index) const { -- cgit v0.12