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 <QDesktopServices>
|
||||
#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)
|
||||
: QTextBrowser(parent), evenNumber(true), ownName(_ownName), showTimestamps(_showTimestamps)
|
||||
ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent)
|
||||
: 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);
|
||||
setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
||||
setOpenLinks(false);
|
||||
|
@ -40,7 +48,7 @@ void ChatView::appendHtml(const QString &html)
|
|||
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 sameSender = (sender == lastSender) && !lastSender.isEmpty();
|
||||
|
@ -55,18 +63,22 @@ void ChatView::appendMessage(QString sender, QString message, QColor playerColor
|
|||
}
|
||||
|
||||
QTextCharFormat senderFormat;
|
||||
if (sender == ownName) {
|
||||
if (tabSupervisor && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
|
||||
senderFormat.setFontWeight(QFont::Bold);
|
||||
senderFormat.setForeground(Qt::red);
|
||||
} else {
|
||||
if (playerColor == QColor())
|
||||
senderFormat.setForeground(QColor(0, 0, 254));
|
||||
else
|
||||
senderFormat.setForeground(playerColor);
|
||||
senderFormat.setForeground(Qt::blue);
|
||||
if (playerBold)
|
||||
senderFormat.setFontWeight(QFont::Bold);
|
||||
}
|
||||
senderFormat.setAnchor(true);
|
||||
senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
|
||||
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);
|
||||
if (!sender.isEmpty())
|
||||
sender.append(": ");
|
||||
|
@ -88,33 +100,41 @@ void ChatView::appendMessage(QString sender, QString message, QColor playerColor
|
|||
|
||||
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);
|
||||
QString cardName = message.left(closeTagIndex);
|
||||
if (closeTagIndex == -1)
|
||||
message.clear();
|
||||
else
|
||||
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]")) {
|
||||
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);
|
||||
|
||||
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
|
||||
from = 1;
|
||||
}
|
||||
|
@ -148,47 +168,61 @@ QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
|
|||
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
|
||||
QString anchorHref = getFragmentUnderMouse(event->pos()).charFormat().anchorHref();
|
||||
if (!anchorHref.isEmpty()) {
|
||||
const int delimiterIndex = anchorHref.indexOf("://");
|
||||
if (delimiterIndex != -1) {
|
||||
const QString scheme = anchorHref.left(delimiterIndex);
|
||||
hoveredContent = anchorHref.mid(delimiterIndex + 3);
|
||||
if (scheme == "card") {
|
||||
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);
|
||||
}
|
||||
|
||||
QTextBrowser::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void ChatView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton)) {
|
||||
QString cardName = getCardNameUnderMouse(event->pos());
|
||||
if (!cardName.isEmpty())
|
||||
emit showCardInfoPopup(event->globalPos(), cardName);
|
||||
}
|
||||
switch (hoveredItemType) {
|
||||
case HoveredCard: {
|
||||
if ((event->button() == Qt::MidButton) || (event->button() == Qt::LeftButton))
|
||||
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);
|
||||
|
||||
QTextBrowser::mousePressEvent(event);
|
||||
userContextMenu->showContextMenu(event->globalPos(), userName, userLevel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
QTextBrowser::mousePressEvent(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("_"));
|
||||
|
||||
QTextBrowser::mouseReleaseEvent(event);
|
||||
|
@ -196,5 +230,8 @@ void ChatView::mouseReleaseEvent(QMouseEvent *event)
|
|||
|
||||
void ChatView::openLink(const QUrl &link)
|
||||
{
|
||||
if ((link.scheme() == "card") || (link.scheme() == "user"))
|
||||
return;
|
||||
|
||||
QDesktopServices::openUrl(link);
|
||||
}
|
||||
|
|
|
@ -5,27 +5,35 @@
|
|||
#include <QTextFragment>
|
||||
#include <QTextCursor>
|
||||
#include <QColor>
|
||||
#include "user_level.h"
|
||||
|
||||
class QTextTable;
|
||||
class QMouseEvent;
|
||||
class UserContextMenu;
|
||||
class TabSupervisor;
|
||||
class TabGame;
|
||||
|
||||
class ChatView : public QTextBrowser {
|
||||
Q_OBJECT;
|
||||
Q_OBJECT
|
||||
protected:
|
||||
const TabSupervisor * const tabSupervisor;
|
||||
TabGame * const game;
|
||||
private:
|
||||
enum HoveredItemType { HoveredNothing, HoveredUrl, HoveredCard, HoveredUser };
|
||||
UserContextMenu *userContextMenu;
|
||||
QString lastSender;
|
||||
bool evenNumber;
|
||||
QString ownName;
|
||||
bool showTimestamps;
|
||||
HoveredItemType hoveredItemType;
|
||||
QString hoveredContent;
|
||||
QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
|
||||
QString getCardNameUnderMouse(QTextFragment frag) const;
|
||||
QString getCardNameUnderMouse(const QPoint &pos) const;
|
||||
QTextCursor prepareBlock(bool same = false);
|
||||
private slots:
|
||||
void openLink(const QUrl &link);
|
||||
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 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:
|
||||
void enterEvent(QEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
|
@ -33,6 +41,7 @@ protected:
|
|||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
signals:
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
void cardNameHovered(QString cardName);
|
||||
void showCardInfoPopup(QPoint pos, QString cardName);
|
||||
void deleteCardInfoPopup(QString cardName);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "pb/serverinfo_game.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)
|
||||
{
|
||||
gameListView = new QTreeView;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define GAMESELECTOR_H
|
||||
|
||||
#include <QGroupBox>
|
||||
//#include "tab_room.h"
|
||||
#include "gametypemap.h"
|
||||
|
||||
class QTreeView;
|
||||
|
@ -28,7 +27,7 @@ signals:
|
|||
void gameJoined(int gameId);
|
||||
private:
|
||||
AbstractClient *client;
|
||||
TabSupervisor *tabSupervisor;
|
||||
const TabSupervisor *tabSupervisor;
|
||||
TabRoom *room;
|
||||
|
||||
QTreeView *gameListView;
|
||||
|
@ -36,7 +35,7 @@ private:
|
|||
GamesProxyModel *gameListProxyModel;
|
||||
QPushButton *filterButton, *clearFilterButton, *createButton, *joinButton, *spectateButton;
|
||||
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 processGameInfo(const ServerInfo_Game &info);
|
||||
};
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "cardzone.h"
|
||||
#include "carditem.h"
|
||||
#include "soundengine.h"
|
||||
#include "tab_supervisor.h"
|
||||
#include "pb/serverinfo_user.pb.h"
|
||||
#include "pb/context_move_card.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;
|
||||
}
|
||||
|
||||
bool MessageLogWidget::userIsFemale() const
|
||||
{
|
||||
return (tabSupervisor && tabSupervisor->getUserInfo()->gender() & ServerInfo_User::Female);
|
||||
}
|
||||
|
||||
void MessageLogWidget::logGameJoined(int gameId)
|
||||
{
|
||||
if (female)
|
||||
if (userIsFemale())
|
||||
appendHtml(tr("You have joined game #%1.", "female").arg(gameId));
|
||||
else
|
||||
appendHtml(tr("You have joined game #%1.", "male").arg(gameId));
|
||||
|
@ -31,7 +37,7 @@ void MessageLogWidget::logGameJoined(int gameId)
|
|||
|
||||
void MessageLogWidget::logReplayStarted(int gameId)
|
||||
{
|
||||
if (female)
|
||||
if (userIsFemale())
|
||||
appendHtml(tr("You are watching a replay of game #%1.", "female").arg(gameId));
|
||||
else
|
||||
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)
|
||||
{
|
||||
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)
|
||||
|
@ -858,7 +864,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
|
|||
connect(player, SIGNAL(logAlwaysRevealTopCard(Player *, CardZone *, bool)), this, SLOT(logAlwaysRevealTopCard(Player *, CardZone *, bool)));
|
||||
}
|
||||
|
||||
MessageLogWidget::MessageLogWidget(const QString &_ownName, bool _female, QWidget *parent)
|
||||
: ChatView(_ownName, false, parent), female(_female)
|
||||
MessageLogWidget::MessageLogWidget(const TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent)
|
||||
: ChatView(_tabSupervisor, _game, false, parent)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define MESSAGELOGWIDGET_H
|
||||
|
||||
#include "chatview.h"
|
||||
#include <QAbstractSocket>
|
||||
#include "translation.h"
|
||||
#include "user_level.h"
|
||||
|
||||
class Player;
|
||||
class CardZone;
|
||||
|
@ -28,9 +28,9 @@ private:
|
|||
|
||||
QString sanitizeHtml(QString dirty) const;
|
||||
bool isFemale(Player *player) const;
|
||||
bool userIsFemale() const;
|
||||
QPair<QString, QString> getFromStr(CardZone *zone, QString cardName, int position, bool ownerChange) const;
|
||||
MessageContext currentContext;
|
||||
bool female;
|
||||
|
||||
QList<LogMoveCard> moveCardQueue;
|
||||
QMap<CardItem *, QString> moveCardPT;
|
||||
|
@ -55,7 +55,7 @@ public slots:
|
|||
void logGameStart();
|
||||
void logConnectionStateChanged(Player *player, bool connectionState);
|
||||
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 logRollDie(Player *player, int sides, int roll);
|
||||
void logDrawCards(Player *player, int number);
|
||||
|
@ -85,7 +85,7 @@ public slots:
|
|||
void containerProcessingDone();
|
||||
public:
|
||||
void connectToPlayer(Player *player);
|
||||
MessageLogWidget(const QString &_ownName, bool _female, QWidget *parent = 0);
|
||||
MessageLogWidget(const TabSupervisor *_tabSupervisor, TabGame *_game, QWidget *parent = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -131,18 +131,18 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr
|
|||
|
||||
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))
|
||||
return pmCache.value(key);
|
||||
|
||||
QString levelString;
|
||||
if (userLevel & ServerInfo_User::IsAdmin)
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
||||
levelString = "admin";
|
||||
else if (userLevel & ServerInfo_User::IsModerator)
|
||||
else if (userLevel.testFlag(ServerInfo_User::IsModerator))
|
||||
levelString = "moderator";
|
||||
else if (userLevel &ServerInfo_User::IsRegistered)
|
||||
else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||
levelString = "registered";
|
||||
else
|
||||
levelString = "normal";
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QPixmap>
|
||||
#include <QMap>
|
||||
|
||||
#include "user_level.h"
|
||||
|
||||
class PhasePixmapGenerator {
|
||||
private:
|
||||
static QMap<QString, QPixmap> pmCache;
|
||||
|
@ -48,7 +50,7 @@ class UserLevelPixmapGenerator {
|
|||
private:
|
||||
static QMap<int, QPixmap> pmCache;
|
||||
public:
|
||||
static QPixmap generatePixmap(int height, int userLevel);
|
||||
static QPixmap generatePixmap(int height, UserLevelFlags userLevel);
|
||||
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));
|
||||
if (prop.has_user_info()) {
|
||||
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()));
|
||||
const QString country = QString::fromStdString(prop.user_info().country());
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
|
|||
|
||||
QPixmap tempPixmap;
|
||||
if (fullPixmap.isNull())
|
||||
tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), info->user_level());
|
||||
tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), UserLevelFlags(info->user_level()));
|
||||
else
|
||||
tempPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QFileDialog>
|
||||
#include <QTimer>
|
||||
#include <QToolButton>
|
||||
#include <QDebug>
|
||||
|
||||
#include "dlg_creategame.h"
|
||||
#include "tab_game.h"
|
||||
|
@ -234,8 +235,8 @@ void DeckViewContainer::setDeck(DeckList *deck)
|
|||
sideboardLockButton->setEnabled(true);
|
||||
}
|
||||
|
||||
TabGame::TabGame(GameReplay *_replay)
|
||||
: Tab(0),
|
||||
TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
||||
: Tab(_tabSupervisor),
|
||||
hostId(-1),
|
||||
localPlayerId(-1),
|
||||
spectator(true),
|
||||
|
@ -282,7 +283,7 @@ TabGame::TabGame(GameReplay *_replay)
|
|||
|
||||
timeElapsedLabel = new QLabel;
|
||||
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(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, 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->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(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
|
||||
connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||
|
@ -813,6 +815,17 @@ AbstractClient *TabGame::getClientForPlayer(int playerId) const
|
|||
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)
|
||||
{
|
||||
getClientForPlayer(playerId)->sendCommand(pend);
|
||||
|
@ -898,12 +911,13 @@ void TabGame::closeGame()
|
|||
|
||||
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*/)
|
||||
{
|
||||
messageLog->logLeaveSpectator(spectators.value(eventPlayerId));
|
||||
messageLog->logLeaveSpectator(QString::fromStdString(spectators.value(eventPlayerId).name()));
|
||||
playerListWidget->removePlayer(eventPlayerId);
|
||||
spectators.remove(eventPlayerId);
|
||||
|
||||
|
@ -919,7 +933,7 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event, int /*e
|
|||
const int playerId = prop.player_id();
|
||||
if (prop.spectator()) {
|
||||
if (!spectators.contains(playerId)) {
|
||||
spectators.insert(playerId, QString::fromStdString(prop.user_info().name()));
|
||||
spectators.insert(playerId, prop.user_info());
|
||||
playerListWidget->addPlayer(prop);
|
||||
}
|
||||
} else {
|
||||
|
@ -1024,7 +1038,7 @@ void TabGame::eventJoin(const Event_Join &event, int /*eventPlayerId*/, const Ga
|
|||
if (players.contains(playerId))
|
||||
return;
|
||||
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()));
|
||||
} else {
|
||||
Player *newPlayer = addPlayer(playerId, playerInfo.user_info());
|
||||
|
|
|
@ -107,7 +107,7 @@ private:
|
|||
int localPlayerId;
|
||||
bool spectator;
|
||||
QMap<int, Player *> players;
|
||||
QMap<int, QString> spectators;
|
||||
QMap<int, ServerInfo_User> spectators;
|
||||
bool gameStateKnown;
|
||||
bool resuming;
|
||||
QStringList phasesList;
|
||||
|
@ -195,7 +195,7 @@ private slots:
|
|||
void actNextTurn();
|
||||
public:
|
||||
TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes);
|
||||
TabGame(GameReplay *replay);
|
||||
TabGame(TabSupervisor *_tabSupervisor, GameReplay *replay);
|
||||
~TabGame();
|
||||
void retranslateUi();
|
||||
void closeRequest();
|
||||
|
@ -208,6 +208,7 @@ public:
|
|||
bool getSpectatorsSeeEverything() const { return gameInfo.spectators_omniscient(); }
|
||||
Player *getActiveLocalPlayer() const;
|
||||
AbstractClient *getClientForPlayer(int playerId) const;
|
||||
int getPlayerIdByName(const QString &playerName) const;
|
||||
|
||||
void setActiveCard(CardItem *_card) { activeCard = _card; }
|
||||
CardItem *getActiveCard() const { return activeCard; }
|
||||
|
|
|
@ -10,11 +10,12 @@
|
|||
#include "pending_command.h"
|
||||
#include "pb/session_commands.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)
|
||||
: Tab(_tabSupervisor), client(_client), userName(_userName), userOnline(true)
|
||||
TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &_ownUserInfo, const ServerInfo_User &_otherUserInfo)
|
||||
: 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(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||
sayEdit = new QLineEdit;
|
||||
|
@ -37,6 +38,8 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor, AbstractClient *_client, c
|
|||
TabMessage::~TabMessage()
|
||||
{
|
||||
emit talkClosing(this);
|
||||
delete ownUserInfo;
|
||||
delete otherUserInfo;
|
||||
}
|
||||
|
||||
void TabMessage::retranslateUi()
|
||||
|
@ -45,6 +48,16 @@ void TabMessage::retranslateUi()
|
|||
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()
|
||||
{
|
||||
actLeave();
|
||||
|
@ -56,7 +69,7 @@ void TabMessage::sendMessage()
|
|||
return;
|
||||
|
||||
Command_Message cmd;
|
||||
cmd.set_user_name(userName.toStdString());
|
||||
cmd.set_user_name(otherUserInfo->name());
|
||||
cmd.set_message(sayEdit->text().toStdString());
|
||||
|
||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||
|
@ -69,7 +82,7 @@ void TabMessage::sendMessage()
|
|||
void TabMessage::messageSent(const Response &response)
|
||||
{
|
||||
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()
|
||||
|
@ -79,18 +92,20 @@ void TabMessage::actLeave()
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
*otherUserInfo = _userInfo;
|
||||
}
|
||||
|
|
|
@ -8,12 +8,14 @@ class ChatView;
|
|||
class QLineEdit;
|
||||
class Event_UserMessage;
|
||||
class Response;
|
||||
class ServerInfo_User;
|
||||
|
||||
class TabMessage : public Tab {
|
||||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
QString userName;
|
||||
ServerInfo_User *ownUserInfo;
|
||||
ServerInfo_User *otherUserInfo;
|
||||
bool userOnline;
|
||||
|
||||
ChatView *chatView;
|
||||
|
@ -27,16 +29,16 @@ private slots:
|
|||
void actLeave();
|
||||
void messageSent(const Response &response);
|
||||
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();
|
||||
void retranslateUi();
|
||||
void closeRequest();
|
||||
QString getUserName() const { return userName; }
|
||||
QString getTabText() const { return tr("Talking to %1").arg(userName); }
|
||||
QString getUserName() const;
|
||||
QString getTabText() const;
|
||||
|
||||
void processUserMessageEvent(const Event_UserMessage &event);
|
||||
void processUserLeft();
|
||||
void processUserJoined();
|
||||
void processUserJoined(const ServerInfo_User &_userInfo);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,7 +40,8 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor, AbstractClient *_client, ServerI
|
|||
userList = new UserList(tabSupervisor, client, UserList::RoomList);
|
||||
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(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
|
||||
sayLabel = new QLabel;
|
||||
|
@ -142,7 +143,7 @@ void TabRoom::sendMessage()
|
|||
void TabRoom::sayFinished(const Response &response)
|
||||
{
|
||||
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()
|
||||
|
@ -197,20 +198,13 @@ void TabRoom::processRoomSayEvent(const Event_RoomSay &event)
|
|||
if (tabSupervisor->getUserListsTab()->getIgnoreList()->getUsers().contains(senderName))
|
||||
return;
|
||||
UserListTWI *twi = userList->getUsers().value(senderName);
|
||||
QColor senderColor;
|
||||
if (twi && (senderName != QString::fromStdString(ownUser->name()))) {
|
||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(twi->getUserLevel());
|
||||
if (userLevel & ServerInfo_User::IsModerator)
|
||||
senderColor = Qt::darkMagenta;
|
||||
else if (userLevel & ServerInfo_User::IsRegistered)
|
||||
senderColor = Qt::darkGreen;
|
||||
else {
|
||||
if (settingsCache->getIgnoreUnregisteredUsers())
|
||||
return;
|
||||
senderColor = QColor(0, 0, 254);
|
||||
}
|
||||
UserLevelFlags userLevel;
|
||||
if (twi) {
|
||||
userLevel = UserLevelFlags(twi->getUserInfo().user_level());
|
||||
if (settingsCache->getIgnoreUnregisteredUsers() && !userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||
return;
|
||||
}
|
||||
chatView->appendMessage(QString::fromStdString(event.name()), QString::fromStdString(event.message()), senderColor);
|
||||
chatView->appendMessage(QString::fromStdString(event.message()), senderName, userLevel);
|
||||
emit userEvent(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "tab_message.h"
|
||||
#include "tab_userlists.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include "userlist.h"
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
|
||||
|
@ -134,7 +135,7 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
|||
|
||||
tabUserLists = new TabUserLists(this, client, *userInfo);
|
||||
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 &)));
|
||||
myAddTab(tabUserLists);
|
||||
|
||||
|
@ -321,7 +322,7 @@ void TabSupervisor::roomLeft(TabRoom *tab)
|
|||
|
||||
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 *)));
|
||||
int tabIndex = myAddTab(replayTab);
|
||||
addCloseButtonToTab(replayTab, tabIndex);
|
||||
|
@ -342,7 +343,13 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
|
|||
if (receiverName == QString::fromStdString(userInfo->name()))
|
||||
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 *)));
|
||||
int tabIndex = myAddTab(tab);
|
||||
addCloseButtonToTab(tab, tabIndex);
|
||||
|
@ -407,11 +414,11 @@ void TabSupervisor::processUserLeft(const QString &userName)
|
|||
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)
|
||||
tab->processUserJoined();
|
||||
tab->processUserJoined(userInfo);
|
||||
}
|
||||
|
||||
void TabSupervisor::updateCurrent(int index)
|
||||
|
|
|
@ -84,7 +84,7 @@ private slots:
|
|||
void openReplay(GameReplay *replay);
|
||||
void replayLeft(TabGame *tab);
|
||||
void processUserLeft(const QString &userName);
|
||||
void processUserJoined(const QString &userName);
|
||||
void processUserJoined(const ServerInfo_User &userInfo);
|
||||
void talkLeft(TabMessage *tab);
|
||||
void tabUserEvent(bool globalEvent);
|
||||
void processRoomEvent(const RoomEvent &event);
|
||||
|
|
|
@ -88,7 +88,7 @@ void TabUserLists::processUserJoinedEvent(const Event_UserJoined &event)
|
|||
ignoreList->sortItems();
|
||||
buddyList->sortItems();
|
||||
|
||||
emit userJoined(userName);
|
||||
emit userJoined(info);
|
||||
}
|
||||
|
||||
void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
|
||||
|
|
|
@ -21,7 +21,7 @@ class TabUserLists : public Tab {
|
|||
signals:
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
void userLeft(const QString &userName);
|
||||
void userJoined(const QString &userName);
|
||||
void userJoined(const ServerInfo_User &userInfo);
|
||||
private slots:
|
||||
void processListUsersResponse(const Response &response);
|
||||
void processUserJoinedEvent(const Event_UserJoined &event);
|
||||
|
@ -40,8 +40,9 @@ public:
|
|||
TabUserLists(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User &userInfo, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
QString getTabText() const { return tr("User lists"); }
|
||||
UserList *getBuddyList() const { return buddyList; }
|
||||
UserList *getIgnoreList() const { return ignoreList; }
|
||||
const UserList *getAllUsersList() const { return allUsersList; }
|
||||
const UserList *getBuddyList() const { return buddyList; }
|
||||
const UserList *getIgnoreList() const { return ignoreList; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "pb/response_get_games_of_user.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)
|
||||
{
|
||||
aUserName = new QAction(QString(), this);
|
||||
|
@ -87,7 +87,7 @@ void UserContextMenu::banUser_dialogFinished()
|
|||
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);
|
||||
|
||||
|
@ -97,7 +97,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
|||
menu->addAction(aDetails);
|
||||
menu->addAction(aShowGames);
|
||||
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();
|
||||
if (tabSupervisor->getUserListsTab()->getBuddyList()->getUsers().contains(userName))
|
||||
menu->addAction(aRemoveFromBuddyList);
|
||||
|
@ -167,7 +167,7 @@ void UserContextMenu::showContextMenu(const QPoint &pos, const QString &userName
|
|||
client->sendCommand(client->prepareSessionCommand(cmd));
|
||||
} else if (actionClicked == aKick) {
|
||||
Command_KickFromGame cmd;
|
||||
cmd.set_player_id(playerId);
|
||||
cmd.set_player_id(game->getPlayerIdByName(userName));
|
||||
game->sendGameCommand(cmd);
|
||||
} else if (actionClicked == aBan) {
|
||||
Command_GetUserInfo cmd;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define USER_CONTEXT_MENU_H
|
||||
|
||||
#include <QObject>
|
||||
#include "pb/serverinfo_user.pb.h"
|
||||
#include "user_level.h"
|
||||
|
||||
class QAction;
|
||||
class TabSupervisor;
|
||||
|
@ -16,7 +16,7 @@ class UserContextMenu : public QObject {
|
|||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
TabSupervisor *tabSupervisor;
|
||||
const TabSupervisor *tabSupervisor;
|
||||
TabGame *game;
|
||||
|
||||
QAction *aUserName;
|
||||
|
@ -34,8 +34,8 @@ private slots:
|
|||
void banUser_dialogFinished();
|
||||
void gamesOfUserReceived(const Response &resp, const CommandContainer &commandContainer);
|
||||
public:
|
||||
UserContextMenu(TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0);
|
||||
void showContextMenu(const QPoint &pos, const QString &userName, ServerInfo_User::UserLevelFlags userLevel, int playerId = -1);
|
||||
UserContextMenu(const TabSupervisor *_tabSupervisor, QWidget *_parent, TabGame *_game = 0);
|
||||
void showContextMenu(const QPoint &pos, const QString &userName, UserLevelFlags userLevel, int playerId = -1);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -56,7 +56,7 @@ void UserInfoBox::retranslateUi()
|
|||
|
||||
void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||
{
|
||||
const int userLevel = user.user_level();
|
||||
const UserLevelFlags userLevel(user.user_level());
|
||||
|
||||
QPixmap avatarPixmap;
|
||||
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())));
|
||||
userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
|
||||
QString userLevelText;
|
||||
if (userLevel & ServerInfo_User::IsAdmin)
|
||||
if (userLevel.testFlag(ServerInfo_User::IsAdmin))
|
||||
userLevelText = tr("Administrator");
|
||||
else if (userLevel & ServerInfo_User::IsModerator)
|
||||
else if (userLevel.testFlag(ServerInfo_User::IsModerator))
|
||||
userLevelText = tr("Moderator");
|
||||
else if (userLevel & ServerInfo_User::IsRegistered)
|
||||
else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
|
||||
userLevelText = tr("Registered user");
|
||||
else
|
||||
userLevelText = tr("Unregistered user");
|
||||
|
|
|
@ -170,19 +170,27 @@ bool UserListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
|||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
UserListTWI::UserListTWI()
|
||||
UserListTWI::UserListTWI(const ServerInfo_User &_userInfo)
|
||||
: 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
|
||||
|
@ -239,25 +247,17 @@ void UserList::processUserInfo(const ServerInfo_User &user, bool online)
|
|||
{
|
||||
const QString userName = QString::fromStdString(user.name());
|
||||
UserListTWI *item = users.value(userName);
|
||||
if (!item) {
|
||||
item = new UserListTWI;
|
||||
if (item)
|
||||
item->setUserInfo(user);
|
||||
else {
|
||||
item = new UserListTWI(user);
|
||||
users.insert(userName, item);
|
||||
userTree->addTopLevelItem(item);
|
||||
if (online)
|
||||
++onlineCount;
|
||||
updateCount();
|
||||
}
|
||||
item->setData(0, Qt::UserRole, user.user_level());
|
||||
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));
|
||||
item->setOnline(online);
|
||||
}
|
||||
|
||||
bool UserList::deleteUser(const QString &userName)
|
||||
|
@ -276,25 +276,18 @@ bool UserList::deleteUser(const QString &userName)
|
|||
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)
|
||||
{
|
||||
UserListTWI *twi = users.value(userName);
|
||||
if (twi)
|
||||
setUserOnline(twi, online);
|
||||
if (!twi)
|
||||
return;
|
||||
|
||||
twi->setOnline(online);
|
||||
if (online)
|
||||
++onlineCount;
|
||||
else
|
||||
--onlineCount;
|
||||
updateCount();
|
||||
}
|
||||
|
||||
void UserList::updateCount()
|
||||
|
@ -312,11 +305,9 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
|
|||
|
||||
void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||
{
|
||||
UserListTWI *twi = static_cast<UserListTWI *>(userTree->topLevelItem(index.row()));
|
||||
const QString &userName = twi->getUserName();
|
||||
ServerInfo_User::UserLevelFlags userLevel = static_cast<ServerInfo_User::UserLevelFlags>(twi->getUserLevel());
|
||||
const ServerInfo_User &userInfo = static_cast<UserListTWI *>(userTree->topLevelItem(index.row()))->getUserInfo();
|
||||
|
||||
userContextMenu->showContextMenu(pos, userName, userLevel);
|
||||
userContextMenu->showContextMenu(pos, QString::fromStdString(userInfo.name()), UserLevelFlags(userInfo.user_level()));
|
||||
}
|
||||
|
||||
void UserList::sortItems()
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QGroupBox>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QStyledItemDelegate>
|
||||
#include "user_level.h"
|
||||
|
||||
class QTreeWidget;
|
||||
class ServerInfo_User;
|
||||
|
@ -47,10 +48,13 @@ public:
|
|||
};
|
||||
|
||||
class UserListTWI : public QTreeWidgetItem {
|
||||
private:
|
||||
ServerInfo_User userInfo;
|
||||
public:
|
||||
UserListTWI();
|
||||
QString getUserName() const;
|
||||
int getUserLevel() const;
|
||||
UserListTWI(const ServerInfo_User &_userInfo);
|
||||
const ServerInfo_User &getUserInfo() const { return userInfo; }
|
||||
void setUserInfo(const ServerInfo_User &_userInfo);
|
||||
void setOnline(bool online);
|
||||
bool operator<(const QTreeWidgetItem &other) const;
|
||||
};
|
||||
|
||||
|
@ -69,7 +73,6 @@ private:
|
|||
int onlineCount;
|
||||
QString titleStr;
|
||||
void updateCount();
|
||||
void setUserOnline(QTreeWidgetItem *user, bool online);
|
||||
private slots:
|
||||
void userClicked(QTreeWidgetItem *item, int column);
|
||||
signals:
|
||||
|
|
|
@ -176,7 +176,7 @@ void MainWindow::actWatchReplay()
|
|||
GameReplay *replay = new GameReplay;
|
||||
replay->ParseFromArray(buf.data(), buf.size());
|
||||
|
||||
TabGame *replayWatcher = new TabGame(replay);
|
||||
TabGame *replayWatcher = new TabGame(0, replay);
|
||||
replayWatcher->show();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
message ServerInfo_User {
|
||||
enum UserLevelFlags {
|
||||
IsNothing = 0;
|
||||
IsUser = 1;
|
||||
enum UserLevelFlag {
|
||||
IsNothing = 0;
|
||||
IsUser = 1;
|
||||
IsRegistered = 2;
|
||||
IsModerator = 4;
|
||||
IsAdmin = 8;
|
||||
|
|
|
@ -387,7 +387,7 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface, Respons
|
|||
newPlayer->moveToThread(thread());
|
||||
|
||||
Event_Join joinEvent;
|
||||
joinEvent.mutable_player_properties()->CopyFrom(newPlayer->getProperties(true));
|
||||
newPlayer->getProperties(*joinEvent.mutable_player_properties(), true);
|
||||
sendGameEventContainer(prepareGameEvent(joinEvent, -1));
|
||||
|
||||
const QString playerName = QString::fromStdString(newPlayer->getUserInfo()->name());
|
||||
|
|
|
@ -240,9 +240,8 @@ void Server_Player::clearZones()
|
|||
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);
|
||||
if (withUserInfo)
|
||||
result.mutable_user_info()->CopyFrom(*userInfo);
|
||||
|
@ -253,8 +252,6 @@ ServerInfo_PlayerProperties Server_Player::getProperties(bool withUserInfo)
|
|||
if (deck)
|
||||
result.set_deck_hash(deck->getDeckHash().toStdString());
|
||||
result.set_ping_seconds(pingTime);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
info->mutable_properties()->CopyFrom(getProperties(withUserInfo));
|
||||
getProperties(*info->mutable_properties(), withUserInfo);
|
||||
if (playerWhosAsking == this)
|
||||
if (deck)
|
||||
info->set_deck_list(deck->writeToString_Native().toStdString());
|
||||
|
|
|
@ -105,7 +105,7 @@ public:
|
|||
|
||||
int getPingTime() const { return pingTime; }
|
||||
void setPingTime(int _pingTime) { pingTime = _pingTime; }
|
||||
ServerInfo_PlayerProperties getProperties(bool withUserInfo);
|
||||
void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
|
||||
|
||||
int newCardId();
|
||||
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