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