refactoring main window (still not functional)

This commit is contained in:
georgemoralis 2023-03-15 21:39:39 +02:00
parent 4612305bd6
commit e3ebcff4a5
9 changed files with 529 additions and 12 deletions

View File

@ -0,0 +1,67 @@
#pragma once
#include <QDockWidget>
#include <QStyleOption>
#include <QPainter>
class custom_dock_widget : public QDockWidget
{
private:
std::shared_ptr<QWidget> 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);
}
};

View File

@ -7,7 +7,7 @@
#include <unordered_set> #include <unordered_set>
game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, QWidget* parent) game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, QWidget* parent)
: QWidget(parent) : custom_dock_widget(tr("Game List"), parent)
, m_gui_settings(std::move(gui_settings)) , m_gui_settings(std::move(gui_settings))
{ {
m_icon_size = gui::game_list_icon_size_min; // ensure a valid size 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> gui_settings, QWi
m_gui_settings->SetValue(gui::game_list_marginFactor, m_margin_factor); m_gui_settings->SetValue(gui::game_list_marginFactor, m_margin_factor);
m_gui_settings->SetValue(gui::game_list_textFactor, m_text_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 = new game_list_table();
m_game_list->setShowGrid(false); m_game_list->setShowGrid(false);
m_game_list->setEditTriggers(QAbstractItemView::NoEditTriggers); m_game_list->setEditTriggers(QAbstractItemView::NoEditTriggers);
@ -48,13 +54,12 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, QWi
m_game_list->installEventFilter(this); m_game_list->installEventFilter(this);
m_game_list->setColumnCount(gui::column_count); m_game_list->setColumnCount(gui::column_count);
//temp code m_central_widget = new QStackedWidget(this);
QVBoxLayout* layout = new QVBoxLayout; m_central_widget->addWidget(m_game_list);
layout->setContentsMargins(0, 0, 0, 0); m_central_widget->addWidget(m_game_grid);
QSpacerItem* item = new QSpacerItem(100, 1, QSizePolicy::Expanding, QSizePolicy::Fixed); m_central_widget->setCurrentWidget(m_is_list_layout ? m_game_list : m_game_grid);
layout->addWidget(m_game_list);
setLayout(layout); m_game_dock->setCentralWidget(m_central_widget);
//endof temp code
// Actions regarding showing/hiding columns // Actions regarding showing/hiding columns
auto add_column = [this](gui::game_list_columns col, const QString& header_text, const QString& action_text) auto add_column = [this](gui::game_list_columns col, const QString& header_text, const QString& action_text)

View File

@ -1,17 +1,19 @@
#pragma once #pragma once
#include "game_list_table.h" #include "game_list_table.h"
#include "custom_dock_widget.h"
#include "shadps4gui.h" #include "shadps4gui.h"
#include "game_list_grid.h" #include "game_list_grid.h"
#include "game_list_item.h" #include "game_list_item.h"
#include <QHeaderView> #include <QHeaderView>
#include <QScrollbar> #include <QScrollbar>
#include <QStackedWidget>
#include <QWidget> #include <QWidget>
#include <deque> #include <deque>
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QtConcurrent> #include <QtConcurrent>
class game_list_frame : public QWidget class game_list_frame : public custom_dock_widget
{ {
Q_OBJECT Q_OBJECT
public : public :
@ -40,12 +42,18 @@ private Q_SLOTS:
void OnHeaderColumnClicked(int col); void OnHeaderColumnClicked(int col);
void OnRepaintFinished(); void OnRepaintFinished();
void OnRefreshFinished(); void OnRefreshFinished();
Q_SIGNALS:
void GameListFrameClosed();
private: private:
QPixmap PaintedPixmap(const QPixmap& icon) const; QPixmap PaintedPixmap(const QPixmap& icon) const;
void SortGameList() const; void SortGameList() const;
std::string CurrentSelectionPath(); std::string CurrentSelectionPath();
void PopulateGameList(); 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 Grid
game_list_grid* m_game_grid = nullptr; game_list_grid* m_game_grid = nullptr;

View File

@ -53,10 +53,15 @@ namespace gui
const QSize game_list_icon_size_medium = QSize(160, 88); const QSize game_list_icon_size_medium = QSize(160, 88);
const QSize game_list_icon_size_max = QSize(320, 176); 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 QString game_list = "GameList";
const QColor game_list_icon_color = QColor(240, 240, 240, 255); 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_sortAsc = gui_save(game_list, "sortAsc", true);
const gui_save game_list_sortCol = gui_save(game_list, "sortCol", 1); const gui_save game_list_sortCol = gui_save(game_list, "sortCol", 1);
const gui_save game_list_state = gui_save(game_list, "state", QByteArray()); const gui_save game_list_state = gui_save(game_list, "state", QByteArray());

View File

@ -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> 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);
}
});
}

43
shadPS4/gui/main_window.h Normal file
View File

@ -0,0 +1,43 @@
#pragma once
#include <QMainWindow>
#include <QActionGroup>
class gui_settings;
class game_list_frame;
namespace Ui
{
class main_window;
}
class main_window : public QMainWindow
{
Q_OBJECT
std::unique_ptr<Ui::main_window> 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> 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<gui_settings> m_gui_settings;
};

297
shadPS4/gui/main_window.ui Normal file
View File

@ -0,0 +1,297 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>main_window</class>
<widget class="QMainWindow" name="main_window">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1058</width>
<height>580</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>4</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>RPCS3</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="animated">
<bool>true</bool>
</property>
<property name="dockNestingEnabled">
<bool>true</bool>
</property>
<property name="dockOptions">
<set>QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks|QMainWindow::GroupedDragging</set>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QLineEdit" name="mw_searchbar">
<property name="geometry">
<rect>
<x>480</x>
<y>10</y>
<width>251</width>
<height>31</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
<bold>false</bold>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="frame">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Search...</string>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
</property>
</widget>
<widget class="QWidget" name="sizeSliderContainer" native="true">
<property name="geometry">
<rect>
<x>280</x>
<y>10</y>
<width>181</width>
<height>31</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="sizeSliderContainer_layout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>14</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>14</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QSlider" name="sizeSlider">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1058</width>
<height>22</height>
</rect>
</property>
<property name="contextMenuPolicy">
<enum>Qt::PreventContextMenu</enum>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="bootInstallPkgAct"/>
<addaction name="separator"/>
<addaction name="exitAct"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
<widget class="QMenu" name="menuGame_List_Icons">
<property name="title">
<string>Game List Icons</string>
</property>
<addaction name="setIconSizeTinyAct"/>
<addaction name="setIconSizeSmallAct"/>
<addaction name="setIconSizeMediumAct"/>
<addaction name="setIconSizeLargeAct"/>
</widget>
<widget class="QMenu" name="menuGame_List_Mode">
<property name="title">
<string>Game List Mode</string>
</property>
<addaction name="setlistModeListAct"/>
<addaction name="setlistModeGridAct"/>
</widget>
<addaction name="showGameListAct"/>
<addaction name="separator"/>
<addaction name="refreshGameListAct"/>
<addaction name="menuGame_List_Mode"/>
<addaction name="menuGame_List_Icons"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuView"/>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<action name="bootInstallPkgAct">
<property name="text">
<string>Install Packages (PKG)</string>
</property>
<property name="toolTip">
<string>Install application from a .pkg file</string>
</property>
</action>
<action name="bootInstallPupAct">
<property name="text">
<string>Install Firmware</string>
</property>
<property name="toolTip">
<string>Install firmware from PS3UPDAT.PUP</string>
</property>
</action>
<action name="exitAct">
<property name="text">
<string>Exit</string>
</property>
<property name="toolTip">
<string>Exit RPCS3</string>
</property>
<property name="statusTip">
<string>Exit the application.</string>
</property>
</action>
<action name="showGameListAct">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Show Game List</string>
</property>
</action>
<action name="refreshGameListAct">
<property name="text">
<string>Game List Refresh</string>
</property>
</action>
<action name="setIconSizeTinyAct">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Tiny</string>
</property>
</action>
<action name="setIconSizeSmallAct">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Small</string>
</property>
</action>
<action name="setIconSizeMediumAct">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Medium</string>
</property>
</action>
<action name="setIconSizeLargeAct">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Large</string>
</property>
</action>
<action name="setlistModeListAct">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>List View</string>
</property>
</action>
<action name="setlistModeGridAct">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Grid View</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="../../../rpcs3/rpcs3/resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -22,6 +22,7 @@
<ClCompile Include="gui\game_list_grid_delegate.cpp" /> <ClCompile Include="gui\game_list_grid_delegate.cpp" />
<ClCompile Include="gui\game_list_table.cpp" /> <ClCompile Include="gui\game_list_table.cpp" />
<ClCompile Include="gui\gui_settings.cpp" /> <ClCompile Include="gui\gui_settings.cpp" />
<ClCompile Include="gui\main_window.cpp" />
<ClCompile Include="gui\settings.cpp" /> <ClCompile Include="gui\settings.cpp" />
<ClCompile Include="gui\shadps4gui.cpp" /> <ClCompile Include="gui\shadps4gui.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
@ -30,6 +31,7 @@
<QtMoc Include="gui\shadps4gui.h" /> <QtMoc Include="gui\shadps4gui.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="gui\main_window.ui" />
<QtUic Include="gui\shadps4gui.ui" /> <QtUic Include="gui\shadps4gui.ui" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -41,6 +43,7 @@
<ClInclude Include="emulator\fileFormat\PSF.h" /> <ClInclude Include="emulator\fileFormat\PSF.h" />
<ClInclude Include="emulator\gameInfo.h" /> <ClInclude Include="emulator\gameInfo.h" />
<ClInclude Include="emulator\Loader.h" /> <ClInclude Include="emulator\Loader.h" />
<ClInclude Include="gui\custom_dock_widget.h" />
<ClInclude Include="gui\custom_table_widget_item.h" /> <ClInclude Include="gui\custom_table_widget_item.h" />
<QtMoc Include="gui\game_list_grid.h" /> <QtMoc Include="gui\game_list_grid.h" />
<QtMoc Include="gui\game_list_frame.h" /> <QtMoc Include="gui\game_list_frame.h" />
@ -50,6 +53,7 @@
<ClInclude Include="gui\gui_save.h" /> <ClInclude Include="gui\gui_save.h" />
<QtMoc Include="gui\gui_settings.h" /> <QtMoc Include="gui\gui_settings.h" />
<QtMoc Include="gui\settings.h" /> <QtMoc Include="gui\settings.h" />
<QtMoc Include="gui\main_window.h" />
<ClInclude Include="gui\qt_utils.h" /> <ClInclude Include="gui\qt_utils.h" />
<ClInclude Include="Types.h" /> <ClInclude Include="Types.h" />
</ItemGroup> </ItemGroup>

View File

@ -77,11 +77,17 @@
<ClCompile Include="gui\settings.cpp"> <ClCompile Include="gui\settings.cpp">
<Filter>gui</Filter> <Filter>gui</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="gui\main_window.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="gui\shadps4gui.ui"> <QtUic Include="gui\shadps4gui.ui">
<Filter>Form Files</Filter> <Filter>Form Files</Filter>
</QtUic> </QtUic>
<QtUic Include="gui\main_window.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="gui\shadps4gui.h"> <QtMoc Include="gui\shadps4gui.h">
@ -102,6 +108,9 @@
<QtMoc Include="gui\gui_settings.h"> <QtMoc Include="gui\gui_settings.h">
<Filter>gui</Filter> <Filter>gui</Filter>
</QtMoc> </QtMoc>
<QtMoc Include="gui\main_window.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Types.h"> <ClInclude Include="Types.h">
@ -134,8 +143,14 @@
<ClInclude Include="gui\gui_save.h"> <ClInclude Include="gui\gui_save.h">
<Filter>gui</Filter> <Filter>gui</Filter>
</ClInclude> </ClInclude>
</ItemGroup> <ClInclude Include="gui\game_list_item.h">
<ItemGroup> <Filter>Header Files</Filter>
<None Include="cpp.hint" /> </ClInclude>
<ClInclude Include="gui\qt_utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="gui\custom_dock_widget.h">
<Filter>gui</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>