Redesigned image selection in ObjectEditor to use new FieldCombo widget.

This commit is contained in:
Jim Evins
2019-03-30 12:50:30 -04:00
parent 54a66dfd8f
commit 87cc5d7e22
7 changed files with 365 additions and 112 deletions
+2
View File
@@ -18,6 +18,7 @@ set (glabels_sources
Cursors.cpp Cursors.cpp
EditVariableDialog.cpp EditVariableDialog.cpp
FieldButton.cpp FieldButton.cpp
FieldCombo.cpp
File.cpp File.cpp
Help.cpp Help.cpp
Icons.cpp Icons.cpp
@@ -55,6 +56,7 @@ set (glabels_qobject_headers
ColorPaletteButtonItem.h ColorPaletteButtonItem.h
EditVariableDialog.h EditVariableDialog.h
FieldButton.h FieldButton.h
FieldCombo.h
File.h File.h
LabelEditor.h LabelEditor.h
MainWindow.h MainWindow.h
+146
View File
@@ -0,0 +1,146 @@
/* FieldCombo.cpp
*
* Copyright (C) 2014-2019 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FieldCombo.h"
#include <QLineEdit>
#include <QStandardItemModel>
namespace glabels
{
///
/// Constructor
///
FieldCombo::FieldCombo( QWidget* parent )
: QComboBox(parent)
{
connect( this, SIGNAL(currentIndexChanged(int)),
this, SLOT(onIndexChanged(int)) );
}
///
/// Is current selection the alternative default selection?
///
bool FieldCombo::isCurrentSelectionSpecial() const
{
return currentIndex() == 0;
}
///
/// Return current selection
///
QString FieldCombo::currentSelection() const
{
return mFieldNames[ currentIndex() ];
}
///
/// Set current selection to special
///
void FieldCombo::setCurrentSelectionToSpecial()
{
setCurrentIndex( 0 );
}
///
/// Set current selection
///
void FieldCombo::setCurrentSelection( const QString& key )
{
setCurrentText( QString( "${%1}" ).arg( key ) );
}
///
/// Set alternative default selection
///
void FieldCombo::setSpecialSelectionText( const QString& name )
{
mName = name;
if ( count() == 0 )
{
addItem( mName );
}
else
{
setItemText( 0, mName );
}
}
///
/// Set field selections
///
void FieldCombo::setFieldSelections( const merge::Merge* merge,
const model::Variables* variables )
{
// Clear old keys
clear();
mFieldNames.clear();
// Add default alt selection
addItem( mName );
mFieldNames.append( mName );
// Add merge fields, if any
for ( auto& key : merge->keys() )
{
addItem( QString( "${%1}" ).arg( key ) );
mFieldNames.append( key );
}
// Add variables, if any
for ( auto& key : variables->keys() )
{
addItem( QString( "${%1}" ).arg( key ) );
mFieldNames.append( key );
}
}
///
/// Clear field selections
///
void FieldCombo::clearFieldSelections()
{
clear();
mFieldNames.clear();
addItem( mName );
mFieldNames.append( mName );
}
///
/// onMenuKeySelected slot
///
void FieldCombo::onIndexChanged( int index )
{
emit selectionChanged();
}
} // namespace glabels
+94
View File
@@ -0,0 +1,94 @@
/* FieldCombo.h
*
* Copyright (C) 2014-2019 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FieldCombo_h
#define FieldCombo_h
#include "model/Variables.h"
#include "merge/Merge.h"
#include <QComboBox>
#include <QString>
#include <QVector>
namespace glabels
{
///
/// Field Combo
///
class FieldCombo : public QComboBox
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldCombo( QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void selectionChanged();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
bool isCurrentSelectionSpecial() const;
QString currentSelection() const;
void setCurrentSelectionToSpecial();
void setCurrentSelection( const QString& key );
void setSpecialSelectionText( const QString& name = "" );
void setFieldSelections( const merge::Merge* merge,
const model::Variables* variables );
void clearFieldSelections();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onIndexChanged( int index );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QString mName;
QVector<QString> mFieldNames;
};
}
#endif // FieldCombo_h
+20 -7
View File
@@ -69,7 +69,7 @@ namespace glabels
textInsertFieldCombo->setName( tr("Insert Field") ); textInsertFieldCombo->setName( tr("Insert Field") );
barcodeInsertFieldCombo->setName( tr("Insert Field") ); barcodeInsertFieldCombo->setName( tr("Insert Field") );
imageFieldCombo->setName( tr("Key") ); imageFieldCombo->setSpecialSelectionText( tr("Selected File...") );
setEnabled( false ); setEnabled( false );
hidePages(); hidePages();
@@ -120,13 +120,14 @@ namespace glabels
model::TextNode filenameNode = mObject->filenameNode(); model::TextNode filenameNode = mObject->filenameNode();
imageFileSelectionBox->setVisible( !filenameNode.isField() );
if ( filenameNode.isField() ) if ( filenameNode.isField() )
{ {
QString field = QString("${%1}").arg( filenameNode.data() ); imageFieldCombo->setCurrentSelection( filenameNode.data() );
imageFilenameLineEdit->setText( field );
} }
else else
{ {
imageFieldCombo->setCurrentSelectionToSpecial();
imageFilenameLineEdit->setText( filenameNode.data() ); imageFilenameLineEdit->setText( filenameNode.data() );
} }
@@ -506,7 +507,7 @@ namespace glabels
fillColorButton->setKeys( keys ); fillColorButton->setKeys( keys );
textInsertFieldCombo->setKeys( keys ); textInsertFieldCombo->setKeys( keys );
barcodeInsertFieldCombo->setKeys( keys ); barcodeInsertFieldCombo->setKeys( keys );
imageFieldCombo->setKeys( keys ); imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() );
shadowColorButton->setKeys( keys ); shadowColorButton->setKeys( keys );
} }
} }
@@ -616,10 +617,22 @@ namespace glabels
} }
void ObjectEditor::onImageKeySelected( QString key ) void ObjectEditor::onImageComboChanged()
{ {
mUndoRedoModel->checkpoint( tr("Set image") ); imageFileSelectionBox->setVisible( imageFieldCombo->isCurrentSelectionSpecial() );
mObject->setFilenameNode( model::TextNode( true, key ) );
if ( mObject )
{
mUndoRedoModel->checkpoint( tr("Set image") );
if ( imageFieldCombo->isCurrentSelectionSpecial() )
{
mObject->setFilenameNode( model::TextNode( false, imageFilenameLineEdit->text() ) );
}
else
{
mObject->setFilenameNode( model::TextNode( true, imageFieldCombo->currentSelection() ) );
}
}
} }
+1 -1
View File
@@ -87,7 +87,7 @@ namespace glabels
void onLineControlsChanged(); void onLineControlsChanged();
void onFillControlsChanged(); void onFillControlsChanged();
void onImageFileButtonClicked(); void onImageFileButtonClicked();
void onImageKeySelected( QString key ); void onImageComboChanged();
void onPositionControlsChanged(); void onPositionControlsChanged();
void onRectSizeControlsChanged(); void onRectSizeControlsChanged();
void onLineSizeControlsChanged(); void onLineSizeControlsChanged();
+94 -88
View File
@@ -31,7 +31,7 @@
<property name="windowTitle"> <property name="windowTitle">
<string notr="true">Form</string> <string notr="true">Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item> <item>
@@ -763,77 +763,74 @@
<property name="title"> <property name="title">
<string>File</string> <string>File</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_12"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item row="0" column="0"> <item>
<layout class="QVBoxLayout" name="verticalLayout_5"> <widget class="glabels::FieldCombo" name="imageFieldCombo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item> <item>
<widget class="QLineEdit" name="imageFilenameLineEdit"> <property name="text">
<property name="sizePolicy"> <string notr="true">Selected File...</string>
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> </property>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>231</width>
<height>0</height>
</size>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>None</string>
</property>
</widget>
</item> </item>
<item> </widget>
<layout class="QHBoxLayout" name="horizontalLayout_17" stretch="1,0,1"> </item>
<item> <item>
<widget class="QPushButton" name="imageFileButton"> <widget class="QWidget" name="imageFileSelectionBox" native="true">
<property name="sizePolicy"> <layout class="QHBoxLayout" name="horizontalLayout_27">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <property name="leftMargin">
<horstretch>0</horstretch> <number>0</number>
<verstretch>0</verstretch> </property>
</sizepolicy> <property name="topMargin">
</property> <number>0</number>
<property name="text"> </property>
<string>Select File...</string> <property name="rightMargin">
</property> <number>0</number>
</widget> </property>
</item> <property name="bottomMargin">
<item> <number>0</number>
<widget class="QLabel" name="label"> </property>
<property name="sizePolicy"> <item>
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> <widget class="QLineEdit" name="imageFilenameLineEdit">
<horstretch>0</horstretch> <property name="sizePolicy">
<verstretch>0</verstretch> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
</sizepolicy> <horstretch>0</horstretch>
</property> <verstretch>0</verstretch>
<property name="text"> </sizepolicy>
<string>or</string> </property>
</property> <property name="minimumSize">
</widget> <size>
</item> <width>231</width>
<item> <height>0</height>
<widget class="glabels::FieldButton" name="imageFieldCombo"> </size>
<property name="sizePolicy"> </property>
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <property name="readOnly">
<horstretch>0</horstretch> <bool>true</bool>
<verstretch>0</verstretch> </property>
</sizepolicy> <property name="placeholderText">
</property> <string>None</string>
<item> </property>
<property name="text"> </widget>
<string>Select Merge Field...</string> </item>
</property> <item>
</item> <widget class="QPushButton" name="imageBrowseButton">
</widget> <property name="sizePolicy">
</item> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
</layout> <horstretch>0</horstretch>
</item> <verstretch>0</verstretch>
</layout> </sizepolicy>
</property>
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@@ -1545,6 +1542,14 @@
<signal>selectionChanged()</signal> <signal>selectionChanged()</signal>
</slots> </slots>
</customwidget> </customwidget>
<customwidget>
<class>glabels::FieldCombo</class>
<extends>QComboBox</extends>
<header>FieldCombo.h</header>
<slots>
<signal>selectionChanged()</signal>
</slots>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../icons.qrc"/> <include location="../icons.qrc"/>
@@ -1999,13 +2004,13 @@
</hints> </hints>
</connection> </connection>
<connection> <connection>
<sender>imageFileButton</sender> <sender>imageBrowseButton</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
<receiver>ObjectEditor</receiver> <receiver>ObjectEditor</receiver>
<slot>onImageFileButtonClicked()</slot> <slot>onImageFileButtonClicked()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>133</x> <x>365</x>
<y>175</y> <y>175</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
@@ -2014,22 +2019,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>imageFieldCombo</sender>
<signal>keySelected(QString)</signal>
<receiver>ObjectEditor</receiver>
<slot>onImageKeySelected(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>302</x>
<y>175</y>
</hint>
<hint type="destinationlabel">
<x>397</x>
<y>32</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>textEdit</sender> <sender>textEdit</sender>
<signal>textChanged()</signal> <signal>textChanged()</signal>
@@ -2190,6 +2179,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>imageFieldCombo</sender>
<signal>selectionChanged()</signal>
<receiver>ObjectEditor</receiver>
<slot>onImageComboChanged()</slot>
<hints>
<hint type="sourcelabel">
<x>283</x>
<y>118</y>
</hint>
<hint type="destinationlabel">
<x>398</x>
<y>18</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>onChanged()</slot> <slot>onChanged()</slot>
@@ -2206,5 +2211,6 @@
<slot>onTextInsertFieldKeySelected(QString)</slot> <slot>onTextInsertFieldKeySelected(QString)</slot>
<slot>onBarcodeControlsChanged()</slot> <slot>onBarcodeControlsChanged()</slot>
<slot>onBarcodeInsertFieldKeySelected(QString)</slot> <slot>onBarcodeInsertFieldKeySelected(QString)</slot>
<slot>onImageComboChanged()</slot>
</slots> </slots>
</ui> </ui>
+8 -16
View File
@@ -405,18 +405,6 @@
<source>File</source> <source>File</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Select File...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>or</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Select Merge Field...</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Line/Fill</source> <source>Line/Fill</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@@ -493,6 +481,10 @@
<source>Opacity:</source> <source>Opacity:</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Browse...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PreferencesDialog</name> <name>PreferencesDialog</name>
@@ -1760,10 +1752,6 @@
<source>Insert Field</source> <source>Insert Field</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Key</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Original size</source> <source>Original size</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@@ -1900,6 +1888,10 @@
<source>Shadow</source> <source>Shadow</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Selected File...</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>glabels::PrintView</name> <name>glabels::PrintView</name>