Redesigned image selection in ObjectEditor to use new FieldCombo widget.
This commit is contained in:
@@ -18,6 +18,7 @@ set (glabels_sources
|
||||
Cursors.cpp
|
||||
EditVariableDialog.cpp
|
||||
FieldButton.cpp
|
||||
FieldCombo.cpp
|
||||
File.cpp
|
||||
Help.cpp
|
||||
Icons.cpp
|
||||
@@ -55,6 +56,7 @@ set (glabels_qobject_headers
|
||||
ColorPaletteButtonItem.h
|
||||
EditVariableDialog.h
|
||||
FieldButton.h
|
||||
FieldCombo.h
|
||||
File.h
|
||||
LabelEditor.h
|
||||
MainWindow.h
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -69,7 +69,7 @@ namespace glabels
|
||||
|
||||
textInsertFieldCombo->setName( tr("Insert Field") );
|
||||
barcodeInsertFieldCombo->setName( tr("Insert Field") );
|
||||
imageFieldCombo->setName( tr("Key") );
|
||||
imageFieldCombo->setSpecialSelectionText( tr("Selected File...") );
|
||||
|
||||
setEnabled( false );
|
||||
hidePages();
|
||||
@@ -120,13 +120,14 @@ namespace glabels
|
||||
|
||||
model::TextNode filenameNode = mObject->filenameNode();
|
||||
|
||||
imageFileSelectionBox->setVisible( !filenameNode.isField() );
|
||||
if ( filenameNode.isField() )
|
||||
{
|
||||
QString field = QString("${%1}").arg( filenameNode.data() );
|
||||
imageFilenameLineEdit->setText( field );
|
||||
imageFieldCombo->setCurrentSelection( filenameNode.data() );
|
||||
}
|
||||
else
|
||||
{
|
||||
imageFieldCombo->setCurrentSelectionToSpecial();
|
||||
imageFilenameLineEdit->setText( filenameNode.data() );
|
||||
}
|
||||
|
||||
@@ -506,7 +507,7 @@ namespace glabels
|
||||
fillColorButton->setKeys( keys );
|
||||
textInsertFieldCombo->setKeys( keys );
|
||||
barcodeInsertFieldCombo->setKeys( keys );
|
||||
imageFieldCombo->setKeys( keys );
|
||||
imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() );
|
||||
shadowColorButton->setKeys( keys );
|
||||
}
|
||||
}
|
||||
@@ -616,10 +617,22 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::onImageKeySelected( QString key )
|
||||
void ObjectEditor::onImageComboChanged()
|
||||
{
|
||||
mUndoRedoModel->checkpoint( tr("Set image") );
|
||||
mObject->setFilenameNode( model::TextNode( true, key ) );
|
||||
imageFileSelectionBox->setVisible( imageFieldCombo->isCurrentSelectionSpecial() );
|
||||
|
||||
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() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace glabels
|
||||
void onLineControlsChanged();
|
||||
void onFillControlsChanged();
|
||||
void onImageFileButtonClicked();
|
||||
void onImageKeySelected( QString key );
|
||||
void onImageComboChanged();
|
||||
void onPositionControlsChanged();
|
||||
void onRectSizeControlsChanged();
|
||||
void onLineSizeControlsChanged();
|
||||
|
||||
+94
-88
@@ -31,7 +31,7 @@
|
||||
<property name="windowTitle">
|
||||
<string notr="true">Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
@@ -763,77 +763,74 @@
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_12">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="glabels::FieldCombo" name="imageFieldCombo">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="imageFilenameLineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<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>
|
||||
<property name="text">
|
||||
<string notr="true">Selected File...</string>
|
||||
</property>
|
||||
</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="glabels::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>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="imageFileSelectionBox" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_27">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="imageFilenameLineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<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>
|
||||
<widget class="QPushButton" name="imageBrowseButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Browse...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@@ -1545,6 +1542,14 @@
|
||||
<signal>selectionChanged()</signal>
|
||||
</slots>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>glabels::FieldCombo</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>FieldCombo.h</header>
|
||||
<slots>
|
||||
<signal>selectionChanged()</signal>
|
||||
</slots>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../icons.qrc"/>
|
||||
@@ -1999,13 +2004,13 @@
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>imageFileButton</sender>
|
||||
<sender>imageBrowseButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>ObjectEditor</receiver>
|
||||
<slot>onImageFileButtonClicked()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>133</x>
|
||||
<x>365</x>
|
||||
<y>175</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
@@ -2014,22 +2019,6 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
<sender>textEdit</sender>
|
||||
<signal>textChanged()</signal>
|
||||
@@ -2190,6 +2179,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
<slots>
|
||||
<slot>onChanged()</slot>
|
||||
@@ -2206,5 +2211,6 @@
|
||||
<slot>onTextInsertFieldKeySelected(QString)</slot>
|
||||
<slot>onBarcodeControlsChanged()</slot>
|
||||
<slot>onBarcodeInsertFieldKeySelected(QString)</slot>
|
||||
<slot>onImageComboChanged()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user