Use a combo box for merge field selection.
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QStandardItemModel>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
|
||||||
@@ -141,7 +143,7 @@ ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
|
|||||||
hline3->setLineWidth( 1 );
|
hline3->setLineWidth( 1 );
|
||||||
vLayout->addWidget( hline3 );
|
vLayout->addWidget( hline3 );
|
||||||
|
|
||||||
ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color") );
|
ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color...") );
|
||||||
connect( customColorButton, SIGNAL(activated()), this, SLOT(onCustomColorItemActivated()) );
|
connect( customColorButton, SIGNAL(activated()), this, SLOT(onCustomColorItemActivated()) );
|
||||||
vLayout->addWidget( customColorButton );
|
vLayout->addWidget( customColorButton );
|
||||||
|
|
||||||
@@ -150,17 +152,22 @@ ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
|
|||||||
hline4->setLineWidth( 1 );
|
hline4->setLineWidth( 1 );
|
||||||
vLayout->addWidget( hline4 );
|
vLayout->addWidget( hline4 );
|
||||||
|
|
||||||
mMergeFieldButton = new ColorPaletteButtonItem( tr("Merge field") );
|
mMergeFieldCombo = new QComboBox();
|
||||||
connect( mMergeFieldButton, SIGNAL(activated()), this, SLOT(onMergeFieldItemActivated()) );
|
mMergeFieldCombo->addItem( tr("Merge field...") );
|
||||||
mMergeFieldButton->setEnabled( false );
|
mMergeFieldCombo->setMinimumSize( 34, 34 );
|
||||||
vLayout->addWidget( mMergeFieldButton );
|
mMergeFieldCombo->setFrame( false );
|
||||||
|
mMergeFieldCombo->setEnabled( false );
|
||||||
|
connect( mMergeFieldCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboIndexChanged(int)) );
|
||||||
|
vLayout->addWidget( mMergeFieldCombo );
|
||||||
|
|
||||||
|
// Item 0 is the ComboBox title, not an item intended for selection. So disable it.
|
||||||
|
const QStandardItemModel* model = qobject_cast<const QStandardItemModel*>(mMergeFieldCombo->model());
|
||||||
|
QStandardItem* item = model->item(0);
|
||||||
|
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
|
||||||
|
|
||||||
setLayout( vLayout );
|
setLayout( vLayout );
|
||||||
|
|
||||||
loadCustomColorHistory();
|
loadCustomColorHistory();
|
||||||
|
|
||||||
mFieldMenu = new FieldMenu();
|
|
||||||
connect( mFieldMenu, SIGNAL(keySelected(QString)), this, SLOT(onFieldMenuItemActivated(QString)) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -172,21 +179,35 @@ void ColorPaletteDialog::setColorNode( const ColorNode& colorNode )
|
|||||||
|
|
||||||
void ColorPaletteDialog::setKeys( const QStringList& keyList )
|
void ColorPaletteDialog::setKeys( const QStringList& keyList )
|
||||||
{
|
{
|
||||||
|
mKeys = keyList;
|
||||||
|
|
||||||
|
// Clear old keys, (all entries, except item 0)
|
||||||
|
for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
|
||||||
|
{
|
||||||
|
mMergeFieldCombo->removeItem( index );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new keys
|
||||||
if ( keyList.size() > 0 )
|
if ( keyList.size() > 0 )
|
||||||
{
|
{
|
||||||
mFieldMenu->setKeys( keyList );
|
mMergeFieldCombo->addItems( keyList );
|
||||||
mMergeFieldButton->setEnabled( true );
|
mMergeFieldCombo->setEnabled( true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mMergeFieldButton->setEnabled( false );
|
mMergeFieldCombo->setEnabled( false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorPaletteDialog::clearKeys()
|
void ColorPaletteDialog::clearKeys()
|
||||||
{
|
{
|
||||||
mMergeFieldButton->setEnabled( false );
|
|
||||||
|
for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
|
||||||
|
{
|
||||||
|
mMergeFieldCombo->removeItem( index );
|
||||||
|
}
|
||||||
|
mMergeFieldCombo->setEnabled( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -275,19 +296,23 @@ void ColorPaletteDialog::loadCustomColorHistory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorPaletteDialog::onMergeFieldItemActivated()
|
void ColorPaletteDialog::onComboIndexChanged( int index )
|
||||||
{
|
{
|
||||||
QPoint pos( mMergeFieldButton->width(), 0 );
|
if ( index != 0 )
|
||||||
mFieldMenu->popup( mMergeFieldButton->mapToGlobal(pos) );
|
{
|
||||||
|
mColorNode.setFieldFlag( true );
|
||||||
|
mColorNode.setColor( QColor("#eeeeec") );
|
||||||
|
mColorNode.setKey( mKeys[index-1] );
|
||||||
|
|
||||||
|
emit colorChanged( mColorNode, false );
|
||||||
|
accept();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorPaletteDialog::onFieldMenuItemActivated( QString key )
|
void ColorPaletteDialog::showEvent( QShowEvent* event )
|
||||||
{
|
{
|
||||||
mColorNode.setFieldFlag( true );
|
mMergeFieldCombo->setCurrentIndex( 0 );
|
||||||
mColorNode.setColor( QColor("#eeeeec") );
|
|
||||||
mColorNode.setKey( key );
|
|
||||||
|
|
||||||
emit colorChanged( mColorNode, false );
|
QDialog::showEvent( event );
|
||||||
accept();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
#include "ColorPaletteButtonItem.h"
|
#include "ColorPaletteButtonItem.h"
|
||||||
#include "FieldMenu.h"
|
#include "FieldMenu.h"
|
||||||
|
|
||||||
|
class QComboBox; // Forward reference
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Color Palette Dialog
|
/// Color Palette Dialog
|
||||||
@@ -74,9 +76,11 @@ private slots:
|
|||||||
void onHistoryItemActivated( int id );
|
void onHistoryItemActivated( int id );
|
||||||
void onCustomColorItemActivated();
|
void onCustomColorItemActivated();
|
||||||
void onColorHistoryChanged();
|
void onColorHistoryChanged();
|
||||||
void onMergeFieldItemActivated();
|
void onComboIndexChanged( int index );
|
||||||
void onFieldMenuItemActivated( QString key );
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent( QShowEvent* event );
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
// Private Methods
|
// Private Methods
|
||||||
@@ -105,8 +109,8 @@ private:
|
|||||||
ColorHistory* mColorHistory;
|
ColorHistory* mColorHistory;
|
||||||
ColorPaletteItem* mHistoryItem[PALETTE_COLS];
|
ColorPaletteItem* mHistoryItem[PALETTE_COLS];
|
||||||
|
|
||||||
FieldMenu* mFieldMenu;
|
QComboBox* mMergeFieldCombo;
|
||||||
ColorPaletteButtonItem* mMergeFieldButton;
|
QStringList mKeys;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user