180 |
180 |
181 |
181 |
182 void HWChatWidget::displayNotice(const QString & message) |
182 void HWChatWidget::displayNotice(const QString & message) |
183 { |
183 { |
184 addLine("msg_Notice", " *** " + message); |
184 addLine("msg_Notice", " *** " + message); |
|
185 // scroll to the end |
|
186 chatText->moveCursor(QTextCursor::End); |
185 } |
187 } |
186 |
188 |
187 |
189 |
188 void HWChatWidget::displayWarning(const QString & message) |
190 void HWChatWidget::displayWarning(const QString & message) |
189 { |
191 { |
190 addLine("msg_Warning", " *!* " + message); |
192 addLine("msg_Warning", " *!* " + message); |
|
193 // scroll to the end |
|
194 chatText->moveCursor(QTextCursor::End); |
191 } |
195 } |
192 |
196 |
193 |
197 |
194 HWChatWidget::HWChatWidget(QWidget* parent, QSettings * gameSettings, bool notify) : |
198 HWChatWidget::HWChatWidget(QWidget* parent, QSettings * gameSettings, bool notify) : |
195 QWidget(parent), |
199 QWidget(parent), |
196 mainLayout(this) |
200 mainLayout(this) |
197 { |
201 { |
198 this->gameSettings = gameSettings; |
202 this->gameSettings = gameSettings; |
199 this->notify = notify; |
203 this->notify = notify; |
200 if(notify && gameSettings->value("frontend/sound", true).toBool()) |
204 if(gameSettings->value("frontend/sound", true).toBool()) |
201 helloSound = HWDataManager::instance().findFileForRead( |
205 { |
202 "Sounds/voices/Classic/Hello.ogg"); |
206 if (notify) |
|
207 m_helloSound = HWDataManager::instance().findFileForRead( |
|
208 "Sounds/voices/Classic/Hello.ogg"); |
|
209 m_hilightSound = HWDataManager::instance().findFileForRead( |
|
210 "Sounds/1C.ogg"); |
|
211 } |
203 |
212 |
204 mainLayout.setSpacing(1); |
213 mainLayout.setSpacing(1); |
205 mainLayout.setMargin(1); |
214 mainLayout.setMargin(1); |
206 mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
215 mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
207 mainLayout.setColumnStretch(0, 76); |
216 mainLayout.setColumnStretch(0, 76); |
440 formattedStr.replace("|nick|",QString("<a href=\"hwnick://?%1\" class=\"nick\">%2</a>").arg(QString(nick.toUtf8().toBase64())).arg(nick)); |
451 formattedStr.replace("|nick|",QString("<a href=\"hwnick://?%1\" class=\"nick\">%2</a>").arg(QString(nick.toUtf8().toBase64())).arg(nick)); |
441 |
452 |
442 QString cssClass("msg_UserChat"); |
453 QString cssClass("msg_UserChat"); |
443 |
454 |
444 // check first character for color code and set color properly |
455 // check first character for color code and set color properly |
445 switch (str[0].toAscii()) { |
456 char c = str[0].toAscii(); |
|
457 switch (c) { |
446 case 3: |
458 case 3: |
447 cssClass = (isFriend ? "msg_FriendJoin" : "msg_UserJoin"); |
459 cssClass = (isFriend ? "msg_FriendJoin" : "msg_UserJoin"); |
448 break; |
460 break; |
449 case 2: |
461 case 2: |
450 cssClass = (isFriend ? "msg_FriendAction" : "msg_UserAction"); |
462 cssClass = (isFriend ? "msg_FriendAction" : "msg_UserAction"); |
452 default: |
464 default: |
453 if (isFriend) |
465 if (isFriend) |
454 cssClass = "msg_FriendChat"; |
466 cssClass = "msg_FriendChat"; |
455 } |
467 } |
456 |
468 |
457 addLine(cssClass,formattedStr); |
469 addLine(cssClass, formattedStr, (!nick.isEmpty()) && str.contains(m_userNick)); |
458 } |
470 } |
459 |
471 |
460 void HWChatWidget::addLine(const QString & cssClass, QString line) |
472 void HWChatWidget::addLine(const QString & cssClass, QString line, bool isHighlight) |
461 { |
473 { |
462 if (s_displayNone->contains(cssClass)) |
474 if (s_displayNone->contains(cssClass)) |
463 return; // the css forbids us to display this line |
475 return; // the css forbids us to display this line |
464 |
476 |
465 if (chatStrings.size() > 250) |
477 if (chatStrings.size() > 250) |
466 chatStrings.removeFirst(); |
478 chatStrings.removeFirst(); |
467 |
479 |
468 line = QString("<span class=\"%2\">%1</span>").arg(line).arg(cssClass); |
480 line = QString("<span class=\"%1\">%2</span>").arg(cssClass).arg(line); |
|
481 |
|
482 if (isHighlight) |
|
483 { |
|
484 line = QString("<span class=\"highlight\">%1</span>").arg(line); |
|
485 SDLInteraction::instance().playSoundFile(m_hilightSound); |
|
486 } |
469 |
487 |
470 chatStrings.append(line); |
488 chatStrings.append(line); |
471 |
489 |
472 chatText->setHtml(chatStrings.join("<br>")); |
490 chatText->setHtml(chatStrings.join("<br>")); |
473 |
491 |
484 chatText->setHtml(chatStrings.join("<br>")); |
502 chatText->setHtml(chatStrings.join("<br>")); |
485 |
503 |
486 chatText->moveCursor(QTextCursor::End); |
504 chatText->moveCursor(QTextCursor::End); |
487 } |
505 } |
488 |
506 |
489 void HWChatWidget::nickAdded(const QString& nick, bool notifyNick) |
507 void HWChatWidget::nickAdded(const QString & nick, bool notifyNick) |
490 { |
508 { |
491 bool isIgnored = ignoreList.contains(nick, Qt::CaseInsensitive); |
509 bool isIgnored = ignoreList.contains(nick, Qt::CaseInsensitive); |
492 QListWidgetItem * item = new ListWidgetNickItem(nick, friendsList.contains(nick, Qt::CaseInsensitive), isIgnored); |
510 QListWidgetItem * item = new ListWidgetNickItem(nick, friendsList.contains(nick, Qt::CaseInsensitive), isIgnored); |
493 updateNickItem(item); |
511 updateNickItem(item); |
494 chatNicks->addItem(item); |
512 chatNicks->addItem(item); |
495 |
513 |
496 if (!isIgnored) |
514 if ((!isIgnored) && (nick != m_userNick)) // don't auto-complete own name |
497 chatEditLine->addNickname(nick); |
515 chatEditLine->addNickname(nick); |
498 |
516 |
499 emit nickCountUpdate(chatNicks->count()); |
517 emit nickCountUpdate(chatNicks->count()); |
500 |
518 |
501 if(notifyNick && notify && gameSettings->value("frontend/sound", true).toBool()) { |
519 if(notifyNick && notify && gameSettings->value("frontend/sound", true).toBool()) { |
502 SDLInteraction::instance().playSoundFile(helloSound); |
520 SDLInteraction::instance().playSoundFile(m_helloSound); |
503 } |
521 } |
504 } |
522 } |
505 |
523 |
506 void HWChatWidget::nickRemoved(const QString& nick) |
524 void HWChatWidget::nickRemoved(const QString& nick) |
507 { |
525 { |