From 6f4537733c25b4d433270c8733f60d50fff62492 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 24 Jan 2021 11:24:05 -0500 Subject: [PATCH] Added a help menu to new Qt PPU pattern table tile editor. --- src/drivers/Qt/ppuViewer.cpp | 97 ++++++++++++++++++++++++++++++++++++ src/drivers/Qt/ppuViewer.h | 1 + 2 files changed, 98 insertions(+) diff --git a/src/drivers/Qt/ppuViewer.cpp b/src/drivers/Qt/ppuViewer.cpp index 0cde1a94..9ccdc7ba 100644 --- a/src/drivers/Qt/ppuViewer.cpp +++ b/src/drivers/Qt/ppuViewer.cpp @@ -26,9 +26,12 @@ #include #include #include +#include #include #include #include +#include +#include #include "../../types.h" #include "../../fceu.h" @@ -1024,9 +1027,38 @@ ppuTileEditor_t::ppuTileEditor_t(int patternIndex, QWidget *parent) { QVBoxLayout *mainLayout; QHBoxLayout *hbox; + QMenuBar *menuBar; + QMenu *helpMenu; + QAction *act; + int useNativeMenuBar; this->setFocusPolicy(Qt::StrongFocus); + menuBar = new QMenuBar(this); + + // This is needed for menu bar to show up on MacOS + g_config->getOption( "SDL.UseNativeMenuBar", &useNativeMenuBar ); + + menuBar->setNativeMenuBar( useNativeMenuBar ? true : false ); + + //----------------------------------------------------------------------- + // Menu + //----------------------------------------------------------------------- + // Help + helpMenu = menuBar->addMenu(tr("Help")); + + // Help -> Key Assignments + act = new QAction(tr("Keys"), this); + //act->setShortcut(QKeySequence::Open); + act->setStatusTip(tr("View Key Descriptions")); + connect(act, SIGNAL(triggered()), this, SLOT(showKeyAssignments(void)) ); + + helpMenu->addAction(act); + + //----------------------------------------------------------------------- + // End Menu + //----------------------------------------------------------------------- + tileAddr = 0; palIdx = pindex[ patternIndex ]; @@ -1036,6 +1068,8 @@ ppuTileEditor_t::ppuTileEditor_t(int patternIndex, QWidget *parent) mainLayout = new QVBoxLayout(); + mainLayout->setMenuBar( menuBar ); + setLayout( mainLayout ); //vbox = new QVBoxLayout(); @@ -1186,6 +1220,69 @@ void ppuTileEditor_t::setCellValue( int y, int x, int colorIndex ) } //---------------------------------------------------- +void ppuTileEditor_t::showKeyAssignments(void) +{ + int i; + QDialog *dialog; + QVBoxLayout *mainLayout; + QTreeWidget *tree; + QTreeWidgetItem *item; + const char *txt[] = + { + "Up" , "Move Selected Cell Up", + "Down" , "Move Selected Cell Down", + "Left" , "Move Selected Cell Left", + "Right", "Move Selected Cell Right", + "1" , "Set Selected Cell to Color #1", + "2" , "Set Selected Cell to Color #2", + "3" , "Set Selected Cell to Color #3", + "4" , "Set Selected Cell to Color #4", + "P" , "Cycle to Next Tile Palette", + "ESC" , "Close Window", + NULL + }; + + dialog = new QDialog(this); + dialog->setWindowTitle("Tile Editor Key Descriptions"); + dialog->resize( 512, 512 ); + + tree = new QTreeWidget(); + + tree->setColumnCount(2); + + item = new QTreeWidgetItem(); + item->setText( 0, QString::fromStdString( "Key" ) ); + item->setText( 1, QString::fromStdString( "Description" ) ); + item->setTextAlignment( 0, Qt::AlignLeft); + item->setTextAlignment( 1, Qt::AlignLeft); + + tree->setHeaderItem( item ); + + tree->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); + + i=0; + while ( txt[i] != NULL ) + { + + item = new QTreeWidgetItem(); + + item->setText( 0, tr(txt[i]) ); i++; + item->setText( 1, tr(txt[i]) ); i++; + + item->setTextAlignment( 0, Qt::AlignLeft); + item->setTextAlignment( 1, Qt::AlignLeft); + + tree->addTopLevelItem( item ); + } + mainLayout = new QVBoxLayout(); + + mainLayout->addWidget( tree ); + + dialog->setLayout( mainLayout ); + + dialog->show(); +} +//---------------------------------------------------- void ppuTileEditor_t::keyPressEvent(QKeyEvent *event) { //printf("Tile Editor Key Press: 0x%x \n", event->key() ); diff --git a/src/drivers/Qt/ppuViewer.h b/src/drivers/Qt/ppuViewer.h index 18b14c07..d8a208cd 100644 --- a/src/drivers/Qt/ppuViewer.h +++ b/src/drivers/Qt/ppuViewer.h @@ -223,6 +223,7 @@ class ppuTileEditor_t : public QDialog private slots: void periodicUpdate(void); void paletteChanged(int index); + void showKeyAssignments(void); }; class ppuViewerDialog_t : public QDialog