Add instance view up/down keyboard navigation, fix some layout glitches (not all)
This commit is contained in:
parent
af046ff6fc
commit
65dc5d44f1
@ -97,6 +97,8 @@ MainWindow::MainWindow ( QWidget *parent ) :
|
|||||||
auto delegate = new ListViewDelegate();
|
auto delegate = new ListViewDelegate();
|
||||||
view->setItemDelegate(delegate);
|
view->setItemDelegate(delegate);
|
||||||
view->setSpacing(10);
|
view->setSpacing(10);
|
||||||
|
//view->setCategorySpacing(10);
|
||||||
|
view->setUniformItemWidths(true);
|
||||||
|
|
||||||
model = new InstanceModel ( instList,this );
|
model = new InstanceModel ( instList,this );
|
||||||
proxymodel = new InstanceProxyModel ( this );
|
proxymodel = new InstanceProxyModel ( this );
|
||||||
|
@ -208,6 +208,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signify that all item delegates size hints return the same fixed size
|
||||||
|
*/
|
||||||
|
void setUniformItemWidths(bool enable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do all item delegate size hints return the same fixed size?
|
||||||
|
*/
|
||||||
|
bool uniformItemWidths() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Reimplemented from QWidget.
|
* Reimplemented from QWidget.
|
||||||
|
@ -115,6 +115,7 @@ KCategorizedView::Private::Private ( KCategorizedView *q )
|
|||||||
, hoveredIndex ( QModelIndex() )
|
, hoveredIndex ( QModelIndex() )
|
||||||
, pressedPosition ( QPoint() )
|
, pressedPosition ( QPoint() )
|
||||||
, rubberBandRect ( QRect() )
|
, rubberBandRect ( QRect() )
|
||||||
|
, constantItemWidth( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,7 +448,7 @@ void KCategorizedView::Private::leftToRightVisualRect ( const QModelIndex &index
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( q->uniformItemSizes() )
|
if ( q->uniformItemSizes() /*|| q->uniformItemWidths()*/ )
|
||||||
{
|
{
|
||||||
const int relativeRow = index.row() - firstIndexRow;
|
const int relativeRow = index.row() - firstIndexRow;
|
||||||
const QSize itemSize = q->sizeHintForIndex ( index );
|
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 )
|
void KCategorizedView::setGridSize ( const QSize &size )
|
||||||
{
|
{
|
||||||
setGridSizeOwn ( size );
|
setGridSizeOwn ( size );
|
||||||
@ -1294,13 +1307,13 @@ QModelIndex KCategorizedView::moveCursor ( CursorAction cursorAction,
|
|||||||
}
|
}
|
||||||
case MoveDown:
|
case MoveDown:
|
||||||
{
|
{
|
||||||
if ( d->hasGrid() || uniformItemSizes() )
|
if ( d->hasGrid() || uniformItemSizes() || uniformItemWidths() )
|
||||||
{
|
{
|
||||||
const QModelIndex current = currentIndex();
|
const QModelIndex current = currentIndex();
|
||||||
const QSize itemSize = d->hasGrid() ? gridSize()
|
const QSize itemSize = d->hasGrid() ? gridSize()
|
||||||
: sizeHintForIndex ( current );
|
: sizeHintForIndex ( current );
|
||||||
const Private::Block &block = d->blocks[d->categoryForIndex ( 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() +
|
const bool canMove = current.row() + maxItemsPerRow < block.firstIndex.row() +
|
||||||
block.items.count();
|
block.items.count();
|
||||||
|
|
||||||
@ -1334,13 +1347,13 @@ QModelIndex KCategorizedView::moveCursor ( CursorAction cursorAction,
|
|||||||
}
|
}
|
||||||
case MoveUp:
|
case MoveUp:
|
||||||
{
|
{
|
||||||
if ( d->hasGrid() || uniformItemSizes() )
|
if ( d->hasGrid() || uniformItemSizes() || uniformItemWidths() )
|
||||||
{
|
{
|
||||||
const QModelIndex current = currentIndex();
|
const QModelIndex current = currentIndex();
|
||||||
const QSize itemSize = d->hasGrid() ? gridSize()
|
const QSize itemSize = d->hasGrid() ? gridSize()
|
||||||
: sizeHintForIndex ( current );
|
: sizeHintForIndex ( current );
|
||||||
const Private::Block &block = d->blocks[d->categoryForIndex ( 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();
|
const bool canMove = current.row() - maxItemsPerRow >= block.firstIndex.row();
|
||||||
|
|
||||||
if ( canMove )
|
if ( canMove )
|
||||||
|
@ -143,6 +143,7 @@ public:
|
|||||||
int categorySpacing;
|
int categorySpacing;
|
||||||
bool alternatingBlockColors;
|
bool alternatingBlockColors;
|
||||||
bool collapsibleBlocks;
|
bool collapsibleBlocks;
|
||||||
|
bool constantItemWidth;
|
||||||
|
|
||||||
Block *hoveredBlock;
|
Block *hoveredBlock;
|
||||||
QString hoveredCategory;
|
QString hoveredCategory;
|
||||||
@ -155,3 +156,4 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // KCATEGORIZEDVIEW_P_H
|
#endif // KCATEGORIZEDVIEW_P_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user