Move color handling to a separate namespace
This commit is contained in:
parent
cf4416a171
commit
86481461fd
@ -24,6 +24,7 @@ calamares_add_plugin( partition
|
|||||||
SOURCES
|
SOURCES
|
||||||
BootLoaderModel.cpp
|
BootLoaderModel.cpp
|
||||||
CheckFileSystemJob.cpp
|
CheckFileSystemJob.cpp
|
||||||
|
ColorUtils.cpp
|
||||||
CreatePartitionDialog.cpp
|
CreatePartitionDialog.cpp
|
||||||
CreatePartitionJob.cpp
|
CreatePartitionJob.cpp
|
||||||
CreatePartitionTableJob.cpp
|
CreatePartitionTableJob.cpp
|
||||||
|
85
src/modules/partition/ColorUtils.cpp
Normal file
85
src/modules/partition/ColorUtils.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ColorUtils.h>
|
||||||
|
|
||||||
|
#include <PMUtils.h>
|
||||||
|
|
||||||
|
// CalaPM
|
||||||
|
#include <core/partition.h>
|
||||||
|
|
||||||
|
// Qt
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
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
|
36
src/modules/partition/ColorUtils.h
Normal file
36
src/modules/partition/ColorUtils.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#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 */
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <PartitionModel.h>
|
#include <PartitionModel.h>
|
||||||
|
|
||||||
|
#include <ColorUtils.h>
|
||||||
#include <PartitionInfo.h>
|
#include <PartitionInfo.h>
|
||||||
#include <PMUtils.h>
|
#include <PMUtils.h>
|
||||||
#include <utils/Logger.h>
|
#include <utils/Logger.h>
|
||||||
@ -33,38 +34,6 @@
|
|||||||
// Qt
|
// Qt
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
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 --------------------------------------------
|
//- ResetHelper --------------------------------------------
|
||||||
PartitionModel::ResetHelper::ResetHelper( PartitionModel* model )
|
PartitionModel::ResetHelper::ResetHelper( PartitionModel* model )
|
||||||
: m_model( model )
|
: m_model( model )
|
||||||
@ -182,7 +151,7 @@ PartitionModel::data( const QModelIndex& index, int role ) const
|
|||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
if ( index.column() == NameColumn )
|
if ( index.column() == NameColumn )
|
||||||
return colorForPartition( partition, index.row() );
|
return ColorUtils::colorForPartition( partition );
|
||||||
else
|
else
|
||||||
return QVariant();
|
return QVariant();
|
||||||
case SizeRole:
|
case SizeRole:
|
||||||
|
Loading…
Reference in New Issue
Block a user