1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
//=============================================================================
//
// File : notifiermessage.cpp
// 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
// as published by the Free Software Foundation; either version 2
// of the License, or (at your opinion) any later version.
//
// This program is distributed in the HOPE that it will be USEFUL,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================
#include "notifiermessage.h"
#include "notifiersettings.h"
#include "kvi_mirccntrl.h"
#include "kvi_texticonmanager.h"
#include "kvi_options.h"
#include <QRect>
KviNotifierMessage::KviNotifierMessage(QPixmap * pPixmap, const QString &szText)
{
m_szText=szText;
m_pPixmap=pPixmap;
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);
m_pHBox = new QHBoxLayout(this);
m_pHBox->setSpacing(SPACING);
m_pHBox->setMargin(SPACING);
m_pHBox->addWidget(m_pLabel0);
m_pHBox->addWidget(m_pLabel1);
}
KviNotifierMessage::~KviNotifierMessage()
{
if(m_pLabel0)
m_pLabel0->deleteLater();
if(m_pLabel1)
m_pLabel1->deleteLater();
if(m_pHBox)
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 &text)
{
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
unsigned int idx = 0;
while(idx < (unsigned int)text.length())
{
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>");
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)
{
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;
}
|