Akonadi Contacts

emailaddressselectiondialog.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2010 KDAB
5  SPDX-FileContributor: Tobias Koenig <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "emailaddressselectiondialog.h"
11 #include "recipientspicker/recipientspickerwidget.h"
12 
13 
14 #include <KConfigGroup>
15 
16 #include <KSharedConfig>
17 #include <QVBoxLayout>
18 #include <QDialogButtonBox>
19 #include <QPushButton>
20 #include <QTreeView>
21 
22 
23 using namespace Akonadi;
24 
25 class Q_DECL_HIDDEN EmailAddressSelectionDialog::Private
26 {
27 public:
29  : q(qq)
30  {
31  QVBoxLayout *mainLayout = new QVBoxLayout(q);
32  if (model) {
33  mView = new RecipientsPickerWidget(true, model, q);
34  } else {
35  mView = new RecipientsPickerWidget(true, nullptr, q);
36  }
37  mainLayout->addWidget(mView);
38  q->connect(mView->emailAddressSelectionWidget()->view(), &QTreeView::doubleClicked, q, &QDialog::accept);
40  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
41  okButton->setDefault(true);
42  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
43  connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept);
44  connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject);
45 
46  mainLayout->addWidget(buttonBox);
47  readConfig();
48  }
49 
50  void readConfig()
51  {
52  KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("EmailAddressSelectionDialog"));
53  const QSize size = group.readEntry("Size", QSize());
54  if (size.isValid()) {
55  q->resize(size);
56  } else {
57  q->resize(q->sizeHint().width(), q->sizeHint().height());
58  }
59  }
60 
61  void writeConfig()
62  {
63  KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("EmailAddressSelectionDialog"));
64  group.writeEntry("Size", q->size());
65  }
66 
68  RecipientsPickerWidget *mView = nullptr;
69 };
70 
72  : AbstractEmailAddressSelectionDialog(parent)
73  , d(new Private(this, nullptr))
74 {
75 }
76 
78  : AbstractEmailAddressSelectionDialog(parent)
79  , d(new Private(this, model))
80 {
81 }
82 
84 {
85  d->writeConfig();
86  delete d;
87 }
88 
90 {
91  return d->mView->emailAddressSelectionWidget()->selectedAddresses();
92 }
93 
95 {
96  return d->mView->emailAddressSelectionWidget();
97 }
void doubleClicked(const QModelIndex &index)
bool isValid() const const
virtual void reject()
EmailAddressSelectionWidget * view() const override
Returns the email address selection view that is used.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
A dialog to select email addresses from Akonadi.
A widget to select email addresses from Akonadi.
void setShortcut(const QKeySequence &key)
virtual void accept()
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
void readConfig()
~EmailAddressSelectionDialog() override
Destroys the email address selection dialog.
QPushButton * button(QDialogButtonBox::StandardButton which) const const
EmailAddressSelection::List selectedAddresses() const override
Returns the list of selected email addresses.
QObject * parent() const const
EmailAddressSelectionDialog(QWidget *parent=nullptr)
Creates a new email address selection dialog.
void setDefault(bool)
Key_Return
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Sep 23 2020 23:08:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.