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({});
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() = default;
66 
67 KContacts::Address::Type AddressTypeDialog::type() const
68 {
70  const int numberOfButtons(mGroup->buttons().count());
71  for (int i = 0; i < numberOfButtons; ++i) {
72  auto box = qobject_cast<QCheckBox *>(mGroup->buttons().at(i));
73  if (box && box->isChecked()) {
74  type |= mTypeList[i];
75  }
76  }
77 
78  return type;
79 }
QString typeLabel() const
virtual void reject()
void setShortcut(const QKeySequence &key)
Type type(const QSqlDatabase &db)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual void accept()
Key_Return
static TypeList typeList()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
const QList< QKeySequence > & end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.