Nested partitions mode support in PartitionBarsView.
This commit is contained in:
parent
1d533fa2f3
commit
086634ae7b
@ -52,6 +52,7 @@ static const int SELECTION_MARGIN = qMin( ( EXTENDED_PARTITION_MARGIN - 2 ) / 2,
|
|||||||
|
|
||||||
PartitionBarsView::PartitionBarsView( QWidget* parent )
|
PartitionBarsView::PartitionBarsView( QWidget* parent )
|
||||||
: QAbstractItemView( parent )
|
: QAbstractItemView( parent )
|
||||||
|
, m_nestedPartitionsMode( NoNestedPartitions )
|
||||||
, m_hoveredIndex( QModelIndex() )
|
, m_hoveredIndex( QModelIndex() )
|
||||||
, canBeSelected( []( const QModelIndex& ) { return true; } )
|
, canBeSelected( []( const QModelIndex& ) { return true; } )
|
||||||
{
|
{
|
||||||
@ -75,6 +76,14 @@ PartitionBarsView::~PartitionBarsView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PartitionBarsView::setNestedPartitionsMode( PartitionBarsView::NestedPartitionsMode mode )
|
||||||
|
{
|
||||||
|
m_nestedPartitionsMode = mode;
|
||||||
|
viewport()->repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
PartitionBarsView::minimumSizeHint() const
|
PartitionBarsView::minimumSizeHint() const
|
||||||
{
|
{
|
||||||
@ -216,16 +225,34 @@ PartitionBarsView::drawPartitions( QPainter* painter, const QRect& rect, const Q
|
|||||||
// Make sure we fill the last pixel column
|
// Make sure we fill the last pixel column
|
||||||
width = rect.right() - x + 1;
|
width = rect.right() - x + 1;
|
||||||
|
|
||||||
drawSection( painter, rect, x, width, item.index );
|
if ( m_nestedPartitionsMode == DrawNestedPartitions )
|
||||||
if ( modl->hasChildren( item.index ) )
|
|
||||||
{
|
{
|
||||||
QRect subRect(
|
drawSection( painter, rect, x, width, item.index );
|
||||||
x + EXTENDED_PARTITION_MARGIN,
|
if ( modl->hasChildren( item.index ) )
|
||||||
rect.y() + EXTENDED_PARTITION_MARGIN,
|
{
|
||||||
width - 2 * EXTENDED_PARTITION_MARGIN,
|
QRect subRect(
|
||||||
rect.height() - 2 * EXTENDED_PARTITION_MARGIN
|
x + EXTENDED_PARTITION_MARGIN,
|
||||||
);
|
rect.y() + EXTENDED_PARTITION_MARGIN,
|
||||||
drawPartitions( painter, subRect, item.index );
|
width - 2 * EXTENDED_PARTITION_MARGIN,
|
||||||
|
rect.height() - 2 * EXTENDED_PARTITION_MARGIN
|
||||||
|
);
|
||||||
|
drawPartitions( painter, subRect, item.index );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( modl->hasChildren( item.index ) )
|
||||||
|
{
|
||||||
|
QRect subRect(
|
||||||
|
x,
|
||||||
|
rect.y(),
|
||||||
|
width,
|
||||||
|
rect.height()
|
||||||
|
);
|
||||||
|
drawPartitions( painter, subRect, item.index );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
drawSection( painter, rect, x, width, item.index );
|
||||||
}
|
}
|
||||||
x += width;
|
x += width;
|
||||||
}
|
}
|
||||||
@ -276,12 +303,22 @@ PartitionBarsView::indexAt( const QPoint &point,
|
|||||||
{
|
{
|
||||||
if ( modl->hasChildren( item.index ) )
|
if ( modl->hasChildren( item.index ) )
|
||||||
{
|
{
|
||||||
QRect subRect(
|
QRect subRect;
|
||||||
x + EXTENDED_PARTITION_MARGIN,
|
if ( m_nestedPartitionsMode == DrawNestedPartitions )
|
||||||
rect.y() + EXTENDED_PARTITION_MARGIN,
|
subRect = QRect(
|
||||||
width - 2 * EXTENDED_PARTITION_MARGIN,
|
x + EXTENDED_PARTITION_MARGIN,
|
||||||
rect.height() - 2 * EXTENDED_PARTITION_MARGIN
|
rect.y() + EXTENDED_PARTITION_MARGIN,
|
||||||
);
|
width - 2 * EXTENDED_PARTITION_MARGIN,
|
||||||
|
rect.height() - 2 * EXTENDED_PARTITION_MARGIN
|
||||||
|
);
|
||||||
|
else
|
||||||
|
subRect = QRect(
|
||||||
|
x,
|
||||||
|
rect.y(),
|
||||||
|
width,
|
||||||
|
rect.height()
|
||||||
|
);
|
||||||
|
|
||||||
if ( subRect.contains( point ) )
|
if ( subRect.contains( point ) )
|
||||||
{
|
{
|
||||||
return indexAt( point, subRect, item.index );
|
return indexAt( point, subRect, item.index );
|
||||||
@ -339,12 +376,22 @@ PartitionBarsView::visualRect( const QModelIndex& index,
|
|||||||
if ( modl->hasChildren( item.index ) &&
|
if ( modl->hasChildren( item.index ) &&
|
||||||
index.parent() == item.index )
|
index.parent() == item.index )
|
||||||
{
|
{
|
||||||
QRect subRect(
|
QRect subRect;
|
||||||
x + EXTENDED_PARTITION_MARGIN,
|
if ( m_nestedPartitionsMode == DrawNestedPartitions )
|
||||||
rect.y() + EXTENDED_PARTITION_MARGIN,
|
subRect = QRect(
|
||||||
width - 2 * EXTENDED_PARTITION_MARGIN,
|
x + EXTENDED_PARTITION_MARGIN,
|
||||||
rect.height() - 2 * EXTENDED_PARTITION_MARGIN
|
rect.y() + EXTENDED_PARTITION_MARGIN,
|
||||||
);
|
width - 2 * EXTENDED_PARTITION_MARGIN,
|
||||||
|
rect.height() - 2 * EXTENDED_PARTITION_MARGIN
|
||||||
|
);
|
||||||
|
else
|
||||||
|
subRect = QRect(
|
||||||
|
x,
|
||||||
|
rect.y(),
|
||||||
|
width,
|
||||||
|
rect.height()
|
||||||
|
);
|
||||||
|
|
||||||
QRect candidateVisualRect = visualRect( index, subRect, item.index );
|
QRect candidateVisualRect = visualRect( index, subRect, item.index );
|
||||||
if ( !candidateVisualRect.isNull() )
|
if ( !candidateVisualRect.isNull() )
|
||||||
return candidateVisualRect;
|
return candidateVisualRect;
|
||||||
|
@ -35,9 +35,17 @@ class PartitionBarsView : public QAbstractItemView
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum NestedPartitionsMode
|
||||||
|
{
|
||||||
|
NoNestedPartitions = 0,
|
||||||
|
DrawNestedPartitions
|
||||||
|
};
|
||||||
|
|
||||||
explicit PartitionBarsView( QWidget* parent = nullptr );
|
explicit PartitionBarsView( QWidget* parent = nullptr );
|
||||||
virtual ~PartitionBarsView();
|
virtual ~PartitionBarsView();
|
||||||
|
|
||||||
|
void setNestedPartitionsMode( NestedPartitionsMode mode );
|
||||||
|
|
||||||
QSize minimumSizeHint() const override;
|
QSize minimumSizeHint() const override;
|
||||||
|
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
@ -75,6 +83,8 @@ private:
|
|||||||
QModelIndex indexAt( const QPoint& point, const QRect& rect, const QModelIndex& parent ) const;
|
QModelIndex indexAt( const QPoint& point, const QRect& rect, const QModelIndex& parent ) const;
|
||||||
QRect visualRect( const QModelIndex& index, const QRect& rect, const QModelIndex& parent ) const;
|
QRect visualRect( const QModelIndex& index, const QRect& rect, const QModelIndex& parent ) const;
|
||||||
|
|
||||||
|
NestedPartitionsMode m_nestedPartitionsMode;
|
||||||
|
|
||||||
SelectionFilter canBeSelected;
|
SelectionFilter canBeSelected;
|
||||||
|
|
||||||
struct Item
|
struct Item
|
||||||
|
Loading…
Reference in New Issue
Block a user