Redesigned FieldButton.

This commit is contained in:
Jim Evins
2019-07-20 23:18:03 -04:00
parent d9a41c66f0
commit 4e94933dcf
6 changed files with 182 additions and 166 deletions
+34 -52
View File
@@ -1,6 +1,6 @@
/* FieldButton.cpp /* FieldButton.cpp
* *
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com> * Copyright (C) 2014-2019 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -30,79 +30,61 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
FieldButton::FieldButton( QWidget* parent ) FieldButton::FieldButton( QWidget* parent ) : QPushButton(parent)
: QComboBox(parent)
{ {
setEnabled( false ); setEnabled( false );
setMenu( &mMenu );
connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int)) ); connect( &mMenu, SIGNAL(triggered(QAction*)),
this, SLOT(onMenuActionTriggered(QAction*)) );
} }
void FieldButton::setName( const QString& name ) ///
{ /// Set Keys
mName = name; ///
if ( count() == 0 ) void FieldButton::setKeys( const merge::Merge* merge,
{ const model::Variables* variables )
addItem( mName );
}
else
{
setItemText( 0, mName );
}
// Item 0 is the ComboBox title, not an item intended for selection. So disable it.
const auto* itemModel = qobject_cast<const QStandardItemModel*>(model());
QStandardItem* item = itemModel->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
}
void FieldButton::setKeys( const QStringList& keyList )
{ {
// Clear old keys // Clear old keys
clear(); mMenu.clear();
addItem( mName );
// Item 0 is the ComboBox title, not an item intended for selection. So disable it. // Add merge keys, if any
const auto* itemModel = qobject_cast<const QStandardItemModel*>(model()); mMenu.addSection( tr("Merge fields") );
QStandardItem* item = itemModel->item(0); for ( auto& key : merge->keys() )
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
// Add new keys
if ( keyList.size() > 0 )
{ {
addItems( keyList ); auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
setEnabled( true ); action->setData( key );
} }
else if ( merge->keys().empty() )
{ {
setEnabled( false ); auto* action = mMenu.addAction( "None" );
} action->setEnabled( false );
} }
// Add variable keys, if any
void FieldButton::clearKeys() mMenu.addSection( tr("Variables") );
for ( auto& key : variables->keys() )
{ {
clear(); auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
addItem( mName ); action->setData( key );
}
setEnabled( false ); if ( variables->keys().empty() )
{
auto* action = mMenu.addAction( "None" );
action->setEnabled( false );
} }
setEnabled( !merge->keys().empty() || !variables->keys().empty() );
}
/// ///
/// onMenuKeySelected slot /// onMenuActionTriggered slot
/// ///
void FieldButton::onIndexChanged( int index ) void FieldButton::onMenuActionTriggered( QAction* action )
{ {
if ( index > 0 ) emit keySelected( action->data().toString() );
{
emit keySelected( itemText(index) );
setCurrentIndex( 0 );
}
} }
} // namespace glabels } // namespace glabels
+13 -9
View File
@@ -1,6 +1,6 @@
/* FieldButton.h /* FieldButton.h
* *
* Copyright (C) 2014-2016 Jim Evins <evins@snaught.com> * Copyright (C) 2019 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -22,8 +22,13 @@
#define FieldButton_h #define FieldButton_h
#include <QComboBox> #include "model/Variables.h"
#include <QString> #include "merge/Merge.h"
#include <QAction>
#include <QPushButton>
#include <QMenu>
#include <QStringList>
namespace glabels namespace glabels
@@ -32,7 +37,7 @@ namespace glabels
/// ///
/// Field Button /// Field Button
/// ///
class FieldButton : public QComboBox class FieldButton : public QPushButton
{ {
Q_OBJECT Q_OBJECT
@@ -54,23 +59,22 @@ namespace glabels
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: public:
void setName( const QString& name = "" ); void setKeys( const merge::Merge* merge,
void setKeys( const QStringList& keyList ); const model::Variables* variables );
void clearKeys();
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onIndexChanged( int index ); void onMenuActionTriggered( QAction* action );
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
QString mName; QMenu mMenu;
}; };
+11 -8
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) );
textInsertFieldCombo->setName( tr("Insert Field") ); textInsertFieldButton->setText( tr("Insert field") );
barcodeInsertFieldCombo->setName( tr("Insert Field") ); barcodeInsertFieldButton->setText( tr("Insert field") );
imageFieldCombo->setSpecialSelectionText( tr("Selected File...") ); imageFieldCombo->setSpecialSelectionText( tr("Selected file...") );
setEnabled( false ); setEnabled( false );
hidePages(); hidePages();
@@ -93,11 +93,14 @@ namespace glabels
this, SLOT(onSelectionChanged()) ); this, SLOT(onSelectionChanged()) );
connect( mModel, SIGNAL(mergeSourceChanged()), connect( mModel, SIGNAL(mergeSourceChanged()),
this, SLOT(onMergeSourceChanged()) ); this, SLOT(onFieldsAvailableChanged()) );
connect( mModel, SIGNAL(variablesChanged()),
this, SLOT(onFieldsAvailableChanged()) );
onLabelSizeChanged(); onLabelSizeChanged();
onSelectionChanged(); onSelectionChanged();
onMergeSourceChanged(); onFieldsAvailableChanged();
} }
@@ -498,15 +501,15 @@ namespace glabels
} }
void ObjectEditor::onMergeSourceChanged() void ObjectEditor::onFieldsAvailableChanged()
{ {
if ( !mBlocked ) if ( !mBlocked )
{ {
QStringList keys = mModel->merge()->keys(); QStringList keys = mModel->merge()->keys();
lineColorButton->setKeys( keys ); lineColorButton->setKeys( keys );
fillColorButton->setKeys( keys ); fillColorButton->setKeys( keys );
textInsertFieldCombo->setKeys( keys ); textInsertFieldButton->setKeys( mModel->merge(), mModel->variables() );
barcodeInsertFieldCombo->setKeys( keys ); barcodeInsertFieldButton->setKeys( mModel->merge(), mModel->variables() );
imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() ); imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() );
shadowColorButton->setKeys( keys ); shadowColorButton->setKeys( keys );
} }
+1 -1
View File
@@ -80,7 +80,7 @@ namespace glabels
void onSettingsChanged(); void onSettingsChanged();
void onLabelSizeChanged(); void onLabelSizeChanged();
void onSelectionChanged(); void onSelectionChanged();
void onMergeSourceChanged(); void onFieldsAvailableChanged();
void onObjectChanged(); void onObjectChanged();
void onObjectMoved(); void onObjectMoved();
void onObjectDestroyed(); void onObjectDestroyed();
+100 -92
View File
@@ -70,7 +70,7 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QTabWidget" name="notebook"> <widget class="QTabWidget" name="notebook">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="textPage"> <widget class="QWidget" name="textPage">
<attribute name="title"> <attribute name="title">
@@ -579,7 +579,11 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="glabels::FieldButton" name="textInsertFieldCombo"/> <widget class="glabels::FieldButton" name="textInsertFieldButton">
<property name="text">
<string notr="true">Insert field</string>
</property>
</widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
@@ -729,7 +733,11 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="glabels::FieldButton" name="barcodeInsertFieldCombo"/> <widget class="glabels::FieldButton" name="barcodeInsertFieldButton">
<property name="text">
<string notr="true">Insert field</string>
</property>
</widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_12"> <spacer name="horizontalSpacer_12">
@@ -1526,14 +1534,6 @@
<signal>colorChanged()</signal> <signal>colorChanged()</signal>
</slots> </slots>
</customwidget> </customwidget>
<customwidget>
<class>glabels::FieldButton</class>
<extends>QComboBox</extends>
<header>FieldButton.h</header>
<slots>
<signal>keySelected(QString)</signal>
</slots>
</customwidget>
<customwidget> <customwidget>
<class>glabels::BarcodeMenuButton</class> <class>glabels::BarcodeMenuButton</class>
<extends>QPushButton</extends> <extends>QPushButton</extends>
@@ -1550,6 +1550,14 @@
<signal>selectionChanged()</signal> <signal>selectionChanged()</signal>
</slots> </slots>
</customwidget> </customwidget>
<customwidget>
<class>glabels::FieldButton</class>
<extends>QPushButton</extends>
<header>FieldButton.h</header>
<slots>
<signal>keySelected(QString)</signal>
</slots>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../icons.qrc"/> <include location="../icons.qrc"/>
@@ -1658,8 +1666,8 @@
<slot>onTextControlsChanged()</slot> <slot>onTextControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>157</x> <x>160</x>
<y>333</y> <y>332</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>396</x> <x>396</x>
@@ -1674,8 +1682,8 @@
<slot>onTextControlsChanged()</slot> <slot>onTextControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>198</x> <x>200</x>
<y>333</y> <y>332</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>398</x> <x>398</x>
@@ -1690,8 +1698,8 @@
<slot>onTextControlsChanged()</slot> <slot>onTextControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>238</x> <x>240</x>
<y>333</y> <y>332</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>395</x> <x>395</x>
@@ -1706,8 +1714,8 @@
<slot>onTextControlsChanged()</slot> <slot>onTextControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>284</x> <x>286</x>
<y>333</y> <y>332</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>393</x> <x>393</x>
@@ -1722,8 +1730,8 @@
<slot>onTextControlsChanged()</slot> <slot>onTextControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>325</x> <x>326</x>
<y>333</y> <y>332</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>396</x> <x>396</x>
@@ -1739,7 +1747,7 @@
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>365</x> <x>365</x>
<y>333</y> <y>332</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>397</x> <x>397</x>
@@ -1754,8 +1762,8 @@
<slot>onTextControlsChanged()</slot> <slot>onTextControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>184</x> <x>189</x>
<y>407</y> <y>404</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>394</x> <x>394</x>
@@ -1771,7 +1779,7 @@
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>178</x> <x>178</x>
<y>143</y> <y>139</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>392</x> <x>392</x>
@@ -1786,8 +1794,8 @@
<slot>onLineControlsChanged()</slot> <slot>onLineControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>137</x> <x>136</x>
<y>179</y> <y>174</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1</x> <x>1</x>
@@ -1802,8 +1810,8 @@
<slot>onFillControlsChanged()</slot> <slot>onFillControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>136</x> <x>135</x>
<y>263</y> <y>256</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>6</x> <x>6</x>
@@ -1818,8 +1826,8 @@
<slot>onPositionControlsChanged()</slot> <slot>onPositionControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>159</x> <x>160</x>
<y>142</y> <y>138</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@@ -1834,8 +1842,8 @@
<slot>onPositionControlsChanged()</slot> <slot>onPositionControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>159</x> <x>160</x>
<y>179</y> <y>174</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>325</x> <x>325</x>
@@ -1850,8 +1858,8 @@
<slot>onRectSizeControlsChanged()</slot> <slot>onRectSizeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>159</x> <x>160</x>
<y>265</y> <y>258</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>3</x> <x>3</x>
@@ -1866,8 +1874,8 @@
<slot>onRectSizeControlsChanged()</slot> <slot>onRectSizeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>159</x> <x>160</x>
<y>302</y> <y>294</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>0</x> <x>0</x>
@@ -1882,8 +1890,8 @@
<slot>onResetImageSize()</slot> <slot>onResetImageSize()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>210</x> <x>213</x>
<y>372</y> <y>362</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>4</x> <x>4</x>
@@ -1914,8 +1922,8 @@
<slot>onShadowControlsChanged()</slot> <slot>onShadowControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>165</x> <x>166</x>
<y>142</y> <y>138</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>398</x> <x>398</x>
@@ -1930,8 +1938,8 @@
<slot>onShadowControlsChanged()</slot> <slot>onShadowControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>165</x> <x>166</x>
<y>179</y> <y>174</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>294</x> <x>294</x>
@@ -1946,8 +1954,8 @@
<slot>onShadowControlsChanged()</slot> <slot>onShadowControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>142</x> <x>141</x>
<y>215</y> <y>209</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@@ -1962,8 +1970,8 @@
<slot>onShadowControlsChanged()</slot> <slot>onShadowControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>159</x> <x>162</x>
<y>252</y> <y>245</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@@ -1978,8 +1986,8 @@
<slot>onLineSizeControlsChanged()</slot> <slot>onLineSizeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>174</x> <x>177</x>
<y>456</y> <y>444</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>5</x> <x>5</x>
@@ -1994,8 +2002,8 @@
<slot>onLineSizeControlsChanged()</slot> <slot>onLineSizeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>174</x> <x>177</x>
<y>493</y> <y>480</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1</x> <x>1</x>
@@ -2010,8 +2018,8 @@
<slot>onImageFileButtonClicked()</slot> <slot>onImageFileButtonClicked()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>365</x> <x>367</x>
<y>175</y> <y>168</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>394</x> <x>394</x>
@@ -2035,22 +2043,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>textInsertFieldCombo</sender>
<signal>keySelected(QString)</signal>
<receiver>ObjectEditor</receiver>
<slot>onTextInsertFieldKeySelected(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>239</x>
<y>599</y>
</hint>
<hint type="destinationlabel">
<x>395</x>
<y>645</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>barcodeShowTextCheck</sender> <sender>barcodeShowTextCheck</sender>
<signal>toggled(bool)</signal> <signal>toggled(bool)</signal>
@@ -2058,8 +2050,8 @@
<slot>onBarcodeControlsChanged()</slot> <slot>onBarcodeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>178</x> <x>195</x>
<y>172</y> <y>167</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>4</x> <x>4</x>
@@ -2074,8 +2066,8 @@
<slot>onBarcodeControlsChanged()</slot> <slot>onBarcodeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>164</x> <x>195</x>
<y>204</y> <y>198</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1</x> <x>1</x>
@@ -2091,7 +2083,7 @@
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>126</x> <x>126</x>
<y>239</y> <y>232</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1</x> <x>1</x>
@@ -2115,22 +2107,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>barcodeInsertFieldCombo</sender>
<signal>keySelected(QString)</signal>
<receiver>ObjectEditor</receiver>
<slot>onBarcodeInsertFieldKeySelected(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>239</x>
<y>400</y>
</hint>
<hint type="destinationlabel">
<x>403</x>
<y>625</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>barcodeStyleButton</sender> <sender>barcodeStyleButton</sender>
<signal>selectionChanged()</signal> <signal>selectionChanged()</signal>
@@ -2138,8 +2114,8 @@
<slot>onBarcodeControlsChanged()</slot> <slot>onBarcodeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>178</x> <x>195</x>
<y>140</y> <y>136</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>5</x> <x>5</x>
@@ -2195,6 +2171,38 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>textInsertFieldButton</sender>
<signal>keySelected(QString)</signal>
<receiver>ObjectEditor</receiver>
<slot>onTextInsertFieldKeySelected(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>191</x>
<y>589</y>
</hint>
<hint type="destinationlabel">
<x>227</x>
<y>642</y>
</hint>
</hints>
</connection>
<connection>
<sender>barcodeInsertFieldButton</sender>
<signal>keySelected(QString)</signal>
<receiver>ObjectEditor</receiver>
<slot>onBarcodeInsertFieldKeySelected(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>208</x>
<y>379</y>
</hint>
<hint type="destinationlabel">
<x>205</x>
<y>649</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>onChanged()</slot> <slot>onChanged()</slot>
+19
View File
@@ -1146,6 +1146,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>glabels::FieldButton</name>
<message>
<source>Merge fields</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Variables</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>glabels::File</name> <name>glabels::File</name>
<message> <message>
@@ -1892,6 +1903,14 @@
<source>Selected File...</source> <source>Selected File...</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Insert field</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Selected file...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>glabels::PrintView</name> <name>glabels::PrintView</name>