File indexing completed on 2024-11-24 04:39:32

0001 /*
0002     This file is part of Contact Editor.
0003 
0004     SPDX-FileCopyrightText: 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
0005     SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include "nicknamewidget.h"
0011 #include <KContacts/Addressee>
0012 #include <KLineEdit>
0013 #include <KLocalizedString>
0014 #include <QLabel>
0015 #include <QVBoxLayout>
0016 using namespace Akonadi;
0017 
0018 NicknameWidget::NicknameWidget(QWidget *parent)
0019     : QWidget(parent)
0020     , mNickName(new KLineEdit(this))
0021 {
0022     auto topLayout = new QVBoxLayout(this);
0023     topLayout->setContentsMargins({});
0024     topLayout->setObjectName(QLatin1StringView("mainlayout"));
0025     auto nickNameLabel = new QLabel(i18n("Nickname"), this);
0026     nickNameLabel->setObjectName(QLatin1StringView("nicknamelabel"));
0027     topLayout->addWidget(nickNameLabel);
0028 
0029     mNickName->setTrapReturnKey(true);
0030     mNickName->setPlaceholderText(i18n("Add a Nickname"));
0031     mNickName->setObjectName(QLatin1StringView("nickname"));
0032     topLayout->addWidget(mNickName);
0033 }
0034 
0035 NicknameWidget::~NicknameWidget() = default;
0036 
0037 void NicknameWidget::loadContact(const KContacts::Addressee &contact)
0038 {
0039     mNickName->setText(contact.nickName());
0040 }
0041 
0042 void NicknameWidget::storeContact(KContacts::Addressee &contact) const
0043 {
0044     contact.setNickName(mNickName->text().trimmed());
0045 }
0046 
0047 void NicknameWidget::setReadOnly(bool readOnly)
0048 {
0049     mNickName->setReadOnly(readOnly);
0050 }
0051 
0052 #include "moc_nicknamewidget.cpp"