• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
  • contact
  • editor
nameeditwidget.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "nameeditwidget.h"
23 
24 #include "nameeditdialog.h"
25 
26 #include <QtCore/QPointer>
27 #include <QHBoxLayout>
28 #include <QToolButton>
29 
30 #include <kabc/addressee.h>
31 #include <kdialog.h>
32 #include <klineedit.h>
33 #include <klocalizedstring.h>
34 
35 NameEditWidget::NameEditWidget( QWidget *parent )
36  : QWidget( parent )
37 {
38  QHBoxLayout *layout = new QHBoxLayout( this );
39  layout->setMargin( 0 );
40  layout->setSpacing( KDialog::spacingHint() );
41 
42  mNameEdit = new KLineEdit;
43  layout->addWidget( mNameEdit );
44  setFocusProxy( mNameEdit );
45  setFocusPolicy( Qt::StrongFocus );
46 
47  mButtonEdit = new QToolButton;
48  mButtonEdit->setText(i18n("..."));
49  layout->addWidget(mButtonEdit);
50 
51 
52  connect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) );
53  connect( mButtonEdit, SIGNAL(clicked()), this, SLOT(openNameEditDialog()) );
54 }
55 
56 NameEditWidget::~NameEditWidget()
57 {
58 }
59 
60 void NameEditWidget::setReadOnly( bool readOnly )
61 {
62  mNameEdit->setReadOnly( readOnly );
63  mButtonEdit->setEnabled(!readOnly);
64 }
65 
66 void NameEditWidget::loadContact( const KABC::Addressee &contact )
67 {
68  mContact = contact;
69 
70  disconnect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) );
71  mNameEdit->setText( contact.assembledName() );
72  connect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) );
73 }
74 
75 void NameEditWidget::storeContact( KABC::Addressee &contact ) const
76 {
77  contact.setPrefix( mContact.prefix() );
78  contact.setGivenName( mContact.givenName() );
79  contact.setAdditionalName( mContact.additionalName() );
80  contact.setFamilyName( mContact.familyName() );
81  contact.setSuffix( mContact.suffix() );
82 }
83 
84 void NameEditWidget::textChanged( const QString &text )
85 {
86  mContact.setNameFromString( text );
87 
88  emit nameChanged( mContact );
89 }
90 
91 void NameEditWidget::openNameEditDialog()
92 {
93  QPointer<NameEditDialog> dlg = new NameEditDialog( this );
94 
95  dlg->setPrefix( mContact.prefix() );
96  dlg->setGivenName( mContact.givenName() );
97  dlg->setAdditionalName( mContact.additionalName() );
98  dlg->setFamilyName( mContact.familyName() );
99  dlg->setSuffix( mContact.suffix() );
100 
101  if ( dlg->exec() == QDialog::Accepted ) {
102  mContact.setPrefix( dlg->prefix() );
103  mContact.setGivenName( dlg->givenName() );
104  mContact.setAdditionalName( dlg->additionalName() );
105  mContact.setFamilyName( dlg->familyName() );
106  mContact.setSuffix( dlg->suffix() );
107 
108  disconnect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) );
109  mNameEdit->setText( mContact.assembledName() );
110  connect( mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)) );
111 
112  emit nameChanged( mContact );
113  }
114 
115  delete dlg;
116 }
117 
NameEditWidget::storeContact
void storeContact(KABC::Addressee &contact) const
Definition: nameeditwidget.cpp:75
NameEditWidget::loadContact
void loadContact(const KABC::Addressee &contact)
Definition: nameeditwidget.cpp:66
NameEditWidget::setReadOnly
void setReadOnly(bool readOnly)
Definition: nameeditwidget.cpp:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal