]>
cloud.milkyroute.net Git - dolphin.git/blob - 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> *
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. *
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. *
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 *****************************************************************************/
20 #include "kcommentwidget_p.h"
23 #include <kglobalsettings.h>
28 #include <QVBoxLayout>
30 KCommentWidget::KCommentWidget(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 KCommentWidget::~KCommentWidget()
53 void KCommentWidget::setText(const QString
& comment
)
56 if (comment
.isEmpty()) {
60 text
= "<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>";
66 text
= "<p>" + comment
+ " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>";
70 m_label
->setText(text
);
74 QString
KCommentWidget::text() const
79 void KCommentWidget::setReadOnly(bool readOnly
)
81 m_readOnly
= readOnly
;
85 bool KCommentWidget::isReadOnly() const
90 void KCommentWidget::slotLinkActivated(const QString
& link
)
92 KDialog
dialog(this, Qt::Dialog
);
94 QTextEdit
* editor
= new QTextEdit(&dialog
);
95 editor
->setText(m_comment
);
97 dialog
.setMainWidget(editor
);
99 const QString caption
= (link
== "changeComment") ?
100 i18nc("@title:window", "Change Comment") :
101 i18nc("@title:window", "Add Comment");
102 dialog
.setCaption(caption
);
103 dialog
.setButtons(KDialog::Ok
| KDialog::Cancel
);
104 dialog
.setDefaultButton(KDialog::Ok
);
106 KConfigGroup
dialogConfig(KGlobal::config(), "Nepomuk KEditCommentDialog");
107 dialog
.restoreDialogSize(dialogConfig
);
109 if (dialog
.exec() == QDialog::Accepted
) {
110 const QString oldText
= m_comment
;
111 setText(editor
->toPlainText());
112 if (oldText
!= m_comment
) {
113 emit
commentChanged(m_comment
);
117 dialog
.saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
120 #include "kcommentwidget_p.moc"