[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdenetwork/kopete/kopete/chatwindow
From:       Benson Tsai <btsai () vrwarp ! com>
Date:       2009-02-27 15:39:26
Message-ID: 1235749166.765299.32035.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 932923 by btsai:

I noticed that the rich text editor did not quite behave as expected when using
foreground/background color. As it turns out, I'm not using a hook for on char format update which
I should be. I also found out that the functions I wrote intended to override the set
background/foreground functions simply never gets called because unfortunately they're not virtual
functions and they're only called from a private class which references the class as
"KRichTextWidget".

Cases:
Deleting text (backspace) -> new text format should follow the last character deleted
Sending text -> new text format should follow the last character in the last message

When deleting a selection, it currently follows the character format where the cursor is--which I
feel is reasonable.

Squashed commit of the following:

commit 512adb03cb1f54035aff54d6d366e16e32e12967
Author: Benson Tsai <btsai@vrwarp.com>
Date:   Wed Feb 25 23:22:51 2009 -0500

    removed background/foreground functions (they don't do anything)
    added CharFormatChanged hook.

commit 949173da11d2673d6b9802e6fc9e6fce02741cb7
Author: Benson Tsai <btsai@vrwarp.com>
Date:   Wed Feb 25 11:44:03 2009 -0500

    testing out a different method for deciding user font

commit c6ef761f7391927d1bf9f9d964f1b2b792f5f20a
Author: Benson Tsai <btsai@vrwarp.com>
Date:   Sun Feb 22 12:20:12 2009 -0500

    debug statements (fixed)

commit 67b86a894fa1cf8d4a6b7aac174711bc94fd659a
Author: Benson Tsai <btsai@vrwarp.com>
Date:   Sun Feb 22 01:36:12 2009 -0500

    added debug messages

commit d80710688c00ca2c37de68a3bc38c725471d000b
Author: Benson Tsai <btsai@vrwarp.com>
Date:   Tue Feb 10 00:44:24 2009 -0500

    small fix for chat

 M  +19 -37    kopeterichtextwidget.cpp  
 M  +1 -2      kopeterichtextwidget.h  


--- trunk/KDE/kdenetwork/kopete/kopete/chatwindow/kopeterichtextwidget.cpp #932922:932923
@@ -81,6 +81,9 @@
         : KRichTextWidget(parent),
         d(new Private(this))
 {
+    connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
+            this, SLOT(updateCharFormat(QTextCharFormat)));
+
     connect(this, SIGNAL(textChanged()),
             this, SLOT(updateTextFormat()) );
 
@@ -181,43 +184,6 @@
     setCurrentCharFormat(d->defaultFormat);
 }
 
-void KopeteRichTextWidget::setTextBackgroundColor(const QColor &color)
-{
-    d->desiredFormat.setBackground(color);
-
-    if (d->protocolCaps & Kopete::Protocol::BaseBgColor)
-    {
-        QTextCharFormat format;
-        format.setBackground(color);
-        d->mergeAll(format);
-
-        QPalette palette = this->palette();
-        palette.setColor(QPalette::Active, QPalette::Base, color);
-        palette.setColor(QPalette::Inactive, QPalette::Base, color);
-        this->setPalette(palette);
-    }
-    else
-    {
-        KRichTextWidget::setTextBackgroundColor(color);
-    }
-}
-
-void KopeteRichTextWidget::setTextForegroundColor(const QColor &color)
-{
-    d->desiredFormat.setForeground(color);
-
-    if (d->protocolCaps & Kopete::Protocol::BaseFgColor)
-    {
-        QTextCharFormat format;
-        format.setForeground(color);
-        d->mergeAll(format);
-    }
-    else
-    {
-        KRichTextWidget::setTextForegroundColor(color);
-    }
-}
-
 void KopeteRichTextWidget::setFontFamily(QString family)
 {
     d->desiredFormat.setFontFamily(family);
@@ -321,6 +287,22 @@
     return d->desiredFormat;
 }
 
+void KopeteRichTextWidget::updateCharFormat(const QTextCharFormat & f){
+    if (!document()->isEmpty())
+    {
+        d->desiredFormat = f;
+
+        // set background color if only base bg color is supported
+        if (d->protocolCaps & Kopete::Protocol::BaseBgColor)
+        {
+            QPalette palette = this->palette();
+            palette.setColor(QPalette::Active, QPalette::Base, f.background().color());
+            palette.setColor(QPalette::Inactive, QPalette::Base, f.background().color());
+            this->setPalette(palette);
+        }
+    }
+}
+
 void KopeteRichTextWidget::updateTextFormat()
 {
     if (d->updating)
--- trunk/KDE/kdenetwork/kopete/kopete/chatwindow/kopeterichtextwidget.h #932922:932923
@@ -62,8 +62,6 @@
     */
     void setRichTextEnabled( bool enable );
 
-    void setTextBackgroundColor(const QColor &color);
-    void setTextForegroundColor(const QColor &color);
     void setFontFamily(QString family);
     void setFontSize(int size);
     void setTextBold(bool bold);
@@ -81,6 +79,7 @@
 
 protected slots:
     void updateTextFormat();
+    void updateCharFormat(const QTextCharFormat &);
 
 
 private:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic