Added color variable type.

This commit is contained in:
Jim Evins
2019-08-03 17:16:14 -04:00
parent dd41aa3dd7
commit f41461ef26
13 changed files with 248 additions and 107 deletions
+6 -2
View File
@@ -49,7 +49,8 @@ namespace glabels
void ColorButton::init( const QString& defaultLabel, void ColorButton::init( const QString& defaultLabel,
const QColor& defaultColor, const QColor& defaultColor,
const QColor& color ) const QColor& color,
bool showUseFieldButton )
{ {
mDefaultColor = defaultColor; mDefaultColor = defaultColor;
mColorNode = model::ColorNode( color ); mColorNode = model::ColorNode( color );
@@ -61,7 +62,10 @@ namespace glabels
setText( "" ); setText( "" );
setCheckable( true ); 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( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) );
connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)), connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)),
+5 -1
View File
@@ -58,7 +58,11 @@ namespace glabels
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: 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 setColorNode( model::ColorNode colorNode );
void setColor( QColor color ); void setColor( QColor color );
void setToDefault(); void setToDefault();
+13 -2
View File
@@ -85,6 +85,7 @@ namespace glabels
ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel, ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor, const QColor& defaultColor,
const QColor& color, const QColor& color,
bool showUseFieldButton,
QWidget* parent ) QWidget* parent )
: QDialog( parent ) : QDialog( parent )
{ {
@@ -167,14 +168,21 @@ namespace glabels
vLayout->addWidget( customColorButton ); vLayout->addWidget( customColorButton );
// //
// Construct "Use key" Button // Construct "Use field" Button
// //
if ( showUseFieldButton )
{
mFieldButton = new FieldButton(); mFieldButton = new FieldButton();
mFieldButton->setText( tr("Use key") ); mFieldButton->setText( tr("Use substitution field") );
mFieldButton->setAutoDefault( false ); mFieldButton->setAutoDefault( false );
mFieldButton->setDefault( false ); mFieldButton->setDefault( false );
connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) ); connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) );
vLayout->addWidget( mFieldButton ); vLayout->addWidget( mFieldButton );
}
else
{
mFieldButton = nullptr;
}
setLayout( vLayout ); setLayout( vLayout );
@@ -190,9 +198,12 @@ namespace glabels
void ColorPaletteDialog::setKeys( const merge::Merge* merge, void ColorPaletteDialog::setKeys( const merge::Merge* merge,
const model::Variables* variables ) const model::Variables* variables )
{
if (mFieldButton)
{ {
mFieldButton->setKeys( merge, variables ); mFieldButton->setKeys( merge, variables );
} }
}
void ColorPaletteDialog::onPaletteItemActivated( int id ) void ColorPaletteDialog::onPaletteItemActivated( int id )
+1
View File
@@ -49,6 +49,7 @@ namespace glabels
ColorPaletteDialog( const QString& defaultLabel, ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor, const QColor& defaultColor,
const QColor& color, const QColor& color,
bool showUseFieldButton = true,
QWidget* parent = nullptr ); QWidget* parent = nullptr );
+20 -1
View File
@@ -31,7 +31,8 @@ namespace
const QVector<glabels::model::Variable::Type> allTypes = { const QVector<glabels::model::Variable::Type> allTypes = {
glabels::model::Variable::Type::STRING, glabels::model::Variable::Type::STRING,
glabels::model::Variable::Type::INTEGER, 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) // All variable increments. (must be in sorted order)
@@ -58,6 +59,11 @@ namespace glabels
QRegularExpression reIdentifier( "[a-zA-Z_][a-zA-Z_0-9]*" ); QRegularExpression reIdentifier( "[a-zA-Z_][a-zA-Z_0-9]*" );
nameEdit->setValidator( new QRegularExpressionValidator( reIdentifier ) ); nameEdit->setValidator( new QRegularExpressionValidator( reIdentifier ) );
colorValueButton->init( tr("Default"),
QColor(0,0,0,255),
QColor(0,0,0,255),
false );
for ( auto type : allTypes ) for ( auto type : allTypes )
{ {
typeCombo->addItem( model::Variable::typeToI18nString( type ) ); typeCombo->addItem( model::Variable::typeToI18nString( type ) );
@@ -80,6 +86,7 @@ namespace glabels
typeCombo->setCurrentIndex( static_cast<int>(variable.type()) ); typeCombo->setCurrentIndex( static_cast<int>(variable.type()) );
nameEdit->setText( variable.name() ); nameEdit->setText( variable.name() );
valueEdit->setText( variable.initialValue() ); valueEdit->setText( variable.initialValue() );
colorValueButton->setColor( QColor( variable.initialValue() ) );
incrementCombo->setCurrentIndex( static_cast<int>(variable.increment()) ); incrementCombo->setCurrentIndex( static_cast<int>(variable.increment()) );
stepSizeEdit->setText( variable.stepSize() ); stepSizeEdit->setText( variable.stepSize() );
@@ -127,6 +134,16 @@ namespace glabels
} }
///
/// colorValueButton Changed
///
void EditVariableDialog::onColorValueButtonChanged()
{
valueEdit->setText( colorValueButton->colorNode().color().name() );
validateCurrentInputs();
}
/// ///
/// incrementCombo Changed /// incrementCombo Changed
/// ///
@@ -173,6 +190,8 @@ namespace glabels
} }
colorValueButton->setVisible( type == model::Variable::Type::COLOR );
bool isNumeric = ( type == model::Variable::Type::INTEGER ) || bool isNumeric = ( type == model::Variable::Type::INTEGER ) ||
( type == model::Variable::Type::FLOATING_POINT ); ( type == model::Variable::Type::FLOATING_POINT );
+1
View File
@@ -57,6 +57,7 @@ namespace glabels
void onNameEditChanged(); void onNameEditChanged();
void onTypeComboChanged(); void onTypeComboChanged();
void onValueEditChanged(); void onValueEditChanged();
void onColorValueButtonChanged();
void onIncrementComboChanged(); void onIncrementComboChanged();
void onStepSizeEditChanged(); void onStepSizeEditChanged();
+3 -3
View File
@@ -67,9 +67,9 @@ namespace glabels
barcodeColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) ); 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) ); shadowColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) );
textInsertFieldButton->setText( tr("Insert field") ); textInsertFieldButton->setText( tr("Insert substitution field") );
barcodeInsertFieldButton->setText( tr("Insert field") ); barcodeInsertFieldButton->setText( tr("Insert subsitution field") );
imageFieldButton->setText( tr("Use field") ); imageFieldButton->setText( tr("Use substitution field") );
setEnabled( false ); setEnabled( false );
hidePages(); hidePages();
+1 -1
View File
@@ -63,7 +63,7 @@ namespace glabels
typeHeaderItem->setFlags( typeHeaderItem->flags() ^ Qt::ItemIsEditable ); typeHeaderItem->setFlags( typeHeaderItem->flags() ^ Qt::ItemIsEditable );
table->setHorizontalHeaderItem( I_COL_TYPE, typeHeaderItem ); 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 ); valueHeaderItem->setFlags( valueHeaderItem->flags() ^ Qt::ItemIsEditable );
table->setHorizontalHeaderItem( I_COL_VALUE, valueHeaderItem ); table->setHorizontalHeaderItem( I_COL_VALUE, valueHeaderItem );
+76 -38
View File
@@ -67,16 +67,6 @@
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="nameEdit"/> <widget class="QLineEdit" name="nameEdit"/>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="valueEdit"/>
</item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
@@ -94,6 +84,27 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="typeCombo"/> <widget class="QComboBox" name="typeCombo"/>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="valueEdit"/>
</item>
<item>
<widget class="glabels::ColorButton" name="colorValueButton">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -111,6 +122,16 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>glabels::ColorButton</class>
<extends>QPushButton</extends>
<header>ColorButton.h</header>
<slots>
<signal>colorChanged()</signal>
</slots>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
@@ -120,8 +141,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>227</x> <x>236</x>
<y>214</y> <y>287</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@@ -136,8 +157,8 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>295</x> <x>304</x>
<y>220</y> <y>287</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>286</x> <x>286</x>
@@ -152,8 +173,8 @@
<slot>onTypeComboChanged()</slot> <slot>onTypeComboChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>179</x> <x>252</x>
<y>30</y> <y>70</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>33</x> <x>33</x>
@@ -161,22 +182,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>valueEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>EditVariableDialog</receiver>
<slot>onValueEditChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>212</x>
<y>86</y>
</hint>
<hint type="destinationlabel">
<x>63</x>
<y>166</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>incrementCombo</sender> <sender>incrementCombo</sender>
<signal>currentIndexChanged(int)</signal> <signal>currentIndexChanged(int)</signal>
@@ -184,8 +189,8 @@
<slot>onIncrementComboChanged()</slot> <slot>onIncrementComboChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>170</x> <x>100</x>
<y>123</y> <y>223</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>97</x> <x>97</x>
@@ -200,8 +205,8 @@
<slot>onStepSizeEditChanged()</slot> <slot>onStepSizeEditChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>344</x> <x>440</x>
<y>125</y> <y>223</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>333</x> <x>333</x>
@@ -216,8 +221,8 @@
<slot>onNameEditChanged()</slot> <slot>onNameEditChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>371</x> <x>440</x>
<y>62</y> <y>103</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>393</x> <x>393</x>
@@ -225,6 +230,38 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>valueEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>EditVariableDialog</receiver>
<slot>onValueEditChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>318</x>
<y>129</y>
</hint>
<hint type="destinationlabel">
<x>459</x>
<y>157</y>
</hint>
</hints>
</connection>
<connection>
<sender>colorValueButton</sender>
<signal>colorChanged()</signal>
<receiver>EditVariableDialog</receiver>
<slot>onColorValueButtonChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>406</x>
<y>114</y>
</hint>
<hint type="destinationlabel">
<x>458</x>
<y>122</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>onTypeComboChanged()</slot> <slot>onTypeComboChanged()</slot>
@@ -232,5 +269,6 @@
<slot>onIncrementComboChanged()</slot> <slot>onIncrementComboChanged()</slot>
<slot>onStepSizeEditChanged()</slot> <slot>onStepSizeEditChanged()</slot>
<slot>onNameEditChanged()</slot> <slot>onNameEditChanged()</slot>
<slot>onColorValueButtonChanged()</slot>
</slots> </slots>
</ui> </ui>
+23 -2
View File
@@ -786,6 +786,8 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QLineEdit" name="imageFilenameLineEdit"> <widget class="QLineEdit" name="imageFilenameLineEdit">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@@ -807,7 +809,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item>
<widget class="QPushButton" name="imageBrowseButton"> <widget class="QPushButton" name="imageBrowseButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@@ -820,7 +822,24 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> </layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_27">
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="glabels::FieldButton" name="imageFieldButton"> <widget class="glabels::FieldButton" name="imageFieldButton">
<property name="text"> <property name="text">
<string notr="true">Use field</string> <string notr="true">Use field</string>
@@ -828,6 +847,8 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>
+22
View File
@@ -86,6 +86,9 @@ namespace glabels
mFloatingPointValue = mInitialValue.toDouble(); mFloatingPointValue = mInitialValue.toDouble();
mFloatingPointStep = mStepSize.toDouble(); mFloatingPointStep = mStepSize.toDouble();
break; break;
case Type::COLOR:
// do nothing
break;
} }
} }
@@ -105,6 +108,9 @@ namespace glabels
case Type::FLOATING_POINT: case Type::FLOATING_POINT:
mFloatingPointValue += mFloatingPointStep; mFloatingPointValue += mFloatingPointStep;
break; break;
case Type::COLOR:
// do nothing
break;
} }
} }
} }
@@ -125,6 +131,9 @@ namespace glabels
case Type::FLOATING_POINT: case Type::FLOATING_POINT:
mFloatingPointValue += mFloatingPointStep; mFloatingPointValue += mFloatingPointStep;
break; break;
case Type::COLOR:
// do nothing
break;
} }
} }
} }
@@ -145,6 +154,9 @@ namespace glabels
case Type::FLOATING_POINT: case Type::FLOATING_POINT:
mFloatingPointValue += mFloatingPointStep; mFloatingPointValue += mFloatingPointStep;
break; break;
case Type::COLOR:
// do nothing
break;
} }
} }
} }
@@ -160,6 +172,8 @@ namespace glabels
return QString::number( mIntegerValue ); return QString::number( mIntegerValue );
case Type::FLOATING_POINT: case Type::FLOATING_POINT:
return QString::number( mFloatingPointValue, 'g', 15 ); return QString::number( mFloatingPointValue, 'g', 15 );
case Type::COLOR:
return mInitialValue;
default: default:
return mInitialValue; return mInitialValue;
} }
@@ -176,6 +190,8 @@ namespace glabels
return tr("Integer"); return tr("Integer");
case Type::FLOATING_POINT: case Type::FLOATING_POINT:
return tr("Floating Point"); return tr("Floating Point");
case Type::COLOR:
return tr("Color");
default: default:
return tr("String"); return tr("String");
} }
@@ -192,6 +208,8 @@ namespace glabels
return "integer"; return "integer";
case Type::FLOATING_POINT: case Type::FLOATING_POINT:
return "float"; return "float";
case Type::COLOR:
return "color";
default: default:
return "string"; return "string";
} }
@@ -212,6 +230,10 @@ namespace glabels
{ {
return Type::FLOATING_POINT; return Type::FLOATING_POINT;
} }
if ( id == "color" )
{
return Type::COLOR;
}
else else
{ {
return Type::STRING; // Default return Type::STRING; // Default
+2 -1
View File
@@ -40,7 +40,8 @@ namespace glabels
{ {
STRING, STRING,
INTEGER, INTEGER,
FLOATING_POINT FLOATING_POINT,
COLOR
}; };
enum class Increment enum class Increment
+31 -12
View File
@@ -1084,6 +1084,10 @@
<source>Per page</source> <source>Per page</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Color</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>VariablesView</name> <name>VariablesView</name>
@@ -1169,6 +1173,17 @@
<source>Custom color #%1</source> <source>Custom color #%1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Use substitution field</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>glabels::EditVariableDialog</name>
<message>
<source>Default</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>glabels::FieldButton</name> <name>glabels::FieldButton</name>
@@ -1783,14 +1798,6 @@
<source>Default</source> <source>Default</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Insert field</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use field</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Original size</source> <source>Original size</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@@ -1935,6 +1942,18 @@
<source>Selected File...</source> <source>Selected File...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Insert substitution field</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Insert subsitution field</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use substitution field</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>glabels::PrintView</name> <name>glabels::PrintView</name>
@@ -2172,10 +2191,6 @@
<source>Type</source> <source>Type</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Initial Value</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Increment</source> <source>Increment</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@@ -2192,6 +2207,10 @@
<source>Edit Variable</source> <source>Edit Variable</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Value</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>glabels::barcode::Backends</name> <name>glabels::barcode::Backends</name>