13#include "changerecorder.h"
15#include "tagselectiondialog.h"
17#include <KLocalizedString>
19#include <QContextMenuEvent>
29class TagView :
public QLineEdit
38 void contextMenuEvent(QContextMenuEvent *
event)
override
40 if (
text().isEmpty()) {
48 void mousePressEvent(QMouseEvent *
event)
override
62#include "ui_tagwidget.h"
64class Akonadi::TagWidgetPrivate
68 Akonadi::Tag::List mTags;
69 Akonadi::TagModel *mModel =
nullptr;
72TagWidget::TagWidget(
QWidget *parent)
74 , d(new TagWidgetPrivate)
76 auto monitor =
new Monitor(
this);
78 monitor->setTypeMonitored(Monitor::Tags);
79 d->mModel =
new Akonadi::TagModel(monitor,
this);
83 connect(d->ui.tagView, &TagView::clearTags,
this, &TagWidget::clearTags);
84 connect(d->ui.tagView, &TagView::addTags,
this, &TagWidget::editTags);
87 connect(d->mModel, &Akonadi::TagModel::populated,
this, &TagWidget::updateView);
90TagWidget::~TagWidget() =
default;
92void TagWidget::clearTags()
94 if (!d->mTags.isEmpty()) {
96 d->ui.tagView->clear();
97 Q_EMIT selectionChanged(d->mTags);
101void TagWidget::setSelection(
const Akonadi::Tag::List &tags)
103 if (d->mTags != tags) {
106 Q_EMIT selectionChanged(d->mTags);
110Akonadi::Tag::List TagWidget::selection()
const
115void TagWidget::setReadOnly(
bool readOnly)
117 d->ui.editButton->setEnabled(!readOnly);
121void TagWidget::editTags()
123 QScopedPointer<Akonadi::TagSelectionDialog> dlg(
new TagSelectionDialog(d->mModel,
this));
124 dlg->setSelection(d->mTags);
126 d->mTags = dlg->selection();
128 Q_EMIT selectionChanged(d->mTags);
132void TagWidget::updateView()
134 QStringList tagsNames;
136 for (
int i = 0; i < d->mModel->rowCount(); ++i) {
137 const QModelIndex index = d->mModel->index(i, 0);
138 const auto tag = d->mModel->data(index, Akonadi::TagModel::TagRole).value<Akonadi::Tag>();
139 if (d->mTags.contains(tag)) {
143 d->ui.tagView->setText(
QLocale::system().createSeparatedList(tagsNames));
146#include "tagwidget.moc"
148#include "moc_tagwidget.cpp"
Monitors an item or collection for changes.
void tagAdded(const Akonadi::Tag &tag)
This signal is emitted if a tag has been added to Akonadi storage.
QString i18n(const char *text, const TYPE &arg...)
Helper integration between Akonadi and Qt.
QLineEdit(QWidget *parent)
virtual void mousePressEvent(QMouseEvent *e) override
void push_back(parameter_type value)
virtual bool event(QEvent *e)
QObject * parent() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)