Use a static colors cache to preserve partition colors.
This commit is contained in:
parent
2c9d6fff17
commit
6b40c8aaa1
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
static const int NUM_PARTITION_COLORS = 5;
|
static const int NUM_PARTITION_COLORS = 5;
|
||||||
static const int NUM_NEW_PARTITION_COLORS = 4;
|
static const int NUM_NEW_PARTITION_COLORS = 4;
|
||||||
@ -49,6 +50,8 @@ static const QColor NEW_PARTITION_COLORS[ NUM_NEW_PARTITION_COLORS ] =
|
|||||||
static QColor FREE_SPACE_COLOR = "#777777";
|
static QColor FREE_SPACE_COLOR = "#777777";
|
||||||
static QColor EXTENDED_COLOR = "#aaaaaa";
|
static QColor EXTENDED_COLOR = "#aaaaaa";
|
||||||
|
|
||||||
|
static QMap< QString, QColor > s_partitionColorsCache;
|
||||||
|
|
||||||
|
|
||||||
namespace ColorUtils
|
namespace ColorUtils
|
||||||
{
|
{
|
||||||
@ -75,6 +78,9 @@ colorForPartition( Partition* partition )
|
|||||||
return FREE_SPACE_COLOR;
|
return FREE_SPACE_COLOR;
|
||||||
if ( partition->roles().has( PartitionRole::Extended ) )
|
if ( partition->roles().has( PartitionRole::Extended ) )
|
||||||
return EXTENDED_COLOR;
|
return EXTENDED_COLOR;
|
||||||
|
if ( s_partitionColorsCache.contains( partition->partitionPath() ) )
|
||||||
|
return s_partitionColorsCache[ partition->partitionPath() ];
|
||||||
|
|
||||||
// No partition-specific color needed, pick one from our list, but skip
|
// 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
|
// free space: we don't want a partition to change colors if space before
|
||||||
// it is inserted or removed
|
// it is inserted or removed
|
||||||
@ -102,6 +108,9 @@ colorForPartition( Partition* partition )
|
|||||||
|
|
||||||
if ( PMUtils::isPartitionNew( partition ) )
|
if ( PMUtils::isPartitionNew( partition ) )
|
||||||
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
|
return NEW_PARTITION_COLORS[ newColorIdx % NUM_NEW_PARTITION_COLORS ];
|
||||||
|
|
||||||
|
s_partitionColorsCache.insert( partition->partitionPath(),
|
||||||
|
PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ] );
|
||||||
return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
|
return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user