Trophy: Save dialog state (#3729)

* Trophy: Save dialog state and add show type settings

* SaveDataManager: Save Dialog State

* SaveDataList: Minor Optimization

* Qt: Save icon size on mouseevent resizes

it's a bit slower than using the slider because it saves every single resize. But better than not saving at all for now

* SaveData: Optimize saving to settings a bit

No Saving needed there

* Qt: get rid of all-uppercase enums and namespaces

* Qt/Linux: adjust remaining DX12 tooltip

* Qt: prevent dockwidget contextmenu
This commit is contained in:
Megamouse 2017-11-22 12:11:59 +01:00 committed by Ivan
parent de465cb941
commit fb52cbb8b2
24 changed files with 607 additions and 436 deletions

View file

@ -25,27 +25,27 @@
#include <QScrollBar>
inline std::string sstr(const QString& _in) { return _in.toUtf8().toStdString(); }
inline QSize sizeFromSlider(const int& pos) { return GUI::gl_icon_size_min + (GUI::gl_icon_size_max - GUI::gl_icon_size_min) * (pos / (float)GUI::gl_max_slider_pos); }
inline QSize sizeFromSlider(const int& pos) { return gui::gl_icon_size_min + (gui::gl_icon_size_max - gui::gl_icon_size_min) * (pos / (float)gui::gl_max_slider_pos); }
game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std::shared_ptr<emu_settings> emuSettings, QWidget *parent)
: QDockWidget(tr("Game List"), parent), xgui_settings(guiSettings), xemu_settings(emuSettings)
{
m_isListLayout = xgui_settings->GetValue(GUI::gl_listMode).toBool();
m_icon_size_index = xgui_settings->GetValue(GUI::gl_iconSize).toInt();
m_Margin_Factor = xgui_settings->GetValue(GUI::gl_marginFactor).toReal();
m_Text_Factor = xgui_settings->GetValue(GUI::gl_textFactor).toReal();
m_showToolBar = xgui_settings->GetValue(GUI::gl_toolBarVisible).toBool();
m_Icon_Color = xgui_settings->GetValue(GUI::gl_iconColor).value<QColor>();
m_colSortOrder = xgui_settings->GetValue(GUI::gl_sortAsc).toBool() ? Qt::AscendingOrder : Qt::DescendingOrder;
m_sortColumn = xgui_settings->GetValue(GUI::gl_sortCol).toInt();
m_isListLayout = xgui_settings->GetValue(gui::gl_listMode).toBool();
m_icon_size_index = xgui_settings->GetValue(gui::gl_iconSize).toInt();
m_Margin_Factor = xgui_settings->GetValue(gui::gl_marginFactor).toReal();
m_Text_Factor = xgui_settings->GetValue(gui::gl_textFactor).toReal();
m_showToolBar = xgui_settings->GetValue(gui::gl_toolBarVisible).toBool();
m_Icon_Color = xgui_settings->GetValue(gui::gl_iconColor).value<QColor>();
m_colSortOrder = xgui_settings->GetValue(gui::gl_sortAsc).toBool() ? Qt::AscendingOrder : Qt::DescendingOrder;
m_sortColumn = xgui_settings->GetValue(gui::gl_sortCol).toInt();
m_oldLayoutIsList = m_isListLayout;
// Save factors for first setup
xgui_settings->SetValue(GUI::gl_iconColor, m_Icon_Color);
xgui_settings->SetValue(GUI::gl_marginFactor, m_Margin_Factor);
xgui_settings->SetValue(GUI::gl_textFactor, m_Text_Factor);
xgui_settings->SetValue(GUI::gl_toolBarVisible, m_showToolBar);
xgui_settings->SetValue(gui::gl_iconColor, m_Icon_Color);
xgui_settings->SetValue(gui::gl_marginFactor, m_Margin_Factor);
xgui_settings->SetValue(gui::gl_textFactor, m_Text_Factor);
xgui_settings->SetValue(gui::gl_toolBarVisible, m_showToolBar);
m_Game_Dock = new QMainWindow(this);
m_Game_Dock->setWindowFlags(Qt::Widget);
@ -57,25 +57,25 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std:
m_Tool_Bar->setContextMenuPolicy(Qt::PreventContextMenu);
// ToolBar Actions
m_catActHDD = { new QAction(""), QIcon(":/Icons/hdd_blue.png"), QIcon(":/Icons/hdd_gray.png"), xgui_settings->GetValue(GUI::cat_hdd_game).toBool() };
m_catActHDD = { new QAction(""), QIcon(":/Icons/hdd_blue.png"), QIcon(":/Icons/hdd_gray.png"), xgui_settings->GetValue(gui::cat_hdd_game).toBool() };
m_catActHDD.action->setToolTip(tr("Show HDD Categories"));
m_catActDisc = { new QAction(""), QIcon(":/Icons/disc_blue.png"), QIcon(":/Icons/disc_gray.png"), xgui_settings->GetValue(GUI::cat_disc_game).toBool() };
m_catActDisc = { new QAction(""), QIcon(":/Icons/disc_blue.png"), QIcon(":/Icons/disc_gray.png"), xgui_settings->GetValue(gui::cat_disc_game).toBool() };
m_catActDisc.action->setToolTip(tr("Show Disc Categories"));
m_catActHome = { new QAction(""), QIcon(":/Icons/home_blue.png"), QIcon(":/Icons/home_gray.png"), xgui_settings->GetValue(GUI::cat_home).toBool() };
m_catActHome = { new QAction(""), QIcon(":/Icons/home_blue.png"), QIcon(":/Icons/home_gray.png"), xgui_settings->GetValue(gui::cat_home).toBool() };
m_catActHome.action->setToolTip(tr("Show Home Categories"));
m_catActAudioVideo = { new QAction(""), QIcon(":/Icons/media_blue.png"), QIcon(":/Icons/media_gray.png"), xgui_settings->GetValue(GUI::cat_audio_video).toBool() };
m_catActAudioVideo = { new QAction(""), QIcon(":/Icons/media_blue.png"), QIcon(":/Icons/media_gray.png"), xgui_settings->GetValue(gui::cat_audio_video).toBool() };
m_catActAudioVideo.action->setToolTip(tr("Show Audio/Video Categories"));
m_catActGameData = { new QAction(""), QIcon(":/Icons/data_blue.png"), QIcon(":/Icons/data_gray.png"), xgui_settings->GetValue(GUI::cat_game_data).toBool() };
m_catActGameData = { new QAction(""), QIcon(":/Icons/data_blue.png"), QIcon(":/Icons/data_gray.png"), xgui_settings->GetValue(gui::cat_game_data).toBool() };
m_catActGameData.action->setToolTip(tr("Show GameData Categories"));
m_catActUnknown = { new QAction(""), QIcon(":/Icons/unknown_blue.png"), QIcon(":/Icons/unknown_gray.png"), xgui_settings->GetValue(GUI::cat_unknown).toBool() };
m_catActUnknown = { new QAction(""), QIcon(":/Icons/unknown_blue.png"), QIcon(":/Icons/unknown_gray.png"), xgui_settings->GetValue(gui::cat_unknown).toBool() };
m_catActUnknown.action->setToolTip(tr("Show Unknown Categories"));
m_catActOther = { new QAction(""), QIcon(":/Icons/other_blue.png"), QIcon(":/Icons/other_gray.png"), xgui_settings->GetValue(GUI::cat_other).toBool() };
m_catActOther = { new QAction(""), QIcon(":/Icons/other_blue.png"), QIcon(":/Icons/other_gray.png"), xgui_settings->GetValue(gui::cat_other).toBool() };
m_catActOther.action->setToolTip(tr("Show Other Categories"));
m_categoryButtons = { &m_catActHDD , &m_catActDisc, &m_catActHome, &m_catActAudioVideo, &m_catActGameData, &m_catActUnknown, &m_catActOther };
@ -109,7 +109,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std:
// Icon Size Slider
m_Slider_Size = new QSlider(Qt::Horizontal , m_Tool_Bar);
m_Slider_Size->setRange(0, GUI::gl_max_slider_pos);
m_Slider_Size->setRange(0, gui::gl_max_slider_pos);
m_Slider_Size->setSliderPosition(m_icon_size_index);
m_Slider_Size->setFixedWidth(m_Tool_Bar->height() * 3);
@ -134,7 +134,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std:
RepaintToolBarIcons();
bool showText = m_icon_size_index < GUI::gl_max_slider_pos;
bool showText = m_icon_size_index < gui::gl_max_slider_pos;
m_Icon_Size = sizeFromSlider(m_icon_size_index);
m_xgrid = new game_list_grid(m_Icon_Size, m_Icon_Color, m_Margin_Factor, m_Text_Factor, showText);
@ -161,17 +161,17 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std:
m_gameList->setAlternatingRowColors(true);
m_gameList->installEventFilter(this);
m_gameList->setColumnCount(GUI::COLUMN_COUNT);
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_ICON, new QTableWidgetItem(tr("Icon")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_NAME, new QTableWidgetItem(tr("Name")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_SERIAL, new QTableWidgetItem(tr("Serial")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_FIRMWARE, new QTableWidgetItem(tr("Firmware")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_VERSION, new QTableWidgetItem(tr("Version")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_CATEGORY, new QTableWidgetItem(tr("Category")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_PATH, new QTableWidgetItem(tr("Path")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_RESOLUTION, new QTableWidgetItem(tr("Supported Resolutions")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_SOUND, new QTableWidgetItem(tr("Sound Formats")));
m_gameList->setHorizontalHeaderItem( GUI::COLUMN_PARENTAL, new QTableWidgetItem(tr("Parental Level")));
m_gameList->setColumnCount(gui::column_count);
m_gameList->setHorizontalHeaderItem(gui::column_icon, new QTableWidgetItem(tr("Icon")));
m_gameList->setHorizontalHeaderItem(gui::column_name, new QTableWidgetItem(tr("Name")));
m_gameList->setHorizontalHeaderItem(gui::column_serial, new QTableWidgetItem(tr("Serial")));
m_gameList->setHorizontalHeaderItem(gui::column_firmware, new QTableWidgetItem(tr("Firmware")));
m_gameList->setHorizontalHeaderItem(gui::column_version, new QTableWidgetItem(tr("Version")));
m_gameList->setHorizontalHeaderItem(gui::column_category, new QTableWidgetItem(tr("Category")));
m_gameList->setHorizontalHeaderItem(gui::column_path, new QTableWidgetItem(tr("Path")));
m_gameList->setHorizontalHeaderItem(gui::column_resolution, new QTableWidgetItem(tr("Supported Resolutions")));
m_gameList->setHorizontalHeaderItem(gui::column_sound, new QTableWidgetItem(tr("Sound Formats")));
m_gameList->setHorizontalHeaderItem(gui::column_parental, new QTableWidgetItem(tr("Parental Level")));
// since this won't work somehow: gameList->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
for (int i = 0; i < m_gameList->horizontalHeader()->count(); i++)
@ -219,7 +219,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std:
connect(m_Search_Bar, &QLineEdit::textChanged, this, &game_list_frame::SetSearchText);
connect(m_Slider_Size, &QSlider::valueChanged, this, &game_list_frame::RequestIconSizeActSet);
connect(m_Slider_Size, &QSlider::sliderReleased, this, [&]{ xgui_settings->SetValue(GUI::gl_iconSize, m_Slider_Size->value()); });
connect(m_Slider_Size, &QSlider::sliderReleased, this, [&]{ xgui_settings->SetValue(gui::gl_iconSize, m_Slider_Size->value()); });
connect(m_Slider_Size, &QSlider::actionTriggered, [&](int action)
{
if (action != QAbstractSlider::SliderNoAction && action != QAbstractSlider::SliderMove)
@ -267,7 +267,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> guiSettings, std:
void game_list_frame::LoadSettings()
{
QByteArray state = xgui_settings->GetValue(GUI::gl_state).toByteArray();
QByteArray state = xgui_settings->GetValue(gui::gl_state).toByteArray();
if (state.isEmpty())
{ // If no settings exist, go to default.
@ -293,11 +293,11 @@ void game_list_frame::LoadSettings()
m_gameList->horizontalHeader()->restoreState(m_gameList->horizontalHeader()->saveState());
m_gameList->horizontalHeader()->stretchLastSection();
m_colSortOrder = xgui_settings->GetValue(GUI::gl_sortAsc).toBool() ? Qt::AscendingOrder : Qt::DescendingOrder;
m_colSortOrder = xgui_settings->GetValue(gui::gl_sortAsc).toBool() ? Qt::AscendingOrder : Qt::DescendingOrder;
m_sortColumn = xgui_settings->GetValue(GUI::gl_sortCol).toInt();
m_sortColumn = xgui_settings->GetValue(gui::gl_sortCol).toInt();
m_Icon_Color = xgui_settings->GetValue(GUI::gl_iconColor).value<QColor>();
m_Icon_Color = xgui_settings->GetValue(gui::gl_iconColor).value<QColor>();
m_categoryFilters = xgui_settings->GetGameListCategoryFilters();
@ -323,8 +323,8 @@ void game_list_frame::OnColClicked(int col)
}
m_sortColumn = col;
xgui_settings->SetValue(GUI::gl_sortAsc, m_colSortOrder == Qt::AscendingOrder);
xgui_settings->SetValue(GUI::gl_sortCol, col);
xgui_settings->SetValue(gui::gl_sortAsc, m_colSortOrder == Qt::AscendingOrder);
xgui_settings->SetValue(gui::gl_sortCol, col);
SortGameList();
}
@ -538,10 +538,10 @@ void game_list_frame::SaveSettings()
{
xgui_settings->SetGamelistColVisibility(col, m_columnActs[col]->isChecked());
}
xgui_settings->SetValue(GUI::gl_sortCol, m_sortColumn);
xgui_settings->SetValue(GUI::gl_sortAsc, m_colSortOrder == Qt::AscendingOrder);
xgui_settings->SetValue(gui::gl_sortCol, m_sortColumn);
xgui_settings->SetValue(gui::gl_sortAsc, m_colSortOrder == Qt::AscendingOrder);
xgui_settings->SetValue(GUI::gl_state, m_gameList->horizontalHeader()->saveState());
xgui_settings->SetValue(gui::gl_state, m_gameList->horizontalHeader()->saveState());
}
static void open_dir(const std::string& spath)
@ -557,7 +557,7 @@ void game_list_frame::doubleClickedSlot(const QModelIndex& index)
if (m_isListLayout)
{
i = m_gameList->item(index.row(), GUI::COLUMN_ICON)->data(Qt::UserRole).toInt();
i = m_gameList->item(index.row(), gui::column_icon)->data(Qt::UserRole).toInt();
}
else
{
@ -584,7 +584,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos)
if (m_isListLayout)
{
int row = m_gameList->indexAt(pos).row();
QTableWidgetItem* item = m_gameList->item(row, GUI::COLUMN_ICON);
QTableWidgetItem* item = m_gameList->item(row, gui::column_icon);
if (item == nullptr) return; // null happens if you are double clicking in dockwidget area on nothing.
index = item->data(Qt::UserRole).toInt();
}
@ -752,7 +752,7 @@ bool game_list_frame::Boot(const GameInfo& game)
}
else
{
Q_EMIT RequestAddRecentGame(GUI::Recent_Game(qstr(Emu.GetBoot()), qstr("[" + game.serial + "] " + game.name)));
Q_EMIT RequestAddRecentGame(gui::Recent_Game(qstr(Emu.GetBoot()), qstr("[" + game.serial + "] " + game.name)));
Refresh(true);
return true;
}
@ -851,13 +851,13 @@ void game_list_frame::RepaintIcons(const bool& fromSettings)
{
if (fromSettings)
{
if (xgui_settings->GetValue(GUI::m_enableUIColors).toBool())
if (xgui_settings->GetValue(gui::m_enableUIColors).toBool())
{
m_Icon_Color = xgui_settings->GetValue(GUI::gl_iconColor).value<QColor>();
m_Icon_Color = xgui_settings->GetValue(gui::gl_iconColor).value<QColor>();
}
else
{
m_Icon_Color = GUI::get_Label_Color("gamelist_icon_background_color");
m_Icon_Color = gui::get_Label_Color("gamelist_icon_background_color");
}
}
@ -879,7 +879,7 @@ void game_list_frame::SetListMode(const bool& isList)
m_oldLayoutIsList = m_isListLayout;
m_isListLayout = isList;
xgui_settings->SetValue(GUI::gl_listMode, isList);
xgui_settings->SetValue(gui::gl_listMode, isList);
m_categoryActs->setEnabled(isList);
m_modeActList.action->setIcon(m_isListLayout ? m_modeActList.colored : m_modeActList.gray);
@ -894,7 +894,7 @@ void game_list_frame::SetToolBarVisible(const bool& showToolBar)
{
m_showToolBar = showToolBar;
m_Tool_Bar->setVisible(showToolBar);
xgui_settings->SetValue(GUI::gl_toolBarVisible, showToolBar);
xgui_settings->SetValue(gui::gl_toolBarVisible, showToolBar);
}
bool game_list_frame::GetToolBarVisible()
{
@ -917,18 +917,18 @@ void game_list_frame::RepaintToolBarIcons()
{
QColor newColor;
if (xgui_settings->GetValue(GUI::m_enableUIColors).toBool())
if (xgui_settings->GetValue(gui::m_enableUIColors).toBool())
{
newColor = xgui_settings->GetValue(GUI::gl_toolIconColor).value<QColor>();
newColor = xgui_settings->GetValue(gui::gl_toolIconColor).value<QColor>();
}
else
{
newColor = GUI::get_Label_Color("gamelist_toolbar_icon_color");
newColor = gui::get_Label_Color("gamelist_toolbar_icon_color");
}
auto icon = [&newColor](const QString& path, bool mask = false)
{
return gui_settings::colorizedIcon(QIcon(path), GUI::gl_tool_icon_color, newColor, mask);
return gui_settings::colorizedIcon(QIcon(path), gui::gl_tool_icon_color, newColor, mask);
};
m_catActHDD.colored = icon(":/Icons/hdd_blue.png", true);
@ -980,6 +980,7 @@ bool game_list_frame::eventFilter(QObject *object, QEvent *event)
{
QPoint numSteps = wheelEvent->angleDelta() / 8 / 15; // http://doc.qt.io/qt-5/qwheelevent.html#pixelDelta
const int value = numSteps.y();
Q_EMIT RequestSaveSliderPos(true);
m_Slider_Size->setValue(m_Slider_Size->value() + value);
return true;
}
@ -992,11 +993,13 @@ bool game_list_frame::eventFilter(QObject *object, QEvent *event)
{
if (keyEvent->key() == Qt::Key_Plus)
{
Q_EMIT RequestSaveSliderPos(true);
m_Slider_Size->setValue(m_Slider_Size->value() + 1);
return true;
}
else if (keyEvent->key() == Qt::Key_Minus)
{
Q_EMIT RequestSaveSliderPos(true);
m_Slider_Size->setValue(m_Slider_Size->value() - 1);
return true;
}
@ -1020,7 +1023,7 @@ int game_list_frame::PopulateGameList()
auto l_GetItem = [](const std::string& text)
{
// force single line text ("hack" used instead of Qt shenanigans like Qt::TextSingleLine)
QString formattedText = GUI::get_Single_Line(qstr(text));
QString formattedText = gui::get_Single_Line(qstr(text));
QTableWidgetItem* curr = new QTableWidgetItem;
curr->setFlags(curr->flags() & ~Qt::ItemIsEditable);
@ -1050,16 +1053,16 @@ int game_list_frame::PopulateGameList()
title_item->setIcon(QIcon(":/Icons/cog_black.png"));
}
m_gameList->setItem(row, GUI::COLUMN_ICON, icon_item);
m_gameList->setItem(row, GUI::COLUMN_NAME, title_item);
m_gameList->setItem(row, GUI::COLUMN_SERIAL, l_GetItem(game.info.serial));
m_gameList->setItem(row, GUI::COLUMN_FIRMWARE, l_GetItem(game.info.fw));
m_gameList->setItem(row, GUI::COLUMN_VERSION, l_GetItem(game.info.app_ver));
m_gameList->setItem(row, GUI::COLUMN_CATEGORY, l_GetItem(game.info.category));
m_gameList->setItem(row, GUI::COLUMN_PATH, l_GetItem(game.info.path));
m_gameList->setItem(row, GUI::COLUMN_RESOLUTION, l_GetItem(GetStringFromU32(game.info.resolution, resolution::mode, true)));
m_gameList->setItem(row, GUI::COLUMN_SOUND, l_GetItem(GetStringFromU32(game.info.sound_format, sound::format, true)));
m_gameList->setItem(row, GUI::COLUMN_PARENTAL, l_GetItem(GetStringFromU32(game.info.parental_lvl, parental::level)));
m_gameList->setItem(row, gui::column_icon, icon_item);
m_gameList->setItem(row, gui::column_name, title_item);
m_gameList->setItem(row, gui::column_serial, l_GetItem(game.info.serial));
m_gameList->setItem(row, gui::column_firmware, l_GetItem(game.info.fw));
m_gameList->setItem(row, gui::column_version, l_GetItem(game.info.app_ver));
m_gameList->setItem(row, gui::column_category, l_GetItem(game.info.category));
m_gameList->setItem(row, gui::column_path, l_GetItem(game.info.path));
m_gameList->setItem(row, gui::column_resolution, l_GetItem(GetStringFromU32(game.info.resolution, resolution::mode, true)));
m_gameList->setItem(row, gui::column_sound, l_GetItem(GetStringFromU32(game.info.sound_format, sound::format, true)));
m_gameList->setItem(row, gui::column_parental, l_GetItem(GetStringFromU32(game.info.parental_lvl, parental::level)));
if (selected_item == game.info.icon_path) result = row;
@ -1080,9 +1083,9 @@ void game_list_frame::PopulateGameGrid(uint maxCols, const QSize& image_size, co
m_xgrid->deleteLater();
bool showText = m_icon_size_index > GUI::gl_max_slider_pos * 2 / 5;
bool showText = m_icon_size_index > gui::gl_max_slider_pos * 2 / 5;
if (m_icon_size_index < GUI::gl_max_slider_pos * 2 / 3)
if (m_icon_size_index < gui::gl_max_slider_pos * 2 / 3)
{
m_xgrid = new game_list_grid(image_size, image_color, m_Margin_Factor, m_Text_Factor * 2, showText);
}
@ -1125,7 +1128,7 @@ void game_list_frame::PopulateGameGrid(uint maxCols, const QSize& image_size, co
for (const auto& app : matching_apps)
{
QString title = GUI::get_Single_Line(qstr(app.first->info.name));
QString title = gui::get_Single_Line(qstr(app.first->info.name));
m_xgrid->addItem(app.first->pxmap, title, app.second, r, c);