22 #include "nameeditwidget.h"
24 #include "nameeditdialog.h"
26 #include <QtCore/QPointer>
27 #include <QtCore/QString>
28 #include <QHBoxLayout>
29 #include <QToolButton>
31 #include <kabc/addressee.h>
33 #include <klineedit.h>
36 NameEditWidget::NameEditWidget( QWidget *parent )
39 QHBoxLayout *layout =
new QHBoxLayout(
this );
40 layout->setMargin( 0 );
41 layout->setSpacing( KDialog::spacingHint() );
43 mNameEdit =
new KLineEdit;
44 layout->addWidget( mNameEdit );
46 QToolButton *button =
new QToolButton;
47 button->setText( i18n(
"..." ) );
48 layout->addWidget( button );
50 connect( mNameEdit, SIGNAL(textChanged(QString)),
this, SLOT(textChanged(QString)) );
51 connect( button, SIGNAL(clicked()),
this, SLOT(openNameEditDialog()) );
54 NameEditWidget::~NameEditWidget()
58 void NameEditWidget::setReadOnly(
bool readOnly )
60 mNameEdit->setReadOnly( readOnly );
63 void NameEditWidget::loadContact(
const KABC::Addressee &contact )
67 disconnect( mNameEdit, SIGNAL(textChanged(QString)),
this, SLOT(textChanged(QString)) );
68 mNameEdit->setText( contact.assembledName() );
69 connect( mNameEdit, SIGNAL(textChanged(QString)),
this, SLOT(textChanged(QString)) );
72 void NameEditWidget::storeContact( KABC::Addressee &contact )
const
74 contact.setPrefix( mContact.prefix() );
75 contact.setGivenName( mContact.givenName() );
76 contact.setAdditionalName( mContact.additionalName() );
77 contact.setFamilyName( mContact.familyName() );
78 contact.setSuffix( mContact.suffix() );
81 void NameEditWidget::textChanged(
const QString &text )
83 mContact.setNameFromString( text );
88 void NameEditWidget::openNameEditDialog()
90 QPointer<NameEditDialog> dlg =
new NameEditDialog(
this );
92 dlg->setPrefix( mContact.prefix() );
93 dlg->setGivenName( mContact.givenName() );
94 dlg->setAdditionalName( mContact.additionalName() );
95 dlg->setFamilyName( mContact.familyName() );
96 dlg->setSuffix( mContact.suffix() );
98 if ( dlg->exec() == QDialog::Accepted ) {
99 mContact.setPrefix( dlg->prefix() );
100 mContact.setGivenName( dlg->givenName() );
101 mContact.setAdditionalName( dlg->additionalName() );
102 mContact.setFamilyName( dlg->familyName() );
103 mContact.setSuffix( dlg->suffix() );
105 disconnect( mNameEdit, SIGNAL(textChanged(QString)),
this, SLOT(textChanged(QString)) );
106 mNameEdit->setText( mContact.assembledName() );
107 connect( mNameEdit, SIGNAL(textChanged(QString)),
this, SLOT(textChanged(QString)) );