Use field button for image selection.

This commit is contained in:
Jim Evins
2016-10-22 19:56:06 -04:00
parent 016e86e9c7
commit 34da3fe17c
6 changed files with 144 additions and 138 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
vLayout->addWidget( hline4 ); vLayout->addWidget( hline4 );
mMergeFieldCombo = new QComboBox(); mMergeFieldCombo = new QComboBox();
mMergeFieldCombo->addItem( tr("Merge field...") ); mMergeFieldCombo->addItem( tr("Merge key...") );
mMergeFieldCombo->setMinimumSize( 34, 34 ); mMergeFieldCombo->setMinimumSize( 34, 34 );
mMergeFieldCombo->setFrame( false ); mMergeFieldCombo->setFrame( false );
mMergeFieldCombo->setEnabled( false ); mMergeFieldCombo->setEnabled( false );
+33 -44
View File
@@ -1,6 +1,6 @@
/* FieldButton.cpp /* FieldButton.cpp
* *
* Copyright (C) 2014 Jim Evins <evins@snaught.com> * Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -20,54 +20,56 @@
#include "FieldButton.h" #include "FieldButton.h"
#include <QStandardItemModel>
#include <QLineEdit>
/// ///
/// Constructor /// Constructor
/// ///
FieldButton::FieldButton( QWidget* parent ) FieldButton::FieldButton( QWidget* parent )
: QPushButton(parent) : QComboBox(parent)
{ {
setEnabled( false ); setEnabled( false );
mMenu = new FieldMenu(); connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int)) );
setMenu( mMenu );
connect( mMenu, SIGNAL(keySelected(const QString&)), this, SLOT(onMenuKeySelected(const QString&)) );
} }
void FieldButton::setName( const QString& name ) void FieldButton::setName( const QString& name )
{ {
if ( name.isNull() || name.isEmpty() ) mName = name;
if ( count() == 0 )
{ {
setText( tr("(None)") ); addItem( mName );
mLabelIsKey = false;
} }
else else
{ {
setText( name ); setItemText( 0, mName );
mLabelIsKey = true;
} }
// Item 0 is the ComboBox title, not an item intended for selection. So disable it.
const QStandardItemModel* itemModel = qobject_cast<const QStandardItemModel*>(model());
QStandardItem* item = itemModel->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
} }
void FieldButton::setKeys( const QList<QString>& keyList ) void FieldButton::setKeys( const QStringList& keyList )
{ {
mMenu->setKeys( keyList ); // Clear old keys
clear();
addItem( mName );
if ( keyList.length() > 0 ) // Item 0 is the ComboBox title, not an item intended for selection. So disable it.
{ const QStandardItemModel* itemModel = qobject_cast<const QStandardItemModel*>(model());
mKey = keyList.first(); QStandardItem* item = itemModel->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
if ( mLabelIsKey ) // Add new keys
if ( keyList.size() > 0 )
{ {
setText( mKey ); addItems( keyList );
}
else
{
setText( tr("(None)") );
}
setEnabled( true ); setEnabled( true );
} }
else else
@@ -79,36 +81,23 @@ void FieldButton::setKeys( const QList<QString>& keyList )
void FieldButton::clearKeys() void FieldButton::clearKeys()
{ {
if ( !mLabelIsKey ) clear();
{ addItem( mName );
setText( tr("(None)") );
}
setEnabled( false ); setEnabled( false );
} }
///
/// key getter
///
QString FieldButton::key() const
{
return mKey;
}
/// ///
/// onMenuKeySelected slot /// onMenuKeySelected slot
/// ///
void FieldButton::onMenuKeySelected( const QString& key ) void FieldButton::onIndexChanged( int index )
{ {
mKey = key; if ( index > 0 )
if ( mLabelIsKey )
{ {
setText( key ); emit keySelected( itemText(index) );
}
emit keySelected( key ); setCurrentIndex( 0 );
}
} }
+7 -17
View File
@@ -1,6 +1,6 @@
/* FieldButton.h /* FieldButton.h
* *
* Copyright (C) 2014 Jim Evins <evins@snaught.com> * Copyright (C) 2014-2016 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -21,15 +21,14 @@
#ifndef FieldButton_h #ifndef FieldButton_h
#define FieldButton_h #define FieldButton_h
#include <QPushButton> #include <QComboBox>
#include <QString> #include <QString>
#include "FieldMenu.h"
/// ///
/// Field Button /// Field Button
/// ///
class FieldButton : public QPushButton class FieldButton : public QComboBox
{ {
Q_OBJECT Q_OBJECT
@@ -44,14 +43,7 @@ public:
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void keySelected( const QString& key ); void keySelected( QString key );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
QString key() const;
///////////////////////////////// /////////////////////////////////
@@ -59,7 +51,7 @@ public:
///////////////////////////////// /////////////////////////////////
public: public:
void setName( const QString& name = "" ); void setName( const QString& name = "" );
void setKeys( const QList<QString>& keyList ); void setKeys( const QStringList& keyList );
void clearKeys(); void clearKeys();
@@ -67,16 +59,14 @@ public:
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onMenuKeySelected( const QString& key ); void onIndexChanged( int index );
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
FieldMenu* mMenu; QString mName;
QString mKey;
bool mLabelIsKey;
}; };
+13 -3
View File
@@ -50,6 +50,8 @@ ObjectEditor::ObjectEditor( QWidget *parent )
fillColorButton->init( "No fill", QColor(0,0,0,0), QColor(0,0,0,255) ); fillColorButton->init( "No fill", QColor(0,0,0,0), QColor(0,0,0,255) );
shadowColorButton->init( "Default", QColor(0,0,0,255), QColor(0,0,0,255) ); shadowColorButton->init( "Default", QColor(0,0,0,255), QColor(0,0,0,255) );
imageFieldCombo->setName( "Key" );
setEnabled( false ); setEnabled( false );
hidePages(); hidePages();
@@ -362,9 +364,11 @@ void ObjectEditor::onMergeSourceChanged()
{ {
if ( !mBlocked ) if ( !mBlocked )
{ {
lineColorButton->setKeys( mModel->merge()->keys() ); QStringList keys = mModel->merge()->keys();
fillColorButton->setKeys( mModel->merge()->keys() ); lineColorButton->setKeys( keys );
shadowColorButton->setKeys( mModel->merge()->keys() ); fillColorButton->setKeys( keys );
imageFieldCombo->setKeys( keys );
shadowColorButton->setKeys( keys );
} }
} }
@@ -444,6 +448,12 @@ void ObjectEditor::onImageFileButtonClicked()
} }
void ObjectEditor::onImageKeySelected(QString key )
{
qDebug() << "Key = " << key;
}
void ObjectEditor::onPositionControlsChanged() void ObjectEditor::onPositionControlsChanged()
{ {
if ( !mBlocked ) if ( !mBlocked )
+1
View File
@@ -78,6 +78,7 @@ private slots:
void onLineControlsChanged(); void onLineControlsChanged();
void onFillControlsChanged(); void onFillControlsChanged();
void onImageFileButtonClicked(); void onImageFileButtonClicked();
void onImageKeySelected(QString key );
void onPositionControlsChanged(); void onPositionControlsChanged();
void onRectSizeControlsChanged(); void onRectSizeControlsChanged();
void onLineSizeControlsChanged(); void onLineSizeControlsChanged();
+80 -64
View File
@@ -451,7 +451,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="FieldButton" name="textInsertFieldButton"> <widget class="QPushButton" name="textInsertFieldButton">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
@@ -679,7 +679,7 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_16"> <layout class="QHBoxLayout" name="horizontalLayout_16">
<item> <item>
<widget class="FieldButton" name="barcodeFieldButton"> <widget class="QPushButton" name="barcodeFieldButton">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
@@ -766,37 +766,8 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout_12"> <layout class="QGridLayout" name="gridLayout_12">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QFormLayout" name="formLayout_8"> <layout class="QVBoxLayout" name="verticalLayout_5">
<property name="fieldGrowthPolicy"> <item>
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="1" column="1">
<widget class="QPushButton" name="imageFileButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>File...</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="FieldButton" name="imageMergeFieldButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Merge field...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<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">
@@ -818,6 +789,51 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17" stretch="1,0,1">
<item>
<widget class="QPushButton" name="imageFileButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Select File...</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>or</string>
</property>
</widget>
</item>
<item>
<widget class="FieldButton" name="imageFieldCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Select Merge Field...</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
@@ -1488,10 +1504,10 @@
</customwidget> </customwidget>
<customwidget> <customwidget>
<class>FieldButton</class> <class>FieldButton</class>
<extends>QPushButton</extends> <extends>QComboBox</extends>
<header>FieldButton.h</header> <header>FieldButton.h</header>
<slots> <slots>
<signal>keySelected()</signal> <signal>keySelected(QString)</signal>
</slots> </slots>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
@@ -1570,8 +1586,8 @@
<slot>onChanged()</slot> <slot>onChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>223</x> <x>236</x>
<y>202</y> <y>200</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>395</x> <x>395</x>
@@ -1586,8 +1602,8 @@
<slot>onChanged()</slot> <slot>onChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>134</x> <x>138</x>
<y>237</y> <y>235</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>396</x> <x>396</x>
@@ -1618,8 +1634,8 @@
<slot>onChanged()</slot> <slot>onChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>208</x> <x>219</x>
<y>318</y> <y>315</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>398</x> <x>398</x>
@@ -1634,8 +1650,8 @@
<slot>onChanged()</slot> <slot>onChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>249</x> <x>271</x>
<y>318</y> <y>315</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>395</x> <x>395</x>
@@ -1682,8 +1698,8 @@
<slot>onChanged()</slot> <slot>onChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>267</x> <x>271</x>
<y>360</y> <y>357</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>397</x> <x>397</x>
@@ -1698,8 +1714,8 @@
<slot>onChanged()</slot> <slot>onChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>149</x> <x>180</x>
<y>390</y> <y>389</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>394</x> <x>394</x>
@@ -1906,8 +1922,8 @@
<slot>onFillControlsChanged()</slot> <slot>onFillControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>124</x> <x>146</x>
<y>237</y> <y>236</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>6</x> <x>6</x>
@@ -1923,7 +1939,7 @@
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>153</x> <x>153</x>
<y>132</y> <y>128</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@@ -1986,8 +2002,8 @@
<slot>onResetImageSize()</slot> <slot>onResetImageSize()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>211</x> <x>228</x>
<y>324</y> <y>323</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>4</x> <x>4</x>
@@ -2066,8 +2082,8 @@
<slot>onShadowControlsChanged()</slot> <slot>onShadowControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>115</x> <x>151</x>
<y>229</y> <y>227</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>406</x> <x>406</x>
@@ -2098,8 +2114,8 @@
<slot>onLineSizeControlsChanged()</slot> <slot>onLineSizeControlsChanged()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>120</x> <x>164</x>
<y>437</y> <y>424</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1</x> <x>1</x>
@@ -2124,18 +2140,18 @@
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>imageMergeFieldButton</sender> <sender>imageFieldCombo</sender>
<signal>keySelected()</signal> <signal>keySelected(QString)</signal>
<receiver>ObjectEditor</receiver> <receiver>ObjectEditor</receiver>
<slot>onImageKeySelected()</slot> <slot>onImageKeySelected(QString)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>351</x> <x>343</x>
<y>147</y> <y>151</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>7</x> <x>397</x>
<y>143</y> <y>32</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@@ -2150,6 +2166,6 @@
<slot>onShadowControlsChanged()</slot> <slot>onShadowControlsChanged()</slot>
<slot>onLineSizeControlsChanged()</slot> <slot>onLineSizeControlsChanged()</slot>
<slot>onImageFileButtonClicked()</slot> <slot>onImageFileButtonClicked()</slot>
<slot>onImageKeySelected()</slot> <slot>onImageKeySelected(QString)</slot>
</slots> </slots>
</ui> </ui>