From f41461ef261d964e378d6d9a9d3cbb42496a371a Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 3 Aug 2019 17:16:14 -0400 Subject: [PATCH] Added color variable type. --- glabels/ColorButton.cpp | 10 ++- glabels/ColorButton.h | 6 +- glabels/ColorPaletteDialog.cpp | 27 +++++--- glabels/ColorPaletteDialog.h | 1 + glabels/EditVariableDialog.cpp | 21 +++++- glabels/EditVariableDialog.h | 1 + glabels/ObjectEditor.cpp | 6 +- glabels/VariablesView.cpp | 2 +- glabels/ui/EditVariableDialog.ui | 114 ++++++++++++++++++++----------- glabels/ui/ObjectEditor.ui | 99 ++++++++++++++++----------- model/Variable.cpp | 22 ++++++ model/Variable.h | 3 +- translations/glabels_C.ts | 43 ++++++++---- 13 files changed, 248 insertions(+), 107 deletions(-) diff --git a/glabels/ColorButton.cpp b/glabels/ColorButton.cpp index 9789628..28ea4c8 100644 --- a/glabels/ColorButton.cpp +++ b/glabels/ColorButton.cpp @@ -48,8 +48,9 @@ namespace glabels void ColorButton::init( const QString& defaultLabel, - const QColor& defaultColor, - const QColor& color ) + const QColor& defaultColor, + const QColor& color, + bool showUseFieldButton ) { mDefaultColor = defaultColor; mColorNode = model::ColorNode( color ); @@ -61,7 +62,10 @@ namespace glabels setText( "" ); setCheckable( true ); - mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color ); + mDialog = new ColorPaletteDialog( defaultLabel, + defaultColor, + color, + showUseFieldButton ); connect( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) ); connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)), diff --git a/glabels/ColorButton.h b/glabels/ColorButton.h index a7155d8..81ba63d 100644 --- a/glabels/ColorButton.h +++ b/glabels/ColorButton.h @@ -58,7 +58,11 @@ namespace glabels // Public Methods ///////////////////////////////// public: - void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color ); + void init( const QString& defaultLabel, + const QColor& defaultColor, + const QColor& color, + bool showUseFieldButton = true ); + void setColorNode( model::ColorNode colorNode ); void setColor( QColor color ); void setToDefault(); diff --git a/glabels/ColorPaletteDialog.cpp b/glabels/ColorPaletteDialog.cpp index 3986fe4..9ad496a 100644 --- a/glabels/ColorPaletteDialog.cpp +++ b/glabels/ColorPaletteDialog.cpp @@ -85,6 +85,7 @@ namespace glabels ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel, const QColor& defaultColor, const QColor& color, + bool showUseFieldButton, QWidget* parent ) : QDialog( parent ) { @@ -167,14 +168,21 @@ namespace glabels vLayout->addWidget( customColorButton ); // - // Construct "Use key" Button + // Construct "Use field" Button // - mFieldButton = new FieldButton(); - mFieldButton->setText( tr("Use key") ); - mFieldButton->setAutoDefault( false ); - mFieldButton->setDefault( false ); - connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) ); - vLayout->addWidget( mFieldButton ); + if ( showUseFieldButton ) + { + mFieldButton = new FieldButton(); + mFieldButton->setText( tr("Use substitution field") ); + mFieldButton->setAutoDefault( false ); + mFieldButton->setDefault( false ); + connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) ); + vLayout->addWidget( mFieldButton ); + } + else + { + mFieldButton = nullptr; + } setLayout( vLayout ); @@ -191,7 +199,10 @@ namespace glabels void ColorPaletteDialog::setKeys( const merge::Merge* merge, const model::Variables* variables ) { - mFieldButton->setKeys( merge, variables ); + if (mFieldButton) + { + mFieldButton->setKeys( merge, variables ); + } } diff --git a/glabels/ColorPaletteDialog.h b/glabels/ColorPaletteDialog.h index 518fd75..6e1a22c 100644 --- a/glabels/ColorPaletteDialog.h +++ b/glabels/ColorPaletteDialog.h @@ -49,6 +49,7 @@ namespace glabels ColorPaletteDialog( const QString& defaultLabel, const QColor& defaultColor, const QColor& color, + bool showUseFieldButton = true, QWidget* parent = nullptr ); diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index 9893da4..a685e73 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -31,7 +31,8 @@ namespace const QVector allTypes = { glabels::model::Variable::Type::STRING, glabels::model::Variable::Type::INTEGER, - glabels::model::Variable::Type::FLOATING_POINT + glabels::model::Variable::Type::FLOATING_POINT, + glabels::model::Variable::Type::COLOR }; // All variable increments. (must be in sorted order) @@ -58,6 +59,11 @@ namespace glabels QRegularExpression reIdentifier( "[a-zA-Z_][a-zA-Z_0-9]*" ); nameEdit->setValidator( new QRegularExpressionValidator( reIdentifier ) ); + colorValueButton->init( tr("Default"), + QColor(0,0,0,255), + QColor(0,0,0,255), + false ); + for ( auto type : allTypes ) { typeCombo->addItem( model::Variable::typeToI18nString( type ) ); @@ -80,6 +86,7 @@ namespace glabels typeCombo->setCurrentIndex( static_cast(variable.type()) ); nameEdit->setText( variable.name() ); valueEdit->setText( variable.initialValue() ); + colorValueButton->setColor( QColor( variable.initialValue() ) ); incrementCombo->setCurrentIndex( static_cast(variable.increment()) ); stepSizeEdit->setText( variable.stepSize() ); @@ -127,6 +134,16 @@ namespace glabels } + /// + /// colorValueButton Changed + /// + void EditVariableDialog::onColorValueButtonChanged() + { + valueEdit->setText( colorValueButton->colorNode().color().name() ); + validateCurrentInputs(); + } + + /// /// incrementCombo Changed /// @@ -173,6 +190,8 @@ namespace glabels } + colorValueButton->setVisible( type == model::Variable::Type::COLOR ); + bool isNumeric = ( type == model::Variable::Type::INTEGER ) || ( type == model::Variable::Type::FLOATING_POINT ); diff --git a/glabels/EditVariableDialog.h b/glabels/EditVariableDialog.h index 8c57a20..6c71d61 100644 --- a/glabels/EditVariableDialog.h +++ b/glabels/EditVariableDialog.h @@ -57,6 +57,7 @@ namespace glabels void onNameEditChanged(); void onTypeComboChanged(); void onValueEditChanged(); + void onColorValueButtonChanged(); void onIncrementComboChanged(); void onStepSizeEditChanged(); diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index f31415a..5f9b42d 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -67,9 +67,9 @@ namespace glabels barcodeColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) ); shadowColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) ); - textInsertFieldButton->setText( tr("Insert field") ); - barcodeInsertFieldButton->setText( tr("Insert field") ); - imageFieldButton->setText( tr("Use field") ); + textInsertFieldButton->setText( tr("Insert substitution field") ); + barcodeInsertFieldButton->setText( tr("Insert subsitution field") ); + imageFieldButton->setText( tr("Use substitution field") ); setEnabled( false ); hidePages(); diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index 339d901..ea13f33 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -63,7 +63,7 @@ namespace glabels typeHeaderItem->setFlags( typeHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_TYPE, typeHeaderItem ); - auto* valueHeaderItem = new QTableWidgetItem( tr("Initial Value") ); + auto* valueHeaderItem = new QTableWidgetItem( tr("Value") ); valueHeaderItem->setFlags( valueHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_VALUE, valueHeaderItem ); diff --git a/glabels/ui/EditVariableDialog.ui b/glabels/ui/EditVariableDialog.ui index 77b5e93..72f8575 100644 --- a/glabels/ui/EditVariableDialog.ui +++ b/glabels/ui/EditVariableDialog.ui @@ -67,16 +67,6 @@ - - - - Type: - - - - - - @@ -94,6 +84,27 @@ + + + + Type: + + + + + + + + + + + + + + + + + @@ -111,6 +122,16 @@ + + + glabels::ColorButton + QPushButton +
ColorButton.h
+ + colorChanged() + +
+
@@ -120,8 +141,8 @@ accept() - 227 - 214 + 236 + 287 157 @@ -136,8 +157,8 @@ reject() - 295 - 220 + 304 + 287 286 @@ -152,8 +173,8 @@ onTypeComboChanged() - 179 - 30 + 252 + 70 33 @@ -161,22 +182,6 @@ - - valueEdit - textChanged(QString) - EditVariableDialog - onValueEditChanged() - - - 212 - 86 - - - 63 - 166 - - - incrementCombo currentIndexChanged(int) @@ -184,8 +189,8 @@ onIncrementComboChanged() - 170 - 123 + 100 + 223 97 @@ -200,8 +205,8 @@ onStepSizeEditChanged() - 344 - 125 + 440 + 223 333 @@ -216,8 +221,8 @@ onNameEditChanged() - 371 - 62 + 440 + 103 393 @@ -225,6 +230,38 @@ + + valueEdit + textChanged(QString) + EditVariableDialog + onValueEditChanged() + + + 318 + 129 + + + 459 + 157 + + + + + colorValueButton + colorChanged() + EditVariableDialog + onColorValueButtonChanged() + + + 406 + 114 + + + 458 + 122 + + + onTypeComboChanged() @@ -232,5 +269,6 @@ onIncrementComboChanged() onStepSizeEditChanged() onNameEditChanged() + onColorValueButtonChanged() diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index e46be75..bcfa051 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -786,46 +786,67 @@ - - - - 0 - 0 - - - - - 231 - 0 - - - - true - - - None - - + + + + + + 0 + 0 + + + + + 231 + 0 + + + + true + + + None + + + + + + + + 0 + 0 + + + + Browse... + + + + - - - - - 0 - 0 - - - - Browse... - - - - - - - Use field - - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Use field + + + + diff --git a/model/Variable.cpp b/model/Variable.cpp index 5156928..fc52e14 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -86,6 +86,9 @@ namespace glabels mFloatingPointValue = mInitialValue.toDouble(); mFloatingPointStep = mStepSize.toDouble(); break; + case Type::COLOR: + // do nothing + break; } } @@ -105,6 +108,9 @@ namespace glabels case Type::FLOATING_POINT: mFloatingPointValue += mFloatingPointStep; break; + case Type::COLOR: + // do nothing + break; } } } @@ -125,6 +131,9 @@ namespace glabels case Type::FLOATING_POINT: mFloatingPointValue += mFloatingPointStep; break; + case Type::COLOR: + // do nothing + break; } } } @@ -145,6 +154,9 @@ namespace glabels case Type::FLOATING_POINT: mFloatingPointValue += mFloatingPointStep; break; + case Type::COLOR: + // do nothing + break; } } } @@ -160,6 +172,8 @@ namespace glabels return QString::number( mIntegerValue ); case Type::FLOATING_POINT: return QString::number( mFloatingPointValue, 'g', 15 ); + case Type::COLOR: + return mInitialValue; default: return mInitialValue; } @@ -176,6 +190,8 @@ namespace glabels return tr("Integer"); case Type::FLOATING_POINT: return tr("Floating Point"); + case Type::COLOR: + return tr("Color"); default: return tr("String"); } @@ -192,6 +208,8 @@ namespace glabels return "integer"; case Type::FLOATING_POINT: return "float"; + case Type::COLOR: + return "color"; default: return "string"; } @@ -212,6 +230,10 @@ namespace glabels { return Type::FLOATING_POINT; } + if ( id == "color" ) + { + return Type::COLOR; + } else { return Type::STRING; // Default diff --git a/model/Variable.h b/model/Variable.h index 95f3dec..3dfad13 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -40,7 +40,8 @@ namespace glabels { STRING, INTEGER, - FLOATING_POINT + FLOATING_POINT, + COLOR }; enum class Increment diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index a81f287..426a73d 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1084,6 +1084,10 @@ Per page + + Color + + VariablesView @@ -1169,6 +1173,17 @@ Custom color #%1 + + Use substitution field + + + + + glabels::EditVariableDialog + + Default + + glabels::FieldButton @@ -1783,14 +1798,6 @@ Default - - Insert field - - - - Use field - - Original size @@ -1935,6 +1942,18 @@ Selected File... + + Insert substitution field + + + + Insert subsitution field + + + + Use substitution field + + glabels::PrintView @@ -2172,10 +2191,6 @@ Type - - Initial Value - - Increment @@ -2192,6 +2207,10 @@ Edit Variable + + Value + + glabels::barcode::Backends