QTfrontend/chatwidget.cpp
changeset 1520 f72f538eba05
parent 1516 bb9fa5809c49
child 1521 971f523d7c01
equal deleted inserted replaced
1519:7b6adbe5266a 1520:f72f538eba05
    14  * You should have received a copy of the GNU General Public License
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
       
    19 #include <QTextBrowser>
    19 #include <QListWidget>
    20 #include <QListWidget>
    20 #include <QLineEdit>
    21 #include <QLineEdit>
    21 #include <QAction>
    22 #include <QAction>
    22 
    23 
    23 #include "chatwidget.h"
    24 #include "chatwidget.h"
    35   chatEditLine = new QLineEdit(this);
    36   chatEditLine = new QLineEdit(this);
    36   connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    37   connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    37 
    38 
    38   mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
    39   mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
    39 
    40 
    40   chatText = new QListWidget(this);
    41   chatText = new QTextBrowser(this);
    41   chatText->setMinimumHeight(10);
    42   chatText->setMinimumHeight(20);
    42   chatText->setMinimumWidth(10);
    43   chatText->setMinimumWidth(10);
    43   chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    44   chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    44   mainLayout.addWidget(chatText, 0, 0);
    45   mainLayout.addWidget(chatText, 0, 0);
    45 
    46 
    46   chatNicks = new QListWidget(this);
    47   chatNicks = new QListWidget(this);
    61   chatEditLine->clear();
    62   chatEditLine->clear();
    62 }
    63 }
    63 
    64 
    64 void HWChatWidget::onChatString(const QString& str)
    65 void HWChatWidget::onChatString(const QString& str)
    65 {
    66 {
    66 	QListWidget* w = chatText;
    67 	if (chatStrings.size() > 250)
       
    68 		chatStrings.removeFirst();
    67 	
    69 	
    68 	if (w->count() > 250)
    70 	chatStrings.append(str);
    69 		delete w->item(0);
    71 	
       
    72 	chatText->setPlainText(chatStrings.join("\n"));
    70 
    73 
    71 	w->addItem(str);
    74 	chatText->moveCursor(QTextCursor::End);
    72 	w->scrollToBottom();
       
    73 	w->setSelectionMode(QAbstractItemView::NoSelection);
       
    74 }
    75 }
    75 
    76 
    76 void HWChatWidget::nickAdded(const QString& nick)
    77 void HWChatWidget::nickAdded(const QString& nick)
    77 {
    78 {
    78 	QListWidgetItem * item = new QListWidgetItem(nick);
    79 	QListWidgetItem * item = new QListWidgetItem(nick);
    79 	chatNicks->addItem(item);
    80 	chatNicks->addItem(item);
    80 }
    81 }
    81 
    82 
    82 void HWChatWidget::nickRemoved(const QString& nick)
    83 void HWChatWidget::nickRemoved(const QString& nick)
    83 {
    84 {
    84   QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
    85 	QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
    85   for(QList<QListWidgetItem *>::iterator it=items.begin(); it!=items.end();) {
    86 	for(QList<QListWidgetItem *>::iterator it=items.begin(); it!=items.end();) {
    86     chatNicks->takeItem(chatNicks->row(*it));
    87 		chatNicks->takeItem(chatNicks->row(*it));
    87     ++it;
    88 		++it;
    88   }
    89 	}
    89 }
    90 }
    90 
    91 
    91 void HWChatWidget::clear()
    92 void HWChatWidget::clear()
    92 {
    93 {
    93 	chatText->clear();
    94 	chatText->clear();
       
    95 	chatStrings.clear();
    94 	chatNicks->clear();
    96 	chatNicks->clear();
    95 }
    97 }
    96 
    98 
    97 void HWChatWidget::onKick()
    99 void HWChatWidget::onKick()
    98 {
   100 {