mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
user details box
This commit is contained in:
parent
09595cc691
commit
7f7398de6a
12 changed files with 207 additions and 85 deletions
|
|
@ -163,7 +163,7 @@ TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Ro
|
|||
: Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
|
||||
{
|
||||
gameSelector = new GameSelector(client, roomId);
|
||||
userList = new UserList(false);
|
||||
userList = new UserList(client, false);
|
||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||
|
||||
chatView = new ChatView(ownName);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
#include "protocol.h"
|
||||
#include "protocol_items.h"
|
||||
#include "userlist.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include "userinfobox.h"
|
||||
//#include "pixmapgenerator.h"
|
||||
#include <QDebug>
|
||||
|
||||
RoomSelector::RoomSelector(AbstractClient *_client, QWidget *parent)
|
||||
|
|
@ -117,74 +118,14 @@ void RoomSelector::joinFinished(ProtocolResponse *r)
|
|||
emit roomJoined(resp->getRoomInfo(), static_cast<Command *>(sender())->getExtraData().toBool());
|
||||
}
|
||||
|
||||
UserInfoBox::UserInfoBox(ServerInfo_User *userInfo, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
avatarLabel = new QLabel;
|
||||
nameLabel = new QLabel;
|
||||
QFont nameFont = nameLabel->font();
|
||||
nameFont.setBold(true);
|
||||
nameFont.setPointSize(nameFont.pointSize() * 1.5);
|
||||
nameLabel->setFont(nameFont);
|
||||
countryLabel1 = new QLabel;
|
||||
countryLabel2 = new QLabel;
|
||||
userLevelLabel1 = new QLabel;
|
||||
userLevelLabel2 = new QLabel;
|
||||
userLevelLabel3 = new QLabel;
|
||||
|
||||
QGridLayout *mainLayout = new QGridLayout;
|
||||
mainLayout->addWidget(avatarLabel, 0, 0, 3, 1, Qt::AlignCenter);
|
||||
mainLayout->addWidget(nameLabel, 0, 1, 1, 3);
|
||||
mainLayout->addWidget(countryLabel1, 1, 1, 1, 1);
|
||||
mainLayout->addWidget(countryLabel2, 1, 2, 1, 2);
|
||||
mainLayout->addWidget(userLevelLabel1, 2, 1, 1, 1);
|
||||
mainLayout->addWidget(userLevelLabel2, 2, 2, 1, 1);
|
||||
mainLayout->addWidget(userLevelLabel3, 2, 3, 1, 1);
|
||||
mainLayout->setColumnMinimumWidth(0, 80);
|
||||
mainLayout->setColumnStretch(3, 10);
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
updateInfo(userInfo);
|
||||
}
|
||||
|
||||
void UserInfoBox::retranslateUi()
|
||||
{
|
||||
countryLabel1->setText(tr("Location:"));
|
||||
userLevelLabel1->setText(tr("User level:"));
|
||||
}
|
||||
|
||||
void UserInfoBox::updateInfo(ServerInfo_User *user)
|
||||
{
|
||||
int userLevel = user->getUserLevel();
|
||||
|
||||
QPixmap avatarPixmap;
|
||||
if (!avatarPixmap.loadFromData(user->getAvatarBmp()))
|
||||
avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel);
|
||||
avatarLabel->setPixmap(avatarPixmap);
|
||||
|
||||
nameLabel->setText(user->getName());
|
||||
countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, user->getCountry()));
|
||||
userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
|
||||
QString userLevelText;
|
||||
if (userLevel & ServerInfo_User::IsAdmin)
|
||||
userLevelText = tr("Administrator");
|
||||
else if (userLevel & ServerInfo_User::IsJudge)
|
||||
userLevelText = tr("Judge");
|
||||
else if (userLevel & ServerInfo_User::IsRegistered)
|
||||
userLevelText = tr("Registered user");
|
||||
else
|
||||
userLevelText = tr("Unregistered user");
|
||||
userLevelLabel3->setText(userLevelText);
|
||||
}
|
||||
|
||||
TabServer::TabServer(AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent)
|
||||
: Tab(parent), client(_client)
|
||||
{
|
||||
roomSelector = new RoomSelector(client);
|
||||
serverInfoBox = new QTextBrowser;
|
||||
userInfoBox = new UserInfoBox(userInfo);
|
||||
userList = new UserList(true);
|
||||
userInfoBox = new UserInfoBox(_client, false);
|
||||
userInfoBox->updateInfo(userInfo);
|
||||
userList = new UserList(client, true);
|
||||
|
||||
connect(roomSelector, SIGNAL(roomJoined(ServerInfo_Room *, bool)), this, SIGNAL(roomJoined(ServerInfo_Room *, bool)));
|
||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class QTextEdit;
|
|||
class QLabel;
|
||||
class UserList;
|
||||
class QPushButton;
|
||||
class UserInfoBox;
|
||||
|
||||
class Event_ListRooms;
|
||||
class Event_ServerMessage;
|
||||
|
|
@ -39,16 +40,6 @@ public:
|
|||
void retranslateUi();
|
||||
};
|
||||
|
||||
class UserInfoBox : public QWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QLabel *avatarLabel, *nameLabel, *countryLabel1, *countryLabel2, *userLevelLabel1, *userLevelLabel2, *userLevelLabel3;
|
||||
void updateInfo(ServerInfo_User *user);
|
||||
public:
|
||||
UserInfoBox(ServerInfo_User *userInfo, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
};
|
||||
|
||||
class TabServer : public Tab {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
|
|
|
|||
91
cockatrice/src/userinfobox.cpp
Normal file
91
cockatrice/src/userinfobox.cpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include "userinfobox.h"
|
||||
#include "protocol_datastructures.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include "protocol_items.h"
|
||||
#include "abstractclient.h"
|
||||
#include <QLabel>
|
||||
#include <QGridLayout>
|
||||
|
||||
UserInfoBox::UserInfoBox(AbstractClient *_client, bool _fullInfo, QWidget *parent, Qt::WindowFlags flags)
|
||||
: QWidget(parent, flags), client(_client), fullInfo(_fullInfo)
|
||||
{
|
||||
avatarLabel = new QLabel;
|
||||
nameLabel = new QLabel;
|
||||
QFont nameFont = nameLabel->font();
|
||||
nameFont.setBold(true);
|
||||
nameFont.setPointSize(nameFont.pointSize() * 1.5);
|
||||
nameLabel->setFont(nameFont);
|
||||
realNameLabel1 = new QLabel;
|
||||
realNameLabel2 = new QLabel;
|
||||
countryLabel1 = new QLabel;
|
||||
countryLabel2 = new QLabel;
|
||||
userLevelLabel1 = new QLabel;
|
||||
userLevelLabel2 = new QLabel;
|
||||
userLevelLabel3 = new QLabel;
|
||||
|
||||
QGridLayout *mainLayout = new QGridLayout;
|
||||
mainLayout->addWidget(avatarLabel, 0, 0, 1, 3, Qt::AlignCenter);
|
||||
mainLayout->addWidget(nameLabel, 1, 0, 1, 3);
|
||||
mainLayout->addWidget(realNameLabel1, 2, 0, 1, 1);
|
||||
mainLayout->addWidget(realNameLabel2, 2, 1, 1, 2);
|
||||
mainLayout->addWidget(countryLabel1, 3, 0, 1, 1);
|
||||
mainLayout->addWidget(countryLabel2, 3, 1, 1, 2);
|
||||
mainLayout->addWidget(userLevelLabel1, 4, 0, 1, 1);
|
||||
mainLayout->addWidget(userLevelLabel2, 4, 1, 1, 1);
|
||||
mainLayout->addWidget(userLevelLabel3, 4, 2, 1, 1);
|
||||
mainLayout->setColumnStretch(2, 10);
|
||||
|
||||
setWindowTitle(tr("User information"));
|
||||
setLayout(mainLayout);
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void UserInfoBox::retranslateUi()
|
||||
{
|
||||
realNameLabel1->setText(tr("Real name:"));
|
||||
countryLabel1->setText(tr("Location:"));
|
||||
userLevelLabel1->setText(tr("User level:"));
|
||||
}
|
||||
|
||||
void UserInfoBox::updateInfo(ServerInfo_User *user)
|
||||
{
|
||||
int userLevel = user->getUserLevel();
|
||||
|
||||
QPixmap avatarPixmap;
|
||||
if (!avatarPixmap.loadFromData(user->getAvatarBmp()))
|
||||
avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel);
|
||||
avatarLabel->setPixmap(avatarPixmap);
|
||||
|
||||
nameLabel->setText(user->getName());
|
||||
realNameLabel2->setText(user->getRealName());
|
||||
countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, user->getCountry()));
|
||||
userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel));
|
||||
QString userLevelText;
|
||||
if (userLevel & ServerInfo_User::IsAdmin)
|
||||
userLevelText = tr("Administrator");
|
||||
else if (userLevel & ServerInfo_User::IsJudge)
|
||||
userLevelText = tr("Judge");
|
||||
else if (userLevel & ServerInfo_User::IsRegistered)
|
||||
userLevelText = tr("Registered user");
|
||||
else
|
||||
userLevelText = tr("Unregistered user");
|
||||
userLevelLabel3->setText(userLevelText);
|
||||
}
|
||||
|
||||
void UserInfoBox::updateInfo(const QString &userName)
|
||||
{
|
||||
Command_GetUserInfo *command = new Command_GetUserInfo(userName);
|
||||
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processResponse(ProtocolResponse *)));
|
||||
client->sendCommand(command);
|
||||
}
|
||||
|
||||
void UserInfoBox::processResponse(ProtocolResponse *r)
|
||||
{
|
||||
Response_GetUserInfo *response = qobject_cast<Response_GetUserInfo *>(r);
|
||||
if (!response)
|
||||
return;
|
||||
|
||||
updateInfo(response->getUserInfo());
|
||||
setFixedSize(sizeHint());
|
||||
show();
|
||||
}
|
||||
27
cockatrice/src/userinfobox.h
Normal file
27
cockatrice/src/userinfobox.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef USERINFOBOX_H
|
||||
#define USERINFOBOX_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QLabel;
|
||||
class ServerInfo_User;
|
||||
class AbstractClient;
|
||||
class ProtocolResponse;
|
||||
|
||||
class UserInfoBox : public QWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
bool fullInfo;
|
||||
QLabel *avatarLabel, *nameLabel, *realNameLabel1, *realNameLabel2, *countryLabel1, *countryLabel2, *userLevelLabel1, *userLevelLabel2, *userLevelLabel3;
|
||||
public:
|
||||
UserInfoBox(AbstractClient *_client, bool fullInfo, QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||
void retranslateUi();
|
||||
private slots:
|
||||
void processResponse(ProtocolResponse *r);
|
||||
public slots:
|
||||
void updateInfo(ServerInfo_User *user);
|
||||
void updateInfo(const QString &userName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,8 +1,28 @@
|
|||
#include "userlist.h"
|
||||
#include "abstractclient.h"
|
||||
#include "pixmapgenerator.h"
|
||||
#include "userinfobox.h"
|
||||
#include <QHeaderView>
|
||||
#include <QVBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QMenu>
|
||||
|
||||
UserListItemDelegate::UserListItemDelegate(QObject *const parent)
|
||||
: QItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool UserListItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
|
||||
QMouseEvent *const mouseEvent = static_cast<QMouseEvent *>(event);
|
||||
if (mouseEvent->button() == Qt::RightButton) {
|
||||
static_cast<UserList *>(parent())->showContextMenu(mouseEvent->globalPos(), index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
UserListTWI::UserListTWI()
|
||||
: QTreeWidgetItem(Type)
|
||||
|
|
@ -18,15 +38,18 @@ bool UserListTWI::operator<(const QTreeWidgetItem &other) const
|
|||
return data(0, Qt::UserRole).toInt() > other.data(0, Qt::UserRole).toInt();
|
||||
}
|
||||
|
||||
UserList::UserList(bool _global, QWidget *parent)
|
||||
: QGroupBox(parent), global(_global)
|
||||
UserList::UserList(AbstractClient *_client, bool _global, QWidget *parent)
|
||||
: QGroupBox(parent), client(_client), global(_global)
|
||||
{
|
||||
itemDelegate = new UserListItemDelegate(this);
|
||||
|
||||
userTree = new QTreeWidget;
|
||||
userTree->setColumnCount(3);
|
||||
userTree->header()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
userTree->setHeaderHidden(true);
|
||||
userTree->setRootIsDecorated(false);
|
||||
userTree->setIconSize(QSize(20, 12));
|
||||
userTree->setItemDelegate(itemDelegate);
|
||||
connect(userTree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(userClicked(QTreeWidgetItem *, int)));
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
|
|
@ -87,6 +110,37 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/)
|
|||
emit openMessageDialog(item->data(2, Qt::UserRole).toString(), true);
|
||||
}
|
||||
|
||||
void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
||||
{
|
||||
const QString &userName = index.sibling(index.row(), 2).data(Qt::UserRole).toString();
|
||||
|
||||
QAction *aUserName = new QAction(userName, this);
|
||||
aUserName->setEnabled(false);
|
||||
QAction *aDetails = new QAction(tr("User &details"), this);
|
||||
QAction *aChat = new QAction(tr("Direct &chat"), this);
|
||||
|
||||
QMenu *menu = new QMenu(this);
|
||||
menu->addAction(aUserName);
|
||||
menu->addSeparator();
|
||||
menu->addAction(aDetails);
|
||||
menu->addAction(aChat);
|
||||
|
||||
QAction *actionClicked = menu->exec(pos);
|
||||
if (actionClicked == aDetails) {
|
||||
UserInfoBox *infoWidget = new UserInfoBox(client, true, this, Qt::Dialog | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
|
||||
infoWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||
infoWidget->setFixedSize(infoWidget->sizeHint());
|
||||
infoWidget->updateInfo(userName);
|
||||
infoWidget->show();
|
||||
} else if (actionClicked == aChat)
|
||||
emit openMessageDialog(userName, true);
|
||||
|
||||
delete menu;
|
||||
delete aUserName;
|
||||
delete aDetails;
|
||||
delete aChat;
|
||||
}
|
||||
|
||||
void UserList::sortItems()
|
||||
{
|
||||
userTree->sortItems(1, Qt::AscendingOrder);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,17 @@
|
|||
|
||||
#include <QGroupBox>
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QItemDelegate>
|
||||
|
||||
class QTreeWidget;
|
||||
class ServerInfo_User;
|
||||
class AbstractClient;
|
||||
|
||||
class UserListItemDelegate : public QItemDelegate {
|
||||
public:
|
||||
UserListItemDelegate(QObject *const parent);
|
||||
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||
};
|
||||
|
||||
class UserListTWI : public QTreeWidgetItem {
|
||||
public:
|
||||
|
|
@ -16,7 +24,9 @@ public:
|
|||
class UserList : public QGroupBox {
|
||||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
QTreeWidget *userTree;
|
||||
UserListItemDelegate *itemDelegate;
|
||||
bool global;
|
||||
QString titleStr;
|
||||
void updateCount();
|
||||
|
|
@ -25,10 +35,11 @@ private slots:
|
|||
signals:
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
public:
|
||||
UserList(bool _global, QWidget *parent = 0);
|
||||
UserList(AbstractClient *_client, bool _global, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
void processUserInfo(ServerInfo_User *user);
|
||||
bool deleteUser(const QString &userName);
|
||||
void showContextMenu(const QPoint &pos, const QModelIndex &index);
|
||||
void sortItems();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue