aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/notifier/notifiermessage.cpp
diff options
context:
space:
mode:
authorGravatar Fabio Bas2010-01-04 21:39:18 +0000
committerGravatar Fabio Bas2010-01-04 21:39:18 +0000
commitea1084670270a8877f1e4baa69d1adf16aec5714 (patch)
tree8febc161ed96186ab4ae6055f279c92d818714f2 /src/modules/notifier/notifiermessage.cpp
parentfix for #678 (diff)
downloadKVIrc-ea1084670270a8877f1e4baa69d1adf16aec5714.tar.gz
KVIrc-ea1084670270a8877f1e4baa69d1adf16aec5714.tar.bz2
KVIrc-ea1084670270a8877f1e4baa69d1adf16aec5714.zip
merged topicbar and notifier html's converters, welcome kvi_htmlgenerator
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3792 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/notifier/notifiermessage.cpp')
-rw-r--r--src/modules/notifier/notifiermessage.cpp256
1 files changed, 2 insertions, 254 deletions
diff --git a/src/modules/notifier/notifiermessage.cpp b/src/modules/notifier/notifiermessage.cpp
index cde4130c7..04d862ac2 100644
--- a/src/modules/notifier/notifiermessage.cpp
+++ b/src/modules/notifier/notifiermessage.cpp
@@ -26,10 +26,8 @@
#include "notifiermessage.h"
#include "notifiersettings.h"
-#include "kvi_iconmanager.h"
-#include "kvi_mirccntrl.h"
+#include "kvi_htmlgenerator.h"
#include "kvi_options.h"
-#include "kvi_texticonmanager.h"
#include <QRect>
#include <QResizeEvent>
@@ -53,7 +51,7 @@ KviNotifierMessage::KviNotifierMessage(QPixmap * pPixmap, const QString &szText)
m_pLabel1 = new QLabel();
m_pLabel1->setTextFormat(Qt::RichText);
- m_pLabel1->setText(KviNotifierMessage::convertToHtml(m_szText));
+ m_pLabel1->setText(KviHtmlGenerator::convertToHtml(m_szText));
m_pLabel1->setWordWrap(true);
m_pHBox = new QHBoxLayout(this);
@@ -78,254 +76,4 @@ KviNotifierMessage::~KviNotifierMessage()
m_pHBox->deleteLater();
}
-//TODO merge this code with kvi_topicw.cpp's one
-#define KVI_LABEL_DEF_BACK 100
-#define KVI_LABEL_DEF_FORE 101
-
-QString KviNotifierMessage::convertToHtml(const QString &szText)
-{
- QString szResult;
- bool bCurBold = false;
- bool bCurUnderline = false;
- bool bIgnoreIcons = false;
- bool bShowIcons = KVI_OPTION_BOOL(KviOption_boolDrawEmoticons);
-
- unsigned char uCurFore = KVI_LABEL_DEF_FORE; //default fore
- unsigned char uCurBack = KVI_LABEL_DEF_BACK; //default back
-
- unsigned int uIdx = 0;
-
- while(uIdx < (unsigned int)szText.length())
- {
- unsigned short c = szText[(int)uIdx].unicode();
- unsigned int uStart = uIdx;
-
- while(
- (c != KVI_TEXT_COLOR) &&
- (c != KVI_TEXT_BOLD) &&
- (c != KVI_TEXT_UNDERLINE) &&
- (c != KVI_TEXT_REVERSE) &&
- (c != KVI_TEXT_RESET) &&
- (c != KVI_TEXT_ICON) &&
- ((c != ':') || bIgnoreIcons) &&
- ((c != ';') || bIgnoreIcons) &&
- ((c != '=') || bIgnoreIcons)
- )
- {
- uIdx++;
- bIgnoreIcons=FALSE;
- if(uIdx >= (unsigned int)szText.length())break;
- else c = szText[(int)uIdx].unicode();
- }
-
- bIgnoreIcons=FALSE;
- int iLen = uIdx - uStart;
-
- if(iLen > 0)
- {
- bool bOpened = FALSE;
-
- if(uCurFore != KVI_LABEL_DEF_FORE)
- {
- szResult.append("<span style=\"color:");
- szResult.append(KVI_OPTION_MIRCCOLOR(uCurFore).name());
- bOpened = TRUE;
- }
-
- if(uCurBack != KVI_LABEL_DEF_BACK)
- {
- if(!bOpened)
- {
- szResult.append("<span style=\"background-color:");
- bOpened = TRUE;
- } else {
- szResult.append(";background-color:");
- }
- szResult.append(KVI_OPTION_MIRCCOLOR(uCurBack).name());
- }
-
- if(bCurUnderline)
- {
- if(!bOpened)
- {
- szResult.append("<span style=\"text-decoration:underline");
- bOpened = TRUE;
- } else {
- szResult.append(";text-decoration:underline");
- }
- }
-
- if(bCurBold)
- {
- if(!bOpened)
- {
- szResult.append("<span style=\"font-weight:bold");
- bOpened = TRUE;
- } else {
- szResult.append(";font-weight:bold");
- }
- }
-
- if(bOpened) szResult.append(";\">");
-
- szResult.append(szText.mid(uStart,iLen));
-
- if( bOpened )
- szResult.append("</span>");
- }
-
- switch(c)
- {
- case KVI_TEXT_BOLD: bCurBold = !bCurBold; ++uIdx; break;
- case KVI_TEXT_UNDERLINE: bCurUnderline = !bCurUnderline; ++uIdx; break;
- case KVI_TEXT_REVERSE:
- {
- char auxBack = uCurBack;
- uCurBack = uCurFore;
- uCurFore = auxBack;
- }
- ++uIdx;
- break;
- case KVI_TEXT_RESET:
- uCurFore = KVI_LABEL_DEF_FORE;
- uCurBack = KVI_LABEL_DEF_BACK;
- bCurBold = false;
- bCurUnderline = false;
- ++uIdx;
- break;
- case KVI_TEXT_COLOR:
- {
- ++uIdx;
- unsigned char fore;
- unsigned char back;
- uIdx = getUnicodeColorBytes(szText,uIdx,&fore,&back);
- if(fore != KVI_NOCHANGE)
- {
- uCurFore = fore;
- if(back != KVI_NOCHANGE)uCurBack = back;
- } else {
- // only a CTRL+K
- uCurBack = KVI_LABEL_DEF_BACK;
- uCurFore = KVI_LABEL_DEF_FORE;
- }
- }
- break;
- case ':':
- case ';':
- case '=':
- {
- //potential emoticon, got eyes
- if(bShowIcons)
- {
- ++uIdx;
- QString szLookup;
- szLookup.append(QChar(c));
- unsigned short uIsEmoticon=0;
- unsigned int uIcoStart = uIdx;
-
- if(uIdx < (unsigned int)szText.length())
- {
- //look up for a nose
- if(szText[(int)uIdx] == '-')
- {
- szLookup.append('-');
- uIdx++;
- }
- }
-
- if(uIdx < (unsigned int)szText.length())
- {
- //look up for a mouth
- unsigned short m = szText[(int)uIdx].unicode();
- switch(m)
- {
- case ')':
- case '(':
- case '/':
- case 'D':
- case 'P':
- case 'S':
- case 'O':
- case '*':
- case '|':
- szLookup+=QChar(m);
- uIsEmoticon++;
- uIdx++;
- break;
- default:
- break;
- }
- }
-
- if(uIdx < (unsigned int)szText.length())
- {
- //look up for a space
- if(szText[(int)uIdx]== ' ')
- {
- uIsEmoticon++;
- }
- } else {
- //got a smile at the end of the szText
- uIsEmoticon++;
- }
-
- if(uIsEmoticon>1)
- {
- KviTextIcon * pIcon = g_pTextIconManager->lookupTextIcon(szLookup);
- // do we have that emoticon-icon association ?
- if(pIcon)
- {
- szResult.append("<img src=\"");
- szResult.append(g_pIconManager->getSmallIconResourceName(pIcon->id()));
- if(uCurBack != KVI_LABEL_DEF_BACK)
- {
- szResult.append("\" style=\"background-color:");
- szResult.append(KVI_OPTION_MIRCCOLOR(uCurBack).name());
- }
- szResult.append("\">");
- } else {
- bIgnoreIcons=TRUE;
- uIdx = uIcoStart-1;
- }
- } else {
- bIgnoreIcons=TRUE;
- uIdx = uIcoStart-1;
- }
- } else {
- bIgnoreIcons=TRUE;
- }
- }
- break;
- case KVI_TEXT_ICON:
- {
- ++uIdx;
- if(bShowIcons)
- {
- unsigned int uIcoStart = uIdx;
- while((uIdx < (unsigned int)szText.length()) && (szText[(int)uIdx].unicode() > 32))uIdx++;
-
- QString szLookup = szText.mid(uIcoStart,uIdx - uIcoStart);
-
- KviTextIcon * pIcon = g_pTextIconManager->lookupTextIcon(szLookup);
- if(pIcon)
- {
- szResult.append("<img src=\"");
- szResult.append(g_pIconManager->getSmallIconResourceName(pIcon->id()));
- if(uCurBack != KVI_LABEL_DEF_BACK)
- {
- szResult.append("\" style=\"background-color:");
- szResult.append(KVI_OPTION_MIRCCOLOR(uCurBack).name());
- }
- szResult.append("\">");
- } else {
- uIdx = uIcoStart;
- }
- }
- }
- break;
- }
- }
- //qDebug("%s",szResult.toUtf8().data());
- return szResult;
-}