Akonadi Contacts

personaleditorwidget.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "personaleditorwidget.h"
10
11#include <KLineEdit>
12#include <KLocalizedString>
13#include <QGridLayout>
14#include <QLabel>
15
16#include "dateeditwidget.h"
17
18#include <KContacts/Addressee>
19
20using namespace Akonadi;
21
22PersonalEditorWidget::PersonalEditorWidget(QWidget *parent)
23 : QWidget(parent)
24 , mBirthdateWidget(new DateEditWidget(DateEditWidget::Birthday, this))
25 , mAnniversaryWidget(new DateEditWidget(DateEditWidget::Anniversary, this))
26 , mPartnerWidget(new KLineEdit(this))
27{
28 auto mainLayout = new QGridLayout(this);
29 auto label = new QLabel(i18nc("@label The birthdate of a contact", "Birthdate:"));
30 mainLayout->addWidget(label, 0, 0);
31
32 label->setBuddy(mBirthdateWidget);
33 mainLayout->addWidget(mBirthdateWidget, 1, 0);
34
35 label = new QLabel(i18nc("@label The wedding anniversary of a contact", "Anniversary:"));
36 mainLayout->addWidget(label, 0, 1);
37
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->setPlaceholderText(i18n("Add name"));
45 mPartnerWidget->setTrapReturnKey(true);
46 label->setBuddy(mPartnerWidget);
47 mainLayout->addWidget(mPartnerWidget, 1, 2);
48 mainLayout->setColumnStretch(1, 1);
49 mainLayout->setColumnStretch(0, 1);
50 mainLayout->setColumnStretch(2, 1);
51
52 mainLayout->setRowStretch(2, 1);
53}
54
55PersonalEditorWidget::~PersonalEditorWidget() = default;
56
57void PersonalEditorWidget::loadContact(const KContacts::Addressee &contact)
58{
59 mBirthdateWidget->setDate(contact.birthday().date());
60 mAnniversaryWidget->setDate(contact.anniversary());
61
62 // family group
63 mPartnerWidget->setText(contact.spousesName());
64}
65
66void PersonalEditorWidget::storeContact(KContacts::Addressee &contact)
67{
68 contact.setBirthday(mBirthdateWidget->date());
69 contact.setAnniversary(mAnniversaryWidget->date());
70
71 // family group
72 contact.setSpousesName(mPartnerWidget->text().trimmed());
73}
74
75void PersonalEditorWidget::setReadOnly(bool readOnly)
76{
77 // widgets from dates group
78 mBirthdateWidget->setReadOnly(readOnly);
79 mAnniversaryWidget->setReadOnly(readOnly);
80
81 // widgets from family group
82 mPartnerWidget->setReadOnly(readOnly);
83}
84
85#include "moc_personaleditorwidget.cpp"
QDateTime birthday() const
QDate anniversary() const
void setBirthday(const QDate &birthday)
void setAnniversary(const QDate &anniversary)
void setSpousesName(const QString &spousesName)
QString spousesName() const
virtual void setReadOnly(bool)
virtual void setText(const QString &)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
QString label(StandardShortcut id)
QDate date() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:57:56 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.