summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-15 21:54:48 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-15 21:54:48 +0300
commit34f943198afd1f7f342d63bd70d30cdeacd3dbad (patch)
tree209699364bdb771d3eb8abab2d6e30dc9e845dbb /src/gui
parent2971fb33f5a31d3e2400e1637e16216e4c4a1a1c (diff)
downloadplus-34f943198afd1f7f342d63bd70d30cdeacd3dbad.tar.gz
plus-34f943198afd1f7f342d63bd70d30cdeacd3dbad.tar.bz2
plus-34f943198afd1f7f342d63bd70d30cdeacd3dbad.tar.xz
plus-34f943198afd1f7f342d63bd70d30cdeacd3dbad.zip
fix rainbow chat colors for different utf8 chars and smiles.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/windows/chatwindow.cpp59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index c434bea2f..e1afb6e5b 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -1240,6 +1240,39 @@ WhisperTab *ChatWindow::getWhisperTab(const std::string &nick) const
return ret;
}
+
+#define changeColor(fun) \
+ { \
+ msg = removeColors(msg); \
+ int skip = 0; \
+ const size_t sz = msg.length(); \
+ for (size_t f = 0; f < sz; f ++) \
+ { \
+ if (skip > 0) \
+ { \
+ newMsg += msg.at(f); \
+ skip --; \
+ continue; \
+ } \
+ const unsigned char ch = static_cast<unsigned char>(msg.at(f)); \
+ if (f + 2 < sz && msg.substr(f, 2) == "%%") \
+ { \
+ newMsg += msg.at(f); \
+ skip = 2; \
+ } \
+ else if (ch > 0xc0 || ch < 0x80) \
+ { \
+ newMsg += "##" + toString(fun) + msg.at(f); \
+ if (mRainbowColor > 9) \
+ mRainbowColor = 0; \
+ } \
+ else \
+ { \
+ newMsg += msg.at(f); \
+ } \
+ } \
+ }
+
std::string ChatWindow::addColors(std::string &msg)
{
// default color or chat command
@@ -1256,31 +1289,13 @@ std::string ChatWindow::addColors(std::string &msg)
switch (mChatColor)
{
case 11:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(mRainbowColor++) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(mRainbowColor++)
return newMsg;
case 12:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(cMap[mRainbowColor++]) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(cMap[mRainbowColor++])
return newMsg;
case 13:
- msg = removeColors(msg);
- for (unsigned int f = 0; f < msg.length(); f ++)
- {
- newMsg += "##" + toString(cMap[9-mRainbowColor++]) + msg.at(f);
- if (mRainbowColor > 9)
- mRainbowColor = 0;
- }
+ changeColor(cMap[9-mRainbowColor++])
return newMsg;
default:
break;
@@ -1290,6 +1305,8 @@ std::string ChatWindow::addColors(std::string &msg)
return std::string("##").append(toString(mChatColor - 1)).append(msg);
}
+#undef changeColor
+
void ChatWindow::autoComplete()
{
const int caretPos = mChatInput->getCaretPosition();