extra files
This commit is contained in:
parent
e597325ec3
commit
6642b332f0
2 changed files with 116 additions and 0 deletions
78
cockatrice/src/tab_message.cpp
Normal file
78
cockatrice/src/tab_message.cpp
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QAction>
|
||||||
|
#include "tab_message.h"
|
||||||
|
#include "abstractclient.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
|
|
||||||
|
TabMessage::TabMessage(AbstractClient *_client, const QString &_userName)
|
||||||
|
: Tab(), client(_client), userName(_userName)
|
||||||
|
{
|
||||||
|
textEdit = new QTextEdit;
|
||||||
|
textEdit->setReadOnly(true);
|
||||||
|
sayEdit = new QLineEdit;
|
||||||
|
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
|
||||||
|
|
||||||
|
QVBoxLayout *vbox = new QVBoxLayout;
|
||||||
|
vbox->addWidget(textEdit);
|
||||||
|
vbox->addWidget(sayEdit);
|
||||||
|
|
||||||
|
aLeave = new QAction(this);
|
||||||
|
connect(aLeave, SIGNAL(triggered()), this, SLOT(actLeave()));
|
||||||
|
|
||||||
|
tabMenu = new QMenu(this);
|
||||||
|
tabMenu->addAction(aLeave);
|
||||||
|
|
||||||
|
retranslateUi();
|
||||||
|
setLayout(vbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
TabMessage::~TabMessage()
|
||||||
|
{
|
||||||
|
emit talkClosing(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabMessage::retranslateUi()
|
||||||
|
{
|
||||||
|
tabMenu->setTitle(tr("Personal &talk"));
|
||||||
|
aLeave->setText(tr("&Leave"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TabMessage::sanitizeHtml(QString dirty) const
|
||||||
|
{
|
||||||
|
return dirty
|
||||||
|
.replace("&", "&")
|
||||||
|
.replace("<", "<")
|
||||||
|
.replace(">", ">");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabMessage::sendMessage()
|
||||||
|
{
|
||||||
|
if (sayEdit->text().isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
client->sendCommand(new Command_Message(userName, sayEdit->text()));
|
||||||
|
sayEdit->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabMessage::actLeave()
|
||||||
|
{
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabMessage::processMessageEvent(Event_Message *event)
|
||||||
|
{
|
||||||
|
textEdit->append(QString("<font color=\"red\">%1:</font> %2").arg(sanitizeHtml(event->getSenderName())).arg(sanitizeHtml(event->getText())));
|
||||||
|
emit userEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabMessage::processUserLeft(const QString &name)
|
||||||
|
{
|
||||||
|
if (userName == name) {
|
||||||
|
textEdit->append("<font color=\"blue\">" + tr("%1 has left the server.").arg(sanitizeHtml(name)) + "</font>");
|
||||||
|
sayEdit->setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
38
cockatrice/src/tab_message.h
Normal file
38
cockatrice/src/tab_message.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef TAB_MESSAGE_H
|
||||||
|
#define TAB_MESSAGE_H
|
||||||
|
|
||||||
|
#include "tab.h"
|
||||||
|
|
||||||
|
class AbstractClient;
|
||||||
|
class QTextEdit;
|
||||||
|
class QLineEdit;
|
||||||
|
class Event_Message;
|
||||||
|
|
||||||
|
class TabMessage : public Tab {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
AbstractClient *client;
|
||||||
|
QString userName;
|
||||||
|
|
||||||
|
QTextEdit *textEdit;
|
||||||
|
QLineEdit *sayEdit;
|
||||||
|
|
||||||
|
QAction *aLeave;
|
||||||
|
QString sanitizeHtml(QString dirty) const;
|
||||||
|
signals:
|
||||||
|
void talkClosing(TabMessage *tab);
|
||||||
|
private slots:
|
||||||
|
void sendMessage();
|
||||||
|
void actLeave();
|
||||||
|
public slots:
|
||||||
|
void processMessageEvent(Event_Message *event);
|
||||||
|
void processUserLeft(const QString &userName);
|
||||||
|
public:
|
||||||
|
TabMessage(AbstractClient *_client, const QString &_userName);
|
||||||
|
~TabMessage();
|
||||||
|
void retranslateUi();
|
||||||
|
QString getUserName() const { return userName; }
|
||||||
|
QString getTabText() const { return tr("Talking to %1").arg(userName); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue