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 "ui_tagselectiondialog.h"
11 #include "tagmodel.h"
12 #include "monitor.h"
13 #include "controlgui.h"
14 
15 #include <KConfigGroup>
16 #include <KSharedConfig>
17 
18 using namespace Akonadi;
19 
20 class Q_DECL_HIDDEN TagSelectionDialog::Private
21 {
22 public:
23  explicit Private(QDialog *parent)
24  : q(parent)
25  {}
26 
27  void writeConfig() const;
28  void readConfig() const;
29 
30  QDialog * const q;
31  Ui::TagSelectionDialog ui;
32 };
33 
34 void TagSelectionDialog::Private::writeConfig() const
35 {
36  KConfigGroup group(KSharedConfig::openConfig(), "TagSelectionDialog");
37  group.writeEntry("Size", q->size());
38 }
39 
40 void TagSelectionDialog::Private::readConfig() const
41 {
42  KConfigGroup group(KSharedConfig::openConfig(), "TagSelectionDialog");
43  const QSize sizeDialog = group.readEntry("Size", QSize(500, 400));
44  if (sizeDialog.isValid()) {
45  q->resize(sizeDialog);
46  }
47 }
48 
49 TagSelectionDialog::TagSelectionDialog(QWidget *parent)
50  : QDialog(parent)
51  , d(new Private(this))
52 {
53  d->ui.setupUi(this);
54 
55  Monitor *monitor = new Monitor(this);
56  monitor->setObjectName(QStringLiteral("TagSelectionDialogMonitor"));
57  monitor->setTypeMonitored(Monitor::Tags);
58 
59  d->ui.tagWidget->setModel(new TagModel(monitor, this));
60  d->ui.tagWidget->setSelectionEnabled(true);
61 
62  d->readConfig();
63 
65 }
66 
67 TagSelectionDialog::TagSelectionDialog(TagModel *model, QWidget *parent)
68  : QDialog(parent)
69  , d(new Private(this))
70 {
71  d->ui.setupUi(this);
72 
73  d->ui.tagWidget->setModel(model);
74  d->ui.tagWidget->setSelectionEnabled(true);
75 
76  d->readConfig();
77 
79 }
80 
81 TagSelectionDialog::~TagSelectionDialog()
82 {
83  d->writeConfig();
84 }
85 
86 QDialogButtonBox *TagSelectionDialog::buttons() const
87 {
88  return d->ui.buttonBox;
89 }
90 
91 Tag::List TagSelectionDialog::selection() const
92 {
93  return d->ui.tagWidget->selection();
94 }
95 
96 void TagSelectionDialog::setSelection(const Tag::List &tags)
97 {
98  d->ui.tagWidget->setSelection(tags);
99 }
100 
bool isValid() const const
QAbstractItemModel * model() const const
A widget that shows a tag selection and provides means to edit that selection.
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:250
void setObjectName(const QString &name)
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
void setTypeMonitored(Type type, bool monitored=true)
Sets whether given type (Collection, Item, Tag should be monitored).
Definition: monitor.cpp:136
Monitors an item or collection for changes.
Definition: monitor.h:71
void readConfig()
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 4 2020 23:16:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.