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