]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/commentwidget.cpp
the configuration menu should be shown also for multiple selections
[dolphin.git] / src / panels / information / commentwidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Sebastian Trueg <trueg@kde.org> *
3 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include "commentwidget_p.h"
22
23 #include <kdialog.h>
24 #include <kglobalsettings.h>
25 #include <klocale.h>
26
27 #include <QLabel>
28 #include <QTextEdit>
29 #include <QVBoxLayout>
30
31 CommentWidget::CommentWidget(QWidget* parent) :
32 QWidget(parent),
33 m_label(0),
34 m_comment()
35 {
36 m_label = new QLabel(this);
37 m_label->setFont(KGlobalSettings::smallestReadableFont());
38 m_label->setWordWrap(true);
39 m_label->setAlignment(Qt::AlignTop);
40 connect(m_label, SIGNAL(linkActivated(const QString&)), this, SLOT(slotLinkActivated(const QString&)));
41
42 QVBoxLayout* layout = new QVBoxLayout(this);
43 layout->setMargin(0);
44 layout->addWidget(m_label);
45
46 setText(m_comment);
47 }
48
49 CommentWidget::~CommentWidget()
50 {
51 }
52
53 void CommentWidget::setText(const QString& comment)
54 {
55 if (comment.isEmpty()) {
56 m_label->setText("<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>");
57 } else {
58 m_label->setText("<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>");
59 }
60 m_comment = comment;
61 }
62
63 QString CommentWidget::text() const
64 {
65 return m_comment;
66 }
67
68 void CommentWidget::slotLinkActivated(const QString& link)
69 {
70 KDialog dialog(this, Qt::Dialog);
71
72 QTextEdit* editor = new QTextEdit(&dialog);
73 editor->setText(m_comment);
74
75 dialog.setMainWidget(editor);
76
77 const QString caption = (link == "changeComment") ?
78 i18nc("@title:window", "Change Comment") :
79 i18nc("@title:window", "Add Comment");
80 dialog.setCaption(caption);
81 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
82 dialog.setDefaultButton(KDialog::Ok);
83
84 KConfigGroup dialogConfig(KGlobal::config(), "Nepomuk EditCommentDialog");
85 dialog.restoreDialogSize(dialogConfig);
86
87 if (dialog.exec() == QDialog::Accepted) {
88 const QString oldText = m_comment;
89 setText(editor->toPlainText());
90 if (oldText != m_comment) {
91 emit commentChanged(m_comment);
92 }
93 }
94
95 dialog.saveDialogSize(dialogConfig, KConfigBase::Persistent);
96 }
97
98 #include "commentwidget_p.moc"