~ubuntu-branches/ubuntu/maverick/kdebase/maverick-updates

« back to all changes in this revision

Viewing changes to apps/dolphin/src/panels/information/ktaggingwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers, Martin Alfke, Modestas Vainius
  • Date: 2010-05-01 23:37:50 UTC
  • mfrom: (0.7.4 upstream) (0.4.4 experimental)
  • mto: This revision was merged to the branch mainline in revision 285.
  • Revision ID: james.westby@ubuntu.com-20100501233750-maq4i4sh8ymjbneb
Tags: 4:4.4.3-1
* New upstream release:
  - Konsole does not crash when closing a broken restored session.
    (Closes: #555831)
  - Konqueror does not crash when closing fast a tab. (Closes: #441298)

[Martin Alfke]
* Update of debian/copyright for kde 4.4

[ Modestas Vainius ]
* Bump kde-sc-dev-latest build dependency to 4.4.3.
* Confirm symbol files for 4.4.2 on hurd-i386 i386 ia64 kfreebsd-amd64
  kfreebsd-i386 mips powerpc s390 sparc.
* Release KDE SC 4.4.3 to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                      *
 
3
 *                                                                           *
 
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.           *
 
7
 *                                                                           *
 
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.                          *
 
12
 *                                                                           *
 
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
 *****************************************************************************/
 
18
 
 
19
#include "ktaggingwidget_p.h"
 
20
 
 
21
#include "kedittagsdialog_p.h"
 
22
 
 
23
#include <kglobalsettings.h>
 
24
#include <klocale.h>
 
25
#include <kurl.h>
 
26
 
 
27
#include <QEvent>
 
28
#include <QLabel>
 
29
#include <QVBoxLayout>
 
30
 
 
31
KTaggingWidget::KTaggingWidget(QWidget* parent) :
 
32
    QWidget(parent),
 
33
    m_readOnly(false),
 
34
    m_label(0),
 
35
    m_tags(),
 
36
    m_tagsText()
 
37
{
 
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&)));
 
43
 
 
44
    QVBoxLayout* layout = new QVBoxLayout(this);
 
45
    layout->setMargin(0);
 
46
    layout->addWidget(m_label);
 
47
 
 
48
    setTags(QList<Nepomuk::Tag>());
 
49
}
 
50
 
 
51
KTaggingWidget::~KTaggingWidget()
 
52
{
 
53
}
 
54
 
 
55
void KTaggingWidget::setTags(const QList<Nepomuk::Tag>& tags)
 
56
{
 
57
    m_tags = tags;
 
58
 
 
59
    m_tagsText.clear();
 
60
    bool first = true;
 
61
    foreach (const Nepomuk::Tag& tag, m_tags) {
 
62
        if (!first) {
 
63
            m_tagsText += ", ";
 
64
        }
 
65
        if (m_readOnly) {
 
66
            m_tagsText += tag.genericLabel();
 
67
        } else {
 
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(),
 
74
                                                        tag.genericLabel());
 
75
        }
 
76
        first = false;
 
77
    }
 
78
 
 
79
    QString text;
 
80
    if (m_tagsText.isEmpty()) {
 
81
        if (m_readOnly) {
 
82
            text = "-";
 
83
        } else {
 
84
            text = "<a href=\"changeTags\">" + i18nc("@label", "Add Tags...") + "</a>";
 
85
        }
 
86
    } else {
 
87
        if (m_readOnly) {
 
88
            text = m_tagsText;
 
89
        } else {
 
90
            text += m_tagsText + " <a href=\"changeTags\">" + i18nc("@label", "Change...") + "</a>";
 
91
        }
 
92
    }
 
93
    m_label->setText(text);
 
94
}
 
95
 
 
96
QList<Nepomuk::Tag> KTaggingWidget::tags() const
 
97
{
 
98
    return m_tags;
 
99
}
 
100
 
 
101
void KTaggingWidget::setReadOnly(bool readOnly)
 
102
{
 
103
    m_readOnly = readOnly;
 
104
    setTags(m_tags);
 
105
}
 
106
 
 
107
bool KTaggingWidget::isReadOnly() const
 
108
{
 
109
    return m_readOnly;
 
110
}
 
111
 
 
112
bool KTaggingWidget::event(QEvent* event)
 
113
{
 
114
    if (event->type() == QEvent::Polish) {
 
115
        m_label->setForegroundRole(foregroundRole());
 
116
    }
 
117
    return QWidget::event(event);
 
118
}
 
119
 
 
120
void KTaggingWidget::slotLinkActivated(const QString& link)
 
121
{
 
122
    if (link != QLatin1String("changeTags")) {
 
123
        emit tagActivated(Nepomuk::Tag(KUrl(link)));
 
124
        return;
 
125
    }
 
126
 
 
127
    KEditTagsDialog dialog(m_tags, this, Qt::Dialog);
 
128
    KConfigGroup dialogConfig(KGlobal::config(), "Nepomuk KEditTagsDialog");
 
129
    dialog.restoreDialogSize(dialogConfig);
 
130
 
 
131
    if (dialog.exec() == QDialog::Accepted) {
 
132
        const QList<Nepomuk::Tag> oldTags = m_tags;
 
133
        m_tags = dialog.tags();
 
134
 
 
135
        if (oldTags.count() != m_tags.count()) {
 
136
            emit tagsChanged(m_tags);
 
137
        } else {
 
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);
 
145
                    break;
 
146
                }
 
147
            }
 
148
        }
 
149
    }
 
150
    dialog.saveDialogSize(dialogConfig, KConfigBase::Persistent);
 
151
}
 
152
 
 
153
#include "ktaggingwidget_p.moc"