GUI fixes + log stacking (#2897)

* Add Stacking option to log contextmenu

Squashed commit:

[69f296af] cleanup

[4f4bf41f] use contextmenu instead

[e67036bc] use gui settings instead (+1 squashed commits)

Squashed commits:

[b3913dbe] fix backwards selection (+1 squashed commits)

Squashed commits:

[1e150f04] add stacking option (+3 squashed commit)

Squashed commit:

[be78da4f] fix scroll

[d3450c21] fix clearSelection

[e962ec9c] fix log color issue

* fix recent games related app crash

* gamelist improvements

Squashed commit:

[aa1f79c2] fix title names & con background

[d8381984] fix gamelist search

* finally fix show menu bug

* add rows to gamelist: resolutions, sound formats and parental level

* fix gamelist loadsettings
This commit is contained in:
Megamouse 2017-06-30 14:41:40 +02:00 committed by Ivan
parent 645f0e63ab
commit fd4a153eef
9 changed files with 257 additions and 59 deletions

View file

@ -161,16 +161,31 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> settings, Render_
gameList->verticalHeader()->setMaximumSectionSize(m_Icon_Size.height());
gameList->verticalHeader()->setVisible(false);
gameList->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
gameList->horizontalHeader()->setHighlightSections(false);
gameList->horizontalHeader()->setSortIndicatorShown(true);
gameList->horizontalHeader()->setStretchLastSection(true);
gameList->horizontalHeader()->setDefaultSectionSize(150);
gameList->setContextMenuPolicy(Qt::CustomContextMenu);
gameList->setAlternatingRowColors(true);
gameList->setStyleSheet("alternate-background-color: rgb(242, 242, 242);");
gameList->setColumnCount(7);
gameList->setColumnCount(10);
gameList->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Icon")));
gameList->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Name")));
gameList->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Serial")));
gameList->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("FW")));
gameList->setHorizontalHeaderItem(4, new QTableWidgetItem(tr("App version")));
gameList->setHorizontalHeaderItem(3, new QTableWidgetItem(tr("Firmware")));
gameList->setHorizontalHeaderItem(4, new QTableWidgetItem(tr("Version")));
gameList->setHorizontalHeaderItem(5, new QTableWidgetItem(tr("Category")));
gameList->setHorizontalHeaderItem(6, new QTableWidgetItem(tr("Path")));
gameList->setHorizontalHeaderItem(7, new QTableWidgetItem(tr("Supported Resolutions")));
gameList->setHorizontalHeaderItem(8, new QTableWidgetItem(tr("Sound Formats")));
gameList->setHorizontalHeaderItem(9, new QTableWidgetItem(tr("Parental Level")));
// since this won't work somehow: gameList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
for (int i = 0; i < gameList->horizontalHeader()->count(); i++)
{
gameList->horizontalHeaderItem(i)->setTextAlignment(Qt::AlignLeft);
}
m_Central_Widget = new QStackedWidget(this);
m_Central_Widget->addWidget(gameList);
@ -183,18 +198,22 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> settings, Render_
showIconColAct = new QAction(tr("Show Icons"), this);
showNameColAct = new QAction(tr("Show Names"), this);
showSerialColAct = new QAction(tr("Show Serials"), this);
showFWColAct = new QAction(tr("Show FWs"), this);
showAppVersionColAct = new QAction(tr("Show App Versions"), this);
showFWColAct = new QAction(tr("Show Firmwares"), this);
showAppVersionColAct = new QAction(tr("Show Versions"), this);
showCategoryColAct = new QAction(tr("Show Categories"), this);
showPathColAct = new QAction(tr("Show Paths"), this);
showResolutionColAct = new QAction(tr("Show Supported Resolutions"), this);
showSoundFormatColAct = new QAction(tr("Show Sound Formats"), this);
showParentalLevelColAct = new QAction(tr("Show Parental Levels"), this);
columnActs = { showIconColAct, showNameColAct, showSerialColAct, showFWColAct, showAppVersionColAct, showCategoryColAct, showPathColAct };
columnActs = { showIconColAct, showNameColAct, showSerialColAct, showFWColAct, showAppVersionColAct, showCategoryColAct, showPathColAct,
showResolutionColAct, showSoundFormatColAct, showParentalLevelColAct };
// Events
connect(gameList, &QTableWidget::customContextMenuRequested, this, &game_list_frame::ShowContextMenu);
connect(gameList->horizontalHeader(), &QHeaderView::customContextMenuRequested, [=](const QPoint& pos) {
QMenu* configure = new QMenu(this);
configure->addActions({ showIconColAct, showNameColAct, showSerialColAct, showFWColAct, showAppVersionColAct, showCategoryColAct, showPathColAct });
configure->addActions(columnActs);
configure->exec(mapToGlobal(pos));
});
connect(gameList, &QTableWidget::doubleClicked, this, &game_list_frame::doubleClickedSlot);
@ -236,42 +255,45 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> settings, Render_
gameList->setColumnHidden(col, !val); // Negate because it's a set col hidden and we have menu say show.
xgui_settings->SetGamelistColVisibility(col, val);
};
columnActs[col]->setChecked(xgui_settings->GetGamelistColVisibility(col));
connect(columnActs[col], &QAction::triggered, l_CallBack);
}
// Init
LoadSettings();
}
void game_list_frame::LoadSettings()
{
QByteArray state = xgui_settings->GetValue(GUI::gl_state).toByteArray();
if (state.isEmpty())
{ // If no settings exist, go to default.
if (gameList->rowCount() > 0)
{
gameList->verticalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
gameList->horizontalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
gameList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
}
}
else
{
gameList->horizontalHeader()->restoreState(state);
}
for (int col = 0; col < columnActs.count(); ++col)
{
bool vis = xgui_settings->GetGamelistColVisibility(col);
columnActs[col]->setChecked(vis);
gameList->setColumnHidden(col, !vis);
}
bool sortAsc = Qt::SortOrder(xgui_settings->GetValue(GUI::gl_sortAsc).toBool());
m_colSortOrder = sortAsc ? Qt::AscendingOrder : Qt::DescendingOrder;
gameList->horizontalHeader()->restoreState(gameList->horizontalHeader()->saveState());
gameList->horizontalHeader()->stretchLastSection();
m_colSortOrder = xgui_settings->GetValue(GUI::gl_sortAsc).toBool() ? Qt::AscendingOrder : Qt::DescendingOrder;
m_sortColumn = xgui_settings->GetValue(GUI::gl_sortCol).toInt();
m_categoryFilters = xgui_settings->GetGameListCategoryFilters();
if (state.isEmpty())
{ // If no settings exist, go to default.
gameList->verticalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
gameList->horizontalHeader()->resizeSections(QHeaderView::ResizeMode::ResizeToContents);
gameList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
}
else
{
gameList->horizontalHeader()->restoreState(state);
}
Refresh(true);
}
@ -306,19 +328,16 @@ void game_list_frame::FilterData()
for (int i = 0; i < gameList->rowCount(); ++i)
{
bool match = false;
for (auto filter : m_categoryFilters)
const QString category = qstr(m_game_data[i].info.category);
for (const auto& filter : m_categoryFilters)
{
for (int j = 0; j < gameList->columnCount(); ++j)
if (category.contains(filter))
{
if (gameList->horizontalHeaderItem(j)->text() == tr("Category") && gameList->item(i, j)->text().contains(filter))
{
match = true;
goto OutOfThis;
}
match = true;
break;
}
}
OutOfThis:
gameList->setRowHidden(i, !match);
gameList->setRowHidden(i, !match || !SearchMatchesApp(m_game_data[i].info.name, m_game_data[i].info.serial));
}
}
@ -354,10 +373,10 @@ void game_list_frame::Refresh(bool fromDrive)
GameInfo game;
game.root = entry.name;
game.serial = psf::get_string(psf, "TITLE_ID", "");
game.name = psf::get_string(psf, "TITLE", "unknown");
game.app_ver = psf::get_string(psf, "APP_VER", "unknown");
game.category = psf::get_string(psf, "CATEGORY", "unknown");
game.fw = psf::get_string(psf, "PS3_SYSTEM_VER", "unknown");
game.name = psf::get_string(psf, "TITLE", sstr(category::unknown));
game.app_ver = psf::get_string(psf, "APP_VER", sstr(category::unknown));
game.category = psf::get_string(psf, "CATEGORY", sstr(category::unknown));
game.fw = psf::get_string(psf, "PS3_SYSTEM_VER", sstr(category::unknown));
game.parental_lvl = psf::get_integer(psf, "PARENTAL_LEVEL");
game.resolution = psf::get_integer(psf, "RESOLUTION");
game.sound_format = psf::get_integer(psf, "SOUND_FORMAT");
@ -383,12 +402,13 @@ void game_list_frame::Refresh(bool fromDrive)
game.icon_path = dir + "/ICON0.PNG";
game.category = sstr(cat->second);
}
else if (game.category == "unknown")
else if (game.category == sstr(category::unknown))
{
game.category = sstr(category::unknown);
game.icon_path = dir + "/ICON0.PNG";
}
else
{
game.icon_path = dir + "/ICON0.PNG";
game.category = sstr(category::other);
}
@ -398,7 +418,11 @@ void game_list_frame::Refresh(bool fromDrive)
if (!game.icon_path.empty() && img.load(qstr(game.icon_path)))
{
QImage scaled = img.scaled(m_Icon_Size, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation);
QImage scaled = QImage(m_Icon_Size, QImage::Format_ARGB32);
scaled.fill(QColor(209, 209, 209, 255));
QPainter painter(&scaled);
painter.drawImage(QPoint(0,0), img.scaled(m_Icon_Size, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));
painter.end();
pxmap = QPixmap::fromImage(scaled);
}
else
@ -458,7 +482,7 @@ void game_list_frame::Refresh(bool fromDrive)
void game_list_frame::ToggleCategoryFilter(const QStringList& categories, bool show)
{
if (show) { m_categoryFilters.append(categories); }
else { for (auto cat : categories) m_categoryFilters.removeAll(cat); }
else { for (const auto& cat : categories) m_categoryFilters.removeAll(cat); }
Refresh();
}
@ -686,7 +710,12 @@ void game_list_frame::ResizeIcons(const QSize& size, const int& idx)
for (size_t i = 0; i < m_game_data.size(); i++)
{
m_game_data[i].pxmap = QPixmap::fromImage(m_game_data[i].icon.scaled(m_Icon_Size, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));
QImage scaled = QImage(m_Icon_Size, QImage::Format_ARGB32);
scaled.fill(QColor(209, 209, 209, 255));
QPainter painter(&scaled);
painter.drawImage(QPoint(0, 0), m_game_data[i].icon.scaled(m_Icon_Size, Qt::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));
painter.end();
m_game_data[i].pxmap = QPixmap::fromImage(scaled);
}
Refresh();
@ -758,15 +787,8 @@ int game_list_frame::PopulateGameList()
};
int row = 0;
for (GUI_GameInfo game : m_game_data)
for (const GUI_GameInfo& game : m_game_data)
{
if (SearchMatchesApp(game.info.name, game.info.serial) == false)
{
// We aren't showing this entry. Decrement row count to avoid empty entries at end.
gameList->setRowCount(gameList->rowCount() - 1);
continue;
}
// Icon
QTableWidgetItem* iconItem = new QTableWidgetItem;
iconItem->setFlags(iconItem->flags() & ~Qt::ItemIsEditable);
@ -780,6 +802,9 @@ int game_list_frame::PopulateGameList()
gameList->setItem(row, 4, l_GetItem(game.info.app_ver));
gameList->setItem(row, 5, l_GetItem(game.info.category));
gameList->setItem(row, 6, l_GetItem(game.info.root));
gameList->setItem(row, 7, l_GetItem(GetStringFromU32(game.info.resolution, resolution::mode, true)));
gameList->setItem(row, 8, l_GetItem(GetStringFromU32(game.info.sound_format, sound::format, true)));
gameList->setItem(row, 9, l_GetItem(GetStringFromU32(game.info.parental_lvl, parental::level)));
if (selected_item == game.info.icon_path) result = row;
@ -811,7 +836,7 @@ void game_list_frame::PopulateGameGrid(uint maxCols, const QSize& image_size)
// Get number of things that'll be in grid and precompute grid size.
int entries = 0;
for (GUI_GameInfo game : m_game_data)
for (const GUI_GameInfo& game : m_game_data)
{
if (qstr(game.info.category) == category::disc_Game || qstr(game.info.category) == category::hdd_Game)
{
@ -910,3 +935,33 @@ std::string game_list_frame::CurrentSelectionIconPath()
return selection;
}
std::string game_list_frame::GetStringFromU32(const u32& key, const std::map<u32, QString>& map, bool combined)
{
QStringList string;
if (combined)
{
for (const auto& item : map)
{
if (key & item.first)
{
string << item.second;
}
}
}
else
{
if (map.find(key) != map.end())
{
string << map.at(key);
}
}
if (string.isEmpty())
{
string << tr("Unknown");
}
return sstr(string.join(", "));
}