diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index e823a2b7..deb22ceb 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -73,8 +73,6 @@ TabGame::TabGame(Client *_client, int _gameId) 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(signalNextTurn()), client, SLOT(nextTurn())); diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index bdb1c667..71c7a2b9 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -5,11 +5,12 @@ #include "tab_game.h" #include "tab_deck_storage.h" #include "protocol_items.h" +#include TabSupervisor:: TabSupervisor(QWidget *parent) : QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0) { - + setIconSize(QSize(15, 15)); } void TabSupervisor::retranslateUi() @@ -38,10 +39,12 @@ void TabSupervisor::start(Client *_client) connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *))); connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *))); 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); connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &))); addTab(tabServer, QString()); + updatePingTime(0, -1); tabDeckStorage = new TabDeckStorage(client); addTab(tabDeckStorage, QString()); @@ -75,6 +78,27 @@ void TabSupervisor::stop() 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) { TabGame *tab = new TabGame(client, event->getGameId()); diff --git a/cockatrice/src/tab_supervisor.h b/cockatrice/src/tab_supervisor.h index 2724f108..427c4cf1 100644 --- a/cockatrice/src/tab_supervisor.h +++ b/cockatrice/src/tab_supervisor.h @@ -27,6 +27,7 @@ public: void start(Client *_client); void stop(); private slots: + void updatePingTime(int value, int max); void gameJoined(Event_GameJoined *event); void addChatChannelTab(const QString &channelName); void processChatEvent(ChatEvent *event); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 3e98ef59..a253a624 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -26,34 +26,6 @@ #include "window_deckeditor.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) { @@ -75,7 +47,6 @@ void MainWindow::statusChanged(ClientStatus _status) // delete game; // game = 0; // } -// pingWidget->setPercentage(0, -1); aConnect->setEnabled(true); aDisconnect->setEnabled(false); // aRestartGame->setEnabled(false); diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index 5d29df2d..c45c86aa 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -25,19 +25,6 @@ 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 { Q_OBJECT private slots: @@ -63,8 +50,6 @@ private: QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit; TabSupervisor *tabSupervisor; - PingWidget *pingWidget; - Client *client; public: MainWindow(QWidget *parent = 0);