Fixed (again) search algorithm for iconview widget. This resolves (again) bug 420.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit d27f4e2fc3)
v3.5.13-sru
Michele Calgaro 9 years ago committed by Slávek Banko
parent 3f8c59015d
commit da181f82c3

@ -5308,23 +5308,21 @@ void QIconView::keyPressEvent( QKeyEvent *e )
/*
Finds the closest item in the direction \a dir starting from the specified \a fromItem.
If the arrangement is LeftToRight (icon view mode): use center as item reference
If the arrangement is TopToBottom (multicolumn view mode): use left top corner as item reference
If the arrangement is LeftToRight (icon view mode): use (center, top) as item reference
If the arrangement is TopToBottom (multicolumn view mode): use (left, top) as item reference
This is to allow for smooth scrolling when using the keyboard arrow keys.
*/
QIconViewItem* QIconView::findItem(Direction dir, const QIconViewItem *fromItem) const
{
QIconViewItem *closestItem=NULL;
int distPri=0, distSec=0;
int itemDistancePri=0, itemDistanceSec=0;
QPoint pos;
QPoint pos=fromItem->rect().topLeft();
if (d->arrangement == LeftToRight) {
pos=fromItem->rect().center();
}
else {
pos=fromItem->rect().topLeft();
pos.setX(fromItem->rect().center().x());
}
QRect searchRect;
switch (dir) {
case DirDown:
@ -5354,16 +5352,16 @@ QIconViewItem* QIconView::findItem(Direction dir, const QIconViewItem *fromItem)
// DirDown/DirUp : primary distance X, secondary distance Y
// DirLeft/DirRight: primary distance Y, secondary distance X
if (d->arrangement == LeftToRight) {
// Left to right arrangement (icon view mode): use center as item reference
// Left to right arrangement (icon view mode): use (center, top) as item reference
switch (dir) {
case DirDown:
if (ir.center().x() > pos.x()) {
distPri = ir.center().x()-pos.x();
distSec = ir.center().y();
distSec = ir.top();
}
else if (ir.center().x() == pos.x() && ir.center().y() > pos.y()) {
else if (ir.center().x() == pos.x() && ir.top() > pos.y()) {
distPri = 0;
distSec = ir.center().y()-pos.y();
distSec = ir.top()-pos.y();
}
else {
itemOK = false;
@ -5373,11 +5371,11 @@ QIconViewItem* QIconView::findItem(Direction dir, const QIconViewItem *fromItem)
case DirUp:
if (ir.center().x() < pos.x()) {
distPri = pos.x()-ir.center().x();
distSec = contentsHeight()-ir.center().y();
distSec = contentsHeight()-ir.top();
}
else if (ir.center().x() == pos.x() && ir.center().y() < pos.y()) {
else if (ir.center().x() == pos.x() && ir.top() < pos.y()) {
distPri = 0;
distSec = pos.y()-ir.center().y();
distSec = pos.y()-ir.top();
}
else {
itemOK = false;
@ -5385,11 +5383,11 @@ QIconViewItem* QIconView::findItem(Direction dir, const QIconViewItem *fromItem)
break;
case DirRight:
if (ir.center().y() > pos.y()) {
distPri = ir.center().y()-pos.y();
if (ir.top() > pos.y()) {
distPri = ir.top()-pos.y();
distSec = ir.center().x();
}
else if (ir.center().y() == pos.y() && ir.center().x() > pos.x()) {
else if (ir.top() == pos.y() && ir.center().x() > pos.x()) {
distPri = 0;
distSec = ir.center().x()-pos.x();
}
@ -5399,11 +5397,11 @@ QIconViewItem* QIconView::findItem(Direction dir, const QIconViewItem *fromItem)
break;
case DirLeft:
if (ir.center().y() < pos.y()) {
distPri = pos.y()-ir.center().y();
if (ir.top() < pos.y()) {
distPri = pos.y()-ir.top();
distSec = contentsWidth()-ir.center().x();
}
else if (ir.center().y() == pos.y() && ir.center().x() < pos.x()) {
else if (ir.top() == pos.y() && ir.center().x() < pos.x()) {
distPri = 0;
distSec = pos.x()-ir.center().x();
}
@ -5417,8 +5415,8 @@ QIconViewItem* QIconView::findItem(Direction dir, const QIconViewItem *fromItem)
break;
}
}
else {
// Top to bottom arrangement (multicolumn view mode): use left top corner as item reference
else {
// Top to bottom arrangement (multicolumn view mode): use (left, top) as item reference
switch (dir) {
case DirDown:
if (ir.left() > pos.x()) {

Loading…
Cancel
Save