]>
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>
29 #include <QVBoxLayout>
31 KCommentWidget::KCommentWidget(QWidget
* parent
) :
37 m_label
= new QLabel(this);
38 m_label
->setFont(KGlobalSettings::smallestReadableFont());
39 m_label
->setWordWrap(true);
40 m_label
->setAlignment(Qt::AlignTop
);
41 connect(m_label
, SIGNAL(linkActivated(const QString
&)), this, SLOT(slotLinkActivated(const QString
&)));
43 QVBoxLayout
* layout
= new QVBoxLayout(this);
45 layout
->addWidget(m_label
);
50 KCommentWidget::~KCommentWidget()
54 void KCommentWidget::setText(const QString
& comment
)
57 if (comment
.isEmpty()) {
61 text
= "<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>";
67 text
= "<p>" + comment
+ " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>";
71 m_label
->setText(text
);
75 QString
KCommentWidget::text() const
80 void KCommentWidget::setReadOnly(bool readOnly
)
82 m_readOnly
= readOnly
;
86 bool KCommentWidget::isReadOnly() const
91 bool KCommentWidget::event(QEvent
* event
)
93 if (event
->type() == QEvent::Polish
) {
94 m_label
->setForegroundRole(foregroundRole());
96 return QWidget::event(event
);
99 void KCommentWidget::slotLinkActivated(const QString
& link
)
101 KDialog
dialog(this, Qt::Dialog
);
103 QTextEdit
* editor
= new QTextEdit(&dialog
);
104 editor
->setText(m_comment
);
106 dialog
.setMainWidget(editor
);
108 const QString caption
= (link
== "changeComment") ?
109 i18nc("@title:window", "Change Comment") :
110 i18nc("@title:window", "Add Comment");
111 dialog
.setCaption(caption
);
112 dialog
.setButtons(KDialog::Ok
| KDialog::Cancel
);
113 dialog
.setDefaultButton(KDialog::Ok
);
115 KConfigGroup
dialogConfig(KGlobal::config(), "Nepomuk KEditCommentDialog");
116 dialog
.restoreDialogSize(dialogConfig
);
118 if (dialog
.exec() == QDialog::Accepted
) {
119 const QString oldText
= m_comment
;
120 setText(editor
->toPlainText());
121 if (oldText
!= m_comment
) {
122 emit
commentChanged(m_comment
);
126 dialog
.saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
129 #include "kcommentwidget_p.moc"