summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp20
-rw-r--r--src/declarative/graphicsitems/qdeclarativeevents.cpp30
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp53
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimage.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp72
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem_p.h2
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp28
-rw-r--r--src/declarative/graphicsitems/qdeclarativerectangle.cpp16
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp11
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp2
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextlayout.cpp8
11 files changed, 153 insertions, 91 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
index 649c8fb..c0a7d72 100644
--- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp
@@ -509,7 +509,7 @@ void QDeclarativeBorderImage::doUpdate()
void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QDeclarativeBorderImage);
- if (d->pix.isNull())
+ if (d->pix.isNull() || d->width() <= 0.0 || d->height() <= 0.0)
return;
bool oldAA = p->testRenderHint(QPainter::Antialiasing);
@@ -518,7 +518,23 @@ void QDeclarativeBorderImage::paint(QPainter *p, const QStyleOptionGraphicsItem
p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
const QDeclarativeScaleGrid *border = d->getScaleGrid();
- QMargins margins(border->left(), border->top(), border->right(), border->bottom());
+ int left = border->left();
+ int right = border->right();
+ qreal borderWidth = left + right;
+ if (borderWidth > 0.0 && d->width() < borderWidth) {
+ qreal diff = borderWidth - d->width() - 1;
+ left -= qRound(diff * qreal(left) / borderWidth);
+ right -= qRound(diff * qreal(right) / borderWidth);
+ }
+ int top = border->top();
+ int bottom = border->bottom();
+ qreal borderHeight = top + bottom;
+ if (borderHeight > 0.0 && d->height() < borderHeight) {
+ qreal diff = borderHeight - d->height() - 1;
+ top -= qRound(diff * qreal(top) / borderHeight);
+ bottom -= qRound(diff * qreal(bottom) / borderHeight);
+ }
+ QMargins margins(left, top, right, bottom);
QTileRules rules((Qt::TileRule)d->horizontalTileMode, (Qt::TileRule)d->verticalTileMode);
qDrawBorderPixmap(p, QRect(0, 0, (int)d->width(), (int)d->height()), margins, d->pix, d->pix.rect(), margins, rules);
if (d->smooth) {
diff --git a/src/declarative/graphicsitems/qdeclarativeevents.cpp b/src/declarative/graphicsitems/qdeclarativeevents.cpp
index 61fd562..4b5e777 100644
--- a/src/declarative/graphicsitems/qdeclarativeevents.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeevents.cpp
@@ -108,6 +108,34 @@ Item {
so that ancestor items do not also respond to the same event.
*/
+/*!
+ \qmlproperty int KeyEvent::modifiers
+
+ This property holds the keyboard modifier flags that existed immediately
+ before the event occurred.
+
+ It contains a bitwise combination of:
+ \list
+ \o Qt.NoModifier - No modifier key is pressed.
+ \o Qt.ShiftModifier - A Shift key on the keyboard is pressed.
+ \o Qt.ControlModifier - A Ctrl key on the keyboard is pressed.
+ \o Qt.AltModifier - An Alt key on the keyboard is pressed.
+ \o Qt.MetaModifier - A Meta key on the keyboard is pressed.
+ \o Qt.KeypadModifier - A keypad button is pressed.
+ \endlist
+
+ For example, to react to a Shift key + Enter key combination:
+ \qml
+ Item {
+ focus: true
+ Keys.onPressed: {
+ if ((event.key == Qt.Key_Enter) && (event.modifiers & Qt.ShiftModifier))
+ doSomething();
+ }
+ }
+ \endqml
+*/
+
/*!
\qmlclass MouseEvent QDeclarativeMouseEvent
@@ -199,7 +227,7 @@ Item {
\qml
MouseArea {
onClicked: {
- if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier)
+ if ((mouse.button == Qt.LeftButton) && (mouse.modifiers & Qt.ShiftModifier))
doSomething();
}
}
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 6f38f63..1615b0f 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -219,12 +219,8 @@ public:
}
} else {
qreal pos = (modelIndex / columns) * rowSize();
- if (header) {
- qreal headerSize = flow == QDeclarativeGridView::LeftToRight
- ? header->item->height()
- : header->item->width();
- pos += headerSize;
- }
+ if (header)
+ pos += headerSize();
return pos;
}
return 0;
@@ -291,11 +287,9 @@ public:
if (item->index == -1)
continue;
qreal itemTop = item->rowPos();
- if (item->index == model->count()-1 || (itemTop+rowSize()/2 >= pos))
+ if (itemTop+rowSize()/2 >= pos && itemTop - rowSize()/2 <= pos)
return item;
}
- if (visibleItems.count() && visibleItems.first()->rowPos() <= pos)
- return visibleItems.first();
return 0;
}
@@ -315,6 +309,16 @@ public:
return index;
}
+ qreal headerSize() const {
+ if (!header)
+ return 0.0;
+
+ return flow == QDeclarativeGridView::LeftToRight
+ ? header->item->height()
+ : header->item->width();
+ }
+
+
virtual void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
Q_Q(const QDeclarativeGridView);
QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry);
@@ -878,14 +882,11 @@ void QDeclarativeGridViewPrivate::updateHeader()
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);
+ header->setPosition(0, startPos - headerSize());
} else {
- if (position() <= startPos || header->rowPos() > startPos - headerSize)
- header->setPosition(0, startPos - headerSize);
+ if (position() <= startPos || header->rowPos() > startPos - headerSize())
+ header->setPosition(0, startPos - headerSize());
}
} else {
header->setPosition(0, 0);
@@ -920,10 +921,14 @@ void QDeclarativeGridViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
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);
+ if (topItem->index == 0 && header && position()+highlightRangeStart < header->rowPos()+headerSize()/2)
+ pos = header->rowPos() - highlightRangeStart;
+ else
+ pos = qMax(qMin(topItem->rowPos() - highlightRangeStart, -maxExtent), -minExtent);
} else if (bottomItem) {
pos = qMax(qMin(bottomItem->rowPos() - highlightRangeStart, -maxExtent), -minExtent);
} else {
+ QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent);
fixupDuration = oldDuration;
return;
}
@@ -1764,8 +1769,10 @@ void QDeclarativeGridView::setFooter(QDeclarativeComponent *footer)
d->footer = 0;
}
d->footerComponent = footer;
- d->updateFooter();
- d->updateGrid();
+ if (isComponentComplete()) {
+ d->updateFooter();
+ d->updateGrid();
+ }
emit footerChanged();
}
}
@@ -1794,9 +1801,11 @@ void QDeclarativeGridView::setHeader(QDeclarativeComponent *header)
d->header = 0;
}
d->headerComponent = header;
- d->updateHeader();
- d->updateFooter();
- d->updateGrid();
+ if (isComponentComplete()) {
+ d->updateHeader();
+ d->updateFooter();
+ d->updateGrid();
+ }
emit headerChanged();
}
}
@@ -2221,6 +2230,8 @@ void QDeclarativeGridView::componentComplete()
{
Q_D(QDeclarativeGridView);
QDeclarativeFlickable::componentComplete();
+ d->updateHeader();
+ d->updateFooter();
d->updateGrid();
if (d->isValid()) {
refill();
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp
index 3b08a9b..aa74716 100644
--- a/src/declarative/graphicsitems/qdeclarativeimage.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp
@@ -461,7 +461,7 @@ QRectF QDeclarativeImage::boundingRect() const
void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QDeclarativeImage);
- if (d->pix.isNull())
+ if (d->pix.pixmap().isNull() )
return;
bool oldAA = p->testRenderHint(QPainter::Antialiasing);
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index e0df751..9d6fe12 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -421,58 +421,28 @@ void QDeclarativeItemKeyFilter::componentComplete()
\since 4.7
\brief The KeyNavigation attached property supports key navigation by arrow keys.
- It is common in key-based UIs to use arrow keys to navigate
- between focused items. The KeyNavigation property provides a
- convenient way of specifying which item will gain focus
- when an arrow key is pressed. The following example provides
- key navigation for a 2x2 grid of items.
-
- \code
- Grid {
- columns: 2
- width: 100; height: 100
- Rectangle {
- id: item1
- focus: true
- width: 50; height: 50
- color: focus ? "red" : "lightgray"
- KeyNavigation.right: item2
- KeyNavigation.down: item3
- }
- Rectangle {
- id: item2
- width: 50; height: 50
- color: focus ? "red" : "lightgray"
- KeyNavigation.left: item1
- KeyNavigation.down: item4
- }
- Rectangle {
- id: item3
- width: 50; height: 50
- color: focus ? "red" : "lightgray"
- KeyNavigation.right: item4
- KeyNavigation.up: item1
- }
- Rectangle {
- id: item4
- width: 50; height: 50
- color: focus ? "red" : "lightgray"
- KeyNavigation.left: item3
- KeyNavigation.up: item2
- }
- }
- \endcode
+ Key-based user interfaces commonly allow the use of arrow keys to navigate between
+ focusable items. The KeyNavigation attached property enables this behavior by providing a
+ convenient way to specify the item that should gain focus when an arrow or tab key is pressed.
+
+ The following example provides key navigation for a 2x2 grid of items:
- By default KeyNavigation receives key events after the item it is attached to.
- If the item accepts an arrow key event, the KeyNavigation
- attached property will not receive an event for that key. Setting the
- \l priority property to KeyNavigation.BeforeItem allows handling
- of the key events before normal item processing.
+ \snippet doc/src/snippets/declarative/keynavigation.qml 0
- If an item has been set for a direction and the KeyNavigation
- attached property receives the corresponding
- key press and release events, the events will be accepted by
- KeyNavigation and will not propagate any further.
+ The top-left item initially receives focus by setting \l {Item::}{focus} to
+ \c true. When an arrow key is pressed, the focus will move to the
+ appropriate item, as defined by the value that has been set for
+ the KeyNavigation \l left, \l right, \l up or \l down properties.
+
+ Note that if a KeyNavigation attached property receives the key press and release
+ events for a requested arrow or tab key, the event is accepted and does not
+ propagate any further.
+
+ By default, KeyNavigation receives key events after the item to which it is attached.
+ If the item accepts the key event, the KeyNavigation attached property will not
+ receive an event for that key. Setting the \l priority property to
+ \c KeyNavigation.BeforeItem allows the event to be used for key navigation
+ before the item, rather than after.
\sa {Keys}{Keys attached property}
*/
@@ -599,7 +569,7 @@ void QDeclarativeKeyNavigationAttached::setBacktab(QDeclarativeItem *i)
\list
\o KeyNavigation.BeforeItem - process the key events before normal
- item key processing. If the event is accepted it will not
+ item key processing. If the event is used for key navigation, it will be accepted and will not
be passed on to the item.
\o KeyNavigation.AfterItem (default) - process the key events after normal item key
handling. If the item accepts the key event it will not be
diff --git a/src/declarative/graphicsitems/qdeclarativeitem_p.h b/src/declarative/graphicsitems/qdeclarativeitem_p.h
index f85fa27..d8635b9 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeitem_p.h
@@ -259,7 +259,7 @@ public:
QDeclarativeStateGroup *_states();
QDeclarativeStateGroup *_stateGroup;
- QDeclarativeItem::TransformOrigin origin:4;
+ QDeclarativeItem::TransformOrigin origin:5;
bool widthValid:1;
bool heightValid:1;
bool componentComplete:1;
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 450b6af..845da79 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -402,6 +402,8 @@ public:
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
Q_Q(QDeclarativeListView);
QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry);
+ if (!q->isComponentComplete())
+ return;
if (item != contentItem && (!highlight || item != highlight->item)) {
if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height())
|| (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) {
@@ -1123,8 +1125,6 @@ void QDeclarativeListViewPrivate::updateHeader()
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
header = new FxListItem(item, q);
- if (visibleItems.isEmpty())
- visiblePos = header->size();
}
}
if (header) {
@@ -1137,6 +1137,8 @@ void QDeclarativeListViewPrivate::updateHeader()
header->setPosition(startPos - header->size());
}
} else {
+ if (itemCount == 0)
+ visiblePos = header->size();
header->setPosition(0);
}
}
@@ -1185,10 +1187,14 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
FxListItem *bottomItem = snapItemAt(position()+highlightRangeEnd);
qreal pos;
if (topItem) {
- pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent);
+ if (topItem->index == 0 && header && position()+highlightRangeStart < header->position()+header->size()/2)
+ pos = header->position() - highlightRangeStart;
+ else
+ pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent);
} else if (bottomItem) {
pos = qMax(qMin(bottomItem->position() - highlightRangeStart, -maxExtent), -minExtent);
} else {
+ QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent);
fixupDuration = oldDuration;
return;
}
@@ -2211,8 +2217,10 @@ void QDeclarativeListView::setFooter(QDeclarativeComponent *footer)
d->footerComponent = footer;
d->minExtentDirty = true;
d->maxExtentDirty = true;
- d->updateFooter();
- d->updateViewport();
+ if (isComponentComplete()) {
+ d->updateFooter();
+ d->updateViewport();
+ }
emit footerChanged();
}
}
@@ -2243,9 +2251,11 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header)
d->headerComponent = header;
d->minExtentDirty = true;
d->maxExtentDirty = true;
- d->updateHeader();
- d->updateFooter();
- d->updateViewport();
+ if (isComponentComplete()) {
+ d->updateHeader();
+ d->updateFooter();
+ d->updateViewport();
+ }
emit headerChanged();
}
}
@@ -2655,6 +2665,8 @@ void QDeclarativeListView::componentComplete()
Q_D(QDeclarativeListView);
QDeclarativeFlickable::componentComplete();
updateSections();
+ d->updateHeader();
+ d->updateFooter();
if (d->isValid()) {
refill();
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
diff --git a/src/declarative/graphicsitems/qdeclarativerectangle.cpp b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
index 7686dde..99b36a8 100644
--- a/src/declarative/graphicsitems/qdeclarativerectangle.cpp
+++ b/src/declarative/graphicsitems/qdeclarativerectangle.cpp
@@ -420,6 +420,10 @@ void QDeclarativeRectangle::generateRoundedRect()
p.drawRoundedRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)), d->radius, d->radius);
else
p.drawRoundedRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw), d->radius, d->radius);
+
+ // end painting before inserting pixmap
+ // to pixmap cache to avoid a deep copy
+ p.end();
QPixmapCache::insert(key, d->rectImage);
}
}
@@ -454,6 +458,10 @@ void QDeclarativeRectangle::generateBorderedRect()
p.drawRect(QRectF(qreal(pw)/2+1, qreal(pw)/2+1, d->rectImage.width()-(pw+1), d->rectImage.height()-(pw+1)));
else
p.drawRect(QRectF(qreal(pw)/2, qreal(pw)/2, d->rectImage.width()-pw, d->rectImage.height()-pw));
+
+ // end painting before inserting pixmap
+ // to pixmap cache to avoid a deep copy
+ p.end();
QPixmapCache::insert(key, d->rectImage);
}
}
@@ -462,6 +470,8 @@ void QDeclarativeRectangle::generateBorderedRect()
void QDeclarativeRectangle::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
{
Q_D(QDeclarativeRectangle);
+ if (width() <= 0 || height() <= 0)
+ return;
if (d->radius > 0 || (d->pen && d->pen->isValid())
|| (d->gradient && d->gradient->gradient()) ) {
drawRect(*p);
@@ -531,6 +541,12 @@ void QDeclarativeRectangle::drawRect(QPainter &p)
Q_ASSERT(d->rectImage.width() == 2*xOffset + 1);
Q_ASSERT(d->rectImage.height() == 2*yOffset + 1);
+ // check whether we've eliminated the center completely
+ if (2*xOffset > width()+pw)
+ xOffset = (width()+pw)/2;
+ if (2*yOffset > height()+pw)
+ yOffset = (height()+pw)/2;
+
QMargins margins(xOffset, yOffset, xOffset, yOffset);
QTileRules rules(Qt::StretchTile, Qt::StretchTile);
//NOTE: even though our item may have qreal-based width and height, qDrawBorderPixmap only supports QRects
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index 82c444e..303b21c 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -436,12 +436,13 @@ void QDeclarativeTextPrivate::invalidateImageCache()
{
Q_Q(QDeclarativeText);
- if (imageCacheDirty)
- return;
-
- imageCacheDirty = true;
- imageCache = QPixmap();
+ if(cacheAllTextAsImage || style != QDeclarativeText::Normal){//If actually using the image cache
+ if (imageCacheDirty)
+ return;
+ imageCacheDirty = true;
+ imageCache = QPixmap();
+ }
if (q->isComponentComplete())
q->update();
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index 0deacf8..f8421a3 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -771,7 +771,7 @@ void QDeclarativeTextInput::setEchoMode(QDeclarativeTextInput::EchoMode echo)
imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
setInputMethodHints(imHints);
d->control->setEchoMode((uint)echo);
- update();
+ q_textChanged();
emit echoModeChanged(echoMode());
}
diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp
index e8da367..14a1109 100644
--- a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp
@@ -361,10 +361,18 @@ void QDeclarativeTextLayout::draw(QPainter *painter, const QPointF &p)
d->position = p;
}
+ QPen oldPen = priv->state->pen;
+ QColor currentColor = oldPen.color();
for (int ii = 0; ii < itemCount; ++ii) {
QStaticTextItem &item = d->items[ii];
+ if (item.color.isValid() && currentColor != item.color) {
+ painter->setPen(item.color);
+ currentColor = item.color;
+ }
priv->extended->drawStaticTextItem(&item);
}
+ if (currentColor != oldPen.color())
+ painter->setPen(oldPen);
}
QT_END_NAMESPACE