diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index 7910f39a4..c8aaf8ad9 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -24,6 +24,7 @@ calamares_add_plugin( partition SOURCES BootLoaderModel.cpp CheckFileSystemJob.cpp + ColorUtils.cpp CreatePartitionDialog.cpp CreatePartitionJob.cpp CreatePartitionTableJob.cpp diff --git a/src/modules/partition/ColorUtils.cpp b/src/modules/partition/ColorUtils.cpp new file mode 100644 index 000000000..f9ef94793 --- /dev/null +++ b/src/modules/partition/ColorUtils.cpp @@ -0,0 +1,85 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include + +#include + +// CalaPM +#include + +// Qt +#include + +static QColor COLORS[ 4 ] = +{ + "#448eca", + "#a5cc42", + "#d87e30", + "#ffbdbd", +}; +static QColor FREE_SPACE_COLOR = "#777777"; +static QColor EXTENDED_COLOR = "#aaaaaa"; + + +namespace ColorUtils +{ + +QColor freeSpaceColor() +{ + return FREE_SPACE_COLOR; +} + +QColor colorForPartition( Partition* partition ) +{ + 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, 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 ]; +} + +QColor colorForPartitionInFreeSpace( Partition* partition ) +{ + 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 ]; +} + +} // namespace diff --git a/src/modules/partition/ColorUtils.h b/src/modules/partition/ColorUtils.h new file mode 100644 index 000000000..b1e79a2dc --- /dev/null +++ b/src/modules/partition/ColorUtils.h @@ -0,0 +1,36 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Aurélien Gâteau + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ +#ifndef COLORUTILS_H +#define COLORUTILS_H + +class QColor; + +class Partition; + +namespace ColorUtils +{ + +QColor freeSpaceColor(); + +QColor colorForPartition( Partition* partition ); + +QColor colorForPartitionInFreeSpace( Partition* partition ); + +} + +#endif /* COLORUTILS_H */ diff --git a/src/modules/partition/PartitionModel.cpp b/src/modules/partition/PartitionModel.cpp index f161d0d00..3ce3f4df2 100644 --- a/src/modules/partition/PartitionModel.cpp +++ b/src/modules/partition/PartitionModel.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -33,38 +34,6 @@ // 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, 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 -------------------------------------------- PartitionModel::ResetHelper::ResetHelper( PartitionModel* model ) : m_model( model ) @@ -182,7 +151,7 @@ PartitionModel::data( const QModelIndex& index, int role ) const } case Qt::DecorationRole: if ( index.column() == NameColumn ) - return colorForPartition( partition, index.row() ); + return ColorUtils::colorForPartition( partition ); else return QVariant(); case SizeRole: