From d7b82a6eed1f3e7a4fe3fe97642c6ded1d9d5fe3 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 22 Dec 2020 21:21:32 -0600 Subject: [PATCH] [nostalgia/core/studio] Fix the TileSheetEditor color key overflow --- src/nostalgia/core/studio/tilesheeteditor.cpp | 11 +++++------ src/nostalgia/core/studio/tilesheeteditor.hpp | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index 50a221b6..233fad9d 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -926,15 +926,14 @@ void TileSheetEditor::saveItem() { bool TileSheetEditor::eventFilter(QObject *o, QEvent *e) { if (e->type() == QEvent::KeyPress) { const auto k = static_cast(e)->key(); - if (k >= Qt::Key_1 && k <= Qt::Key_9) { - m_colorPicker.colorTable->setCurrentCell(k - Qt::Key_1, 0); - return true; - } else if (k == Qt::Key_0) { - m_colorPicker.colorTable->setCurrentCell(k - Qt::Key_1 + 10, 0); + const auto max = m_colorPicker.colorTable->rowCount() - 1; + if (k >= Qt::Key_0 && k <= Qt::Key_9) { + const auto val = k - Qt::Key_1 + (k == Qt::Key_0 ? 10 : 0); + m_colorPicker.colorTable->setCurrentCell(std::min(max, val), 0); return true; } } - return QObject::eventFilter(o, e); + return QWidget::eventFilter(o, e); } QWidget *TileSheetEditor::setupColorPicker(QWidget *parent) { diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index 3bb5e050..ae73d70a 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -284,7 +284,7 @@ class TileSheetEditor: public studio::Editor { protected: void saveItem() override; - bool eventFilter(QObject *obj, QEvent *event); + bool eventFilter(QObject *obj, QEvent *event) override; private: QWidget *setupColorPicker(QWidget *widget);