From cf4416a171a2145b47bdc6469849f0b6152cf8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 7 Aug 2014 16:13:46 +0200 Subject: [PATCH] Keep partition color if space is inserted/removed before it --- src/modules/partition/PartitionModel.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/PartitionModel.cpp b/src/modules/partition/PartitionModel.cpp index 6364838ba..f161d0d00 100644 --- a/src/modules/partition/PartitionModel.cpp +++ b/src/modules/partition/PartitionModel.cpp @@ -49,8 +49,20 @@ static QColor colorForPartition( Partition* partition, int row ) return FREE_SPACE_COLOR; if ( partition->roles().has( PartitionRole::Extended ) ) return EXTENDED_COLOR; - // No partition-specific color needed, pick one from our list - return COLORS[ row % 4 ]; + // No partition-specific color needed, pick one from our list, but skip + // free space: we don't want a partition to change colors if space before + // it is inserted or removed + PartitionNode* parent = partition->parent(); + Q_ASSERT( parent ); + int colorIdx = 0; + for ( auto child : parent->children() ) + { + if ( child == partition ) + break; + if ( !PMUtils::isPartitionFreeSpace( child ) ) + ++colorIdx; + } + return COLORS[ colorIdx % 4 ]; } //- ResetHelper --------------------------------------------