Skip to content

Commit 168b80d

Browse files
Pesastenzek
authored andcommitted
Qt: Add tooltips to game list
1 parent df65879 commit 168b80d

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

src/duckstation-qt/gamelistwidget.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -544,23 +544,19 @@ QVariant GameListModel::data(const QModelIndex& index, int role, const GameList:
544544

545545
case Column_Year:
546546
{
547-
if (ge->dbentry && ge->dbentry->release_date != 0)
548-
{
549-
return QStringLiteral("%1").arg(
550-
QDateTime::fromSecsSinceEpoch(static_cast<qint64>(ge->dbentry->release_date), QTimeZone::utc())
551-
.date()
552-
.year());
553-
}
554-
else
555-
{
556-
return QString();
557-
}
547+
if (!ge->dbentry || ge->dbentry->release_date == 0)
548+
return {};
549+
550+
return QString::number(
551+
QDateTime::fromSecsSinceEpoch(static_cast<qint64>(ge->dbentry->release_date), QTimeZone::utc())
552+
.date()
553+
.year());
558554
}
559555

560556
case Column_Players:
561557
{
562558
if (!ge->dbentry || ge->dbentry->min_players == 0)
563-
return QString();
559+
return {};
564560
else if (ge->dbentry->min_players == ge->dbentry->max_players)
565561
return QStringLiteral("%1").arg(ge->dbentry->min_players);
566562
else
@@ -596,6 +592,9 @@ QVariant GameListModel::data(const QModelIndex& index, int role, const GameList:
596592
else
597593
return {};
598594
}
595+
596+
default:
597+
return {};
599598
}
600599
}
601600

@@ -651,6 +650,30 @@ QVariant GameListModel::data(const QModelIndex& index, int role, const GameList:
651650
const_cast<GameListModel*>(this)->loadOrGenerateCover(ge);
652651
return *m_cover_pixmap_cache.Insert(ge->path, m_loading_pixmap);
653652
}
653+
654+
default:
655+
return {};
656+
}
657+
}
658+
659+
case Qt::ToolTipRole:
660+
{
661+
switch (index.column())
662+
{
663+
case Column_TimePlayed:
664+
if (ge->total_played_time == 0)
665+
return {};
666+
else
667+
return QtUtils::StringViewToQString(GameList::FormatTimespan(ge->total_played_time, false));
668+
669+
case Column_LastPlayed:
670+
if (ge->last_played_time == 0)
671+
return {};
672+
else
673+
return QtHost::FormatNumber(Host::NumberFormatType::LongDateTime, static_cast<s64>(ge->last_played_time));
674+
675+
default:
676+
return {};
654677
}
655678
}
656679
}

0 commit comments

Comments
 (0)