From 9962cf333c1e81a8f6834a3adbdb646ea369a5c6 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 16 Mar 2023 19:51:22 +0200 Subject: [PATCH] new main window working --- shadPS4/gui/gui_settings.h | 3 ++ shadPS4/gui/main_window.cpp | 45 ++++++++++++++++++++- shadPS4/gui/main_window.h | 1 + shadPS4/main.cpp | 8 +++- shadPS4/shadPS4.vcxproj.filters | 70 ++++++++++++++++++--------------- 5 files changed, 92 insertions(+), 35 deletions(-) diff --git a/shadPS4/gui/gui_settings.h b/shadPS4/gui/gui_settings.h index 7b99bf4c..6ddb2d31 100644 --- a/shadPS4/gui/gui_settings.h +++ b/shadPS4/gui/gui_settings.h @@ -68,6 +68,9 @@ namespace gui const QColor game_list_icon_color = QColor(240, 240, 240, 255); const gui_save main_window_gamelist_visible = gui_save(main_window, "gamelistVisible", true); + const gui_save main_window_geometry = gui_save(main_window, "geometry", QByteArray()); + const gui_save main_window_windowState = gui_save(main_window, "windowState", QByteArray()); + const gui_save main_window_mwState = gui_save(main_window, "mwState", QByteArray()); const gui_save game_list_sortAsc = gui_save(game_list, "sortAsc", true); const gui_save game_list_sortCol = gui_save(game_list, "sortCol", 1); diff --git a/shadPS4/gui/main_window.cpp b/shadPS4/gui/main_window.cpp index 252073c5..fb6b1700 100644 --- a/shadPS4/gui/main_window.cpp +++ b/shadPS4/gui/main_window.cpp @@ -6,6 +6,7 @@ main_window::main_window(std::shared_ptr gui_settings, QWidget* parent) : QMainWindow(parent) , ui(new Ui::main_window) + , m_gui_settings(std::move(gui_settings)) { ui->setupUi(this); @@ -15,7 +16,7 @@ main_window::main_window(std::shared_ptr gui_settings, QWidget* pa main_window::~main_window() { - + SaveWindowState(); } bool main_window::Init() @@ -35,6 +36,11 @@ bool main_window::Init() ConfigureGuiFromSettings(); + show(); + + // Fix possible hidden game list columns. The game list has to be visible already. Use this after show() + m_game_list_frame->FixNarrowColumns(); + return true; } @@ -185,5 +191,42 @@ void main_window::ResizeIcons(int index) } void main_window::ConfigureGuiFromSettings() { + // Restore GUI state if needed. We need to if they exist. + if (!restoreGeometry(m_gui_settings->GetValue(gui::main_window_geometry).toByteArray())) + { + resize(QGuiApplication::primaryScreen()->availableSize() * 0.7); + } + restoreState(m_gui_settings->GetValue(gui::main_window_windowState).toByteArray()); + m_main_window->restoreState(m_gui_settings->GetValue(gui::main_window_mwState).toByteArray()); + + ui->showGameListAct->setChecked(m_gui_settings->GetValue(gui::main_window_gamelist_visible).toBool()); + + m_game_list_frame->setVisible(ui->showGameListAct->isChecked()); + + // handle icon size options + m_is_list_mode = m_gui_settings->GetValue(gui::game_list_listMode).toBool(); + if (m_is_list_mode) + ui->setlistModeListAct->setChecked(true); + else + ui->setlistModeGridAct->setChecked(true); + + const int icon_size_index = m_gui_settings->GetValue(m_is_list_mode ? gui::game_list_iconSize : gui::game_list_iconSizeGrid).toInt(); + m_other_slider_pos = m_gui_settings->GetValue(!m_is_list_mode ? gui::game_list_iconSize : gui::game_list_iconSizeGrid).toInt(); + ui->sizeSlider->setSliderPosition(icon_size_index); + SetIconSizeActions(icon_size_index); + + // Gamelist + m_game_list_frame->LoadSettings(); +} + +void main_window::SaveWindowState() const +{ + // Save gui settings + m_gui_settings->SetValue(gui::main_window_geometry, saveGeometry()); + m_gui_settings->SetValue(gui::main_window_windowState, saveState()); + m_gui_settings->SetValue(gui::main_window_mwState, m_main_window->saveState()); + + // Save column settings + m_game_list_frame->SaveSettings(); } \ No newline at end of file diff --git a/shadPS4/gui/main_window.h b/shadPS4/gui/main_window.h index e12c5c14..9a945e34 100644 --- a/shadPS4/gui/main_window.h +++ b/shadPS4/gui/main_window.h @@ -30,6 +30,7 @@ private Q_SLOTS: void ConfigureGuiFromSettings(); void SetIconSizeActions(int idx) const; void ResizeIcons(int index); + void SaveWindowState() const; private: void CreateActions(); void CreateDockWindows(); diff --git a/shadPS4/main.cpp b/shadPS4/main.cpp index baaf71a0..3b5c816a 100644 --- a/shadPS4/main.cpp +++ b/shadPS4/main.cpp @@ -1,13 +1,17 @@ #include "gui/shadps4gui.h" #include #include "gui/gui_settings.h" +#include "gui/main_window.h" int main(int argc, char* argv[]) { QApplication a(argc, argv); std::shared_ptr m_gui_settings; m_gui_settings.reset(new gui_settings()); - shadps4gui w(m_gui_settings,nullptr); - w.show(); + //shadps4gui w(m_gui_settings,nullptr); + //w.show(); + main_window* m_main_window = new main_window(m_gui_settings, nullptr); + m_main_window->Init(); + return a.exec(); } \ No newline at end of file diff --git a/shadPS4/shadPS4.vcxproj.filters b/shadPS4/shadPS4.vcxproj.filters index 87bb22e0..829c9d37 100644 --- a/shadPS4/shadPS4.vcxproj.filters +++ b/shadPS4/shadPS4.vcxproj.filters @@ -33,6 +33,12 @@ {ed31734c-f010-4590-9f01-18e0b2497ffb} + + {b4b58418-b124-41bb-96ef-610faa1c8812} + + + {731089fd-7d11-4f10-8f55-4854c2e42e9e} + @@ -59,26 +65,26 @@ gui - - gui - - - gui - - - gui - - - gui - - - gui - gui + + gui\game list + + + gui\game list + + + gui\game list + + + gui\game list + + + gui\game list + - Source Files + gui\main window @@ -96,20 +102,20 @@ gui - - gui - - - gui - gui gui + + gui\game list + + + gui\game list + - Header Files + gui\main window @@ -131,15 +137,6 @@ Header Files - - gui - - - gui - - - gui - gui @@ -152,5 +149,14 @@ gui + + gui\game list + + + gui\game list + + + gui\game list + \ No newline at end of file