summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-04-30 08:34:09 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-04-30 08:34:09 (GMT)
commite2bfab6f145ddc61ef21590e69c709456e430d1c (patch)
tree0d3947e866d60a85bf05684a8a73a12b1ffb4c9c /src
parent0ce47e44c2c2259ebe2c8167766d91de082a3531 (diff)
parent6d217e8b3ba881eb02d09e225305ccd0329598e9 (diff)
downloadQt-e2bfab6f145ddc61ef21590e69c709456e430d1c.zip
Qt-e2bfab6f145ddc61ef21590e69c709456e430d1c.tar.gz
Qt-e2bfab6f145ddc61ef21590e69c709456e430d1c.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/qfxgridview.cpp6
-rw-r--r--src/declarative/fx/qfximage.cpp2
-rw-r--r--src/declarative/fx/qfxitem.cpp2
-rw-r--r--src/declarative/fx/qfxlistview.cpp10
-rw-r--r--src/declarative/fx/qfxpathview.cpp169
-rw-r--r--src/declarative/fx/qfxpathview.h2
-rw-r--r--src/declarative/fx/qfxtext.cpp50
-rw-r--r--src/declarative/fx/qfxwebview.cpp27
8 files changed, 148 insertions, 120 deletions
diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp
index c8b8d27..b8acea2 100644
--- a/src/declarative/fx/qfxgridview.cpp
+++ b/src/declarative/fx/qfxgridview.cpp
@@ -650,12 +650,12 @@ void QFxGridViewPrivate::updateCurrent(int modelIndex)
\brief The GridView element provides a grid view of items provided by a model.
The model is typically provided by a QAbstractListModel "C++ model object",
- but can also be created directly in XML.
+ but can also be created directly in QML.
The items are laid out top to bottom (vertically) or left to right (horizontally)
and may be flicked to scroll.
- The below example creates a very simple grid, using an XML model.
+ The below example creates a very simple grid, using a QML model.
\code
<resources>
<ListModel id="contactModel">
@@ -706,7 +706,7 @@ QFxGridView::~QFxGridView()
The C++ model object must be a \l QListModelInterface subclass, a \l VisualModel,
or a simple list.
- Models can also be created directly in XML, using the \l ListModel element. For example:
+ Models can also be created directly in QML, using the \l ListModel element. For example:
\code
<ListModel id="contactModel">
<Contact>
diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index a34cd12..74ba8b8 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -135,7 +135,7 @@ QFxImage::~QFxImage()
This property contains the image currently being displayed by this item,
which may be an empty pixmap if nothing is currently displayed. If this
property is set, the src property will be unset. This property is intended
- to be used only in C++, not in XML.
+ to be used only in C++, not in QML.
*/
QPixmap QFxImage::pixmap() const
{
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 11b7dd3..38b5713 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -1676,7 +1676,7 @@ QmlList<QmlTransition *>* QFxItem::transitions()
the item, or giving it a \l Reflection. Some
filters may not be available on all canvases; if a filter is not
available on a certain canvas, it will simply not be applied for
- that canvas (but the XML will still be considered valid).
+ that canvas (but the QML will still be considered valid).
\qml
<Item>
diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp
index 13e5b21..98fa606 100644
--- a/src/declarative/fx/qfxlistview.cpp
+++ b/src/declarative/fx/qfxlistview.cpp
@@ -797,10 +797,10 @@ void QFxListViewPrivate::fixupX()
\inherits Flickable
\brief The ListView element provides a list view of items provided by a model.
- The model is typically provided by a QAbstractListModel "C++ model object", but can also be created directly in XML.
+ The model is typically provided by a QAbstractListModel "C++ model object", but can also be created directly in QML.
The items are laid out vertically or horizontally and may be flicked to scroll.
- The below example creates a very simple vertical list, using an XML model.
+ The below example creates a very simple vertical list, using a QML model.
\image trivialListView.png
The user interface defines a delegate to display an item, a highlight,
@@ -808,7 +808,7 @@ void QFxListViewPrivate::fixupX()
\snippet doc/src/snippets/declarative/listview/listview.qml 3
- The model is defined as a ListModel using XML:
+ The model is defined as a ListModel using QML:
\quotefromfile doc/src/snippets/declarative/listview/dummydata/ContactModel.qml
\skipto <ListModel
\printuntil </ListModel
@@ -837,10 +837,10 @@ QFxListView::~QFxListView()
The model provides a set of data that is used to create the items for the view.
For large or dynamic datasets the model is usually provided by a C++ model object.
- The C++ model object must be a \l QListModelInterface subclass, a \l VisualModel,
+ The C++ model object must be a \l QAbstractItemModel subclass, a \l VisualModel,
or a simple list.
- Models can also be created directly in XML, using the \l ListModel element.
+ Models can also be created directly in QML, using the \l ListModel element.
*/
QVariant QFxListView::model() const
{
diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp
index c0d3ab2..a2ea8ee 100644
--- a/src/declarative/fx/qfxpathview.cpp
+++ b/src/declarative/fx/qfxpathview.cpp
@@ -99,7 +99,7 @@ private:
\brief The PathView element lays out model-provided items on a path.
\inherits Item
- The model is typically provided by a QAbstractListModel "C++ model object", but can also be created directly in XML.
+ The model is typically provided by a QAbstractListModel "C++ model object", but can also be created directly in QML.
The items are laid out along a path defined by a \l Path and may be flicked to scroll.
@@ -140,28 +140,7 @@ QFxPathView::~QFxPathView()
The model provides a set of data that is used to create the items for the view.
For large or dynamic datasets the model is usually provided by a C++ model object.
- However, models can also be created directly in XML, for example:
- \code
-<model>
- <ListModel>
- <Contact>
- <portrait>pics/john.png</portrait>
- <firstName>John</firstName>
- <lastName>Smith</lastName>
- </Contact>
- <Contact>
- <portrait>pics/bill.png</portrait>
- <firstName>Bill</firstName>
- <lastName>Jones</lastName>
- </Contact>
- <Contact>
- <portrait>pics/jane.png</portrait>
- <firstName>Jane</firstName>
- <lastName>Doe</lastName>
- </Contact>
- </ListModel>
-</model>
- \endcode
+ Models can also be created directly in XML, using the ListModel element.
*/
/*!
@@ -180,6 +159,10 @@ QVariant QFxPathView::model() const
void QFxPathView::setModel(const QVariant &model)
{
Q_D(QFxPathView);
+ if (d->model) {
+ disconnect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
+ disconnect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
+ }
if (QFxVisualItemModel *m = qvariant_cast<QFxVisualItemModel*>(model)) {
if (d->ownModel) {
delete d->model;
@@ -193,6 +176,12 @@ void QFxPathView::setModel(const QVariant &model)
}
d->model->setModel(model);
}
+ if (d->model) {
+ connect(d->model, SIGNAL(itemsInserted(int,int)), this, SLOT(itemsInserted(int,int)));
+ connect(d->model, SIGNAL(itemsRemoved(int,int)), this, SLOT(itemsRemoved(int,int)));
+ }
+ d->firstIndex = 0;
+ d->pathOffset = 0;
d->regenerate();
d->fixOffset();
}
@@ -425,6 +414,8 @@ QPointF QFxPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent)
void QFxPathView::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(QFxPathView);
+ if (!d->items.count())
+ return;
QPointF scenePoint = mapToScene(event->pos());
int idx = 0;
for (; idx < d->items.count(); ++idx) {
@@ -576,9 +567,6 @@ bool QFxPathView::mouseFilter(QGraphicsSceneMouseEvent *e)
void QFxPathViewPrivate::regenerate()
{
Q_Q(QFxPathView);
- if (!model || model->count() <= 0 || !model->delegate() || !path)
- return;
-
for (int i=0; i<items.count(); i++){
QFxItem *p = items[i];
q->attachedProperties.remove(p);
@@ -586,29 +574,23 @@ void QFxPathViewPrivate::regenerate()
}
items.clear();
- firstIndex = 0;
- pathOffset = 0;
+ if (!model || model->count() <= 0 || !model->delegate() || !path)
+ return;
- int numItems = (pathItems>=0 ? pathItems : model->count());
- qreal minDiff = 1e9;
- int minI = -1;
- for (int i=0; i<numItems; i++){
- QFxItem *item = model->item(i);
+ if (firstIndex >= model->count())
+ firstIndex = model->count()-1;
+ if (pathOffset >= model->count())
+ pathOffset = model->count()-1;
+
+ int numItems = pathItems >= 0 ? pathItems : model->count();
+ for (int i=0; i < numItems && i < model->count(); ++i){
+ QFxItem *item = model->item((i + firstIndex) % model->count());
if (!item)
return;
items.append(item);
item->setZ(i);
item->setParent(q);
- qreal percent = i * (100.0 / (numItems));
- percent /= 100.0;
- updateItem(items.last(), percent);
- qreal diff = qAbs(percent - snapPos);
- if (diff < minDiff){
- minDiff = diff;
- minI = i;
- }
}
- q->setCurrentIndex(minI);
q->refill();
}
@@ -639,10 +621,9 @@ void QFxPathView::refill()
positions << qAbs(percent/100.0);
}
- if (d->pathItems==-1){
- for (int i=0; i<positions.count(); i++){
+ if (d->pathItems==-1) {
+ for (int i=0; i<positions.count(); i++)
d->updateItem(d->items.at(i), positions[i]);
- }
return;
}
@@ -650,54 +631,110 @@ void QFxPathView::refill()
for (int i=0; i<d->items.count(); i++)
rotatedPositions << positions[(i + d->pathOffset + d->items.count()) % d->items.count()];
- int firstFind = -1;
- int i;
- for (i=0; i<d->items.count()-1; i++)
- {
+ int wrapIndex= -1;
+ for (int i=0; i<d->items.count()-1; i++) {
if (rotatedPositions[i] > rotatedPositions[i+1]){
- firstFind = i;
+ wrapIndex = i;
break;
}
}
- if (firstFind!=-1 ){
+ if (wrapIndex != -1 ){
//A wraparound has occured
- if (firstFind<(d->items.count()/2)){
- while(firstFind-- >= 0){
+ if (wrapIndex < d->items.count()/2){
+ while(wrapIndex-- >= 0){
QFxItem* p = d->items.takeFirst();
attachedProperties.remove(p);
d->model->release(p);
d->firstIndex++;
- d->firstIndex%=d->model->count();
+ d->firstIndex %= d->model->count();
int index = (d->firstIndex + d->items.count())%d->model->count();
d->items << d->model->item(index);
- d->items.last()->setZ(i);
+ d->items.last()->setZ(wrapIndex);
d->items.last()->setParent(this);
d->pathOffset++;
d->pathOffset=d->pathOffset % d->items.count();
}
- }else{
- while(firstFind++ < (d->items.count()-1)){
+ } else {
+ while(wrapIndex++ < d->items.count()-1){
QFxItem* p = d->items.takeLast();
attachedProperties.remove(p);
d->model->release(p);
d->firstIndex--;
- if (d->firstIndex<0)
+ if (d->firstIndex < 0)
d->firstIndex = d->model->count() - 1;
d->items.prepend(d->model->item(d->firstIndex));
d->items.first()->setZ(d->firstIndex);
d->items.first()->setParent(this);
d->pathOffset--;
- if (d->pathOffset<0)
+ if (d->pathOffset < 0)
d->pathOffset = d->items.count() - 1;
}
}
for (int i=0; i<d->items.count(); i++)
rotatedPositions[i] = positions[(i + d->pathOffset + d->items.count())
- % d->items.count()];
+ % d->items.count()];
}
- for (int i=0; i<d->items.count(); i++){
+ for (int i=0; i<d->items.count(); i++)
d->updateItem(d->items.at(i), rotatedPositions[i]);
+}
+
+void QFxPathView::itemsInserted(int modelIndex, int count)
+{
+ //XXX support animated insertion
+ Q_D(QFxPathView);
+ if (d->pathItems == -1 || d->items.count() < d->pathItems) {
+ for (int i = 0; i < count; ++i) {
+ QFxItem *item = d->model->item(modelIndex + i);
+ item->setZ(modelIndex + i);
+ item->setParent(this);
+ d->items.insert(modelIndex + i, item);
+ }
+ refill();
+ } else {
+ //XXX This is pretty heavy handed until we reference count items.
+ d->regenerate();
}
+
+ // make sure the current item is still at the snap position
+ int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count();
+ itemIndex += d->pathOffset;
+ itemIndex %= d->items.count();
+ qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100);
+
+ if (targetOffset < 0)
+ targetOffset = 100.0 + targetOffset;
+ if (targetOffset != d->_offset)
+ d->moveOffset.setValue(targetOffset);
+}
+
+void QFxPathView::itemsRemoved(int modelIndex, int count)
+{
+ //XXX support animated removal
+ Q_D(QFxPathView);
+ if (d->pathItems == -1) {
+ for (int i = 0; i < count; ++i) {
+ QFxItem* p = d->items.takeAt(modelIndex);
+ attachedProperties.remove(p);
+ d->model->release(p);
+ }
+ d->snapToCurrent();
+ refill();
+ } else {
+ d->regenerate();
+ }
+
+ // make sure the current item is still at the snap position
+ if (d->currentIndex >= d->model->count())
+ d->currentIndex = d->model->count() - 1;
+ int itemIndex = (d->currentIndex - d->firstIndex + d->model->count())%d->model->count();
+ itemIndex += d->pathOffset;
+ itemIndex %= d->items.count();
+ qreal targetOffset = fmod(100 + (d->snapPos*100) - 100.0 * itemIndex / d->items.count(), 100);
+
+ if (targetOffset < 0)
+ targetOffset = 100.0 + targetOffset;
+ if (targetOffset != d->_offset)
+ d->moveOffset.setValue(targetOffset);
}
void QFxPathView::ticked()
@@ -715,7 +752,7 @@ int QFxPathViewPrivate::calcCurrentIndex()
if (_offset < 0)
_offset += 100.0;
- if (pathItems == -1){
+ if (pathItems == -1) {
qreal delta = fmod(_offset - snapPos, 100.0);
if (delta < 0)
delta = 100.0 + delta;
@@ -723,7 +760,7 @@ int QFxPathViewPrivate::calcCurrentIndex()
if (ii < 0)
ii = 0;
current = ii;
- }else{
+ } else {
qreal bestDiff=1e9;
int bestI=-1;
for (int i=0; i<items.count(); i++){
@@ -778,11 +815,11 @@ void QFxPathViewPrivate::snapToCurrent()
if (!model || model->count() <= 0)
return;
- int itemIndex = (currentIndex - firstIndex + model->count())%model->count();
+ int itemIndex = (currentIndex - firstIndex + model->count()) % model->count();
//Rounds is the number of times round to make the current item visible
int rounds = itemIndex / items.count();
- int otherWayRounds = (model->count() - (itemIndex))/items.count() + 1;
+ int otherWayRounds = (model->count() - (itemIndex)) / items.count() + 1;
if (otherWayRounds < rounds)
rounds = -otherWayRounds;
@@ -792,7 +829,7 @@ void QFxPathViewPrivate::snapToCurrent()
if (targetOffset < 0)
targetOffset = 100.0 + targetOffset;
- if (targetOffset == _offset && rounds==0)
+ if (targetOffset == _offset && rounds == 0)
return;
moveReason = Other;
diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h
index 2cc0769..23f2f07 100644
--- a/src/declarative/fx/qfxpathview.h
+++ b/src/declarative/fx/qfxpathview.h
@@ -113,6 +113,8 @@ protected:
private Q_SLOTS:
void refill();
void ticked();
+ void itemsInserted(int index, int count);
+ void itemsRemoved(int index, int count);
protected:
QFxPathView(QFxPathViewPrivate &dd, QFxItem *parent);
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp
index 5cb31e1..f1aefb9 100644
--- a/src/declarative/fx/qfxtext.cpp
+++ b/src/declarative/fx/qfxtext.cpp
@@ -67,16 +67,12 @@ QML_DEFINE_TYPE(QFxText,Text);
It can display both plain and rich text. For example:
\code
- <Text text="Hello World!" font.family="Helvetica" font.size="24" color="red"/>
- <Text>
- <![CDATA[<b>Hello</b> <i>World!</i>]]]]><![CDATA[>
- </Text>
+ Text { text: "Hello World!"; font.family: "Helvetica"; font.size: 24; color: "red" }
+ Text { text: "<b>Hello</b> <i>World!</i>" }
\endcode
\image declarative-text.png
- Additional examples can be found in examples/poc/text.xml
-
If height and width are not explicitly set, Text will attempt to determine how
much room is needed and set it accordingly. Unless \c wrap is set, it will always
prefer width to height (all text will be placed on a single line).
@@ -99,26 +95,19 @@ QML_DEFINE_TYPE(QFxText,Text);
It can display both plain and rich text. For example:
\code
- <Text text="Hello World!" font.family="Helvetica" font.size="24" color="red"/>
- <Text>
- <![CDATA[<b>Hello</b> <i>World!</i>]]>
- </Text>
+ Text { text: "Hello World!"; font.family: "Helvetica"; font.size: 24; color: "red" }
+ Text { text: "<b>Hello</b> <i>World!</i>" }
\endcode
\image text.png
- Note that the 'styling' properties such as color and outline are ignored for rich text, styling
- of rich text should be done within the text itself.
-
- Additional examples can be found in examples/poc/text.xml
-
If height and width are not explicitly set, Text will attempt to determine how
much room is needed and set it accordingly. Unless \c wrap is set, it will always
prefer width to height (all text will be placed on a single line).
The \c elideMode can alternatively be used to fit a line of plain text to a set width.
- A QFxText object can be instantiated in Qml using the tag \c &lt;Text&gt;.
+ A QFxText object can be instantiated in Qml using the tag \c Text.
*/
QFxText::QFxText(QFxItem *parent)
: QFxItem(*(new QFxTextPrivate), parent)
@@ -143,9 +132,14 @@ QFxText::~QFxText()
}
/*!
- \qmlproperty font Text::font
+ \qmlproperty string Text::font.family
+ \qmlproperty bool Text::font.bold
+ \qmlproperty bool Text::font.italic
+ \qmlproperty real Text::font.size
- Set the Text's font attributes. \c font.size sets the font's point size.
+ Set the Text's font attributes.
+
+ \note \c font.size sets the font's point size (not pixel size).
*/
/*!
@@ -219,11 +213,11 @@ void QFxText::setColor(const QColor &color)
The text color.
\code
- <!-- green text using hexadecimal notation -->
- <Text color="#00FF00" .../>
+ //green text using hexadecimal notation
+ Text { color: "#00FF00"; ... }
- <!-- steelblue text using SVG color name-->
- <Text color="steelblue" .../>
+ //steelblue text using SVG color name
+ Text { color: "steelblue"; ... }
\endcode
*/
@@ -241,12 +235,12 @@ QColor QFxText::color() const
Supported text styles are \c Normal, \c Outline, \c Raised and \c Sunken.
\code
- <HorizontalLayout>
- <Text font.size="24" text="Normal" />
- <Text font.size="24" text="Raised" style="Raised" styleColor="#AAAAAA"/>
- <Text font.size="24" text="Outline" style="Outline" styleColor="red"/>
- <Text font.size="24" text="Sunken" style="Sunken" styleColor="#AAAAAA"/>
- </HorizontalLayout>
+ HorizontalLayout {
+ Text { font.size: 24; text: "Normal" }
+ Text { font.size: 24; text: "Raised"; style: "Raised"; styleColor: "#AAAAAA" }
+ Text { font.size: 24; text: "Outline"; style: "Outline"; styleColor: "red" }
+ Text { font.size: 24; text: "Sunken"; style: "Sunken"; styleColor: "#AAAAAA" }
+ }
\endcode
\image declarative-textstyle.png
diff --git a/src/declarative/fx/qfxwebview.cpp b/src/declarative/fx/qfxwebview.cpp
index 05730f9..fe694ea 100644
--- a/src/declarative/fx/qfxwebview.cpp
+++ b/src/declarative/fx/qfxwebview.cpp
@@ -221,7 +221,13 @@ public:
if the idealHeight is changed after the content is loaded.
\code
- <WebView url="http://www.nokia.com" smooth="true" scale="0.5" width="490" height="400"/>
+ WebView {
+ url: "http://www.nokia.com"
+ width: 490
+ height: 400
+ scale: 0.5
+ smooth: true
+ }
\endcode
\image webview.png
@@ -998,23 +1004,12 @@ QString QFxWebView::html() const
\qmlproperty string WebView::html
This property holds HTML text set directly
- The html property can be set as a string (using CDATA for large blocks),
- or as xhtml inline using the XML namespace http://www.w3.org/1999/xhtml:
+ The html property can be set as a string.
\code
- <WebView>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <p>This is valid xHTML.</p>
- </html>
- </WebView>
- \endcode
-
- \code
- <WebView>
- <html>&lt;CDATA[
- <p>This is just HTML.
- ]]&gt;html>
- </WebView>
+ WebView {
+ html: "<p>This is <b>HTML</b>."
+ }
\endcode
*/
void QFxWebView::setHtml(const QString &html, const QUrl &baseUrl)