1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

Qt: fix table item delegate usage

This commit is contained in:
Megamouse 2023-04-23 09:09:07 +02:00
parent f932cc4073
commit a6e4b77273
8 changed files with 67 additions and 38 deletions

View File

@ -671,6 +671,7 @@
<ClCompile Include="rpcs3qt\downloader.cpp" />
<ClCompile Include="rpcs3qt\fatal_error_dialog.cpp" />
<ClCompile Include="rpcs3qt\game_list.cpp" />
<ClCompile Include="rpcs3qt\game_list_delegate.cpp" />
<ClCompile Include="rpcs3qt\gui_application.cpp" />
<ClCompile Include="rpcs3qt\input_dialog.cpp" />
<ClCompile Include="rpcs3qt\ipc_settings_dialog.cpp" />
@ -1158,6 +1159,7 @@
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
</CustomBuild>
<ClInclude Include="rpcs3qt\game_list_delegate.h" />
<ClInclude Include="rpcs3qt\gui_save.h" />
<CustomBuild Include="rpcs3qt\patch_manager_dialog.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>

View File

@ -948,6 +948,9 @@
<ClCompile Include="QTGeneratedFiles\Release\moc_game_list.cpp">
<Filter>Generated Files\Release</Filter>
</ClCompile>
<ClCompile Include="rpcs3qt\game_list_delegate.cpp">
<Filter>Gui\game list</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Input\ds4_pad_handler.h">
@ -1118,6 +1121,9 @@
<ClInclude Include="rpcs3qt\progress_indicator.h">
<Filter>Gui\progress</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\game_list_delegate.h">
<Filter>Gui\game list</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">

View File

@ -24,6 +24,7 @@ set(SRC_FILES
find_dialog.cpp
game_compatibility.cpp
game_list.cpp
game_list_delegate.cpp
game_list_frame.cpp
game_list_grid.cpp
game_list_grid_delegate.cpp

View File

@ -0,0 +1,41 @@
#include "game_list_delegate.h"
#include "movie_item.h"
#include "gui_settings.h"
game_list_delegate::game_list_delegate(QObject* parent)
: table_item_delegate(parent, true)
{}
void game_list_delegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
table_item_delegate::paint(painter, option, index);
// Find out if the icon or size items are visible
if (index.column() == gui::game_list_columns::column_dir_size || (m_has_icons && index.column() == gui::game_list_columns::column_icon))
{
if (const QTableWidget* table = static_cast<const QTableWidget*>(parent()))
{
if (const QTableWidgetItem* current_item = table->item(index.row(), index.column());
current_item && table->visibleRegion().intersects(table->visualItemRect(current_item)))
{
if (movie_item* item = static_cast<movie_item*>(table->item(index.row(), gui::game_list_columns::column_icon)))
{
if (index.column() == gui::game_list_columns::column_dir_size)
{
if (!item->size_on_disk_loading())
{
item->call_size_calc_func();
}
}
else if (m_has_icons && index.column() == gui::game_list_columns::column_icon)
{
if (!item->icon_loading())
{
item->call_icon_load_func();
}
}
}
}
}
}
}

View File

@ -0,0 +1,11 @@
#pragma once
#include "table_item_delegate.h"
class game_list_delegate : public table_item_delegate
{
public:
explicit game_list_delegate(QObject* parent);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
};

View File

@ -2,7 +2,7 @@
#include "qt_utils.h"
#include "settings_dialog.h"
#include "pad_settings_dialog.h"
#include "table_item_delegate.h"
#include "game_list_delegate.h"
#include "custom_table_widget_item.h"
#include "input_dialog.h"
#include "localized.h"
@ -81,7 +81,7 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
m_game_list = new game_list();
m_game_list->setShowGrid(false);
m_game_list->setItemDelegate(new table_item_delegate(m_game_list, true));
m_game_list->setItemDelegate(new game_list_delegate(m_game_list));
m_game_list->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_game_list->setSelectionBehavior(QAbstractItemView::SelectRows);
m_game_list->setSelectionMode(QAbstractItemView::SingleSelection);

View File

@ -1,7 +1,4 @@
#include "table_item_delegate.h"
#include <QTableWidget>
#include "movie_item.h"
#include "gui_settings.h"
table_item_delegate::table_item_delegate(QObject* parent, bool has_icons)
@ -29,40 +26,11 @@ void table_item_delegate::initStyleOption(QStyleOptionViewItem *option, const QM
void table_item_delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == gui::game_list_columns::column_icon && option.state & QStyle::State_Selected)
if (m_has_icons && index.column() == gui::game_list_columns::column_icon && option.state & QStyle::State_Selected)
{
// Add background highlight color to icons
painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
}
QStyledItemDelegate::paint(painter, option, index);
// Find out if the icon or size items are visible
if (index.column() == gui::game_list_columns::column_dir_size || (m_has_icons && index.column() == gui::game_list_columns::column_icon))
{
if (const QTableWidget* table = static_cast<const QTableWidget*>(parent()))
{
if (const QTableWidgetItem* current_item = table->item(index.row(), index.column());
current_item && table->visibleRegion().intersects(table->visualItemRect(current_item)))
{
if (movie_item* item = static_cast<movie_item*>(table->item(index.row(), gui::game_list_columns::column_icon)))
{
if (index.column() == gui::game_list_columns::column_dir_size)
{
if (!item->size_on_disk_loading())
{
item->call_size_calc_func();
}
}
else if (m_has_icons && index.column() == gui::game_list_columns::column_icon)
{
if (!item->icon_loading())
{
item->call_icon_load_func();
}
}
}
}
}
}
}

View File

@ -6,13 +6,13 @@
/** This class is used to get rid of somewhat ugly item focus rectangles. You could change the rectangle instead of omiting it if you wanted */
class table_item_delegate : public QStyledItemDelegate
{
private:
bool m_has_icons;
public:
explicit table_item_delegate(QObject *parent = nullptr, bool has_icons = false);
void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
protected:
bool m_has_icons{};
};