Qt TAS editor key logic in work.

This commit is contained in:
mjbudd77 2021-11-10 21:07:18 -05:00
parent 8b4caef750
commit d2193d3e83
3 changed files with 91 additions and 8 deletions

View File

@ -41,6 +41,7 @@
#include "driver.h" #include "driver.h"
#include "Qt/config.h" #include "Qt/config.h"
#include "Qt/keyscan.h"
#include "Qt/throttle.h" #include "Qt/throttle.h"
#include "Qt/fceuWrapper.h" #include "Qt/fceuWrapper.h"
#include "Qt/ConsoleUtilities.h" #include "Qt/ConsoleUtilities.h"
@ -951,15 +952,22 @@ void TasEditorWindow::buildPianoRollDisplay(void)
QHBoxLayout *hbox; QHBoxLayout *hbox;
QGridLayout *grid; QGridLayout *grid;
pianoRollFrame = new QFrame();
grid = new QGridLayout(); grid = new QGridLayout();
pianoRoll = new QPianoRoll(this); pianoRoll = new QPianoRoll(this);
pianoRollVBar = new QScrollBar( Qt::Vertical, this ); pianoRollVBar = new QScrollBar( Qt::Vertical, this );
pianoRollHBar = new QScrollBar( Qt::Horizontal, this ); pianoRollHBar = new QScrollBar( Qt::Horizontal, this );
upperMarkerLabel = new QLabel( tr("Marker 0") ); upperMarkerLabel = new QLabel( tr("Marker 0") );
lowerMarkerLabel = new QLabel( tr("Marker 1") ); lowerMarkerLabel = new QLabel( tr("Marker 0") );
upperMarkerNote = new QLineEdit(); upperMarkerNote = new QLineEdit();
lowerMarkerNote = new QLineEdit(); lowerMarkerNote = new QLineEdit();
pianoRollFrame->setLineWidth(2);
pianoRollFrame->setMidLineWidth(1);
//pianoRollFrame->setFrameShape( QFrame::StyledPanel );
pianoRollFrame->setFrameShape( QFrame::Box );
pianoRollVBar->setInvertedAppearance(true);
pianoRoll->setScrollBars( pianoRollHBar, pianoRollVBar ); pianoRoll->setScrollBars( pianoRollHBar, pianoRollVBar );
connect( pianoRollHBar, SIGNAL(valueChanged(int)), pianoRoll, SLOT(hbarChanged(int)) ); connect( pianoRollHBar, SIGNAL(valueChanged(int)), pianoRoll, SLOT(hbarChanged(int)) );
connect( pianoRollVBar, SIGNAL(valueChanged(int)), pianoRoll, SLOT(vbarChanged(int)) ); connect( pianoRollVBar, SIGNAL(valueChanged(int)), pianoRoll, SLOT(vbarChanged(int)) );
@ -980,7 +988,9 @@ void TasEditorWindow::buildPianoRollDisplay(void)
hbox->addWidget( upperMarkerNote, 10 ); hbox->addWidget( upperMarkerNote, 10 );
vbox->addLayout( hbox, 1 ); vbox->addLayout( hbox, 1 );
vbox->addLayout( grid, 100 ); vbox->addWidget( pianoRollFrame, 100 );
//vbox->addLayout( grid, 100 );
pianoRollFrame->setLayout( grid );
hbox = new QHBoxLayout(); hbox = new QHBoxLayout();
hbox->addWidget( lowerMarkerLabel, 1 ); hbox->addWidget( lowerMarkerLabel, 1 );
@ -2159,7 +2169,7 @@ void QPianoRoll::hbarChanged(int val)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void QPianoRoll::vbarChanged(int val) void QPianoRoll::vbarChanged(int val)
{ {
lineOffset = val; lineOffset = maxLineOffset - val;
if ( lineOffset < 0 ) if ( lineOffset < 0 )
{ {
@ -2311,6 +2321,8 @@ void QPianoRoll::ensureTheLineIsVisible( int lineNum )
{ {
lineOffset = 0; lineOffset = 0;
} }
vbar->setValue( lineOffset );
update(); update();
} }
} }
@ -2324,14 +2336,20 @@ void QPianoRoll::resizeEvent(QResizeEvent *event)
viewLines = (viewHeight / pxLineSpacing) + 1; viewLines = (viewHeight / pxLineSpacing) + 1;
maxLineOffset = currMovieData.records.size() - viewLines + 1; maxLineOffset = currMovieData.records.size() - viewLines + 5;
if ( maxLineOffset < 0 ) if ( maxLineOffset < 0 )
{ {
vbar->hide();
maxLineOffset = 0; maxLineOffset = 0;
} }
else
{
vbar->show();
}
vbar->setMinimum(0); vbar->setMinimum(0);
vbar->setMaximum(maxLineOffset); vbar->setMaximum(maxLineOffset);
vbar->setPageStep( (3*viewLines)/4 );
if ( viewWidth >= pxLineWidth ) if ( viewWidth >= pxLineWidth )
{ {
@ -2345,11 +2363,12 @@ void QPianoRoll::resizeEvent(QResizeEvent *event)
hbar->show(); hbar->show();
pxLineXScroll = hbar->value(); pxLineXScroll = hbar->value();
} }
vbar->setPageStep( (3*viewLines)/4 );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void QPianoRoll::mousePressEvent(QMouseEvent * event) void QPianoRoll::mousePressEvent(QMouseEvent * event)
{ {
fceuCriticalSection emuLock;
int col, line, row_index, column_index, kbModifiers, alt_pressed; int col, line, row_index, column_index, kbModifiers, alt_pressed;
QPoint c = convPixToCursor( event->pos() ); QPoint c = convPixToCursor( event->pos() );
@ -2506,6 +2525,7 @@ void QPianoRoll::mousePressEvent(QMouseEvent * event)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void QPianoRoll::mouseReleaseEvent(QMouseEvent * event) void QPianoRoll::mouseReleaseEvent(QMouseEvent * event)
{ {
fceuCriticalSection emuLock;
int col, line; int col, line;
QPoint c = convPixToCursor( event->pos() ); QPoint c = convPixToCursor( event->pos() );
@ -2532,6 +2552,7 @@ void QPianoRoll::mouseReleaseEvent(QMouseEvent * event)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void QPianoRoll::mouseMoveEvent(QMouseEvent * event) void QPianoRoll::mouseMoveEvent(QMouseEvent * event)
{ {
fceuCriticalSection emuLock;
int col, line; int col, line;
QPoint c = convPixToCursor( event->pos() ); QPoint c = convPixToCursor( event->pos() );
@ -2544,7 +2565,7 @@ void QPianoRoll::mouseMoveEvent(QMouseEvent * event)
rowUnderMouse = realRowUnderMouse = line; rowUnderMouse = realRowUnderMouse = line;
columnUnderMouse = col; columnUnderMouse = col;
printf("Mouse Move Event: 0x%x (%i,%i) Col:%i\n", event->button(), c.x(), c.y(), col ); //printf("Mouse Move Event: 0x%x (%i,%i) Col:%i\n", event->button(), c.x(), c.y(), col );
if ( event->button() == Qt::LeftButton ) if ( event->button() == Qt::LeftButton )
{ {
@ -2553,6 +2574,40 @@ void QPianoRoll::mouseMoveEvent(QMouseEvent * event)
updateDrag(); updateDrag();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void QPianoRoll::keyPressEvent(QKeyEvent *event)
{
//printf("Key Press: 0x%x \n", event->key() );
pushKeyEvent( event, 1 );
event->accept();
}
void QPianoRoll::keyReleaseEvent(QKeyEvent *event)
{
//printf("Key Release: 0x%x \n", event->key() );
pushKeyEvent( event, 0 );
event->accept();
}
//----------------------------------------------------------------------------
void QPianoRoll::focusInEvent(QFocusEvent *event)
{
QWidget::focusInEvent(event);
printf("PianoRoll Focus In\n");
parent->pianoRollFrame->setStyleSheet("QFrame { border: 2px solid rgb(48,140,198); }");
}
//----------------------------------------------------------------------------
void QPianoRoll::focusOutEvent(QFocusEvent *event)
{
QWidget::focusOutEvent(event);
printf("PianoRoll Focus Out\n");
parent->pianoRollFrame->setStyleSheet(NULL);
}
//----------------------------------------------------------------------------
void QPianoRoll::updateDrag(void) void QPianoRoll::updateDrag(void)
{ {
int kbModifiers, altHeld; int kbModifiers, altHeld;
@ -3033,7 +3088,7 @@ void QPianoRoll::paintEvent(QPaintEvent *event)
{ {
int x, y, row, nrow, lineNum; int x, y, row, nrow, lineNum;
QPainter painter(this); QPainter painter(this);
QColor white("white"), black("black"), blkColor; QColor white(255,255,255), black(0,0,0), blkColor;
static const char *buttonNames[] = { "A", "B", "S", "T", "U", "D", "L", "R", NULL }; static const char *buttonNames[] = { "A", "B", "S", "T", "U", "D", "L", "R", NULL };
char stmp[32]; char stmp[32];
char rowIsSel=0; char rowIsSel=0;
@ -3048,12 +3103,19 @@ void QPianoRoll::paintEvent(QPaintEvent *event)
viewLines = nrow; viewLines = nrow;
maxLineOffset = currMovieData.records.size() - nrow + 1; maxLineOffset = currMovieData.records.size() - nrow + 5;
if ( maxLineOffset < 0 ) if ( maxLineOffset < 0 )
{ {
vbar->hide();
maxLineOffset = 0; maxLineOffset = 0;
} }
else
{
vbar->show();
}
lineOffset = maxLineOffset - vbar->value();
if ( lineOffset < 0 ) if ( lineOffset < 0 )
{ {

View File

@ -88,6 +88,10 @@ class QPianoRoll : public QWidget
void mousePressEvent(QMouseEvent * event); void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent * event); void mouseMoveEvent(QMouseEvent * event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);
void startDraggingPlaybackCursor(void); void startDraggingPlaybackCursor(void);
void startDraggingMarker(int mouseX, int mouseY, int rowIndex, int columnIndex); void startDraggingMarker(int mouseX, int mouseY, int rowIndex, int columnIndex);
@ -208,6 +212,7 @@ class TasEditorWindow : public QDialog
QAction *showToolTipsAct; QAction *showToolTipsAct;
QSplitter *mainHBox; QSplitter *mainHBox;
QFrame *pianoRollFrame;
QWidget *pianoRollContainerWidget; QWidget *pianoRollContainerWidget;
QWidget *controlPanelContainerWidget; QWidget *controlPanelContainerWidget;
QScrollBar *pianoRollHBar; QScrollBar *pianoRollHBar;
@ -316,6 +321,7 @@ class TasEditorWindow : public QDialog
friend class SELECTION; friend class SELECTION;
friend class PLAYBACK; friend class PLAYBACK;
friend class HISTORY; friend class HISTORY;
friend class QPianoRoll;
}; };
extern TASEDITOR_PROJECT *project; extern TASEDITOR_PROJECT *project;

View File

@ -43,3 +43,18 @@ int fceuWrapperTogglePause(void);
bool fceuWrapperGameLoaded(void); bool fceuWrapperGameLoaded(void);
void fceuWrapperRequestAppExit(void); void fceuWrapperRequestAppExit(void);
class fceuCriticalSection
{
public:
fceuCriticalSection(void)
{
//printf("Wrapper Lock\n");
fceuWrapperLock();
}
~fceuCriticalSection(void)
{
//printf("Wrapper UnLock\n");
fceuWrapperUnLock();
}
};