mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
some cleanups and fixes
This commit is contained in:
parent
6ba2e98315
commit
564ae4db84
27 changed files with 371 additions and 206 deletions
|
|
@ -1,10 +1,11 @@
|
|||
#include "playerlistwidget.h"
|
||||
#include "protocol_datastructures.h"
|
||||
#include "pingpixmapgenerator.h"
|
||||
|
||||
PlayerListWidget::PlayerListWidget(QWidget *parent)
|
||||
: QTreeWidget(parent)
|
||||
{
|
||||
setColumnCount(1);
|
||||
setColumnCount(2);
|
||||
setRootIsDecorated(false);
|
||||
retranslateUi();
|
||||
}
|
||||
|
|
@ -12,12 +13,14 @@ PlayerListWidget::PlayerListWidget(QWidget *parent)
|
|||
void PlayerListWidget::retranslateUi()
|
||||
{
|
||||
headerItem()->setText(0, tr("Player name"));
|
||||
headerItem()->setText(1, tr("Role"));
|
||||
}
|
||||
|
||||
void PlayerListWidget::addPlayer(ServerInfo_Player *player)
|
||||
{
|
||||
QTreeWidgetItem *newPlayer = new QTreeWidgetItem;
|
||||
newPlayer->setText(0, player->getName());
|
||||
newPlayer->setText(1, player->getSpectator() ? tr("Spectator") : tr("Player"));
|
||||
addTopLevelItem(newPlayer);
|
||||
players.insert(player->getPlayerId(), newPlayer);
|
||||
}
|
||||
|
|
@ -37,6 +40,16 @@ void PlayerListWidget::setActivePlayer(int playerId)
|
|||
while (i.hasNext()) {
|
||||
i.next();
|
||||
QTreeWidgetItem *twi = i.value();
|
||||
twi->setBackground(0, i.key() == playerId ? QColor(150, 255, 150) : Qt::white);
|
||||
QColor c = i.key() == playerId ? QColor(150, 255, 150) : Qt::white;
|
||||
twi->setBackground(0, c);
|
||||
twi->setBackground(1, c);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerListWidget::updatePing(int playerId, int pingTime)
|
||||
{
|
||||
QTreeWidgetItem *twi = players.value(playerId, 0);
|
||||
if (!twi)
|
||||
return;
|
||||
twi->setIcon(0, QIcon(PingPixmapGenerator::generatePixmap(10, pingTime, 10)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue