Akonadi Contacts

phonetypedialog.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016-2020 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  QVBoxLayout *layout = new QVBoxLayout(this);
27 
28  QGridLayout *buttonLayout = new QGridLayout;
29  layout->addLayout(buttonLayout);
30 
31  // fill widgets
35  int row, column, counter;
36  row = column = counter = 0;
37  mGroup = new QButtonGroup(this);
38  mGroup->setExclusive(false);
39  for (it = mTypeList.constBegin(); it != mTypeList.constEnd(); ++it, ++counter) {
41  cb->setChecked(type & mTypeList[counter]);
42  buttonLayout->addWidget(cb, row, column);
43  mGroup->addButton(cb);
44 
45  column++;
46  if (column == 5) {
47  column = 0;
48  ++row;
49  }
50  }
51 
53  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
54  okButton->setDefault(true);
55  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
56  layout->addWidget(buttonBox);
59 }
60 
62 {
64 
65  for (int i = 0; i < mGroup->buttons().count(); ++i) {
66  QCheckBox *box = qobject_cast<QCheckBox *>(mGroup->buttons().at(i));
67  if (box && box->isChecked()) {
68  type |= mTypeList[i];
69  }
70  }
71  return type;
72 }
QLayout * layout() const const
virtual void reject()
int removeAll(const T &t)
void addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment)
void addButton(QAbstractButton *button, int id)
QVector::const_iterator constEnd() const const
PhoneTypeDialog(KContacts::PhoneNumber::Type type, QWidget *parent=nullptr)
Creates a new phone type dialog.
static TypeList typeList()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setExclusive(bool)
void setShortcut(const QKeySequence &key)
virtual void accept()
QString typeLabel() const
void setChecked(bool)
QVector::const_iterator constBegin() const const
QList< QAbstractButton * > buttons() const const
KContacts::PhoneNumber::Type type() const
Returns the selected type.
void setWindowTitle(const QString &)
QPushButton * button(QDialogButtonBox::StandardButton which) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
void setDefault(bool)
Key_Return
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 25 2020 23:09:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.