From 2333079b1316319be0331ecaf6e714c727090200 Mon Sep 17 00:00:00 2001 From: doitux Date: Fri, 25 May 2007 00:09:51 +0000 Subject: [PATCH] add chat functions --- src/gui/generic/serverguiwrapper.cpp | 2 ++ src/gui/generic/serverguiwrapper.h | 2 ++ src/gui/guiinterface.h | 3 +++ src/gui/qt/guiwrapper.cpp | 4 ++++ src/gui/qt/guiwrapper.h | 4 ++++ src/gui/qt/mainwindow.ui | 2 +- src/gui/qt/mainwindow/chat/chat.cpp | 12 +++++++++++- src/gui/qt/mainwindow/chat/chat.h | 7 +++---- src/gui/qt/mainwindow/mainwindowimpl.cpp | 14 +++++++++++++- src/gui/qt/mainwindow/mainwindowimpl.h | 8 +++++++- src/session.cpp | 5 +++++ src/session.h | 3 +++ 12 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index dd8da9ca..531a7d61 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -94,6 +94,8 @@ void ServerGuiWrapper::meInAction() {} void ServerGuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) {} void ServerGuiWrapper::logNewGameHandMsg(int gameID, int handID) {} +void ServerGuiWrapper::chatAppendMsg(std::string msg) {} + void ServerGuiWrapper::SignalNetClientConnect(int actionID) { if (myClientcb) myClientcb->SignalNetClientConnect(actionID); } void ServerGuiWrapper::SignalNetClientGameInfo(int actionID) { if (myClientcb) myClientcb->SignalNetClientGameInfo(actionID); } void ServerGuiWrapper::SignalNetClientError(int errorID, int osErrorID) { if (myClientcb) myClientcb->SignalNetClientError(errorID, osErrorID); } diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 4b485dba..7595ebcc 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -77,6 +77,8 @@ public: void logPlayerActionMsg(std::string playerName, int action, int setValue) ; void logNewGameHandMsg(int gameID, int handID) ; + void chatAppendMsg(std::string msg); + void SignalNetClientConnect(int actionID); void SignalNetClientGameInfo(int actionID); void SignalNetClientError(int errorID, int osErrorID); diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index 56f9de04..f15c1fb3 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -93,6 +93,9 @@ public: virtual void logPlayerActionMsg(std::string playName, int action, int setValue) =0; virtual void logNewGameHandMsg(int gameID, int HandID) =0; + //chat + virtual void chatAppendMsg(std::string msg) =0; + }; #endif diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index 6ae3babc..0ba4d30f 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -21,6 +21,7 @@ #include "guiwrapper.h" #include "session.h" #include "log.h" +#include "chat.h" #include "mainwindowimpl.h" #include "configfile.h" @@ -34,6 +35,7 @@ GuiWrapper::GuiWrapper(ConfigFile *c) : myLog(0), myW(0), myConfig(c) myW = new mainWindowImpl(myConfig); myW->show(); myLog = new Log(myW, myConfig); + myChat = new Chat(myW, myConfig); } @@ -90,6 +92,8 @@ void GuiWrapper::meInAction() { myW->signalMeInAction(); } void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->signalLogPlayerActionMsg(QString::fromUtf8(playerName.c_str()), action, setValue); } void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->signalLogNewGameHandMsg(gameID, handID); } +void GuiWrapper::chatAppendMsg(string msg) { myChat->receiveMessage(msg); } + void GuiWrapper::SignalNetClientConnect(int actionID) { myW->signalNetClientConnect(actionID); } void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGameInfo(actionID); } void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index 6999314c..ff4a8d41 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -28,6 +28,7 @@ class Session; class mainWindowImpl; class Log; +class Chat; class ConfigFile; class GuiWrapper : public GuiInterface @@ -84,6 +85,8 @@ public: void logPlayerActionMsg(std::string playerName, int action, int setValue) ; void logNewGameHandMsg(int gameID, int handID) ; + void chatAppendMsg(std::string msg); + void SignalNetClientConnect(int actionID); void SignalNetClientGameInfo(int actionID); void SignalNetClientError(int errorID, int osErrorID); @@ -100,6 +103,7 @@ public: private: Log *myLog; + Chat *myChat; mainWindowImpl *myW; ConfigFile *myConfig; diff --git a/src/gui/qt/mainwindow.ui b/src/gui/qt/mainwindow.ui index dbbf5ecc..797579da 100644 --- a/src/gui/qt/mainwindow.ui +++ b/src/gui/qt/mainwindow.ui @@ -1847,7 +1847,7 @@ QTabWidget::Rounded - 1 + 0 diff --git a/src/gui/qt/mainwindow/chat/chat.cpp b/src/gui/qt/mainwindow/chat/chat.cpp index f1998ce3..a949cb9d 100644 --- a/src/gui/qt/mainwindow/chat/chat.cpp +++ b/src/gui/qt/mainwindow/chat/chat.cpp @@ -20,12 +20,14 @@ #include "chat.h" #include "mainwindowimpl.h" +#include "session.h" using namespace std; Chat::Chat(mainWindowImpl* w, ConfigFile *c) : myW(w), myConfig(c) { -// myW->setChat(this); + + myW->setChat(this); } @@ -34,3 +36,11 @@ Chat::~Chat() delete myConfig; myConfig = 0; } + +void Chat::sendMessage() { + + myW->getSession().sendChatMessage(myW->lineEdit_ChatInput->text().toUtf8().constData()); + myW->lineEdit_ChatInput->setText(""); +} + +void Chat::receiveMessage(std::string message) { myW->textBrowser_Chat->append(QString::fromUtf8(message.c_str())); } \ No newline at end of file diff --git a/src/gui/qt/mainwindow/chat/chat.h b/src/gui/qt/mainwindow/chat/chat.h index 7db37313..ca8c294b 100644 --- a/src/gui/qt/mainwindow/chat/chat.h +++ b/src/gui/qt/mainwindow/chat/chat.h @@ -40,10 +40,9 @@ public: public slots: -public: - -signals: - + void sendMessage(); + void receiveMessage(std::string); + private: mainWindowImpl *myW; diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 5314c3e2..44334f5d 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -558,6 +558,9 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) connect ( horizontalSlider_speed, SIGNAL( valueChanged(int)), this, SLOT ( setGameSpeed(int) ) ); connect ( pushButton_break, SIGNAL( clicked()), this, SLOT ( breakButtonClicked() ) ); // auch wieder starten!!!! + connect( tabWidget, SIGNAL( currentChanged(int) ), this, SLOT( setChatFocus() ) ); + connect( lineEdit_ChatInput, SIGNAL( returnPressed () ), this, SLOT( sendChatMessage() ) ); + //Nachrichten Thread-Save connect(this, SIGNAL(signalRefreshSet()), this, SLOT(refreshSet())); connect(this, SIGNAL(signalRefreshCash()), this, SLOT(refreshCash())); @@ -862,7 +865,7 @@ void mainWindowImpl::setSession(boost::shared_ptr session) mySession = session; } -void mainWindowImpl::setLog(Log* l) { myLog = l; } + //refresh-Funktionen void mainWindowImpl::refreshSet() { @@ -2506,6 +2509,15 @@ void mainWindowImpl::blinkingStartButtonAnimationAction() { pushButton_break->setPalette(tempPalette); } +void mainWindowImpl::sendChatMessage() { myChat->sendMessage(); } + +void mainWindowImpl::setChatFocus() { + + if(tabWidget->currentIndex() == 1) lineEdit_ChatInput->setFocus(); + else lineEdit_ChatInput->clearFocus(); + +} + void mainWindowImpl::closeEvent(QCloseEvent *event) { mySession->terminateNetworkClient(); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index d4838fd4..a375afe3 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -31,6 +31,7 @@ #include class Log; +class Chat; class ConfigFile; class Session; class Game; @@ -66,7 +67,8 @@ public: Session &getSession(); void setSession(boost::shared_ptr session); - void setLog(Log*); + void setLog(Log* l) { myLog = l; } + void setChat(Chat* c) { myChat = c; } void setSpeeds(); @@ -234,6 +236,9 @@ public slots: void paintStartSplash(); + void sendChatMessage(); + void setChatFocus(); + void networkError(int, int); void networkStart(boost::shared_ptr game); @@ -244,6 +249,7 @@ private: boost::shared_ptr myServerGuiInterface; boost::shared_ptr mySession; Log *myLog; + Chat *myChat; ConfigFile *myConfig; //Logo diff --git a/src/session.cpp b/src/session.cpp index a4e46161..d9fd9743 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -189,3 +189,8 @@ void Session::sendClientPlayerAction() myNetClient->SendPlayerAction(); } +void Session::sendChatMessage(std::string message) { + + //hi lothar --> zum testen schick ich es gleich wieder zurück an die gui. wie du siehst klappt es ;-) + myGui->chatAppendMsg(message); +} diff --git a/src/session.h b/src/session.h index 94588de7..fac7e944 100755 --- a/src/session.h +++ b/src/session.h @@ -23,6 +23,7 @@ #include "playerdata.h" #include "game_defs.h" #include +#include #include class GuiInterface; @@ -58,6 +59,8 @@ public: void setCurrentGameID(const int& theValue) { currentGameID = theValue; } int getCurrentGameID() const { return currentGameID; } + void sendChatMessage(std::string message); + private: int currentGameID;