Redesigned ColorHistory to include color description.
This commit is contained in:
+45
-41
@@ -46,23 +46,25 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void ColorHistory::addColor( const QColor &color )
|
||||
void ColorHistory::addColor( const QColor &color, const QString& name )
|
||||
{
|
||||
QList<QColor> colorList = readColorList();
|
||||
QString nameColor = name + ":" + color.name();
|
||||
|
||||
QStringList nameColorList = readNameColorList();
|
||||
|
||||
// Remove any occurrences of this color already in list
|
||||
colorList.removeAll( color );
|
||||
nameColorList.removeAll( nameColor );
|
||||
|
||||
// Now add to list
|
||||
colorList.append( color );
|
||||
nameColorList.append( nameColor );
|
||||
|
||||
// Remove oldest colors, if size exceeds current max
|
||||
while ( colorList.size() > MAX_COLORS )
|
||||
while ( nameColorList.size() > MAX_COLORS )
|
||||
{
|
||||
colorList.removeFirst();
|
||||
nameColorList.removeFirst();
|
||||
}
|
||||
|
||||
writeColorList( colorList );
|
||||
writeNameColorList( nameColorList );
|
||||
|
||||
emit changed();
|
||||
}
|
||||
@@ -70,55 +72,57 @@ namespace glabels
|
||||
|
||||
QList<QColor> ColorHistory::getColors()
|
||||
{
|
||||
return readColorList();
|
||||
}
|
||||
|
||||
|
||||
QColor ColorHistory::getColor( int id )
|
||||
{
|
||||
QList<QColor> colors = readColorList();
|
||||
return colors[id];
|
||||
}
|
||||
|
||||
|
||||
QList<QColor> ColorHistory::readColorList()
|
||||
{
|
||||
QStringList defaultList;
|
||||
QSettings settings;
|
||||
|
||||
settings.beginGroup( "ColorHistory" );
|
||||
QStringList colorNameList = settings.value( "colors", defaultList ).toStringList();
|
||||
settings.endGroup();
|
||||
|
||||
QList<QColor> colorList;
|
||||
foreach ( QString colorName, colorNameList )
|
||||
|
||||
for ( QString& nameColor : readNameColorList() )
|
||||
{
|
||||
colorList << QColor( colorName );
|
||||
}
|
||||
|
||||
// Remove oldest colors, if size exceeds current max
|
||||
while ( colorList.size() > MAX_COLORS )
|
||||
{
|
||||
colorList.removeFirst();
|
||||
QStringList v = nameColor.split( ':' );
|
||||
colorList << QColor( v[1] );
|
||||
}
|
||||
|
||||
return colorList;
|
||||
}
|
||||
|
||||
|
||||
void ColorHistory::writeColorList( const QList<QColor>& colorList )
|
||||
QStringList ColorHistory::getNames()
|
||||
{
|
||||
// Build name list
|
||||
QStringList colorNameList;
|
||||
foreach ( QColor color, colorList )
|
||||
QStringList nameList;
|
||||
|
||||
for ( QString& nameColor : readNameColorList() )
|
||||
{
|
||||
colorNameList << color.name();
|
||||
QStringList v = nameColor.split( ':' );
|
||||
nameList << v[0];
|
||||
}
|
||||
|
||||
return nameList;
|
||||
}
|
||||
|
||||
|
||||
QStringList ColorHistory::readNameColorList()
|
||||
{
|
||||
QStringList defaultList;
|
||||
QSettings settings;
|
||||
|
||||
settings.beginGroup( "ColorHistory" );
|
||||
QStringList nameColorList = settings.value( "colors", defaultList ).toStringList();
|
||||
settings.endGroup();
|
||||
|
||||
// Remove oldest colors, if size exceeds current max
|
||||
while ( nameColorList.size() > MAX_COLORS )
|
||||
{
|
||||
nameColorList.removeFirst();
|
||||
}
|
||||
|
||||
return nameColorList;
|
||||
}
|
||||
|
||||
|
||||
void ColorHistory::writeNameColorList( const QStringList& nameColorList )
|
||||
{
|
||||
// Save
|
||||
QSettings settings;
|
||||
settings.beginGroup( "ColorHistory" );
|
||||
settings.setValue( "colors", colorNameList );
|
||||
settings.setValue( "colors", nameColorList );
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,17 +60,17 @@ namespace glabels
|
||||
// Public Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void addColor( const QColor &color );
|
||||
void addColor( const QColor& color, const QString& name );
|
||||
QList<QColor> getColors();
|
||||
QColor getColor( int id );
|
||||
QStringList getNames();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
QList<QColor> readColorList();
|
||||
void writeColorList( const QList<QColor>& colorList );
|
||||
QStringList readNameColorList();
|
||||
void writeNameColorList( const QStringList& nameColorList );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace glabels
|
||||
{
|
||||
mColorNode = newColorNode;
|
||||
|
||||
mColorHistory->addColor( mColorNode.color() );
|
||||
mColorHistory->addColor( mColorNode.color(), mColorTable[id].trname );
|
||||
|
||||
emit colorChanged( mColorNode, false );
|
||||
accept();
|
||||
@@ -217,7 +217,7 @@ namespace glabels
|
||||
void ColorPaletteDialog::onHistoryItemActivated( int id )
|
||||
{
|
||||
mColorNode.setField( false );
|
||||
mColorNode.setColor( mColorHistory->getColor(id) );
|
||||
mColorNode.setColor( mColorHistory->getColors()[id] );
|
||||
mColorNode.setKey( "" );
|
||||
|
||||
emit colorChanged( mColorNode, false );
|
||||
@@ -253,7 +253,10 @@ namespace glabels
|
||||
{
|
||||
mColorNode = newColorNode;
|
||||
|
||||
mColorHistory->addColor( mColorNode.color() );
|
||||
// TRANSLATORS
|
||||
//: %1 = color specification in hex. String must not contain a colon (:).
|
||||
mColorHistory->addColor( mColorNode.color(),
|
||||
QString(tr("Custom Color %1")).arg(mColorNode.color().name()) );
|
||||
|
||||
emit colorChanged( mColorNode, false );
|
||||
accept();
|
||||
@@ -270,12 +273,13 @@ namespace glabels
|
||||
|
||||
void ColorPaletteDialog::loadCustomColorHistory()
|
||||
{
|
||||
QStringList nameList = mColorHistory->getNames();
|
||||
QList<QColor> colorList = mColorHistory->getColors();
|
||||
|
||||
int id = 0;
|
||||
foreach ( QColor color, colorList )
|
||||
{
|
||||
mHistoryItem[id]->setColor( id, color, QString(tr("Custom color #%1").arg(id+1) ) );
|
||||
mHistoryItem[id]->setColor( id, color, nameList[id] );
|
||||
mHistoryItem[id]->setEnabled( true );
|
||||
id++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user