]>
cloud.milkyroute.net Git - dolphin.git/blob - 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> *
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. *
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. *
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 ***************************************************************************/
21 #include "commentwidget_p.h"
24 #include <kglobalsettings.h>
29 #include <QVBoxLayout>
31 CommentWidget::CommentWidget(QWidget
* parent
) :
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
&)));
42 QVBoxLayout
* layout
= new QVBoxLayout(this);
44 layout
->addWidget(m_label
);
49 CommentWidget::~CommentWidget()
53 void CommentWidget::setText(const QString
& comment
)
55 if (comment
.isEmpty()) {
56 m_label
->setText("<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>");
58 m_label
->setText("<p>" + comment
+ " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>");
63 QString
CommentWidget::text() const
68 void CommentWidget::slotLinkActivated(const QString
& link
)
70 KDialog
dialog(this, Qt::Dialog
);
72 QTextEdit
* editor
= new QTextEdit(&dialog
);
73 editor
->setText(m_comment
);
75 dialog
.setMainWidget(editor
);
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
);
84 KConfigGroup
dialogConfig(KGlobal::config(), "Nepomuk EditCommentDialog");
85 dialog
.restoreDialogSize(dialogConfig
);
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
);
95 dialog
.saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
98 #include "commentwidget_p.moc"