Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: fix table item delegate usage #13737

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rpcs3/rpcs3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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>
Expand Down
7 changes: 7 additions & 0 deletions rpcs3/rpcs3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -941,12 +941,16 @@
</ClCompile>
<ClCompile Include="rpcs3qt\movie_item.cpp">
<Filter>Gui\custom items</Filter>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Debug\moc_game_list.cpp">
<Filter>Generated Files\Debug</Filter>
</ClCompile>
<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">
Expand Down Expand Up @@ -1117,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">
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions rpcs3/rpcs3qt/game_list_delegate.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}
}
}
}
11 changes: 11 additions & 0 deletions rpcs3/rpcs3qt/game_list_delegate.h
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 1 addition & 33 deletions rpcs3/rpcs3qt/table_item_delegate.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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();
}
}
}
}
}
}
}
6 changes: 3 additions & 3 deletions rpcs3/rpcs3qt/table_item_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
};