Yet another redesign of image file selection in ObjectEditor.
This commit is contained in:
@@ -18,7 +18,6 @@ set (glabels_sources
|
||||
Cursors.cpp
|
||||
EditVariableDialog.cpp
|
||||
FieldButton.cpp
|
||||
FieldCombo.cpp
|
||||
File.cpp
|
||||
Help.cpp
|
||||
Icons.cpp
|
||||
@@ -56,7 +55,6 @@ set (glabels_qobject_headers
|
||||
ColorPaletteButtonItem.h
|
||||
EditVariableDialog.h
|
||||
FieldButton.h
|
||||
FieldCombo.h
|
||||
File.h
|
||||
LabelEditor.h
|
||||
MainWindow.h
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* 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.
|
||||
*
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -69,7 +69,7 @@ namespace glabels
|
||||
|
||||
textInsertFieldButton->setText( tr("Insert field") );
|
||||
barcodeInsertFieldButton->setText( tr("Insert field") );
|
||||
imageFieldCombo->setSpecialSelectionText( tr("Selected file...") );
|
||||
imageFieldButton->setText( tr("Use field") );
|
||||
|
||||
setEnabled( false );
|
||||
hidePages();
|
||||
@@ -123,14 +123,12 @@ namespace glabels
|
||||
|
||||
model::TextNode filenameNode = mObject->filenameNode();
|
||||
|
||||
imageFileSelectionBox->setVisible( !filenameNode.isField() );
|
||||
if ( filenameNode.isField() )
|
||||
{
|
||||
imageFieldCombo->setCurrentSelection( filenameNode.data() );
|
||||
imageFilenameLineEdit->setText( QString("${%1}").arg(filenameNode.data()) );
|
||||
}
|
||||
else
|
||||
{
|
||||
imageFieldCombo->setCurrentSelectionToSpecial();
|
||||
imageFilenameLineEdit->setText( filenameNode.data() );
|
||||
}
|
||||
|
||||
@@ -510,7 +508,7 @@ namespace glabels
|
||||
fillColorButton->setKeys( keys );
|
||||
textInsertFieldButton->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 );
|
||||
}
|
||||
}
|
||||
@@ -620,21 +618,12 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::onImageComboChanged()
|
||||
void ObjectEditor::onImageKeySelected( QString 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() ) );
|
||||
}
|
||||
mObject->setFilenameNode( model::TextNode( true, key ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace glabels
|
||||
void onLineControlsChanged();
|
||||
void onFillControlsChanged();
|
||||
void onImageFileButtonClicked();
|
||||
void onImageComboChanged();
|
||||
void onImageKeySelected( QString key );
|
||||
void onPositionControlsChanged();
|
||||
void onRectSizeControlsChanged();
|
||||
void onLineSizeControlsChanged();
|
||||
|
||||
+69
-103
@@ -70,7 +70,7 @@
|
||||
<item row="1" column="0">
|
||||
<widget class="QTabWidget" name="notebook">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="textPage">
|
||||
<attribute name="title">
|
||||
@@ -766,83 +766,6 @@
|
||||
<string>Image</string>
|
||||
</attribute>
|
||||
<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">
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
@@ -856,6 +779,57 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
<widget class="QWidget" name="lineFillPage">
|
||||
@@ -1542,14 +1516,6 @@
|
||||
<signal>selectionChanged()</signal>
|
||||
</slots>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>glabels::FieldCombo</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>FieldCombo.h</header>
|
||||
<slots>
|
||||
<signal>selectionChanged()</signal>
|
||||
</slots>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>glabels::FieldButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
@@ -2019,7 +1985,7 @@
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>367</x>
|
||||
<y>168</y>
|
||||
<y>135</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>394</x>
|
||||
@@ -2155,22 +2121,6 @@
|
||||
</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>
|
||||
<connection>
|
||||
<sender>textInsertFieldButton</sender>
|
||||
<signal>keySelected(QString)</signal>
|
||||
@@ -2203,6 +2153,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
<slots>
|
||||
<slot>onChanged()</slot>
|
||||
|
||||
@@ -1908,7 +1908,7 @@
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Selected file...</source>
|
||||
<source>Use field</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
|
||||
Reference in New Issue
Block a user