1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

Qt: unify some movie hover code and fix cellLeave

This commit is contained in:
Megamouse 2021-04-16 22:37:00 +02:00
parent 7bc673002f
commit 330dea181a
7 changed files with 53 additions and 41 deletions

View File

@ -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" />

View File

@ -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">

View File

@ -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

View File

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

View File

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

View File

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

View File

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