New palette + don't reset count when coloring logical partitions.

This commit is contained in:
Teo Mrnjavac 2015-04-24 16:52:30 +02:00
parent 5ab7896fca
commit c7563af1c9

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Aurélien Gâteau <agateau@kde.org> * Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -19,6 +20,7 @@
#include <core/ColorUtils.h> #include <core/ColorUtils.h>
#include <core/PMUtils.h> #include <core/PMUtils.h>
#include <core/PartitionIterator.h>
// CalaPM // CalaPM
#include <core/partition.h> #include <core/partition.h>
@ -26,12 +28,15 @@
// Qt // Qt
#include <QColor> #include <QColor>
static QColor COLORS[ 4 ] = static const int NUM_PARTITION_COLORS = 5;
//Let's try to use the Breeze palette
static QColor PARTITION_COLORS[ NUM_PARTITION_COLORS ] =
{ {
"#448eca", "#2980b9", //Dark Plasma Blue
"#a5cc42", "#27ae60", //Dark Icon Green
"#d87e30", "#c9ce3b", //Dirty Yellow
"#ffbdbd", "#3daee9", //Plasma Blue
"#9b59b6", //Purple
}; };
static QColor FREE_SPACE_COLOR = "#777777"; static QColor FREE_SPACE_COLOR = "#777777";
static QColor EXTENDED_COLOR = "#aaaaaa"; static QColor EXTENDED_COLOR = "#aaaaaa";
@ -45,7 +50,18 @@ QColor freeSpaceColor()
return FREE_SPACE_COLOR; return FREE_SPACE_COLOR;
} }
QColor colorForPartition( Partition* partition ) PartitionNode*
_findRootForPartition( PartitionNode* partition )
{
if ( partition->isRoot() ||
!partition->parent() )
return partition;
return _findRootForPartition( partition->parent() );
}
QColor
colorForPartition( Partition* partition )
{ {
if ( PMUtils::isPartitionFreeSpace( partition ) ) if ( PMUtils::isPartitionFreeSpace( partition ) )
return FREE_SPACE_COLOR; return FREE_SPACE_COLOR;
@ -54,20 +70,26 @@ QColor colorForPartition( Partition* partition )
// 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
PartitionNode* parent = partition->parent(); PartitionNode* parent = _findRootForPartition( partition );
Q_ASSERT( parent ); PartitionTable* table = dynamic_cast< PartitionTable* >( parent );
Q_ASSERT( table );
int colorIdx = 0; int colorIdx = 0;
for ( auto child : parent->children() ) for ( PartitionIterator it = PartitionIterator::begin( table );
it != PartitionIterator::end( table );
++it )
{ {
Partition* child = *it;
if ( child == partition ) if ( child == partition )
break; break;
if ( !PMUtils::isPartitionFreeSpace( child ) ) if ( !PMUtils::isPartitionFreeSpace( child ) &&
!child->hasChildren() )
++colorIdx; ++colorIdx;
} }
return COLORS[ colorIdx % 4 ]; return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
} }
QColor colorForPartitionInFreeSpace( Partition* partition ) QColor
colorForPartitionInFreeSpace( Partition* partition )
{ {
PartitionNode* parent = partition->parent(); PartitionNode* parent = partition->parent();
Q_ASSERT( parent ); Q_ASSERT( parent );
@ -79,7 +101,7 @@ QColor colorForPartitionInFreeSpace( Partition* partition )
if ( !PMUtils::isPartitionFreeSpace( child ) ) if ( !PMUtils::isPartitionFreeSpace( child ) )
++colorIdx; ++colorIdx;
} }
return COLORS[ colorIdx % 4 ]; return PARTITION_COLORS[ colorIdx % NUM_PARTITION_COLORS ];
} }
} // namespace } // namespace