#include <kglobalsettings.h>
#include <klocale.h>
+#include <QEvent>
#include <QLabel>
#include <QTextEdit>
#include <QVBoxLayout>
KCommentWidget::KCommentWidget(QWidget* parent) :
QWidget(parent),
+ m_readOnly(false),
m_label(0),
m_comment()
{
void KCommentWidget::setText(const QString& comment)
{
- if (comment.isEmpty()) {
- m_label->setText("<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>");
+ QString text;
+ if (comment.isEmpty()) {
+ if (m_readOnly) {
+ text = "-";
+ } else {
+ text = "<a href=\"addComment\">" + i18nc("@label", "Add Comment...") + "</a>";
+ }
} else {
- m_label->setText("<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>");
+ if (m_readOnly) {
+ text = comment;
+ } else {
+ text = "<p>" + comment + " <a href=\"changeComment\">" + i18nc("@label", "Change...") + "</a></p>";
+ }
}
+
+ m_label->setText(text);
m_comment = comment;
}
return m_comment;
}
+void KCommentWidget::setReadOnly(bool readOnly)
+{
+ m_readOnly = readOnly;
+ setText(m_comment);
+}
+
+bool KCommentWidget::isReadOnly() const
+{
+ return m_readOnly;
+}
+
+bool KCommentWidget::event(QEvent* event)
+{
+ if (event->type() == QEvent::Polish) {
+ m_label->setForegroundRole(foregroundRole());
+ }
+ return QWidget::event(event);
+}
+
void KCommentWidget::slotLinkActivated(const QString& link)
{
KDialog dialog(this, Qt::Dialog);