Redesigned ColorHistory to include color description.

This commit is contained in:
Jim Evins
2019-07-24 08:25:22 -04:00
parent cd0af020c6
commit f6ecdc64e0
4 changed files with 106 additions and 105 deletions
+45 -41
View File
@@ -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();
}
+4 -4
View File
@@ -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 );
/////////////////////////////////
+8 -4
View File
@@ -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++;
}
+49 -56
View File
@@ -184,22 +184,22 @@
<source>Dialog</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Name:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Increment:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Variable type:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Name:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Initial value:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Increment:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Step size:</source>
<translation type="unfinished"></translation>
@@ -405,6 +405,10 @@
<source>File</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Browse...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Line/Fill</source>
<translation type="unfinished"></translation>
@@ -481,10 +485,6 @@
<source>Opacity:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Browse...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PreferencesDialog</name>
@@ -1056,18 +1056,6 @@
<source>String</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Never</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Per copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Per page</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Integer</source>
<translation type="unfinished"></translation>
@@ -1076,10 +1064,22 @@
<source>Floating Point</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Never</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Per item</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Per copy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Per page</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>VariablesView</name>
@@ -1129,28 +1129,29 @@
</context>
<context>
<name>glabels::ColorPaletteDialog</name>
<message>
<source>Standard Colors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Recent Colors</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Custom color...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Custom Color</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Custom color #%1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use key</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Standard Colors</source>
<source>Custom Color</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Recent Colors</source>
<source>Custom Color %1</source>
<extracomment>%1 = color specification in hex. String must not contain a colon (:).</extracomment>
<translation type="unfinished"></translation>
</message>
</context>
@@ -1768,7 +1769,11 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>Insert Field</source>
<source>Insert field</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use field</source>
<translation type="unfinished"></translation>
</message>
<message>
@@ -1907,18 +1912,6 @@
<source>Shadow</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Selected File...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Insert field</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use field</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>glabels::PrintView</name>
@@ -2148,14 +2141,6 @@
<source>Variables</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Add Variable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit Variable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
@@ -2164,6 +2149,10 @@
<source>Type</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Initial Value</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Increment</source>
<translation type="unfinished"></translation>
@@ -2173,7 +2162,11 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>Initial Value</source>
<source>Add Variable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit Variable</source>
<translation type="unfinished"></translation>
</message>
</context>