Added a custom tool tip base class to handle common window management details.

This commit is contained in:
mjbudd77 2021-07-15 00:54:52 -04:00
parent e31384ab60
commit baa0af5d7c
4 changed files with 189 additions and 40 deletions

View File

@ -4295,15 +4295,16 @@ QAsmView::QAsmView(QWidget *parent)
this->setPalette(pal); this->setPalette(pal);
this->setMouseTracking(true); this->setMouseTracking(true);
showByteCodes = false;
displayROMoffsets = false;
symbolicDebugEnable = true;
registerNameEnable = true;
calcFontData(); calcFontData();
vbar = NULL; vbar = NULL;
hbar = NULL; hbar = NULL;
asmPC = NULL; asmPC = NULL;
displayROMoffsets = false;
symbolicDebugEnable = true;
registerNameEnable = true;
showByteCodes = false;
maxLineLen = 0; maxLineLen = 0;
pxLineWidth = 0; pxLineWidth = 0;
lineOffset = 0; lineOffset = 0;
@ -4796,16 +4797,16 @@ bool QAsmView::event(QEvent *event)
} }
else else
{ {
printf("Tool Tip Hide\n"); //printf("Tool Tip Hide\n");
QToolTip::hideText(); QToolTip::hideText();
event->ignore(); event->ignore();
} }
return true; return true;
} }
else if (event->type() == QEvent::Leave) //else if (event->type() == QEvent::Leave)
{ //{
printf("QEvent::Leave\n"); // printf("QEvent::Leave\n");
} //}
return QWidget::event(event); return QWidget::event(event);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -6268,10 +6269,10 @@ ppuCtrlRegDpy::ppuCtrlRegDpy( QWidget *parent )
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
ppuCtrlRegDpy::~ppuCtrlRegDpy( void ) ppuCtrlRegDpy::~ppuCtrlRegDpy( void )
{ {
if ( popup != NULL ) //if ( popup != NULL )
{ //{
popup->close(); // popup->close();
} //}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool ppuCtrlRegDpy::event(QEvent *event) bool ppuCtrlRegDpy::event(QEvent *event)
@ -6279,36 +6280,23 @@ bool ppuCtrlRegDpy::event(QEvent *event)
if (event->type() == QEvent::ToolTip) if (event->type() == QEvent::ToolTip)
{ {
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event); QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
if ( popup == NULL ) //if ( popup == NULL )
{ //{
printf("Tool Tip Show\n"); // printf("Tool Tip Show\n");
popup = static_cast<ppuRegPopup*>(fceuCustomToolTipShow( helpEvent, new ppuRegPopup(this) )); //}
} popup = static_cast<ppuRegPopup*>(fceuCustomToolTipShow( helpEvent, new ppuRegPopup(this) ));
QToolTip::hideText(); QToolTip::hideText();
event->ignore(); event->ignore();
return true; return true;
} }
else if (event->type() == QEvent::MouseMove)
{
printf("QEvent::MouseMove\n");
}
else if (event->type() == QEvent::Leave)
{
printf("QEvent::Leave\n");
if ( popup )
{
popup->done(0);
popup->deleteLater();
popup = NULL;
}
}
return QWidget::event(event); return QWidget::event(event);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
//-- PPU Register Tool Tip Popup //-- PPU Register Tool Tip Popup
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
ppuRegPopup::ppuRegPopup( QWidget *parent ) ppuRegPopup::ppuRegPopup( QWidget *parent )
: QDialog( parent, Qt::ToolTip ) : fceuCustomToolTip( parent )
{ {
QVBoxLayout *vbox, *vbox1; QVBoxLayout *vbox, *vbox1;
QGridLayout *grid, *grid1; QGridLayout *grid, *grid1;
@ -6330,10 +6318,10 @@ ppuRegPopup::ppuRegPopup( QWidget *parent )
QCheckBox *iBlu_cbox; QCheckBox *iBlu_cbox;
char stmp[32]; char stmp[32];
QPalette pal = this->palette(); //QPalette pal = this->palette();
pal.setColor( QPalette::Window , pal.color(QPalette::ToolTipBase) ); //pal.setColor( QPalette::Window , pal.color(QPalette::ToolTipBase) );
pal.setColor( QPalette::WindowText, pal.color(QPalette::ToolTipText) ); //pal.setColor( QPalette::WindowText, pal.color(QPalette::ToolTipText) );
setPalette(pal); //setPalette(pal);
vbox1 = new QVBoxLayout(); vbox1 = new QVBoxLayout();
vbox = new QVBoxLayout(); vbox = new QVBoxLayout();

View File

@ -29,6 +29,7 @@
#include "Qt/main.h" #include "Qt/main.h"
#include "Qt/SymbolicDebug.h" #include "Qt/SymbolicDebug.h"
#include "Qt/ConsoleUtilities.h"
#include "Qt/ColorMenu.h" #include "Qt/ColorMenu.h"
#include "../../debug.h" #include "../../debug.h"
@ -273,7 +274,7 @@ class DebuggerStackDisplay : public QPlainTextEdit
void sel4BytesPerLine(void); void sel4BytesPerLine(void);
}; };
class ppuRegPopup : public QDialog class ppuRegPopup : public fceuCustomToolTip
{ {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -24,6 +24,8 @@
#include <QWindow> #include <QWindow>
#include <QScreen> #include <QScreen>
#include <QToolTip>
#include <QApplication>
#if WIN32 #if WIN32
#include <Windows.h> #include <Windows.h>
@ -353,6 +355,141 @@ QDialog *fceuCustomToolTipShow( QHelpEvent *helpEvent, QDialog *popup )
return popup; return popup;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
fceuCustomToolTip *fceuCustomToolTip::instance = 0;
//---------------------------------------------------------------------------
fceuCustomToolTip::fceuCustomToolTip( QWidget *parent )
: QDialog( parent, Qt::ToolTip )
{
w = parent;
if ( instance )
{
instance->done(0);
instance->deleteLater();
instance = 0;
}
instance = this;
qApp->installEventFilter(this);
setForegroundRole( QPalette::ToolTipText );
setBackgroundRole( QPalette::ToolTipBase );
setPalette( QToolTip::palette() );
setMouseTracking(true);
//printf("Create Tool Tip\n");
hideTimer = new QTimer( this );
hideTimer->setSingleShot(true);
connect( hideTimer, &QTimer::timeout, this, &fceuCustomToolTip::hideTimerExpired );
}
//---------------------------------------------------------------------------
fceuCustomToolTip::~fceuCustomToolTip( void )
{
//printf("Destroy Tool Tip\n");
if ( instance == this )
{
instance = 0;
}
}
//---------------------------------------------------------------------------
void fceuCustomToolTip::hideTip(void)
{
if ( !hideTimer->isActive() )
{
hideTimer->start( 300 );
}
}
//---------------------------------------------------------------------------
void fceuCustomToolTip::hideTipImmediately(void)
{
close();
deleteLater();
}
//---------------------------------------------------------------------------
void fceuCustomToolTip::hideTimerExpired(void)
{
//printf("Hide Timer Expired:\n");
hideTipImmediately();
}
//---------------------------------------------------------------------------
bool fceuCustomToolTip::eventFilter( QObject *obj, QEvent *event)
{
//printf("Event:%i %p\n", event->type(), obj);
switch (event->type() )
{
case QEvent::Leave:
//if ( obj == w )
//{
// printf("Left parent\n");
//}
hideTip();
break;
case QEvent::Enter:
if ( obj == w )
{
if ( hideTimer->isActive() )
{
hideTimer->stop();
}
//printf("Enter parent\n");
}
break;
case QEvent::WindowActivate:
case QEvent::WindowDeactivate:
case QEvent::FocusIn:
case QEvent::FocusOut:
if ( obj != this )
{
hideTipImmediately();
}
break;
case QEvent::Close:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
hideTipImmediately();
break;
case QEvent::MouseMove:
{
if ( (obj == w) && !rect().isNull() &&
!rect().contains(static_cast<QMouseEvent*>(event)->pos()))
{
hideTip();
}
break;
}
default:
break;
}
return false;
}
//---------------------------------------------------------------------------
void fceuCustomToolTip::mouseMoveEvent(QMouseEvent *event)
{
//printf("QEvent::MouseMove\n");
if (!w->rect().isNull())
{
QPoint pos = event->globalPos();
pos = mapFromGlobal(pos);
//printf("QEvent::MouseMove: (%i,%i) (%i,%i)\n",
// event->globalPos().x(), event->globalPos().y(), pos.x(), pos.y() );
if (!w->rect().contains(pos))
{
done(0);
deleteLater();
}
}
}
//---------------------------------------------------------------------------
// FCEU Data Entry Custom Validators // FCEU Data Entry Custom Validators
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
fceuDecIntValidtor::fceuDecIntValidtor( int min, int max, QObject *parent) fceuDecIntValidtor::fceuDecIntValidtor( int min, int max, QObject *parent)

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <QColor> #include <QColor>
#include <QTimer>
#include <QValidator> #include <QValidator>
#include <QDialog> #include <QDialog>
#include <QHelpEvent> #include <QHelpEvent>
@ -34,8 +35,8 @@ class fceuDecIntValidtor : public QValidator
class fceuHexIntValidtor : public QValidator class fceuHexIntValidtor : public QValidator
{ {
public: public:
fceuHexIntValidtor( int min, int max, QObject *parent); fceuHexIntValidtor( int min, int max, QObject *parent);
QValidator::State validate(QString &input, int &pos) const; QValidator::State validate(QString &input, int &pos) const;
@ -45,6 +46,28 @@ class fceuHexIntValidtor : public QValidator
int max; int max;
}; };
class fceuCustomToolTip : public QDialog
{
public:
fceuCustomToolTip( QWidget *parent = nullptr );
~fceuCustomToolTip( void );
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
void mouseMoveEvent( QMouseEvent *event ) override;
void hideTip(void);
void hideTipImmediately(void);
private:
QWidget *w;
QTimer *hideTimer;
static fceuCustomToolTip *instance;
private slots:
void hideTimerExpired(void);
};
QString fceuGetOpcodeToolTip( uint8_t *opcode, int size ); QString fceuGetOpcodeToolTip( uint8_t *opcode, int size );
QDialog *fceuCustomToolTipShow( QHelpEvent *helpEvent, QDialog *popup ); QDialog *fceuCustomToolTipShow( QHelpEvent *helpEvent, QDialog *popup );