From 9633f081caafb7216a9d076702514921966bc6b9 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sat, 11 Dec 2021 20:54:19 -0500 Subject: [PATCH] Changed bookmark image view implementation so that it doesn't use tooltip events. --- src/drivers/Qt/ConsoleDebugger.cpp | 6 +-- src/drivers/Qt/ConsoleUtilities.cpp | 10 ++--- src/drivers/Qt/ConsoleUtilities.h | 2 +- src/drivers/Qt/TasEditor/bookmarks.cpp | 51 +++++++++++++++++++++++--- src/drivers/Qt/TasEditor/bookmarks.h | 17 +++++---- src/drivers/Qt/TasEditor/branches.cpp | 31 +++++++++++++++- src/drivers/Qt/TasEditor/branches.h | 7 ++++ 7 files changed, 99 insertions(+), 25 deletions(-) diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 763aaa82..5ab1e692 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -5272,7 +5272,7 @@ bool QAsmView::event(QEvent *event) asmEntry[line]->addr, asmEntry[line]->bank, asmEntry[line]->rom ); } - //static_cast(fceuCustomToolTipShow( helpEvent, new asmLookAheadPopup(asmEntry[line]->addr, this) )); + //static_cast(fceuCustomToolTipShow( helpEvent->globalPos(), new asmLookAheadPopup(asmEntry[line]->addr, this) )); QToolTip::showText(helpEvent->globalPos(), tr(stmp), this ); //QToolTip::hideText(); //event->ignore(); @@ -5297,7 +5297,7 @@ bool QAsmView::event(QEvent *event) addr, bank, romOfs ); } - static_cast(fceuCustomToolTipShow( helpEvent, new asmLookAheadPopup(addr, this) )); + static_cast(fceuCustomToolTipShow( helpEvent->globalPos(), new asmLookAheadPopup(addr, this) )); //QToolTip::showText(helpEvent->globalPos(), tr(stmp), this ); QToolTip::hideText(); event->ignore(); @@ -6866,7 +6866,7 @@ bool ppuCtrlRegDpy::event(QEvent *event) //{ // printf("Tool Tip Show\n"); //} - popup = static_cast(fceuCustomToolTipShow( helpEvent, new ppuRegPopup(this) )); + popup = static_cast(fceuCustomToolTipShow( helpEvent->globalPos(), new ppuRegPopup(this) )); QToolTip::hideText(); event->ignore(); diff --git a/src/drivers/Qt/ConsoleUtilities.cpp b/src/drivers/Qt/ConsoleUtilities.cpp index 0e9abc3e..a9e5bff1 100644 --- a/src/drivers/Qt/ConsoleUtilities.cpp +++ b/src/drivers/Qt/ConsoleUtilities.cpp @@ -312,7 +312,7 @@ int fceuLoadConfigColor( const char *confName, QColor *color ) //--------------------------------------------------------------------------- // FCEU Custom Tool Tip Helper Functions //--------------------------------------------------------------------------- -QDialog *fceuCustomToolTipShow( QHelpEvent *helpEvent, QDialog *popup ) +QDialog *fceuCustomToolTipShow( const QPoint &globalPos, QDialog *popup ) { int xo = 32, yo = 32; QPoint pos; @@ -332,19 +332,19 @@ QDialog *fceuCustomToolTipShow( QHelpEvent *helpEvent, QDialog *popup ) popup->show(); - pos.setX( helpEvent->globalPos().x() + xo ); - pos.setY( helpEvent->globalPos().y() + yo ); + pos.setX( globalPos.x() + xo ); + pos.setY( globalPos.y() + yo ); if ( scr ) { if ( ( (pos.x() + popup->width()) > scr->virtualSize().width() ) ) { - pos.setX( helpEvent->globalPos().x() - popup->width() - xo ); + pos.setX( globalPos.x() - popup->width() - xo ); } if ( ( (pos.y() + popup->height()) > scr->virtualSize().height() ) ) { - pos.setY( helpEvent->globalPos().y() - popup->height() - yo ); + pos.setY( globalPos.y() - popup->height() - yo ); } popup->move( pos ); } diff --git a/src/drivers/Qt/ConsoleUtilities.h b/src/drivers/Qt/ConsoleUtilities.h index 6223c7ab..032030d1 100644 --- a/src/drivers/Qt/ConsoleUtilities.h +++ b/src/drivers/Qt/ConsoleUtilities.h @@ -90,4 +90,4 @@ class QCheckBoxRO : public QCheckBox QString fceuGetOpcodeToolTip( uint8_t *opcode, int size ); -QDialog *fceuCustomToolTipShow( QHelpEvent *helpEvent, QDialog *popup ); +QDialog *fceuCustomToolTipShow( const QPoint &globalPos, QDialog *popup ); diff --git a/src/drivers/Qt/TasEditor/bookmarks.cpp b/src/drivers/Qt/TasEditor/bookmarks.cpp index c5fdeca6..cfe240d4 100644 --- a/src/drivers/Qt/TasEditor/bookmarks.cpp +++ b/src/drivers/Qt/TasEditor/bookmarks.cpp @@ -47,9 +47,9 @@ Bookmarks/Branches - Manager of Bookmarks //extern BRANCHES branches; // resources -char bookmarks_save_id[BOOKMARKS_ID_LEN] = "BOOKMARKS"; -char bookmarks_skipsave_id[BOOKMARKS_ID_LEN] = "BOOKMARKX"; -char bookmarksCaption[3][23] = { " Bookmarks ", " Bookmarks / Branches ", " Branches " }; +static char bookmarks_save_id[BOOKMARKS_ID_LEN] = "BOOKMARKS"; +static char bookmarks_skipsave_id[BOOKMARKS_ID_LEN] = "BOOKMARKX"; +//char bookmarksCaption[3][23] = { " Bookmarks ", " Bookmarks / Branches ", " Branches " }; // color tables for flashing when saving/loading bookmarks //COLORREF bookmark_flash_colors[TOTAL_BOOKMARK_COMMANDS][FLASH_PHASE_MAX+1] = { // // set @@ -68,6 +68,12 @@ BOOKMARKS::BOOKMARKS(QWidget *parent) viewWidth = 256; viewHeight = 256; + imageItem = 0; + imageTimer = new QTimer(this); + imageTimer->setSingleShot(true); + imageTimer->setInterval(100); + connect( imageTimer, SIGNAL(timeout(void)), this, SLOT(showImage(void)) ); + g_config->getOption("SDL.TasBookmarksFont", &fontString); if ( fontString.size() > 0 ) @@ -97,6 +103,7 @@ void BOOKMARKS::init() reset(); selectedSlot = DEFAULT_SLOT; + imageItem = 0; redrawBookmarksSectionCaption(); } @@ -125,6 +132,7 @@ void BOOKMARKS::reset_vars() mustCheckItemUnderMouse = true; bookmarkLeftclicked = bookmarkRightclicked = ITEM_UNDER_MOUSE_NONE; nextFlashUpdateTime = clock() + BOOKMARKS_FLASH_TICK; + imageItem = 0; } void BOOKMARKS::setFont( QFont &newFont ) @@ -727,6 +735,7 @@ int BOOKMARKS::calcColumn( int px ) void BOOKMARKS::mousePressEvent(QMouseEvent * event) { + fceuCriticalSection emuLock; int item, row_under_mouse, item_valid; QPoint c = convPixToCursor( event->pos() ); @@ -765,6 +774,7 @@ void BOOKMARKS::mousePressEvent(QMouseEvent * event) void BOOKMARKS::mouseReleaseEvent(QMouseEvent * event) { + fceuCriticalSection emuLock; //QPoint c = convPixToCursor( event->pos() ); //printf("Mouse Button Released: 0x%x (%i,%i)\n", event->button(), c.x(), c.y() ); @@ -787,11 +797,37 @@ void BOOKMARKS::mouseReleaseEvent(QMouseEvent * event) } } +void BOOKMARKS::showImage(void) +{ + static_cast(fceuCustomToolTipShow( imagePos, new bookmarkPreviewPopup(imageItem, this) )); +} + void BOOKMARKS::mouseMoveEvent(QMouseEvent * event) { - //QPoint c = convPixToCursor( event->pos() ); + fceuCriticalSection emuLock; + int item, row_under_mouse, item_valid, column; + + QPoint c = convPixToCursor( event->pos() ); //printf("Mouse Move: 0x%x (%i,%i)\n", event->button(), c.x(), c.y() ); + + row_under_mouse = c.y(); + column = calcColumn( event->pos().x() ); + + item = (row_under_mouse + 1) % TOTAL_BOOKMARKS; + item_valid = (item >= 0) && (item < TOTAL_BOOKMARKS); + + if ( item_valid && (column == BOOKMARKSLIST_COLUMN_TIME) && bookmarks->bookmarksArray[item].notEmpty) + { + imageItem = item; + imagePos = event->globalPos(); + imageTimer->start(); + QToolTip::hideText(); + } + else + { + imageTimer->stop(); + } } bool BOOKMARKS::event(QEvent *event) @@ -811,7 +847,7 @@ bool BOOKMARKS::event(QEvent *event) if ( item_valid && (column == BOOKMARKSLIST_COLUMN_TIME) && bookmarks->bookmarksArray[item].notEmpty) { - static_cast(fceuCustomToolTipShow( helpEvent, new bookmarkPreviewPopup(item, this) )); + //static_cast(fceuCustomToolTipShow( helpEvent, new bookmarkPreviewPopup(item, this) )); //QToolTip::showText(helpEvent->globalPos(), tr(stmp), this ); QToolTip::hideText(); event->ignore(); @@ -820,7 +856,10 @@ bool BOOKMARKS::event(QEvent *event) { QToolTip::showText(helpEvent->globalPos(), tr("Right click = set Bookmark, Left click = jump to Bookmark or load Branch"), this ); } - + else + { + QToolTip::hideText(); + } return true; } return QWidget::event(event); diff --git a/src/drivers/Qt/TasEditor/bookmarks.h b/src/drivers/Qt/TasEditor/bookmarks.h index 8e8d393c..25b659bc 100644 --- a/src/drivers/Qt/TasEditor/bookmarks.h +++ b/src/drivers/Qt/TasEditor/bookmarks.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -74,8 +75,6 @@ public: void command(int command_id, int slot = -1); - //void getDispInfo(NMLVDISPINFO* nmlvDispInfo); - //LONG handleCustomDraw(NMLVCUSTOMDRAW* msg); void handleLeftClick(); void handleRightClick(); @@ -100,14 +99,11 @@ public: bool mustCheckItemUnderMouse; bool mouseOverBranchesBitmap, mouseOverBookmarksList; int itemUnderMouse; - //TRACKMOUSEEVENT tme, tmeList; int bookmarkLeftclicked, bookmarkRightclicked, columnClicked; int listTopMargin; int listRowLeft; int listRowHeight; - //HWND hwndBookmarksList, hwndBranchesBitmap, hwndBookmarks; - protected: void resizeEvent(QResizeEvent *event); void paintEvent(QPaintEvent *event); @@ -131,13 +127,15 @@ private: int nextFlashUpdateTime; int mouseX, mouseY; - // GDI stuff - //HFONT hBookmarksFont; - //HIMAGELIST hImgList; + // GUI stuff QFont font; QScrollBar *hbar; QScrollBar *vbar; + QTimer *imageTimer; + QPoint imagePos; + + int imageItem; int viewWidth; int viewHeight; int viewLines; @@ -156,4 +154,7 @@ private: int pxStartCol1; int pxStartCol2; int pxStartCol3; + + private slots: + void showImage(void); }; diff --git a/src/drivers/Qt/TasEditor/branches.cpp b/src/drivers/Qt/TasEditor/branches.cpp index c1fcea70..4df822e3 100644 --- a/src/drivers/Qt/TasEditor/branches.cpp +++ b/src/drivers/Qt/TasEditor/branches.cpp @@ -57,6 +57,12 @@ BRANCHES::BRANCHES(QWidget *parent) { std::string fontString; + imageItem = 0; + imageTimer = new QTimer(this); + imageTimer->setSingleShot(true); + imageTimer->setInterval(100); + connect( imageTimer, SIGNAL(timeout(void)), this, SLOT(showImage(void)) ); + //this->parent = qobject_cast ( parent ); this->setFocusPolicy(Qt::StrongFocus); this->setMouseTracking(true); @@ -559,12 +565,33 @@ void BRANCHES::mouseReleaseEvent(QMouseEvent * event) } } +void BRANCHES::showImage(void) +{ + static_cast(fceuCustomToolTipShow( imagePos, new bookmarkPreviewPopup(imageItem, this) )); +} + void BRANCHES::mouseMoveEvent(QMouseEvent * event) { - int item = findItemUnderMouse( event->pos().x(), event->pos().y() ); + int item, item_valid; + + item = findItemUnderMouse( event->pos().x(), event->pos().y() ); + + item_valid = (item >= 0) && (item < TOTAL_BOOKMARKS); bookmarks->itemUnderMouse = item; + if ( item_valid && bookmarks->bookmarksArray[item].notEmpty) + { + imageItem = item; + imagePos = event->globalPos(); + imageTimer->start(); + QToolTip::hideText(); + } + else + { + imageTimer->stop(); + } + //if (event->button() & Qt::LeftButton) //{ @@ -589,7 +616,7 @@ bool BRANCHES::event(QEvent *event) if ( item_valid && bookmarks->bookmarksArray[item].notEmpty) { - static_cast(fceuCustomToolTipShow( helpEvent, new bookmarkPreviewPopup(item, this) )); + //static_cast(fceuCustomToolTipShow( helpEvent->globalPos(), new bookmarkPreviewPopup(item, this) )); //QToolTip::showText(helpEvent->globalPos(), tr(stmp), this ); QToolTip::hideText(); event->ignore(); diff --git a/src/drivers/Qt/TasEditor/branches.h b/src/drivers/Qt/TasEditor/branches.h index fe5488a1..45c7cdc5 100644 --- a/src/drivers/Qt/TasEditor/branches.h +++ b/src/drivers/Qt/TasEditor/branches.h @@ -5,6 +5,7 @@ #include #include +#include #include #define BRANCHES_ANIMATION_TICK (40 * CLOCKS_PER_SEC / 1000) // animate at 25FPS @@ -189,7 +190,10 @@ private: int lastItemUnderMouse; QFont font; + QPoint imagePos; + QTimer *imageTimer; + int imageItem; int viewWidth; int viewHeight; int pxCharWidth; @@ -207,4 +211,7 @@ private: std::vector gridY; std::vector gridHeight; std::vector> children; + + private slots: + void showImage(void); };