Merge pull request #2071 from Cockatrice/game_view_time
Game Viewer Update
This commit is contained in:
commit
8cd5803556
3 changed files with 39 additions and 32 deletions
|
@ -36,7 +36,7 @@ GameSelector::GameSelector(AbstractClient *_client, const TabSupervisor *_tabSup
|
||||||
gameListView->setAlternatingRowColors(true);
|
gameListView->setAlternatingRowColors(true);
|
||||||
gameListView->setRootIsDecorated(true);
|
gameListView->setRootIsDecorated(true);
|
||||||
// game created width
|
// game created width
|
||||||
gameListView->resizeColumnToContents(1);
|
gameListView->setColumnWidth(1, gameListView->columnWidth(2) * 0.7);
|
||||||
// players width
|
// players width
|
||||||
gameListView->resizeColumnToContents(6);
|
gameListView->resizeColumnToContents(6);
|
||||||
// description width
|
// description width
|
||||||
|
|
|
@ -13,30 +13,21 @@ enum GameListColumn {ROOM, CREATED, DESCRIPTION, CREATOR, GAME_TYPE, RESTRICTION
|
||||||
const QString GamesModel::getGameCreatedString(const int secs) const {
|
const QString GamesModel::getGameCreatedString(const int secs) const {
|
||||||
|
|
||||||
QString ret;
|
QString ret;
|
||||||
if (secs < SECS_PER_MIN)
|
if (secs < SECS_PER_MIN * 2) // for first min we display "New"
|
||||||
ret = tr("<1m ago");
|
ret = tr("New");
|
||||||
else if (secs < SECS_PER_MIN * 5)
|
else if (secs < SECS_PER_MIN * 10) // from 2 - 10 mins we show the mins
|
||||||
ret = tr("<5m ago");
|
ret = QString("%1 min").arg(QString::number(secs / SECS_PER_MIN));
|
||||||
else if (secs < SECS_PER_HOUR)
|
else if (secs < SECS_PER_MIN * 60) { // from 10 mins to 1h we aggregate every 10 mins
|
||||||
ret = tr("%1m ago").arg(QString::number(secs / SECS_PER_MIN));
|
int unitOfTen = secs / SECS_PER_TEN_MIN;
|
||||||
else if (secs < SECS_PER_MIN * 90) {
|
QString str = "%1%2";
|
||||||
ret = tr("1hr %1m ago").arg(QString::number((secs / SECS_PER_MIN) - 60));
|
ret = str.arg(QString::number(unitOfTen), "0+ min");
|
||||||
} else if (secs < SECS_PER_HOUR * 4) {
|
} else { // from 1 hr onward we show hrs
|
||||||
unsigned int hours = secs / SECS_PER_HOUR;
|
int hours = secs / SECS_PER_HOUR;
|
||||||
if (secs % SECS_PER_HOUR >= SECS_PER_MIN * 30)
|
if (secs % SECS_PER_HOUR >= SECS_PER_MIN * 30) // if the room is open for 1hr 30 mins, we round to 2hrs
|
||||||
hours++;
|
hours++;
|
||||||
ret = tr("%1hr ago").arg(QString::number(hours));
|
ret = QString("%1+ h").arg(QString::number(hours));
|
||||||
} else
|
}
|
||||||
ret = tr("5+ hrs ago");
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/*
|
|
||||||
todo
|
|
||||||
. would like less if()
|
|
||||||
. would like less code repition
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent)
|
GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent)
|
||||||
|
@ -67,6 +58,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole: return getGameCreatedString(secs);
|
case Qt::DisplayRole: return getGameCreatedString(secs);
|
||||||
case SORT_ROLE: return QVariant(secs);
|
case SORT_ROLE: return QVariant(secs);
|
||||||
|
case Qt::TextAlignmentRole: return Qt::AlignCenter;
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +127,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
return QString("%1/%2").arg(g.player_count()).arg(g.max_players());
|
||||||
case Qt::TextAlignmentRole:
|
case Qt::TextAlignmentRole:
|
||||||
return Qt::AlignLeft;
|
return Qt::AlignCenter;
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -174,18 +166,32 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant GamesModel::headerData(int section, Qt::Orientation /*orientation*/, int role) const
|
||||||
{
|
{
|
||||||
if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal))
|
if ((role != Qt::DisplayRole) && (role != Qt::TextAlignmentRole))
|
||||||
return QVariant();
|
return QVariant();
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case ROOM: return tr("Room");
|
case ROOM: return tr("Room");
|
||||||
case CREATED: return tr("Game Created");
|
case CREATED: {
|
||||||
|
switch(role) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return tr("Age");
|
||||||
|
case Qt::TextAlignmentRole:
|
||||||
|
return Qt::AlignCenter;
|
||||||
|
}
|
||||||
|
}
|
||||||
case DESCRIPTION: return tr("Description");
|
case DESCRIPTION: return tr("Description");
|
||||||
case CREATOR: return tr("Creator");
|
case CREATOR: return tr("Creator");
|
||||||
case GAME_TYPE: return tr("Game Type");
|
case GAME_TYPE: return tr("Type");
|
||||||
case RESTRICTIONS: return tr("Restrictions");
|
case RESTRICTIONS: return tr("Restrictions");
|
||||||
case PLAYERS: return tr("Players");
|
case PLAYERS: {
|
||||||
|
switch(role) {
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return tr("Players");
|
||||||
|
case Qt::TextAlignmentRole:
|
||||||
|
return Qt::AlignCenter;
|
||||||
|
}
|
||||||
|
}
|
||||||
case SPECTATORS: return tr("Spectators");
|
case SPECTATORS: return tr("Spectators");
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,8 @@
|
||||||
#include "gametypemap.h"
|
#include "gametypemap.h"
|
||||||
#include "pb/serverinfo_game.pb.h"
|
#include "pb/serverinfo_game.pb.h"
|
||||||
|
|
||||||
class ServerInfo_User;
|
|
||||||
|
|
||||||
class GamesModel : public QAbstractTableModel {
|
class GamesModel : public QAbstractTableModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QList<ServerInfo_Game> gameList;
|
QList<ServerInfo_Game> gameList;
|
||||||
QMap<int, QString> rooms;
|
QMap<int, QString> rooms;
|
||||||
|
@ -19,6 +17,7 @@ private:
|
||||||
|
|
||||||
static const int NUM_COLS = 8;
|
static const int NUM_COLS = 8;
|
||||||
static const int SECS_PER_MIN = 60;
|
static const int SECS_PER_MIN = 60;
|
||||||
|
static const int SECS_PER_TEN_MIN = 600;
|
||||||
static const int SECS_PER_HOUR = 3600;
|
static const int SECS_PER_HOUR = 3600;
|
||||||
public:
|
public:
|
||||||
static const int SORT_ROLE = Qt::UserRole+1;
|
static const int SORT_ROLE = Qt::UserRole+1;
|
||||||
|
@ -42,6 +41,8 @@ public:
|
||||||
const QMap<int, GameTypeMap> &getGameTypes() { return gameTypes; }
|
const QMap<int, GameTypeMap> &getGameTypes() { return gameTypes; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ServerInfo_User;
|
||||||
|
|
||||||
class GamesProxyModel : public QSortFilterProxyModel {
|
class GamesProxyModel : public QSortFilterProxyModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue