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