Added custom color dialog to color palette dialog.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* ColorButton.cpp
|
/* ColorButton.cpp
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||||
*
|
*
|
||||||
* This file is part of gLabels-qt.
|
* This file is part of gLabels-qt.
|
||||||
*
|
*
|
||||||
@@ -74,6 +74,8 @@ void ColorButton::setColorNode( ColorNode colorNode )
|
|||||||
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
|
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
|
||||||
setText( "" );
|
setText( "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mDialog->setColorNode( colorNode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* ColorButton.h
|
/* ColorButton.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||||
*
|
*
|
||||||
* This file is part of gLabels-qt.
|
* This file is part of gLabels-qt.
|
||||||
*
|
*
|
||||||
|
|||||||
+41
-45
@@ -1,6 +1,6 @@
|
|||||||
/* ColorHistory.cpp
|
/* ColorHistory.cpp
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||||
*
|
*
|
||||||
* This file is part of gLabels-qt.
|
* This file is part of gLabels-qt.
|
||||||
*
|
*
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "ColorHistory.h"
|
#include "ColorHistory.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
|
||||||
ColorHistory::ColorHistory()
|
ColorHistory::ColorHistory()
|
||||||
@@ -43,74 +44,69 @@ ColorHistory* ColorHistory::instance()
|
|||||||
|
|
||||||
void ColorHistory::addColor( const QColor &color )
|
void ColorHistory::addColor( const QColor &color )
|
||||||
{
|
{
|
||||||
QColor oldColors[MAX_COLORS];
|
QList<QColor> colorList = readColorList();
|
||||||
QColor newColors[MAX_COLORS];
|
|
||||||
int n;
|
|
||||||
|
|
||||||
readColorArray( oldColors, &n );
|
// Remove any occurances of this color already in list
|
||||||
|
colorList.removeAll( color );
|
||||||
|
|
||||||
int i;
|
// Now add to list
|
||||||
newColors[0] = color;
|
colorList.append( color );
|
||||||
for ( i = 0; ( i < (MAX_COLORS-1) ) && (i < n); i++ )
|
|
||||||
|
// Remove oldest colors, if size exceeds current max
|
||||||
|
while ( colorList.size() > MAX_COLORS )
|
||||||
{
|
{
|
||||||
newColors[i+1] = oldColors[i];
|
colorList.removeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
writeColorArray( newColors, i+1 );
|
writeColorList( colorList );
|
||||||
|
|
||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QColor ColorHistory::getColor( int i )
|
QList<QColor> ColorHistory::getColors()
|
||||||
{
|
{
|
||||||
QColor colors[MAX_COLORS];
|
return readColorList();
|
||||||
int n;
|
|
||||||
|
|
||||||
readColorArray( colors, &n );
|
|
||||||
|
|
||||||
if ( (n > 0) && (i < n) )
|
|
||||||
{
|
|
||||||
return colors[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return QColor( 0, 0, 0, 0 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorHistory::readColorArray( QColor array[MAX_COLORS], int* n )
|
QList<QColor> ColorHistory::readColorList()
|
||||||
{
|
{
|
||||||
|
QStringList defaultList;
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
settings.beginGroup( "ColorHistory" );
|
settings.beginGroup( "ColorHistory" );
|
||||||
|
QStringList colorNameList = settings.value( "colors", defaultList ).toStringList();
|
||||||
settings.beginReadArray( "history" );
|
|
||||||
*n = settings.value( "history/size", 0 ).toInt();
|
|
||||||
for ( int i = 0; i < *n; i++ )
|
|
||||||
{
|
|
||||||
settings.setArrayIndex(i);
|
|
||||||
array[i] = settings.value( "color" ).value<QColor>();
|
|
||||||
}
|
|
||||||
settings.endArray();
|
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
|
QList<QColor> colorList;
|
||||||
|
foreach ( QString colorName, colorNameList )
|
||||||
|
{
|
||||||
|
colorList << QColor( colorName );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove oldest colors, if size exceeds current max
|
||||||
|
while ( colorList.size() > MAX_COLORS )
|
||||||
|
{
|
||||||
|
colorList.removeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
return colorList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorHistory::writeColorArray( const QColor array[MAX_COLORS], int n )
|
void ColorHistory::writeColorList( const QList<QColor>& colorList )
|
||||||
{
|
{
|
||||||
QSettings settings;
|
// Build name list
|
||||||
|
QStringList colorNameList;
|
||||||
settings.beginGroup( "ColorHistory" );
|
foreach ( QColor color, colorList )
|
||||||
|
|
||||||
settings.beginWriteArray( "history" );
|
|
||||||
for ( int i = 0; (i < n) && (i < MAX_COLORS); i++ )
|
|
||||||
{
|
{
|
||||||
settings.setArrayIndex(i);
|
colorNameList << color.name();
|
||||||
settings.setValue( "color", array[i] );
|
|
||||||
}
|
}
|
||||||
settings.endArray();
|
|
||||||
|
|
||||||
|
// Save
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup( "ColorHistory" );
|
||||||
|
settings.setValue( "colors", colorNameList );
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* ColorHistory.h
|
/* ColorHistory.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||||
*
|
*
|
||||||
* This file is part of gLabels-qt.
|
* This file is part of gLabels-qt.
|
||||||
*
|
*
|
||||||
@@ -26,14 +26,14 @@
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Barcode Backends Database
|
/// Color History
|
||||||
///
|
///
|
||||||
class ColorHistory : public QObject
|
class ColorHistory : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int MAX_COLORS = 10;
|
static const int MAX_COLORS = 9;
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
// Life Cycle
|
// Life Cycle
|
||||||
@@ -57,15 +57,15 @@ signals:
|
|||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
public:
|
public:
|
||||||
void addColor( const QColor &color );
|
void addColor( const QColor &color );
|
||||||
QColor getColor( int i );
|
QList<QColor> getColors();
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
// Private Methods
|
// Private Methods
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
private:
|
private:
|
||||||
void readColorArray( QColor array[MAX_COLORS], int* n );
|
QList<QColor> readColorList();
|
||||||
void writeColorArray( const QColor array[MAX_COLORS], int n );
|
void writeColorList( const QList<QColor>& colorList );
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* ColorPaletteDialog.cpp
|
/* ColorPaletteDialog.cpp
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||||
*
|
*
|
||||||
* This file is part of gLabels-qt.
|
* This file is part of gLabels-qt.
|
||||||
*
|
*
|
||||||
@@ -27,6 +27,8 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
#include <QColorDialog>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
|
||||||
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = {
|
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = {
|
||||||
@@ -160,6 +162,12 @@ ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ColorPaletteDialog::setColorNode( const ColorNode& colorNode )
|
||||||
|
{
|
||||||
|
mColorNode = colorNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorPaletteDialog::setKeys( const QList<QString> keyList )
|
void ColorPaletteDialog::setKeys( const QList<QString> keyList )
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
@@ -197,7 +205,7 @@ void ColorPaletteDialog::onPaletteItemActivated( int id )
|
|||||||
void ColorPaletteDialog::onHistoryItemActivated( int id )
|
void ColorPaletteDialog::onHistoryItemActivated( int id )
|
||||||
{
|
{
|
||||||
mColorNode.setFieldFlag( false );
|
mColorNode.setFieldFlag( false );
|
||||||
mColorNode.setColor( mColorHistory->getColor( id ) );
|
mColorNode.setColor( mColorHistory->getColors()[id] );
|
||||||
mColorNode.setKey( "" );
|
mColorNode.setKey( "" );
|
||||||
|
|
||||||
emit colorChanged( mColorNode, false );
|
emit colorChanged( mColorNode, false );
|
||||||
@@ -207,8 +215,27 @@ void ColorPaletteDialog::onHistoryItemActivated( int id )
|
|||||||
|
|
||||||
void ColorPaletteDialog::onCustomColorItemActivated()
|
void ColorPaletteDialog::onCustomColorItemActivated()
|
||||||
{
|
{
|
||||||
// TODO
|
QColorDialog dlg( mColorNode.color(), this );
|
||||||
|
dlg.setWindowTitle( tr("Custom Color") );
|
||||||
|
|
||||||
|
if ( dlg.exec() )
|
||||||
|
{
|
||||||
|
ColorNode newColorNode;
|
||||||
|
|
||||||
|
newColorNode.setFieldFlag( false );
|
||||||
|
newColorNode.setColor( dlg.currentColor() );
|
||||||
|
newColorNode.setKey( "" );
|
||||||
|
|
||||||
|
if ( newColorNode != mColorNode )
|
||||||
|
{
|
||||||
|
mColorNode = newColorNode;
|
||||||
|
|
||||||
|
mColorHistory->addColor( mColorNode.color() );
|
||||||
|
|
||||||
|
emit colorChanged( mColorNode, false );
|
||||||
accept();
|
accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -220,14 +247,19 @@ void ColorPaletteDialog::onColorHistoryChanged()
|
|||||||
|
|
||||||
void ColorPaletteDialog::loadCustomColorHistory()
|
void ColorPaletteDialog::loadCustomColorHistory()
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < PALETTE_COLS; i++ )
|
QList<QColor> colorList = mColorHistory->getColors();
|
||||||
{
|
|
||||||
QColor color = mColorHistory->getColor( i );
|
|
||||||
|
|
||||||
if ( color.alpha() != 0 )
|
int id = 0;
|
||||||
|
foreach ( QColor color, colorList )
|
||||||
{
|
{
|
||||||
mHistoryItem[i]->setColor( i, color, QString(tr("Custom color #%d").arg(i) ) );
|
mHistoryItem[id]->setColor( id, color, QString(tr("Custom color #%1").arg(id+1) ) );
|
||||||
mHistoryItem[i]->setEnabled( true );
|
mHistoryItem[id]->setEnabled( true );
|
||||||
|
id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while ( id < PALETTE_ROWS )
|
||||||
|
{
|
||||||
|
mHistoryItem[id]->setEnabled( false );
|
||||||
|
id++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* ColorPaletteDialog.h
|
/* ColorPaletteDialog.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
|
||||||
*
|
*
|
||||||
* This file is part of gLabels-qt.
|
* This file is part of gLabels-qt.
|
||||||
*
|
*
|
||||||
@@ -58,6 +58,7 @@ signals:
|
|||||||
// Public Methods
|
// Public Methods
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
public:
|
public:
|
||||||
|
void setColorNode( const ColorNode& colorNode );
|
||||||
void setKeys( const QList<QString> keyList );
|
void setKeys( const QList<QString> keyList );
|
||||||
void clearKeys();
|
void clearKeys();
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ private:
|
|||||||
QColor mDefaultColor;
|
QColor mDefaultColor;
|
||||||
ColorNode mColorNode;
|
ColorNode mColorNode;
|
||||||
|
|
||||||
static const int PALETTE_COLS = 9;
|
static const int PALETTE_COLS = ColorHistory::MAX_COLORS;
|
||||||
static const int PALETTE_ROWS = 4;
|
static const int PALETTE_ROWS = 4;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ QStringList Settings::recentTemplateList()
|
|||||||
QStringList defaultList;
|
QStringList defaultList;
|
||||||
|
|
||||||
mInstance->beginGroup( "Recent" );
|
mInstance->beginGroup( "Recent" );
|
||||||
QStringList returnList = mInstance->value( "templateList", defaultList ).toStringList();
|
QStringList returnList = mInstance->value( "templates", defaultList ).toStringList();
|
||||||
mInstance->endGroup();
|
mInstance->endGroup();
|
||||||
|
|
||||||
return returnList;
|
return returnList;
|
||||||
@@ -235,7 +235,7 @@ void Settings::addToRecentTemplateList( const QString& name )
|
|||||||
{
|
{
|
||||||
mInstance->beginGroup( "Recent" );
|
mInstance->beginGroup( "Recent" );
|
||||||
|
|
||||||
QStringList list = mInstance->value( "templateList" ).toStringList();
|
QStringList list = mInstance->value( "templates" ).toStringList();
|
||||||
|
|
||||||
list.removeAll( name );
|
list.removeAll( name );
|
||||||
list.prepend( name );
|
list.prepend( name );
|
||||||
@@ -244,7 +244,7 @@ void Settings::addToRecentTemplateList( const QString& name )
|
|||||||
list.removeLast();
|
list.removeLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
mInstance->setValue( "templateList", list );
|
mInstance->setValue( "templates", list );
|
||||||
|
|
||||||
mInstance->endGroup();
|
mInstance->endGroup();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user