ping time display is working again

This commit is contained in:
Max-Wilhelm Bruker 2009-11-22 14:41:02 +01:00
parent 4fac0e5b5a
commit 6c93b1e9b7
5 changed files with 26 additions and 47 deletions

View file

@ -73,8 +73,6 @@ TabGame::TabGame(Client *_client, int _gameId)
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay())); connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int))); connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int)));
connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn())); connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn()));

View file

@ -5,11 +5,12 @@
#include "tab_game.h" #include "tab_game.h"
#include "tab_deck_storage.h" #include "tab_deck_storage.h"
#include "protocol_items.h" #include "protocol_items.h"
#include <QPainter>
TabSupervisor:: TabSupervisor(QWidget *parent) TabSupervisor:: TabSupervisor(QWidget *parent)
: QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0) : QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0)
{ {
setIconSize(QSize(15, 15));
} }
void TabSupervisor::retranslateUi() void TabSupervisor::retranslateUi()
@ -38,10 +39,12 @@ void TabSupervisor::start(Client *_client)
connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *))); connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *)));
connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *))); connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *)));
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *))); connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
tabServer = new TabServer(client); tabServer = new TabServer(client);
connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &))); connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &)));
addTab(tabServer, QString()); addTab(tabServer, QString());
updatePingTime(0, -1);
tabDeckStorage = new TabDeckStorage(client); tabDeckStorage = new TabDeckStorage(client);
addTab(tabDeckStorage, QString()); addTab(tabDeckStorage, QString());
@ -75,6 +78,27 @@ void TabSupervisor::stop()
gameTabs.clear(); gameTabs.clear();
} }
void TabSupervisor::updatePingTime(int value, int max)
{
if (!tabServer)
return;
QPixmap pixmap(15, 15);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QColor color;
if (max == -1)
color = Qt::black;
else
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
QRadialGradient g(QPointF((double) pixmap.width() / 2, (double) pixmap.height() / 2), qMin(pixmap.width(), pixmap.height()) / 2.0);
g.setColorAt(0, color);
g.setColorAt(1, Qt::transparent);
painter.fillRect(0, 0, pixmap.width(), pixmap.height(), QBrush(g));
setTabIcon(0, QIcon(pixmap));
}
void TabSupervisor::gameJoined(Event_GameJoined *event) void TabSupervisor::gameJoined(Event_GameJoined *event)
{ {
TabGame *tab = new TabGame(client, event->getGameId()); TabGame *tab = new TabGame(client, event->getGameId());

View file

@ -27,6 +27,7 @@ public:
void start(Client *_client); void start(Client *_client);
void stop(); void stop();
private slots: private slots:
void updatePingTime(int value, int max);
void gameJoined(Event_GameJoined *event); void gameJoined(Event_GameJoined *event);
void addChatChannelTab(const QString &channelName); void addChatChannelTab(const QString &channelName);
void processChatEvent(ChatEvent *event); void processChatEvent(ChatEvent *event);

View file

@ -26,34 +26,6 @@
#include "window_deckeditor.h" #include "window_deckeditor.h"
#include "tab_supervisor.h" #include "tab_supervisor.h"
PingWidget::PingWidget(QWidget *parent)
: QWidget(parent)
{
setPercentage(0, -1);
}
QSize PingWidget::sizeHint() const
{
return QSize(15, 15);
}
void PingWidget::paintEvent(QPaintEvent */*event*/)
{
QPainter painter(this);
QRadialGradient g(QPointF((double) width() / 2, (double) height() / 2), qMin(width(), height()) / 2.0);
g.setColorAt(0, color);
g.setColorAt(1, Qt::transparent);
painter.fillRect(0, 0, width(), height(), QBrush(g));
}
void PingWidget::setPercentage(int value, int max)
{
if (max == -1)
color = Qt::black;
else
color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
update();
}
/* /*
void MainWindow::playerAdded(Player *player) void MainWindow::playerAdded(Player *player)
{ {
@ -75,7 +47,6 @@ void MainWindow::statusChanged(ClientStatus _status)
// delete game; // delete game;
// game = 0; // game = 0;
// } // }
// pingWidget->setPercentage(0, -1);
aConnect->setEnabled(true); aConnect->setEnabled(true);
aDisconnect->setEnabled(false); aDisconnect->setEnabled(false);
// aRestartGame->setEnabled(false); // aRestartGame->setEnabled(false);

View file

@ -25,19 +25,6 @@
class TabSupervisor; class TabSupervisor;
class PingWidget : public QWidget {
Q_OBJECT
private:
QColor color;
protected:
void paintEvent(QPaintEvent *event);
public:
PingWidget(QWidget *parent = 0);
QSize sizeHint() const;
public slots:
void setPercentage(int value, int max);
};
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
private slots: private slots:
@ -63,8 +50,6 @@ private:
QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit; QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;
PingWidget *pingWidget;
Client *client; Client *client;
public: public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);