1
//=============================================================================
3
// File : KviNickColors.cpp
4
// Creation date : Sun Apr 11 2010 15:00:01 CEST by Fabio Bas
6
// This file is part of the KVIrc irc client distribution
7
// Copyright (C) 2009 Fabio Bas (ctrlaltca at libero dot it)
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
25
#include "KviNickColors.h"
27
#include "KviMemory.h"
30
namespace KviNickColors
33
#define KVI_NUM_NICK_COLORS 95
35
static const char * g_nickColors[KVI_NUM_NICK_COLORS]=
37
"0,1" ,"0,2" ,"0,3" ,"0,4" ,"0,5" ,"0,6" ,"0,10" ,"0,12" ,"0,14" , //9
38
"1,0" ,"1,4" ,"1,7" ,"1,8" ,"1,9" ,"1,11" ,"1,15" , //7
39
"2,0" ,"2,4" ,"2,7" ,"2,8" ,"2,9" ,"2,11" ,"2,15" , //7
40
"3,8" ,"3,9" ,"3,0" ,"3,15" , //4
41
"4,0" ,"4,1" ,"4,8" ,"4,9" ,"4,11" ,"4,15" , //6
42
"5,0" ,"5,7" ,"5,8" ,"5,15" , //4
43
"6,0" ,"6,7" ,"6,8" ,"6,9" ,"6,10" ,"6,11" ,"6,15" , //7
44
"7,1" ,"7,2" ,"7,5" ,"7,6" ,"7,14" , //5
45
"8,1" ,"8,2" ,"8,3" ,"8,4" ,"8,5" ,"8,6" ,"8,7" ,"8,10" ,"8,12" ,"8,14" , //10
46
"9,1" ,"9,2" ,"9,3" ,"9,5" ,"9,6" ,"9,14" , //6
48
"11,1" ,"11,2" ,"11,3" ,"11,5" ,"11,6" ,"11,14", //6
49
"12,0" ,"12,7" ,"12,8" ,"12,9" ,"12,10","12,11","12,15", //7
50
"13,0" ,"13,1" ,"13,6" ,"13,8" ,"13,11","13,15", //6
51
"14,0" ,"14,8" ,"14,11","14,15", //4
52
"15,1" ,"15,2" ,"15,3" ,"15,6" ,"15,14" //5
55
int getSmartColorForNick(QString *szNick)
58
int i = szNick->length();
59
const QChar * aux = szNick->unicode();
60
// FIXME: Shouldn't this be case insensitive ?
63
sum += aux->unicode();
70
const char * getSmartColor(int iPos)
72
return g_nickColors[iPos % KVI_NUM_NICK_COLORS];
75
int getSmartColorIntByMircColor(unsigned char iFore,unsigned char iBack)
78
char* comb= (char*)KviMemory::allocate(6);
80
// TODO handle KVI_TRANSPARENT and KVI_NOCHANGE (ticket #812)
81
#if defined(COMPILE_ON_WINDOWS) && !(defined(MINGW))
82
_snprintf(comb, 6, "%d,%d", iFore % 16, iBack % 16);
84
snprintf(comb, 6, "%d,%d", iFore % 16, iBack % 16);
86
// qDebug("Nick color %s",comb);
87
for(int i=0; i<KVI_NUM_NICK_COLORS;++i)
91
while(g_nickColors[i][numc] && comb[numc])
93
if(g_nickColors[i][numc] != comb[numc])
100
if(!g_nickColors[i][numc] && !comb[numc])
103
// qDebug("Exact match %s",g_nickColors[i]);
104
KviMemory::free(comb);
110
//better than any previous one
117
KviMemory::free(comb);
119
// qDebug("Best match %s",g_nickColors[iBestMatch]);