gui part for #239 server ping state display

This commit is contained in:
doitux
2013-12-11 15:54:29 +01:00
parent 7fb8a8e948
commit 3997a40f09
9 changed files with 117 additions and 43 deletions
+6 -1
View File
@@ -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);
}
+2
View File
@@ -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:
+47 -3
View File
@@ -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<Session> 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 = "<b>"+tr("Server response times")+"</b>";
toolTip.append("<br>"+tr("Average: ")+QString("%1").arg(myAvgPing)+tr("ms"));
toolTip.append("<br>"+tr("Minimum: ")+QString("%1").arg(myMinPing)+tr("ms"));
toolTip.append("<br>"+tr("Maximum: ")+QString("%1").arg(myMaxPing)+tr("ms"));
this->setToolTip(toolTip);
}
else {
this->setToolTip("");
}
}
+6
View File
@@ -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