From 5fc07aad7ca04f6400be515b5af4aeab2ca25780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Tue, 29 Jul 2014 13:36:48 +0200 Subject: [PATCH] Expose colors for Qt::DecorationRole --- src/modules/partition/PartitionModel.cpp | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/modules/partition/PartitionModel.cpp b/src/modules/partition/PartitionModel.cpp index 07c6356ed..912fd136b 100644 --- a/src/modules/partition/PartitionModel.cpp +++ b/src/modules/partition/PartitionModel.cpp @@ -30,6 +30,28 @@ // KF5 #include +// Qt +#include + +static QColor COLORS[ 4 ] = { + "#448eca", + "#a5cc42", + "#d87e30", + "#ffbdbd", +}; +static QColor FREE_SPACE_COLOR = "#777777"; +static QColor EXTENDED_COLOR = "#aaaaaa"; + +static QColor colorForPartition( Partition* partition, int row ) +{ + if ( PMUtils::isPartitionFreeSpace( partition ) ) + 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 ]; +} + //- ResetHelper -------------------------------------------- PartitionModel::ResetHelper::ResetHelper( PartitionModel* model ) : m_model( model ) @@ -145,6 +167,11 @@ PartitionModel::data( const QModelIndex& index, int role ) const cDebug() << "Unknown column" << col; return QVariant(); } + case Qt::DecorationRole: + if ( index.column() == NameColumn ) + return colorForPartition( partition, index.row() ); + else + return QVariant(); default: return QVariant(); }