Akonadi Contacts

phonetypedialog.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016-2023 Laurent Montel <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "phonetypedialog.h"
10 #include <KLocalizedString>
11 
12 #include <QButtonGroup>
13 #include <QCheckBox>
14 #include <QDialogButtonBox>
15 #include <QPushButton>
16 #include <QVBoxLayout>
17 
18 using namespace ContactEditor;
19 
21  : QDialog(parent)
22  , mType(type)
23 {
24  setWindowTitle(i18nc("@title:window", "Edit Phone Number"));
25 
26  auto layout = new QVBoxLayout(this);
27 
28  auto buttonLayout = new QGridLayout;
29  layout->addLayout(buttonLayout);
30 
31  // fill widgets
35  int row;
36  int column;
37  int counter;
38  row = column = counter = 0;
39  mGroup = new QButtonGroup(this);
40  mGroup->setExclusive(false);
41  for (it = mTypeList.constBegin(); it != mTypeList.constEnd(); ++it, ++counter) {
42  auto cb = new QCheckBox(KContacts::PhoneNumber::typeLabel(*it), this);
43  cb->setChecked(type & mTypeList[counter]);
44  buttonLayout->addWidget(cb, row, column);
45  mGroup->addButton(cb);
46 
47  column++;
48  if (column == 5) {
49  column = 0;
50  ++row;
51  }
52  }
53 
55  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
56  okButton->setDefault(true);
57  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
58  layout->addWidget(buttonBox);
61 }
62 
64 {
66 
67  for (int i = 0; i < mGroup->buttons().count(); ++i) {
68  auto box = qobject_cast<QCheckBox *>(mGroup->buttons().at(i));
69  if (box && box->isChecked()) {
70  type |= mTypeList[i];
71  }
72  }
73  return type;
74 }
static TypeList typeList()
virtual void reject()
void setShortcut(const QKeySequence &key)
QLayout * layout() const const
QVector::const_iterator constEnd() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addButton(QAbstractButton *button, int id)
QString typeLabel() const
KContacts::PhoneNumber::Type type() const
Returns the selected type.
void setWindowTitle(const QString &)
virtual void accept()
Key_Return
int removeAll(const T &t)
void addWidget(QWidget *w)
void setExclusive(bool)
QList< QAbstractButton * > buttons() const const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
QVector::const_iterator constBegin() const const
PhoneTypeDialog(KContacts::PhoneNumber::Type type, QWidget *parent=nullptr)
Creates a new phone type dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.