mirror of
https://github.com/stenzek/duckstation.git
synced 2026-02-15 02:44:41 +00:00
Qt: Remove multiple source of truth for column titles
This commit is contained in:
@@ -59,9 +59,17 @@ static const char* SUPPORTED_FORMATS_STRING =
|
||||
".chd (Compressed Hunks of Data)\n"
|
||||
".pbp (PlayStation Portable, Only Decrypted)");
|
||||
|
||||
static constexpr std::array<const char*, GameListModel::Column_Count> s_column_names = {
|
||||
{"Icon", "Serial", "Title", "File Title", "Developer", "Publisher", "Genre", "Year", "Players", "Time Played",
|
||||
"Last Played", "Size", "File Size", "Region", "Achievements", "Compatibility", "Cover"}};
|
||||
static constexpr std::array<const char*, GameListModel::Column_Count> s_column_names = {{
|
||||
QT_TRANSLATE_NOOP("GameListModel", "Icon"), QT_TRANSLATE_NOOP("GameListModel", "Serial"),
|
||||
QT_TRANSLATE_NOOP("GameListModel", "Title"), QT_TRANSLATE_NOOP("GameListModel", "File Title"),
|
||||
QT_TRANSLATE_NOOP("GameListModel", "Developer"), QT_TRANSLATE_NOOP("GameListModel", "Publisher"),
|
||||
QT_TRANSLATE_NOOP("GameListModel", "Genre"), QT_TRANSLATE_NOOP("GameListModel", "Year"),
|
||||
QT_TRANSLATE_NOOP("GameListModel", "Players"), QT_TRANSLATE_NOOP("GameListModel", "Time Played"),
|
||||
QT_TRANSLATE_NOOP("GameListModel", "Last Played"), QT_TRANSLATE_NOOP("GameListModel", "Size"),
|
||||
QT_TRANSLATE_NOOP("GameListModel", "File Size"), QT_TRANSLATE_NOOP("GameListModel", "Region"),
|
||||
QT_TRANSLATE_NOOP("GameListModel", "Achievements"), QT_TRANSLATE_NOOP("GameListModel", "Compatibility"),
|
||||
"Cover", // Do not translate.
|
||||
}};
|
||||
|
||||
static constexpr int COVER_ART_SIZE = 512;
|
||||
static constexpr int COVER_ART_SPACING = 32;
|
||||
@@ -162,7 +170,6 @@ GameListModel::GameListModel(GameListWidget* parent)
|
||||
m_show_game_icons = Host::GetBaseBoolSettingValue("UI", "GameListShowGameIcons", true);
|
||||
|
||||
loadCommonImages();
|
||||
setColumnDisplayNames();
|
||||
updateCoverScale();
|
||||
|
||||
if (m_show_game_icons)
|
||||
@@ -833,10 +840,11 @@ QVariant GameListModel::data(const QModelIndex& index, int role, const GameList:
|
||||
|
||||
QVariant GameListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation != Qt::Horizontal || role != Qt::DisplayRole || section < 0 || section >= Column_Count)
|
||||
return {};
|
||||
QVariant ret;
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section < Column_Count)
|
||||
ret = qApp->translate("GameListModel", s_column_names[static_cast<u32>(section)]);
|
||||
|
||||
return m_column_display_names[section];
|
||||
return ret;
|
||||
}
|
||||
|
||||
const GameList::Entry* GameListModel::getTakenGameListEntry(u32 index) const
|
||||
@@ -1104,26 +1112,6 @@ void GameListModel::loadCommonImages()
|
||||
.pixmap(ACHIEVEMENT_ICON_SIZE, m_device_pixel_ratio);
|
||||
}
|
||||
|
||||
void GameListModel::setColumnDisplayNames()
|
||||
{
|
||||
m_column_display_names[Column_Icon] = tr("Icon");
|
||||
m_column_display_names[Column_Serial] = tr("Serial");
|
||||
m_column_display_names[Column_Title] = tr("Title");
|
||||
m_column_display_names[Column_FileTitle] = tr("File Title");
|
||||
m_column_display_names[Column_Developer] = tr("Developer");
|
||||
m_column_display_names[Column_Publisher] = tr("Publisher");
|
||||
m_column_display_names[Column_Genre] = tr("Genre");
|
||||
m_column_display_names[Column_Year] = tr("Year");
|
||||
m_column_display_names[Column_Players] = tr("Players");
|
||||
m_column_display_names[Column_Achievements] = tr("Achievements");
|
||||
m_column_display_names[Column_TimePlayed] = tr("Time Played");
|
||||
m_column_display_names[Column_LastPlayed] = tr("Last Played");
|
||||
m_column_display_names[Column_FileSize] = tr("Size");
|
||||
m_column_display_names[Column_UncompressedSize] = tr("Raw Size");
|
||||
m_column_display_names[Column_Region] = tr("Region");
|
||||
m_column_display_names[Column_Compatibility] = tr("Compatibility");
|
||||
}
|
||||
|
||||
class GameListSortModel final : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
@@ -1925,7 +1913,7 @@ void GameListListView::setFixedColumnWidth(int column, int width)
|
||||
void GameListListView::setFixedColumnWidth(const QFontMetrics& fm, int column, int str_width)
|
||||
{
|
||||
const int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr, this);
|
||||
const int header_width = fm.size(0, m_model->getColumnDisplayName(column)).width() +
|
||||
const int header_width = fm.size(0, m_model->headerData(column, Qt::Horizontal, Qt::DisplayRole).toString()).width() +
|
||||
style()->pixelMetric(QStyle::PM_HeaderMarkSize, nullptr, this) + // sort indicator
|
||||
margin; // space between text and sort indicator
|
||||
const int width = std::max(header_width, str_width) + 2 * margin; // left and right margins
|
||||
@@ -2062,7 +2050,7 @@ void GameListListView::onHeaderContextMenuRequested(const QPoint& point)
|
||||
if (column == GameListModel::Column_Cover)
|
||||
continue;
|
||||
|
||||
QAction* action = menu.addAction(m_model->getColumnDisplayName(column));
|
||||
QAction* const action = menu.addAction(m_model->headerData(column, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
action->setCheckable(true);
|
||||
action->setChecked(!isColumnHidden(column));
|
||||
connect(action, &QAction::triggered, [this, column](bool enabled) { setAndSaveColumnHidden(column, !enabled); });
|
||||
|
||||
@@ -56,7 +56,9 @@ public:
|
||||
Column_Compatibility,
|
||||
Column_Cover,
|
||||
|
||||
Column_Count
|
||||
Column_Count,
|
||||
|
||||
Column_LastVisible = Column_Compatibility,
|
||||
};
|
||||
|
||||
static std::optional<Column> getColumnIdForName(std::string_view name);
|
||||
@@ -70,7 +72,6 @@ public:
|
||||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
|
||||
ALWAYS_INLINE const QString& getColumnDisplayName(int column) const { return m_column_display_names[column]; }
|
||||
ALWAYS_INLINE const QPixmap& getNoAchievementsPixmap() const { return m_no_achievements_pixmap; }
|
||||
ALWAYS_INLINE const QPixmap& getHasAchievementsPixmap() const { return m_has_achievements_pixmap; }
|
||||
ALWAYS_INLINE const QPixmap& getMasteredAchievementsPixmap() const { return m_mastered_achievements_pixmap; }
|
||||
@@ -122,7 +123,6 @@ private:
|
||||
|
||||
void loadCommonImages();
|
||||
void loadSizeDependentPixmaps();
|
||||
void setColumnDisplayNames();
|
||||
void updateCoverScale();
|
||||
void loadOrGenerateCover(const GameList::Entry* ge);
|
||||
void invalidateCoverForPath(const std::string& path);
|
||||
@@ -148,7 +148,6 @@ private:
|
||||
bool m_show_titles_for_covers = false;
|
||||
bool m_show_game_icons = false;
|
||||
|
||||
std::array<QString, Column_Count> m_column_display_names;
|
||||
std::array<QPixmap, static_cast<int>(GameList::EntryType::MaxCount)> m_type_pixmaps;
|
||||
std::array<QPixmap, static_cast<int>(GameDatabase::CompatibilityRating::Count)> m_compatibility_pixmaps;
|
||||
|
||||
|
||||
@@ -1842,68 +1842,56 @@ void MainWindow::setupAdditionalUi()
|
||||
|
||||
// View > Sort By
|
||||
{
|
||||
const GameListModel::Column DEFAULT_SORT_COLUMN = GameListModel::Column_Icon;
|
||||
const bool DEFAULT_SORT_DESCENDING = false;
|
||||
const int current_sort_column = m_game_list_widget->getListView()->horizontalHeader()->sortIndicatorSection();
|
||||
const Qt::SortOrder current_sort_order =
|
||||
m_game_list_widget->getListView()->horizontalHeader()->sortIndicatorOrder();
|
||||
|
||||
const GameListModel::Column sort_column =
|
||||
GameListModel::getColumnIdForName(Host::GetBaseStringSettingValue("GameListTableView", "SortColumn"))
|
||||
.value_or(DEFAULT_SORT_COLUMN);
|
||||
QActionGroup* const column_group = new QActionGroup(this);
|
||||
QActionGroup* const order_group = new QActionGroup(this);
|
||||
|
||||
const bool sort_descending =
|
||||
Host::GetBaseBoolSettingValue("GameListTableView", "SortDescending", DEFAULT_SORT_DESCENDING);
|
||||
const Qt::SortOrder sort_order = sort_descending ? Qt::DescendingOrder : Qt::AscendingOrder;
|
||||
|
||||
QAction* action;
|
||||
GameListModel* model = m_game_list_widget->getModel();
|
||||
GameListListView* list_view = m_game_list_widget->getListView();
|
||||
|
||||
QActionGroup* column_group = new QActionGroup(this);
|
||||
QActionGroup* order_group = new QActionGroup(this);
|
||||
|
||||
for (int i = 0; i < model->Column_Count - 1; i++)
|
||||
for (int i = 0; i <= GameListModel::Column_LastVisible; i++)
|
||||
{
|
||||
const QString& column_name = model->getColumnDisplayName(i);
|
||||
|
||||
action = new QAction(column_name);
|
||||
QAction* const action =
|
||||
new QAction(m_game_list_widget->getModel()->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
action->setCheckable(true);
|
||||
action->setChecked(sort_column == i);
|
||||
action->setChecked(current_sort_column == i);
|
||||
column_group->addAction(action);
|
||||
m_ui.menuSortBy->addAction(action);
|
||||
|
||||
connect(action, &QAction::triggered, [list_view, i] {
|
||||
const Qt::SortOrder order = list_view->horizontalHeader()->sortIndicatorOrder();
|
||||
list_view->horizontalHeader()->setSortIndicator(i, order);
|
||||
connect(action, &QAction::triggered, [this, i] {
|
||||
const Qt::SortOrder order = m_game_list_widget->getListView()->horizontalHeader()->sortIndicatorOrder();
|
||||
m_game_list_widget->getListView()->horizontalHeader()->setSortIndicator(i, order);
|
||||
});
|
||||
}
|
||||
|
||||
m_ui.menuSortBy->addSeparator();
|
||||
|
||||
action = new QAction(tr("&Ascending"));
|
||||
action->setIcon(QIcon::fromTheme(QStringLiteral("go-up")));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(sort_order == Qt::AscendingOrder);
|
||||
order_group->addAction(action);
|
||||
m_ui.menuSortBy->addAction(action);
|
||||
connect(action, &QAction::triggered, [list_view] {
|
||||
const int section = list_view->horizontalHeader()->sortIndicatorSection();
|
||||
list_view->horizontalHeader()->setSortIndicator(section, Qt::AscendingOrder);
|
||||
QAction* const ascending_action = new QAction(tr("&Ascending"));
|
||||
ascending_action->setIcon(QIcon::fromTheme(QStringLiteral("go-up")));
|
||||
ascending_action->setCheckable(true);
|
||||
ascending_action->setChecked(current_sort_order == Qt::AscendingOrder);
|
||||
order_group->addAction(ascending_action);
|
||||
m_ui.menuSortBy->addAction(ascending_action);
|
||||
connect(ascending_action, &QAction::triggered, [this] {
|
||||
const int section = m_game_list_widget->getListView()->horizontalHeader()->sortIndicatorSection();
|
||||
m_game_list_widget->getListView()->horizontalHeader()->setSortIndicator(section, Qt::AscendingOrder);
|
||||
});
|
||||
|
||||
action = new QAction(tr("&Descending"));
|
||||
action->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
|
||||
action->setCheckable(true);
|
||||
action->setChecked(sort_order == Qt::DescendingOrder);
|
||||
order_group->addAction(action);
|
||||
m_ui.menuSortBy->addAction(action);
|
||||
connect(action, &QAction::triggered, [list_view] {
|
||||
const int section = list_view->horizontalHeader()->sortIndicatorSection();
|
||||
list_view->horizontalHeader()->setSortIndicator(section, Qt::DescendingOrder);
|
||||
QAction* const descending_action = new QAction(tr("&Descending"));
|
||||
descending_action->setIcon(QIcon::fromTheme(QStringLiteral("go-down")));
|
||||
descending_action->setCheckable(true);
|
||||
descending_action->setChecked(current_sort_order == Qt::DescendingOrder);
|
||||
order_group->addAction(descending_action);
|
||||
m_ui.menuSortBy->addAction(descending_action);
|
||||
connect(descending_action, &QAction::triggered, [this] {
|
||||
const int section = m_game_list_widget->getListView()->horizontalHeader()->sortIndicatorSection();
|
||||
m_game_list_widget->getListView()->horizontalHeader()->setSortIndicator(section, Qt::DescendingOrder);
|
||||
});
|
||||
}
|
||||
|
||||
for (u32 scale = 1; scale <= 10; scale++)
|
||||
{
|
||||
QAction* action = m_ui.menuWindowSize->addAction(tr("%1x Scale").arg(scale));
|
||||
QAction* const action = m_ui.menuWindowSize->addAction(tr("%1x Scale").arg(scale));
|
||||
connect(action, &QAction::triggered, [scale]() { g_emu_thread->requestDisplaySize(scale); });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user