diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 99a5cf3..1adfc5d 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -11,7 +11,8 @@ set (glabels_sources BarcodeStyle.cpp ColorHistory.cpp ColorNode.cpp - ColorPalletteItem.cpp + ColorPaletteDialog.cpp + ColorPaletteItem.cpp ColorSwatch.cpp File.cpp Help.cpp @@ -35,7 +36,8 @@ set (glabels_qobject_headers BarcodeMenuButton.h BarcodeMenuItem.h ColorHistory.h - ColorPalletteItem.h + ColorPaletteDialog.h + ColorPaletteItem.h LabelModel.h LabelModelObject.h LabelModelBoxObject.h diff --git a/glabels/ColorNode.cpp b/glabels/ColorNode.cpp index 0829e88..a9128fa 100644 --- a/glabels/ColorNode.cpp +++ b/glabels/ColorNode.cpp @@ -91,6 +91,15 @@ namespace glabels } + /// + /// Field Flag Property Setter + /// + void ColorNode::setFieldFlag( bool fieldFlag ) + { + mFieldFlag = fieldFlag; + } + + /// /// Color Property Getter /// @@ -98,15 +107,33 @@ namespace glabels { return mColor; } + + + /// + /// Color Property Setter + /// + void ColorNode::setColor( const QColor& color ) + { + mColor = color; + } /// - /// Key Property + /// Key Property Getter /// const QString& ColorNode::key( void ) const { return mKey; } + + + /// + /// Key Property Setter + /// + void ColorNode::setKey( const QString& key ) + { + mKey = key; + } #if TODO diff --git a/glabels/ColorNode.h b/glabels/ColorNode.h index 9013207..7d86760 100644 --- a/glabels/ColorNode.h +++ b/glabels/ColorNode.h @@ -64,18 +64,21 @@ namespace glabels // Field Flag Property // bool fieldFlag( void ) const; + void setFieldFlag( bool fieldFlag ); // // Color Property // const QColor& color( void ) const; + void setColor( const QColor& color ); // // Key Property // const QString& key( void ) const; + void setKey( const QString& key ); diff --git a/glabels/ColorPaletteDialog.cpp b/glabels/ColorPaletteDialog.cpp new file mode 100644 index 0000000..8ee93f7 --- /dev/null +++ b/glabels/ColorPaletteDialog.cpp @@ -0,0 +1,200 @@ +/* ColorPaletteDialog.cpp + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#include "ColorPaletteDialog.h" + +#include +#include + + +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 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 ); + } + } + } + +} diff --git a/glabels/ColorPaletteDialog.h b/glabels/ColorPaletteDialog.h new file mode 100644 index 0000000..3f72982 --- /dev/null +++ b/glabels/ColorPaletteDialog.h @@ -0,0 +1,111 @@ +/* ColorPaletteDialog.h + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#ifndef glabels_ColorPaletteDialog_h +#define glabels_ColorPaletteDialog_h + +#include +#include + +#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 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 diff --git a/glabels/ColorPalletteItem.cpp b/glabels/ColorPaletteItem.cpp similarity index 79% rename from glabels/ColorPalletteItem.cpp rename to glabels/ColorPaletteItem.cpp index 9f9bf37..771b4a1 100644 --- a/glabels/ColorPalletteItem.cpp +++ b/glabels/ColorPaletteItem.cpp @@ -1,4 +1,4 @@ -/* ColorPalletteItem.cpp +/* ColorPaletteItem.cpp * * Copyright (C) 2014 Jim Evins * @@ -18,7 +18,7 @@ * along with gLabels-qt. If not, see . */ -#include "ColorPalletteItem.h" +#include "ColorPaletteItem.h" #include "ColorSwatch.h" @@ -39,10 +39,10 @@ namespace glabels /// /// Constructor From Data /// - ColorPalletteItem::ColorPalletteItem( int id, - const QColor& color, - const QString& tip, - QWidget* parent ) + ColorPaletteItem::ColorPaletteItem( int id, + const QColor& color, + const QString& tip, + QWidget* parent ) : QPushButton(parent), mId(id), mColor(color), mTip(tip) { setIcon( QIcon( ColorSwatch( wSwatch, hSwatch, color ) ) ); @@ -55,9 +55,9 @@ namespace glabels /// /// Color Property Setter /// - void ColorPalletteItem::setColor( int id, - const QColor& color, - const QString& tip ) + void ColorPaletteItem::setColor( int id, + const QColor& color, + const QString& tip ) { mId = id; mColor = color; @@ -71,7 +71,7 @@ namespace glabels /// /// onClicked slot /// - void ColorPalletteItem::onClicked() + void ColorPaletteItem::onClicked() { emit activated( mId ); } diff --git a/glabels/ColorPalletteItem.h b/glabels/ColorPaletteItem.h similarity index 81% rename from glabels/ColorPalletteItem.h rename to glabels/ColorPaletteItem.h index 3efeb2e..990a553 100644 --- a/glabels/ColorPalletteItem.h +++ b/glabels/ColorPaletteItem.h @@ -1,4 +1,4 @@ -/* ColorPalletteItem.h +/* ColorPaletteItem.h * * Copyright (C) 2014 Jim Evins * @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorPalletteItem_h -#define glabels_ColorPalletteItem_h +#ifndef glabels_ColorPaletteItem_h +#define glabels_ColorPaletteItem_h #include #include @@ -31,7 +31,7 @@ namespace glabels /// /// Barcode Menu Item /// - class ColorPalletteItem : public QPushButton + class ColorPaletteItem : public QPushButton { Q_OBJECT @@ -39,10 +39,10 @@ namespace glabels // Life Cycle ///////////////////////////////// public: - ColorPalletteItem( int id, - const QColor& color, - const QString& tip, - QWidget* parent = 0 ); + ColorPaletteItem( int id, + const QColor& color, + const QString& tip, + QWidget* parent = 0 ); ///////////////////////////////// @@ -81,4 +81,4 @@ namespace glabels } -#endif // glabels_ColorPalletteItem_h +#endif // glabels_ColorPaletteItem_h