481 |
483 |
482 QString cssClass("msg_UserChat"); |
484 QString cssClass("msg_UserChat"); |
483 |
485 |
484 // check first character for color code and set color properly |
486 // check first character for color code and set color properly |
485 char c = str[0].toAscii(); |
487 char c = str[0].toAscii(); |
486 switch (c) { |
488 switch (c) |
|
489 { |
487 case 3: |
490 case 3: |
488 cssClass = (isFriend ? "msg_FriendJoin" : "msg_UserJoin"); |
491 cssClass = (isFriend ? "msg_FriendJoin" : "msg_UserJoin"); |
489 break; |
492 break; |
490 case 2: |
493 case 2: |
491 cssClass = (isFriend ? "msg_FriendAction" : "msg_UserAction"); |
494 cssClass = (isFriend ? "msg_FriendAction" : "msg_UserAction"); |
493 default: |
496 default: |
494 if (isFriend) |
497 if (isFriend) |
495 cssClass = "msg_FriendChat"; |
498 cssClass = "msg_FriendChat"; |
496 } |
499 } |
497 |
500 |
498 bool isHL = (!nick.isEmpty() && |
501 bool isHL = false; |
499 (nick != m_userNick) && |
502 |
500 str.toLower().contains(m_hlRegExp)); |
503 if ((!nick.isEmpty()) && (nick != m_userNick)) |
|
504 { |
|
505 QString lcStr = str.toLower(); |
|
506 |
|
507 foreach (const QRegExp & hl, m_highlights) |
|
508 { |
|
509 if (lcStr.contains(hl)) |
|
510 { |
|
511 isHL = true; |
|
512 break; |
|
513 } |
|
514 } |
|
515 } |
501 |
516 |
502 addLine(cssClass, formattedStr, isHL); |
517 addLine(cssClass, formattedStr, isHL); |
503 } |
518 } |
504 |
519 |
505 void HWChatWidget::addLine(const QString & cssClass, QString line, bool isHighlight) |
520 void HWChatWidget::addLine(const QString & cssClass, QString line, bool isHighlight) |
582 |
597 |
583 chatText->clear(); |
598 chatText->clear(); |
584 chatStrings.clear(); |
599 chatStrings.clear(); |
585 chatNicks->clear(); |
600 chatNicks->clear(); |
586 m_userNick = gameSettings->value("net/nick","").toString(); |
601 m_userNick = gameSettings->value("net/nick","").toString(); |
587 m_hlRegExp = QRegExp(QString("^(.* )?%1(( |[^-a-z0-9_]( |$)).*)?$"). |
602 |
588 arg(QRegExp::escape(m_userNick).toLower())); |
603 // clear and re compile regexp for highlighting |
|
604 m_highlights.clear(); |
|
605 |
|
606 QString hlRegExp("^(.* )?%1(( |[^-a-z0-9_]( |$)).*)?$"); |
|
607 QRegExp whitespace("\\s"); |
|
608 |
|
609 m_highlights.append(QRegExp(hlRegExp.arg(m_userNick))); |
|
610 |
|
611 QFile file(cfgdir->absolutePath() + "/" + m_userNick + "_highlight.txt"); |
|
612 |
|
613 if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text))) |
|
614 { |
|
615 QTextStream in(&file); |
|
616 while (!in.atEnd()) |
|
617 { |
|
618 QString line = in.readLine(); |
|
619 QStringList list = line.split(whitespace); |
|
620 foreach (QString word, list) |
|
621 { |
|
622 m_highlights.append(QRegExp( |
|
623 hlRegExp.arg(QRegExp::escape(word.toLower())))); |
|
624 } |
|
625 } |
|
626 |
|
627 if (file.isOpen()) |
|
628 file.close(); |
|
629 } |
|
630 |
|
631 QFile file2(cfgdir->absolutePath() + "/" + m_userNick + "_hlregexp.txt"); |
|
632 |
|
633 if (file2.exists() && (file2.open(QIODevice::ReadOnly | QIODevice::Text))) |
|
634 { |
|
635 QTextStream in(&file2); |
|
636 while (!in.atEnd()) |
|
637 { |
|
638 m_highlights.append(QRegExp(in.readLine().toLower())); |
|
639 } |
|
640 |
|
641 if (file2.isOpen()) |
|
642 file2.close(); |
|
643 } |
589 } |
644 } |
590 |
645 |
591 void HWChatWidget::onKick() |
646 void HWChatWidget::onKick() |
592 { |
647 { |
593 QListWidgetItem * curritem = chatNicks->currentItem(); |
648 QListWidgetItem * curritem = chatNicks->currentItem(); |
785 |
840 |
786 setStyleSheet(style); |
841 setStyleSheet(style); |
787 chatText->document()->setDefaultStyleSheet(*s_styleSheet); |
842 chatText->document()->setDefaultStyleSheet(*s_styleSheet); |
788 displayNotice(tr("Stylesheet imported from %1").arg(path)); |
843 displayNotice(tr("Stylesheet imported from %1").arg(path)); |
789 displayNotice(tr("Enter %1 if you want to use the current styleSheet in future, enter %2 to reset!").arg("/saveStyleSheet").arg("/discaredStyleSheet")); |
844 displayNotice(tr("Enter %1 if you want to use the current styleSheet in future, enter %2 to reset!").arg("/saveStyleSheet").arg("/discaredStyleSheet")); |
|
845 |
|
846 if (file.isOpen()) |
|
847 file.close(); |
790 |
848 |
791 event->acceptProposedAction(); |
849 event->acceptProposedAction(); |
792 } |
850 } |
793 else |
851 else |
794 displayError(tr("Couldn't read %1").arg(event->mimeData()->urls()[0].toString())); |
852 displayError(tr("Couldn't read %1").arg(event->mimeData()->urls()[0].toString())); |