start chat-implementing in startnetworkgamedialog with only chattools ;)
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
using namespace std;
|
||||
|
||||
|
||||
ChatTools::ChatTools(QLineEdit* l, QTreeWidget *t) : nickAutoCompletitionCounter(0), myLineEdit(l), myNickTreeWidget(t), myNickStringList(NULL)
|
||||
ChatTools::ChatTools(QLineEdit* l, QTreeWidget *t, QTextBrowser *b) : nickAutoCompletitionCounter(0), myLineEdit(l), myNickTreeWidget(t), myNickStringList(NULL), myTextBrowser(b)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -33,6 +33,30 @@ ChatTools::~ChatTools()
|
||||
|
||||
}
|
||||
|
||||
void ChatTools::sendMessage() {
|
||||
|
||||
fillChatLinesHistory(myLineEdit->text());
|
||||
// myW->getSession().sendChatMessage(myW->lineEdit_ChatInput->text().toUtf8().constData());
|
||||
myLineEdit->setText("");
|
||||
}
|
||||
|
||||
void ChatTools::receiveMessage(QString playerName, QString message) {
|
||||
|
||||
if(myTextBrowser)
|
||||
myTextBrowser->append(playerName + ": " + message);
|
||||
}
|
||||
|
||||
void ChatTools::clearChat() {
|
||||
|
||||
if(myTextBrowser)
|
||||
myTextBrowser->clear();
|
||||
}
|
||||
|
||||
void ChatTools::checkInputLength(QString string) {
|
||||
|
||||
if(string.toUtf8().length() > 120) myLineEdit->setMaxLength(string.length());
|
||||
}
|
||||
|
||||
void ChatTools::fillChatLinesHistory(QString fillString) {
|
||||
|
||||
chatLinesHistory << fillString;
|
||||
|
||||
@@ -29,12 +29,17 @@ class ChatTools : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChatTools(QLineEdit* l, QTreeWidget *t = NULL);
|
||||
ChatTools(QLineEdit* l, QTreeWidget *t = NULL, QTextBrowser *b = NULL);
|
||||
|
||||
~ChatTools();
|
||||
|
||||
public slots:
|
||||
|
||||
void sendMessage();
|
||||
void receiveMessage(QString playerName, QString message);
|
||||
void clearChat();
|
||||
void checkInputLength(QString string);
|
||||
|
||||
void fillChatLinesHistory(QString fillString);
|
||||
void showChatHistoryIndex(int index);
|
||||
int getChatLinesHistorySize() { return chatLinesHistory.size(); }
|
||||
@@ -53,6 +58,8 @@ private:
|
||||
QLineEdit* myLineEdit;
|
||||
QTreeWidget *myNickTreeWidget;
|
||||
QStringList myNickStringList;
|
||||
QTextBrowser* myTextBrowser;
|
||||
|
||||
// friend class GuiWrapper;
|
||||
};
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
<item row="3" column="0" >
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<string>Lobby-Chat</string>
|
||||
<string>Chat</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="leftMargin" >
|
||||
|
||||
@@ -20,19 +20,25 @@
|
||||
#include "startnetworkgamedialogimpl.h"
|
||||
#include "session.h"
|
||||
#include "configfile.h"
|
||||
#include "chattools.h"
|
||||
#include <net/socket_msg.h>
|
||||
|
||||
startNetworkGameDialogImpl::startNetworkGameDialogImpl(QWidget *parent, ConfigFile *config)
|
||||
: QDialog(parent), myW(NULL), myPlayerId(0), isAdmin(false), myConfig(config), mySession(NULL)
|
||||
: QDialog(parent), myW(NULL), keyUpDownChatCounter(0), myPlayerId(0), isAdmin(false), myConfig(config), mySession(NULL), myChat(NULL)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
myChat = new ChatTools(lineEdit_ChatInput, treeWidget, textBrowser_ChatDisplay);
|
||||
|
||||
lineEdit_ChatInput->installEventFilter(this);
|
||||
|
||||
connect( pushButton_cancel, SIGNAL( clicked() ), this, SLOT( cancel() ) );
|
||||
connect( pushButton_startGame, SIGNAL( clicked() ), this, SLOT( startGame() ) );
|
||||
connect( pushButton_Kick, SIGNAL( clicked() ), this, SLOT( kickPlayer() ) );
|
||||
connect( treeWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem*) ), this, SLOT( playerSelected(QTreeWidgetItem*, QTreeWidgetItem*) ) );
|
||||
connect( lineEdit_ChatInput, SIGNAL( returnPressed () ), this, SLOT( sendChatMessage() ) );
|
||||
|
||||
connect( lineEdit_ChatInput, SIGNAL( returnPressed () ), myChat, SLOT( sendMessage() ) );
|
||||
connect( lineEdit_ChatInput, SIGNAL( textChanged (QString) ), myChat, SLOT( checkInputLength(QString) ) );
|
||||
connect( lineEdit_ChatInput, SIGNAL( textEdited (QString) ), myChat, SLOT( setChatTextEdited() ) );
|
||||
|
||||
clearDialog();
|
||||
}
|
||||
@@ -175,6 +181,7 @@ void startNetworkGameDialogImpl::clearDialog()
|
||||
pushButton_Kick->setEnabled(false);
|
||||
pushButton_startGame->setEnabled(false);
|
||||
treeWidget->clear();
|
||||
myChat->clearChat();
|
||||
checkBox_fillUpWithComputerOpponents->hide();
|
||||
|
||||
myPlayerId = 0;
|
||||
@@ -187,9 +194,33 @@ void startNetworkGameDialogImpl::setSession(Session *session)
|
||||
|
||||
void startNetworkGameDialogImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||
|
||||
|
||||
if (event->key() == 16777220) { pushButton_startGame->click(); } //ENTER
|
||||
|
||||
if (event->key() == Qt::Key_Up && lineEdit_ChatInput->hasFocus()) {
|
||||
if((keyUpDownChatCounter + 1) <= myChat->getChatLinesHistorySize()) { keyUpDownChatCounter++; }
|
||||
// std::cout << "Up keyUpDownChatCounter: " << keyUpDownChatCounter << "\n";
|
||||
myChat->showChatHistoryIndex(keyUpDownChatCounter);
|
||||
}
|
||||
else if(event->key() == Qt::Key_Down && lineEdit_ChatInput->hasFocus()) {
|
||||
if((keyUpDownChatCounter - 1) >= 0) { keyUpDownChatCounter--; }
|
||||
// std::cout << "Down keyUpDownChatCounter: " << keyUpDownChatCounter << "\n";
|
||||
myChat->showChatHistoryIndex(keyUpDownChatCounter);
|
||||
}
|
||||
else { keyUpDownChatCounter = 0; }
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::sendChatMessage() { /*myChat->sendMessage();*/ }
|
||||
bool startNetworkGameDialogImpl::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
||||
|
||||
if (obj == lineEdit_ChatInput && lineEdit_ChatInput->text() != "" && event->type() == QEvent::KeyPress && keyEvent->key() == Qt::Key_Tab)
|
||||
{
|
||||
myChat->nickAutoCompletition();
|
||||
return true;
|
||||
} else {
|
||||
// pass the event on to the parent class
|
||||
return QDialog::eventFilter(obj, event);
|
||||
}
|
||||
}
|
||||
|
||||
void startNetworkGameDialogImpl::receiveChatMsg(QString playerName, QString message) {
|
||||
myChat->receiveMessage(playerName, message);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
class Session;
|
||||
class ConfigFile;
|
||||
class ChatTools;
|
||||
|
||||
class startNetworkGameDialogImpl: public QDialog, public Ui::startNetworkGameDialog {
|
||||
Q_OBJECT
|
||||
@@ -56,23 +57,28 @@ public slots:
|
||||
void checkPlayerQuantity();
|
||||
void clearDialog();
|
||||
|
||||
void receiveChatMsg(QString playerName, QString message);
|
||||
|
||||
void keyPressEvent ( QKeyEvent*);
|
||||
bool eventFilter(QObject *obj, QEvent *event);
|
||||
|
||||
|
||||
void setMaxPlayerNumber ( int theValue ) { maxPlayerNumber = theValue; label_maxPlayerNumber->setText(QString::number(theValue,10)); }
|
||||
int getMaxPlayerNumber() const { return maxPlayerNumber; }
|
||||
|
||||
void exec();
|
||||
|
||||
void sendChatMessage();
|
||||
|
||||
private:
|
||||
|
||||
mainWindowImpl* myW;
|
||||
int maxPlayerNumber;
|
||||
int keyUpDownChatCounter;
|
||||
unsigned myPlayerId;
|
||||
bool isAdmin;
|
||||
ConfigFile *myConfig;
|
||||
Session *mySession;
|
||||
ChatTools *myChat;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user