]> cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/commentwidget.cpp
layout improvements
[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 connect(m_label, SIGNAL(linkActivated(const QString&)), this, SLOT(slotLinkActivated(const QString&)));
39
40 QVBoxLayout* layout = new QVBoxLayout(this);
41 layout->addWidget(m_label);
42
43 setText(m_comment);
44 }
45
46 CommentWidget::~CommentWidget()
47 {
48 }
49
50 void CommentWidget::setText(const QString& comment)
51 {
52 if (comment.isEmpty()) {
53 m_label->setText("<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>");
54 } else {
55 m_label->setText("<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>");
56 }
57 m_comment = comment;
58 }
59
60 QString CommentWidget::text() const
61 {
62 return m_comment;
63 }
64
65 void CommentWidget::slotLinkActivated(const QString& link)
66 {
67 KDialog dialog(0, Qt::Dialog);
68
69 QTextEdit* editor = new QTextEdit(&dialog);
70 editor->setText(m_comment);
71
72 dialog.setMainWidget(editor);
73
74 const QString caption = (link == "changeComment") ?
75 i18nc("@title:window", "Change Comment") :
76 i18nc("@title:window", "Add Comment");
77 dialog.setCaption(caption);
78 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
79 dialog.setDefaultButton(KDialog::Ok);
80
81 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
82 "EditCommitDialog");
83 dialog.restoreDialogSize(dialogConfig);
84
85 if (dialog.exec() == QDialog::Accepted) {
86 setText(editor->toPlainText());
87 }
88
89 dialog.saveDialogSize(dialogConfig, KConfigBase::Persistent);
90 }
91
92 #include "commentwidget_p.moc"