context menu for a message sender's name in chat; also display the user level icon next to the name; minor consistency and type-safety changes
This commit is contained in:
parent
f9e0b6fe9e
commit
95cd293b9c
30 changed files with 283 additions and 195 deletions
|
@ -4,10 +4,18 @@
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include "chatview.h"
|
#include "chatview.h"
|
||||||
|
#include "user_level.h"
|
||||||
|
#include "user_context_menu.h"
|
||||||
|
#include "tab_supervisor.h"
|
||||||
|
#include "pixmapgenerator.h"
|
||||||
|
|
||||||
ChatView::ChatView(const QString &_ownName, bool _showTimestamps, QWidget *parent)
|
ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent)
|
||||||
: QTextBrowser(parent), evenNumber(true), ownName(_ownName), showTimestamps(_showTimestamps)
|
: QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game), evenNumber(true), showTimestamps(_showTimestamps), hoveredItemType(HoveredNothing)
|
||||||
{
|
{
|
||||||
|
userContextMenu = new UserContextMenu(tabSupervisor, this, game);
|
||||||
|
connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||||
|
|
||||||
|
viewport()->setCursor(Qt::IBeamCursor);
|
||||||
setReadOnly(true);
|
setReadOnly(true);
|
||||||
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
||||||
setOpenLinks(false);
|
setOpenLinks(false);
|
||||||
|
@ -40,7 +48,7 @@ void ChatView::appendHtml(const QString &html)
|
||||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::appendMessage(QString sender, QString message, QColor playerColor, bool playerBold)
|
void ChatView::appendMessage(QString message, QString sender, UserLevelFlags userLevel, bool playerBold)
|
||||||
{
|
{
|
||||||
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
bool atBottom = verticalScrollBar()->value() >= verticalScrollBar()->maximum();
|
||||||
bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
bool sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
||||||
|
@ -55,18 +63,22 @@ void ChatView::appendMessage(QString sender, QString message, QColor playerColor
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCharFormat senderFormat;
|
QTextCharFormat senderFormat;
|
||||||
if (sender == ownName) {
|
if (tabSupervisor && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
|
||||||
senderFormat.setFontWeight(QFont::Bold);
|
senderFormat.setFontWeight(QFont::Bold);
|
||||||
senderFormat.setForeground(Qt::red);
|
senderFormat.setForeground(Qt::red);
|
||||||
} else {
|
} else {
|
||||||
if (playerColor == QColor())
|
senderFormat.setForeground(Qt::blue);
|
||||||
senderFormat.setForeground(QColor(0, 0, 254));
|
|
||||||
else
|
|
||||||
senderFormat.setForeground(playerColor);
|
|
||||||
if (playerBold)
|
if (playerBold)
|
||||||
senderFormat.setFontWeight(QFont::Bold);
|
senderFormat.setFontWeight(QFont::Bold);
|
||||||
}
|
}
|
||||||
|
senderFormat.setAnchor(true);
|
||||||
|
senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
|
||||||
if (!sameSender) {
|
if (!sameSender) {
|
||||||
|
if (!sender.isEmpty()) {
|
||||||
|
const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
|
||||||
|
cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel));
|
||||||
|
cursor.insertText(" ");
|
||||||
|
}
|
||||||
cursor.setCharFormat(senderFormat);
|
cursor.setCharFormat(senderFormat);
|
||||||
if (!sender.isEmpty())
|
if (!sender.isEmpty())
|
||||||
sender.append(": ");
|
sender.append(": ");
|
||||||
|
@ -88,33 +100,41 @@ void ChatView::appendMessage(QString sender, QString message, QColor playerColor
|
||||||
|
|
||||||
if (message.startsWith("[card]")) {
|
if (message.startsWith("[card]")) {
|
||||||
message = message.mid(6);
|
message = message.mid(6);
|
||||||
QTextCharFormat tempFormat = messageFormat;
|
|
||||||
tempFormat.setForeground(Qt::blue);
|
|
||||||
cursor.setCharFormat(tempFormat);
|
|
||||||
int closeTagIndex = message.indexOf("[/card]");
|
int closeTagIndex = message.indexOf("[/card]");
|
||||||
cursor.insertText(message.left(closeTagIndex));
|
QString cardName = message.left(closeTagIndex);
|
||||||
cursor.setCharFormat(messageFormat);
|
|
||||||
if (closeTagIndex == -1)
|
if (closeTagIndex == -1)
|
||||||
message.clear();
|
message.clear();
|
||||||
else
|
else
|
||||||
message = message.mid(closeTagIndex + 7);
|
message = message.mid(closeTagIndex + 7);
|
||||||
|
|
||||||
|
QTextCharFormat tempFormat = messageFormat;
|
||||||
|
tempFormat.setForeground(Qt::blue);
|
||||||
|
tempFormat.setAnchor(true);
|
||||||
|
tempFormat.setAnchorHref("card://" + cardName);
|
||||||
|
|
||||||
|
cursor.setCharFormat(tempFormat);
|
||||||
|
cursor.insertText(cardName);
|
||||||
|
cursor.setCharFormat(messageFormat);
|
||||||
} else if (message.startsWith("[url]")) {
|
} else if (message.startsWith("[url]")) {
|
||||||
message = message.mid(5);
|
message = message.mid(5);
|
||||||
int closeTagIndex = message.indexOf("[/url]");
|
int closeTagIndex = message.indexOf("[/url]");
|
||||||
QString url = message.left(closeTagIndex);
|
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)
|
if (closeTagIndex == -1)
|
||||||
message.clear();
|
message.clear();
|
||||||
else
|
else
|
||||||
message = message.mid(closeTagIndex + 6);
|
message = message.mid(closeTagIndex + 6);
|
||||||
|
|
||||||
|
if (!url.contains("://"))
|
||||||
|
url.prepend("http://");
|
||||||
|
|
||||||
|
QTextCharFormat tempFormat = messageFormat;
|
||||||
|
tempFormat.setForeground(Qt::blue);
|
||||||
|
tempFormat.setAnchor(true);
|
||||||
|
tempFormat.setAnchorHref(url);
|
||||||
|
|
||||||
|
cursor.setCharFormat(tempFormat);
|
||||||
|
cursor.insertText(url);
|
||||||
|
cursor.setCharFormat(messageFormat);
|
||||||
} else
|
} else
|
||||||
from = 1;
|
from = 1;
|
||||||
}
|
}
|
||||||
|
@ -148,47 +168,61 @@ QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
|
||||||
return QTextFragment();
|
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)
|
void ChatView::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QTextFragment frag = getFragmentUnderMouse(event->pos());
|
QString anchorHref = getFragmentUnderMouse(event->pos()).charFormat().anchorHref();
|
||||||
QString cardName = getCardNameUnderMouse(frag);
|
if (!anchorHref.isEmpty()) {
|
||||||
if (!cardName.isEmpty()) {
|
const int delimiterIndex = anchorHref.indexOf("://");
|
||||||
viewport()->setCursor(Qt::PointingHandCursor);
|
if (delimiterIndex != -1) {
|
||||||
emit cardNameHovered(cardName);
|
const QString scheme = anchorHref.left(delimiterIndex);
|
||||||
} else if (frag.charFormat().isAnchor())
|
hoveredContent = anchorHref.mid(delimiterIndex + 3);
|
||||||
viewport()->setCursor(Qt::PointingHandCursor);
|
if (scheme == "card") {
|
||||||
else
|
hoveredItemType = HoveredCard;
|
||||||
|
emit cardNameHovered(hoveredContent);
|
||||||
|
} else if (scheme == "user")
|
||||||
|
hoveredItemType = HoveredUser;
|
||||||
|
else
|
||||||
|
hoveredItemType = HoveredUrl;
|
||||||
|
viewport()->setCursor(Qt::PointingHandCursor);
|
||||||
|
} else {
|
||||||
|
hoveredItemType = HoveredNothing;
|
||||||
|
viewport()->setCursor(Qt::IBeamCursor);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
hoveredItemType = HoveredNothing;
|
||||||
viewport()->setCursor(Qt::IBeamCursor);
|
viewport()->setCursor(Qt::IBeamCursor);
|
||||||
|
}
|
||||||
|
|
||||||
QTextBrowser::mouseMoveEvent(event);
|
QTextBrowser::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::mousePressEvent(QMouseEvent *event)
|
void ChatView::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton)) {
|
switch (hoveredItemType) {
|
||||||
QString cardName = getCardNameUnderMouse(event->pos());
|
case HoveredCard: {
|
||||||
if (!cardName.isEmpty())
|
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
||||||
emit showCardInfoPopup(event->globalPos(), cardName);
|
emit showCardInfoPopup(event->globalPos(), hoveredContent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case HoveredUser: {
|
||||||
|
if (event->button() == Qt::RightButton) {
|
||||||
|
const int delimiterIndex = hoveredContent.indexOf("_");
|
||||||
|
UserLevelFlags userLevel(hoveredContent.left(delimiterIndex).toInt());
|
||||||
|
const QString userName = hoveredContent.mid(delimiterIndex + 1);
|
||||||
|
|
||||||
|
userContextMenu->showContextMenu(event->globalPos(), userName, userLevel);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
QTextBrowser::mousePressEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextBrowser::mousePressEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatView::mouseReleaseEvent(QMouseEvent *event)
|
void ChatView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
if (hoveredItemType == HoveredCard && ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton)))
|
||||||
emit deleteCardInfoPopup(QString("_"));
|
emit deleteCardInfoPopup(QString("_"));
|
||||||
|
|
||||||
QTextBrowser::mouseReleaseEvent(event);
|
QTextBrowser::mouseReleaseEvent(event);
|
||||||
|
@ -196,5 +230,8 @@ void ChatView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
|
||||||
void ChatView::openLink(const QUrl &link)
|
void ChatView::openLink(const QUrl &link)
|
||||||
{
|
{
|
||||||
|
if ((link.scheme() == "card") || (link.scheme() == "user"))
|
||||||
|
return;
|
||||||
|
|
||||||
QDesktopServices::openUrl(link);
|
QDesktopServices::openUrl(link);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,35 @@
|
||||||
#include <QTextFragment>
|
#include <QTextFragment>
|
||||||
#include <QTextCursor>
|
#include <QTextCursor>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include "user_level.h"
|
||||||
|
|
||||||
class QTextTable;
|
class QTextTable;
|
||||||
class QMouseEvent;
|
class QMouseEvent;
|
||||||
|
class UserContextMenu;
|
||||||
|
class TabSupervisor;
|
||||||
|
class TabGame;
|
||||||
|
|
||||||
class ChatView : public QTextBrowser {
|
class ChatView : public QTextBrowser {
|
||||||
Q_OBJECT;
|
Q_OBJECT
|
||||||
|
protected:
|
||||||
|
const TabSupervisor * const tabSupervisor;
|
||||||
|
TabGame * const game;
|
||||||
private:
|
private:
|
||||||
|
enum HoveredItemType { HoveredNothing, HoveredUrl, HoveredCard, HoveredUser };
|
||||||
|
UserContextMenu *userContextMenu;
|
||||||
QString lastSender;
|
QString lastSender;
|
||||||
bool evenNumber;
|
bool evenNumber;
|
||||||
QString ownName;
|
|
||||||
bool showTimestamps;
|
bool showTimestamps;
|
||||||
|
HoveredItemType hoveredItemType;
|
||||||
|
QString hoveredContent;
|
||||||
QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
|
QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
|
||||||
QString getCardNameUnderMouse(QTextFragment frag) const;
|
|
||||||
QString getCardNameUnderMouse(const QPoint &pos) const;
|
|
||||||
QTextCursor prepareBlock(bool same = false);
|
QTextCursor prepareBlock(bool same = false);
|
||||||
private slots:
|
private slots:
|
||||||
void openLink(const QUrl &link);
|
void openLink(const QUrl &link);
|
||||||
public:
|
public:
|
||||||
ChatView(const QString &_ownName, bool _showTimestamps, QWidget *parent = 0);
|
ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent = 0);
|
||||||
void appendHtml(const QString &html);
|
void appendHtml(const QString &html);
|
||||||
void appendMessage(QString sender, QString message, QColor playerColor = QColor(), bool playerBold = false);
|
void appendMessage(QString message, QString sender = QString(), UserLevelFlags userLevel = UserLevelFlags(), bool playerBold = false);
|
||||||
protected:
|
protected:
|
||||||
void enterEvent(QEvent *event);
|
void enterEvent(QEvent *event);
|
||||||
void leaveEvent(QEvent *event);
|
void leaveEvent(QEvent *event);
|
||||||
|
@ -33,6 +41,7 @@ protected:
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
void mouseReleaseEvent(QMouseEvent *event);
|
||||||
signals:
|
signals:
|
||||||
|
void openMessageDialog(const QString &userName, bool focus);
|
||||||
void cardNameHovered(QString cardName);
|
void cardNameHovered(QString cardName);
|
||||||
void showCardInfoPopup(QPoint pos, QString cardName);
|
void showCardInfoPopup(QPoint pos, QString cardName);
|
||||||
void deleteCardInfoPopup(QString cardName);
|
void deleteCardInfoPopup(QString cardName);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "pb/serverinfo_game.pb.h"
|
#include "pb/serverinfo_game.pb.h"
|
||||||
#include "pb/response.pb.h"
|
#include "pb/response.pb.h"
|
||||||
|
|
||||||
GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
|
GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent)
|
||||||
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
|
: QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room)
|
||||||
{
|
{
|
||||||
gameListView = new QTreeView;
|
gameListView = new QTreeView;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define GAMESELECTOR_H
|
#define GAMESELECTOR_H
|
||||||
|
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
//#include "tab_room.h"
|
|
||||||
#include "gametypemap.h"
|
#include "gametypemap.h"
|
||||||
|
|
||||||
class QTreeView;
|
class QTreeView;
|
||||||
|
@ -28,7 +27,7 @@ signals:
|
||||||
void gameJoined(int gameId);
|
void gameJoined(int gameId);
|
||||||
private:
|
private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
TabSupervisor *tabSupervisor;
|
const TabSupervisor *tabSupervisor;
|
||||||
TabRoom *room;
|
TabRoom *room;
|
||||||
|
|
||||||
QTreeView *gameListView;
|
QTreeView *gameListView;
|
||||||
|
@ -36,7 +35,7 @@ private:
|
||||||
GamesProxyModel *gameListProxyModel;
|
GamesProxyModel *gameListProxyModel;
|
||||||
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
|
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
|
||||||
public:
|
public:
|
||||||
GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
|
GameSelector(AbstractClient *_client, const TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void processGameInfo(const ServerInfo_Game &info);
|
void processGameInfo(const ServerInfo_Game &info);
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "soundengine.h"
|
#include "soundengine.h"
|
||||||
|
#include "tab_supervisor.h"
|
||||||
#include "pb/serverinfo_user.pb.h"
|
#include "pb/serverinfo_user.pb.h"
|
||||||
#include "pb/context_move_card.pb.h"
|
#include "pb/context_move_card.pb.h"
|
||||||
#include "pb/context_mulligan.pb.h"
|
#include "pb/context_mulligan.pb.h"
|
||||||
|
@ -21,9 +22,14 @@ bool MessageLogWidget::isFemale(Player *player) const
|
||||||
return player->getUserInfo()->gender() == ServerInfo_User::Female;
|
return player->getUserInfo()->gender() == ServerInfo_User::Female;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MessageLogWidget::userIsFemale() const
|
||||||
|
{
|
||||||
|
return (tabSupervisor && tabSupervisor->getUserInfo()->gender() & ServerInfo_User::Female);
|
||||||
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logGameJoined(int gameId)
|
void MessageLogWidget::logGameJoined(int gameId)
|
||||||
{
|
{
|
||||||
if (female)
|
if (userIsFemale())
|
||||||
appendHtml(tr("You have joined game #%1.", "female").arg(gameId));
|
appendHtml(tr("You have joined game #%1.", "female").arg(gameId));
|
||||||
else
|
else
|
||||||
appendHtml(tr("You have joined game #%1.", "male").arg(gameId));
|
appendHtml(tr("You have joined game #%1.", "male").arg(gameId));
|
||||||
|
@ -31,7 +37,7 @@ void MessageLogWidget::logGameJoined(int gameId)
|
||||||
|
|
||||||
void MessageLogWidget::logReplayStarted(int gameId)
|
void MessageLogWidget::logReplayStarted(int gameId)
|
||||||
{
|
{
|
||||||
if (female)
|
if (userIsFemale())
|
||||||
appendHtml(tr("You are watching a replay of game #%1.", "female").arg(gameId));
|
appendHtml(tr("You are watching a replay of game #%1.", "female").arg(gameId));
|
||||||
else
|
else
|
||||||
appendHtml(tr("You are watching a replay of game #%1.", "male").arg(gameId));
|
appendHtml(tr("You are watching a replay of game #%1.", "male").arg(gameId));
|
||||||
|
@ -143,12 +149,12 @@ void MessageLogWidget::logConnectionStateChanged(Player *player, bool connection
|
||||||
|
|
||||||
void MessageLogWidget::logSay(Player *player, QString message)
|
void MessageLogWidget::logSay(Player *player, QString message)
|
||||||
{
|
{
|
||||||
appendMessage(player->getName(), message, QColor(), true);
|
appendMessage(message, player->getName(), UserLevelFlags(player->getUserInfo()->user_level()), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logSpectatorSay(QString spectatorName, QString message)
|
void MessageLogWidget::logSpectatorSay(QString spectatorName, UserLevelFlags spectatorUserLevel, QString message)
|
||||||
{
|
{
|
||||||
appendMessage(spectatorName, message, QColor(), false);
|
appendMessage(message, spectatorName, spectatorUserLevel, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logShuffle(Player *player, CardZone *zone)
|
void MessageLogWidget::logShuffle(Player *player, CardZone *zone)
|
||||||
|
@ -858,7 +864,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
|
||||||
connect(player, SIGNAL(logAlwaysRevealTopCard(Player *, CardZone *, bool)), this, SLOT(logAlwaysRevealTopCard(Player *, CardZone *, bool)));
|
connect(player, SIGNAL(logAlwaysRevealTopCard(Player *, CardZone *, bool)), this, SLOT(logAlwaysRevealTopCard(Player *, CardZone *, bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageLogWidget::MessageLogWidget(const QString &_ownName, bool _female, QWidget *parent)
|
MessageLogWidget::MessageLogWidget(const TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent)
|
||||||
: ChatView(_ownName, false, parent), female(_female)
|
: ChatView(_tabSupervisor, _game, false, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#define MESSAGELOGWIDGET_H
|
#define MESSAGELOGWIDGET_H
|
||||||
|
|
||||||
#include "chatview.h"
|
#include "chatview.h"
|
||||||
#include <QAbstractSocket>
|
|
||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
|
#include "user_level.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
|
@ -28,9 +28,9 @@ private:
|
||||||
|
|
||||||
QString sanitizeHtml(QString dirty) const;
|
QString sanitizeHtml(QString dirty) const;
|
||||||
bool isFemale(Player *player) const;
|
bool isFemale(Player *player) const;
|
||||||
|
bool userIsFemale() const;
|
||||||
QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange) const;
|
QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange) const;
|
||||||
MessageContext currentContext;
|
MessageContext currentContext;
|
||||||
bool female;
|
|
||||||
|
|
||||||
QList<LogMoveCard> moveCardQueue;
|
QList<LogMoveCard> moveCardQueue;
|
||||||
QMap<CardItem *, QString> moveCardPT;
|
QMap<CardItem *, QString> moveCardPT;
|
||||||
|
@ -55,7 +55,7 @@ public slots:
|
||||||
void logGameStart();
|
void logGameStart();
|
||||||
void logConnectionStateChanged(Player *player, bool connectionState);
|
void logConnectionStateChanged(Player *player, bool connectionState);
|
||||||
void logSay(Player *player, QString message);
|
void logSay(Player *player, QString message);
|
||||||
void logSpectatorSay(QString spectatorName, QString message);
|
void logSpectatorSay(QString spectatorName, UserLevelFlags spectatorUserLevel, QString message);
|
||||||
void logShuffle(Player *player, CardZone *zone);
|
void logShuffle(Player *player, CardZone *zone);
|
||||||
void logRollDie(Player *player, int sides, int roll);
|
void logRollDie(Player *player, int sides, int roll);
|
||||||
void logDrawCards(Player *player, int number);
|
void logDrawCards(Player *player, int number);
|
||||||
|
@ -85,7 +85,7 @@ public slots:
|
||||||
void containerProcessingDone();
|
void containerProcessingDone();
|
||||||
public:
|
public:
|
||||||
void connectToPlayer(Player *player);
|
void connectToPlayer(Player *player);
|
||||||
MessageLogWidget(const QString &_ownName, bool _female, QWidget *parent = 0);
|
MessageLogWidget(const TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -131,18 +131,18 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr
|
||||||
|
|
||||||
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
QMap<QString, QPixmap> CountryPixmapGenerator::pmCache;
|
||||||
|
|
||||||
QPixmap UserLevelPixmapGenerator::generatePixmap(int height, int userLevel)
|
QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel)
|
||||||
{
|
{
|
||||||
int key = height * 10000 + userLevel;
|
int key = height * 10000 + (int) userLevel;
|
||||||
if (pmCache.contains(key))
|
if (pmCache.contains(key))
|
||||||
return pmCache.value(key);
|
return pmCache.value(key);
|
||||||
|
|
||||||
QString levelString;
|
QString levelString;
|
||||||
if (userLevel & ServerInfo_User::IsAdmin)
|
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
||||||
levelString = "admin";
|
levelString = "admin";
|
||||||
else if (userLevel & ServerInfo_User::IsModerator)
|
else if (userLevel.testFlag(ServerInfo_User::IsModerator))
|
||||||
levelString = "moderator";
|
levelString = "moderator";
|
||||||
else if (userLevel &ServerInfo_User::IsRegistered)
|
else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||||
levelString = "registered";
|
levelString = "registered";
|
||||||
else
|
else
|
||||||
levelString = "normal";
|
levelString = "normal";
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
|
#include "user_level.h"
|
||||||
|
|
||||||
class PhasePixmapGenerator {
|
class PhasePixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<QString, QPixmap> pmCache;
|
static QMap<QString, QPixmap> pmCache;
|
||||||
|
@ -48,7 +50,7 @@ class UserLevelPixmapGenerator {
|
||||||
private:
|
private:
|
||||||
static QMap<int, QPixmap> pmCache;
|
static QMap<int, QPixmap> pmCache;
|
||||||
public:
|
public:
|
||||||
static QPixmap generatePixmap(int height, int userLevel);
|
static QPixmap generatePixmap(int height, UserLevelFlags userLevel);
|
||||||
static void clear() { pmCache.clear(); }
|
static void clear() { pmCache.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties
|
||||||
player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon()) : (prop.ready_start() ? readyIcon : notReadyIcon));
|
player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon()) : (prop.ready_start() ? readyIcon : notReadyIcon));
|
||||||
if (prop.has_user_info()) {
|
if (prop.has_user_info()) {
|
||||||
player->setData(3, Qt::UserRole, prop.user_info().user_level());
|
player->setData(3, Qt::UserRole, prop.user_info().user_level());
|
||||||
player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, prop.user_info().user_level())));
|
player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level()))));
|
||||||
player->setText(4, QString::fromStdString(prop.user_info().name()));
|
player->setText(4, QString::fromStdString(prop.user_info().name()));
|
||||||
const QString country = QString::fromStdString(prop.user_info().country());
|
const QString country = QString::fromStdString(prop.user_info().country());
|
||||||
if (!country.isEmpty())
|
if (!country.isEmpty())
|
||||||
|
@ -172,7 +172,7 @@ void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &ind
|
||||||
|
|
||||||
const QString &userName = index.sibling(index.row(), 4).data(Qt::UserRole).toString();
|
const QString &userName = index.sibling(index.row(), 4).data(Qt::UserRole).toString();
|
||||||
int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt();
|
int playerId = index.sibling(index.row(), 4).data(Qt::UserRole + 1).toInt();
|
||||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(index.sibling(index.row(), 3).data(Qt::UserRole).toInt());
|
UserLevelFlags userLevel(index.sibling(index.row(), 3).data(Qt::UserRole).toInt());
|
||||||
|
|
||||||
userContextMenu->showContextMenu(pos, userName, userLevel, playerId);
|
userContextMenu->showContextMenu(pos, userName, userLevel, playerId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
|
||||||
|
|
||||||
QPixmap tempPixmap;
|
QPixmap tempPixmap;
|
||||||
if (fullPixmap.isNull())
|
if (fullPixmap.isNull())
|
||||||
tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), info->user_level());
|
tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), UserLevelFlags(info->user_level()));
|
||||||
else
|
else
|
||||||
tempPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
tempPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "dlg_creategame.h"
|
#include "dlg_creategame.h"
|
||||||
#include "tab_game.h"
|
#include "tab_game.h"
|
||||||
|
@ -234,8 +235,8 @@ void DeckViewContainer::setDeck(DeckList *deck)
|
||||||
sideboardLockButton->setEnabled(true);
|
sideboardLockButton->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TabGame::TabGame(GameReplay *_replay)
|
TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
||||||
: Tab(0),
|
: Tab(_tabSupervisor),
|
||||||
hostId(-1),
|
hostId(-1),
|
||||||
localPlayerId(-1),
|
localPlayerId(-1),
|
||||||
spectator(true),
|
spectator(true),
|
||||||
|
@ -282,7 +283,7 @@ TabGame::TabGame(GameReplay *_replay)
|
||||||
|
|
||||||
timeElapsedLabel = new QLabel;
|
timeElapsedLabel = new QLabel;
|
||||||
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
||||||
messageLog = new MessageLogWidget(QString(), false);
|
messageLog = new MessageLogWidget(tabSupervisor, this);
|
||||||
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(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||||
|
@ -411,7 +412,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
|
||||||
|
|
||||||
timeElapsedLabel = new QLabel;
|
timeElapsedLabel = new QLabel;
|
||||||
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
||||||
messageLog = new MessageLogWidget(QString::fromStdString(tabSupervisor->getUserInfo()->name()), tabSupervisor->getUserInfo()->gender() == ServerInfo_User::Female);
|
messageLog = new MessageLogWidget(tabSupervisor, this);
|
||||||
|
connect(messageLog, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||||
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(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||||
|
@ -813,6 +815,17 @@ AbstractClient *TabGame::getClientForPlayer(int playerId) const
|
||||||
return clients.first();
|
return clients.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TabGame::getPlayerIdByName(const QString &playerName) const
|
||||||
|
{
|
||||||
|
QMapIterator<int, Player *> playerIterator(players);
|
||||||
|
while (playerIterator.hasNext()) {
|
||||||
|
const Player *const p = playerIterator.next().value();
|
||||||
|
if (p->getName() == playerName)
|
||||||
|
return p->getId();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void TabGame::sendGameCommand(PendingCommand *pend, int playerId)
|
void TabGame::sendGameCommand(PendingCommand *pend, int playerId)
|
||||||
{
|
{
|
||||||
getClientForPlayer(playerId)->sendCommand(pend);
|
getClientForPlayer(playerId)->sendCommand(pend);
|
||||||
|
@ -898,12 +911,13 @@ void TabGame::closeGame()
|
||||||
|
|
||||||
void TabGame::eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext & /*context*/)
|
void TabGame::eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
messageLog->logSpectatorSay(spectators.value(eventPlayerId), QString::fromStdString(event.message()));
|
const ServerInfo_User &userInfo = spectators.value(eventPlayerId);
|
||||||
|
messageLog->logSpectatorSay(QString::fromStdString(userInfo.name()), UserLevelFlags(userInfo.user_level()), QString::fromStdString(event.message()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::eventSpectatorLeave(const Event_Leave & /*event*/, int eventPlayerId, const GameEventContext & /*context*/)
|
void TabGame::eventSpectatorLeave(const Event_Leave & /*event*/, int eventPlayerId, const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
messageLog->logLeaveSpectator(spectators.value(eventPlayerId));
|
messageLog->logLeaveSpectator(QString::fromStdString(spectators.value(eventPlayerId).name()));
|
||||||
playerListWidget->removePlayer(eventPlayerId);
|
playerListWidget->removePlayer(eventPlayerId);
|
||||||
spectators.remove(eventPlayerId);
|
spectators.remove(eventPlayerId);
|
||||||
|
|
||||||
|
@ -919,7 +933,7 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*e
|
||||||
const int playerId = prop.player_id();
|
const int playerId = prop.player_id();
|
||||||
if (prop.spectator()) {
|
if (prop.spectator()) {
|
||||||
if (!spectators.contains(playerId)) {
|
if (!spectators.contains(playerId)) {
|
||||||
spectators.insert(playerId, QString::fromStdString(prop.user_info().name()));
|
spectators.insert(playerId, prop.user_info());
|
||||||
playerListWidget->addPlayer(prop);
|
playerListWidget->addPlayer(prop);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1024,7 +1038,7 @@ void TabGame::eventJoin(const Event_Join &event, int /*eventPlayerId*/, const Ga
|
||||||
if (players.contains(playerId))
|
if (players.contains(playerId))
|
||||||
return;
|
return;
|
||||||
if (playerInfo.spectator()) {
|
if (playerInfo.spectator()) {
|
||||||
spectators.insert(playerId, QString::fromStdString(playerInfo.user_info().name()));
|
spectators.insert(playerId, playerInfo.user_info());
|
||||||
messageLog->logJoinSpectator(QString::fromStdString(playerInfo.user_info().name()));
|
messageLog->logJoinSpectator(QString::fromStdString(playerInfo.user_info().name()));
|
||||||
} else {
|
} else {
|
||||||
Player *newPlayer = addPlayer(playerId, playerInfo.user_info());
|
Player *newPlayer = addPlayer(playerId, playerInfo.user_info());
|
||||||
|
|
|
@ -107,7 +107,7 @@ private:
|
||||||
int localPlayerId;
|
int localPlayerId;
|
||||||
bool spectator;
|
bool spectator;
|
||||||
QMap<int, Player *> players;
|
QMap<int, Player *> players;
|
||||||
QMap<int, QString> spectators;
|
QMap<int, ServerInfo_User> spectators;
|
||||||
bool gameStateKnown;
|
bool gameStateKnown;
|
||||||
bool resuming;
|
bool resuming;
|
||||||
QStringList phasesList;
|
QStringList phasesList;
|
||||||
|
@ -195,7 +195,7 @@ private slots:
|
||||||
void actNextTurn();
|
void actNextTurn();
|
||||||
public:
|
public:
|
||||||
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes);
|
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes);
|
||||||
TabGame(GameReplay *replay);
|
TabGame(TabSupervisor *_tabSupervisor, GameReplay *replay);
|
||||||
~TabGame();
|
~TabGame();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
|
@ -208,6 +208,7 @@ public:
|
||||||
bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
|
bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
|
||||||
Player *getActiveLocalPlayer() const;
|
Player *getActiveLocalPlayer() const;
|
||||||
AbstractClient *getClientForPlayer(int playerId) const;
|
AbstractClient *getClientForPlayer(int playerId) const;
|
||||||
|
int getPlayerIdByName(const QString &playerName) const;
|
||||||
|
|
||||||
void setActiveCard(CardItem *_card) { activeCard = _card; }
|
void setActiveCard(CardItem *_card) { activeCard = _card; }
|
||||||
CardItem *getActiveCard() const { return activeCard; }
|
CardItem *getActiveCard() const { return activeCard; }
|
||||||
|
|
|
@ -10,11 +10,12 @@
|
||||||
#include "pending_command.h"
|
#include "pending_command.h"
|
||||||
#include "pb/session_commands.pb.h"
|
#include "pb/session_commands.pb.h"
|
||||||
#include "pb/event_user_message.pb.h"
|
#include "pb/event_user_message.pb.h"
|
||||||
|
#include "pb/serverinfo_user.pb.h"
|
||||||
|
|
||||||
TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName)
|
TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &_ownUserInfo, const ServerInfo_User &_otherUserInfo)
|
||||||
: Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true)
|
: Tab(_tabSupervisor), client(_client), ownUserInfo(new ServerInfo_User(_ownUserInfo)), otherUserInfo(new ServerInfo_User(_otherUserInfo)), userOnline(true)
|
||||||
{
|
{
|
||||||
chatView = new ChatView(_ownName, true);
|
chatView = new ChatView(tabSupervisor, 0, true);
|
||||||
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
||||||
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||||
sayEdit = new QLineEdit;
|
sayEdit = new QLineEdit;
|
||||||
|
@ -37,6 +38,8 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, c
|
||||||
TabMessage::~TabMessage()
|
TabMessage::~TabMessage()
|
||||||
{
|
{
|
||||||
emit talkClosing(this);
|
emit talkClosing(this);
|
||||||
|
delete ownUserInfo;
|
||||||
|
delete otherUserInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabMessage::retranslateUi()
|
void TabMessage::retranslateUi()
|
||||||
|
@ -45,6 +48,16 @@ void TabMessage::retranslateUi()
|
||||||
aLeave->setText(tr("&Leave"));
|
aLeave->setText(tr("&Leave"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TabMessage::getUserName() const
|
||||||
|
{
|
||||||
|
return QString::fromStdString(otherUserInfo->name());
|
||||||
|
}
|
||||||
|
|
||||||
|
QString TabMessage::getTabText() const
|
||||||
|
{
|
||||||
|
return tr("Talking to %1").arg(QString::fromStdString(otherUserInfo->name()));
|
||||||
|
}
|
||||||
|
|
||||||
void TabMessage::closeRequest()
|
void TabMessage::closeRequest()
|
||||||
{
|
{
|
||||||
actLeave();
|
actLeave();
|
||||||
|
@ -56,7 +69,7 @@ void TabMessage::sendMessage()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Command_Message cmd;
|
Command_Message cmd;
|
||||||
cmd.set_user_name(userName.toStdString());
|
cmd.set_user_name(otherUserInfo->name());
|
||||||
cmd.set_message(sayEdit->text().toStdString());
|
cmd.set_message(sayEdit->text().toStdString());
|
||||||
|
|
||||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||||
|
@ -69,7 +82,7 @@ void TabMessage::sendMessage()
|
||||||
void TabMessage::messageSent(const Response &response)
|
void TabMessage::messageSent(const Response &response)
|
||||||
{
|
{
|
||||||
if (response.response_code() == Response::RespInIgnoreList)
|
if (response.response_code() == Response::RespInIgnoreList)
|
||||||
chatView->appendMessage(QString(), tr("This user is ignoring you."));
|
chatView->appendMessage(tr("This user is ignoring you."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabMessage::actLeave()
|
void TabMessage::actLeave()
|
||||||
|
@ -79,18 +92,20 @@ void TabMessage::actLeave()
|
||||||
|
|
||||||
void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
|
void TabMessage::processUserMessageEvent(const Event_UserMessage &event)
|
||||||
{
|
{
|
||||||
chatView->appendMessage(QString::fromStdString(event.sender_name()), QString::fromStdString(event.message()));
|
const UserLevelFlags userLevel(event.sender_name() == otherUserInfo->name() ? otherUserInfo->user_level() : ownUserInfo->user_level());
|
||||||
|
chatView->appendMessage(QString::fromStdString(event.message()), QString::fromStdString(event.sender_name()), userLevel);
|
||||||
emit userEvent();
|
emit userEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabMessage::processUserLeft()
|
void TabMessage::processUserLeft()
|
||||||
{
|
{
|
||||||
chatView->appendMessage(QString(), tr("%1 has left the server.").arg(userName));
|
chatView->appendMessage(tr("%1 has left the server.").arg(QString::fromStdString(otherUserInfo->name())));
|
||||||
userOnline = false;
|
userOnline = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabMessage::processUserJoined()
|
void TabMessage::processUserJoined(const ServerInfo_User &_userInfo)
|
||||||
{
|
{
|
||||||
chatView->appendMessage(QString(), tr("%1 has joined the server.").arg(userName));
|
chatView->appendMessage(tr("%1 has joined the server.").arg(QString::fromStdString(otherUserInfo->name())));
|
||||||
userOnline = true;
|
userOnline = true;
|
||||||
|
*otherUserInfo = _userInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,14 @@ class ChatView;
|
||||||
class QLineEdit;
|
class QLineEdit;
|
||||||
class Event_UserMessage;
|
class Event_UserMessage;
|
||||||
class Response;
|
class Response;
|
||||||
|
class ServerInfo_User;
|
||||||
|
|
||||||
class TabMessage : public Tab {
|
class TabMessage : public Tab {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
QString userName;
|
ServerInfo_User *ownUserInfo;
|
||||||
|
ServerInfo_User *otherUserInfo;
|
||||||
bool userOnline;
|
bool userOnline;
|
||||||
|
|
||||||
ChatView *chatView;
|
ChatView *chatView;
|
||||||
|
@ -27,16 +29,16 @@ private slots:
|
||||||
void actLeave();
|
void actLeave();
|
||||||
void messageSent(const Response &response);
|
void messageSent(const Response &response);
|
||||||
public:
|
public:
|
||||||
TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const QString &_ownName, const QString &_userName);
|
TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &_ownUserInfo, const ServerInfo_User &_otherUserInfo);
|
||||||
~TabMessage();
|
~TabMessage();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
QString getUserName() const { return userName; }
|
QString getUserName() const;
|
||||||
QString getTabText() const { return tr("Talking to %1").arg(userName); }
|
QString getTabText() const;
|
||||||
|
|
||||||
void processUserMessageEvent(const Event_UserMessage &event);
|
void processUserMessageEvent(const Event_UserMessage &event);
|
||||||
void processUserLeft();
|
void processUserLeft();
|
||||||
void processUserJoined();
|
void processUserJoined(const ServerInfo_User &_userInfo);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,7 +40,8 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
|
||||||
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(QString::fromStdString(ownUser->name()), true);
|
chatView = new ChatView(tabSupervisor, 0, true);
|
||||||
|
connect(chatView, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
|
||||||
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
||||||
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||||
sayLabel = new QLabel;
|
sayLabel = new QLabel;
|
||||||
|
@ -142,7 +143,7 @@ void TabRoom::sendMessage()
|
||||||
void TabRoom::sayFinished(const Response &response)
|
void TabRoom::sayFinished(const Response &response)
|
||||||
{
|
{
|
||||||
if (response.response_code() == Response::RespChatFlood)
|
if (response.response_code() == Response::RespChatFlood)
|
||||||
chatView->appendMessage(QString(), tr("You are flooding the chat. Please wait a couple of seconds."));
|
chatView->appendMessage(tr("You are flooding the chat. Please wait a couple of seconds."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabRoom::actLeaveRoom()
|
void TabRoom::actLeaveRoom()
|
||||||
|
@ -197,20 +198,13 @@ void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
|
||||||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(senderName))
|
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(senderName))
|
||||||
return;
|
return;
|
||||||
UserListTWI *twi = userList->getUsers().value(senderName);
|
UserListTWI *twi = userList->getUsers().value(senderName);
|
||||||
QColor senderColor;
|
UserLevelFlags userLevel;
|
||||||
if (twi && (senderName != QString::fromStdString(ownUser->name()))) {
|
if (twi) {
|
||||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(twi->getUserLevel());
|
userLevel = UserLevelFlags(twi->getUserInfo().user_level());
|
||||||
if (userLevel & ServerInfo_User::IsModerator)
|
if (settingsCache->getIgnoreUnregisteredUsers() && !userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||||
senderColor = Qt::darkMagenta;
|
return;
|
||||||
else if (userLevel & ServerInfo_User::IsRegistered)
|
|
||||||
senderColor = Qt::darkGreen;
|
|
||||||
else {
|
|
||||||
if (settingsCache->getIgnoreUnregisteredUsers())
|
|
||||||
return;
|
|
||||||
senderColor = QColor(0, 0, 254);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
chatView->appendMessage(QString::fromStdString(event.name()), QString::fromStdString(event.message()), senderColor);
|
chatView->appendMessage(QString::fromStdString(event.message()), senderName, userLevel);
|
||||||
emit userEvent(false);
|
emit userEvent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "tab_message.h"
|
#include "tab_message.h"
|
||||||
#include "tab_userlists.h"
|
#include "tab_userlists.h"
|
||||||
#include "pixmapgenerator.h"
|
#include "pixmapgenerator.h"
|
||||||
|
#include "userlist.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||||
|
|
||||||
tabUserLists = new TabUserLists(this, client, *userInfo);
|
tabUserLists = new TabUserLists(this, client, *userInfo);
|
||||||
connect(tabUserLists, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
|
connect(tabUserLists, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
|
||||||
connect(tabUserLists, SIGNAL(userJoined(const QString &)), this, SLOT(processUserJoined(const QString &)));
|
connect(tabUserLists, SIGNAL(userJoined(ServerInfo_User)), this, SLOT(processUserJoined(ServerInfo_User)));
|
||||||
connect(tabUserLists, SIGNAL(userLeft(const QString &)), this, SLOT(processUserLeft(const QString &)));
|
connect(tabUserLists, SIGNAL(userLeft(const QString &)), this, SLOT(processUserLeft(const QString &)));
|
||||||
myAddTab(tabUserLists);
|
myAddTab(tabUserLists);
|
||||||
|
|
||||||
|
@ -321,7 +322,7 @@ void TabSupervisor::roomLeft(TabRoom *tab)
|
||||||
|
|
||||||
void TabSupervisor::openReplay(GameReplay *replay)
|
void TabSupervisor::openReplay(GameReplay *replay)
|
||||||
{
|
{
|
||||||
TabGame *replayTab = new TabGame(replay);
|
TabGame *replayTab = new TabGame(this, replay);
|
||||||
connect(replayTab, SIGNAL(gameClosing(TabGame *)), this, SLOT(replayLeft(TabGame *)));
|
connect(replayTab, SIGNAL(gameClosing(TabGame *)), this, SLOT(replayLeft(TabGame *)));
|
||||||
int tabIndex = myAddTab(replayTab);
|
int tabIndex = myAddTab(replayTab);
|
||||||
addCloseButtonToTab(replayTab, tabIndex);
|
addCloseButtonToTab(replayTab, tabIndex);
|
||||||
|
@ -342,7 +343,13 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
|
||||||
if (receiverName == QString::fromStdString(userInfo->name()))
|
if (receiverName == QString::fromStdString(userInfo->name()))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
TabMessage *tab = new TabMessage(this, client, QString::fromStdString(userInfo->name()), receiverName);
|
ServerInfo_User otherUser;
|
||||||
|
UserListTWI *twi = tabUserLists->getAllUsersList()->getUsers().value(receiverName);
|
||||||
|
if (twi)
|
||||||
|
otherUser = twi->getUserInfo();
|
||||||
|
else
|
||||||
|
otherUser.set_name(receiverName.toStdString());
|
||||||
|
TabMessage *tab = new TabMessage(this, client, *userInfo, otherUser);
|
||||||
connect(tab, SIGNAL(talkClosing(TabMessage *)), this, SLOT(talkLeft(TabMessage *)));
|
connect(tab, SIGNAL(talkClosing(TabMessage *)), this, SLOT(talkLeft(TabMessage *)));
|
||||||
int tabIndex = myAddTab(tab);
|
int tabIndex = myAddTab(tab);
|
||||||
addCloseButtonToTab(tab, tabIndex);
|
addCloseButtonToTab(tab, tabIndex);
|
||||||
|
@ -407,11 +414,11 @@ void TabSupervisor::processUserLeft(const QString &userName)
|
||||||
tab->processUserLeft();
|
tab->processUserLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabSupervisor::processUserJoined(const QString &userName)
|
void TabSupervisor::processUserJoined(const ServerInfo_User &userInfo)
|
||||||
{
|
{
|
||||||
TabMessage *tab = messageTabs.value(userName);
|
TabMessage *tab = messageTabs.value(QString::fromStdString(userInfo.name()));
|
||||||
if (tab)
|
if (tab)
|
||||||
tab->processUserJoined();
|
tab->processUserJoined(userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabSupervisor::updateCurrent(int index)
|
void TabSupervisor::updateCurrent(int index)
|
||||||
|
|
|
@ -84,7 +84,7 @@ private slots:
|
||||||
void openReplay(GameReplay *replay);
|
void openReplay(GameReplay *replay);
|
||||||
void replayLeft(TabGame *tab);
|
void replayLeft(TabGame *tab);
|
||||||
void processUserLeft(const QString &userName);
|
void processUserLeft(const QString &userName);
|
||||||
void processUserJoined(const QString &userName);
|
void processUserJoined(const ServerInfo_User &userInfo);
|
||||||
void talkLeft(TabMessage *tab);
|
void talkLeft(TabMessage *tab);
|
||||||
void tabUserEvent(bool globalEvent);
|
void tabUserEvent(bool globalEvent);
|
||||||
void processRoomEvent(const RoomEvent &event);
|
void processRoomEvent(const RoomEvent &event);
|
||||||
|
|
|
@ -88,7 +88,7 @@ void TabUserLists::processUserJoinedEvent(const Event_UserJoined &event)
|
||||||
ignoreList->sortItems();
|
ignoreList->sortItems();
|
||||||
buddyList->sortItems();
|
buddyList->sortItems();
|
||||||
|
|
||||||
emit userJoined(userName);
|
emit userJoined(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
|
void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class TabUserLists : public Tab {
|
||||||
signals:
|
signals:
|
||||||
void openMessageDialog(const QString &userName, bool focus);
|
void openMessageDialog(const QString &userName, bool focus);
|
||||||
void userLeft(const QString &userName);
|
void userLeft(const QString &userName);
|
||||||
void userJoined(const QString &userName);
|
void userJoined(const ServerInfo_User &userInfo);
|
||||||
private slots:
|
private slots:
|
||||||
void processListUsersResponse(const Response &response);
|
void processListUsersResponse(const Response &response);
|
||||||
void processUserJoinedEvent(const Event_UserJoined &event);
|
void processUserJoinedEvent(const Event_UserJoined &event);
|
||||||
|
@ -40,8 +40,9 @@ public:
|
||||||
TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo, QWidget *parent = 0);
|
TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo, QWidget *parent = 0);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
QString getTabText() const { return tr("User lists"); }
|
QString getTabText() const { return tr("User lists"); }
|
||||||
UserList *getBuddyList() const { return buddyList; }
|
const UserList *getAllUsersList() const { return allUsersList; }
|
||||||
UserList *getIgnoreList() const { return ignoreList; }
|
const UserList *getBuddyList() const { return buddyList; }
|
||||||
|
const UserList *getIgnoreList() const { return ignoreList; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "pb/response_get_games_of_user.pb.h"
|
#include "pb/response_get_games_of_user.pb.h"
|
||||||
#include "pb/response_get_user_info.pb.h"
|
#include "pb/response_get_user_info.pb.h"
|
||||||
|
|
||||||
UserContextMenu::UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *parent, TabGame *_game)
|
UserContextMenu::UserContextMenu(const TabSupervisor *_tabSupervisor, QWidget *parent, TabGame *_game)
|
||||||
: QObject(parent), client(_tabSupervisor->getClient()), tabSupervisor(_tabSupervisor), game(_game)
|
: QObject(parent), client(_tabSupervisor->getClient()), tabSupervisor(_tabSupervisor), game(_game)
|
||||||
{
|
{
|
||||||
aUserName = new QAction(QString(), this);
|
aUserName = new QAction(QString(), this);
|
||||||
|
@ -87,7 +87,7 @@ void UserContextMenu::banUser_dialogFinished()
|
||||||
client->sendCommand(client->prepareModeratorCommand(cmd));
|
client->sendCommand(client->prepareModeratorCommand(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, ServerInfo_User::UserLevelFlags userLevel, int playerId)
|
void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, int playerId)
|
||||||
{
|
{
|
||||||
aUserName->setText(userName);
|
aUserName->setText(userName);
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
menu->addAction(aDetails);
|
menu->addAction(aDetails);
|
||||||
menu->addAction(aShowGames);
|
menu->addAction(aShowGames);
|
||||||
menu->addAction(aChat);
|
menu->addAction(aChat);
|
||||||
if ((userLevel & ServerInfo_User::IsRegistered) && (tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)) {
|
if (userLevel.testFlag(ServerInfo_User::IsRegistered) && (tabSupervisor->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)) {
|
||||||
menu->addSeparator();
|
menu->addSeparator();
|
||||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName))
|
if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName))
|
||||||
menu->addAction(aRemoveFromBuddyList);
|
menu->addAction(aRemoveFromBuddyList);
|
||||||
|
@ -167,7 +167,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
||||||
client->sendCommand(client->prepareSessionCommand(cmd));
|
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||||
} else if (actionClicked == aKick) {
|
} else if (actionClicked == aKick) {
|
||||||
Command_KickFromGame cmd;
|
Command_KickFromGame cmd;
|
||||||
cmd.set_player_id(playerId);
|
cmd.set_player_id(game->getPlayerIdByName(userName));
|
||||||
game->sendGameCommand(cmd);
|
game->sendGameCommand(cmd);
|
||||||
} else if (actionClicked == aBan) {
|
} else if (actionClicked == aBan) {
|
||||||
Command_GetUserInfo cmd;
|
Command_GetUserInfo cmd;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define USER_CONTEXT_MENU_H
|
#define USER_CONTEXT_MENU_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "pb/serverinfo_user.pb.h"
|
#include "user_level.h"
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class TabSupervisor;
|
class TabSupervisor;
|
||||||
|
@ -16,7 +16,7 @@ class UserContextMenu : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
AbstractClient *client;
|
AbstractClient *client;
|
||||||
TabSupervisor *tabSupervisor;
|
const TabSupervisor *tabSupervisor;
|
||||||
TabGame *game;
|
TabGame *game;
|
||||||
|
|
||||||
QAction *aUserName;
|
QAction *aUserName;
|
||||||
|
@ -34,8 +34,8 @@ private slots:
|
||||||
void banUser_dialogFinished();
|
void banUser_dialogFinished();
|
||||||
void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer);
|
void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer);
|
||||||
public:
|
public:
|
||||||
UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0);
|
UserContextMenu(const TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0);
|
||||||
void showContextMenu(const QPoint &pos, const QString &userName, ServerInfo_User::UserLevelFlags userLevel, int playerId = -1);
|
void showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, int playerId = -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,7 +56,7 @@ void UserInfoBox::retranslateUi()
|
||||||
|
|
||||||
void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||||
{
|
{
|
||||||
const int userLevel = user.user_level();
|
const UserLevelFlags userLevel(user.user_level());
|
||||||
|
|
||||||
QPixmap avatarPixmap;
|
QPixmap avatarPixmap;
|
||||||
const std::string bmp = user.avatar_bmp();
|
const std::string bmp = user.avatar_bmp();
|
||||||
|
@ -70,11 +70,11 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||||
countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, QString::fromStdString(user.country())));
|
countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, QString::fromStdString(user.country())));
|
||||||
userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
|
userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
|
||||||
QString userLevelText;
|
QString userLevelText;
|
||||||
if (userLevel & ServerInfo_User::IsAdmin)
|
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
||||||
userLevelText = tr("Administrator");
|
userLevelText = tr("Administrator");
|
||||||
else if (userLevel & ServerInfo_User::IsModerator)
|
else if (userLevel.testFlag(ServerInfo_User::IsModerator))
|
||||||
userLevelText = tr("Moderator");
|
userLevelText = tr("Moderator");
|
||||||
else if (userLevel & ServerInfo_User::IsRegistered)
|
else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||||
userLevelText = tr("Registered user");
|
userLevelText = tr("Registered user");
|
||||||
else
|
else
|
||||||
userLevelText = tr("Unregistered user");
|
userLevelText = tr("Unregistered user");
|
||||||
|
|
|
@ -170,19 +170,27 @@ bool UserListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserListTWI::UserListTWI()
|
UserListTWI::UserListTWI(const ServerInfo_User &_userInfo)
|
||||||
: QTreeWidgetItem(Type)
|
: QTreeWidgetItem(Type)
|
||||||
{
|
{
|
||||||
|
setUserInfo(_userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString UserListTWI::getUserName() const
|
void UserListTWI::setUserInfo(const ServerInfo_User &_userInfo)
|
||||||
{
|
{
|
||||||
return data(2, Qt::UserRole).toString();
|
userInfo = _userInfo;
|
||||||
|
|
||||||
|
setData(0, Qt::UserRole, userInfo.user_level());
|
||||||
|
setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(userInfo.user_level()))));
|
||||||
|
setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(userInfo.country()))));
|
||||||
|
setData(2, Qt::UserRole, QString::fromStdString(userInfo.name()));
|
||||||
|
setData(2, Qt::DisplayRole, QString::fromStdString(userInfo.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int UserListTWI::getUserLevel() const
|
void UserListTWI::setOnline(bool online)
|
||||||
{
|
{
|
||||||
return data(0, Qt::UserRole).toInt();
|
setData(0, Qt::UserRole + 1, online);
|
||||||
|
setData(2, Qt::ForegroundRole, online ? QBrush() : QBrush(Qt::gray));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UserListTWI::operator<(const QTreeWidgetItem &other) const
|
bool UserListTWI::operator<(const QTreeWidgetItem &other) const
|
||||||
|
@ -239,25 +247,17 @@ void UserList::processUserInfo(const ServerInfo_User &user, bool online)
|
||||||
{
|
{
|
||||||
const QString userName = QString::fromStdString(user.name());
|
const QString userName = QString::fromStdString(user.name());
|
||||||
UserListTWI *item = users.value(userName);
|
UserListTWI *item = users.value(userName);
|
||||||
if (!item) {
|
if (item)
|
||||||
item = new UserListTWI;
|
item->setUserInfo(user);
|
||||||
|
else {
|
||||||
|
item = new UserListTWI(user);
|
||||||
users.insert(userName, item);
|
users.insert(userName, item);
|
||||||
userTree->addTopLevelItem(item);
|
userTree->addTopLevelItem(item);
|
||||||
if (online)
|
if (online)
|
||||||
++onlineCount;
|
++onlineCount;
|
||||||
updateCount();
|
updateCount();
|
||||||
}
|
}
|
||||||
item->setData(0, Qt::UserRole, user.user_level());
|
item->setOnline(online);
|
||||||
item->setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, user.user_level())));
|
|
||||||
item->setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(user.country()))));
|
|
||||||
item->setData(2, Qt::UserRole, QString::fromStdString(user.name()));
|
|
||||||
item->setData(2, Qt::DisplayRole, QString::fromStdString(user.name()));
|
|
||||||
|
|
||||||
item->setData(0, Qt::UserRole + 1, online);
|
|
||||||
if (online)
|
|
||||||
item->setData(2, Qt::ForegroundRole, QBrush());
|
|
||||||
else
|
|
||||||
item->setData(2, Qt::ForegroundRole, QBrush(Qt::gray));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UserList::deleteUser(const QString &userName)
|
bool UserList::deleteUser(const QString &userName)
|
||||||
|
@ -276,25 +276,18 @@ bool UserList::deleteUser(const QString &userName)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserList::setUserOnline(QTreeWidgetItem *item, bool online)
|
|
||||||
{
|
|
||||||
item->setData(0, Qt::UserRole + 1, online);
|
|
||||||
|
|
||||||
if (online) {
|
|
||||||
item->setData(2, Qt::ForegroundRole, QBrush());
|
|
||||||
++onlineCount;
|
|
||||||
} else {
|
|
||||||
item->setData(2, Qt::ForegroundRole, QBrush(Qt::gray));
|
|
||||||
--onlineCount;
|
|
||||||
}
|
|
||||||
updateCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserList::setUserOnline(const QString &userName, bool online)
|
void UserList::setUserOnline(const QString &userName, bool online)
|
||||||
{
|
{
|
||||||
UserListTWI *twi = users.value(userName);
|
UserListTWI *twi = users.value(userName);
|
||||||
if (twi)
|
if (!twi)
|
||||||
setUserOnline(twi, online);
|
return;
|
||||||
|
|
||||||
|
twi->setOnline(online);
|
||||||
|
if (online)
|
||||||
|
++onlineCount;
|
||||||
|
else
|
||||||
|
--onlineCount;
|
||||||
|
updateCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserList::updateCount()
|
void UserList::updateCount()
|
||||||
|
@ -312,11 +305,9 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
|
||||||
|
|
||||||
void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||||
{
|
{
|
||||||
UserListTWI *twi = static_cast<UserListTWI *>(userTree->topLevelItem(index.row()));
|
const ServerInfo_User &userInfo = static_cast<UserListTWI *>(userTree->topLevelItem(index.row()))->getUserInfo();
|
||||||
const QString &userName = twi->getUserName();
|
|
||||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(twi->getUserLevel());
|
|
||||||
|
|
||||||
userContextMenu->showContextMenu(pos, userName, userLevel);
|
userContextMenu->showContextMenu(pos, QString::fromStdString(userInfo.name()), UserLevelFlags(userInfo.user_level()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserList::sortItems()
|
void UserList::sortItems()
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QTreeWidgetItem>
|
#include <QTreeWidgetItem>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
#include "user_level.h"
|
||||||
|
|
||||||
class QTreeWidget;
|
class QTreeWidget;
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
|
@ -47,10 +48,13 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserListTWI : public QTreeWidgetItem {
|
class UserListTWI : public QTreeWidgetItem {
|
||||||
|
private:
|
||||||
|
ServerInfo_User userInfo;
|
||||||
public:
|
public:
|
||||||
UserListTWI();
|
UserListTWI(const ServerInfo_User &_userInfo);
|
||||||
QString getUserName() const;
|
const ServerInfo_User &getUserInfo() const { return userInfo; }
|
||||||
int getUserLevel() const;
|
void setUserInfo(const ServerInfo_User &_userInfo);
|
||||||
|
void setOnline(bool online);
|
||||||
bool operator<(const QTreeWidgetItem &other) const;
|
bool operator<(const QTreeWidgetItem &other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,7 +73,6 @@ private:
|
||||||
int onlineCount;
|
int onlineCount;
|
||||||
QString titleStr;
|
QString titleStr;
|
||||||
void updateCount();
|
void updateCount();
|
||||||
void setUserOnline(QTreeWidgetItem *user, bool online);
|
|
||||||
private slots:
|
private slots:
|
||||||
void userClicked(QTreeWidgetItem *item, int column);
|
void userClicked(QTreeWidgetItem *item, int column);
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -176,7 +176,7 @@ void MainWindow::actWatchReplay()
|
||||||
GameReplay *replay = new GameReplay;
|
GameReplay *replay = new GameReplay;
|
||||||
replay->ParseFromArray(buf.data(), buf.size());
|
replay->ParseFromArray(buf.data(), buf.size());
|
||||||
|
|
||||||
TabGame *replayWatcher = new TabGame(replay);
|
TabGame *replayWatcher = new TabGame(0, replay);
|
||||||
replayWatcher->show();
|
replayWatcher->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
message ServerInfo_User {
|
message ServerInfo_User {
|
||||||
enum UserLevelFlags {
|
enum UserLevelFlag {
|
||||||
IsNothing = 0;
|
IsNothing = 0;
|
||||||
IsUser = 1;
|
IsUser = 1;
|
||||||
IsRegistered = 2;
|
IsRegistered = 2;
|
||||||
IsModerator = 4;
|
IsModerator = 4;
|
||||||
IsAdmin = 8;
|
IsAdmin = 8;
|
||||||
|
|
|
@ -387,7 +387,7 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface, Respons
|
||||||
newPlayer->moveToThread(thread());
|
newPlayer->moveToThread(thread());
|
||||||
|
|
||||||
Event_Join joinEvent;
|
Event_Join joinEvent;
|
||||||
joinEvent.mutable_player_properties()->CopyFrom(newPlayer->getProperties(true));
|
newPlayer->getProperties(*joinEvent.mutable_player_properties(), true);
|
||||||
sendGameEventContainer(prepareGameEvent(joinEvent, -1));
|
sendGameEventContainer(prepareGameEvent(joinEvent, -1));
|
||||||
|
|
||||||
const QString playerName = QString::fromStdString(newPlayer->getUserInfo()->name());
|
const QString playerName = QString::fromStdString(newPlayer->getUserInfo()->name());
|
||||||
|
|
|
@ -240,9 +240,8 @@ void Server_Player::clearZones()
|
||||||
lastDrawList.clear();
|
lastDrawList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_PlayerProperties Server_Player::getProperties(bool withUserInfo)
|
void Server_Player::getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo)
|
||||||
{
|
{
|
||||||
ServerInfo_PlayerProperties result;
|
|
||||||
result.set_player_id(playerId);
|
result.set_player_id(playerId);
|
||||||
if (withUserInfo)
|
if (withUserInfo)
|
||||||
result.mutable_user_info()->CopyFrom(*userInfo);
|
result.mutable_user_info()->CopyFrom(*userInfo);
|
||||||
|
@ -253,8 +252,6 @@ ServerInfo_PlayerProperties Server_Player::getProperties(bool withUserInfo)
|
||||||
if (deck)
|
if (deck)
|
||||||
result.set_deck_hash(deck->getDeckHash().toStdString());
|
result.set_deck_hash(deck->getDeckHash().toStdString());
|
||||||
result.set_ping_seconds(pingTime);
|
result.set_ping_seconds(pingTime);
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Player::addZone(Server_CardZone *zone)
|
void Server_Player::addZone(Server_CardZone *zone)
|
||||||
|
@ -1668,7 +1665,7 @@ void Server_Player::disconnectClient()
|
||||||
|
|
||||||
void Server_Player::getInfo(ServerInfo_Player *info, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo)
|
void Server_Player::getInfo(ServerInfo_Player *info, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo)
|
||||||
{
|
{
|
||||||
info->mutable_properties()->CopyFrom(getProperties(withUserInfo));
|
getProperties(*info->mutable_properties(), withUserInfo);
|
||||||
if (playerWhosAsking == this)
|
if (playerWhosAsking == this)
|
||||||
if (deck)
|
if (deck)
|
||||||
info->set_deck_list(deck->writeToString_Native().toStdString());
|
info->set_deck_list(deck->writeToString_Native().toStdString());
|
||||||
|
|
|
@ -105,7 +105,7 @@ public:
|
||||||
|
|
||||||
int getPingTime() const { return pingTime; }
|
int getPingTime() const { return pingTime; }
|
||||||
void setPingTime(int _pingTime) { pingTime = _pingTime; }
|
void setPingTime(int _pingTime) { pingTime = _pingTime; }
|
||||||
ServerInfo_PlayerProperties getProperties(bool withUserInfo);
|
void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
|
||||||
|
|
||||||
int newCardId();
|
int newCardId();
|
||||||
int newCounterId() const;
|
int newCounterId() const;
|
||||||
|
|
10
common/user_level.h
Normal file
10
common/user_level.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef USER_LEVEL_H
|
||||||
|
#define USER_LEVEL_H
|
||||||
|
|
||||||
|
#include "pb/serverinfo_user.pb.h"
|
||||||
|
#include <QFlags>
|
||||||
|
|
||||||
|
Q_DECLARE_FLAGS(UserLevelFlags, ServerInfo_User::UserLevelFlag)
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(UserLevelFlags)
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue