Skip to content

Commit

Permalink
Qt: unify some movie hover code and fix cellLeave
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Apr 16, 2021
1 parent 7bc6730 commit 330dea1
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 41 deletions.
1 change: 1 addition & 0 deletions rpcs3/rpcs3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@
<ClCompile Include="rpcs3qt\debugger_list.cpp" />
<ClCompile Include="rpcs3qt\downloader.cpp" />
<ClCompile Include="rpcs3qt\fatal_error_dialog.cpp" />
<ClCompile Include="rpcs3qt\game_list.cpp" />
<ClCompile Include="rpcs3qt\gui_application.cpp" />
<ClCompile Include="rpcs3qt\input_dialog.cpp" />
<ClCompile Include="rpcs3qt\localized.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/rpcs3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,9 @@
<ClCompile Include="Input\hid_pad_handler.cpp">
<Filter>Io</Filter>
</ClCompile>
<ClCompile Include="rpcs3qt\game_list.cpp">
<Filter>Gui\game list</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Input\ds4_pad_handler.h">
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions rpcs3/rpcs3qt/game_list.cpp
Original file line number Diff line number Diff line change
@@ -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<movie_item*>(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;
}
}
22 changes: 8 additions & 14 deletions rpcs3/rpcs3qt/game_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,18 @@ struct gui_game_info
typedef std::shared_ptr<gui_game_info> 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;
};
13 changes: 0 additions & 13 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,6 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> 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<movie_item*>(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<movie_item*>(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)
Expand Down
14 changes: 0 additions & 14 deletions rpcs3/rpcs3qt/game_list_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<movie_item*>(item(m_last_entered_row, m_last_entered_col)))
{
old_item->set_active(false);
}
if (auto new_item = dynamic_cast<movie_item*>(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)
Expand Down

0 comments on commit 330dea1

Please sign in to comment.