Commit d2be21d7 authored by Tobias Koenig's avatar Tobias Koenig

Implemented name and display name widgets

svn path=/trunk/KDE/kdepim/kcontactmanager/editor/; revision=914793
parent 1aa969d3
......@@ -22,11 +22,15 @@
#include "addresseditwidget.h"
#include "dateeditwidget.h"
#include "displaynameeditwidget.h"
#include "emaileditwidget.h"
#include "imagewidget.h"
#include "nameeditwidget.h"
#include "phoneeditwidget.h"
#include "soundeditwidget.h"
#include <kconfig.h>
#include <kconfiggroup.h>
#include <klineedit.h>
#include <klocale.h>
#include <ktabwidget.h>
......@@ -58,9 +62,9 @@ class ContactEditor::Private
KTabWidget *mTabWidget;
// widgets from name group
KLineEdit *mNameWidget;
NameEditWidget *mNameWidget;
ImageWidget *mPhotoWidget;
KLineEdit *mDisplayNameWidget;
DisplayNameEditWidget *mDisplayNameWidget;
KLineEdit *mNickNameWidget;
SoundEditWidget *mPronunciationWidget;
......@@ -142,7 +146,7 @@ void ContactEditor::Private::initGuiContactTab()
label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
nameLayout->addWidget( label, 0, 0 );
mNameWidget = new KLineEdit;
mNameWidget = new NameEditWidget;
label->setBuddy( mNameWidget );
nameLayout->addWidget( mNameWidget, 0, 1 );
......@@ -154,10 +158,13 @@ void ContactEditor::Private::initGuiContactTab()
label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
nameLayout->addWidget( label, 1, 0 );
mDisplayNameWidget = new KLineEdit;
mDisplayNameWidget = new DisplayNameEditWidget;
label->setBuddy( mDisplayNameWidget );
nameLayout->addWidget( mDisplayNameWidget, 1, 1 );
connect( mNameWidget, SIGNAL( nameChanged( const KABC::Addressee& ) ),
mDisplayNameWidget, SLOT( changeName( const KABC::Addressee& ) ) );
label = new QLabel( i18n( "Nickname:" ) );
label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
nameLayout->addWidget( label, 2, 0 );
......@@ -400,20 +407,31 @@ void ContactEditor::Private::storeCustom( KABC::Addressee &contact, const QStrin
contact.insertCustom( "KADDRESSBOOK", key, value );
}
ContactEditor::ContactEditor( QWidget *parent )
: d( new Private(this) )
ContactEditor::ContactEditor( QWidget* )
: d( new Private( this ) )
{
d->initGui();
KConfig config( "kcontactmanagerrc" );
KConfigGroup group( &config, "General" );
d->mDisplayNameWidget->setDisplayType( DisplayNameEditWidget::DisplayType( group.readEntry( "DisplayNameType", 1 ) ) );
}
ContactEditor::~ContactEditor()
{
KConfig config( "kcontactmanagerrc" );
KConfigGroup group( &config, "General" );
group.writeEntry( "DisplayNameType", (int)d->mDisplayNameWidget->displayType() );
}
void ContactEditor::loadContact( const KABC::Addressee &contact )
{
// name group
d->mPhotoWidget->loadContact( contact );
d->mNameWidget->loadContact( contact );
d->mDisplayNameWidget->loadContact( contact );
d->mNickNameWidget->setText( contact.nickName() );
d->mPronunciationWidget->loadContact( contact );
......@@ -456,6 +474,8 @@ void ContactEditor::storeContact( KABC::Addressee &contact ) const
{
// name group
d->mPhotoWidget->storeContact( contact );
d->mNameWidget->storeContact( contact );
d->mDisplayNameWidget->storeContact( contact );
contact.setNickName( d->mNickNameWidget->text().trimmed() );
d->mPronunciationWidget->storeContact( contact );
......
/*
This file is part of KContactManager.
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "displaynameeditwidget.h"
#include <QtCore/QString>
#include <QtGui/QActionGroup>
#include <QtGui/QContextMenuEvent>
#include <QtGui/QHBoxLayout>
#include <QtGui/QMenu>
#include <kabc/addressee.h>
#include <kdialog.h>
#include <klineedit.h>
#include <klocale.h>
#include <ktoggleaction.h>
class DisplayNameEditWidget::LineEdit : public KLineEdit
{
public:
LineEdit( DisplayNameEditWidget *parent )
: KLineEdit( parent ), mParent( parent )
{
}
protected:
// context menu handling
virtual void contextMenuEvent( QContextMenuEvent *event )
{
mParent->contextMenuEvent( event );
}
private:
DisplayNameEditWidget *mParent;
};
DisplayNameEditWidget::DisplayNameEditWidget( QWidget *parent )
: QWidget( parent ),
mDisplayType( FullName )
{
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( KDialog::spacingHint() );
mView = new LineEdit( this );
layout->addWidget( mView );
}
DisplayNameEditWidget::~DisplayNameEditWidget()
{
}
void DisplayNameEditWidget::setReadOnly( bool readOnly )
{
mView->setReadOnly( readOnly && (mDisplayType != CustomName) );
}
void DisplayNameEditWidget::setDisplayType( DisplayType type )
{
mDisplayType = type;
updateView();
}
DisplayNameEditWidget::DisplayType DisplayNameEditWidget::displayType() const
{
return mDisplayType;
}
void DisplayNameEditWidget::loadContact( const KABC::Addressee &contact )
{
mView->setText( contact.formattedName() );
mContact = contact;
updateView();
}
void DisplayNameEditWidget::storeContact( KABC::Addressee &contact ) const
{
contact.setFormattedName( mView->text() );
}
void DisplayNameEditWidget::changeName( const KABC::Addressee &contact )
{
mContact = contact;
mContact.setFormattedName( mView->text() );
updateView();
}
void DisplayNameEditWidget::contextMenuEvent( QContextMenuEvent *event )
{
QMenu menu;
QActionGroup *group = new QActionGroup( this );
KToggleAction *simpleNameAction = new KToggleAction( i18n( "Simple Name" ), group );
KToggleAction *fullNameAction = new KToggleAction( i18n( "Full Name" ), group );
KToggleAction *reverseNameWithCommaAction = new KToggleAction( i18n( "Reverse Name with Comma" ), group );
KToggleAction *reverseNameAction = new KToggleAction( i18n( "Reverse Name" ), group );
KToggleAction *organizationNameAction = new KToggleAction( i18n( "Organization Name" ), group );
KToggleAction *customNameAction = new KToggleAction( i18n( "Custom" ), group );
group->setExclusive( true );
menu.addAction( simpleNameAction );
menu.addAction( fullNameAction );
menu.addAction( reverseNameWithCommaAction );
menu.addAction( reverseNameAction );
menu.addAction( organizationNameAction );
menu.addAction( customNameAction );
if ( mDisplayType == SimpleName )
simpleNameAction->setChecked( true );
if ( mDisplayType == FullName )
fullNameAction->setChecked( true );
if ( mDisplayType == ReverseNameWithComma )
reverseNameWithCommaAction->setChecked( true );
if ( mDisplayType == ReverseName )
reverseNameAction->setChecked( true );
if ( mDisplayType == Organization )
organizationNameAction->setChecked( true );
if ( mDisplayType == CustomName )
customNameAction->setChecked( true );
QAction *result = menu.exec( event->globalPos() );
if ( result == simpleNameAction )
mDisplayType = SimpleName;
else if ( result == fullNameAction )
mDisplayType = FullName;
else if ( result == reverseNameWithCommaAction )
mDisplayType = ReverseNameWithComma;
else if ( result == reverseNameAction )
mDisplayType = ReverseName;
else if ( result == organizationNameAction )
mDisplayType = Organization;
else if ( result == customNameAction )
mDisplayType = CustomName;
delete group;
updateView();
}
void DisplayNameEditWidget::updateView()
{
QString text;
switch ( mDisplayType ) {
case SimpleName:
text = mContact.givenName() + ' ' + mContact.familyName();
break;
case FullName:
text = mContact.assembledName();
break;
case ReverseNameWithComma:
text = mContact.familyName() + ", " + mContact.givenName();
break;
case ReverseName:
text = mContact.familyName() + ' ' + mContact.givenName();
break;
case Organization:
text = mContact.organization();
break;
case CustomName:
text = mContact.formattedName();
default:
break;
}
mView->setText( text );
mView->setReadOnly( mDisplayType != CustomName );
}
#include "displaynameeditwidget.moc"
/*
This file is part of KContactManager.
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef DISPLAYNAMEEDITWIDGET_H
#define DISPLAYNAMEEDITWIDGET_H
#include <QtGui/QWidget>
#include <kabc/addressee.h>
/**
* @short A widget for editing the display name of a contact.
*
* The widget will either use a predefined schema for formatting
* the name or a custom one.
*/
class DisplayNameEditWidget : public QWidget
{
Q_OBJECT
public:
/**
* Describes what the display name should look like.
*/
enum DisplayType
{
CustomName, ///< Let the user input a display name
SimpleName, ///< A name of the form: givenName familyName
FullName, ///< A name of the form: prefix givenName additionalName familyName suffix
ReverseNameWithComma, ///< A name of the form: familyName, givenName
ReverseName, ///< A name of the form: familyName givenName
Organization ///< The organization name
};
explicit DisplayNameEditWidget( QWidget *parent = 0 );
~DisplayNameEditWidget();
void loadContact( const KABC::Addressee &contact );
void storeContact( KABC::Addressee &contact ) const;
void setReadOnly( bool readOnly );
void setDisplayType( DisplayType type );
DisplayType displayType() const;
public Q_SLOTS:
void changeName( const KABC::Addressee &contact );
protected:
// context menu handling
virtual void contextMenuEvent( QContextMenuEvent* );
private:
void updateView();
class LineEdit;
LineEdit *mView;
DisplayType mDisplayType;
KABC::Addressee mContact;
};
#endif
/*
This file is part of KContactManager.
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "nameeditwidget.h"
#include <QtCore/QString>
#include <QtGui/QHBoxLayout>
#include <kabc/addressee.h>
#include <kdialog.h>
#include <klineedit.h>
NameEditWidget::NameEditWidget( QWidget *parent )
: QWidget( parent )
{
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( KDialog::spacingHint() );
mNameEdit = new KLineEdit;
layout->addWidget( mNameEdit );
connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( textChanged( const QString& ) ) );
}
NameEditWidget::~NameEditWidget()
{
}
void NameEditWidget::setReadOnly( bool readOnly )
{
mNameEdit->setReadOnly( readOnly );
}
void NameEditWidget::loadContact( const KABC::Addressee &contact )
{
mNameEdit->setText( contact.assembledName() );
}
void NameEditWidget::storeContact( KABC::Addressee &contact ) const
{
contact.setNameFromString( mNameEdit->text() );
}
void NameEditWidget::textChanged( const QString &text )
{
KABC::Addressee contact;
contact.setNameFromString( text );
emit nameChanged( contact );
}
#include "nameeditwidget.moc"
/*
This file is part of KContactManager.
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef NAMEEDITWIDGET_H
#define NAMEEDITWIDGET_H
#include <QtGui/QWidget>
#include <kabc/addressee.h>
class KLineEdit;
/**
* @short A widget for editing the name of a contact.
*
* The widget will show the name in a lineedit
* and provides a button to open a dialog for editing of
* the single name components.
*/
class NameEditWidget : public QWidget
{
Q_OBJECT
public:
explicit NameEditWidget( QWidget *parent = 0 );
~NameEditWidget();
void loadContact( const KABC::Addressee &contact );
void storeContact( KABC::Addressee &contact ) const;
void setReadOnly( bool readOnly );
Q_SIGNALS:
/**
* This signal is emitted whenever the name has been changed.
*
* @param contact A dummy contact that contains only the name components.
*/
void nameChanged( const KABC::Addressee &contact );
private Q_SLOTS:
void textChanged( const QString& );
private:
KLineEdit *mNameEdit;
KABC::Addressee mContact;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment