From 87cc5d7e2203748e49a025d60888ae11ed2cf987 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 30 Mar 2019 12:50:30 -0400 Subject: [PATCH] Redesigned image selection in ObjectEditor to use new FieldCombo widget. --- glabels/CMakeLists.txt | 2 + glabels/FieldCombo.cpp | 146 +++++++++++++++++++++++++++++ glabels/FieldCombo.h | 94 +++++++++++++++++++ glabels/ObjectEditor.cpp | 27 ++++-- glabels/ObjectEditor.h | 2 +- glabels/ui/ObjectEditor.ui | 182 +++++++++++++++++++------------------ translations/glabels_C.ts | 24 ++--- 7 files changed, 365 insertions(+), 112 deletions(-) create mode 100644 glabels/FieldCombo.cpp create mode 100644 glabels/FieldCombo.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index df14917..d03daa7 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -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 diff --git a/glabels/FieldCombo.cpp b/glabels/FieldCombo.cpp new file mode 100644 index 0000000..0a41107 --- /dev/null +++ b/glabels/FieldCombo.cpp @@ -0,0 +1,146 @@ +/* FieldCombo.cpp + * + * Copyright (C) 2014-2019 Jim Evins + * + * 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 . + */ + +#include "FieldCombo.h" + +#include +#include + + +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 diff --git a/glabels/FieldCombo.h b/glabels/FieldCombo.h new file mode 100644 index 0000000..a748628 --- /dev/null +++ b/glabels/FieldCombo.h @@ -0,0 +1,94 @@ +/* FieldCombo.h + * + * Copyright (C) 2014-2019 Jim Evins + * + * 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 . + */ + +#ifndef FieldCombo_h +#define FieldCombo_h + + +#include "model/Variables.h" +#include "merge/Merge.h" + +#include +#include +#include + + +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 mFieldNames; + + }; + +} + + +#endif // FieldCombo_h diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index f61e9fe..ee2ba24 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -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() ) ); + } + } } diff --git a/glabels/ObjectEditor.h b/glabels/ObjectEditor.h index 6e84687..311f691 100644 --- a/glabels/ObjectEditor.h +++ b/glabels/ObjectEditor.h @@ -87,7 +87,7 @@ namespace glabels void onLineControlsChanged(); void onFillControlsChanged(); void onImageFileButtonClicked(); - void onImageKeySelected( QString key ); + void onImageComboChanged(); void onPositionControlsChanged(); void onRectSizeControlsChanged(); void onLineSizeControlsChanged(); diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index 0493a38..d213373 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -31,7 +31,7 @@ Form - + @@ -763,77 +763,74 @@ File - - - + + + + + + 0 + 0 + + - - - - 0 - 0 - - - - - 231 - 0 - - - - true - - - None - - + + Selected File... + - - - - - - - 0 - 0 - - - - Select File... - - - - - - - - 0 - 0 - - - - or - - - - - - - - 0 - 0 - - - - - Select Merge Field... - - - - - - - + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 231 + 0 + + + + true + + + None + + + + + + + + 0 + 0 + + + + Browse... + + + + + @@ -1545,6 +1542,14 @@ selectionChanged() + + glabels::FieldCombo + QComboBox +
FieldCombo.h
+ + selectionChanged() + +
@@ -1999,13 +2004,13 @@ - imageFileButton + imageBrowseButton clicked() ObjectEditor onImageFileButtonClicked() - 133 + 365 175 @@ -2014,22 +2019,6 @@ - - imageFieldCombo - keySelected(QString) - ObjectEditor - onImageKeySelected(QString) - - - 302 - 175 - - - 397 - 32 - - - textEdit textChanged() @@ -2190,6 +2179,22 @@ + + imageFieldCombo + selectionChanged() + ObjectEditor + onImageComboChanged() + + + 283 + 118 + + + 398 + 18 + + + onChanged() @@ -2206,5 +2211,6 @@ onTextInsertFieldKeySelected(QString) onBarcodeControlsChanged() onBarcodeInsertFieldKeySelected(QString) + onImageComboChanged() diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 75a8f11..f131f4f 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -405,18 +405,6 @@ File - - Select File... - - - - or - - - - Select Merge Field... - - Line/Fill @@ -493,6 +481,10 @@ Opacity: + + Browse... + + PreferencesDialog @@ -1760,10 +1752,6 @@ Insert Field - - Key - - Original size @@ -1900,6 +1888,10 @@ Shadow + + Selected File... + + glabels::PrintView