From 461148c22706ea35c8ae4985f21d695e46be01ff Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Sun, 26 Jan 2025 04:32:14 -0800 Subject: [PATCH] qt: Prevent interacting with empty grid cells. (#2243) --- src/qt_gui/game_grid_frame.cpp | 3 ++- src/qt_gui/gui_context_menus.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/qt_gui/game_grid_frame.cpp b/src/qt_gui/game_grid_frame.cpp index 2ebb09e5d..d719ac878 100644 --- a/src/qt_gui/game_grid_frame.cpp +++ b/src/qt_gui/game_grid_frame.cpp @@ -38,17 +38,18 @@ GameGridFrame::GameGridFrame(std::shared_ptr game_info_get, void GameGridFrame::onCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) { - cellClicked = true; crtRow = currentRow; crtColumn = currentColumn; columnCnt = this->columnCount(); auto itemID = (crtRow * columnCnt) + currentColumn; if (itemID > m_game_info->m_games.count() - 1) { + cellClicked = false; validCellSelected = false; BackgroundMusicPlayer::getInstance().stopMusic(); return; } + cellClicked = true; validCellSelected = true; SetGridBackgroundImage(crtRow, crtColumn); auto snd0Path = QString::fromStdString(m_game_info->m_games[itemID].snd0_path.string()); diff --git a/src/qt_gui/gui_context_menus.h b/src/qt_gui/gui_context_menus.h index 0e8675c0c..72affeca7 100644 --- a/src/qt_gui/gui_context_menus.h +++ b/src/qt_gui/gui_context_menus.h @@ -41,8 +41,8 @@ public: itemID = widget->currentRow() * widget->columnCount() + widget->currentColumn(); } - // Do not show the menu if an item is selected - if (itemID == -1) { + // Do not show the menu if no item is selected + if (itemID < 0 || itemID >= m_games.size()) { return; }