• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
tagwidget.cpp
1 /*
2  This file is part of Akonadi
3 
4  Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
5  Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
6 
7  This library is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Library General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to the
19  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301, USA.
21 */
22 
23 #include "tagwidget.h"
24 
25 #include "tagmodel.h"
26 #include "changerecorder.h"
27 #include "tagselectiondialog.h"
28 
29 #include <kicon.h>
30 #include <klocalizedstring.h>
31 #include <ksqueezedtextlabel.h>
32 
33 #include <QHBoxLayout>
34 #include <QToolButton>
35 
36 using namespace Akonadi;
37 
38 struct TagWidget::Private {
39  QLabel *mTagLabel;
40  Akonadi::Tag::List mTags;
41  Akonadi::TagModel *mModel;
42 };
43 
44 TagWidget::TagWidget(QWidget *parent)
45  : QWidget(parent)
46  , d(new Private)
47 {
48  Monitor *monitor = new Monitor(this);
49  monitor->setTypeMonitored(Monitor::Tags);
50  d->mModel = new Akonadi::TagModel(monitor, this);
51 
52  QHBoxLayout *layout = new QHBoxLayout(this);
53  layout->setMargin(0);
54  layout->setSpacing(0);
55  d->mTagLabel = new KSqueezedTextLabel;
56  d->mTagLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
57  layout->addWidget(d->mTagLabel);
58 
59  QToolButton *editButton = new QToolButton;
60  editButton->setText(i18n("..."));
61  layout->addWidget(editButton, Qt::AlignRight);
62 
63  layout->setStretch(0, 10);
64 
65  connect(editButton, SIGNAL(clicked()), SLOT(editTags()));
66 }
67 
68 TagWidget::~TagWidget()
69 {
70 }
71 
72 void TagWidget::setSelection(const Akonadi::Tag::List &tags)
73 {
74  d->mTags = tags;
75  updateView();
76 }
77 
78 Akonadi::Tag::List TagWidget::selection() const
79 {
80  return d->mTags;
81 }
82 
83 void TagWidget::editTags()
84 {
85  QScopedPointer<Akonadi::TagSelectionDialog> dlg(new TagSelectionDialog(this));
86  dlg->setSelection(d->mTags);
87  if (dlg->exec() == QDialog::Accepted) {
88  d->mTags = dlg->selection();
89  updateView();
90  emit selectionChanged(d->mTags);
91  }
92 }
93 
94 void TagWidget::updateView()
95 {
96  QStringList tagsNames;
97  // Load the real tag names from the model
98  for (int i = 0; i < d->mModel->rowCount(); ++i) {
99  const QModelIndex index = d->mModel->index(i, 0);
100  const Akonadi::Tag tag = d->mModel->data(index, Akonadi::TagModel::TagRole).value<Akonadi::Tag>();
101  if (d->mTags.contains(tag)) {
102  tagsNames << tag.name();
103  }
104  }
105  d->mTagLabel->setText(tagsNames.join(QLatin1String(", ")));
106 }
QModelIndex
QWidget
QHBoxLayout
QBoxLayout::setStretch
void setStretch(int index, int stretch)
QStringList::join
QString join(const QString &separator) const
QSharedPointer::data
T * data() const
Akonadi::TagSelectionDialog
A widget that shows a tag selection and provides means to edit that selection.
Definition: tagselectiondialog.h:38
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QScopedPointer
QList
QLayout::setMargin
void setMargin(int margin)
QStringList
QToolButton
Akonadi::Monitor::setTypeMonitored
void setTypeMonitored(Type type, bool monitored=true)
Sets whether given type (Collection, Item, Tag should be monitored).
Definition: monitor.cpp:166
Akonadi::Monitor
Monitors an item or collection for changes.
Definition: monitor.h:74
QLatin1String
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:43
QAbstractButton::setText
void setText(const QString &text)
QLabel
QBoxLayout::setSpacing
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal