From e3ebcff4a58be775314c8b3c331b2f9368a06a94 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Wed, 15 Mar 2023 21:39:39 +0200 Subject: [PATCH] refactoring main window (still not functional) --- shadPS4/gui/custom_dock_widget.h | 67 +++++++ shadPS4/gui/game_list_frame.cpp | 21 ++- shadPS4/gui/game_list_frame.h | 10 +- shadPS4/gui/gui_settings.h | 5 + shadPS4/gui/main_window.cpp | 73 ++++++++ shadPS4/gui/main_window.h | 43 +++++ shadPS4/gui/main_window.ui | 297 +++++++++++++++++++++++++++++++ shadPS4/shadPS4.vcxproj | 4 + shadPS4/shadPS4.vcxproj.filters | 21 ++- 9 files changed, 529 insertions(+), 12 deletions(-) create mode 100644 shadPS4/gui/custom_dock_widget.h create mode 100644 shadPS4/gui/main_window.cpp create mode 100644 shadPS4/gui/main_window.h create mode 100644 shadPS4/gui/main_window.ui diff --git a/shadPS4/gui/custom_dock_widget.h b/shadPS4/gui/custom_dock_widget.h new file mode 100644 index 00000000..ece514c1 --- /dev/null +++ b/shadPS4/gui/custom_dock_widget.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include + +class custom_dock_widget : public QDockWidget +{ +private: + std::shared_ptr m_title_bar_widget; + bool m_is_title_bar_visible = true; + +public: + explicit custom_dock_widget(const QString& title, QWidget* parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()) + : QDockWidget(title, parent, flags) + { + m_title_bar_widget.reset(titleBarWidget()); + + connect(this, &QDockWidget::topLevelChanged, [this](bool/* topLevel*/) + { + SetTitleBarVisible(m_is_title_bar_visible); + style()->unpolish(this); + style()->polish(this); + }); + } + + void SetTitleBarVisible(bool visible) + { + if (visible || isFloating()) + { + if (m_title_bar_widget.get() != titleBarWidget()) + { + setTitleBarWidget(m_title_bar_widget.get()); + QMargins margins = widget()->contentsMargins(); + margins.setTop(0); + widget()->setContentsMargins(margins); + } + } + else + { + setTitleBarWidget(new QWidget()); + QMargins margins = widget()->contentsMargins(); + margins.setTop(1); + widget()->setContentsMargins(margins); + } + + m_is_title_bar_visible = visible; + } + +protected: + void paintEvent(QPaintEvent* event) override + { + // We need to repaint the dock widgets as plain widgets in floating mode. + // Source: https://stackoverflow.com/questions/10272091/cannot-add-a-background-image-to-a-qdockwidget + if (isFloating()) + { + QStyleOption opt; + opt.initFrom(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); + return; + } + + // Use inherited method for docked mode because otherwise the dock would lose the title etc. + QDockWidget::paintEvent(event); + } +}; diff --git a/shadPS4/gui/game_list_frame.cpp b/shadPS4/gui/game_list_frame.cpp index d5c5d25e..ba38d44b 100644 --- a/shadPS4/gui/game_list_frame.cpp +++ b/shadPS4/gui/game_list_frame.cpp @@ -7,7 +7,7 @@ #include game_list_frame::game_list_frame(std::shared_ptr gui_settings, QWidget* parent) - : QWidget(parent) + : custom_dock_widget(tr("Game List"), parent) , m_gui_settings(std::move(gui_settings)) { m_icon_size = gui::game_list_icon_size_min; // ensure a valid size @@ -25,6 +25,12 @@ game_list_frame::game_list_frame(std::shared_ptr gui_settings, QWi m_gui_settings->SetValue(gui::game_list_marginFactor, m_margin_factor); m_gui_settings->SetValue(gui::game_list_textFactor, m_text_factor); + m_game_dock = new QMainWindow(this); + m_game_dock->setWindowFlags(Qt::Widget); + setWidget(m_game_dock); + + m_game_grid = new game_list_grid(QSize(), m_icon_color, m_margin_factor, m_text_factor, false); + m_game_list = new game_list_table(); m_game_list->setShowGrid(false); m_game_list->setEditTriggers(QAbstractItemView::NoEditTriggers); @@ -48,13 +54,12 @@ game_list_frame::game_list_frame(std::shared_ptr gui_settings, QWi m_game_list->installEventFilter(this); m_game_list->setColumnCount(gui::column_count); - //temp code - QVBoxLayout* layout = new QVBoxLayout; - layout->setContentsMargins(0, 0, 0, 0); - QSpacerItem* item = new QSpacerItem(100, 1, QSizePolicy::Expanding, QSizePolicy::Fixed); - layout->addWidget(m_game_list); - setLayout(layout); - //endof temp code + m_central_widget = new QStackedWidget(this); + m_central_widget->addWidget(m_game_list); + m_central_widget->addWidget(m_game_grid); + m_central_widget->setCurrentWidget(m_is_list_layout ? m_game_list : m_game_grid); + + m_game_dock->setCentralWidget(m_central_widget); // Actions regarding showing/hiding columns auto add_column = [this](gui::game_list_columns col, const QString& header_text, const QString& action_text) diff --git a/shadPS4/gui/game_list_frame.h b/shadPS4/gui/game_list_frame.h index 75e4a17a..4182ba7d 100644 --- a/shadPS4/gui/game_list_frame.h +++ b/shadPS4/gui/game_list_frame.h @@ -1,17 +1,19 @@ #pragma once #include "game_list_table.h" +#include "custom_dock_widget.h" #include "shadps4gui.h" #include "game_list_grid.h" #include "game_list_item.h" #include #include +#include #include #include #include #include -class game_list_frame : public QWidget +class game_list_frame : public custom_dock_widget { Q_OBJECT public : @@ -40,12 +42,18 @@ private Q_SLOTS: void OnHeaderColumnClicked(int col); void OnRepaintFinished(); void OnRefreshFinished(); +Q_SIGNALS: + void GameListFrameClosed(); private: QPixmap PaintedPixmap(const QPixmap& icon) const; void SortGameList() const; std::string CurrentSelectionPath(); void PopulateGameList(); + // Which widget we are displaying depends on if we are in grid or list mode. + QMainWindow* m_game_dock = nullptr; + QStackedWidget* m_central_widget = nullptr; + // Game Grid game_list_grid* m_game_grid = nullptr; diff --git a/shadPS4/gui/gui_settings.h b/shadPS4/gui/gui_settings.h index 7b316862..ca2af497 100644 --- a/shadPS4/gui/gui_settings.h +++ b/shadPS4/gui/gui_settings.h @@ -53,10 +53,15 @@ namespace gui const QSize game_list_icon_size_medium = QSize(160, 88); const QSize game_list_icon_size_max = QSize(320, 176); + const int game_list_max_slider_pos = 100; + + const QString main_window = "main_window"; const QString game_list = "GameList"; 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 game_list_sortAsc = gui_save(game_list, "sortAsc", true); const gui_save game_list_sortCol = gui_save(game_list, "sortCol", 1); const gui_save game_list_state = gui_save(game_list, "state", QByteArray()); diff --git a/shadPS4/gui/main_window.cpp b/shadPS4/gui/main_window.cpp new file mode 100644 index 00000000..a98f78bd --- /dev/null +++ b/shadPS4/gui/main_window.cpp @@ -0,0 +1,73 @@ +#include "game_list_frame.h" +#include "main_window.h" +#include "gui_settings.h" +#include "ui_main_window.h" + +main_window::main_window(std::shared_ptr gui_settings, QWidget* parent) + : QMainWindow(parent) + , ui(new Ui::main_window) +{ + + ui->setupUi(this); + + setAttribute(Qt::WA_DeleteOnClose); +} + +main_window::~main_window() +{ + +} + +bool main_window::Init() +{ + // add toolbar widgets + ui->toolBar->setObjectName("mw_toolbar"); + ui->sizeSlider->setRange(0, gui::game_list_max_slider_pos); + ui->toolBar->addWidget(ui->sizeSliderContainer); + ui->toolBar->addWidget(ui->mw_searchbar); + + CreateActions(); + CreateDockWindows(); + + return true; +} + +void main_window::CreateActions() +{ + //create action group for icon size + m_icon_size_act_group = new QActionGroup(this); + m_icon_size_act_group->addAction(ui->setIconSizeTinyAct); + m_icon_size_act_group->addAction(ui->setIconSizeSmallAct); + m_icon_size_act_group->addAction(ui->setIconSizeMediumAct); + m_icon_size_act_group->addAction(ui->setIconSizeLargeAct); + + //create action group for list mode + m_list_mode_act_group = new QActionGroup(this); + m_list_mode_act_group->addAction(ui->setlistModeListAct); + m_list_mode_act_group->addAction(ui->setlistModeGridAct); + +} + +void main_window::CreateDockWindows() +{ + m_main_window = new QMainWindow(); + m_main_window->setContextMenuPolicy(Qt::PreventContextMenu); + + m_game_list_frame = new game_list_frame(m_gui_settings,m_main_window); + m_game_list_frame->setObjectName("gamelist"); + + m_main_window->addDockWidget(Qt::LeftDockWidgetArea, m_game_list_frame); + + m_main_window->setDockNestingEnabled(true); + + setCentralWidget(m_main_window); + + connect(m_game_list_frame, &game_list_frame::GameListFrameClosed, this, [this]() + { + if (ui->showGameListAct->isChecked()) + { + ui->showGameListAct->setChecked(false); + m_gui_settings->SetValue(gui::main_window_gamelist_visible, false); + } + }); +} diff --git a/shadPS4/gui/main_window.h b/shadPS4/gui/main_window.h new file mode 100644 index 00000000..3e6e856f --- /dev/null +++ b/shadPS4/gui/main_window.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include + +class gui_settings; +class game_list_frame; + +namespace Ui +{ + class main_window; +} + +class main_window : public QMainWindow +{ + Q_OBJECT + + std::unique_ptr ui; + + bool m_is_list_mode = true; + bool m_save_slider_pos = false; + int m_other_slider_pos = 0; + +public: + explicit main_window(std::shared_ptr gui_settings,QWidget* parent = nullptr); + ~main_window(); + bool Init(); + +private: + void CreateActions(); + void CreateDockWindows(); + + QActionGroup* m_icon_size_act_group = nullptr; + QActionGroup* m_list_mode_act_group = nullptr; + + // Dockable widget frames + QMainWindow* m_main_window = nullptr; + game_list_frame* m_game_list_frame = nullptr; + + std::shared_ptr m_gui_settings; + +}; + diff --git a/shadPS4/gui/main_window.ui b/shadPS4/gui/main_window.ui new file mode 100644 index 00000000..bbe343a4 --- /dev/null +++ b/shadPS4/gui/main_window.ui @@ -0,0 +1,297 @@ + + + main_window + + + + 0 + 0 + 1058 + 580 + + + + + 0 + 0 + + + + + 4 + 0 + + + + RPCS3 + + + false + + + true + + + true + + + QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks|QMainWindow::GroupedDragging + + + + + 0 + 0 + + + + + + 480 + 10 + 251 + 31 + + + + + 0 + 0 + + + + + 10 + false + + + + Qt::ClickFocus + + + false + + + Search... + + + false + + + + + + 280 + 10 + 181 + 31 + + + + + 0 + 0 + + + + + 0 + + + 14 + + + 0 + + + 14 + + + 0 + + + + + + 0 + 0 + + + + Qt::ClickFocus + + + false + + + Qt::Horizontal + + + QSlider::NoTicks + + + + + + + + + + 0 + 0 + 1058 + 22 + + + + Qt::PreventContextMenu + + + + File + + + + + + + + View + + + + Game List Icons + + + + + + + + + Game List Mode + + + + + + + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + Install Packages (PKG) + + + Install application from a .pkg file + + + + + Install Firmware + + + Install firmware from PS3UPDAT.PUP + + + + + Exit + + + Exit RPCS3 + + + Exit the application. + + + + + true + + + Show Game List + + + + + Game List Refresh + + + + + true + + + Tiny + + + + + true + + + true + + + Small + + + + + true + + + Medium + + + + + true + + + Large + + + + + true + + + true + + + List View + + + + + true + + + Grid View + + + + + + + + + diff --git a/shadPS4/shadPS4.vcxproj b/shadPS4/shadPS4.vcxproj index 5338f302..86b503fa 100644 --- a/shadPS4/shadPS4.vcxproj +++ b/shadPS4/shadPS4.vcxproj @@ -22,6 +22,7 @@ + @@ -30,6 +31,7 @@ + @@ -41,6 +43,7 @@ + @@ -50,6 +53,7 @@ + diff --git a/shadPS4/shadPS4.vcxproj.filters b/shadPS4/shadPS4.vcxproj.filters index e62e16b6..87bb22e0 100644 --- a/shadPS4/shadPS4.vcxproj.filters +++ b/shadPS4/shadPS4.vcxproj.filters @@ -77,11 +77,17 @@ gui + + Source Files + Form Files + + Form Files + @@ -102,6 +108,9 @@ gui + + Header Files + @@ -134,8 +143,14 @@ gui - - - + + Header Files + + + Header Files + + + gui + \ No newline at end of file