Akonadi Contacts

personaleditorwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "personaleditorwidget.h"
10 #include "../utils/utils.h"
11 
12 #include <KLineEdit>
13 #include <KLocalizedString>
14 #include <QGridLayout>
15 #include <QLabel>
16 
17 #include "dateeditwidget.h"
18 
19 #include <KContacts/Addressee>
20 
21 using namespace ContactEditor;
22 
23 PersonalEditorWidget::PersonalEditorWidget(QWidget *parent)
24  : QWidget(parent)
25 {
26  auto mainLayout = new QGridLayout(this);
27  auto label = new QLabel(i18nc("@label The birthdate of a contact", "Birthdate:"));
28  mainLayout->addWidget(label, 0, 0);
29 
30  mBirthdateWidget = new DateEditWidget(DateEditWidget::Birthday);
31  label->setBuddy(mBirthdateWidget);
32  mainLayout->addWidget(mBirthdateWidget, 1, 0);
33 
34  label = new QLabel(i18nc("@label The wedding anniversary of a contact", "Anniversary:"));
35  mainLayout->addWidget(label, 0, 1);
36 
37  mAnniversaryWidget = new DateEditWidget(DateEditWidget::Anniversary);
38  label->setBuddy(mAnniversaryWidget);
39  mainLayout->addWidget(mAnniversaryWidget, 1, 1);
40 
41  label = new QLabel(i18nc("@label The partner's name of a contact", "Partner's name:"));
42  mainLayout->addWidget(label, 0, 2);
43 
44  mPartnerWidget = new KLineEdit;
45  mPartnerWidget->setPlaceholderText(i18n("Add name"));
46  mPartnerWidget->setTrapReturnKey(true);
47  label->setBuddy(mPartnerWidget);
48  mainLayout->addWidget(mPartnerWidget, 1, 2);
49  mainLayout->setColumnStretch(1, 1);
50  mainLayout->setColumnStretch(0, 1);
51  mainLayout->setColumnStretch(2, 1);
52 
53  mainLayout->setRowStretch(2, 1);
54 }
55 
56 PersonalEditorWidget::~PersonalEditorWidget()
57 {
58 }
59 
60 void PersonalEditorWidget::loadContact(const KContacts::Addressee &contact)
61 {
62  mBirthdateWidget->setDate(contact.birthday().date());
63  mAnniversaryWidget->setDate(contact.anniversary());
64 
65  // family group
66  mPartnerWidget->setText(contact.spousesName());
67 }
68 
69 void PersonalEditorWidget::storeContact(KContacts::Addressee &contact)
70 {
71  contact.setBirthday(mBirthdateWidget->date());
72  contact.setAnniversary(mAnniversaryWidget->date());
73 
74  // family group
75  contact.setSpousesName(mPartnerWidget->text().trimmed());
76 }
77 
78 void PersonalEditorWidget::setReadOnly(bool readOnly)
79 {
80  // widgets from dates group
81  mBirthdateWidget->setReadOnly(readOnly);
82  mAnniversaryWidget->setReadOnly(readOnly);
83 
84  // widgets from family group
85  mPartnerWidget->setReadOnly(readOnly);
86 }
void setAnniversary(const QDate &anniversary)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
void setSpousesName(const QString &spousesName)
void setPlaceholderText(const QString &)
QDateTime birthday() const
QString spousesName() const
QString i18n(const char *text, const TYPE &arg...)
QDate date() const const
void setBirthday(const QDateTime &birthday, bool withTime=true)
QDate anniversary() 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.