1
/*****************************************************************************
2
* Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
4
* This library is free software; you can redistribute it and/or *
5
* modify it under the terms of the GNU Library General Public *
6
* License version 2 as published by the Free Software Foundation. *
8
* This library is distributed in the hope that it will be useful, *
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
11
* Library General Public License for more details. *
13
* You should have received a copy of the GNU Library General Public License *
14
* along with this library; see the file COPYING.LIB. If not, write to *
15
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
16
* Boston, MA 02110-1301, USA. *
17
*****************************************************************************/
19
#include "ktaggingwidget_p.h"
21
#include "kedittagsdialog_p.h"
23
#include <kglobalsettings.h>
29
#include <QVBoxLayout>
31
KTaggingWidget::KTaggingWidget(QWidget* parent) :
38
m_label = new QLabel(this);
39
m_label->setFont(KGlobalSettings::smallestReadableFont());
40
m_label->setWordWrap(true);
41
m_label->setAlignment(Qt::AlignTop);
42
connect(m_label, SIGNAL(linkActivated(const QString&)), this, SLOT(slotLinkActivated(const QString&)));
44
QVBoxLayout* layout = new QVBoxLayout(this);
46
layout->addWidget(m_label);
48
setTags(QList<Nepomuk::Tag>());
51
KTaggingWidget::~KTaggingWidget()
55
void KTaggingWidget::setTags(const QList<Nepomuk::Tag>& tags)
61
foreach (const Nepomuk::Tag& tag, m_tags) {
66
m_tagsText += tag.genericLabel();
68
// use the text color for the tag-links, to create a visual difference
69
// to the semantically different "Change..." link
70
const QColor linkColor = palette().text().color();
71
const char* link = "<a style=\"color:%1;\" href=\"%2\">%3</a>";
72
m_tagsText += QString::fromLatin1(link).arg(linkColor.name(),
73
KUrl(tag.resourceUri()).url(),
80
if (m_tagsText.isEmpty()) {
84
text = "<a href=\"changeTags\">" + i18nc("@label", "Add Tags...") + "</a>";
90
text += m_tagsText + " <a href=\"changeTags\">" + i18nc("@label", "Change...") + "</a>";
93
m_label->setText(text);
96
QList<Nepomuk::Tag> KTaggingWidget::tags() const
101
void KTaggingWidget::setReadOnly(bool readOnly)
103
m_readOnly = readOnly;
107
bool KTaggingWidget::isReadOnly() const
112
bool KTaggingWidget::event(QEvent* event)
114
if (event->type() == QEvent::Polish) {
115
m_label->setForegroundRole(foregroundRole());
117
return QWidget::event(event);
120
void KTaggingWidget::slotLinkActivated(const QString& link)
122
if (link != QLatin1String("changeTags")) {
123
emit tagActivated(Nepomuk::Tag(KUrl(link)));
127
KEditTagsDialog dialog(m_tags, this, Qt::Dialog);
128
KConfigGroup dialogConfig(KGlobal::config(), "Nepomuk KEditTagsDialog");
129
dialog.restoreDialogSize(dialogConfig);
131
if (dialog.exec() == QDialog::Accepted) {
132
const QList<Nepomuk::Tag> oldTags = m_tags;
133
m_tags = dialog.tags();
135
if (oldTags.count() != m_tags.count()) {
136
emit tagsChanged(m_tags);
138
// The number of tags is equal. Check whether the
139
// content of the tags are also equal:
140
const int tagsCount = m_tags.count();
141
for (int i = 0; i < tagsCount; ++i) {
142
if (oldTags[i].genericLabel() != m_tags[i].genericLabel()) {
143
// at least one tag has been changed
144
emit tagsChanged(m_tags);
150
dialog.saveDialogSize(dialogConfig, KConfigBase::Persistent);
153
#include "ktaggingwidget_p.moc"