Add home/end and fix navigation with collapsed groups (they are skipped)

This commit is contained in:
Petr Mrázek 2014-07-12 23:27:32 +02:00
parent cc6968e9a3
commit aba1f89e2a

View File

@ -463,6 +463,7 @@ void GroupView::resizeEvent(QResizeEvent *event)
int newItemsPerRow = calculateItemsPerRow(); int newItemsPerRow = calculateItemsPerRow();
if(newItemsPerRow != m_currentItemsPerRow) if(newItemsPerRow != m_currentItemsPerRow)
{ {
m_currentCursorColumn = -1;
m_currentItemsPerRow = newItemsPerRow; m_currentItemsPerRow = newItemsPerRow;
updateGeometries(); updateGeometries();
} }
@ -832,9 +833,15 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
{ {
if(row == 0) if(row == 0)
{ {
if(group_index == 0) int prevgroupindex = group_index-1;
return current; while(prevgroupindex >= 0)
auto prevgroup = m_groups[group_index-1]; {
auto prevgroup = m_groups[prevgroupindex];
if(prevgroup->collapsed)
{
prevgroupindex--;
continue;
}
int newRow = prevgroup->numRows() - 1; int newRow = prevgroup->numRows() - 1;
int newRowSize = prevgroup->rows[newRow].size(); int newRowSize = prevgroup->rows[newRow].size();
int newColumn = m_currentCursorColumn; int newColumn = m_currentCursorColumn;
@ -844,6 +851,7 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
} }
return prevgroup->rows[newRow][newColumn]; return prevgroup->rows[newRow][newColumn];
} }
}
else else
{ {
int newRow = row - 1; int newRow = row - 1;
@ -855,14 +863,21 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
} }
return cat->rows[newRow][newColumn]; return cat->rows[newRow][newColumn];
} }
return current;
} }
case MoveDown: case MoveDown:
{ {
if(row == cat->rows.size() - 1) if(row == cat->rows.size() - 1)
{ {
if(group_index == m_groups.size() - 1) int nextgroupindex = group_index+1;
return current; while (nextgroupindex < m_groups.size())
auto nextgroup = m_groups[group_index+1]; {
auto nextgroup = m_groups[nextgroupindex];
if(nextgroup->collapsed)
{
nextgroupindex++;
continue;
}
int newRowSize = nextgroup->rows[0].size(); int newRowSize = nextgroup->rows[0].size();
int newColumn = m_currentCursorColumn; int newColumn = m_currentCursorColumn;
if (m_currentCursorColumn >= newRowSize) if (m_currentCursorColumn >= newRowSize)
@ -871,6 +886,7 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
} }
return nextgroup->rows[0][newColumn]; return nextgroup->rows[0][newColumn];
} }
}
else else
{ {
int newRow = row + 1; int newRow = row + 1;
@ -882,6 +898,7 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
} }
return cat->rows[newRow][newColumn]; return cat->rows[newRow][newColumn];
} }
return current;
} }
case MoveLeft: case MoveLeft:
{ {
@ -890,6 +907,7 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
m_currentCursorColumn = column - 1; m_currentCursorColumn = column - 1;
return cat->rows[row][column - 1]; return cat->rows[row][column - 1];
} }
// TODO: moving to previous line
return current; return current;
} }
case MoveRight: case MoveRight:
@ -899,8 +917,20 @@ QModelIndex GroupView::moveCursor(QAbstractItemView::CursorAction cursorAction,
m_currentCursorColumn = column + 1; m_currentCursorColumn = column + 1;
return cat->rows[row][column + 1]; return cat->rows[row][column + 1];
} }
// TODO: moving to next line
return current; return current;
} }
case MoveHome:
{
m_currentCursorColumn = 0;
return cat->rows[row][0];
}
case MoveEnd:
{
auto last = cat->rows[row].size() - 1;
m_currentCursorColumn = last;
return cat->rows[row][last];
}
default: default:
break; break;
} }