Akonadi Contacts

addresstypedialog.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
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
18using namespace Akonadi;
19
20AddressTypeDialog::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);
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
65AddressTypeDialog::~AddressTypeDialog() = default;
66
67KContacts::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}
80
81#include "moc_addresstypedialog.cpp"
static TypeList typeList()
QString typeLabel() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
A widget for editing the display name of a contact.
const QList< QKeySequence > & end()
void setShortcut(const QKeySequence &key)
QList< QAbstractButton * > buttons() const const
virtual void accept()
virtual void reject()
T qobject_cast(QObject *object)
void setDefault(bool)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.