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