[nostalgia/core/studio] Make number keys map to color indices in TileSheetEditor

This commit is contained in:
Gary Talent 2020-12-18 00:04:34 -06:00
parent 843da4a810
commit d98a5e386a
2 changed files with 17 additions and 0 deletions

View File

@ -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<QKeyEvent*>(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);

View File

@ -284,6 +284,8 @@ class TileSheetEditor: public studio::Editor {
protected:
void saveItem() override;
bool eventFilter(QObject *obj, QEvent *event);
private:
QWidget *setupColorPicker(QWidget *widget);