From 330dea181a7e4a708cc58563bb08ca7fc87de932 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 16 Apr 2021 22:37:00 +0200 Subject: [PATCH] Qt: unify some movie hover code and fix cellLeave --- rpcs3/rpcs3.vcxproj | 1 + rpcs3/rpcs3.vcxproj.filters | 3 +++ rpcs3/rpcs3qt/CMakeLists.txt | 1 + rpcs3/rpcs3qt/game_list.cpp | 40 +++++++++++++++++++++++++++++++ rpcs3/rpcs3qt/game_list.h | 22 +++++++---------- rpcs3/rpcs3qt/game_list_frame.cpp | 13 ---------- rpcs3/rpcs3qt/game_list_grid.cpp | 14 ----------- 7 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 rpcs3/rpcs3qt/game_list.cpp diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index f7388ca224..1a5532b8c9 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -564,6 +564,7 @@ + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index d230c5336f..abb8a0118e 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -744,6 +744,9 @@ Io + + Gui\game list + diff --git a/rpcs3/rpcs3qt/CMakeLists.txt b/rpcs3/rpcs3qt/CMakeLists.txt index 1a3bf5222d..711d1cd329 100644 --- a/rpcs3/rpcs3qt/CMakeLists.txt +++ b/rpcs3/rpcs3qt/CMakeLists.txt @@ -21,6 +21,7 @@ set(SRC_FILES fatal_error_dialog.cpp find_dialog.cpp game_compatibility.cpp + game_list.cpp game_list_frame.cpp game_list_grid.cpp game_list_grid_delegate.cpp diff --git a/rpcs3/rpcs3qt/game_list.cpp b/rpcs3/rpcs3qt/game_list.cpp new file mode 100644 index 0000000000..d67378d4ad --- /dev/null +++ b/rpcs3/rpcs3qt/game_list.cpp @@ -0,0 +1,40 @@ +#include "game_list.h" +#include "movie_item.h" + +void game_list::mousePressEvent(QMouseEvent *event) +{ + if (!indexAt(event->pos()).isValid() || !itemAt(event->pos())->data(Qt::UserRole).isValid()) + { + clearSelection(); + setCurrentItem(nullptr); // Needed for currentItemChanged + } + QTableWidget::mousePressEvent(event); +} + +void game_list::mouseMoveEvent(QMouseEvent *event) +{ + movie_item* new_item = static_cast(itemAt(event->pos())); + + if (new_item != m_last_hover_item) + { + if (m_last_hover_item) + { + m_last_hover_item->set_active(false); + } + if (new_item) + { + new_item->set_active(true); + } + } + + m_last_hover_item = new_item; +} + +void game_list::leaveEvent(QEvent *event) +{ + if (m_last_hover_item) + { + m_last_hover_item->set_active(false); + m_last_hover_item = nullptr; + } +} diff --git a/rpcs3/rpcs3qt/game_list.h b/rpcs3/rpcs3qt/game_list.h index 941ccf9563..dc40c65036 100644 --- a/rpcs3/rpcs3qt/game_list.h +++ b/rpcs3/rpcs3qt/game_list.h @@ -23,24 +23,18 @@ struct gui_game_info typedef std::shared_ptr game_info; Q_DECLARE_METATYPE(game_info) +class movie_item; + /* - class used in order to get deselection + class used in order to get deselection and hover change if you know a simpler way, tell @Megamouse */ class game_list : public QTableWidget { -public: - int m_last_entered_row = -1; - int m_last_entered_col = -1; +protected: + movie_item* m_last_hover_item = nullptr; -private: - void mousePressEvent(QMouseEvent *event) override - { - if (!indexAt(event->pos()).isValid() || !itemAt(event->pos())->data(Qt::UserRole).isValid()) - { - clearSelection(); - setCurrentItem(nullptr); // Needed for currentItemChanged - } - QTableWidget::mousePressEvent(event); - } + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void leaveEvent(QEvent *event) override; }; diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index 780f008270..0413c1a8a4 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -133,19 +133,6 @@ game_list_frame::game_list_frame(std::shared_ptr gui_settings, std connect(m_game_list, &QTableWidget::customContextMenuRequested, this, &game_list_frame::ShowContextMenu); connect(m_game_list, &QTableWidget::itemSelectionChanged, this, &game_list_frame::itemSelectionChangedSlot); connect(m_game_list, &QTableWidget::itemDoubleClicked, this, &game_list_frame::doubleClickedSlot); - connect(m_game_list, &QTableWidget::cellEntered, this, [this](int row, int column) - { - if (auto old_item = static_cast(m_game_list->item(m_game_list->m_last_entered_row, m_game_list->m_last_entered_col))) - { - old_item->set_active(false); - } - if (auto new_item = static_cast(m_game_list->item(row, column))) - { - new_item->set_active(true); - } - m_game_list->m_last_entered_row = row; - m_game_list->m_last_entered_col = column; - }); connect(m_game_list->horizontalHeader(), &QHeaderView::sectionClicked, this, &game_list_frame::OnColClicked); connect(m_game_list->horizontalHeader(), &QHeaderView::customContextMenuRequested, [this](const QPoint& pos) diff --git a/rpcs3/rpcs3qt/game_list_grid.cpp b/rpcs3/rpcs3qt/game_list_grid.cpp index 83d8b1bd2b..9723acee3e 100644 --- a/rpcs3/rpcs3qt/game_list_grid.cpp +++ b/rpcs3/rpcs3qt/game_list_grid.cpp @@ -40,20 +40,6 @@ game_list_grid::game_list_grid(const QSize& icon_size, QColor icon_color, const horizontalHeader()->setVisible(false); setShowGrid(false); setMouseTracking(true); - - connect(this, &QTableWidget::cellEntered, this, [this](int row, int column) - { - if (auto old_item = dynamic_cast(item(m_last_entered_row, m_last_entered_col))) - { - old_item->set_active(false); - } - if (auto new_item = dynamic_cast(item(row, column))) - { - new_item->set_active(true); - } - m_last_entered_row = row; - m_last_entered_col = column; - }); } void game_list_grid::enableText(const bool& enabled)