summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-07-14 01:51:22 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-07-14 01:51:22 (GMT)
commit07ebc9161263c04dc072b9fc2a922b9665cbe7be (patch)
treebbf983b8968f4a0df6ac089a7ff716ec4a66efc6
parent237bc693a527f9cb2b6bbe7c518018cbf56b0eb6 (diff)
downloadQt-07ebc9161263c04dc072b9fc2a922b9665cbe7be.zip
Qt-07ebc9161263c04dc072b9fc2a922b9665cbe7be.tar.gz
Qt-07ebc9161263c04dc072b9fc2a922b9665cbe7be.tar.bz2
improvements to docs and examples
-rw-r--r--doc/src/declarative/anchor-layout.qdoc5
-rw-r--r--doc/src/declarative/basictypes.qdoc3
-rw-r--r--doc/src/images/qml-mousearea-example.pngbin5527 -> 6969 bytes
-rw-r--r--doc/src/images/qml-xmllistmodel-example.pngbin0 -> 5252 bytes
-rw-r--r--doc/src/snippets/declarative/mousearea.qml13
-rw-r--r--examples/declarative/cppextensions/imageprovider/imageprovider.cpp2
-rw-r--r--examples/declarative/touchinteraction/mousearea/mousearea-example.qml64
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp59
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp6
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp10
-rw-r--r--src/declarative/qml/qdeclarativeimageprovider.cpp16
-rw-r--r--src/declarative/util/qdeclarativestateoperations.cpp2
-rw-r--r--src/declarative/util/qdeclarativexmllistmodel.cpp17
13 files changed, 115 insertions, 82 deletions
diff --git a/doc/src/declarative/anchor-layout.qdoc b/doc/src/declarative/anchor-layout.qdoc
index 9c217e1..5c025e5 100644
--- a/doc/src/declarative/anchor-layout.qdoc
+++ b/doc/src/declarative/anchor-layout.qdoc
@@ -33,7 +33,10 @@
In addition to the more traditional \l Grid, \l Row, and \l Column,
QML also provides a way to layout items using the concept of \e anchors.
Each item can be thought of as having a set of 7 invisible "anchor lines":
-\e left, \e horizontalCenter, \e right, \e top, \e verticalCenter, \e baseline, and \e bottom.
+\l {Item::anchors.left}{left}, \l {Item::anchors.horizontalCenter}{horizontalCenter},
+\l {Item::anchors.right}{right}, \l {Item::anchors.top}{top},
+\l {Item::anchors.verticalCenter}{verticalCenter}, \l {Item::anchors.baseline}{baseline},
+and \l {Item::anchors.bottom}{bottom}.
\image edges_qml.png
diff --git a/doc/src/declarative/basictypes.qdoc b/doc/src/declarative/basictypes.qdoc
index 109e6d5..e327d4a 100644
--- a/doc/src/declarative/basictypes.qdoc
+++ b/doc/src/declarative/basictypes.qdoc
@@ -107,6 +107,9 @@
Text { text: "Hello world!" }
\endqml
+ Strings have a \c length attribute that holds the number of
+ characters in the string.
+
\sa {QML Basic Types}
*/
diff --git a/doc/src/images/qml-mousearea-example.png b/doc/src/images/qml-mousearea-example.png
index c6e52d6..c0eef7f 100644
--- a/doc/src/images/qml-mousearea-example.png
+++ b/doc/src/images/qml-mousearea-example.png
Binary files differ
diff --git a/doc/src/images/qml-xmllistmodel-example.png b/doc/src/images/qml-xmllistmodel-example.png
new file mode 100644
index 0000000..be2d15d
--- /dev/null
+++ b/doc/src/images/qml-xmllistmodel-example.png
Binary files differ
diff --git a/doc/src/snippets/declarative/mousearea.qml b/doc/src/snippets/declarative/mousearea.qml
index 8e7c737..fb6cba0 100644
--- a/doc/src/snippets/declarative/mousearea.qml
+++ b/doc/src/snippets/declarative/mousearea.qml
@@ -83,17 +83,18 @@ Rectangle {
id: container
width: 600; height: 200
- Image {
- id: pic
- source: "pics/qt.png"
- opacity: (600.0 - pic.x) / 600
+ Rectangle {
+ id: rect
+ width: 50; height: 50
+ color: "red"
+ opacity: (600.0 - rect.x) / 600
MouseArea {
anchors.fill: parent
- drag.target: pic
+ drag.target: rect
drag.axis: Drag.XAxis
drag.minimumX: 0
- drag.maximumX: container.width - pic.width
+ drag.maximumX: container.width - rect.width
}
}
}
diff --git a/examples/declarative/cppextensions/imageprovider/imageprovider.cpp b/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
index 995192a..18d027e 100644
--- a/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
+++ b/examples/declarative/cppextensions/imageprovider/imageprovider.cpp
@@ -54,7 +54,7 @@ class ColorImageProvider : public QDeclarativeImageProvider
{
public:
ColorImageProvider()
- : QDeclarativeImageProvider(Pixmap)
+ : QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap)
{
}
diff --git a/examples/declarative/touchinteraction/mousearea/mousearea-example.qml b/examples/declarative/touchinteraction/mousearea/mousearea-example.qml
index 64f72a9..85ea2dc 100644
--- a/examples/declarative/touchinteraction/mousearea/mousearea-example.qml
+++ b/examples/declarative/touchinteraction/mousearea/mousearea-example.qml
@@ -44,59 +44,69 @@ Rectangle {
id: box
width: 350; height: 250
- function showInfo(text) {
- statusText.text = text
- }
-
Rectangle {
+ id: redSquare
width: 80; height: 80
+ anchors.top: parent.top; anchors.left: parent.left; anchors.margins: 10
color: "red"
Text { text: "Click"; font.pixelSize: 16; anchors.centerIn: parent }
MouseArea {
- anchors.fill: parent
+ anchors.fill: parent
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
- onPressed: box.showInfo('Pressed (x=' + mouse.x + ' y=' + mouse.y + ' button='
- + (mouse.button == Qt.RightButton ? 'right' : 'left')
- + ' Shift=' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')')
- onReleased: box.showInfo('Released (x=' + mouse.x + ' y=' + mouse.y
- + ' isClick=' + mouse.isClick + ' wasHeld=' + mouse.wasHeld + ')')
- onClicked: box.showInfo('Clicked (x=' + mouse.x + ' y=' + mouse.y + ' wasHeld=' + mouse.wasHeld + ')')
- onDoubleClicked: box.showInfo('Double clicked (x=' + mouse.x + ' y=' + mouse.y + ')')
- onPressAndHold: box.showInfo('Press and hold')
- onEntered: box.showInfo('Entered (pressed=' + pressed + ')')
- onExited: box.showInfo('Exited (pressed=' + pressed + ')')
+ onEntered: info.text = 'Entered'
+ onExited: info.text = 'Exited (pressed=' + pressed + ')'
+
+ onPressed: {
+ info.text = 'Pressed (button=' + (mouse.button == Qt.RightButton ? 'right' : 'left')
+ + ' shift=' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')'
+ var posInBox = redSquare.mapToItem(box, mouse.x, mouse.y)
+ posInfo.text = + mouse.x + ',' + mouse.y + ' in square'
+ + ' (' + posInBox.x + ',' + posInBox.y + ' in window)'
+ }
+
+ onReleased: {
+ info.text = 'Released (isClick=' + mouse.isClick + ' wasHeld=' + mouse.wasHeld + ')'
+ posInfo.text = ''
+ }
+
+ onPressAndHold: info.text = 'Press and hold'
+ onClicked: info.text = 'Clicked (wasHeld=' + mouse.wasHeld + ')'
+ onDoubleClicked: info.text = 'Double clicked'
}
}
Rectangle {
- width: 80; height: 80; anchors.right: parent.right
+ id: blueSquare
+ width: 80; height: 80
+ x: box.width - width - 10; y: 10 // making this item draggable, so don't use anchors
color: "blue"
Text { text: "Drag"; font.pixelSize: 16; color: "white"; anchors.centerIn: parent }
MouseArea {
anchors.fill: parent
- drag.target: parent
- drag.axis: Drag.XAxis
+ drag.target: blueSquare
+ drag.axis: Drag.XandYAxis
drag.minimumX: 0
- drag.maximumX: 150
-
- onPressed: box.showInfo('Pressed')
- onReleased: box.showInfo('Released (isClick=' + mouse.isClick + ' wasHeld=' + mouse.wasHeld + ')')
- onClicked: box.showInfo('Clicked' + ' (wasHeld=' + mouse.wasHeld + ')')
- onDoubleClicked: box.showInfo('Double clicked')
- onPressAndHold: box.showInfo('Press and hold')
+ drag.maximumX: box.width - parent.width
+ drag.minimumY: 0
+ drag.maximumY: box.height - parent.width
}
}
Text {
- id: statusText
- anchors.bottom: parent.bottom; anchors.horizontalCenter: parent.horizontalCenter; anchors.margins: 30
+ id: info
+ anchors.bottom: posInfo.top; anchors.horizontalCenter: parent.horizontalCenter; anchors.margins: 30
onTextChanged: console.log(text)
}
+
+ Text {
+ id: posInfo
+ anchors.bottom: parent.bottom; anchors.horizontalCenter: parent.horizontalCenter; anchors.margins: 30
+ }
}
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index 34d33f5..90738c8 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -324,17 +324,34 @@ qreal QDeclarativeImage::paintedHeight() const
/*!
\qmlproperty QSize Image::sourceSize
- This property holds the size of the loaded image, in pixels.
+ This property holds the actual width and height of the loaded image.
- This is used to control the storage used by a loaded image. Unlike
- the width and height properties, which scale the painting of the image, this property
- affects the number of pixels stored.
+ Unlike the \l {Item::}{width} and \l {Item::}{height} properties, which scale
+ the painting of the image, this property sets the actual number of pixels
+ stored for the loaded image so that large images do not use more
+ memory than necessary. For example, this ensures the image is memory is no
+ larger than 1024x1024 pixels, regardless of the Image's \l {Item::}{width} and
+ \l {Item::}{height} values:
+
+ \code
+ Rectangle {
+ width: ...
+ height: ...
+
+ Image {
+ anchors.fill: parent
+ source: "reallyBigImage.jpg"
+ sourceSize.width: 1024
+ sourceSize.height: 1024
+ }
+ }
+ \endcode
If the image's actual size is larger than the sourceSize, the image is scaled down.
If only one dimension of the size is set to greater than 0, the
other dimension is set in proportion to preserve the source image's aspect ratio.
(The \l fillMode is independent of this.)
-
+
If the source is an instrinsically scalable image (eg. SVG), this property
determines the size of the loaded image regardless of intrinsic size.
Avoid changing this property dynamically; rendering an SVG is \e slow compared
@@ -344,34 +361,8 @@ qreal QDeclarativeImage::paintedHeight() const
be no greater than this property specifies. For some formats (currently only JPEG),
the whole image will never actually be loaded into memory.
- \note \e{Changing this property dynamically will lead to the image source being reloaded,
- potentially even from the network if it is not in the disk cache.}
-
- Here is an example that ensures the size of the image in memory is
- no larger than 1024x1024 pixels, regardless of the size of the Image element.
-
- \code
- Image {
- anchors.fill: parent
- source: "images/reallyBigImage.jpg"
- sourceSize.width: 1024
- sourceSize.height: 1024
- }
- \endcode
-
- The example below ensures the memory used by the image is no more than necessary
- to display the image at the size of the Image element.
- Of course if the Image element is resized a costly reload will be required, so
- use this technique \e only when the Image size is fixed.
-
- \code
- Image {
- anchors.fill: parent
- source: "images/reallyBigImage.jpg"
- sourceSize.width: width
- sourceSize.height: height
- }
- \endcode
+ \note \e {Changing this property dynamically causes the image source to be reloaded,
+ potentially even from the network, if it is not in the disk cache.}
*/
void QDeclarativeImage::updatePaintedGeometry()
@@ -415,6 +406,8 @@ void QDeclarativeImage::geometryChanged(const QRectF &newGeometry, const QRectF
Image can handle any image format supported by Qt, loaded from any URL scheme supported by Qt.
The URL may be absolute, or relative to the URL of the component.
+
+ \sa QDeclarativeImageProvider
*/
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 7022fac..190b22c 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -2097,7 +2097,7 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const
relationship with other items.
Margins apply to top, bottom, left, right, and fill anchors.
- The margins property can be used to set all of the various margins at once, to the same value.
+ The \c anchors.margins property can be used to set all of the various margins at once, to the same value.
Offsets apply for horizontal center, vertical center, and baseline anchors.
@@ -2132,10 +2132,12 @@ QDeclarativeAnchorLine QDeclarativeItemPrivate::baseline() const
\endqml
\endtable
- anchors.fill provides a convenient way for one item to have the
+ \c anchors.fill provides a convenient way for one item to have the
same geometry as another item, and is equivalent to connecting all
four directional anchors.
+ To clear an anchor value, set it to \c undefined.
+
\note You can only anchor an item to siblings or a parent.
For more information see \l {anchor-layout}{Anchor Layouts}.
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index 7b65ca7..b7b0c9e 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -767,10 +767,16 @@ QDeclarativeDrag *QDeclarativeMouseArea::drag()
\i \c drag.minimum and \c drag.maximum limit how far the target can be dragged along the corresponding axes.
\endlist
- The following example displays an image that can be dragged along the X-axis. The opacity
- of the image is reduced when it is dragged to the right.
+ The following example displays a \l Rectangle that can be dragged along the X-axis. The opacity
+ of the rectangle is reduced when it is dragged to the right.
\snippet doc/src/snippets/declarative/mousearea.qml drag
+
+ \note Items cannot be dragged if they are anchored for the requested
+ \c drag.axis. For example, if \c anchors.left or \c anchors.right was set
+ for \c rect in the above example, it cannot be dragged along the X-axis.
+ This can be avoided by settng the anchor value to \c undefined in
+ an \l onPressed handler.
*/
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp
index f38da4e..a294c38 100644
--- a/src/declarative/qml/qdeclarativeimageprovider.cpp
+++ b/src/declarative/qml/qdeclarativeimageprovider.cpp
@@ -180,9 +180,13 @@ QDeclarativeImageProvider::ImageType QDeclarativeImageProvider::imageType() cons
Implement this method to return the image with \a id. The default
implementation returns an empty image.
- If \a requestedSize is a valid size, the image returned should be of that size.
+ The \a requestedSize corresponds to the \l {Image::sourceSize} requested by
+ an Image element. If \a requestedSize is a valid size, the image
+ returned should be of that size.
- In all cases, \a size must be set to the original size of the image.
+ In all cases, \a size must be set to the original size of the image. This
+ is used to set the \l {Item::}{width} and \l {Item::}{height} of image
+ elements that should be automatically sized to the loaded image.
\note this method may be called by multiple threads, so ensure the
implementation of this method is reentrant.
@@ -201,9 +205,13 @@ QImage QDeclarativeImageProvider::requestImage(const QString &id, QSize *size, c
Implement this method to return the pixmap with \a id. The default
implementation returns an empty pixmap.
- If \a requestedSize is a valid size, the image returned should be of that size.
+ The \a requestedSize corresponds to the \l {Image::sourceSize} requested by
+ an Image element. If \a requestedSize is a valid size, the image
+ returned should be of that size.
- In all cases, \a size must be set to the original size of the image.
+ In all cases, \a size must be set to the original size of the image. This
+ is used to set the \l {Item::}{width} and \l {Item::}{height} of image
+ elements that should be automatically sized to the loaded image.
\note this method may be called by multiple threads, so ensure the
implementation of this method is reentrant.
diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp
index 51e6f99..5590449 100644
--- a/src/declarative/util/qdeclarativestateoperations.cpp
+++ b/src/declarative/util/qdeclarativestateoperations.cpp
@@ -1039,7 +1039,7 @@ public:
/*!
\qmlproperty Item AnchorChanges::target
- This property holds the Item whose anchors will change
+ This property holds the \l Item for which the anchor changes will be applied.
*/
QDeclarativeAnchorChanges::QDeclarativeAnchorChanges(QObject *parent)
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp
index 00169db..9895ff2 100644
--- a/src/declarative/util/qdeclarativexmllistmodel.cpp
+++ b/src/declarative/util/qdeclarativexmllistmodel.cpp
@@ -508,8 +508,8 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
\since 4.7
\brief The XmlListModel element is used to specify a model using XPath expressions.
- XmlListModel is used to create a model from XML data. XmlListModel can be used as a data source
- for the view classes (such as ListView, PathView, GridView) and other classes that interact with model
+ XmlListModel is used to create a model from XML data. It can be used as a data source
+ for view elements (such as ListView, PathView, GridView) and other elements that interact with model
data (such as \l Repeater).
For example, if there is a XML document at http://www.mysite.com/feed.xml like this:
@@ -520,11 +520,11 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
...
<channel>
<item>
- <title>Item A</title>
+ <title>A blog post</title>
<pubDate>Sat, 07 Sep 2010 10:00:01 GMT</pubDate>
</item>
<item>
- <title>Item B</title>
+ <title>Another blog post</title>
<pubDate>Sat, 07 Sep 2010 15:35:01 GMT</pubDate>
</item>
</channel>
@@ -560,10 +560,17 @@ void QDeclarativeXmlListModelPrivate::clear_role(QDeclarativeListProperty<QDecla
ListView {
width: 180; height: 300
model: xmlModel
- delegate: Text { title + " (" + pubDate + ")" }
+ delegate: Text { text: title + " (" + pubDate + ")" }
}
\endqml
+ \image qml-xmllistmodel-example.png
+
+ The XmlListModel data is loaded asynchronously, and \l status
+ is set to \l XmlListModel::Ready when loading is complete.
+ Note this means when XmlListModel is used for a view, the view is not
+ populated until the model is loaded.
+
\section2 Using key XML roles