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

List:       kde-commits
Subject:    KDE_3_1_BRANCH: kdenetwork/kit
From:       Neil Stevens <neil () qualityassistant ! com>
Date:       2003-08-17 23:39:24
[Download RAW message or body]

CVS commit by neil: 

Back-port font fix


  M +47 -11    tmessage.cpp   1.37.2.10


--- kdenetwork/kit/tmessage.cpp  #1.37.2.9:1.37.2.10
@@ -8,22 +8,22 @@
 
 #include <kaction.h>
-#include <kglobalsettings.h>
-#include <kglobal.h>
 #include <kcolorbutton.h>
 #include <kcolordialog.h>
+#include <kdebug.h>
 #include <kfile.h>
-#include <kiconloader.h>
-#include <ktextedit.h>
+#include <kglobalsettings.h>
+#include <kglobal.h>
 #include <khtmlview.h>
+#include <kiconloader.h>
+#include <klocale.h>
 #include <kmenubar.h>
+#include <kmessagebox.h>
 #include <knotifyclient.h>
-#include <kstandarddirs.h>
 #include <kpopupmenu.h>
-#include <kmessagebox.h>
-#include <klocale.h>
+#include <kstandarddirs.h>
+#include <ktextedit.h>
 #include <qlayout.h>
 #include <qtextcodec.h>
 #include <qvbox.h>
-#include <kdebug.h>
 
 #include "aim.h"
@@ -32,5 +32,41 @@
 #include "tmessage.h"
 
-// helper functions
+QString htmlEscape(QString string)
+{
+        string.replace('&', "&amp;");
+        string.replace('<', "&lt;");
+        string.replace('>', "&gt;");
+        return string;
+}
+
+QString htmlQuote(QString string)
+{
+        string = htmlEscape(string);
+        string.replace('"', "\\\"");
+        string = QString("\"%1\"").arg(string);
+        return string;
+}
+
+QString htmlFont(const QFont &font)
+{
+        QString fontString;
+
+        if(font.italic())
+                fontString += "font-style: italic;\n";
+
+        fontString += QString("font-weight: %1;\n").arg(font.weight() * 10);
+
+        if(font.pointSize() != -1)
+                fontString += QString("font-size: %1pt;\n").arg(font.pointSize());
+        else if(font.pixelSize() != -1)
+                fontString += QString("font-size: %1px;\n").arg(font.pixelSize());
+        else
+                fontString += QString("font-size: \
%1pt;\n").arg(font.pointSizeFloat()); +
+        fontString += QString("font-family: %1;\n").arg(htmlQuote(font.family()));
+
+        return fontString;
+}
+
 inline bool tagIsOpen(const QString &html, const QString &tag)
 {
@@ -135,5 +171,5 @@ QString stripTags(const QString &oldstr)
         // background colors
         bodyPos = newstr.find("<BODY BGCOLOR=");
-        if(bodyPos != -1) newstr.replace(bodyPos, 15, "<span STYLE=\"font-style: \
normal; background: "); +        if(bodyPos != -1) newstr.replace(bodyPos, 15, "<span \
style=\"font-style: normal; background: ");  // merge font in with span
         if(bodyPos != -1) newstr.replace(QRegExp(">\\w*<\\w*font", false), "" );
@@ -544,5 +580,5 @@ void TMessage::openLogFile(void)
 void TMessage::initializeHTML()
 {
-        conversationBuffer = QString("<html><head><style type=\"text/css\">p \
{margin: .3em;} body: {background-color: #ffffff;} }</style><title>") + displayName + \
QString("</title></head><body>"); +        conversationBuffer = \
QString("<html><head><style type=\"text/css\">p {margin: .3em; ") + \
htmlFont(KGlobalSettings::generalFont()) + QString("} body: {background-color: \
#ffffff;} }</style><title>") + displayName + QString("</title></head><body>");  \
conversationLength = 0;  htmlpart->begin();


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

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