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 )
|
||||||
|
@ -32,126 +32,128 @@ class KCategoryDrawerV3;
|
|||||||
class KCategorizedView::Private
|
class KCategorizedView::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct Block;
|
struct Block;
|
||||||
struct Item;
|
struct Item;
|
||||||
|
|
||||||
Private(KCategorizedView *q);
|
Private(KCategorizedView *q);
|
||||||
~Private();
|
~Private();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return whether this view has all required elements to be categorized.
|
* @return whether this view has all required elements to be categorized.
|
||||||
*/
|
*/
|
||||||
bool isCategorized() const;
|
bool isCategorized() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the block rect for the representative @p representative.
|
* @return the block rect for the representative @p representative.
|
||||||
*/
|
*/
|
||||||
QStyleOptionViewItemV4 blockRect(const QModelIndex &representative);
|
QStyleOptionViewItemV4 blockRect(const QModelIndex &representative);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the first and last element that intersects with rect.
|
* Returns the first and last element that intersects with rect.
|
||||||
*
|
*
|
||||||
* @note see that here we cannot take out items between first and last (as we could
|
* @note see that here we cannot take out items between first and last (as we could
|
||||||
* do with the rubberband).
|
* do with the rubberband).
|
||||||
*
|
*
|
||||||
* Complexity: O(log(n)) where n is model()->rowCount().
|
* Complexity: O(log(n)) where n is model()->rowCount().
|
||||||
*/
|
*/
|
||||||
QPair<QModelIndex, QModelIndex> intersectingIndexesWithRect(const QRect &rect) const;
|
QPair<QModelIndex, QModelIndex> intersectingIndexesWithRect(const QRect &rect) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the position of the block of @p category.
|
* Returns the position of the block of @p category.
|
||||||
*
|
*
|
||||||
* Complexity: O(n) where n is the number of different categories when the block has been
|
* Complexity: O(n) where n is the number of different categories when the block has been
|
||||||
* marked as in quarantine. O(1) the rest of the times (the vast majority).
|
* marked as in quarantine. O(1) the rest of the times (the vast majority).
|
||||||
*/
|
*/
|
||||||
QPoint blockPosition(const QString &category);
|
QPoint blockPosition(const QString &category);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the height of the block determined by @p category.
|
* Returns the height of the block determined by @p category.
|
||||||
*/
|
*/
|
||||||
int blockHeight(const QString &category);
|
int blockHeight(const QString &category);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the actual viewport width.
|
* Returns the actual viewport width.
|
||||||
*/
|
*/
|
||||||
int viewportWidth() const;
|
int viewportWidth() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks all elements as in quarantine.
|
* Marks all elements as in quarantine.
|
||||||
*
|
*
|
||||||
* Complexity: O(n) where n is model()->rowCount().
|
* Complexity: O(n) where n is model()->rowCount().
|
||||||
*
|
*
|
||||||
* @warning this is an expensive operation
|
* @warning this is an expensive operation
|
||||||
*/
|
*/
|
||||||
void regenerateAllElements();
|
void regenerateAllElements();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update internal information, and keep sync with the real information that the model contains.
|
* Update internal information, and keep sync with the real information that the model contains.
|
||||||
*/
|
*/
|
||||||
void rowsInserted(const QModelIndex &parent, int start, int end);
|
void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns @p rect in viewport terms, taking in count horizontal and vertical offsets.
|
* Returns @p rect in viewport terms, taking in count horizontal and vertical offsets.
|
||||||
*/
|
*/
|
||||||
QRect mapToViewport(const QRect &rect) const;
|
QRect mapToViewport(const QRect &rect) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns @p rect in absolute terms, converted from viewport position.
|
* Returns @p rect in absolute terms, converted from viewport position.
|
||||||
*/
|
*/
|
||||||
QRect mapFromViewport(const QRect &rect) const;
|
QRect mapFromViewport(const QRect &rect) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the height of the highest element in last row. This is only applicable if there is
|
* Returns the height of the highest element in last row. This is only applicable if there is
|
||||||
* no grid set and uniformItemSizes is false.
|
* no grid set and uniformItemSizes is false.
|
||||||
*
|
*
|
||||||
* @param block in which block are we searching. Necessary to stop the search if we hit the
|
* @param block in which block are we searching. Necessary to stop the search if we hit the
|
||||||
* first item in this block.
|
* first item in this block.
|
||||||
*/
|
*/
|
||||||
int highestElementInLastRow(const Block &block) const;
|
int highestElementInLastRow(const Block &block) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the view has a valid grid size.
|
* Returns whether the view has a valid grid size.
|
||||||
*/
|
*/
|
||||||
bool hasGrid() const;
|
bool hasGrid() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the category for the given index.
|
* Returns the category for the given index.
|
||||||
*/
|
*/
|
||||||
QString categoryForIndex(const QModelIndex &index) const;
|
QString categoryForIndex(const QModelIndex &index) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the visual rect for item when flow is LeftToRight.
|
* Updates the visual rect for item when flow is LeftToRight.
|
||||||
*/
|
*/
|
||||||
void leftToRightVisualRect(const QModelIndex &index, Item &item,
|
void leftToRightVisualRect(const QModelIndex &index, Item &item,
|
||||||
const Block &block, const QPoint &blockPos) const;
|
const Block &block, const QPoint &blockPos) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the visual rect for item when flow is TopToBottom.
|
* Updates the visual rect for item when flow is TopToBottom.
|
||||||
* @note we only support viewMode == ListMode in this case.
|
* @note we only support viewMode == ListMode in this case.
|
||||||
*/
|
*/
|
||||||
void topToBottomVisualRect(const QModelIndex &index, Item &item,
|
void topToBottomVisualRect(const QModelIndex &index, Item &item,
|
||||||
const Block &block, const QPoint &blockPos) const;
|
const Block &block, const QPoint &blockPos) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when expand or collapse has been clicked on the category drawer.
|
* Called when expand or collapse has been clicked on the category drawer.
|
||||||
*/
|
*/
|
||||||
void _k_slotCollapseOrExpandClicked(QModelIndex);
|
void _k_slotCollapseOrExpandClicked(QModelIndex);
|
||||||
|
|
||||||
KCategorizedView *q;
|
KCategorizedView *q;
|
||||||
KCategorizedSortFilterProxyModel *proxyModel;
|
KCategorizedSortFilterProxyModel *proxyModel;
|
||||||
KCategoryDrawer *categoryDrawer;
|
KCategoryDrawer *categoryDrawer;
|
||||||
int categorySpacing;
|
int categorySpacing;
|
||||||
bool alternatingBlockColors;
|
bool alternatingBlockColors;
|
||||||
bool collapsibleBlocks;
|
bool collapsibleBlocks;
|
||||||
|
bool constantItemWidth;
|
||||||
|
|
||||||
Block *hoveredBlock;
|
Block *hoveredBlock;
|
||||||
QString hoveredCategory;
|
QString hoveredCategory;
|
||||||
QModelIndex hoveredIndex;
|
QModelIndex hoveredIndex;
|
||||||
|
|
||||||
QPoint pressedPosition;
|
QPoint pressedPosition;
|
||||||
QRect rubberBandRect;
|
QRect rubberBandRect;
|
||||||
|
|
||||||
QHash<QString, Block> blocks;
|
QHash<QString, Block> blocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KCATEGORIZEDVIEW_P_H
|
#endif // KCATEGORIZEDVIEW_P_H
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user