]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/kcommentwidget.cpp
Get back names, and use "using" keyword to keep GCC silent on "method foo on base...
[dolphin.git] / src / panels / information / kcommentwidget.cpp
index 770b6c10c79381cc8eb03f9c501bd361213ec65f..408e6a873a41c0d647e1024a583c5ae0c5437d20 100644 (file)
 #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()
 {
@@ -51,11 +53,22 @@ KCommentWidget::~KCommentWidget()
 
 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;
 }
 
@@ -64,6 +77,25 @@ QString KCommentWidget::text() const
     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);