summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanchors.cpp48
-rw-r--r--src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp7
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp8
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp290
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview_p.h11
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp38
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp98
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp28
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea.cpp6
-rw-r--r--src/declarative/graphicsitems/qdeclarativemousearea_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp7
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp24
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners_p_p.h16
-rw-r--r--src/declarative/graphicsitems/qdeclarativerepeater.cpp94
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp20
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit.cpp82
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextedit_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp61
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h1
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp110
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h5
24 files changed, 661 insertions, 305 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeanchors.cpp b/src/declarative/graphicsitems/qdeclarativeanchors.cpp
index aa53aba041..67969772c3 100644
--- a/src/declarative/graphicsitems/qdeclarativeanchors.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeanchors.cpp
@@ -53,6 +53,30 @@ QT_BEGIN_NAMESPACE
//TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)?
//TODO: support non-parent, non-sibling (need to find lowest common ancestor)
+static qreal hcenter(QGraphicsItem *i)
+{
+ QGraphicsItemPrivate *item = QGraphicsItemPrivate::get(i);
+
+ qreal width = item->width();
+ int iw = width;
+ if (iw % 2)
+ return (width + 1) / 2;
+ else
+ return width / 2;
+}
+
+static qreal vcenter(QGraphicsItem *i)
+{
+ QGraphicsItemPrivate *item = QGraphicsItemPrivate::get(i);
+
+ qreal height = item->height();
+ int ih = height;
+ if (ih % 2)
+ return (height + 1) / 2;
+ else
+ return height / 2;
+}
+
//### const item?
//local position
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
@@ -73,10 +97,10 @@ static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine
ret = item->y() + d->height();
break;
case QDeclarativeAnchorLine::HCenter:
- ret = item->x() + d->width()/2;
+ ret = item->x() + hcenter(item);
break;
case QDeclarativeAnchorLine::VCenter:
- ret = item->y() + d->height()/2;
+ ret = item->y() + vcenter(item);
break;
case QDeclarativeAnchorLine::Baseline:
if (d->isDeclarativeItem)
@@ -108,10 +132,10 @@ static qreal adjustedPosition(QGraphicsObject *item, QDeclarativeAnchorLine::Anc
ret = d->height();
break;
case QDeclarativeAnchorLine::HCenter:
- ret = d->width()/2;
+ ret = hcenter(item);
break;
case QDeclarativeAnchorLine::VCenter:
- ret = d->height()/2;
+ ret = vcenter(item);
break;
case QDeclarativeAnchorLine::Baseline:
if (d->isDeclarativeItem)
@@ -192,14 +216,14 @@ void QDeclarativeAnchorsPrivate::centerInChanged()
QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item);
if (centerIn == item->parentItem()) {
QGraphicsItemPrivate *parentPrivate = QGraphicsItemPrivate::get(item->parentItem());
- QPointF p((parentPrivate->width() - itemPrivate->width()) / 2. + hCenterOffset,
- (parentPrivate->height() - itemPrivate->height()) / 2. + vCenterOffset);
+ QPointF p(hcenter(item->parentItem()) - hcenter(item) + hCenterOffset,
+ vcenter(item->parentItem()) - vcenter(item) + vCenterOffset);
setItemPos(p);
} else if (centerIn->parentItem() == item->parentItem()) {
QGraphicsItemPrivate *centerPrivate = QGraphicsItemPrivate::get(centerIn);
- QPointF p(centerIn->x() + (centerPrivate->width() - itemPrivate->width()) / 2. + hCenterOffset,
- centerIn->y() + (centerPrivate->height() - itemPrivate->height()) / 2. + vCenterOffset);
+ QPointF p(centerIn->x() + hcenter(centerIn) - hcenter(item) + hCenterOffset,
+ centerIn->y() + vcenter(centerIn) - vcenter(item) + vCenterOffset);
setItemPos(p);
}
@@ -535,9 +559,9 @@ void QDeclarativeAnchorsPrivate::updateVerticalAnchors()
//Handle vCenter
if (vCenter.item == item->parentItem()) {
setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine)
- - itemPrivate->height()/2 + vCenterOffset);
+ - vcenter(item) + vCenterOffset);
} else if (vCenter.item->parentItem() == item->parentItem()) {
- setItemY(position(vCenter.item, vCenter.anchorLine) - itemPrivate->height()/2 + vCenterOffset);
+ setItemY(position(vCenter.item, vCenter.anchorLine) - vcenter(item) + vCenterOffset);
}
} else if (usedAnchors & QDeclarativeAnchors::BaselineAnchor) {
//Handle baseline
@@ -604,9 +628,9 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors()
} else if (usedAnchors & QDeclarativeAnchors::HCenterAnchor) {
//Handle hCenter
if (hCenter.item == item->parentItem()) {
- setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - itemPrivate->width()/2 + hCenterOffset);
+ setItemX(adjustedPosition(hCenter.item, hCenter.anchorLine) - hcenter(item) + hCenterOffset);
} else if (hCenter.item->parentItem() == item->parentItem()) {
- setItemX(position(hCenter.item, hCenter.anchorLine) - itemPrivate->width()/2 + hCenterOffset);
+ setItemX(position(hCenter.item, hCenter.anchorLine) - hcenter(item) + hCenterOffset);
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
index 261cc5cf40..d8527d3c11 100644
--- a/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeanimatedimage.cpp
@@ -63,9 +63,10 @@ QT_BEGIN_NAMESPACE
\inherits Image
\since 4.7
- This item provides for playing animations stored as images containing a series of frames,
- such as GIF files. The full list of supported formats can be determined with
- QMovie::supportedFormats().
+ The AnimatedImage element provides for playing animations stored as images containing a series of frames,
+ such as GIF files.
+
+ The full list of supported formats can be determined with QMovie::supportedFormats().
\table
\row
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
index 1f1e453c8f..cf458dab54 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
@@ -138,7 +138,7 @@ QDeclarativeBorderImage::~QDeclarativeBorderImage()
BorderImage can handle any image format supported by Qt, loaded from any URL scheme supported by Qt.
- It can also handle .sci files, which are a Qml-specific format. A .sci file uses a simple text-based format that specifies
+ It can also handle .sci files, which are a QML-specific format. A .sci file uses a simple text-based format that specifies
the borders, the image file and the tile rules.
The following .sci file sets the borders to 10 on each side for the image \c picture.png:
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index 10dc0f8a19..fdc1444341 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -351,6 +351,8 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd()
Flickable places its children on a surface that can be dragged and flicked.
\code
+ import Qt 4.7
+
Flickable {
width: 200; height: 200
contentWidth: image.width; contentHeight: image.height
@@ -1039,11 +1041,11 @@ QDeclarativeListProperty<QGraphicsObject> QDeclarativeFlickable::flickableChildr
The \c boundsBehavior can be one of:
\list
- \o \e Flickable.StopAtBounds - the contents can not be dragged beyond the boundary
+ \o Flickable.StopAtBounds - the contents can not be dragged beyond the boundary
of the flickable, and flicks will not overshoot.
- \o \e Flickable.DragOverBounds - the contents can be dragged beyond the boundary
+ \o Flickable.DragOverBounds - the contents can be dragged beyond the boundary
of the Flickable, but flicks will not overshoot.
- \o \e Flickable.DragAndOvershootBounds (default) - the contents can be dragged
+ \o Flickable.DragAndOvershootBounds (default) - the contents can be dragged
beyond the boundary of the Flickable, and can overshoot the
boundary when flicked.
\endlist
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index ffffc2f117..3792595d56 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -108,6 +108,7 @@ public:
, highlightComponent(0), highlight(0), trackedItem(0)
, moveReason(Other), buffer(0), highlightXAnimator(0), highlightYAnimator(0)
, highlightMoveDuration(150)
+ , footerComponent(0), footer(0), headerComponent(0), header(0)
, bufferMode(BufferBefore | BufferAfter), snapMode(QDeclarativeGridView::NoSnap)
, ownModel(false), wrap(false), autoHighlight(true)
, fixCurrentVisibility(false), lazyRelease(false), layoutScheduled(false)
@@ -128,6 +129,8 @@ public:
void createHighlight();
void updateHighlight();
void updateCurrent(int modelIndex);
+ void updateHeader();
+ void updateFooter();
void fixupPosition();
FxGridItem *visibleItem(int modelIndex) const {
@@ -230,6 +233,18 @@ public:
return visibleItems.count() ? visibleItems.first() : 0;
}
+ int lastVisibleIndex() const {
+ int lastIndex = -1;
+ for (int i = visibleItems.count()-1; i >= 0; --i) {
+ FxGridItem *gridItem = visibleItems.at(i);
+ if (gridItem->index != -1) {
+ lastIndex = gridItem->index;
+ break;
+ }
+ }
+ return lastIndex;
+ }
+
// Map a model index to visibleItems list index.
// These may differ if removed items are still present in the visible list,
// e.g. doing a removal animation
@@ -246,16 +261,37 @@ public:
return -1; // Not in visibleList
}
- qreal snapPosAt(qreal pos) {
+ qreal snapPosAt(qreal pos) const {
+ Q_Q(const QDeclarativeGridView);
qreal snapPos = 0;
if (!visibleItems.isEmpty()) {
pos += rowSize()/2;
snapPos = visibleItems.first()->rowPos() - visibleIndex / columns * rowSize();
snapPos = pos - fmodf(pos - snapPos, qreal(rowSize()));
+ qreal maxExtent = flow == QDeclarativeGridView::LeftToRight ? -q->maxYExtent() : -q->maxXExtent();
+ qreal minExtent = flow == QDeclarativeGridView::LeftToRight ? -q->minYExtent() : -q->minXExtent();
+ if (snapPos > maxExtent)
+ snapPos = maxExtent;
+ if (snapPos < minExtent)
+ snapPos = minExtent;
}
return snapPos;
}
+ FxGridItem *snapItemAt(qreal pos) {
+ for (int i = 0; i < visibleItems.count(); ++i) {
+ FxGridItem *item = visibleItems[i];
+ if (item->index == -1)
+ continue;
+ qreal itemTop = item->rowPos();
+ if (item->index == model->count()-1 || (itemTop+rowSize()/2 >= pos))
+ return item;
+ }
+ if (visibleItems.count() && visibleItems.first()->rowPos() <= pos)
+ return visibleItems.first();
+ return 0;
+ }
+
int snapIndex() {
int index = currentIndex;
for (int i = 0; i < visibleItems.count(); ++i) {
@@ -283,6 +319,9 @@ public:
scheduleLayout();
}
}
+ } else if ((header && header->item == item) || (footer && footer->item == item)) {
+ updateHeader();
+ updateFooter();
}
}
@@ -330,6 +369,10 @@ public:
QSmoothedAnimation *highlightXAnimator;
QSmoothedAnimation *highlightYAnimator;
int highlightMoveDuration;
+ QDeclarativeComponent *footerComponent;
+ FxGridItem *footer;
+ QDeclarativeComponent *headerComponent;
+ FxGridItem *header;
enum BufferMode { NoBuffer = 0x00, BufferBefore = 0x01, BufferAfter = 0x02 };
int bufferMode;
QDeclarativeGridView::SnapMode snapMode;
@@ -412,7 +455,6 @@ void QDeclarativeGridViewPrivate::refill(qreal from, qreal to, bool doBuffer)
Q_Q(QDeclarativeGridView);
if (!isValid() || !q->isComponentComplete())
return;
-
itemCount = model->count();
qreal bufferFrom = from - buffer;
qreal bufferTo = to + buffer;
@@ -522,6 +564,10 @@ void QDeclarativeGridViewPrivate::refill(qreal from, qreal to, bool doBuffer)
deferredRelease = true;
}
if (changed) {
+ if (header)
+ updateHeader();
+ if (footer)
+ updateFooter();
if (flow == QDeclarativeGridView::LeftToRight)
q->setContentHeight(endPosition() - startPosition());
else
@@ -557,7 +603,7 @@ void QDeclarativeGridViewPrivate::layout()
{
Q_Q(QDeclarativeGridView);
layoutScheduled = false;
- if (!isValid()) {
+ if (!isValid() && !visibleItems.count()) {
clear();
return;
}
@@ -579,6 +625,10 @@ void QDeclarativeGridViewPrivate::layout()
item->setPosition(colPos, rowPos);
}
}
+ if (header)
+ updateHeader();
+ if (footer)
+ updateFooter();
q->refill();
updateHighlight();
moveReason = Other;
@@ -742,6 +792,94 @@ void QDeclarativeGridViewPrivate::updateCurrent(int modelIndex)
releaseItem(oldCurrentItem);
}
+void QDeclarativeGridViewPrivate::updateFooter()
+{
+ Q_Q(QDeclarativeGridView);
+ if (!footer && footerComponent) {
+ QDeclarativeItem *item = 0;
+ QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
+ QObject *nobj = footerComponent->create(context);
+ if (nobj) {
+ QDeclarative_setParent_noEvent(context, nobj);
+ item = qobject_cast<QDeclarativeItem *>(nobj);
+ if (!item)
+ delete nobj;
+ } else {
+ delete context;
+ }
+ if (item) {
+ QDeclarative_setParent_noEvent(item, q->viewport());
+ item->setParentItem(q->viewport());
+ item->setZValue(1);
+ QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
+ itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
+ footer = new FxGridItem(item, q);
+ }
+ }
+ if (footer) {
+ if (visibleItems.count()) {
+ qreal endPos = endPosition();
+ if (lastVisibleIndex() == model->count()-1) {
+ footer->setPosition(0, endPos);
+ } else {
+ qreal visiblePos = position() + q->height();
+ if (endPos <= visiblePos || footer->endRowPos() < endPos)
+ footer->setPosition(0, endPos);
+ }
+ } else {
+ qreal endPos = 0;
+ if (header) {
+ endPos += flow == QDeclarativeGridView::LeftToRight
+ ? header->item->height()
+ : header->item->width();
+ }
+ footer->setPosition(0, endPos);
+ }
+ }
+}
+
+void QDeclarativeGridViewPrivate::updateHeader()
+{
+ Q_Q(QDeclarativeGridView);
+ if (!header && headerComponent) {
+ QDeclarativeItem *item = 0;
+ QDeclarativeContext *context = new QDeclarativeContext(qmlContext(q));
+ QObject *nobj = headerComponent->create(context);
+ if (nobj) {
+ QDeclarative_setParent_noEvent(context, nobj);
+ item = qobject_cast<QDeclarativeItem *>(nobj);
+ if (!item)
+ delete nobj;
+ } else {
+ delete context;
+ }
+ if (item) {
+ QDeclarative_setParent_noEvent(item, q->viewport());
+ item->setParentItem(q->viewport());
+ item->setZValue(1);
+ QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
+ itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
+ header = new FxGridItem(item, q);
+ }
+ }
+ if (header) {
+ if (visibleItems.count()) {
+ qreal startPos = startPosition();
+ qreal headerSize = flow == QDeclarativeGridView::LeftToRight
+ ? header->item->height()
+ : header->item->width();
+ if (visibleIndex == 0) {
+ header->setPosition(0, startPos - headerSize);
+ } else {
+ if (position() <= startPos || header->rowPos() > startPos - headerSize)
+ header->setPosition(0, startPos - headerSize);
+ }
+ } else {
+ header->setPosition(0, 0);
+ }
+ }
+}
+
void QDeclarativeGridViewPrivate::fixupPosition()
{
moveReason = Other;
@@ -753,7 +891,6 @@ void QDeclarativeGridViewPrivate::fixupPosition()
void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
{
- Q_Q(QDeclarativeGridView);
if ((flow == QDeclarativeGridView::TopToBottom && &data == &vData)
|| (flow == QDeclarativeGridView::LeftToRight && &data == &hData))
return;
@@ -761,7 +898,41 @@ void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
int oldDuration = fixupDuration;
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
- if (haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) {
+ if (snapMode != QDeclarativeGridView::NoSnap) {
+ FxGridItem *topItem = snapItemAt(position()+highlightRangeStart);
+ FxGridItem *bottomItem = snapItemAt(position()+highlightRangeEnd);
+ qreal pos;
+ if (topItem && bottomItem && haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) {
+ qreal topPos = qMin(topItem->rowPos() - highlightRangeStart, -maxExtent);
+ qreal bottomPos = qMax(bottomItem->rowPos() - highlightRangeEnd, -minExtent);
+ pos = qAbs(data.move + topPos) < qAbs(data.move + bottomPos) ? topPos : bottomPos;
+ } else if (topItem) {
+ pos = qMax(qMin(topItem->rowPos() - highlightRangeStart, -maxExtent), -minExtent);
+ } else if (bottomItem) {
+ pos = qMax(qMin(bottomItem->rowPos() - highlightRangeStart, -maxExtent), -minExtent);
+ } else {
+ fixupDuration = oldDuration;
+ return;
+ }
+ if (currentItem && haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) {
+ updateHighlight();
+ qreal currPos = currentItem->rowPos();
+ if (pos < currPos + rowSize() - highlightRangeEnd)
+ pos = currPos + rowSize() - highlightRangeEnd;
+ if (pos > currPos - highlightRangeStart)
+ pos = currPos - highlightRangeStart;
+ }
+
+ qreal dist = qAbs(data.move + pos);
+ if (dist > 0) {
+ timeline.reset(data.move);
+ if (fixupDuration)
+ timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ else
+ timeline.set(data.move, -pos);
+ vTime = timeline.time();
+ }
+ } else if (haveHighlightRange && highlightRange == QDeclarativeGridView::StrictlyEnforceRange) {
if (currentItem) {
updateHighlight();
qreal pos = currentItem->rowPos();
@@ -773,26 +944,10 @@ void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
timeline.reset(data.move);
if (viewPos != position()) {
- if (fixupDuration) {
+ if (fixupDuration)
timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- } else {
- data.move.setValue(-viewPos);
- q->viewportMoved();
- }
- }
- vTime = timeline.time();
- }
- } else if (snapMode != QDeclarativeGridView::NoSnap) {
- qreal pos = -snapPosAt(-(data.move.value() - highlightRangeStart)) + highlightRangeStart;
- pos = qMin(qMax(pos, maxExtent), minExtent);
- qreal dist = qAbs(data.move.value() - pos);
- if (dist > 0) {
- timeline.reset(data.move);
- if (fixupDuration) {
- timeline.move(data.move, pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- } else {
- data.move.setValue(pos);
- q->viewportMoved();
+ else
+ timeline.set(data.move, -viewPos);
}
vTime = timeline.time();
}
@@ -806,7 +961,6 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity)
{
Q_Q(QDeclarativeGridView);
-
moveReason = Mouse;
if ((!haveHighlightRange || highlightRange != QDeclarativeGridView::StrictlyEnforceRange)
&& snapMode == QDeclarativeGridView::NoSnap) {
@@ -851,9 +1005,10 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
qreal accel = deceleration;
qreal v2 = v * v;
qreal overshootDist = 0.0;
- if (maxDistance > 0.0 && v2 / (2.0f * maxDistance) < accel) {
+ if ((maxDistance > 0.0 && v2 / (2.0f * maxDistance) < accel) || snapMode == QDeclarativeGridView::SnapOneRow) {
// + rowSize()/4 to encourage moving at least one item in the flick direction
qreal dist = v2 / (accel * 2.0) + rowSize()/4;
+ dist = qMin(dist, maxDistance);
if (v > 0)
dist = -dist;
data.flickTarget = -snapPosAt(-(data.move.value() - highlightRangeStart) + dist) + highlightRangeStart;
@@ -958,11 +1113,13 @@ QDeclarativeGridView::~QDeclarativeGridView()
d->clear();
if (d->ownModel)
delete d->model;
+ delete d->header;
+ delete d->footer;
}
/*!
\qmlattachedproperty bool GridView::isCurrentItem
- This attched property is true if this delegate is the current item; otherwise false.
+ This attached property is true if this delegate is the current item; otherwise false.
It is attached to each instance of the delegate.
*/
@@ -1524,6 +1681,67 @@ void QDeclarativeGridView::setSnapMode(SnapMode mode)
}
}
+/*!
+ \qmlproperty Component GridView::footer
+ This property holds the component to use as the footer.
+
+ An instance of the footer component is created for each view. The
+ footer is positioned at the end of the view, after any items.
+
+ \sa header
+*/
+QDeclarativeComponent *QDeclarativeGridView::footer() const
+{
+ Q_D(const QDeclarativeGridView);
+ return d->footerComponent;
+}
+
+void QDeclarativeGridView::setFooter(QDeclarativeComponent *footer)
+{
+ Q_D(QDeclarativeGridView);
+ if (d->footerComponent != footer) {
+ if (d->footer) {
+ delete d->footer;
+ d->footer = 0;
+ }
+ d->footerComponent = footer;
+ d->updateFooter();
+ d->updateGrid();
+ emit footerChanged();
+ }
+}
+
+/*!
+ \qmlproperty Component GridView::header
+ This property holds the component to use as the header.
+
+ An instance of the header component is created for each view. The
+ header is positioned at the beginning of the view, before any items.
+
+ \sa footer
+*/
+QDeclarativeComponent *QDeclarativeGridView::header() const
+{
+ Q_D(const QDeclarativeGridView);
+ return d->headerComponent;
+}
+
+void QDeclarativeGridView::setHeader(QDeclarativeComponent *header)
+{
+ Q_D(QDeclarativeGridView);
+ if (d->headerComponent != header) {
+ if (d->header) {
+ delete d->header;
+ d->header = 0;
+ }
+ d->headerComponent = header;
+ d->updateHeader();
+ d->updateFooter();
+ d->updateGrid();
+ emit headerChanged();
+ }
+}
+
bool QDeclarativeGridView::event(QEvent *event)
{
Q_D(QDeclarativeGridView);
@@ -1590,6 +1808,8 @@ qreal QDeclarativeGridView::minYExtent() const
if (d->flow == QDeclarativeGridView::TopToBottom)
return QDeclarativeFlickable::minYExtent();
qreal extent = -d->startPosition();
+ if (d->header && d->visibleItems.count())
+ extent += d->header->item->height();
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent += d->highlightRangeStart;
extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd));
@@ -1603,13 +1823,17 @@ qreal QDeclarativeGridView::maxYExtent() const
if (d->flow == QDeclarativeGridView::TopToBottom)
return QDeclarativeFlickable::maxYExtent();
qreal extent;
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
+ if (!d->model || !d->model->count()) {
+ extent = 0;
+ } else if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart);
if (d->highlightRangeEnd != d->highlightRangeStart)
extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1));
} else {
extent = -(d->endPosition() - height());
}
+ if (d->footer)
+ extent -= d->footer->item->height();
const qreal minY = minYExtent();
if (extent > minY)
extent = minY;
@@ -1622,6 +1846,8 @@ qreal QDeclarativeGridView::minXExtent() const
if (d->flow == QDeclarativeGridView::LeftToRight)
return QDeclarativeFlickable::minXExtent();
qreal extent = -d->startPosition();
+ if (d->header && d->visibleItems.count())
+ extent += d->header->item->width();
if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent += d->highlightRangeStart;
extent = qMax(extent, -(d->rowPosAt(0) + d->rowSize() - d->highlightRangeEnd));
@@ -1635,13 +1861,17 @@ qreal QDeclarativeGridView::maxXExtent() const
if (d->flow == QDeclarativeGridView::LeftToRight)
return QDeclarativeFlickable::maxXExtent();
qreal extent;
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
+ if (!d->model || !d->model->count()) {
+ extent = 0;
+ } if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
extent = -(d->rowPosAt(d->model->count()-1) - d->highlightRangeStart);
if (d->highlightRangeEnd != d->highlightRangeStart)
extent = qMin(extent, -(d->endPosition() - d->highlightRangeEnd + 1));
} else {
- extent = -(d->endPosition() - height());
+ extent = -(d->endPosition() - width());
}
+ if (d->footer)
+ extent -= d->footer->item->width();
const qreal minX = minXExtent();
if (extent > minX)
extent = minX;
diff --git a/src/declarative/graphicsitems/qdeclarativegridview_p.h b/src/declarative/graphicsitems/qdeclarativegridview_p.h
index 2bf154c725..021aad91aa 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativegridview_p.h
@@ -80,6 +80,9 @@ class Q_DECLARATIVE_EXPORT QDeclarativeGridView : public QDeclarativeFlickable
Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged)
+ Q_PROPERTY(QDeclarativeComponent *header READ header WRITE setHeader NOTIFY headerChanged)
+ Q_PROPERTY(QDeclarativeComponent *footer READ footer WRITE setFooter NOTIFY footerChanged)
+
Q_ENUMS(HighlightRangeMode)
Q_ENUMS(SnapMode)
Q_ENUMS(Flow)
@@ -142,6 +145,12 @@ public:
SnapMode snapMode() const;
void setSnapMode(SnapMode mode);
+ QDeclarativeComponent *footer() const;
+ void setFooter(QDeclarativeComponent *);
+
+ QDeclarativeComponent *header() const;
+ void setHeader(QDeclarativeComponent *);
+
enum PositionMode { Beginning, Center, End, Visible, Contain };
Q_INVOKABLE void positionViewAtIndex(int index, int mode);
@@ -172,6 +181,8 @@ Q_SIGNALS:
void keyNavigationWrapsChanged();
void cacheBufferChanged();
void snapModeChanged();
+ void headerChanged();
+ void footerChanged();
protected:
virtual bool event(QEvent *event);
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index 94240c2f23..ec08517255 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -83,6 +83,8 @@ QT_BEGIN_NAMESPACE
that images which do not form part of the user interface have their
size bounded via the \l sourceSize property. This is especially important for content
that is loaded from external sources or provided by the user.
+
+ \sa {declarative/imageelements/image}{Image example}
*/
/*!
@@ -95,7 +97,7 @@ QT_BEGIN_NAMESPACE
Image { source: "pics/star.png" }
\endqml
- A QDeclarativeImage object can be instantiated in Qml using the tag \l Image.
+ A QDeclarativeImage object can be instantiated in QML using the tag \l Image.
*/
QDeclarativeImage::QDeclarativeImage(QDeclarativeItem *parent)
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 9949e6528d..18806e7f2b 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -86,8 +86,8 @@ QT_BEGIN_NAMESPACE
The Transform elements let you create and control advanced transformations that can be configured
independently using specialized properties.
- You can assign any number of Transform elements to an Item. Each Transform is applied in order,
- one at a time, to the Item it's assigned to.
+ You can assign any number of Transform elements to an \l Item. Each Transform is applied in order,
+ one at a time.
*/
/*!
@@ -134,9 +134,9 @@ QT_BEGIN_NAMESPACE
/*!
\qmlclass Scale QGraphicsScale
\since 4.7
- \brief The Scale object provides a way to scale an Item.
+ \brief The Scale element provides a way to scale an Item.
- The Scale object gives more control over scaling than using Item's scale property. Specifically,
+ The Scale element gives more control over scaling than using \l Item's \l{Item::scale}{scale} property. Specifically,
it allows a different scale for the x and y axes, and allows the scale to be relative to an
arbitrary point.
@@ -148,6 +148,8 @@ QT_BEGIN_NAMESPACE
transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}
}
\endqml
+
+ \sa Rotate, Translate
*/
/*!
@@ -175,7 +177,7 @@ QT_BEGIN_NAMESPACE
\since 4.7
\brief The Rotation object provides a way to rotate an Item.
- The Rotation object gives more control over rotation than using Item's rotation property.
+ The Rotation object gives more control over rotation than using \l Item's \l{Item::rotation}{rotation} property.
Specifically, it allows (z axis) rotation to be relative to an arbitrary point.
The following example rotates a Rectangle around its interior point 25, 25:
@@ -726,7 +728,7 @@ void QDeclarativeKeyNavigationAttached::keyReleased(QKeyEvent *event, bool post)
The signal properties have a \l KeyEvent parameter, named
\e event which contains details of the event. If a key is
handled \e event.accepted should be set to true to prevent the
- event from propagating up the item heirarchy.
+ event from propagating up the item hierarchy.
\code
Item {
@@ -1633,7 +1635,7 @@ void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *pro
QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
{
- QObjectList children = prop->object->children();
+ const QObjectList children = prop->object->children();
if (index < children.count())
return children.at(index);
else
@@ -2391,6 +2393,28 @@ void QDeclarativeItem::forceFocus()
}
}
+
+/*!
+ \qmlmethod Item::childAt(real x, real y)
+
+ Returns the visible child item at point (\a x, \a y), which is in this
+ item's coordinate system, or \c null if there is no such item.
+ */
+QDeclarativeItem *QDeclarativeItem::childAt(qreal x, qreal y) const
+{
+ const QList<QGraphicsItem *> children = childItems();
+ for (int i = children.count()-1; i >= 0; --i) {
+ if (QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i))) {
+ if (child->isVisible() && child->x() <= x
+ && child->x() + child->width() >= x
+ && child->y() <= y
+ && child->y() + child->height() >= y)
+ return child;
+ }
+ }
+ return 0;
+}
+
void QDeclarativeItemPrivate::focusChanged(bool flag)
{
Q_Q(QDeclarativeItem);
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.h b/src/declarative/graphicsitems/qdeclarativeitem.h
index 77e316b997..4f420f8952 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem.h
@@ -148,6 +148,7 @@ public:
Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const;
Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const;
Q_INVOKABLE void forceFocus();
+ Q_INVOKABLE QDeclarativeItem *childAt(qreal x, qreal y) const;
Q_SIGNALS:
void childrenChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index dbd19768cf..dcf18afe17 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -427,6 +427,10 @@ public:
scheduleLayout();
}
}
+ if ((header && header->item == item) || (footer && footer->item == item)) {
+ updateHeader();
+ updateFooter();
+ }
if (currentItem && currentItem->item == item)
updateHighlight();
if (trackedItem && trackedItem->item == item)
@@ -733,7 +737,7 @@ void QDeclarativeListViewPrivate::layout()
{
Q_Q(QDeclarativeListView);
layoutScheduled = false;
- if (!isValid()) {
+ if (!isValid() && !visibleItems.count()) {
clear();
setPosition(0);
return;
@@ -1045,6 +1049,8 @@ void QDeclarativeListViewPrivate::updateFooter()
QDeclarative_setParent_noEvent(item, q->viewport());
item->setParentItem(q->viewport());
item->setZValue(1);
+ QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
+ itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
footer = new FxListItem(item, q);
}
}
@@ -1083,6 +1089,8 @@ void QDeclarativeListViewPrivate::updateHeader()
QDeclarative_setParent_noEvent(item, q->viewport());
item->setParentItem(q->viewport());
item->setZValue(1);
+ QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
+ itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
header = new FxListItem(item, q);
if (visibleItems.isEmpty())
visiblePos = header->size();
@@ -1116,7 +1124,6 @@ void QDeclarativeListViewPrivate::fixupPosition()
void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal maxExtent)
{
- Q_Q(QDeclarativeListView);
if ((orient == QDeclarativeListView::Horizontal && &data == &vData)
|| (orient == QDeclarativeListView::Vertical && &data == &hData))
return;
@@ -1124,7 +1131,41 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
int oldDuration = fixupDuration;
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
- if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
+ if (snapMode != QDeclarativeListView::NoSnap) {
+ FxListItem *topItem = snapItemAt(position()+highlightRangeStart);
+ FxListItem *bottomItem = snapItemAt(position()+highlightRangeEnd);
+ qreal pos;
+ if (topItem && bottomItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
+ qreal topPos = qMin(topItem->position() - highlightRangeStart, -maxExtent);
+ qreal bottomPos = qMax(bottomItem->position() - highlightRangeEnd, -minExtent);
+ pos = qAbs(data.move + topPos) < qAbs(data.move + bottomPos) ? topPos : bottomPos;
+ } else if (topItem) {
+ pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent);
+ } else if (bottomItem) {
+ pos = qMax(qMin(bottomItem->position() - highlightRangeStart, -maxExtent), -minExtent);
+ } else {
+ fixupDuration = oldDuration;
+ return;
+ }
+ if (currentItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
+ updateHighlight();
+ qreal currPos = currentItem->position();
+ if (pos < currPos + currentItem->size() - highlightRangeEnd)
+ pos = currPos + currentItem->size() - highlightRangeEnd;
+ if (pos > currPos - highlightRangeStart)
+ pos = currPos - highlightRangeStart;
+ }
+
+ qreal dist = qAbs(data.move + pos);
+ if (dist > 0) {
+ timeline.reset(data.move);
+ if (fixupDuration)
+ timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ else
+ timeline.set(data.move, -pos);
+ vTime = timeline.time();
+ }
+ } else if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
if (currentItem) {
updateHighlight();
qreal pos = currentItem->position();
@@ -1136,30 +1177,13 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
timeline.reset(data.move);
if (viewPos != position()) {
- if (fixupDuration) {
+ if (fixupDuration)
timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- } else {
- data.move.setValue(-viewPos);
- q->viewportMoved();
- }
+ else
+ timeline.set(data.move, -viewPos);
}
vTime = timeline.time();
}
- } else if (snapMode != QDeclarativeListView::NoSnap) {
- if (FxListItem *item = snapItemAt(position())) {
- qreal pos = qMin(item->position() - highlightRangeStart, -maxExtent);
- qreal dist = qAbs(data.move + pos);
- if (dist > 0) {
- timeline.reset(data.move);
- if (fixupDuration) {
- timeline.move(data.move, -pos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- } else {
- data.move.setValue(-pos);
- q->viewportMoved();
- }
- vTime = timeline.time();
- }
- }
} else {
QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent);
}
@@ -1354,6 +1378,8 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
is not clipped by another item or the screen, it will be necessary
to set \e {clip: true} in order to have the out of view items clipped
nicely.
+
+ \sa ListModel, GridView
*/
QDeclarativeListView::QDeclarativeListView(QDeclarativeItem *parent)
@@ -2074,6 +2100,15 @@ void QDeclarativeListView::setSnapMode(SnapMode mode)
}
}
+/*!
+ \qmlproperty Component ListView::footer
+ This property holds the component to use as the footer.
+
+ An instance of the footer component is created for each view. The
+ footer is positioned at the end of the view, after any items.
+
+ \sa header
+*/
QDeclarativeComponent *QDeclarativeListView::footer() const
{
Q_D(const QDeclarativeListView);
@@ -2097,6 +2132,15 @@ void QDeclarativeListView::setFooter(QDeclarativeComponent *footer)
}
}
+/*!
+ \qmlproperty Component ListView::header
+ This property holds the component to use as the header.
+
+ An instance of the header component is created for each view. The
+ header is positioned at the beginning of the view, before any items.
+
+ \sa footer
+*/
QDeclarativeComponent *QDeclarativeListView::header() const
{
Q_D(const QDeclarativeListView);
@@ -2222,7 +2266,9 @@ qreal QDeclarativeListView::maxYExtent() const
if (d->orient == QDeclarativeListView::Horizontal)
return height();
if (d->maxExtentDirty) {
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
+ if (!d->model || !d->model->count()) {
+ d->maxExtent = 0;
+ } else if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
d->maxExtent = -(d->positionAt(d->model->count()-1) - d->highlightRangeStart);
if (d->highlightRangeEnd != d->highlightRangeStart)
d->maxExtent = qMin(d->maxExtent, -(d->endPosition() - d->highlightRangeEnd + 1));
@@ -2264,7 +2310,9 @@ qreal QDeclarativeListView::maxXExtent() const
if (d->orient == QDeclarativeListView::Vertical)
return width();
if (d->maxExtentDirty) {
- if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
+ if (!d->model || !d->model->count()) {
+ d->maxExtent = 0;
+ } else if (d->haveHighlightRange && d->highlightRange == StrictlyEnforceRange) {
d->maxExtent = -(d->positionAt(d->model->count()-1) - d->highlightRangeStart);
if (d->highlightRangeEnd != d->highlightRangeStart)
d->maxExtent = qMin(d->maxExtent, -(d->endPosition() - d->highlightRangeEnd + 1));
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 898c5a564e..25b11195dc 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -112,27 +112,35 @@ void QDeclarativeLoaderPrivate::initResize()
\inherits Item
\brief The Loader item allows dynamically loading an Item-based
- subtree from a QML URL or Component.
+ subtree from a URL or Component.
- Loader instantiates an item from a component. The component to
- instantiate may be specified directly by the \l sourceComponent
+ The Loader element instantiates an item from a component. The component to
+ be instantiated may be specified directly by the \l sourceComponent
property, or loaded from a URL via the \l source property.
- It is also an effective means of delaying the creation of a component
- until it is required:
+ Loader can be used to delay the creation of a component until it is required.
+ For example, this loads "Page1.qml" as a component into the \l Loader element
+ when the \l MouseArea is clicked:
+
\code
import Qt 4.7
- Loader { id: pageLoader }
+ Item {
+ width: 200; height: 200
- Rectangle {
MouseArea {
anchors.fill: parent
onClicked: pageLoader.source = "Page1.qml"
}
+
+ Loader { id: pageLoader }
}
\endcode
+ Note that Loader is like any other graphical Item and needs to be positioned
+ and sized accordingly to become visible. When a component is loaded, the
+ Loader is automatically resized to the size of the component.
+
If the Loader source is changed, any previous items instantiated
will be destroyed. Setting \l source to an empty string, or setting
sourceComponent to \e undefined
@@ -225,7 +233,7 @@ void QDeclarativeLoader::setSource(const QUrl &url)
/*!
\qmlproperty Component Loader::sourceComponent
- The sourceComponent property holds the \l{Component} to instantiate.
+ This property holds the \l{Component} to instantiate.
\qml
Item {
@@ -239,6 +247,8 @@ void QDeclarativeLoader::setSource(const QUrl &url)
}
\endqml
+ Note this value must hold a \l Component object; it cannot be a \l Item.
+
\sa source, progress
*/
@@ -401,7 +411,7 @@ void QDeclarativeLoader::componentComplete()
/*!
\qmlsignal Loader::onLoaded()
- This handler is called when the \l status becomes Loader.Ready, or on successful
+ This handler is called when the \l status becomes \c Loader.Ready, or on successful
initial load.
*/
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
index 6fca283b76..c4956dfc74 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp
+++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp
@@ -305,12 +305,12 @@ QDeclarativeMouseAreaPrivate::~QDeclarativeMouseAreaPrivate()
/*!
\internal
\class QDeclarativeMouseArea
- \brief The QDeclarativeMouseArea class provides a simple mouse handling abstraction for use within Qml.
+ \brief The QDeclarativeMouseArea class provides a simple mouse handling abstraction for use within QML.
All QDeclarativeItem derived classes can do mouse handling but the QDeclarativeMouseArea class exposes mouse
handling data as properties and tracks flicking and dragging of the mouse.
- A QDeclarativeMouseArea object can be instantiated in Qml using the tag \l MouseArea.
+ A QDeclarativeMouseArea object can be instantiated in QML using the tag \l MouseArea.
*/
QDeclarativeMouseArea::QDeclarativeMouseArea(QDeclarativeItem *parent)
: QDeclarativeItem(*(new QDeclarativeMouseAreaPrivate), parent)
@@ -410,7 +410,7 @@ void QDeclarativeMouseArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
setHovered(true);
d->startScene = event->scenePos();
// we should only start timer if pressAndHold is connected to.
- if (d->isConnected("pressAndHold(QDeclarativeMouseEvent*)"))
+ if (d->isPressAndHoldConnected())
d->pressAndHoldTimer.start(PressAndHoldDelay, this);
setKeepMouseGrab(false);
event->setAccepted(setPressed(true));
diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
index 4e909ffcee..3d7bd1e8f1 100644
--- a/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativemousearea_p_p.h
@@ -88,9 +88,9 @@ public:
lastModifiers = event->modifiers();
}
- bool isConnected(const char *signal) {
+ bool isPressAndHoldConnected() {
Q_Q(QDeclarativeMouseArea);
- int idx = QObjectPrivate::get(q)->signalIndex(signal);
+ static int idx = QObjectPrivate::get(q)->signalIndex("pressAndHold(QDeclarativeMouseEvent*)");
return QObjectPrivate::get(q)->isSignalConnected(idx);
}
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index f58b054b73..0c2d249f7c 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -358,6 +358,13 @@ QDeclarativePathView::~QDeclarativePathView()
}
/*!
+ \qmlattachedproperty PathView PathView::view
+ This attached property holds the view that manages this delegate instance.
+
+ It is attached to each instance of the delegate.
+*/
+
+/*!
\qmlattachedproperty bool PathView::onPath
This attached property holds whether the item is currently on the path.
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index 20cc46b035..ad61bab064 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -219,6 +219,7 @@ void QDeclarativeBasePositioner::prePositioning()
QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii));
if (!child)
continue;
+ QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child));
PositionedItem *item = 0;
PositionedItem posItem(child);
int wIdx = oldItems.find(posItem);
@@ -227,11 +228,13 @@ void QDeclarativeBasePositioner::prePositioning()
positionedItems.append(posItem);
item = &positionedItems[positionedItems.count()-1];
item->isNew = true;
- if (child->opacity() <= 0.0 || !child->isVisible())
+ if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden)
item->isVisible = false;
} else {
item = &oldItems[wIdx];
- if (child->opacity() <= 0.0 || !child->isVisible()) {
+ // Items are only omitted from positioning if they are explicitly hidden
+ // i.e. their positioning is not affected if an ancestor is hidden.
+ if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden) {
item->isVisible = false;
} else if (!item->isVisible) {
item->isVisible = true;
@@ -299,6 +302,12 @@ void QDeclarativeBasePositioner::finishApplyTransitions()
d->moveActions.clear();
}
+static inline bool isInvisible(QDeclarativeItem *child)
+{
+ QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child));
+ return child->opacity() == 0.0 || childPrivate->explicitlyHidden || !child->width() || !child->height();
+}
+
/*!
\qmlclass Column QDeclarativeColumn
\since 4.7
@@ -349,6 +358,7 @@ Column {
positioner may exhibit strange behaviour. If you need to perform any of these
actions, consider positioning the items without the use of a Column.
+ \sa Row, {declarative/positioners}{Positioners example}
*/
/*!
\qmlproperty Transition Column::add
@@ -416,11 +426,6 @@ QDeclarativeColumn::QDeclarativeColumn(QDeclarativeItem *parent)
{
}
-static inline bool isInvisible(QDeclarativeItem *child)
-{
- return child->opacity() == 0.0 || !child->isVisible() || !child->width() || !child->height();
-}
-
void QDeclarativeColumn::doPositioning(QSizeF *contentSize)
{
int voffset = 0;
@@ -496,6 +501,8 @@ Row {
width of a child depend on the position of a child, then the
positioner may exhibit strange behaviour. If you need to perform any of these
actions, consider positioning the items without the use of a Row.
+
+ \sa Column, {declarative/positioners}{Positioners example}
*/
/*!
\qmlproperty Transition Row::add
@@ -649,6 +656,8 @@ Grid {
width or height of a child depend on the position of a child, then the
positioner may exhibit strange behaviour. If you need to perform any of these
actions, consider positioning the items without the use of a Grid.
+
+ \sa Flow, {declarative/positioners}{Positioners example}
*/
/*!
\qmlproperty Transition Grid::add
@@ -904,6 +913,7 @@ void QDeclarativeGrid::reportConflictingAnchors()
positioner may exhibit strange behaviour. If you need to perform any of these
actions, consider positioning the items without the use of a Flow.
+ \sa Grid, {declarative/positioners}{Positioners example}
*/
/*!
\qmlproperty Transition Flow::add
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h b/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h
index 04f0181edb..822079b45e 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepositioners_p_p.h
@@ -100,18 +100,23 @@ public:
bool doingPositioning : 1;
bool anchorConflict : 1;
- virtual void itemSiblingOrderChanged(QDeclarativeItem* other)
+ void schedulePositioning()
{
Q_Q(QDeclarativeBasePositioner);
- Q_UNUSED(other);
if(!queuedPositioning){
- //Delay is due to many children often being reordered at once
- //And we only want to reposition them all once
QTimer::singleShot(0,q,SLOT(prePositioning()));
queuedPositioning = true;
}
}
+ virtual void itemSiblingOrderChanged(QDeclarativeItem* other)
+ {
+ Q_UNUSED(other);
+ //Delay is due to many children often being reordered at once
+ //And we only want to reposition them all once
+ schedulePositioning();
+ }
+
void itemGeometryChanged(QDeclarativeItem *, const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_Q(QDeclarativeBasePositioner);
@@ -120,8 +125,7 @@ public:
}
virtual void itemVisibilityChanged(QDeclarativeItem *)
{
- Q_Q(QDeclarativeBasePositioner);
- q->prePositioning();
+ schedulePositioning();
}
virtual void itemOpacityChanged(QDeclarativeItem *)
{
diff --git a/src/declarative/graphicsitems/qdeclarativerepeater.cpp b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
index 691cfa24bf..995e22ac1b 100644
--- a/src/declarative/graphicsitems/qdeclarativerepeater.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerepeater.cpp
@@ -65,55 +65,75 @@ QDeclarativeRepeaterPrivate::~QDeclarativeRepeaterPrivate()
\since 4.7
\inherits Item
- \brief The Repeater item allows you to repeat an Item-based component using a model.
+ \brief The Repeater element allows you to repeat an Item-based component using a model.
- The Repeater item is used to create a large number of
- similar items. For each entry in the model, an item is instantiated
- in a context seeded with data from the model. If the repeater will
- be instantiating a large number of instances, it may be more efficient to
- use one of Qt Declarative's \l {xmlViews}{view items}.
+ The Repeater element is used to create a large number of
+ similar items. Like other view elements, a Repeater has a \l model and a \l delegate:
+ for each entry in the model, the delegate is instantiated
+ in a context seeded with data from the model. A Repeater item is usually
+ enclosed in a positioner element such as \l Row or \l Column to visually
+ position the multiple delegate items created by the Repeater.
- The model may be either an object list, a string list, a number or a Qt model.
- In each case, the data element and the index is exposed to each instantiated
- component.
-
- The index is always exposed as an accessible \c index property.
- In the case of an object or string list, the data element (of type string
- or object) is available as the \c modelData property. In the case of a Qt model,
- all roles are available as named properties just like in the view classes.
+ The following Repeater creates three instances of a \l Rectangle item within
+ a \l Row:
+
+ \snippet doc/src/snippets/declarative/repeater.qml import
+ \codeline
+ \snippet doc/src/snippets/declarative/repeater.qml simple
+
+ \image repeater-simple.png
+
+ The \l model of a Repeater can be specified as a model object, a number, a string list
+ or an object list. If a model object is used, the
+ \l delegate can access the model roles as named properties, just as for view elements like
+ ListView and GridView.
- The following example shows how to use the \c index property inside the instantiated
- items:
+ The \l delegate can also access two additional properties:
- \snippet doc/src/snippets/declarative/repeater-index.qml 0
- \image repeater-index.png
+ \list
+ \o \c index - the index of the delegate's item
+ \o \c modelData - the data element for the delegate, which is useful where the \l model is a string or object list
+ \endlist
- The repeater could also use the \c modelData property to reference the data for a
+ Here is a Repeater that uses the \c index property inside the instantiated items:
+
+ \table
+ \row
+ \o \snippet doc/src/snippets/declarative/repeater.qml index
+ \o \image repeater-index.png
+ \endtable
+
+ Here is another Repeater that uses the \c modelData property to reference the data for a
particular index:
- \snippet doc/src/snippets/declarative/repeater-modeldata.qml 0
- \image repeater-modeldata.png
+ \table
+ \row
+ \o \snippet doc/src/snippets/declarative/repeater.qml modeldata
+ \o \image repeater-modeldata.png
+ \endtable
Items instantiated by the Repeater are inserted, in order, as
children of the Repeater's parent. The insertion starts immediately after
- the repeater's position in its parent stacking list. This is to allow
- you to use a Repeater inside a layout. The following QML example shows how
- the instantiated items would visually appear stacked between the red and
- blue rectangles.
-
- \snippet doc/src/snippets/declarative/repeater.qml 0
+ the repeater's position in its parent stacking list. This allows
+ a Repeater to be used inside a layout. For example, the following Repeater's
+ items are stacked between a red rectangle and a blue rectangle:
+
+ \snippet doc/src/snippets/declarative/repeater.qml layout
\image repeater.png
- The repeater instance continues to own all items it instantiates, even
- if they are otherwise manipulated. It is illegal to manually remove an item
- created by the Repeater.
+ A Repeater item owns all items it instantiates. Removing or dynamically destroying
+ an item created by a Repeater results in unpredictable behavior.
- \note Repeater is Item-based, and cannot be used to repeat non-Item-derived objects.
+ Note that if a repeater is
+ required to instantiate a large number of items, it may be more efficient to
+ use other view elements such as ListView.
+
+ \note Repeater is \l {Item}-based, and can only repeat \l {Item}-derived objects.
For example, it cannot be used to repeat QtObjects.
\badcode
Item {
- //XXX illegal. Can't repeat QtObject as it doesn't derive from Item.
+ //XXX does not work! Can't repeat QtObject as it doesn't derive from Item.
Repeater {
model: 10
QtObject {}
@@ -149,7 +169,15 @@ QDeclarativeRepeater::~QDeclarativeRepeater()
The model providing data for the repeater.
- The model may be either an object list, a string list, a number or a Qt model.
+ This property can be set to any of the following:
+
+ \list
+ \o A number that indicates the number of delegates to be created
+ \o A model (e.g. a ListModel item, or a QAbstractItemModel subclass)
+ \o A string list
+ \o An object list
+ \endlist
+
In each case, the data element and the index is exposed to each instantiated
component. The index is always exposed as an accessible \c index property.
In the case of an object or string list, the data element (of type string
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index f4722c3513..c2e0d672bc 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -119,8 +119,6 @@ QSet<QUrl> QTextDocumentWithImageResources::errors;
A Text item can display both plain and rich text. For example:
\qml
- import Qt 4.7
-
Text { text: "Hello World!"; font.family: "Helvetica"; font.pointSize: 24; color: "red" }
Text { text: "<b>Hello</b> <i>World!</i>" }
\endqml
@@ -128,10 +126,10 @@ QSet<QUrl> QTextDocumentWithImageResources::errors;
\image declarative-text.png
If height and width are not explicitly set, Text will attempt to determine how
- much room is needed and set it accordingly. Unless \c wrapMode is set, it will always
+ much room is needed and set it accordingly. Unless \l wrapMode is set, it will always
prefer width to height (all text will be placed on a single line).
- The \c elide property can alternatively be used to fit a single line of
+ The \l elide property can alternatively be used to fit a single line of
plain text to a set width.
Note that the \l{Supported HTML Subset} is limited. Also, if the text contains
@@ -163,7 +161,7 @@ QSet<QUrl> QTextDocumentWithImageResources::errors;
The \c elide property can alternatively be used to fit a line of plain text to a set width.
- A QDeclarativeText object can be instantiated in Qml using the tag \c Text.
+ A QDeclarativeText object can be instantiated in QML using the tag \c Text.
*/
QDeclarativeText::QDeclarativeText(QDeclarativeItem *parent)
: QDeclarativeItem(*(new QDeclarativeTextPrivate), parent)
@@ -507,13 +505,11 @@ void QDeclarativeText::setVAlign(VAlignment align)
wrap if an explicit width has been set. wrapMode can be one of:
\list
- \o Text.NoWrap - no wrapping will be performed. If the text contains insufficient newlines, then implicitWidth will exceed a set width.
- \o Text.WordWrap - wrapping is done on word boundaries only. If a word is too long, implicitWidth will exceed a set width.
+ \o Text.NoWrap (default) - no wrapping will be performed. If the text contains insufficient newlines, then \l paintedWidth will exceed a set width.
+ \o Text.WordWrap - wrapping is done on word boundaries only. If a word is too long, \l paintedWidth will exceed a set width.
\o Text.WrapAnywhere - wrapping is done at any point on a line, even if it occurs in the middle of a word.
\o Text.Wrap - if possible, wrapping occurs at a word boundary; otherwise it will occur at the appropriate point on the line, even in the middle of a word.
\endlist
-
- The default is Text.NoWrap.
*/
QDeclarativeText::WrapMode QDeclarativeText::wrapMode() const
{
@@ -543,13 +539,13 @@ void QDeclarativeText::setWrapMode(WrapMode mode)
Supported text formats are:
\list
- \o Text.AutoText
+ \o Text.AutoText (default)
\o Text.PlainText
\o Text.RichText
\o Text.StyledText
\endlist
- The default is Text.AutoText. If the text format is Text.AutoText the text element
+ If the text format is \c Text.AutoText the text element
will automatically determine whether the text should be treated as
rich text. This determination is made using Qt::mightBeRichText().
@@ -1171,7 +1167,7 @@ void QDeclarativeText::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
/*!
- \qmlsignal Text::linkActivated(link)
+ \qmlsignal Text::onLinkActivated(link)
This handler is called when the user clicks on a link embedded in the text.
*/
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
index 94973f2833..3b4f2a709c 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp
@@ -62,25 +62,28 @@ QT_BEGIN_NAMESPACE
/*!
\qmlclass TextEdit QDeclarativeTextEdit
\since 4.7
- \brief The TextEdit item allows you to add editable formatted text to a scene.
+ \brief The TextEdit item displays multiple lines of editable formatted text.
\inherits Item
+ The TextEdit item displays a block of editable, formatted text.
+
It can display both plain and rich text. For example:
\qml
TextEdit {
- id: edit
+ width: 240
text: "<b>Hello</b> <i>World!</i>"
- focus: true
font.family: "Helvetica"
font.pointSize: 20
color: "blue"
- width: 240
+ focus: true
}
\endqml
\image declarative-textedit.gif
+ Setting \l {Item::focus}{focus} to \c true enables the TextEdit item to receive keyboard focus.
+
Note that the TextEdit does not implement scrolling, following the cursor, or other behaviors specific
to a look-and-feel. For example, to add flickable scrolling that follows the cursor:
@@ -96,7 +99,7 @@ TextEdit {
You can translate between cursor positions (characters from the start of the document) and pixel
points using positionAt() and positionToRectangle().
- \sa Text
+ \sa Text, TextInput
*/
/*!
@@ -110,7 +113,7 @@ TextEdit {
\image declarative-textedit.png
- A QDeclarativeTextEdit object can be instantiated in Qml using the tag \c &lt;TextEdit&gt;.
+ A QDeclarativeTextEdit object can be instantiated in QML using the tag \c &lt;TextEdit&gt;.
*/
/*!
@@ -206,7 +209,7 @@ QString QDeclarativeTextEdit::text() const
Sets the font size in pixels.
Using this function makes the font device dependent.
- Use \c pointSize to set the size of the font in a device independent manner.
+ Use \l pointSize to set the size of the font in a device independent manner.
*/
/*!
@@ -453,12 +456,22 @@ void QDeclarativeTextEdit::setSelectedTextColor(const QColor &color)
\qmlproperty enumeration TextEdit::horizontalAlignment
\qmlproperty enumeration TextEdit::verticalAlignment
- Sets the horizontal and vertical alignment of the text within the TextEdit items
+ Sets the horizontal and vertical alignment of the text within the TextEdit item's
width and height. By default, the text is top-left aligned.
- The valid values for \c horizontalAlignment are \c TextEdit.AlignLeft, \c TextEdit.AlignRight and
- \c TextEdit.AlignHCenter. The valid values for \c verticalAlignment are \c TextEdit.AlignTop, \c TextEdit.AlignBottom
- and \c TextEdit.AlignVCenter.
+ Valid values for \c horizontalAlignment are:
+ \list
+ \o TextEdit.AlignLeft (default)
+ \o TextEdit.AlignRight
+ \o TextEdit.AlignHCenter
+ \endlist
+
+ Valid values for \c verticalAlignment are:
+ \list
+ \o TextEdit.AlignTop (default)
+ \o TextEdit.AlignBottom
+ \c TextEdit.AlignVCenter
+ \endlist
*/
QDeclarativeTextEdit::HAlignment QDeclarativeTextEdit::hAlign() const
{
@@ -529,8 +542,8 @@ void QDeclarativeTextEdit::setWrapMode(WrapMode mode)
/*!
\qmlproperty real TextEdit::paintedWidth
- Returns the width of the text, including width past the width
- which is covered due to insufficient wrapping if WrapMode is set.
+ Returns the width of the text, including the width past the width
+ which is covered due to insufficient wrapping if \l wrapMode is set.
*/
qreal QDeclarativeTextEdit::paintedWidth() const
{
@@ -540,8 +553,8 @@ qreal QDeclarativeTextEdit::paintedWidth() const
/*!
\qmlproperty real TextEdit::paintedHeight
- Returns the height of the text, including height past the height
- which is covered due to there being more text than fits in the set height.
+ Returns the height of the text, including the height past the height
+ that is covered if the text does not fit within the set height.
*/
qreal QDeclarativeTextEdit::paintedHeight() const
{
@@ -567,10 +580,10 @@ QRectF QDeclarativeTextEdit::positionToRectangle(int pos) const
/*!
\qmlmethod int TextEdit::positionAt(x,y)
- Returns the text position closest to pixel position (\a x,\a y).
+ Returns the text position closest to pixel position (\a x, \a y).
Position 0 is before the first character, position 1 is after the first character
- but before the second, and so on until position text.length, which is after all characters.
+ but before the second, and so on until position \l {text}.length, which is after all characters.
*/
int QDeclarativeTextEdit::positionAt(int x, int y) const
{
@@ -1082,7 +1095,7 @@ void QDeclarativeTextEdit::copy()
/*!
\qmlmethod TextEdit::paste()
- Relaces the currently selected text by the contents of the system clipboard.
+ Replaces the currently selected text by the contents of the system clipboard.
*/
void QDeclarativeTextEdit::paste()
{
@@ -1391,11 +1404,11 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption()
your application.
By default the opening of input panels follows the platform style. On Symbian^1 and
- Symbian^3 -based devices the panels are opened by clicking TextEdit and need to be
- manually closed by the user. On other platforms the panels are automatically opened
- when TextEdit element gains focus and closed when the focus is lost.
+ Symbian^3 -based devices the panels are opened by clicking TextEdit. On other platforms
+ the panels are automatically opened when TextEdit element gains focus. Input panels are
+ always closed if no editor owns focus.
- . You can disable the automatic behavior by setting the property \c focusOnPress to false
+ You can disable the automatic behavior by setting the property \c focusOnPress to false
and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
the behavior you want.
@@ -1415,9 +1428,9 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption()
textEdit.openSoftwareInputPanel();
} else {
textEdit.focus = false;
- textEdit.closeSoftwareInputPanel();
}
}
+ onPressAndHold: textEdit.closeSoftwareInputPanel();
}
}
\endcode
@@ -1442,11 +1455,11 @@ void QDeclarativeTextEdit::openSoftwareInputPanel()
your application.
By default the opening of input panels follows the platform style. On Symbian^1 and
- Symbian^3 -based devices the panels are opened by clicking TextEdit and need to be
- manually closed by the user. On other platforms the panels are automatically opened
- when TextEdit element gains focus and closed when the focus is lost.
+ Symbian^3 -based devices the panels are opened by clicking TextEdit. On other platforms
+ the panels are automatically opened when TextEdit element gains focus. Input panels are
+ always closed if no editor owns focus.
- . You can disable the automatic behavior by setting the property \c focusOnPress to false
+ You can disable the automatic behavior by setting the property \c focusOnPress to false
and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
the behavior you want.
@@ -1466,9 +1479,9 @@ void QDeclarativeTextEdit::openSoftwareInputPanel()
textEdit.openSoftwareInputPanel();
} else {
textEdit.focus = false;
- textEdit.closeSoftwareInputPanel();
}
}
+ onPressAndHold: textEdit.closeSoftwareInputPanel();
}
}
\endcode
@@ -1489,22 +1502,11 @@ void QDeclarativeTextEdit::focusInEvent(QFocusEvent *event)
{
Q_D(const QDeclarativeTextEdit);
if (d->showInputPanelOnFocus) {
- if (d->focusOnPress && !isReadOnly() && event->reason() != Qt::ActiveWindowFocusReason) {
+ if (d->focusOnPress && !isReadOnly()) {
openSoftwareInputPanel();
}
}
QDeclarativePaintedItem::focusInEvent(event);
}
-void QDeclarativeTextEdit::focusOutEvent(QFocusEvent *event)
-{
- Q_D(const QDeclarativeTextEdit);
- if (d->showInputPanelOnFocus) {
- if (d->focusOnPress && !isReadOnly()) {
- closeSoftwareInputPanel();
- }
- }
- QDeclarativePaintedItem::focusOutEvent(event);
-}
-
QT_END_NAMESPACE
diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
index 0ecb2f3c3e..d08f607ae1 100644
--- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h
@@ -247,7 +247,6 @@ protected:
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);
void focusInEvent(QFocusEvent *event);
- void focusOutEvent(QFocusEvent *event);
// mouse filter?
void mousePressEvent(QGraphicsSceneMouseEvent *event);
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 8d320f4b8a..633c01e65c 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -56,17 +56,20 @@ QT_BEGIN_NAMESPACE
/*!
\qmlclass TextInput QDeclarativeTextInput
\since 4.7
- \brief The TextInput item allows you to add an editable line of text to a scene.
+ \brief The TextInput item displays an editable line of text.
\inherits Item
- TextInput can only display a single line of text, and can only display
- plain text. However it can provide addition input constraints on the text.
+ The TextInput element displays a single line of editable plain text.
- Input constraints include setting a QValidator, an input mask, or a
- maximum input length.
+ TextInput is used to accept a line of text input. Input constraints
+ can be placed on a TextInput item (for example, through a \l validator or \l inputMask),
+ and setting \l echoMode to an appropriate value enables TextInput to be used for
+ a password input field.
On Mac OS X, the Up/Down key bindings for Home/End are explicitly disabled.
If you want such bindings (on any platform), you will need to construct them in QML.
+
+ \sa TextEdit, Text
*/
QDeclarativeTextInput::QDeclarativeTextInput(QDeclarativeItem* parent)
: QDeclarativePaintedItem(*(new QDeclarativeTextInputPrivate), parent)
@@ -249,7 +252,12 @@ QColor QDeclarativeTextInput::color() const
void QDeclarativeTextInput::setColor(const QColor &c)
{
Q_D(QDeclarativeTextInput);
- d->color = c;
+ if (c != d->color) {
+ d->color = c;
+ clearCache();
+ update();
+ emit colorChanged(c);
+ }
}
@@ -553,7 +561,7 @@ void QDeclarativeTextInput::setAutoScroll(bool b)
/*!
\qmlclass IntValidator QIntValidator
- This element provides a validator for integer values
+ This element provides a validator for integer values.
*/
/*!
\qmlproperty int IntValidator::top
@@ -596,10 +604,14 @@ void QDeclarativeTextInput::setAutoScroll(bool b)
\qmlproperty enumeration DoubleValidator::notation
This property holds the notation of how a string can describe a number.
- The values for this property are DoubleValidator.StandardNotation or DoubleValidator.ScientificNotation.
- If this property is set to DoubleValidator.ScientificNotation, the written number may have an exponent part(i.e. 1.5E-2).
+ The possible values for this property are:
+
+ \list
+ \o DoubleValidator.StandardNotation
+ \o DoubleValidator.ScientificNotation (default)
+ \endlist
- By default, this property is set to DoubleValidator.ScientificNotation.
+ If this property is set to DoubleValidator.ScientificNotation, the written number may have an exponent part (e.g. 1.5E-2).
*/
/*!
@@ -1234,9 +1246,9 @@ void QDeclarativeTextInput::moveCursorSelection(int position)
your application.
By default the opening of input panels follows the platform style. On Symbian^1 and
- Symbian^3 -based devices the panels are opened by clicking TextInput and need to be
- manually closed by the user. On other platforms the panels are automatically opened
- when TextInput element gains focus and closed when the focus is lost.
+ Symbian^3 -based devices the panels are opened by clicking TextInput. On other platforms
+ the panels are automatically opened when TextInput element gains focus. Input panels are
+ always closed if no editor owns focus.
. You can disable the automatic behavior by setting the property \c focusOnPress to false
and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
@@ -1258,9 +1270,9 @@ void QDeclarativeTextInput::moveCursorSelection(int position)
textInput.openSoftwareInputPanel();
} else {
textInput.focus = false;
- textInput.closeSoftwareInputPanel();
}
}
+ onPressAndHold: textInput.closeSoftwareInputPanel();
}
}
\endqml
@@ -1285,9 +1297,9 @@ void QDeclarativeTextInput::openSoftwareInputPanel()
your application.
By default the opening of input panels follows the platform style. On Symbian^1 and
- Symbian^3 -based devices the panels are opened by clicking TextInput and need to be
- manually closed by the user. On other platforms the panels are automatically opened
- when TextInput element gains focus and closed when the focus is lost.
+ Symbian^3 -based devices the panels are opened by clicking TextInput. On other platforms
+ the panels are automatically opened when TextInput element gains focus. Input panels are
+ always closed if no editor owns focus.
. You can disable the automatic behavior by setting the property \c focusOnPress to false
and use functions openSoftwareInputPanel() and closeSoftwareInputPanel() to implement
@@ -1309,9 +1321,9 @@ void QDeclarativeTextInput::openSoftwareInputPanel()
textInput.openSoftwareInputPanel();
} else {
textInput.focus = false;
- textInput.closeSoftwareInputPanel();
}
}
+ onPressAndHold: textInput.closeSoftwareInputPanel();
}
}
\endqml
@@ -1333,24 +1345,13 @@ void QDeclarativeTextInput::focusInEvent(QFocusEvent *event)
{
Q_D(const QDeclarativeTextInput);
if (d->showInputPanelOnFocus) {
- if (d->focusOnPress && !isReadOnly() && event->reason() != Qt::ActiveWindowFocusReason) {
+ if (d->focusOnPress && !isReadOnly()) {
openSoftwareInputPanel();
}
}
QDeclarativePaintedItem::focusInEvent(event);
}
-void QDeclarativeTextInput::focusOutEvent(QFocusEvent *event)
-{
- Q_D(const QDeclarativeTextInput);
- if (d->showInputPanelOnFocus) {
- if (d->focusOnPress && !isReadOnly()) {
- closeSoftwareInputPanel();
- }
- }
- QDeclarativePaintedItem::focusOutEvent(event);
-}
-
void QDeclarativeTextInputPrivate::init()
{
Q_Q(QDeclarativeTextInput);
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index e34634a42a..c539bd3424 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -224,7 +224,6 @@ protected:
void keyPressEvent(QKeyEvent* ev);
bool event(QEvent *e);
void focusInEvent(QFocusEvent *event);
- void focusOutEvent(QFocusEvent *event);
public Q_SLOTS:
void selectAll();
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index 2a88a80ce0..5092349eed 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -113,16 +113,18 @@ public:
\since 4.7
\brief The VisualItemModel allows items to be provided to a view.
- The children of the VisualItemModel are provided in a model which
- can be used in a view. Note that no delegate should be
- provided to a view since the VisualItemModel contains the
- visual delegate (items).
+ A VisualItemModel contains the visual items to be used in a view.
+ When a VisualItemModel is used in a view, the view does not require
+ a delegate since the VisualItemModel already contains the visual
+ delegate (items).
An item can determine its index within the
- model via the \c VisualItemModel.index attached property.
+ model via the \l{VisualItemModel::index}{index} attached property.
The example below places three colored rectangles in a ListView.
\code
+ import Qt 4.7
+
Rectangle {
VisualItemModel {
id: itemModel
@@ -139,12 +141,21 @@ public:
\endcode
\image visualitemmodel.png
+
+ \sa {declarative/modelviews/visualitemmodel}{VisualItemModel example}
*/
QDeclarativeVisualItemModel::QDeclarativeVisualItemModel(QObject *parent)
: QDeclarativeVisualModel(*(new QDeclarativeVisualItemModelPrivate), parent)
{
}
+/*!
+ \qmlattachedproperty int VisualItemModel::index
+ This attached property holds the index of this delegate's item within the model.
+
+ It is attached to each instance of the delegate.
+*/
+
QDeclarativeListProperty<QDeclarativeItem> QDeclarativeVisualItemModel::children()
{
Q_D(QDeclarativeVisualItemModel);
@@ -607,30 +618,15 @@ QDeclarativeVisualDataModelData *QDeclarativeVisualDataModelPrivate::data(QObjec
A VisualDataModel encapsulates a model and the delegate that will
be instantiated for items in the model.
- It is usually not necessary to create a VisualDataModel directly,
- since the QML views will create one internally.
+ It is usually not necessary to create VisualDataModel elements.
+ However, it can be useful for manipulating and accessing the \l modelIndex
+ when a QAbstractItemModel subclass is used as the
+ model. Also, VisualDataModel is used together with \l Package to
+ provide delegates to multiple views.
The example below illustrates using a VisualDataModel with a ListView.
- \code
- VisualDataModel {
- id: visualModel
- model: myModel
- delegate: Component {
- Rectangle {
- height: 25
- width: 100
- Text { text: "Name:" + name}
- }
- }
- }
- ListView {
- width: 100
- height: 100
- anchors.fill: parent
- model: visualModel
- }
- \endcode
+ \snippet doc/src/snippets/declarative/visualdatamodel.qml 0
*/
QDeclarativeVisualDataModel::QDeclarativeVisualDataModel()
@@ -805,56 +801,22 @@ void QDeclarativeVisualDataModel::setDelegate(QDeclarativeComponent *delegate)
/*!
\qmlproperty QModelIndex VisualDataModel::rootIndex
- QAbstractItemModel provides a heirachical tree of data, whereas
+ QAbstractItemModel provides a hierarchical tree of data, whereas
QML only operates on list data. \c rootIndex allows the children of
any node in a QAbstractItemModel to be provided by this model.
This property only affects models of type QAbstractItemModel.
- \code
- // main.cpp
-
- int main(int argc, char ** argv)
- {
- QApplication app(argc, argv);
-
- QDeclarativeView view;
-
- QDirModel model;
- view.rootContext()->setContextProperty("myModel", &model);
-
- view.setSource(QUrl("qrc:view.qml"));
- view.show();
-
- return app.exec();
- }
-
- #include "main.moc"
- \endcode
-
- \code
- // view.qml
- import Qt 4.7
+ For example, here is a simple interactive file system browser.
+ When a directory name is clicked, the view's \c rootIndex is set to the
+ QModelIndex node of the clicked directory, thus updating the view to show
+ the new directory's contents.
- ListView {
- id: view
- width: 200
- height: 200
- model: VisualDataModel {
- model: myModel
- delegate: Component {
- Rectangle {
- height: 25; width: 200
- Text { text: filePath }
- MouseArea {
- anchors.fill: parent;
- onClicked: if (hasModelChildren) view.model.rootIndex = view.model.modelIndex(index)
- }
- }
- }
- }
- }
- \endcode
+ \c main.cpp:
+ \snippet doc/src/snippets/declarative/visualdatamodel_rootindex/main.cpp 0
+
+ \c view.qml:
+ \snippet doc/src/snippets/declarative/visualdatamodel_rootindex/view.qml 0
\sa modelIndex(), parentModelIndex()
*/
@@ -886,7 +848,7 @@ void QDeclarativeVisualDataModel::setRootIndex(const QVariant &root)
/*!
\qmlmethod QModelIndex VisualDataModel::modelIndex(int index)
- QAbstractItemModel provides a heirachical tree of data, whereas
+ QAbstractItemModel provides a hierarchical tree of data, whereas
QML only operates on list data. This function assists in using
tree models in QML.
@@ -906,7 +868,7 @@ QVariant QDeclarativeVisualDataModel::modelIndex(int idx) const
/*!
\qmlmethod QModelIndex VisualDataModel::parentModelIndex()
- QAbstractItemModel provides a heirachical tree of data, whereas
+ QAbstractItemModel provides a hierarchical tree of data, whereas
QML only operates on list data. This function assists in using
tree models in QML.
@@ -1000,10 +962,10 @@ QDeclarativeVisualDataModel::ReleaseFlags QDeclarativeVisualDataModel::release(Q
The \a parts property selects a VisualDataModel which creates
delegates from the part named. This is used in conjunction with
- the Package element.
+ the \l Package element.
For example, the code below selects a model which creates
- delegates named \e list from a Package:
+ delegates named \e list from a \l Package:
\code
VisualDataModel {
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h
index 0bdbbcf142..079c9e6a92 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel_p.h
@@ -54,11 +54,6 @@ Q_DECLARE_METATYPE(QModelIndex)
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-/*****************************************************************************
- *****************************************************************************
- XXX Experimental
- *****************************************************************************
-*****************************************************************************/
class QDeclarativeItem;
class QDeclarativeComponent;