From 65dc5d44f147fa70710b651f1d6cab8d09fad3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 25 Mar 2013 17:39:52 +0100 Subject: Add instance view up/down keyboard navigation, fix some layout glitches (not all) --- libgroupview/src/kcategorizedview.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'libgroupview/src/kcategorizedview.cpp') diff --git a/libgroupview/src/kcategorizedview.cpp b/libgroupview/src/kcategorizedview.cpp index 5b7c8d42..fdf6bc77 100644 --- a/libgroupview/src/kcategorizedview.cpp +++ b/libgroupview/src/kcategorizedview.cpp @@ -115,6 +115,7 @@ KCategorizedView::Private::Private ( KCategorizedView *q ) , hoveredIndex ( QModelIndex() ) , pressedPosition ( QPoint() ) , rubberBandRect ( QRect() ) + , constantItemWidth( 0 ) { } @@ -447,7 +448,7 @@ void KCategorizedView::Private::leftToRightVisualRect ( const QModelIndex &index } else { - if ( q->uniformItemSizes() ) + if ( q->uniformItemSizes() /*|| q->uniformItemWidths()*/ ) { const int relativeRow = index.row() - firstIndexRow; const QSize itemSize = q->sizeHintForIndex ( index ); @@ -622,6 +623,18 @@ void KCategorizedView::setModel ( QAbstractItemModel *model ) } } + +void KCategorizedView::setUniformItemWidths(bool enable) +{ + d->constantItemWidth = enable; +} + + +bool KCategorizedView::uniformItemWidths() const +{ + return d->constantItemWidth; +} + void KCategorizedView::setGridSize ( const QSize &size ) { setGridSizeOwn ( size ); @@ -1294,13 +1307,13 @@ QModelIndex KCategorizedView::moveCursor ( CursorAction cursorAction, } case MoveDown: { - if ( d->hasGrid() || uniformItemSizes() ) + if ( d->hasGrid() || uniformItemSizes() || uniformItemWidths() ) { const QModelIndex current = currentIndex(); const QSize itemSize = d->hasGrid() ? gridSize() : sizeHintForIndex ( current ); const Private::Block &block = d->blocks[d->categoryForIndex ( current )]; - const int maxItemsPerRow = qMax ( d->viewportWidth() / itemSize.width(), 1 ); + const int maxItemsPerRow = qMax ( ( d->viewportWidth() - spacing() ) / ( itemSize.width() + spacing() ), 1 ); const bool canMove = current.row() + maxItemsPerRow < block.firstIndex.row() + block.items.count(); @@ -1334,13 +1347,13 @@ QModelIndex KCategorizedView::moveCursor ( CursorAction cursorAction, } case MoveUp: { - if ( d->hasGrid() || uniformItemSizes() ) + if ( d->hasGrid() || uniformItemSizes() || uniformItemWidths() ) { const QModelIndex current = currentIndex(); const QSize itemSize = d->hasGrid() ? gridSize() : sizeHintForIndex ( current ); const Private::Block &block = d->blocks[d->categoryForIndex ( current )]; - const int maxItemsPerRow = qMax ( d->viewportWidth() / itemSize.width(), 1 ); + const int maxItemsPerRow = qMax ( ( d->viewportWidth() - spacing() ) / ( itemSize.width() + spacing() ), 1 ); const bool canMove = current.row() - maxItemsPerRow >= block.firstIndex.row(); if ( canMove ) -- cgit v1.2.3 From 37852d47a7e5c3d65a0cfa127ced477b33eca269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 25 Mar 2013 19:28:08 +0100 Subject: Fix an another layout problem in instance list --- libgroupview/src/kcategorizedview.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libgroupview/src/kcategorizedview.cpp') diff --git a/libgroupview/src/kcategorizedview.cpp b/libgroupview/src/kcategorizedview.cpp index fdf6bc77..19f9a0af 100644 --- a/libgroupview/src/kcategorizedview.cpp +++ b/libgroupview/src/kcategorizedview.cpp @@ -479,7 +479,8 @@ void KCategorizedView::Private::leftToRightVisualRect ( const QModelIndex &index Q_FOREVER { prevIndex = proxyModel->index ( prevIndex.row() - 1, q->modelColumn(), q->rootIndex() ); - const QRect tempRect = q->visualRect ( prevIndex ); + QRect tempRect = q->visualRect ( prevIndex ); + tempRect = mapFromViewport ( tempRect ); if ( tempRect.topLeft().y() < prevRect.topLeft().y() ) { break; -- cgit v1.2.3 From d2eef6974be6c9d65f0108bb86fc94e141330c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 25 Mar 2013 20:58:45 +0100 Subject: Mystery meat layout hack to get things aligned --- libgroupview/src/kcategorizedview.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libgroupview/src/kcategorizedview.cpp') diff --git a/libgroupview/src/kcategorizedview.cpp b/libgroupview/src/kcategorizedview.cpp index 19f9a0af..4da4271f 100644 --- a/libgroupview/src/kcategorizedview.cpp +++ b/libgroupview/src/kcategorizedview.cpp @@ -452,7 +452,8 @@ void KCategorizedView::Private::leftToRightVisualRect ( const QModelIndex &index { const int relativeRow = index.row() - firstIndexRow; const QSize itemSize = q->sizeHintForIndex ( index ); - const int maxItemsPerRow = qMax ( ( viewportWidth() - q->spacing() ) / ( itemSize.width() + q->spacing() ), 1 ); + //HACK: Why is the -2 needed? + const int maxItemsPerRow = qMax ( ( viewportWidth() - q->spacing() - 2 ) / ( itemSize.width() + q->spacing() ), 1 ); if ( q->layoutDirection() == Qt::LeftToRight ) { item.topLeft.rx() = ( relativeRow % maxItemsPerRow ) * itemSize.width() + blockPos.x() + categoryDrawer->leftMargin(); @@ -1314,7 +1315,8 @@ QModelIndex KCategorizedView::moveCursor ( CursorAction cursorAction, const QSize itemSize = d->hasGrid() ? gridSize() : sizeHintForIndex ( current ); const Private::Block &block = d->blocks[d->categoryForIndex ( current )]; - const int maxItemsPerRow = qMax ( ( d->viewportWidth() - spacing() ) / ( itemSize.width() + spacing() ), 1 ); + //HACK: Why is the -2 needed? + const int maxItemsPerRow = qMax ( ( d->viewportWidth() - spacing() - 2 ) / ( itemSize.width() + spacing() ), 1 ); const bool canMove = current.row() + maxItemsPerRow < block.firstIndex.row() + block.items.count(); @@ -1354,7 +1356,8 @@ QModelIndex KCategorizedView::moveCursor ( CursorAction cursorAction, const QSize itemSize = d->hasGrid() ? gridSize() : sizeHintForIndex ( current ); const Private::Block &block = d->blocks[d->categoryForIndex ( current )]; - const int maxItemsPerRow = qMax ( ( d->viewportWidth() - spacing() ) / ( itemSize.width() + spacing() ), 1 ); + //HACK: Why is the -2 needed? + const int maxItemsPerRow = qMax ( ( d->viewportWidth() - spacing() - 2 ) / ( itemSize.width() + spacing() ), 1 ); const bool canMove = current.row() - maxItemsPerRow >= block.firstIndex.row(); if ( canMove ) -- cgit v1.2.3