mirror of https://github.com/cutefishos/calamares
Move color handling to a separate namespace
parent
cf4416a171
commit
86481461fd
@ -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
|
||||||
@ -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 */
|
||||||
Loading…
Reference in New Issue