From d98a5e386aa7bda96c2fd4894784ee15239f6c08 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 18 Dec 2020 00:04:34 -0600 Subject: [PATCH] [nostalgia/core/studio] Make number keys map to color indices in TileSheetEditor --- src/nostalgia/core/studio/tilesheeteditor.cpp | 15 +++++++++++++++ src/nostalgia/core/studio/tilesheeteditor.hpp | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/nostalgia/core/studio/tilesheeteditor.cpp b/src/nostalgia/core/studio/tilesheeteditor.cpp index 8e62a214..50a221b6 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.cpp +++ b/src/nostalgia/core/studio/tilesheeteditor.cpp @@ -876,6 +876,7 @@ TileSheetEditor::TileSheetEditor(QString path, const studio::Context *ctx, QWidg setPasteEnabled(selected && !m_sheetData.clipboardEmpty()); }); setExportable(true); + installEventFilter(this); } TileSheetEditor::~TileSheetEditor() { @@ -922,6 +923,20 @@ void TileSheetEditor::saveItem() { m_sheetData.save(m_ctx, m_itemPath); } +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); + return true; + } + } + return QObject::eventFilter(o, e); +} + QWidget *TileSheetEditor::setupColorPicker(QWidget *parent) { auto colorPicker = new QWidget(parent); auto lyt = new QVBoxLayout(colorPicker); diff --git a/src/nostalgia/core/studio/tilesheeteditor.hpp b/src/nostalgia/core/studio/tilesheeteditor.hpp index daeb4614..3bb5e050 100644 --- a/src/nostalgia/core/studio/tilesheeteditor.hpp +++ b/src/nostalgia/core/studio/tilesheeteditor.hpp @@ -284,6 +284,8 @@ class TileSheetEditor: public studio::Editor { protected: void saveItem() override; + bool eventFilter(QObject *obj, QEvent *event); + private: QWidget *setupColorPicker(QWidget *widget);