patch_manager: save widget layout

This commit is contained in:
Megamouse 2020-06-25 18:26:47 +02:00
parent ab9cdc70ad
commit 7d3389d548
4 changed files with 43 additions and 9 deletions

View file

@ -106,6 +106,7 @@ namespace gui
const QString fs = "FileSystem"; const QString fs = "FileSystem";
const QString gs_frame = "GSFrame"; const QString gs_frame = "GSFrame";
const QString trophy = "Trophy"; const QString trophy = "Trophy";
const QString patches = "Patches";
const QString savedata = "SaveData"; const QString savedata = "SaveData";
const QString users = "Users"; const QString users = "Users";
const QString notes = "Notes"; const QString notes = "Notes";
@ -213,6 +214,9 @@ namespace gui
const gui_save tr_games_state = gui_save(trophy, "games_state", QByteArray()); const gui_save tr_games_state = gui_save(trophy, "games_state", QByteArray());
const gui_save tr_trophy_state = gui_save(trophy, "trophy_state", QByteArray()); const gui_save tr_trophy_state = gui_save(trophy, "trophy_state", QByteArray());
const gui_save pm_geometry = gui_save(patches, "geometry", QByteArray());
const gui_save pm_splitter_state = gui_save(patches, "splitter_state", QByteArray());
const gui_save sd_geometry = gui_save(savedata, "geometry", QByteArray()); const gui_save sd_geometry = gui_save(savedata, "geometry", QByteArray());
const gui_save sd_icon_size = gui_save(savedata, "icon_size", 60); const gui_save sd_icon_size = gui_save(savedata, "icon_size", 60);
const gui_save sd_icon_color = gui_save(savedata, "icon_color", gl_icon_color); const gui_save sd_icon_color = gui_save(savedata, "icon_color", gl_icon_color);

View file

@ -1551,7 +1551,7 @@ void main_window::CreateConnects()
connect(ui->actionManage_Game_Patches, &QAction::triggered, [this] connect(ui->actionManage_Game_Patches, &QAction::triggered, [this]
{ {
patch_manager_dialog patch_manager(this); patch_manager_dialog patch_manager(m_gui_settings, this);
patch_manager.exec(); patch_manager.exec();
}); });

View file

@ -11,6 +11,7 @@
#include "ui_patch_manager_dialog.h" #include "ui_patch_manager_dialog.h"
#include "patch_manager_dialog.h" #include "patch_manager_dialog.h"
#include "table_item_delegate.h" #include "table_item_delegate.h"
#include "gui_settings.h"
#include "qt_utils.h" #include "qt_utils.h"
#include "Utilities/File.h" #include "Utilities/File.h"
#include "util/logs.hpp" #include "util/logs.hpp"
@ -35,8 +36,9 @@ enum patch_role : int
persistance_role persistance_role
}; };
patch_manager_dialog::patch_manager_dialog(QWidget* parent) patch_manager_dialog::patch_manager_dialog(std::shared_ptr<gui_settings> gui_settings, QWidget* parent)
: QDialog(parent) : QDialog(parent)
, m_gui_settings(gui_settings)
, ui(new Ui::patch_manager_dialog) , ui(new Ui::patch_manager_dialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -66,21 +68,43 @@ patch_manager_dialog::patch_manager_dialog(QWidget* parent)
save_config(); save_config();
} }
}); });
refresh();
resize(QGuiApplication::primaryScreen()->availableSize() * 0.7);
} }
patch_manager_dialog::~patch_manager_dialog() patch_manager_dialog::~patch_manager_dialog()
{ {
// Save gui settings
m_gui_settings->SetValue(gui::pm_geometry, saveGeometry());
m_gui_settings->SetValue(gui::pm_splitter_state, ui->splitter->saveState());
delete ui; delete ui;
} }
void patch_manager_dialog::refresh() int patch_manager_dialog::exec()
{
show();
refresh(true);
return QDialog::exec();
}
void patch_manager_dialog::refresh(bool restore_layout)
{ {
load_patches(); load_patches();
populate_tree(); populate_tree();
if (restore_layout)
{
if (!restoreGeometry(m_gui_settings->GetValue(gui::pm_geometry).toByteArray()))
{
resize(QGuiApplication::primaryScreen()->availableSize() * 0.7);
}
if (!ui->splitter->restoreState(m_gui_settings->GetValue(gui::pm_splitter_state).toByteArray()))
{
const int width_left = ui->splitter->width() * 0.7;
const int width_right = ui->splitter->width() - width_left;
ui->splitter->setSizes({ width_left, width_right });
}
}
} }
void patch_manager_dialog::load_patches() void patch_manager_dialog::load_patches()

View file

@ -12,14 +12,18 @@ namespace Ui
class patch_manager_dialog; class patch_manager_dialog;
} }
class gui_settings;
class patch_manager_dialog : public QDialog class patch_manager_dialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit patch_manager_dialog(QWidget* parent = nullptr); explicit patch_manager_dialog(std::shared_ptr<gui_settings> gui_settings, QWidget* parent = nullptr);
~patch_manager_dialog(); ~patch_manager_dialog();
int exec() override;
private Q_SLOTS: private Q_SLOTS:
void filter_patches(const QString& term); void filter_patches(const QString& term);
void on_item_selected(QTreeWidgetItem *current, QTreeWidgetItem *previous); void on_item_selected(QTreeWidgetItem *current, QTreeWidgetItem *previous);
@ -28,13 +32,15 @@ private Q_SLOTS:
void on_legacy_patches_enabled(int state); void on_legacy_patches_enabled(int state);
private: private:
void refresh(); void refresh(bool restore_layout = false);
void load_patches(); void load_patches();
void populate_tree(); void populate_tree();
void save_config(); void save_config();
void update_patch_info(const patch_engine::patch_info& info); void update_patch_info(const patch_engine::patch_info& info);
bool is_valid_file(const QMimeData& md, QStringList* drop_paths = nullptr); bool is_valid_file(const QMimeData& md, QStringList* drop_paths = nullptr);
std::shared_ptr<gui_settings> m_gui_settings;
patch_engine::patch_map m_map; patch_engine::patch_map m_map;
bool m_legacy_patches_enabled = false; bool m_legacy_patches_enabled = false;