From 086634ae7b38154f7360bb864d30a4b93ebb46e0 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 10 Feb 2016 14:57:44 +0100 Subject: [PATCH] Nested partitions mode support in PartitionBarsView. --- .../partition/gui/PartitionBarsView.cpp | 89 ++++++++++++++----- src/modules/partition/gui/PartitionBarsView.h | 10 +++ 2 files changed, 78 insertions(+), 21 deletions(-) diff --git a/src/modules/partition/gui/PartitionBarsView.cpp b/src/modules/partition/gui/PartitionBarsView.cpp index 423a8020a..399be81fa 100644 --- a/src/modules/partition/gui/PartitionBarsView.cpp +++ b/src/modules/partition/gui/PartitionBarsView.cpp @@ -52,6 +52,7 @@ static const int SELECTION_MARGIN = qMin( ( EXTENDED_PARTITION_MARGIN - 2 ) / 2, PartitionBarsView::PartitionBarsView( QWidget* parent ) : QAbstractItemView( parent ) + , m_nestedPartitionsMode( NoNestedPartitions ) , m_hoveredIndex( QModelIndex() ) , canBeSelected( []( const QModelIndex& ) { return true; } ) { @@ -75,6 +76,14 @@ PartitionBarsView::~PartitionBarsView() } +void +PartitionBarsView::setNestedPartitionsMode( PartitionBarsView::NestedPartitionsMode mode ) +{ + m_nestedPartitionsMode = mode; + viewport()->repaint(); +} + + QSize PartitionBarsView::minimumSizeHint() const { @@ -216,16 +225,34 @@ PartitionBarsView::drawPartitions( QPainter* painter, const QRect& rect, const Q // Make sure we fill the last pixel column width = rect.right() - x + 1; - drawSection( painter, rect, x, width, item.index ); - if ( modl->hasChildren( item.index ) ) + if ( m_nestedPartitionsMode == DrawNestedPartitions ) { - QRect subRect( - x + EXTENDED_PARTITION_MARGIN, - rect.y() + EXTENDED_PARTITION_MARGIN, - width - 2 * EXTENDED_PARTITION_MARGIN, - rect.height() - 2 * EXTENDED_PARTITION_MARGIN - ); - drawPartitions( painter, subRect, item.index ); + drawSection( painter, rect, x, width, item.index ); + if ( modl->hasChildren( item.index ) ) + { + QRect subRect( + x + EXTENDED_PARTITION_MARGIN, + rect.y() + EXTENDED_PARTITION_MARGIN, + 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; } @@ -276,12 +303,22 @@ PartitionBarsView::indexAt( const QPoint &point, { if ( modl->hasChildren( item.index ) ) { - QRect subRect( - x + EXTENDED_PARTITION_MARGIN, - rect.y() + EXTENDED_PARTITION_MARGIN, - width - 2 * EXTENDED_PARTITION_MARGIN, - rect.height() - 2 * EXTENDED_PARTITION_MARGIN - ); + QRect subRect; + if ( m_nestedPartitionsMode == DrawNestedPartitions ) + subRect = QRect( + x + 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 ) ) { return indexAt( point, subRect, item.index ); @@ -339,12 +376,22 @@ PartitionBarsView::visualRect( const QModelIndex& index, if ( modl->hasChildren( item.index ) && index.parent() == item.index ) { - QRect subRect( - x + EXTENDED_PARTITION_MARGIN, - rect.y() + EXTENDED_PARTITION_MARGIN, - width - 2 * EXTENDED_PARTITION_MARGIN, - rect.height() - 2 * EXTENDED_PARTITION_MARGIN - ); + QRect subRect; + if ( m_nestedPartitionsMode == DrawNestedPartitions ) + subRect = QRect( + x + 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 ); if ( !candidateVisualRect.isNull() ) return candidateVisualRect; diff --git a/src/modules/partition/gui/PartitionBarsView.h b/src/modules/partition/gui/PartitionBarsView.h index 3d6937093..002d2c943 100644 --- a/src/modules/partition/gui/PartitionBarsView.h +++ b/src/modules/partition/gui/PartitionBarsView.h @@ -35,9 +35,17 @@ class PartitionBarsView : public QAbstractItemView { Q_OBJECT public: + enum NestedPartitionsMode + { + NoNestedPartitions = 0, + DrawNestedPartitions + }; + explicit PartitionBarsView( QWidget* parent = nullptr ); virtual ~PartitionBarsView(); + void setNestedPartitionsMode( NestedPartitionsMode mode ); + QSize minimumSizeHint() const override; QSize sizeHint() const override; @@ -75,6 +83,8 @@ private: QModelIndex indexAt( const QPoint& point, const QRect& rect, const QModelIndex& parent ) const; QRect visualRect( const QModelIndex& index, const QRect& rect, const QModelIndex& parent ) const; + NestedPartitionsMode m_nestedPartitionsMode; + SelectionFilter canBeSelected; struct Item