Changeset 4791 for trunk/qt-gui/src/ewidgets.cpp
- Timestamp:
- 11/30/06 03:02:49 (2 years ago)
- Files:
-
- 1 modified
-
trunk/qt-gui/src/ewidgets.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt-gui/src/ewidgets.cpp
r4788 r4791 45 45 #include <qlayout.h> 46 46 #include <qheader.h> 47 #include <qstringlist.h> 47 48 #include <ctype.h> 48 49 #include <algorithm> … … 662 663 663 664 //- Message View Widget --------------------------------------------------------- 665 666 QStringList CMessageViewWidget::getStyleNames(bool includeHistoryStyles) 667 { 668 static const char *const styleNames[] = { 669 QT_TR_NOOP("Default"), 670 QT_TR_NOOP("Compact"), 671 QT_TR_NOOP("Tiny"), 672 QT_TR_NOOP("Table"), 673 QT_TR_NOOP("Long"), 674 QT_TR_NOOP("Wide") 675 }; 676 677 int listLength; 678 679 // Style 5 (Wide) is currently only supported in buffered mode which is not used for chat 680 if(includeHistoryStyles) 681 listLength = 6; 682 else 683 listLength = 5; 684 685 QStringList styleList; 686 for(int i = 0; i < listLength; ++i) 687 styleList.append(tr(styleNames[i])); 688 689 return styleList; 690 } 691 664 692 CMessageViewWidget::CMessageViewWidget(const char *szId, unsigned long nPPID, 665 CMainWindow *m, QWidget* parent, const char * name)693 CMainWindow *m, QWidget* parent, const char *name, bool historyMode) 666 694 : CHistoryWidget(parent, name) 667 695 { 668 696 m_szId = szId ? strdup(szId) : 0; 669 697 m_nPPID = nPPID; 670 m_nMsgStyle = m->m_nMsgStyle; 671 m_nDateFormat = m->m_nDateFormat; 672 m_bAppendLineBreak = m->m_bAppendLineBreak; 698 if (historyMode) 699 { 700 m_useBuffer = true; 701 m_nMsgStyle = m->m_histMsgStyle; 702 m_nDateFormat = m->m_histDateFormat; 703 m_extraSpacing = m->m_histVertSpacing; 704 m_appendLineBreak = false; 705 } 706 else 707 { 708 m_useBuffer = false; 709 m_nMsgStyle = m->m_chatMsgStyle; 710 m_nDateFormat = m->m_chatDateFormat; 711 m_extraSpacing = m->m_chatVertSpacing; 712 m_appendLineBreak = m->m_chatAppendLineBreak; 713 } 673 714 m_colorRcv = m->m_colorRcv; 674 715 m_colorSnt = m->m_colorSnt; … … 679 720 mainwin = m; 680 721 722 clear(); 723 681 724 /* 682 725 // add all unread messages. … … 698 741 } 699 742 700 CMessageViewWidget::CMessageViewWidget(unsigned long _nUin, CMainWindow *m, QWidget * parent, const char * name)743 CMessageViewWidget::CMessageViewWidget(unsigned long _nUin, CMainWindow *m, QWidget *parent, const char *name, bool historyMode) 701 744 :CHistoryWidget(parent,name) 702 745 { 703 746 m_nUin= _nUin; 704 747 m_szId = NULL; // avoid desalocation error at destructor 705 m_nMsgStyle = m->m_nMsgStyle; 706 m_nDateFormat = m->m_nDateFormat; 707 m_bAppendLineBreak = m->m_bAppendLineBreak; 748 if (historyMode) 749 { 750 m_useBuffer = true; 751 m_nMsgStyle = m->m_histMsgStyle; 752 m_nDateFormat = m->m_histDateFormat; 753 m_extraSpacing = m->m_histVertSpacing; 754 m_appendLineBreak = false; 755 } 756 else 757 { 758 m_useBuffer = false; 759 m_nMsgStyle = m->m_chatMsgStyle; 760 m_nDateFormat = m->m_chatDateFormat; 761 m_extraSpacing = m->m_chatVertSpacing; 762 m_appendLineBreak = m->m_chatAppendLineBreak; 763 } 708 764 m_colorRcv = m->m_colorRcv; 709 765 m_colorSnt = m->m_colorSnt; … … 713 769 setPaletteBackgroundColor(m->m_colorChatBkg); 714 770 mainwin = m; 771 772 clear(); 773 715 774 /* 716 775 // add all unread messages. … … 746 805 } 747 806 807 void CMessageViewWidget::clear() 808 { 809 CHistoryWidget::clear(); 810 811 m_buffer = ""; 812 813 switch (m_nMsgStyle) 814 { 815 case 5: 816 // table doesn't work when appending so must buffer when using this style 817 m_buffer.append("<table border=\"0\">"); 818 m_useBuffer = true; 819 break; 820 } 821 if (m_useBuffer) 822 m_buffer.prepend("<html><body>"); 823 } 824 825 void CMessageViewWidget::updateContent() 826 { 827 if (m_useBuffer) 828 setText(m_buffer); 829 } 830 831 void CMessageViewWidget::internalAddMsg(QString s) 832 { 833 if (m_extraSpacing) 834 { 835 if (m_nMsgStyle != 5) 836 { 837 if (m_useBuffer) 838 { 839 s.prepend("<p>"); 840 s.append("</p>"); 841 } 842 else 843 { 844 s.append("<br>"); 845 } 846 } 847 else 848 { 849 s.append("<tr><td colspan=\"3\"></td></tr>"); 850 } 851 } 852 853 if (m_useBuffer) 854 { 855 if (!m_extraSpacing && m_nMsgStyle != 5) 856 s.append("<br>"); 857 858 m_buffer.append(s); 859 if (m_appendLineBreak) 860 m_buffer.append("<hr>"); 861 } 862 else 863 { 864 append(s); 865 if (m_appendLineBreak) 866 append("<hr>"); 867 } 868 } 869 748 870 void CMessageViewWidget::addMsg(ICQEvent * _e) 749 871 { … … 759 881 QString s; 760 882 QString color; 761 bool bAIM = (m_nPPID == LICQ_PPID) && !isdigit(m_szId[0]); 762 763 if (fromHistory)883 884 if (fromHistory) 885 { 764 886 if (dir == D_RECEIVER) 765 887 color = m_colorRcvHistory.name(); 766 888 else 767 color = m_colorSntHistory.name(); 889 color = m_colorSntHistory.name(); 890 } 768 891 else 892 { 769 893 if (dir == D_RECEIVER) 770 894 color = m_colorRcv.name(); 771 895 else 772 color = m_colorSnt.name(); 773 774 /* Remove trailing line breaks. */ 775 for (unsigned int i = messageText.length() - 1; i>=0; i--) { 776 if (messageText.at(i) == '\n' || messageText.at(i) == '\r') { 896 color = m_colorSnt.name(); 897 } 898 899 // Remove trailing line breaks. 900 for (int i = messageText.length(); i >= 0; i--) 901 { 902 if (messageText.at(i - 1) != '\n' && messageText.at(i - 1) != '\r') 903 { 777 904 messageText.truncate(i); 778 } else {779 905 break; 780 906 } 781 907 } 782 908 909 // Extract everything inside <body>...</body> 910 // Leaving <html> and <body> messes with our message display 911 QRegExp body("<body[^>]*>(.*)</body>"); 912 if (body.search(messageText) != -1) 913 messageText = body.cap(1); 914 915 // Remove all font tags 916 messageText.replace(QRegExp("</?font[^>]*>"), ""); 917 783 918 QString my_date = date.toString( m_nDateFormat ); 784 919 785 920 switch (m_nMsgStyle) { 786 921 case 0: 787 s = QString("< html><body><font color=\"%1\"><b>%2%3 [%4%5%6%7] %8:</b></font><br>")922 s = QString("<font color=\"%1\"><b>%2%3 [%4%5%6%7] %8:</b></font><br>") 788 923 .arg(color) 789 924 .arg(eventDescription) … … 794 929 .arg(isEncrypted ? 'E' : '-') 795 930 .arg(contactName); 796 s.append(QString("<font color=\"%1\">%2</font> </body></html>")931 s.append(QString("<font color=\"%1\">%2</font>") 797 932 .arg(color) 798 933 .arg(messageText)); … … 811 946 .arg(color) 812 947 .arg(messageText)); 813 if (bAIM)814 {815 s.prepend("<html><body>");816 s.append("</body></html>");817 }818 819 948 break; 820 949 case 2: … … 827 956 .arg(color) 828 957 .arg(messageText)); 829 830 if (bAIM)831 {832 s.prepend("<html><body>");833 s.append("</body></html>");834 }835 836 958 break; 837 959 case 3: … … 864 986 .arg(color) 865 987 .arg(messageText)); 866 break; 867 } 868 869 append(s); 870 if (m_bAppendLineBreak) { 871 append("<hr>"); 872 } 988 break; 989 case 5: 990 // Mode 5 is a table so it cannot be displayed in paragraphs 991 s = QString("<tr><td><nobr><b><font color=\"%1\">%2</font><b></nobr></td>") 992 .arg(color) 993 .arg(my_date); 994 s.append(QString("<td><b><font color=\"%3\">%4</font></b></font></td>") 995 .arg(color) 996 .arg(contactName)); 997 s.append(QString("<td><font color=\"%1\">%2</font></td></tr>") 998 .arg(color) 999 .arg(messageText)); 1000 break; 1001 } 1002 1003 internalAddMsg(s); 873 1004 } 874 1005 … … 989 1120 break; 990 1121 1122 case 5: 1123 s = QString("<tr><td><b><font color=\"%1\">%2</font><b></td><td colspan=\"2\"><b><font color=\"%3\">%4</font></b></font></td></tr>") 1124 .arg(color) 1125 .arg(dateTime) 1126 .arg(color) 1127 .arg(messageText); 1128 break; 1129 991 1130 case 0: 992 1131 default: 993 s = QString("< html><body><font color=\"%1\"><b>[%2] %3</b></font><br></body></html>")1132 s = QString("<font color=\"%1\"><b>[%2] %3</b></font><br>") 994 1133 .arg(color) 995 1134 .arg(dateTime) … … 998 1137 } 999 1138 1000 append(s); 1001 if (m_bAppendLineBreak) 1002 append("<hr>"); 1139 internalAddMsg(s); 1003 1140 } 1004 1141
