Akonadi

tagselectiondialog.cpp
1 /*
2  This file is part of Akonadi
3 
4  SPDX-FileCopyrightText: 2014 Christian Mollekopf <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "tagselectiondialog.h"
10 #include "controlgui.h"
11 #include "monitor.h"
12 #include "tagmodel.h"
13 #include "ui_tagselectiondialog.h"
14 
15 #include <KConfigGroup>
16 #include <KSharedConfig>
17 
18 using namespace Akonadi;
19 
20 class Akonadi::TagSelectionDialogPrivate
21 {
22 public:
23  explicit TagSelectionDialogPrivate(QDialog *parent)
24  : q(parent)
25  {
26  }
27 
28  void writeConfig() const;
29  void readConfig() const;
30 
31  QDialog *const q;
32  Ui::TagSelectionDialog ui;
33 };
34 
35 void TagSelectionDialogPrivate::writeConfig() const
36 {
37  KConfigGroup group(KSharedConfig::openStateConfig(), "TagSelectionDialog");
38  group.writeEntry("Size", q->size());
39 }
40 
41 void TagSelectionDialogPrivate::readConfig() const
42 {
43  KConfigGroup group(KSharedConfig::openStateConfig(), "TagSelectionDialog");
44  const QSize sizeDialog = group.readEntry("Size", QSize(500, 400));
45  if (sizeDialog.isValid()) {
46  q->resize(sizeDialog);
47  }
48 }
49 
50 TagSelectionDialog::TagSelectionDialog(QWidget *parent)
51  : QDialog(parent)
52  , d(new TagSelectionDialogPrivate(this))
53 {
54  d->ui.setupUi(this);
55 
56  auto monitor = new Monitor(this);
57  monitor->setObjectName(QStringLiteral("TagSelectionDialogMonitor"));
58  monitor->setTypeMonitored(Monitor::Tags);
59 
60  d->ui.tagWidget->setModel(new TagModel(monitor, this));
61  d->ui.tagWidget->setSelectionEnabled(true);
62 
63  d->readConfig();
64 
66 }
67 
68 TagSelectionDialog::TagSelectionDialog(TagModel *model, QWidget *parent)
69  : QDialog(parent)
70  , d(new TagSelectionDialogPrivate(this))
71 {
72  d->ui.setupUi(this);
73 
74  d->ui.tagWidget->setModel(model);
75  d->ui.tagWidget->setSelectionEnabled(true);
76 
77  d->readConfig();
78 
80 }
81 
82 TagSelectionDialog::~TagSelectionDialog()
83 {
84  d->writeConfig();
85 }
86 
87 QDialogButtonBox *TagSelectionDialog::buttons() const
88 {
89  return d->ui.buttonBox;
90 }
91 
92 Tag::List TagSelectionDialog::selection() const
93 {
94  return d->ui.tagWidget->selection();
95 }
96 
97 void TagSelectionDialog::setSelection(const Tag::List &tags)
98 {
99  d->ui.tagWidget->setSelection(tags);
100 }
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
Definition: controlgui.cpp:243
bool isValid() const const
void readConfig()
QAbstractItemModel * model() const const
Monitors an item or collection for changes.
Definition: monitor.h:71
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Dec 6 2022 03:53:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.