Akonadi Contacts

nameeditdialog.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2010 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "nameeditdialog.h"
10 
11 #include <KComboBox>
12 #include <KLineEdit>
13 #include <KLocalizedString>
14 
15 #include <QDialogButtonBox>
16 #include <QFormLayout>
17 #include <QPushButton>
18 
19 NameEditDialog::NameEditDialog(QWidget *parent)
20  : QDialog(parent)
21 {
22  setWindowTitle(i18nc("@title:window", "Edit Contact Name"));
23 
24  auto mainLayout = new QVBoxLayout(this);
25 
26  auto layout = new QFormLayout;
27  mainLayout->addLayout(layout);
28 
29  mPrefixCombo = new KComboBox(this);
30  mPrefixCombo->setDuplicatesEnabled(false);
31  mPrefixCombo->setEditable(true);
32 
33  mGivenNameEdit = new KLineEdit(this);
34  mGivenNameEdit->setTrapReturnKey(true);
35 
36  mAdditionalNameEdit = new KLineEdit(this);
37  mAdditionalNameEdit->setTrapReturnKey(true);
38 
39  mFamilyNameEdit = new KLineEdit(this);
40  mFamilyNameEdit->setTrapReturnKey(true);
41 
42  mSuffixCombo = new KComboBox(this);
43  mSuffixCombo->setDuplicatesEnabled(false);
44  mSuffixCombo->setEditable(true);
45 
46  mDisplayNameEdit = new DisplayNameEditWidget(this);
47 
48  layout->addRow(i18n("Honorific prefixes:"), mPrefixCombo);
49  layout->addRow(i18n("Given name:"), mGivenNameEdit);
50  layout->addRow(i18n("Additional names:"), mAdditionalNameEdit);
51  layout->addRow(i18n("Family names:"), mFamilyNameEdit);
52  layout->addRow(i18n("Honorific suffixes:"), mSuffixCombo);
53  layout->addRow(i18n("Display:"), mDisplayNameEdit);
54 
55  QStringList prefixList;
56  prefixList += QString();
57  prefixList += i18n("Dr.");
58  prefixList += i18n("Miss");
59  prefixList += i18n("Mr.");
60  prefixList += i18n("Mrs.");
61  prefixList += i18n("Ms.");
62  prefixList += i18n("Prof.");
63  prefixList.sort();
64 
65  QStringList suffixList;
66  suffixList += QString();
67  suffixList += i18n("I");
68  suffixList += i18n("II");
69  suffixList += i18n("III");
70  suffixList += i18n("Jr.");
71  suffixList += i18n("Sr.");
72  suffixList.sort();
73 
74  mPrefixCombo->addItems(prefixList);
75  mSuffixCombo->addItems(suffixList);
76 
77  mPrefixCombo->lineEdit()->setFocus();
79  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
80  okButton->setDefault(true);
81  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
82  connect(buttonBox, &QDialogButtonBox::accepted, this, &NameEditDialog::accept);
83  connect(buttonBox, &QDialogButtonBox::rejected, this, &NameEditDialog::reject);
84  mainLayout->addWidget(buttonBox);
85 }
86 
87 void NameEditDialog::setFamilyName(const QString &name)
88 {
89  mFamilyNameEdit->setText(name);
90 }
91 
92 QString NameEditDialog::familyName() const
93 {
94  return mFamilyNameEdit->text();
95 }
96 
97 void NameEditDialog::setGivenName(const QString &name)
98 {
99  mGivenNameEdit->setText(name);
100 }
101 
102 QString NameEditDialog::givenName() const
103 {
104  return mGivenNameEdit->text();
105 }
106 
107 void NameEditDialog::setPrefix(const QString &prefix)
108 {
109  mPrefixCombo->setItemText(mPrefixCombo->currentIndex(), prefix);
110 }
111 
112 QString NameEditDialog::prefix() const
113 {
114  return mPrefixCombo->currentText();
115 }
116 
117 void NameEditDialog::setSuffix(const QString &suffix)
118 {
119  mSuffixCombo->setItemText(mSuffixCombo->currentIndex(), suffix);
120 }
121 
122 QString NameEditDialog::suffix() const
123 {
124  return mSuffixCombo->currentText();
125 }
126 
127 void NameEditDialog::setAdditionalName(const QString &name)
128 {
129  mAdditionalNameEdit->setText(name);
130 }
131 
132 QString NameEditDialog::additionalName() const
133 {
134  return mAdditionalNameEdit->text();
135 }
136 
137 void NameEditDialog::loadContact(const KContacts::Addressee &contact)
138 {
139  setPrefix(contact.prefix());
140  setGivenName(contact.givenName());
141  setAdditionalName(contact.additionalName());
142  setFamilyName(contact.familyName());
143  setSuffix(contact.suffix());
144  mDisplayNameEdit->loadContact(contact);
145 }
146 
147 void NameEditDialog::storeContact(KContacts::Addressee &contact) const
148 {
149  mDisplayNameEdit->storeContact(contact);
150  contact.setPrefix(prefix());
151  contact.setGivenName(givenName());
152  contact.setAdditionalName(additionalName());
153  contact.setFamilyName(familyName());
154  contact.setSuffix(suffix());
155 }
156 
157 void NameEditDialog::setDisplayType(DisplayNameEditWidget::DisplayType type)
158 {
159  mDisplayNameEdit->setDisplayType(type);
160 }
161 
162 DisplayNameEditWidget::DisplayType NameEditDialog::displayType() const
163 {
164  return mDisplayNameEdit->displayType();
165 }
QString familyName() const
QString additionalName() const
void setSuffix(const QString &suffix)
A widget for editing the display name of a contact.
void setPrefix(const QString &prefix)
void setGivenName(const QString &givenName)
void setAdditionalName(const QString &additionalName)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
DisplayType
Describes what the display name should look like.
void setFamilyName(const QString &familyName)
QString suffix() const
void setShortcut(const QKeySequence &key)
QString i18n(const char *text, const TYPE &arg...)
void sort(Qt::CaseSensitivity cs)
QString givenName() const
void setDefault(bool)
Key_Return
QString prefix() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.