00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "nameeditwidget.h"
00023
00024 #include "nameeditdialog.h"
00025
00026 #include <QtCore/QPointer>
00027 #include <QtCore/QString>
00028 #include <QtGui/QHBoxLayout>
00029 #include <QtGui/QToolButton>
00030
00031 #include <kabc/addressee.h>
00032 #include <kdialog.h>
00033 #include <klineedit.h>
00034 #include <klocale.h>
00035
00036 NameEditWidget::NameEditWidget( QWidget *parent )
00037 : QWidget( parent )
00038 {
00039 QHBoxLayout *layout = new QHBoxLayout( this );
00040 layout->setMargin( 0 );
00041 layout->setSpacing( KDialog::spacingHint() );
00042
00043 mNameEdit = new KLineEdit;
00044 layout->addWidget( mNameEdit );
00045
00046 QToolButton *button = new QToolButton;
00047 button->setText( i18n( "..." ) );
00048 layout->addWidget( button );
00049
00050 connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged( const QString& ) ) );
00051 connect( button, SIGNAL( clicked() ), this, SLOT( openNameEditDialog() ) );
00052 }
00053
00054 NameEditWidget::~NameEditWidget()
00055 {
00056 }
00057
00058 void NameEditWidget::setReadOnly( bool readOnly )
00059 {
00060 mNameEdit->setReadOnly( readOnly );
00061 }
00062
00063 void NameEditWidget::loadContact( const KABC::Addressee &contact )
00064 {
00065 mContact = contact;
00066
00067 disconnect( mNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged( const QString& ) ) );
00068 mNameEdit->setText( contact.assembledName() );
00069 connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged( const QString& ) ) );
00070 }
00071
00072 void NameEditWidget::storeContact( KABC::Addressee &contact ) const
00073 {
00074 contact.setPrefix( mContact.prefix() );
00075 contact.setGivenName( mContact.givenName() );
00076 contact.setAdditionalName( mContact.additionalName() );
00077 contact.setFamilyName( mContact.familyName() );
00078 contact.setSuffix( mContact.suffix() );
00079 }
00080
00081 void NameEditWidget::textChanged( const QString &text )
00082 {
00083 mContact.setNameFromString( text );
00084
00085 emit nameChanged( mContact );
00086 }
00087
00088 void NameEditWidget::openNameEditDialog()
00089 {
00090 QPointer<NameEditDialog> dlg = new NameEditDialog( this );
00091
00092 dlg->setPrefix( mContact.prefix() );
00093 dlg->setGivenName( mContact.givenName() );
00094 dlg->setAdditionalName( mContact.additionalName() );
00095 dlg->setFamilyName( mContact.familyName() );
00096 dlg->setSuffix( mContact.suffix() );
00097
00098 if ( dlg->exec() == QDialog::Accepted ) {
00099 mContact.setPrefix( dlg->prefix() );
00100 mContact.setGivenName( dlg->givenName() );
00101 mContact.setAdditionalName( dlg->additionalName() );
00102 mContact.setFamilyName( dlg->familyName() );
00103 mContact.setSuffix( dlg->suffix() );
00104
00105 disconnect( mNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged( const QString& ) ) );
00106 mNameEdit->setText( mContact.assembledName() );
00107 connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( textChanged( const QString& ) ) );
00108
00109 emit nameChanged( mContact );
00110 }
00111
00112 delete dlg;
00113 }
00114
00115 #include "nameeditwidget.moc"