Yet another redesign of image file selection in ObjectEditor.

This commit is contained in:
Jim Evins
2019-07-21 00:59:14 -04:00
parent 4e94933dcf
commit 3cfda79b82
8 changed files with 77 additions and 367 deletions
-2
View File
@@ -18,7 +18,6 @@ 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
@@ -56,7 +55,6 @@ 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
+1 -1
View File
@@ -1,6 +1,6 @@
/* FieldButton.cpp /* FieldButton.cpp
* *
* Copyright (C) 2014-2019 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.
* *
-149
View File
@@ -1,149 +0,0 @@
/* 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 )
{
if ( index >= 0 )
{
emit selectionChanged();
}
}
} // namespace glabels
-94
View File
@@ -1,94 +0,0 @@
/* 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
+5 -16
View File
@@ -69,7 +69,7 @@ namespace glabels
textInsertFieldButton->setText( tr("Insert field") ); textInsertFieldButton->setText( tr("Insert field") );
barcodeInsertFieldButton->setText( tr("Insert field") ); barcodeInsertFieldButton->setText( tr("Insert field") );
imageFieldCombo->setSpecialSelectionText( tr("Selected file...") ); imageFieldButton->setText( tr("Use field") );
setEnabled( false ); setEnabled( false );
hidePages(); hidePages();
@@ -123,14 +123,12 @@ namespace glabels
model::TextNode filenameNode = mObject->filenameNode(); model::TextNode filenameNode = mObject->filenameNode();
imageFileSelectionBox->setVisible( !filenameNode.isField() );
if ( filenameNode.isField() ) if ( filenameNode.isField() )
{ {
imageFieldCombo->setCurrentSelection( filenameNode.data() ); imageFilenameLineEdit->setText( QString("${%1}").arg(filenameNode.data()) );
} }
else else
{ {
imageFieldCombo->setCurrentSelectionToSpecial();
imageFilenameLineEdit->setText( filenameNode.data() ); imageFilenameLineEdit->setText( filenameNode.data() );
} }
@@ -510,7 +508,7 @@ namespace glabels
fillColorButton->setKeys( keys ); fillColorButton->setKeys( keys );
textInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); textInsertFieldButton->setKeys( mModel->merge(), mModel->variables() );
barcodeInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); barcodeInsertFieldButton->setKeys( mModel->merge(), mModel->variables() );
imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() ); imageFieldButton->setKeys( mModel->merge(), mModel->variables() );
shadowColorButton->setKeys( keys ); shadowColorButton->setKeys( keys );
} }
} }
@@ -620,21 +618,12 @@ namespace glabels
} }
void ObjectEditor::onImageComboChanged() void ObjectEditor::onImageKeySelected( QString key )
{ {
imageFileSelectionBox->setVisible( imageFieldCombo->isCurrentSelectionSpecial() );
if ( mObject ) if ( mObject )
{ {
mUndoRedoModel->checkpoint( tr("Set image") ); mUndoRedoModel->checkpoint( tr("Set image") );
if ( imageFieldCombo->isCurrentSelectionSpecial() ) mObject->setFilenameNode( model::TextNode( true, key ) );
{
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 onImageComboChanged(); void onImageKeySelected( QString key );
void onPositionControlsChanged(); void onPositionControlsChanged();
void onRectSizeControlsChanged(); void onRectSizeControlsChanged();
void onLineSizeControlsChanged(); void onLineSizeControlsChanged();
+69 -103
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>1</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="textPage"> <widget class="QWidget" name="textPage">
<attribute name="title"> <attribute name="title">
@@ -766,83 +766,6 @@
<string>Image</string> <string>Image</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_13"> <layout class="QGridLayout" name="gridLayout_13">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_9">
<property name="title">
<string>File</string>
</property>
<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>
<property name="text">
<string notr="true">Selected File...</string>
</property>
</item>
</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>
</item>
<item row="2" column="0"> <item row="2" column="0">
<spacer name="verticalSpacer_3"> <spacer name="verticalSpacer_3">
<property name="orientation"> <property name="orientation">
@@ -856,6 +779,57 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_9">
<property name="title">
<string>File</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<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 row="0" column="1">
<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>
<item row="1" column="1">
<widget class="glabels::FieldButton" name="imageFieldButton">
<property name="text">
<string notr="true">Use field</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="lineFillPage"> <widget class="QWidget" name="lineFillPage">
@@ -1542,14 +1516,6 @@
<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>
<customwidget> <customwidget>
<class>glabels::FieldButton</class> <class>glabels::FieldButton</class>
<extends>QPushButton</extends> <extends>QPushButton</extends>
@@ -2019,7 +1985,7 @@
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>367</x> <x>367</x>
<y>168</y> <y>135</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>394</x> <x>394</x>
@@ -2155,22 +2121,6 @@
</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>
<connection> <connection>
<sender>textInsertFieldButton</sender> <sender>textInsertFieldButton</sender>
<signal>keySelected(QString)</signal> <signal>keySelected(QString)</signal>
@@ -2203,6 +2153,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>imageFieldButton</sender>
<signal>keySelected(QString)</signal>
<receiver>ObjectEditor</receiver>
<slot>onImageKeySelected(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>317</x>
<y>160</y>
</hint>
<hint type="destinationlabel">
<x>331</x>
<y>-12</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>onChanged()</slot> <slot>onChanged()</slot>
+1 -1
View File
@@ -1908,7 +1908,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Selected file...</source> <source>Use field</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>