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

akonadi

  • 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
36using namespace Akonadi;
37
38struct TagWidget::Private {
39 QLabel *mTagLabel;
40 Akonadi::Tag::List mTags;
41 Akonadi::TagModel *mModel;
42};
43
44TagWidget::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
68TagWidget::~TagWidget()
69{
70}
71
72void TagWidget::setSelection(const Akonadi::Tag::List &tags)
73{
74 d->mTags = tags;
75 updateView();
76}
77
78Akonadi::Tag::List TagWidget::selection() const
79{
80 return d->mTags;
81}
82
83void 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
94void 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}
Akonadi::Monitor
Monitors an item or collection for changes.
Definition monitor.h:75
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::TagSelectionDialog
A widget that shows a tag selection and provides means to edit that selection.
Definition tagselectiondialog.h:39
Akonadi::Tag
An Akonadi Tag.
Definition tag.h:44
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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