QTfrontend/chatwidget.cpp
changeset 1577 e3e37c730dc0
parent 1521 971f523d7c01
child 1584 90f6a5abad17
equal deleted inserted replaced
1576:a02353129a41 1577:e3e37c730dc0
     1 /*
     1 /*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com>
     3  * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com>
       
     4  * Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     5  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     8  * the Free Software Foundation; version 2 of the License
     8  *
     9  *
    18 
    19 
    19 #include <QTextBrowser>
    20 #include <QTextBrowser>
    20 #include <QListWidget>
    21 #include <QListWidget>
    21 #include <QLineEdit>
    22 #include <QLineEdit>
    22 #include <QAction>
    23 #include <QAction>
       
    24 #include <QApplication>
    23 
    25 
    24 #include "chatwidget.h"
    26 #include "chatwidget.h"
    25 
    27 
    26 HWChatWidget::HWChatWidget(QWidget* parent) :
    28 HWChatWidget::HWChatWidget(QWidget* parent) :
    27   QWidget(parent),
    29   QWidget(parent),
    28   mainLayout(this)
    30   mainLayout(this)
    29 {
    31 {
    30   mainLayout.setSpacing(1);
    32 	mainLayout.setSpacing(1);
    31   mainLayout.setMargin(1);
    33 	mainLayout.setMargin(1);
    32   mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
    34 	mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
    33   mainLayout.setColumnStretch(0, 75);
    35 	mainLayout.setColumnStretch(0, 75);
    34   mainLayout.setColumnStretch(1, 25);
    36 	mainLayout.setColumnStretch(1, 25);
    35 
    37 
    36   chatEditLine = new QLineEdit(this);
    38 	chatEditLine = new QLineEdit(this);
    37   chatEditLine->setMaxLength(300);
    39 	chatEditLine->setMaxLength(300);
    38   connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    40 	connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    39 
    41 
    40   mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
    42 	mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
    41 
    43 
    42   chatText = new QTextBrowser(this);
    44 	chatText = new QTextBrowser(this);
    43   chatText->setMinimumHeight(20);
    45 	chatText->setMinimumHeight(20);
    44   chatText->setMinimumWidth(10);
    46 	chatText->setMinimumWidth(10);
    45   chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    47 	chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    46   mainLayout.addWidget(chatText, 0, 0);
    48 	mainLayout.addWidget(chatText, 0, 0);
    47 
    49 
    48   chatNicks = new QListWidget(this);
    50 	chatNicks = new QListWidget(this);
    49   chatNicks->setMinimumHeight(10);
    51 	chatNicks->setMinimumHeight(10);
    50   chatNicks->setMinimumWidth(10);
    52 	chatNicks->setMinimumWidth(10);
    51   chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    53 	chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    52   chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
    54 	chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu);
    53   mainLayout.addWidget(chatNicks, 0, 1);
    55 	mainLayout.addWidget(chatNicks, 0, 1);
    54 
    56 
    55   QAction * acBan = new QAction(QAction::tr("Kick"), chatNicks);
    57 	QAction * acBan = new QAction(QAction::tr("Kick"), chatNicks);
    56   connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onKick()));
    58 	connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onKick()));
    57   chatNicks->insertAction(0, acBan);
    59 	chatNicks->insertAction(0, acBan);
       
    60 
       
    61 	QAction * acInfo = new QAction(QAction::tr("Info"), chatNicks);
       
    62 	connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo()));
       
    63 	chatNicks->insertAction(0, acInfo);
    58 }
    64 }
    59 
    65 
    60 void HWChatWidget::returnPressed()
    66 void HWChatWidget::returnPressed()
    61 {
    67 {
    62   emit chatLine(chatEditLine->text());
    68 	emit chatLine(chatEditLine->text());
    63   chatEditLine->clear();
    69 	chatEditLine->clear();
    64 }
    70 }
    65 
    71 
    66 void HWChatWidget::onChatString(const QString& str)
    72 void HWChatWidget::onChatString(const QString& str)
    67 {
    73 {
    68 	if (chatStrings.size() > 250)
    74 	if (chatStrings.size() > 250)
   102 	QListWidgetItem * curritem = chatNicks->currentItem();
   108 	QListWidgetItem * curritem = chatNicks->currentItem();
   103 	if (curritem)
   109 	if (curritem)
   104 		emit kick(curritem->text());
   110 		emit kick(curritem->text());
   105 }
   111 }
   106 
   112 
       
   113 void HWChatWidget::onInfo()
       
   114 {
       
   115 	QListWidgetItem * curritem = chatNicks->currentItem();
       
   116 	if (curritem)
       
   117 		emit info(curritem->text());
       
   118 }
       
   119 
   107 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady)
   120 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady)
   108 {
   121 {
   109 	QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
   122 	QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
   110 	if (items.size() != 1)
   123 	if (items.size() != 1)
   111 	{
   124 	{