Added skeletal color palette dialog class.

This commit is contained in:
Jim Evins
2014-07-12 22:21:19 -04:00
parent e689c9a24a
commit f289e43ffb
7 changed files with 365 additions and 22 deletions
+4 -2
View File
@@ -11,7 +11,8 @@ set (glabels_sources
BarcodeStyle.cpp BarcodeStyle.cpp
ColorHistory.cpp ColorHistory.cpp
ColorNode.cpp ColorNode.cpp
ColorPalletteItem.cpp ColorPaletteDialog.cpp
ColorPaletteItem.cpp
ColorSwatch.cpp ColorSwatch.cpp
File.cpp File.cpp
Help.cpp Help.cpp
@@ -35,7 +36,8 @@ set (glabels_qobject_headers
BarcodeMenuButton.h BarcodeMenuButton.h
BarcodeMenuItem.h BarcodeMenuItem.h
ColorHistory.h ColorHistory.h
ColorPalletteItem.h ColorPaletteDialog.h
ColorPaletteItem.h
LabelModel.h LabelModel.h
LabelModelObject.h LabelModelObject.h
LabelModelBoxObject.h LabelModelBoxObject.h
+28 -1
View File
@@ -91,6 +91,15 @@ namespace glabels
} }
///
/// Field Flag Property Setter
///
void ColorNode::setFieldFlag( bool fieldFlag )
{
mFieldFlag = fieldFlag;
}
/// ///
/// Color Property Getter /// Color Property Getter
/// ///
@@ -98,15 +107,33 @@ namespace glabels
{ {
return mColor; return mColor;
} }
///
/// Color Property Setter
///
void ColorNode::setColor( const QColor& color )
{
mColor = color;
}
/// ///
/// Key Property /// Key Property Getter
/// ///
const QString& ColorNode::key( void ) const const QString& ColorNode::key( void ) const
{ {
return mKey; return mKey;
} }
///
/// Key Property Setter
///
void ColorNode::setKey( const QString& key )
{
mKey = key;
}
#if TODO #if TODO
+3
View File
@@ -64,18 +64,21 @@ namespace glabels
// Field Flag Property // Field Flag Property
// //
bool fieldFlag( void ) const; bool fieldFlag( void ) const;
void setFieldFlag( bool fieldFlag );
// //
// Color Property // Color Property
// //
const QColor& color( void ) const; const QColor& color( void ) const;
void setColor( const QColor& color );
// //
// Key Property // Key Property
// //
const QString& key( void ) const; const QString& key( void ) const;
void setKey( const QString& key );
+200
View File
@@ -0,0 +1,200 @@
/* ColorPaletteDialog.cpp
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt 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.
*
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ColorPaletteDialog.h"
#include <QGridLayout>
#include <QPushButton>
namespace glabels
{
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = {
{ "#ef2929", tr("Light Scarlet Red", "Color name") },
{ "#fcaf3e", tr("Light Orange", "Color name") },
{ "#fce94f", tr("Light Butter", "Color name") },
{ "#8ae234", tr("Light Chameleon", "Color name") },
{ "#729fcf", tr("Light Sky Blue", "Color name") },
{ "#ad7fa8", tr("Light Plum", "Color name") },
{ "#e9b96e", tr("Light Chocolate", "Color name") },
{ "#888a85", tr("Light Aluminum 1", "Color name") },
{ "#eeeeec", tr("Light Aluminum 2", "Color name") },
{ "#cc0000", tr("Scarlet Red", "Color name") },
{ "#f57900", tr("Orange", "Color name") },
{ "#edd400", tr("Butter", "Color name") },
{ "#73d216", tr("Chameleon", "Color name") },
{ "#3465a4", tr("Sky Blue", "Color name") },
{ "#75507b", tr("Plum", "Color name") },
{ "#c17d11", tr("Chocolate", "Color name") },
{ "#555753", tr("Aluminum 1", "Color name") },
{ "#d3d7cf", tr("Aluminum 2", "Color name") },
{ "#a40000", tr("Dark Scarlet Red", "Color name") },
{ "#ce5c00", tr("Dark Orange", "Color name") },
{ "#c4a000", tr("Dark Butter", "Color name") },
{ "#4e9a06", tr("Dark Chameleon", "Color name") },
{ "#204a87", tr("Dark Sky Blue", "Color name") },
{ "#5c3566", tr("Dark Plum", "Color name") },
{ "#8f5902", tr("Dark Chocolate", "Color name") },
{ "#2e3436", tr("Dark Aluminum 1", "Color name") },
{ "#babdb6", tr("Dark Aluminum 2", "Color name") },
{ "#000000", tr("Black", "Color name") },
{ "#2e3436", tr("Very Dark Gray", "Color name") },
{ "#555753", tr("Darker Gray", "Color name") },
{ "#888a85", tr("Dark Gray", "Color name") },
{ "#babdb6", tr("Medium Gray", "Color name") },
{ "#d3d7cf", tr("Light Gray", "Color name") },
{ "#eeeeec", tr("Lighter Gray", "Color name") },
{ "#f3f3f3", tr("Very Light Gray", "Color name") },
{ "#ffffff", tr("White", "Color name") }
};
ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
QColor defaultColor,
QColor color,
QWidget* parent )
: QDialog( parent )
{
mColorHistory = ColorHistory::instance();
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
QGridLayout* layout = new QGridLayout();
int iAbsRow = 0;
QPushButton* defaultButton = new QPushButton( defaultLabel );
layout->addWidget( defaultButton, iAbsRow, 0, 1, PALETTE_COLS );
iAbsRow++;
for ( int iRow = 0; iRow < PALETTE_ROWS; iRow++ )
{
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
{
int i = iRow*PALETTE_COLS + iCol;
ColorPaletteItem* item = new ColorPaletteItem( i,
QColor( mColorTable[i].colorSpec ),
mColorTable[i].name );
connect( item, SIGNAL(activated(int)), this, SLOT(onPaletteItemActivated(int)) );
layout->addWidget( item, iAbsRow, iCol );
}
iAbsRow++;
}
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
{
mHistoryItem[iCol] = new ColorPaletteItem( iCol,
QColor(0,0,0,0),
"" );
mHistoryItem[iCol]->setEnabled( false );
connect( mHistoryItem[iCol], SIGNAL(activated(int)), this, SLOT(onHistoryItemActivated(int)) );
layout->addWidget( mHistoryItem[iCol], iAbsRow, iCol );
}
iAbsRow++;
QPushButton* customColorButton = new QPushButton( tr("Custom color") );
layout->addWidget( customColorButton, iAbsRow, 0, 1, PALETTE_COLS );
iAbsRow++;
QPushButton* mergeFieldButton = new QPushButton( "TODO: Field Button" );
layout->addWidget( mergeFieldButton, iAbsRow, 0, 1, PALETTE_COLS );
loadCustomColorHistory();
}
void ColorPaletteDialog::setKeys( const QList<QString> keyList )
{
// TODO
}
void ColorPaletteDialog::clearKeys()
{
// TODO
}
void ColorPaletteDialog::onDefaultButtonClicked()
{
mColorNode.setFieldFlag( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, true );
}
void ColorPaletteDialog::onPaletteItemActivated( int id )
{
mColorNode.setFieldFlag( false );
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, false );
}
void ColorPaletteDialog::onHistoryItemActivated( int id )
{
mColorNode.setFieldFlag( false );
mColorNode.setColor( mColorHistory->getColor( id ) );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, false );
}
void ColorPaletteDialog::onCustomColorButtonClicked()
{
// TODO
}
void ColorPaletteDialog::onColorHistoryChanged()
{
loadCustomColorHistory();
}
void ColorPaletteDialog::loadCustomColorHistory()
{
for ( int i; i < PALETTE_COLS; i++ )
{
QColor color = mColorHistory->getColor( i );
if ( color.alpha() != 0 )
{
mHistoryItem[i]->setColor( i, color, QString(tr("Custom color #%d").arg(i) ) );
mHistoryItem[i]->setEnabled( true );
}
}
}
}
+111
View File
@@ -0,0 +1,111 @@
/* ColorPaletteDialog.h
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt 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.
*
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_ColorPaletteDialog_h
#define glabels_ColorPaletteDialog_h
#include <QObject>
#include <QDialog>
#include "ColorNode.h"
#include "ColorHistory.h"
#include "ColorPaletteItem.h"
namespace glabels
{
///
/// Barcode Backends Database
///
class ColorPaletteDialog : public QDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteDialog( const QString& defaultLabel,
QColor defaultColor,
QColor color,
QWidget* parent );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged( ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setKeys( const QList<QString> keyList );
void clearKeys();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onDefaultButtonClicked();
void onPaletteItemActivated( int id );
void onHistoryItemActivated( int id );
void onCustomColorButtonClicked();
void onColorHistoryChanged();
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
void loadCustomColorHistory();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
ColorNode mColorNode;
static const int PALETTE_COLS = 9;
static const int PALETTE_ROWS = 4;
typedef struct {
QString colorSpec;
QString name;
} ColorTableEntry;
static ColorTableEntry mColorTable[];
ColorHistory* mColorHistory;
ColorPaletteItem* mHistoryItem[PALETTE_COLS];
};
}
#endif // glabels_ColorPaletteDialog_h
@@ -1,4 +1,4 @@
/* ColorPalletteItem.cpp /* ColorPaletteItem.cpp
* *
* Copyright (C) 2014 Jim Evins <evins@snaught.com> * Copyright (C) 2014 Jim Evins <evins@snaught.com>
* *
@@ -18,7 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ColorPalletteItem.h" #include "ColorPaletteItem.h"
#include "ColorSwatch.h" #include "ColorSwatch.h"
@@ -39,10 +39,10 @@ namespace glabels
/// ///
/// Constructor From Data /// Constructor From Data
/// ///
ColorPalletteItem::ColorPalletteItem( int id, ColorPaletteItem::ColorPaletteItem( int id,
const QColor& color, const QColor& color,
const QString& tip, const QString& tip,
QWidget* parent ) QWidget* parent )
: QPushButton(parent), mId(id), mColor(color), mTip(tip) : QPushButton(parent), mId(id), mColor(color), mTip(tip)
{ {
setIcon( QIcon( ColorSwatch( wSwatch, hSwatch, color ) ) ); setIcon( QIcon( ColorSwatch( wSwatch, hSwatch, color ) ) );
@@ -55,9 +55,9 @@ namespace glabels
/// ///
/// Color Property Setter /// Color Property Setter
/// ///
void ColorPalletteItem::setColor( int id, void ColorPaletteItem::setColor( int id,
const QColor& color, const QColor& color,
const QString& tip ) const QString& tip )
{ {
mId = id; mId = id;
mColor = color; mColor = color;
@@ -71,7 +71,7 @@ namespace glabels
/// ///
/// onClicked slot /// onClicked slot
/// ///
void ColorPalletteItem::onClicked() void ColorPaletteItem::onClicked()
{ {
emit activated( mId ); emit activated( mId );
} }
@@ -1,4 +1,4 @@
/* ColorPalletteItem.h /* ColorPaletteItem.h
* *
* Copyright (C) 2014 Jim Evins <evins@snaught.com> * Copyright (C) 2014 Jim Evins <evins@snaught.com>
* *
@@ -18,8 +18,8 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef glabels_ColorPalletteItem_h #ifndef glabels_ColorPaletteItem_h
#define glabels_ColorPalletteItem_h #define glabels_ColorPaletteItem_h
#include <QPushButton> #include <QPushButton>
#include <QColor> #include <QColor>
@@ -31,7 +31,7 @@ namespace glabels
/// ///
/// Barcode Menu Item /// Barcode Menu Item
/// ///
class ColorPalletteItem : public QPushButton class ColorPaletteItem : public QPushButton
{ {
Q_OBJECT Q_OBJECT
@@ -39,10 +39,10 @@ namespace glabels
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
ColorPalletteItem( int id, ColorPaletteItem( int id,
const QColor& color, const QColor& color,
const QString& tip, const QString& tip,
QWidget* parent = 0 ); QWidget* parent = 0 );
///////////////////////////////// /////////////////////////////////
@@ -81,4 +81,4 @@ namespace glabels
} }
#endif // glabels_ColorPalletteItem_h #endif // glabels_ColorPaletteItem_h