Akonadi Contacts

phonewidget.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2016 eyeOS S.L.U., a Telefonica company, sales@eyeos.com
5 SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "phonewidget.h"
11#include "editor/widgets/preferredlineeditwidget.h"
12#include "phonecomboboxtype.h"
13
14#include <KLocalizedString>
15
16#include <QHBoxLayout>
17#include <QToolButton>
18
19using namespace Akonadi;
20PhoneWidget::PhoneWidget(QWidget *parent)
21 : QWidget(parent)
22 , mPhoneNumberEdit(new PreferredLineEditWidget(this))
23 , mAddButton(new QToolButton(this))
24 , mRemoveButton(new QToolButton(this))
25 , mPhoneType(new PhoneComboBoxType(this))
26{
27 auto layout = new QHBoxLayout(this);
28 layout->setSpacing(0);
29 layout->setContentsMargins({});
30
31 mPhoneNumberEdit->setTrapReturnKey(true);
32 mPhoneNumberEdit->setPlaceholderText(i18nc("@info:placeholder", "Add a Phone Number"));
33 mPhoneNumberEdit->setObjectName(QLatin1StringView("phonenumber"));
34 layout->addWidget(mPhoneNumberEdit);
35 connect(mPhoneNumberEdit, &PreferredLineEditWidget::preferredChanged, this, &PhoneWidget::slotPreferredChanged);
36
37 mPhoneType->setObjectName(QLatin1StringView("phonetype"));
38 layout->addWidget(mPhoneType);
39
40 mAddButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
41 mAddButton->setToolTip(i18nc("@info:tooltip", "Add a Phone Number"));
42 mAddButton->setObjectName(QLatin1StringView("addbutton"));
43 connect(mAddButton, &QToolButton::clicked, this, &PhoneWidget::slotAddPhone);
44 layout->addWidget(mAddButton);
45
46 mRemoveButton->setObjectName(QLatin1StringView("removebutton"));
47 mRemoveButton->setToolTip(i18nc("@info:tooltip", "Remove Phone Number"));
48 mRemoveButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
49 connect(mRemoveButton, &QToolButton::clicked, this, &PhoneWidget::slotRemovePhone);
50 layout->addWidget(mRemoveButton);
51}
52
53PhoneWidget::~PhoneWidget() = default;
54
55void PhoneWidget::updateAddRemoveButton(bool addButtonEnabled)
56{
57 mAddButton->setEnabled(addButtonEnabled);
58}
59
60KContacts::PhoneNumber PhoneWidget::storePhone()
61{
63 number.setNumber(mPhoneNumberEdit->text());
64 KContacts::PhoneNumber::Type currentType = mPhoneType->type();
65 if (mPhoneNumberEdit->preferred()) {
66 currentType |= KContacts::PhoneNumber::Pref;
67 }
68 number.setType(currentType);
69 return number;
70}
71
72void PhoneWidget::loadPhone(const KContacts::PhoneNumber &number)
73{
74 mPhoneNumberEdit->setText(number.number());
75 KContacts::PhoneNumber::Type currentType = number.type();
76 mPhoneType->setType(number.type() & ~KContacts::PhoneNumber::Pref);
77 mPhoneNumberEdit->setPreferred(currentType & KContacts::PhoneNumber::Pref);
78}
79
80void PhoneWidget::slotAddPhone()
81{
82 Q_EMIT addWidget(this);
83}
84
85void PhoneWidget::slotRemovePhone()
86{
87 Q_EMIT removeWidget(this);
88}
89
90void PhoneWidget::clearWidget()
91{
92 mPhoneNumberEdit->clear();
93 mPhoneType->resetToDefault();
94}
95
96void PhoneWidget::slotPreferredChanged()
97{
98 Q_EMIT preferredChanged(this);
99}
100
101void PhoneWidget::setPreferred(bool b)
102{
103 mPhoneNumberEdit->setPreferred(b);
104}
105
106void PhoneWidget::setReadOnly(bool readOnly)
107{
108 mPhoneNumberEdit->setReadOnly(readOnly);
109 mAddButton->setEnabled(!readOnly);
110 mRemoveButton->setEnabled(!readOnly);
111 mPhoneType->setEnabled(!readOnly);
112}
113
114#include "moc_phonewidget.cpp"
A combobox to select a phone number type.
void setType(KContacts::PhoneNumber::Type type)
Sets the phone number type that shall be selected.
KContacts::PhoneNumber::Type type() const
Returns the selected phone number type.
virtual void setReadOnly(bool)
virtual void setText(const QString &)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
KIOCORE_EXPORT QString number(KIO::filesize_t size)
void clicked(bool checked)
QIcon fromTheme(const QString &name)
void clear()
Q_EMITQ_EMIT
QString number(double n, char format, int precision)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.