Commit 05ebb83b authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

improved banning; added [url] and [card] tags for chat

parent 4b84168b
...@@ -136,6 +136,7 @@ SOURCES += src/abstractcounter.cpp \ ...@@ -136,6 +136,7 @@ SOURCES += src/abstractcounter.cpp \
src/gamescene.cpp \ src/gamescene.cpp \
src/arrowitem.cpp \ src/arrowitem.cpp \
src/arrowtarget.cpp \ src/arrowtarget.cpp \
src/tab.cpp \
src/tab_server.cpp \ src/tab_server.cpp \
src/tab_room.cpp \ src/tab_room.cpp \
src/tab_message.cpp \ src/tab_message.cpp \
......
...@@ -2,34 +2,41 @@ ...@@ -2,34 +2,41 @@
#include <QDateTime> #include <QDateTime>
#include <QTextTable> #include <QTextTable>
#include <QScrollBar> #include <QScrollBar>
#include <QMouseEvent>
#include <QDesktopServices>
#include "chatview.h" #include "chatview.h"
ChatView::ChatView(const QString &_ownName, QWidget *parent) ChatView::ChatView(const QString &_ownName, bool _showTimestamps, QWidget *parent)
: QTextEdit(parent), ownName(_ownName) : QTextBrowser(parent), ownName(_ownName), showTimestamps(_showTimestamps)
{ {
setTextInteractionFlags(Qt::TextSelectableByMouse); setReadOnly(true);
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
setOpenLinks(false);
connect(this, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(openLink(const QUrl &)));
} }
void ChatView::appendMessage(QString sender, const QString &message) void ChatView::appendMessage(QString sender, QString message)
{ {
QTextCursor cursor(document()->lastBlock()); QTextCursor cursor(document()->lastBlock());
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
QTextBlockFormat blockFormat; QTextBlockFormat blockFormat;
blockFormat.setBottomMargin(3); blockFormat.setBottomMargin(2);
cursor.insertBlock(blockFormat); cursor.insertBlock(blockFormat);
QTextCharFormat timeFormat; if (showTimestamps) {
timeFormat.setForeground(Qt::black); QTextCharFormat timeFormat;
cursor.setCharFormat(timeFormat); timeFormat.setForeground(Qt::black);
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] ")); cursor.setCharFormat(timeFormat);
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm] "));
}
QTextCharFormat senderFormat; QTextCharFormat senderFormat;
if (sender == ownName) { if (sender == ownName) {
senderFormat.setFontWeight(QFont::Bold); senderFormat.setFontWeight(QFont::Bold);
senderFormat.setForeground(Qt::red); senderFormat.setForeground(Qt::red);
} else } else
senderFormat.setForeground(Qt::blue); senderFormat.setForeground(QColor(0, 0, 254));
cursor.setCharFormat(senderFormat); cursor.setCharFormat(senderFormat);
if (!sender.isEmpty()) if (!sender.isEmpty())
sender.append(": "); sender.append(": ");
...@@ -39,7 +46,122 @@ void ChatView::appendMessage(QString sender, const QString &message) ...@@ -39,7 +46,122 @@ void ChatView::appendMessage(QString sender, const QString &message)
if (sender.isEmpty()) if (sender.isEmpty())
messageFormat.setForeground(Qt::darkGreen); messageFormat.setForeground(Qt::darkGreen);
cursor.setCharFormat(messageFormat); cursor.setCharFormat(messageFormat);
cursor.insertText(message);
int from = 0, index = 0;
while ((index = message.indexOf('[', from)) != -1) {
cursor.insertText(message.left(index));
message = message.mid(index);
if (message.isEmpty())
break;
if (message.startsWith("[card]")) {
message = message.mid(6);
QTextCharFormat tempFormat = messageFormat;
tempFormat.setForeground(Qt::blue);
cursor.setCharFormat(tempFormat);
int closeTagIndex = message.indexOf("[/card]");
cursor.insertText(message.left(closeTagIndex));
cursor.setCharFormat(messageFormat);
if (closeTagIndex == -1)
message.clear();
else
message = message.mid(closeTagIndex + 7);
} else if (message.startsWith("[url]")) {
message = message.mid(5);
int closeTagIndex = message.indexOf("[/url]");
QString url = message.left(closeTagIndex);
if (!url.startsWith("http://"))
url.prepend("http://");
QTextCharFormat tempFormat = messageFormat;
tempFormat.setForeground(QColor(0, 0, 254));
tempFormat.setAnchor(true);
tempFormat.setAnchorHref(url);
cursor.setCharFormat(tempFormat);
cursor.insertText(url);
cursor.setCharFormat(messageFormat);
if (closeTagIndex == -1)
message.clear();
else
message = message.mid(closeTagIndex + 6);
} else
from = 1;
}
if (!message.isEmpty())
cursor.insertText(message);
verticalScrollBar()->setValue(verticalScrollBar()->maximum()); verticalScrollBar()->setValue(verticalScrollBar()->maximum());
} }
void ChatView::enterEvent(QEvent * /*event*/)
{
setMouseTracking(true);
}
void ChatView::leaveEvent(QEvent * /*event*/)
{
setMouseTracking(false);
}
QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
{
QTextCursor cursor(cursorForPosition(pos));
QTextBlock block(cursor.block());
QTextBlock::iterator it;
for (it = block.begin(); !(it.atEnd()); ++it) {
QTextFragment frag = it.fragment();
if (frag.contains(cursor.position()))
return frag;
}
return QTextFragment();
}
QString ChatView::getCardNameUnderMouse(QTextFragment frag) const
{
if (frag.charFormat().foreground().color() == Qt::blue)
return frag.text();
return QString();
}
QString ChatView::getCardNameUnderMouse(const QPoint &pos) const
{
return getCardNameUnderMouse(getFragmentUnderMouse(pos));
}
void ChatView::mouseMoveEvent(QMouseEvent *event)
{
QTextFragment frag = getFragmentUnderMouse(event->pos());
QString cardName = getCardNameUnderMouse(frag);
if (!cardName.isEmpty()) {
viewport()->setCursor(Qt::PointingHandCursor);
emit cardNameHovered(cardName);
} else if (frag.charFormat().isAnchor())
viewport()->setCursor(Qt::PointingHandCursor);
else
viewport()->setCursor(Qt::IBeamCursor);
QTextBrowser::mouseMoveEvent(event);
}
void ChatView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::MidButton) {
QString cardName = getCardNameUnderMouse(event->pos());
if (!cardName.isEmpty())
emit showCardInfoPopup(event->globalPos(), cardName);
}
QTextBrowser::mousePressEvent(event);
}
void ChatView::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::MidButton)
emit deleteCardInfoPopup();
QTextBrowser::mouseReleaseEvent(event);
}
void ChatView::openLink(const QUrl &link)
{
QDesktopServices::openUrl(link);
}
#ifndef CHATVIEW_H #ifndef CHATVIEW_H
#define CHATVIEW_H #define CHATVIEW_H
#include <QTextEdit> #include <QTextBrowser>
#include <QTextFragment>
class QTextTable; class QTextTable;
class QMouseEvent;
class ChatView : public QTextEdit { class ChatView : public QTextBrowser {
Q_OBJECT; Q_OBJECT;
private: private:
QTextTable *table; QTextTable *table;
QString ownName; QString ownName;
bool showTimestamps;
QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
QString getCardNameUnderMouse(QTextFragment frag) const;
QString getCardNameUnderMouse(const QPoint &pos) const;
private slots:
void openLink(const QUrl &link);
public: public:
ChatView(const QString &_ownName, QWidget *parent = 0); ChatView(const QString &_ownName, bool _showTimestamps, QWidget *parent = 0);
void appendMessage(QString sender, const QString &message); void appendMessage(QString sender, QString message);
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
signals:
void cardNameHovered(QString cardName);
void showCardInfoPopup(QPoint pos, QString cardName);
void deleteCardInfoPopup();
}; };
#endif #endif
\ No newline at end of file
...@@ -11,7 +11,7 @@ class LocalServer : public Server ...@@ -11,7 +11,7 @@ class LocalServer : public Server
public: public:
LocalServer(QObject *parent = 0); LocalServer(QObject *parent = 0);
~LocalServer(); ~LocalServer();
AuthenticationResult checkUserPassword(const QString & /*user*/, const QString & /*password*/) { return UnknownUser; } AuthenticationResult checkUserPassword(Server_ProtocolHandler * /*handler*/, const QString & /*user*/, const QString & /*password*/) { return UnknownUser; }
QString getLoginMessage() const { return QString(); } QString getLoginMessage() const { return QString(); }
bool getGameShouldPing() const { return false; } bool getGameShouldPing() const { return false; }
int getMaxGameInactivityTime() const { return 9999999; } int getMaxGameInactivityTime() const { return 9999999; }
......
This diff is collapsed.
#ifndef MESSAGELOGWIDGET_H #ifndef MESSAGELOGWIDGET_H
#define MESSAGELOGWIDGET_H #define MESSAGELOGWIDGET_H
#include <QTextEdit> #include "chatview.h"
#include <QAbstractSocket> #include <QAbstractSocket>
#include "translation.h" #include "translation.h"
#include "protocol_datastructures.h" #include "protocol_datastructures.h"
class Player; class Player;
class CardZone; class CardZone;
class QMouseEvent;
class QEvent;
class CardInfoWidget; class CardInfoWidget;
class GameEventContext; class GameEventContext;
class CardItem; class CardItem;
...@@ -24,16 +22,15 @@ struct LogMoveCard { ...@@ -24,16 +22,15 @@ struct LogMoveCard {
int newX; int newX;
}; };
class MessageLogWidget : public QTextEdit { class MessageLogWidget : public ChatView {
Q_OBJECT Q_OBJECT
private: private:
enum MessageContext { MessageContext_None, MessageContext_MoveCard, MessageContext_Mulligan }; enum MessageContext { MessageContext_None, MessageContext_MoveCard, MessageContext_Mulligan };
CardInfoWidget *infoWidget;
QString sanitizeHtml(QString dirty) const; QString sanitizeHtml(QString dirty) const;
void myAppend(const QString &message);
bool isFemale(Player *player) const; bool isFemale(Player *player) const;
QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position) const; QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position) const;
QString getCardNameUnderMouse(const QPoint &pos) const;
MessageContext currentContext; MessageContext currentContext;
QList<LogMoveCard> moveCardQueue; QList<LogMoveCard> moveCardQueue;
...@@ -42,10 +39,6 @@ private: ...@@ -42,10 +39,6 @@ private:
Player *mulliganPlayer; Player *mulliganPlayer;
int mulliganNumber; int mulliganNumber;
signals:
void cardNameHovered(QString cardName);
void showCardInfoPopup(QPoint pos, QString cardName);
void deleteCardInfoPopup();
public slots: public slots:
void logConnecting(QString hostname); void logConnecting(QString hostname);
void logConnected(); void logConnected();
...@@ -96,13 +89,7 @@ public slots: ...@@ -96,13 +89,7 @@ public slots:
void containerProcessingDone(); void containerProcessingDone();
public: public:
void connectToPlayer(Player *player); void connectToPlayer(Player *player);
MessageLogWidget(QWidget *parent = 0); MessageLogWidget(const QString &_ownName, QWidget *parent = 0);
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
}; };
#endif #endif
#include "tab.h"
#include "cardinfowidget.h"
#include <QDesktopWidget>
#include <QApplication>
Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent)
: QWidget(parent), tabMenu(0), tabSupervisor(_tabSupervisor), contentsChanged(false), infoPopup(0)
{
}
void Tab::showCardInfoPopup(const QPoint &pos, const QString &cardName)
{
infoPopup = new CardInfoWidget(CardInfoWidget::ModePopUp, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents);
infoPopup->setCard(cardName);
QRect screenRect = qApp->desktop()->screenGeometry(this);
infoPopup->move(
qMax(screenRect.left(), qMin(pos.x() - infoPopup->width() / 2, screenRect.left() + screenRect.width() - infoPopup->width())),
qMax(screenRect.top(), qMin(pos.y() - infoPopup->height() / 2, screenRect.top() + screenRect.height() - infoPopup->height()))
);
infoPopup->show();
}
void Tab::deleteCardInfoPopup()
{
if (infoPopup) {
infoPopup->deleteLater();
infoPopup = 0;
}
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
class QMenu; class QMenu;
class TabSupervisor; class TabSupervisor;
class CardInfoWidget;
class Tab : public QWidget { class Tab : public QWidget {
Q_OBJECT Q_OBJECT
...@@ -13,11 +14,14 @@ signals: ...@@ -13,11 +14,14 @@ signals:
protected: protected:
QMenu *tabMenu; QMenu *tabMenu;
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;
protected slots:
void showCardInfoPopup(const QPoint &pos, const QString &cardName);
void deleteCardInfoPopup();
private: private:
bool contentsChanged; bool contentsChanged;
CardInfoWidget *infoPopup;
public: public:
Tab(TabSupervisor *_tabSupervisor, QWidget *parent = 0) Tab(TabSupervisor *_tabSupervisor, QWidget *parent = 0);
: QWidget(parent), tabMenu(0), tabSupervisor(_tabSupervisor), contentsChanged(false) { }
QMenu *getTabMenu() const { return tabMenu; } QMenu *getTabMenu() const { return tabMenu; }
bool getContentsChanged() const { return contentsChanged; } bool getContentsChanged() const { return contentsChanged; }
void setContentsChanged(bool _contentsChanged) { contentsChanged = _contentsChanged; } void setContentsChanged(bool _contentsChanged) { contentsChanged = _contentsChanged; }
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include <QAction> #include <QAction>
#include <QMessageBox> #include <QMessageBox>
#include <QFileDialog> #include <QFileDialog>
#include <QApplication>
#include <QDesktopWidget>
#include "tab_game.h" #include "tab_game.h"
#include "cardinfowidget.h" #include "cardinfowidget.h"
#include "playerlistwidget.h" #include "playerlistwidget.h"
...@@ -160,8 +158,8 @@ void DeckViewContainer::setDeck(DeckList *deck) ...@@ -160,8 +158,8 @@ void DeckViewContainer::setDeck(DeckList *deck)
readyStartButton->setEnabled(true); readyStartButton->setEnabled(true);
} }
TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming) TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, const QString &_userName, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming)
: Tab(_tabSupervisor), clients(_clients), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1), infoPopup(0) : Tab(_tabSupervisor), clients(_clients), gameId(_gameId), gameDescription(_gameDescription), localPlayerId(_localPlayerId), spectator(_spectator), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), started(false), resuming(_resuming), currentPhase(-1)
{ {
phasesToolbar = new PhasesToolbar; phasesToolbar = new PhasesToolbar;
phasesToolbar->hide(); phasesToolbar->hide();
...@@ -178,7 +176,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client ...@@ -178,7 +176,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
timeElapsedLabel = new QLabel; timeElapsedLabel = new QLabel;
timeElapsedLabel->setAlignment(Qt::AlignCenter); timeElapsedLabel->setAlignment(Qt::AlignCenter);
messageLog = new MessageLogWidget; messageLog = new MessageLogWidget(_userName);
connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfo, SLOT(setCard(QString))); connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfo, SLOT(setCard(QString)));
connect(messageLog, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(messageLog, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
connect(messageLog, SIGNAL(deleteCardInfoPopup()), this, SLOT(deleteCardInfoPopup())); connect(messageLog, SIGNAL(deleteCardInfoPopup()), this, SLOT(deleteCardInfoPopup()));
...@@ -779,24 +777,3 @@ Player *TabGame::getActiveLocalPlayer() const ...@@ -779,24 +777,3 @@ Player *TabGame::getActiveLocalPlayer() const
return 0; return 0;
} }
void TabGame::showCardInfoPopup(const QPoint &pos, const QString &cardName)
{
infoPopup = new CardInfoWidget(CardInfoWidget::ModePopUp, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint);
infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents);
infoPopup->setCard(cardName);
QRect screenRect = qApp->desktop()->screenGeometry(this);
infoPopup->move(
qMax(screenRect.left(), qMin(pos.x() - infoPopup->width() / 2, screenRect.left() + screenRect.width() - infoPopup->width())),
qMax(screenRect.top(), qMin(pos.y() - infoPopup->height() / 2, screenRect.top() + screenRect.height() - infoPopup->height()))
);
infoPopup->show();
}
void TabGame::deleteCardInfoPopup()
{
if (infoPopup) {
infoPopup->deleteLater();
infoPopup = 0;
}
}
...@@ -100,7 +100,6 @@ private: ...@@ -100,7 +100,6 @@ private:
int activePlayer; int activePlayer;
QSplitter *splitter; QSplitter *splitter;
CardInfoWidget *infoPopup;
CardInfoWidget *cardInfo; CardInfoWidget *cardInfo;
PlayerListWidget *playerListWidget; PlayerListWidget *playerListWidget;
QLabel *timeElapsedLabel; QLabel *timeElapsedLabel;
...@@ -147,8 +146,6 @@ signals: ...@@ -147,8 +146,6 @@ signals:
void openMessageDialog(const QString &userName, bool focus); void openMessageDialog(const QString &userName, bool focus);
private slots: private slots:
void newCardAdded(AbstractCardItem *card); void newCardAdded(AbstractCardItem *card);
void showCardInfoPopup(const QPoint &pos, const QString &cardName);
void deleteCardInfoPopup();
void actConcede(); void actConcede();
void actLeaveGame(); void actLeaveGame();
...@@ -158,7 +155,7 @@ private slots: ...@@ -158,7 +155,7 @@ private slots:
void actNextPhase(); void actNextPhase();
void actNextTurn(); void actNextTurn();
public: public:
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming); TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, int _gameId, const QString &_gameDescription, int _localPlayerId, const QString &_userName, bool _spectator, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, bool _resuming);
~TabGame(); ~TabGame();
void retranslateUi(); void retranslateUi();
void closeRequest(); void closeRequest();
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName) TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName)
: Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true) : Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true)
{ {
chatView = new ChatView(_ownName); chatView = new ChatView(_ownName, true);
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
connect(chatView, SIGNAL(deleteCardInfoPopup()), this, SLOT(deleteCardInfoPopup()));
sayEdit = new QLineEdit; sayEdit = new QLineEdit;
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage())); connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(sendMessage()));
......
...@@ -137,7 +137,9 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q ...@@ -137,7 +137,9 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, const Q
userList = new UserList(tabSupervisor, client, UserList::RoomList); userList = new UserList(tabSupervisor, client, UserList::RoomList);
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool))); connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
chatView = new ChatView(ownName); chatView = new ChatView(ownName, true);
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
connect(chatView, SIGNAL(deleteCardInfoPopup()), this, SLOT(deleteCardInfoPopup()));
sayLabel = new QLabel; sayLabel = new QLabel;
sayEdit = new QLineEdit; sayEdit = new QLineEdit;
sayLabel->setBuddy(sayEdit); sayLabel->setBuddy(sayEdit);
......
...@@ -221,7 +221,7 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex) ...@@ -221,7 +221,7 @@ void TabSupervisor::addCloseButtonToTab(Tab *tab, int tabIndex)
void TabSupervisor::gameJoined(Event_GameJoined *event) void TabSupervisor::gameJoined(Event_GameJoined *event)
{ {
TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming()); TabGame *tab = new TabGame(this, QList<AbstractClient *>() << client, event->getGameId(), event->getGameDescription(), event->getPlayerId(), userName, event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool))); connect(tab, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
int tabIndex = myAddTab(tab); int tabIndex = myAddTab(tab);
...@@ -232,7 +232,7 @@ void TabSupervisor::gameJoined(Event_GameJoined *event) ...@@ -232,7 +232,7 @@ void TabSupervisor::gameJoined(Event_GameJoined *event)
void TabSupervisor::localGameJoined(Event_GameJoined *event) void TabSupervisor::localGameJoined(Event_GameJoined *event)
{ {
TabGame *tab = new TabGame(this, localClients, event->getGameId(), event->getGameDescription(), event->getPlayerId(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming()); TabGame *tab = new TabGame(this, localClients, event->getGameId(), event->getGameDescription(), event->getPlayerId(), QString(), event->getSpectator(), event->getSpectatorsCanTalk(), event->getSpectatorsSeeEverything(), event->getResuming());
connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *))); connect(tab, SIGNAL(gameClosing(TabGame *)), this, SLOT(gameLeft(TabGame *)));
int tabIndex = myAddTab(tab); int tabIndex = myAddTab(tab);
addCloseButtonToTab(tab, tabIndex); addCloseButtonToTab(tab, tabIndex);
......
...@@ -10,6 +10,53 @@ ...@@ -10,6 +10,53 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QMenu> #include <QMenu>
#include <QInputDialog> #include <QInputDialog>
#include <QLabel>
#include <QSpinBox>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QHBoxLayout>
BanDialog::BanDialog(QWidget *parent)
: QDialog(parent)
{
QLabel *durationLabel = new QLabel(tr("Please enter the duration of the ban (in minutes).\nEnter 0 for an indefinite ban."));
durationEdit = new QSpinBox;
durationEdit->setMinimum(0);
durationEdit->setValue(5);
QLabel *reasonLabel = new QLabel(tr("Please enter the reason for the ban.\nThis is only saved for moderators and cannot be seen by the banned person."));
reasonEdit = new QPlainTextEdit;
QPushButton *okButton = new QPushButton(tr("&OK"));
okButton->setAutoDefault(true);
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(okButton);
buttonLayout->addWidget(cancelButton);
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(durationLabel);
vbox->addWidget(durationEdit);
vbox->addWidget(reasonLabel);
vbox->addWidget(reasonEdit);
vbox->addLayout(buttonLayout);
setLayout(vbox);
setWindowTitle(tr("Ban user from server"));
}
int BanDialog::getMinutes() const
{
return durationEdit->value();
}
QString BanDialog::getReason() const
{
return reasonEdit->toPlainText();
}
UserListItemDelegate::UserListItemDelegate(QObject *const parent) UserListItemDelegate::UserListItemDelegate(QObject *const parent)
: QStyledItemDelegate(parent) : QStyledItemDelegate(parent)
...@@ -215,10 +262,9 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index) ...@@ -215,10 +262,9 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
else if (actionClicked == aRemoveFromIgnoreList) else if (actionClicked == aRemoveFromIgnoreList)
client->sendCommand(new Command_RemoveFromList("ignore", userName)); client->sendCommand(new Command_RemoveFromList("ignore", userName));
else if (actionClicked == aBan) { else if (actionClicked == aBan) {
bool ok; BanDialog dlg(this);
int minutes = QInputDialog::getInt(this, tr("Duration"), tr("Please enter the duration of the ban (in minutes).\nEnter 0 for an indefinite ban."), 0, 0, 2147483647, 10, &ok); if (dlg.exec())
if (ok) client->sendCommand(new Command_BanFromServer(userName, dlg.getMinutes(), dlg.getReason()));
client->sendCommand(new Command_BanFromServer(userName, minutes));
} }
delete menu; delete menu;
......
#ifndef USERLIST_H #ifndef USERLIST_H
#define USERLIST_H #define USERLIST_H
#include <QDialog>
#include <QGroupBox> #include <QGroupBox>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
...@@ -9,6 +10,19 @@ class QTreeWidget; ...@@ -9,6 +10,19 @@ class QTreeWidget;
class ServerInfo_User; class ServerInfo_User;
class AbstractClient; class AbstractClient;
class TabSupervisor; class TabSupervisor;
class QSpinBox;
class QPlainTextEdit;
class BanDialog : public QDialog {
Q_OBJECT
private:
QSpinBox *durationEdit;
QPlainTextEdit *reasonEdit;
public:
BanDialog(QWidget *parent = 0);
int getMinutes() const;
QString getReason() const;
};
class UserListItemDelegate : public QStyledItemDelegate { class UserListItemDelegate : public QStyledItemDelegate {
public: public:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment