Akonadi Contacts

phonetypedialog.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
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
18using namespace Akonadi;
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);
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}
75
76#include "moc_phonetypedialog.cpp"
PhoneTypeDialog(KContacts::PhoneNumber::Type type, QWidget *parent=nullptr)
Creates a new phone type dialog.
KContacts::PhoneNumber::Type type() const
Returns the selected type.
QString typeLabel() const
static TypeList typeList()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
void setShortcut(const QKeySequence &key)
void addButton(QAbstractButton *button, int id)
QList< QAbstractButton * > buttons() const const
void setExclusive(bool)
virtual void accept()
virtual void reject()
void addWidget(QWidget *w)
const_iterator constBegin() const const
const_iterator constEnd() const const
qsizetype removeAll(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
void setDefault(bool)
Key_Return
QLayout * layout() const const
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.