From 875c4af96f094dad9158d77e926049dbf9a75475 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 14 May 2009 13:38:20 +1000 Subject: GridView shall not crash when given a broken delegate. --- src/declarative/fx/qfxgridview.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 5156d06..e745b24 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -409,7 +409,8 @@ void QFxGridViewPrivate::refill(qreal from, qreal to) FxGridItem *item = 0; while (modelIndex < model->count() && rowPos <= to) { //qDebug() << "refill: append item" << modelIndex; - item = getItem(modelIndex); + if (!(item = getItem(modelIndex))) + break; item->setPosition(colPos, rowPos); visibleItems.append(item); colPos += colSize(); @@ -431,7 +432,8 @@ void QFxGridViewPrivate::refill(qreal from, qreal to) } while (visibleIndex > 0 && rowPos + rowSize() - 1 >= from){ //qDebug() << "refill: prepend item" << visibleIndex-1 << "top pos" << rowPos << colPos; - item = getItem(visibleIndex-1); + if (!(item = getItem(visibleIndex-1))) + break; --visibleIndex; item->setPosition(colPos, rowPos); visibleItems.prepend(item); @@ -629,14 +631,17 @@ void QFxGridViewPrivate::updateCurrent(int modelIndex) currentItem = visibleItem(modelIndex); if (!currentItem) { currentItem = getItem(modelIndex); - currentItem->setPosition(colPosAt(modelIndex), rowPosAt(modelIndex)); + if (currentItem) + currentItem->setPosition(colPosAt(modelIndex), rowPosAt(modelIndex)); } currentIndex = modelIndex; fixCurrentVisibility = true; - if (oldCurrentItem && oldCurrentItem->item != currentItem->item) + if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) oldCurrentItem->attached->setIsCurrentItem(false); - currentItem->item->setFocus(true); - currentItem->attached->setIsCurrentItem(true); + if (currentItem) { + currentItem->item->setFocus(true); + currentItem->attached->setIsCurrentItem(true); + } updateHighlight(); emit q->currentIndexChanged(); // Release the old current item -- cgit v0.12 From efc9a552d6d3f03b962ce0df260fb2c61b8b8ec1 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 14 May 2009 15:38:27 +1000 Subject: Make compile on arm. --- src/declarative/fx/qfxgridview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index 5156d06..0f848d6 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -472,7 +472,7 @@ void QFxGridViewPrivate::refill(qreal from, qreal to) void QFxGridViewPrivate::updateGrid() { Q_Q(QFxGridView); - columns = (int)qMax((flow == QFxGridView::LeftToRight ? q->width() : q->height()) / colSize(), 1.); + columns = (int)qMax((flow == QFxGridView::LeftToRight ? q->width() : q->height()) / colSize(), qreal(1.)); if (isValid()) { if (flow == QFxGridView::LeftToRight) q->setViewportHeight(endPosition() - startPosition()); -- cgit v0.12 From 309e8a96af899c612ea26b73fc97d9d377bc9819 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Thu, 14 May 2009 15:41:14 +1000 Subject: Flickr demo: Scale the image about the center of the visible area. --- demos/declarative/flickr/content/ImageDetails.qml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/demos/declarative/flickr/content/ImageDetails.qml b/demos/declarative/flickr/content/ImageDetails.qml index d575be9..b8091f2 100644 --- a/demos/declarative/flickr/content/ImageDetails.qml +++ b/demos/declarative/flickr/content/ImageDetails.qml @@ -12,6 +12,7 @@ Flipable { property string photoDate property string photoUrl property int rating: 2 + property var prevScale: 1.0 signal closed @@ -93,7 +94,8 @@ Flipable { // Default scale shows the entire image. if (status == 0 && width != 0) { Slider.minimum = Math.min(Flick.width / width, Flick.height / height); - Slider.value = Math.min(Slider.minimum, 1); + prevScale = Math.min(Slider.minimum, 1); + Slider.value = prevScale; } } } @@ -109,7 +111,20 @@ Flipable { anchors.centeredIn: parent; color: "white"; font.bold: true } - Slider { id: Slider; x: 25; y: 374; visible: { BigImage.status == 0 && maximum > minimum } } + Slider { + id: Slider; x: 25; y: 374; visible: { BigImage.status == 0 && maximum > minimum } + onValueChanged: { + if (BigImage.width * value > Flick.width) { + var xoff = (Flick.width/2 + Flick.xPosition) * value / prevScale; + Flick.xPosition = xoff - Flick.width/2; + } + if (BigImage.height * value > Flick.height) { + var yoff = (Flick.height/2 + Flick.yPosition) * value / prevScale; + Flick.yPosition = yoff - Flick.height/2; + } + prevScale = value; + } + } } states: [ -- cgit v0.12 From b7f710a79b3d5f529dde8ad43ee4e0b78100674f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 14 May 2009 15:41:45 +1000 Subject: Have scale grid images degrade a bit nicer. If a scale grid image has offsets that add up to bigger than the size, we don't paint the middle bits at all. --- src/declarative/fx/qfximage.cpp | 4 ++-- src/declarative/fx/qfxrect.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index dfd6915..9d7a36a 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -365,8 +365,8 @@ void QFxImage::paintContents(QPainter &p) const int sgr = d->_scaleGrid->right(); const int sgt = d->_scaleGrid->top(); const int sgb = d->_scaleGrid->bottom(); - const int xSide = sgl + sgr; - const int ySide = sgt + sgb; + const int xSide = qMin(sgl + sgr, int(width())); + const int ySide = qMin(sgt + sgb, int(height())); // Upper left if (sgt && sgl) diff --git a/src/declarative/fx/qfxrect.cpp b/src/declarative/fx/qfxrect.cpp index 371aa0c..dafd8a2 100644 --- a/src/declarative/fx/qfxrect.cpp +++ b/src/declarative/fx/qfxrect.cpp @@ -486,8 +486,8 @@ void QFxRect::drawRect(QPainter &p) } //basically same code as QFxImage uses to paint sci images - int xSide = offset * 2; - int ySide = offset * 2; + int xSide = qMin(offset * 2, int(width())); + int ySide = qMin(offset * 2, int(height()));; // Upper left p.drawImage(QRect(0, 0, offset, offset), d->_rectImage, QRect(0, 0, offset, offset)); -- cgit v0.12