Akonadi Contacts

addresstypedialog.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "addresstypedialog.h"
10 #include <KLocalizedString>
11 #include <QButtonGroup>
12 #include <QCheckBox>
13 #include <QDialogButtonBox>
14 #include <QGroupBox>
15 #include <QPushButton>
16 #include <QVBoxLayout>
17 
18 using namespace ContactEditor;
19 
20 AddressTypeDialog::AddressTypeDialog(KContacts::Address::Type type, QWidget *parent)
21  : QDialog(parent)
22 {
23  auto mainLayout = new QVBoxLayout(this);
24  setWindowTitle(i18nc("street/postal", "Edit Address Type"));
26  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
27  okButton->setDefault(true);
28  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
31 
32  auto page = new QWidget(this);
33  mainLayout->addWidget(page);
34  mainLayout->addWidget(buttonBox);
35  auto layout = new QVBoxLayout(page);
36  layout->setContentsMargins(0, 0, 0, 0);
37 
38  auto box = new QGroupBox(i18nc("street/postal", "Address Types"), page);
39  mainLayout->addWidget(box);
40  layout->addWidget(box);
41  mGroup = new QButtonGroup(box);
42  mGroup->setExclusive(false);
43 
44  auto buttonLayout = new QGridLayout(box);
45 
46  mTypeList = KContacts::Address::typeList();
47  mTypeList.removeAll(KContacts::Address::Pref);
48 
50  int i = 0;
51  int row = 0;
53  for (it = mTypeList.constBegin(); it != end; ++it, ++i) {
54  auto cb = new QCheckBox(KContacts::Address::typeLabel(*it), box);
55  cb->setChecked(type & mTypeList[i]);
56  buttonLayout->addWidget(cb, row, i % 3);
57 
58  if (i % 3 == 2) {
59  ++row;
60  }
61  mGroup->addButton(cb);
62  }
63 }
64 
65 AddressTypeDialog::~AddressTypeDialog()
66 {
67 }
68 
69 KContacts::Address::Type AddressTypeDialog::type() const
70 {
72  const int numberOfButtons(mGroup->buttons().count());
73  for (int i = 0; i < numberOfButtons; ++i) {
74  auto box = qobject_cast<QCheckBox *>(mGroup->buttons().at(i));
75  if (box && box->isChecked()) {
76  type |= mTypeList[i];
77  }
78  }
79 
80  return type;
81 }
virtual void reject()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setShortcut(const QKeySequence &key)
virtual void accept()
static TypeList typeList()
const QList< QKeySequence > & end()
QString typeLabel() 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.