diff -r 803b277e4894 -r 3f21a9dc93d0 QTfrontend/chatwidget.cpp
--- a/QTfrontend/chatwidget.cpp Sat Mar 06 10:54:24 2010 +0000
+++ b/QTfrontend/chatwidget.cpp Sat Mar 06 10:59:20 2010 +0000
@@ -51,192 +51,192 @@
sound[3] = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/Russian/Hello.ogg").toLocal8Bit().constData());
}
- mainLayout.setSpacing(1);
- mainLayout.setMargin(1);
- mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
- mainLayout.setColumnStretch(0, 75);
- mainLayout.setColumnStretch(1, 25);
+ mainLayout.setSpacing(1);
+ mainLayout.setMargin(1);
+ mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
+ mainLayout.setColumnStretch(0, 75);
+ mainLayout.setColumnStretch(1, 25);
- chatEditLine = new QLineEdit(this);
- chatEditLine->setMaxLength(300);
- connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+ chatEditLine = new QLineEdit(this);
+ chatEditLine->setMaxLength(300);
+ connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
- mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
+ mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
- chatText = new QTextBrowser(this);
- chatText->setMinimumHeight(20);
- chatText->setMinimumWidth(10);
- chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- chatText->setOpenExternalLinks(true);
- mainLayout.addWidget(chatText, 0, 0);
+ chatText = new QTextBrowser(this);
+ chatText->setMinimumHeight(20);
+ chatText->setMinimumWidth(10);
+ chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ chatText->setOpenExternalLinks(true);
+ mainLayout.addWidget(chatText, 0, 0);
- chatNicks = new QListWidget(this);
- chatNicks->setMinimumHeight(10);
- chatNicks->setMinimumWidth(10);
- chatNicks->setSortingEnabled(true);
- chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
- connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
- this, SLOT(chatNickDoubleClicked(QListWidgetItem *)));
- connect(chatNicks, SIGNAL(currentRowChanged(int)),
- this, SLOT(chatNickSelected(int)));
+ chatNicks = new QListWidget(this);
+ chatNicks->setMinimumHeight(10);
+ chatNicks->setMinimumWidth(10);
+ chatNicks->setSortingEnabled(true);
+ chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
+ connect(chatNicks, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
+ this, SLOT(chatNickDoubleClicked(QListWidgetItem *)));
+ connect(chatNicks, SIGNAL(currentRowChanged(int)),
+ this, SLOT(chatNickSelected(int)));
- mainLayout.addWidget(chatNicks, 0, 1);
+ mainLayout.addWidget(chatNicks, 0, 1);
- acInfo = new QAction(QAction::tr("Info"), chatNicks);
- connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo()));
- acKick = new QAction(QAction::tr("Kick"), chatNicks);
- connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick()));
- acBan = new QAction(QAction::tr("Ban"), chatNicks);
- connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan()));
- acFollow = new QAction(QAction::tr("Follow"), chatNicks);
- connect(acFollow, SIGNAL(triggered(bool)), this, SLOT(onFollow()));
- acIgnore = new QAction(QAction::tr("Ignore"), chatNicks);
- connect(acIgnore, SIGNAL(triggered(bool)), this, SLOT(onIgnore()));
- acFriend = new QAction(QAction::tr("Add friend"), chatNicks);
- connect(acFriend, SIGNAL(triggered(bool)), this, SLOT(onFriend()));
+ acInfo = new QAction(QAction::tr("Info"), chatNicks);
+ connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo()));
+ acKick = new QAction(QAction::tr("Kick"), chatNicks);
+ connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick()));
+ acBan = new QAction(QAction::tr("Ban"), chatNicks);
+ connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan()));
+ acFollow = new QAction(QAction::tr("Follow"), chatNicks);
+ connect(acFollow, SIGNAL(triggered(bool)), this, SLOT(onFollow()));
+ acIgnore = new QAction(QAction::tr("Ignore"), chatNicks);
+ connect(acIgnore, SIGNAL(triggered(bool)), this, SLOT(onIgnore()));
+ acFriend = new QAction(QAction::tr("Add friend"), chatNicks);
+ connect(acFriend, SIGNAL(triggered(bool)), this, SLOT(onFriend()));
- chatNicks->insertAction(0, acInfo);
- chatNicks->insertAction(0, acFollow);
- chatNicks->insertAction(0, acIgnore);
- chatNicks->insertAction(0, acFriend);
-
- showReady = false;
+ chatNicks->insertAction(0, acInfo);
+ chatNicks->insertAction(0, acFollow);
+ chatNicks->insertAction(0, acIgnore);
+ chatNicks->insertAction(0, acFriend);
+
+ showReady = false;
}
void HWChatWidget::loadList(QStringList & list, const QString & file)
{
- list.clear();
- QFile txt((cfgdir->absolutePath() + "/" + file).toLocal8Bit().constData());
- if(!txt.open(QIODevice::ReadOnly))
- return;
- QTextStream stream(&txt);
- stream.setCodec("UTF-8");
+ list.clear();
+ QFile txt((cfgdir->absolutePath() + "/" + file).toLocal8Bit().constData());
+ if(!txt.open(QIODevice::ReadOnly))
+ return;
+ QTextStream stream(&txt);
+ stream.setCodec("UTF-8");
- while(!stream.atEnd())
- {
- QString str = stream.readLine();
- if(str.startsWith(";") || str.length() == 0)
- continue;
- list << str.trimmed();
- }
- list.removeDuplicates();
- txt.close();
+ while(!stream.atEnd())
+ {
+ QString str = stream.readLine();
+ if(str.startsWith(";") || str.length() == 0)
+ continue;
+ list << str.trimmed();
+ }
+ list.removeDuplicates();
+ txt.close();
}
void HWChatWidget::saveList(QStringList & list, const QString & file)
{
- QFile txt((cfgdir->absolutePath() + "/" + file).toLocal8Bit().constData());
- if(!txt.open(QIODevice::WriteOnly | QIODevice::Truncate))
- return;
- QTextStream stream(&txt);
- stream.setCodec("UTF-8");
+ QFile txt((cfgdir->absolutePath() + "/" + file).toLocal8Bit().constData());
+ if(!txt.open(QIODevice::WriteOnly | QIODevice::Truncate))
+ return;
+ QTextStream stream(&txt);
+ stream.setCodec("UTF-8");
- stream << "; this list is used by Hedgewars - do not edit it unless you know what you're doing!" << endl;
- for(int i = 0; i < list.size(); i++)
- stream << list[i] << endl;
- txt.close();
+ stream << "; this list is used by Hedgewars - do not edit it unless you know what you're doing!" << endl;
+ for(int i = 0; i < list.size(); i++)
+ stream << list[i] << endl;
+ txt.close();
}
void HWChatWidget::updateIcon(QListWidgetItem *item)
{
- QString nick = item->text();
+ QString nick = item->text();
- if(ignoreList.contains(nick, Qt::CaseInsensitive))
- {
- item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_ignore_on" : ":/res/chat_ignore_off") : ":/res/chat_ignore.png"));
- item->setForeground(Qt::gray);
- }
- else if(friendsList.contains(nick, Qt::CaseInsensitive))
- {
- item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_friend_on" : ":/res/chat_friend_off") : ":/res/chat_friend.png"));
- item->setForeground(Qt::green);
- }
- else
- {
- item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_default_on" : ":/res/chat_default_off") : ":/res/chat_default.png"));
- item->setForeground(QBrush(QColor(0xff, 0xcc, 0x00)));
- }
+ if(ignoreList.contains(nick, Qt::CaseInsensitive))
+ {
+ item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_ignore_on" : ":/res/chat_ignore_off") : ":/res/chat_ignore.png"));
+ item->setForeground(Qt::gray);
+ }
+ else if(friendsList.contains(nick, Qt::CaseInsensitive))
+ {
+ item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_friend_on" : ":/res/chat_friend_off") : ":/res/chat_friend.png"));
+ item->setForeground(Qt::green);
+ }
+ else
+ {
+ item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_default_on" : ":/res/chat_default_off") : ":/res/chat_default.png"));
+ item->setForeground(QBrush(QColor(0xff, 0xcc, 0x00)));
+ }
}
void HWChatWidget::updateIcons()
{
- for(int i = 0; i < chatNicks->count(); i++)
- updateIcon(chatNicks->item(i));
+ for(int i = 0; i < chatNicks->count(); i++)
+ updateIcon(chatNicks->item(i));
}
void HWChatWidget::loadLists(const QString & nick)
{
- loadList(ignoreList, nick.toLower() + "_ignore.txt");
- loadList(friendsList, nick.toLower() + "_friends.txt");
- updateIcons();
+ loadList(ignoreList, nick.toLower() + "_ignore.txt");
+ loadList(friendsList, nick.toLower() + "_friends.txt");
+ updateIcons();
}
void HWChatWidget::saveLists(const QString & nick)
{
- saveList(ignoreList, nick.toLower() + "_ignore.txt");
- saveList(friendsList, nick.toLower() + "_friends.txt");
+ saveList(ignoreList, nick.toLower() + "_ignore.txt");
+ saveList(friendsList, nick.toLower() + "_friends.txt");
}
void HWChatWidget::returnPressed()
{
- emit chatLine(chatEditLine->text());
- chatEditLine->clear();
+ emit chatLine(chatEditLine->text());
+ chatEditLine->clear();
}
void HWChatWidget::onChatString(const QString& str)
{
- if (chatStrings.size() > 250)
- chatStrings.removeFirst();
+ if (chatStrings.size() > 250)
+ chatStrings.removeFirst();
- QString formattedStr = Qt::escape(str.mid(1));
- QStringList parts = formattedStr.split(QRegExp("\\W+"), QString::SkipEmptyParts);
+ QString formattedStr = Qt::escape(str.mid(1));
+ QStringList parts = formattedStr.split(QRegExp("\\W+"), QString::SkipEmptyParts);
- if (!formattedStr.startsWith(" ***")) // don't ignore status messages
- {
- if (formattedStr.startsWith(" *")) // emote
- parts[0] = parts[1];
- if(parts.size() > 0 && ignoreList.contains(parts[0], Qt::CaseInsensitive))
- return;
- }
+ if (!formattedStr.startsWith(" ***")) // don't ignore status messages
+ {
+ if (formattedStr.startsWith(" *")) // emote
+ parts[0] = parts[1];
+ if(parts.size() > 0 && ignoreList.contains(parts[0], Qt::CaseInsensitive))
+ return;
+ }
- QString color("");
- bool isFriend = friendsList.contains(parts[0], Qt::CaseInsensitive);
-
- if (str.startsWith("\x03"))
- color = QString("#c0c0c0");
- else if (str.startsWith("\x02"))
- color = QString(isFriend ? "#00ff00" : "#ff00ff");
- else if (isFriend)
- color = QString("#00c000");
+ QString color("");
+ bool isFriend = friendsList.contains(parts[0], Qt::CaseInsensitive);
+
+ if (str.startsWith("\x03"))
+ color = QString("#c0c0c0");
+ else if (str.startsWith("\x02"))
+ color = QString(isFriend ? "#00ff00" : "#ff00ff");
+ else if (isFriend)
+ color = QString("#00c000");
- if(color.compare("") != 0)
- formattedStr = QString("%1").arg(formattedStr).arg(color);
+ if(color.compare("") != 0)
+ formattedStr = QString("%1").arg(formattedStr).arg(color);
- chatStrings.append(formattedStr);
+ chatStrings.append(formattedStr);
- chatText->setHtml(chatStrings.join("
"));
+ chatText->setHtml(chatStrings.join("
"));
- chatText->moveCursor(QTextCursor::End);
+ chatText->moveCursor(QTextCursor::End);
}
void HWChatWidget::onServerMessage(const QString& str)
{
- if (chatStrings.size() > 250)
- chatStrings.removeFirst();
+ if (chatStrings.size() > 250)
+ chatStrings.removeFirst();
- chatStrings.append("