From 3997a40f0966fdcf6a79e5fcebcebfecb0f7577f Mon Sep 17 00:00:00 2001 From: doitux Date: Wed, 11 Dec 2013 15:54:29 +0100 Subject: [PATCH] gui part for #239 server ping state display --- src/config/configfile.cpp | 4 +- src/gui/qt/gametable/gametableimpl.cpp | 7 +- src/gui/qt/gametable/gametableimpl.h | 2 + src/gui/qt/gametable/myavatarlabel.cpp | 50 +++++++++++++- src/gui/qt/gametable/myavatarlabel.h | 6 ++ .../qt/gui_800x480/settingsdialog_800x480.ui | 67 ++++++++++--------- src/gui/qt/guiwrapper.cpp | 3 +- src/gui/qt/settingsdialog.ui | 19 ++++-- .../qt/settingsdialog/settingsdialogimpl.cpp | 2 + 9 files changed, 117 insertions(+), 43 deletions(-) diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index 3d9d1e74..701199f5 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -64,7 +64,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) myConfigState = OK; // !!!! Revisionsnummer der Configdefaults !!!!! - configRev = 103; + configRev = 104; //standard defaults logOnOffDefault = "1"; @@ -150,9 +150,9 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) configList.push_back(ConfigInfo("AppDataDir", CONFIG_TYPE_STRING, myQtToolsInterface->getDataPathStdString(myArgv0))); #endif configList.push_back(ConfigInfo("Language", CONFIG_TYPE_INT, myQtToolsInterface->getDefaultLanguage())); - /*configList.push_back(ConfigInfo("InternetServerAddressIRCChannelUpdateDone", CONFIG_TYPE_INT, "1"));*/ //HACK configList.push_back(ConfigInfo("ShowLeftToolBox", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("ShowCountryFlagInAvatar", CONFIG_TYPE_INT, "1")); + configList.push_back(ConfigInfo("ShowPingStateInAvatar", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("ShowRightToolBox", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("ShowFadeOutCardsAnimation", CONFIG_TYPE_INT, "1")); configList.push_back(ConfigInfo("ShowFlipCardsAnimation", CONFIG_TYPE_INT, "1")); diff --git a/src/gui/qt/gametable/gametableimpl.cpp b/src/gui/qt/gametable/gametableimpl.cpp index 27ce8904..8110035c 100755 --- a/src/gui/qt/gametable/gametableimpl.cpp +++ b/src/gui/qt/gametable/gametableimpl.cpp @@ -681,7 +681,7 @@ gameTableImpl::gameTableImpl(ConfigFile *c, QMainWindow *parent) connect(this, SIGNAL(signalNetClientPlayerLeft(unsigned)), this, SLOT(netClientPlayerLeft(unsigned))); connect(this, SIGNAL(signalNetClientSpectatorLeft(unsigned)), this, SLOT(netClientSpectatorLeft(unsigned))); connect(this, SIGNAL(signalNetClientSpectatorJoined(unsigned)), this, SLOT(netClientSpectatorJoined(unsigned))); - + connect(this, SIGNAL(signalNetClientPingUpdate(unsigned, unsigned, unsigned)), this, SLOT(pingUpdate(unsigned, unsigned, unsigned))); #ifdef GUI_800x480 connect( tabsButton, SIGNAL( clicked() ), this, SLOT( tabsButtonClicked() ) ); @@ -4496,3 +4496,8 @@ void gameTableImpl::refreshSpectatorsDisplay() } } +void gameTableImpl::pingUpdate(unsigned minPing, unsigned avgPing, unsigned maxPing) +{ + label_Avatar0->refreshPing(minPing, avgPing, maxPing); +} + diff --git a/src/gui/qt/gametable/gametableimpl.h b/src/gui/qt/gametable/gametableimpl.h index 5bbe874e..c46193a9 100755 --- a/src/gui/qt/gametable/gametableimpl.h +++ b/src/gui/qt/gametable/gametableimpl.h @@ -175,6 +175,7 @@ signals: void signalNetClientPlayerLeft(unsigned playerId); void signalNetClientSpectatorLeft(unsigned playerId); void signalNetClientSpectatorJoined(unsigned playerId); + void signalNetClientPingUpdate(unsigned minPing, unsigned avgPing, unsigned maxPing); public slots: @@ -375,6 +376,7 @@ public slots: void tabsButtonClose(); #endif void refreshSpectatorsDisplay(); + void pingUpdate(unsigned, unsigned, unsigned); private: diff --git a/src/gui/qt/gametable/myavatarlabel.cpp b/src/gui/qt/gametable/myavatarlabel.cpp index 793bce28..2c08f1eb 100644 --- a/src/gui/qt/gametable/myavatarlabel.cpp +++ b/src/gui/qt/gametable/myavatarlabel.cpp @@ -42,7 +42,7 @@ using namespace std; MyAvatarLabel::MyAvatarLabel(QGroupBox* parent) - : QLabel(parent), voteRunning(false), transparent(false), myUniqueId(0) + : QLabel(parent), voteRunning(false), transparent(false), myUniqueId(0), myPingState(0), myAvgPing(0), myMinPing(0), myMaxPing(0) { myContextMenu = new QMenu; @@ -398,10 +398,54 @@ void MyAvatarLabel::paintEvent(QPaintEvent*) boost::shared_ptr mySession = myW->myStartWindow->getSession(); if(!playerIsOnIgnoreList(QString::fromUtf8(mySession->getClientPlayerInfo(myUniqueId).playerName.c_str()))) { painter.drawPixmap(0,0,myPixmap); - return; } else if(myW->getMyConfig()->readConfigInt("DontHideAvatarsOfIgnored")) { painter.drawPixmap(0,0,myPixmap); - return; + } + + if(myW->getMyConfig()->readConfigInt("ShowPingStateInAvatar")) { + //paint ping state color for network clients + if(mySession->isNetworkClientRunning() && myId == 0) { + QColor pingColor; + if(myAvgPing > 0 && myAvgPing <= 1000) { + pingColor.setNamedColor("green"); + } + else if(myAvgPing > 1000 && myAvgPing <= 2000 ) { + pingColor.setNamedColor("yellow"); + } + else if(myAvgPing > 2000) { + pingColor.setNamedColor("red"); + } + else { + pingColor.setNamedColor("white"); + } + QColor pen = pingColor.darker(200); + // pen.setAlpha(130); + painter.setPen(pen); + QColor brush = pingColor; + // brush.setAlpha(130); + painter.setBrush(brush); + painter.setRenderHint(QPainter::Antialiasing); + painter.drawEllipse(1, 1, 10, 10); + } + } +} + +void MyAvatarLabel::refreshPing(unsigned minPing, unsigned avgPing, unsigned maxPing) +{ + myMinPing = minPing; + myAvgPing = avgPing; + myMaxPing = maxPing; + this->update(); + + if(myW->getMyConfig()->readConfigInt("ShowPingStateInAvatar")) { + QString toolTip = ""+tr("Server response times")+""; + toolTip.append("
"+tr("Average: ")+QString("%1").arg(myAvgPing)+tr("ms")); + toolTip.append("
"+tr("Minimum: ")+QString("%1").arg(myMinPing)+tr("ms")); + toolTip.append("
"+tr("Maximum: ")+QString("%1").arg(myMaxPing)+tr("ms")); + this->setToolTip(toolTip); + } + else { + this->setToolTip(""); } } diff --git a/src/gui/qt/gametable/myavatarlabel.h b/src/gui/qt/gametable/myavatarlabel.h index fcf61647..14e0d993 100644 --- a/src/gui/qt/gametable/myavatarlabel.h +++ b/src/gui/qt/gametable/myavatarlabel.h @@ -86,6 +86,8 @@ public slots: void setPlayerRating(QString); void refreshTooltips(); void refreshStars(); + void refreshPing(unsigned, unsigned, unsigned); + private: gameTableImpl *myW; @@ -103,6 +105,10 @@ private: bool transparent; int myId; int myUniqueId; + unsigned myPingState; + unsigned myAvgPing; + unsigned myMinPing; + unsigned myMaxPing; }; #endif diff --git a/src/gui/qt/gui_800x480/settingsdialog_800x480.ui b/src/gui/qt/gui_800x480/settingsdialog_800x480.ui index f0acae58..7b695e9f 100644 --- a/src/gui/qt/gui_800x480/settingsdialog_800x480.ui +++ b/src/gui/qt/gui_800x480/settingsdialog_800x480.ui @@ -291,42 +291,14 @@ Network / Internet Game - - - - Show country flag in the corner of avatar - - - - - - - Switch keyboard focus to bet-input-field if it's your turn - - - - - - - Activate the "accidentally call after big raise" blocker - - - - + Do not hide avatars of players which are on the ignore list - - - - Disable emoticons in the chat - - - - + Qt::Vertical @@ -339,6 +311,41 @@ + + + + Disable emoticons in the chat + + + + + + + Switch keyboard focus to bet-input-field if it's your turn + + + + + + + Activate the "accidentally call after big raise" blocker + + + + + + + Show country flag in the corner of avatar + + + + + + + Show multicolor network state display in the avatar + + + diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index 20ef8b6e..cd0a1f74 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -343,7 +343,7 @@ void GuiWrapper::SignalNetClientStatsUpdate(const ServerStats &stats) } void GuiWrapper::SignalNetClientPingUpdate(unsigned minPing, unsigned avgPing, unsigned maxPing) { - // TODO + myW->signalNetClientPingUpdate(minPing, avgPing, maxPing); } void GuiWrapper::SignalNetClientShowTimeoutDialog(NetTimeoutReason reason, unsigned remainingSec) { @@ -533,3 +533,4 @@ void GuiWrapper::SignalRejectedGameInvitation(unsigned gameId, unsigned playerId { myStartWindow->signalRejectedGameInvitation(gameId, playerIdWho, reason); } + diff --git a/src/gui/qt/settingsdialog.ui b/src/gui/qt/settingsdialog.ui index de3ec349..225429e4 100644 --- a/src/gui/qt/settingsdialog.ui +++ b/src/gui/qt/settingsdialog.ui @@ -289,7 +289,7 @@ Network / Internet Game - + Qt::Vertical @@ -309,41 +309,48 @@ - + Show lobby chat - + Switch keyboard focus to bet-input-field if it's your turn - + Activate the "accidentally call after big raise" blocker - + Do not hide avatars of players which are on the ignore list - + Disable emoticons in the chat + + + + Show multicolor network state display in the corner of the avatar + + + diff --git a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp index 294f93af..29a2ddcb 100644 --- a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp +++ b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp @@ -287,6 +287,7 @@ void settingsDialogImpl::prepareDialog() checkBox_showFlipCardsAnimation->setChecked(myConfig->readConfigInt("ShowFlipCardsAnimation")); checkBox_showBlindButtons->setChecked(myConfig->readConfigInt("ShowBlindButtons")); checkBox_showCountryFlagInAvatar->setChecked(myConfig->readConfigInt("ShowCountryFlagInAvatar")); + checkBox_showPingStateInAvatar->setChecked(myConfig->readConfigInt("ShowPingStateInAvatar")); checkBox_antiPeekMode->setChecked(myConfig->readConfigInt("AntiPeekMode")); checkBox_enableBetInputFocusSwitch->setChecked(myConfig->readConfigInt("EnableBetInputFocusSwitch")); checkBox_cardsChanceMonitor->setChecked(myConfig->readConfigInt("ShowCardsChanceMonitor")); @@ -738,6 +739,7 @@ void settingsDialogImpl::isAccepted() myConfig->writeConfigInt("ShowCardsChanceMonitor", checkBox_cardsChanceMonitor->isChecked()); myConfig->writeConfigInt("AntiPeekMode", checkBox_antiPeekMode->isChecked()); myConfig->writeConfigInt("ShowCountryFlagInAvatar", checkBox_showCountryFlagInAvatar->isChecked()); + myConfig->writeConfigInt("ShowPingStateInAvatar", checkBox_showPingStateInAvatar->isChecked()); myConfig->writeConfigInt("DontTranslateInternationalPokerStringsFromStyle", checkBox_dontTranslatePokerStrings->isChecked()); myConfig->writeConfigInt("DisableSplashScreenOnStartup", checkBox_disableSplashscreen->isChecked()); myConfig->writeConfigInt("EnableBetInputFocusSwitch", checkBox_enableBetInputFocusSwitch->isChecked());