diff options
| author | 2009-07-08 17:59:44 +0000 | |
|---|---|---|
| committer | 2009-07-08 17:59:44 +0000 | |
| commit | 056334356d0939a352e97eb1c9d7f92b763e0772 (patch) | |
| tree | f0279d9ca0e2322e8773045efdd52e861be417c8 /src/modules/notifier/notifiermessage.cpp | |
| parent | little improvement on german translation (diff) | |
| download | KVIrc-056334356d0939a352e97eb1c9d7f92b763e0772.tar.gz KVIrc-056334356d0939a352e97eb1c9d7f92b763e0772.tar.bz2 KVIrc-056334356d0939a352e97eb1c9d7f92b763e0772.zip | |
re-written mostly of the notifier, now featuring:
- colored msg, icons etc
- different layout, easier to mantain the code & patch
- native os theme for widgets (except window decorations)
- and, of course, a lot of new bugs for your own pleasure :)
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3310 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/notifier/notifiermessage.cpp')
| -rw-r--r-- | src/modules/notifier/notifiermessage.cpp | 206 |
1 files changed, 152 insertions, 54 deletions
diff --git a/src/modules/notifier/notifiermessage.cpp b/src/modules/notifier/notifiermessage.cpp index 5dce22138..1c8fd2cf0 100644 --- a/src/modules/notifier/notifiermessage.cpp +++ b/src/modules/notifier/notifiermessage.cpp @@ -1,10 +1,11 @@ //============================================================================= // // File : notifiermessage.cpp -// Creation date : Mar 02 Nov 2004 02:41:18 by Iacopo +// Creation date : Mar 02 Nov 2004 02:41:18 by Iacopo Palazzi // // This file is part of the KVirc irc client distribution // Copyright (C) 2004-2008 Iacopo <iakko@siena.linux.it> +// Copyright (C) 2009 Fabio Bas < ctrlaltca at gmail dot com > // // This program is FREE software. You can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -23,79 +24,176 @@ //============================================================================= #include "notifiermessage.h" -#include "notifierwindow.h" +#include "notifiersettings.h" -#include "kvi_iconmanager.h" -#include "kvi_config.h" -#include "kvi_app.h" -#include "kvi_window.h" -#include "kvi_locale.h" -#include "kvi_frame.h" #include "kvi_mirccntrl.h" +#include "kvi_texticonmanager.h" #include "kvi_options.h" -/* -#ifdef COMPILE_ON_WINDOWS - #include <windows.h> -#endif - -#ifdef COMPILE_KDE_SUPPORT - #include <netwm.h> -#endif -*/ +#include <QRect> +KviNotifierMessage::KviNotifierMessage(QPixmap * pPixmap, const QString &szText) +{ + m_szText=szText; + m_pPixmap=pPixmap; -#include <QApplication> -#include <QPainter> -#include <QImage> -#include <QDesktopWidget> -#include <QToolTip> -#include "kvi_tal_popupmenu.h" + m_pLabel0 = new QLabel(); + m_pLabel0->setFixedSize(16,16); + if(m_pPixmap) + m_pLabel0->setPixmap(*m_pPixmap); + m_pLabel1 = new QLabel(KviNotifierMessage::convertToHtml(m_szText)); + m_pLabel1->setWordWrap(true); -extern kvi_time_t g_tNotifierDisabledUntil; + m_pHBox = new QHBoxLayout(this); + m_pHBox->setSpacing(SPACING); + m_pHBox->setMargin(SPACING); -KviNotifierMessage::KviNotifierMessage(KviNotifierWindow * pNotifierWindow, QPixmap * pImage, const QString &szText) -{ - m_pText = new QTextDocument(); - m_pText->setHtml(KviMircCntrl::stripControlBytes(szText)); - m_pText->setDefaultFont(pNotifierWindow->defaultFont()); - m_pText->setTextWidth(pNotifierWindow->textWidth()); - m_pImage = pImage; - m_bHistoric = false; + m_pHBox->addWidget(m_pLabel0); + m_pHBox->addWidget(m_pLabel1); } KviNotifierMessage::~KviNotifierMessage() { - delete m_pText; - if(m_pImage)delete m_pImage; + if(m_pLabel0) + delete m_pLabel0; + if(m_pLabel1) + delete m_pLabel1; + if(m_pHBox) + delete m_pHBox; } -static void increase_transparency(QImage &buffer,QImage &srcimg,int iDivisor) +//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 &text) { - buffer = QImage(srcimg.size(),QImage::Format_ARGB32); + QString result; + bool curBold = false; + bool curUnderline = false; + unsigned char curFore = KVI_LABEL_DEF_FORE; //default fore + unsigned char curBack = KVI_LABEL_DEF_BACK; //default back - for(int y = 0;y < buffer.height();y++) + unsigned int idx = 0; + + while(idx < (unsigned int)text.length()) { - QRgb * dst = (QRgb *)buffer.scanLine(y); - QRgb * end = dst + buffer.width(); - QRgb * src = (QRgb *)srcimg.scanLine(y); + unsigned short c = text[(int)idx].unicode(); + + unsigned int start = idx; + + 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) + ) + { + idx++; + if(idx >= (unsigned int)text.length())break; + else c = text[(int)idx].unicode(); + } + + int len = idx - start; + + if(len > 0) + { + bool bOpened = FALSE; + QString szText = text.mid(start,len); + + if(curBold) result.append("<b>"); + if(curUnderline) result.append("<u>"); - while(dst < end) + if(curFore != KVI_LABEL_DEF_FORE) + { + result.append("<font color=\""); + result.append(KVI_OPTION_MIRCCOLOR(curFore).name()); + result.append('"'); + bOpened = TRUE; + } + +/* if(curBack != KVI_LABEL_DEF_BACK) + { + if(!bOpened) + result.append("<font bgcolor="); + else + result.append(" bgcolor="); + result.append(KVI_OPTION_MIRCCOLOR(curBack).name()); + }*/ + + if(bOpened) result.append(">"); + + result.append(text.mid(start,len)); + + if( (curFore != KVI_LABEL_DEF_FORE) /*|| (curBack != KVI_LABEL_DEF_BACK)*/ ) + result.append("</font>"); + + if(curUnderline) result.append("</u>"); + if(curBold) result.append("</b>"); + + } + + switch(c) { - *dst = qRgba(qRed(*src),qGreen(*src),qBlue(*src),qAlpha(*src) / iDivisor); - dst++; - src++; + case KVI_TEXT_BOLD: curBold = !curBold; ++idx; break; + case KVI_TEXT_UNDERLINE: curUnderline = !curUnderline; ++idx; break; + case KVI_TEXT_REVERSE: + { + char auxBack = curBack; + curBack = curFore; + curFore = auxBack; + } + ++idx; + break; + case KVI_TEXT_RESET: + curFore = KVI_LABEL_DEF_FORE; + curBack = KVI_LABEL_DEF_BACK; + curBold = false; + curUnderline = false; + ++idx; + break; + case KVI_TEXT_COLOR: + { + ++idx; + unsigned char fore; + unsigned char back; + idx = getUnicodeColorBytes(text,idx,&fore,&back); + if(fore != KVI_NOCHANGE) + { + curFore = fore; + if(back != KVI_NOCHANGE)curBack = back; + } else { + // only a CTRL+K + curBack = KVI_LABEL_DEF_BACK; + curFore = KVI_LABEL_DEF_FORE; + } + } + break; + case KVI_TEXT_ICON: + { + ++idx; + + unsigned int icoStart = idx; + while((idx < (unsigned int)text.length()) && (text[(int)idx].unicode() > 32))idx++; + + KviStr lookupString = text.mid(icoStart,idx - icoStart); + + KviTextIcon * icon = g_pTextIconManager->lookupTextIcon(lookupString.ptr()); + if(icon) + { + //TODO: icons +/* QPixmap * pigzmap = icon->pixmap(); + p->drawPixmap(curX,(baseline + 2) - pigzmap->height(),*(pigzmap)); + curX += pigzmap->width();*/ + } else { + idx = icoStart; + } + } + break; } } + return result; } -void KviNotifierMessage::setHistoric() -{ - m_bHistoric = true; - if(!m_pImage)return; - if(!m_pImage->hasAlphaChannel())return; - QImage tmp; - QImage out = m_pImage->toImage(); - increase_transparency(tmp,out,2); - *m_pImage = QPixmap::fromImage(tmp); -} |
