Akonadi Contacts

phonecomboboxtype.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016 eyeOS S.L.U., a Telefonica company, [email protected]
5  SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel.org>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "phonecomboboxtype.h"
11 #include "phonetypedialog.h"
12 #include <KLocalizedString>
13 #include <QPointer>
14 
15 using namespace ContactEditor;
16 
18  : ContactEditor::ContactEditorComboBox(parent)
19 {
20  const int nbMax = KContacts::PhoneNumber::typeList().count();
21  mTypeList.reserve(nbMax + 1);
22  for (int i = 0; i < nbMax; ++i) {
24  if (typeflag != KContacts::PhoneNumber::Pref) {
25  mTypeList.append(typeflag);
26  }
27  }
28 
29  mTypeList.append(-1); // Others...
30 
31  update();
32 
33  connect(this, QOverload<int>::of(&PhoneComboBoxType::activated), this, &PhoneComboBoxType::selected);
34 }
35 
37 {
38 }
39 
41 {
42  if (static_cast<int>(type) != 0) {
43  if (!mTypeList.contains(type)) {
44  mTypeList.insert(mTypeList.at(mTypeList.count() - 1), type);
45  }
46  }
47  mType = type;
48  update();
49 }
50 
52 {
53  return mType;
54 }
55 
56 void PhoneComboBoxType::resetToDefault()
57 {
58  setCurrentIndex(0);
59 }
60 
61 void PhoneComboBoxType::update()
62 {
63  clear();
64 
65  const int typeListCount(mTypeList.count());
66  for (int i = 0; i < typeListCount; ++i) {
67  if (mTypeList.at(i) == -1) { // "Other..." entry
68  addItem(i18nc("@item:inlistbox Category of contact info field", "Other..."));
69  } else {
71  }
72  }
73 
74  setCurrentIndex(mLastSelected = mTypeList.indexOf(mType));
75 }
76 
77 void PhoneComboBoxType::selected(int pos)
78 {
79  if (mTypeList.at(pos) == -1) {
80  otherSelected();
81  } else {
82  mType = KContacts::PhoneNumber::Type(mTypeList.at(pos));
83  mLastSelected = pos;
84  }
85 }
86 
87 void PhoneComboBoxType::otherSelected()
88 {
90  if (dlg->exec()) {
91  mType = dlg->type();
92  if (!mTypeList.contains(mType)) {
93  if (static_cast<int>(mType) != 0) {
94  mTypeList.insert(mTypeList.at(mTypeList.count() - 1), mType);
95  }
96  }
97  } else {
98  setType(KContacts::PhoneNumber::Type(mTypeList.at(mLastSelected)));
99  }
100  delete dlg;
101  update();
102 }
A dialog for editing phone number types.
QFlags< TypeFlag > Type
void reserve(int alloc)
const T & at(int i) const const
void clear()
static TypeList typeList()
int indexOf(const T &value, int from) const const
void addItem(const QString &text, const QVariant &userData)
int count(const T &value) const const
void append(const T &value)
void setType(KContacts::PhoneNumber::Type type)
Sets the phone number type that shall be selected.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KContacts::PhoneNumber::Type type() const
Returns the selected phone number type.
void activated(int index)
QPoint pos() const const
bool contains(const T &value) const const
QString typeLabel() const
const T & at(int i) const const
~PhoneComboBoxType()
Destroys the phone type combo.
void insert(int i, const T &value)
int count(const T &value) const const
void setCurrentIndex(int index)
PhoneComboBoxType(QWidget *parent=nullptr)
Creates a phone type combo.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Jun 20 2021 23:09:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.