Reimplemented Qt bookmark preview popup window to allow for alpha fade effect.

This commit is contained in:
mjbudd77 2021-12-28 21:52:10 -05:00
parent fd1f33f27e
commit 57ed6d8ecc
6 changed files with 214 additions and 8 deletions

View File

@ -6468,17 +6468,31 @@ void QPianoRoll::paintEvent(QPaintEvent *event)
//---- Bookmark Preview Popup //---- Bookmark Preview Popup
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bookmarkPreviewPopup *bookmarkPreviewPopup::instance = 0;
//----------------------------------------------------------------------------
bookmarkPreviewPopup::bookmarkPreviewPopup( int index, QWidget *parent ) bookmarkPreviewPopup::bookmarkPreviewPopup( int index, QWidget *parent )
: fceuCustomToolTip( parent ) : QDialog( parent, Qt::ToolTip )
{ {
int p; int p;
QPoint pos;
QVBoxLayout *vbox; QVBoxLayout *vbox;
QLabel *imgLbl, *descLbl; QLabel *imgLbl, *descLbl;
uint32_t *pixBuf; uint32_t *pixBuf;
uint32_t pixel; uint32_t pixel;
QPixmap pixmap; QPixmap pixmap;
setHideOnMouseMove(true); if ( instance )
{
//instance->done(0);
//instance->deleteLater();
instance->actv = false;
instance = 0;
}
instance = this;
imageIndex = index;
//qApp->installEventFilter(this);
fceuWrapperLock(); fceuWrapperLock();
@ -6534,11 +6548,32 @@ bookmarkPreviewPopup::bookmarkPreviewPopup( int index, QWidget *parent )
{ {
free( pixBuf ); pixBuf = NULL; free( pixBuf ); pixBuf = NULL;
} }
pos = parent->mapToGlobal(QPoint(0,0));
pos.setX( pos.x() - 300 );
move(pos);
fceuWrapperUnLock(); fceuWrapperUnLock();
alpha = 0;
actv = true;
setWindowOpacity(0.0f);
timer = new QTimer(this);
connect( timer, &QTimer::timeout, this, &bookmarkPreviewPopup::periodicUpdate );
timer->start(33);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bookmarkPreviewPopup::~bookmarkPreviewPopup( void ) bookmarkPreviewPopup::~bookmarkPreviewPopup( void )
{ {
timer->stop();
if ( screenShotRaster != NULL ) if ( screenShotRaster != NULL )
{ {
free( screenShotRaster ); screenShotRaster = NULL; free( screenShotRaster ); screenShotRaster = NULL;
@ -6546,6 +6581,70 @@ bookmarkPreviewPopup::~bookmarkPreviewPopup( void )
//printf("Popup Deleted\n"); //printf("Popup Deleted\n");
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void bookmarkPreviewPopup::periodicUpdate(void)
{
if ( actv )
{
if ( alpha < 255 )
{
alpha += 10;
if ( alpha > 255 )
{
alpha = 255;
}
setWindowOpacity( alpha / 255.0f );
update();
}
}
else
{
if ( alpha > 0 )
{
alpha -= 10;
if ( alpha < 0 )
{
alpha = 0;
}
setWindowOpacity( alpha / 255.0f );
update();
}
else
{
if ( instance == this )
{
instance = NULL;
}
done(0);
deleteLater();
}
}
}
//----------------------------------------------------------------------------
int bookmarkPreviewPopup::currentIndex(void)
{
if ( instance )
{
return instance->imageIndex;
}
return -1;
}
//----------------------------------------------------------------------------
void bookmarkPreviewPopup::imageIndexChanged(int newIndex)
{
//printf("newIndex:%i\n", newIndex );
actv = false;
if ( instance == this )
{
instance = NULL;
}
}
//----------------------------------------------------------------------------
int bookmarkPreviewPopup::loadImage(int index) int bookmarkPreviewPopup::loadImage(int index)
{ {
// uncompress // uncompress

View File

@ -114,17 +114,29 @@ struct NewProjectParameters
std::wstring authorName; std::wstring authorName;
}; };
class bookmarkPreviewPopup : public fceuCustomToolTip class bookmarkPreviewPopup : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
bookmarkPreviewPopup( int index, QWidget *parent = nullptr ); bookmarkPreviewPopup( int index, QWidget *parent = nullptr );
~bookmarkPreviewPopup(void); ~bookmarkPreviewPopup(void);
private: static int currentIndex(void);
int loadImage(int index);
unsigned char *screenShotRaster; private:
int loadImage(int index);
int alpha;
int imageIndex;
bool actv;
unsigned char *screenShotRaster;
QTimer *timer;
static bookmarkPreviewPopup *instance;
public slots:
void periodicUpdate(void);
void imageIndexChanged(int);
}; };
class markerDragPopup : public QDialog class markerDragPopup : public QDialog

View File

@ -788,7 +788,17 @@ void BOOKMARKS::mouseReleaseEvent(QMouseEvent * event)
void BOOKMARKS::showImage(void) void BOOKMARKS::showImage(void)
{ {
fceuCriticalSection emuLock; fceuCriticalSection emuLock;
static_cast<bookmarkPreviewPopup*>(fceuCustomToolTipShow( imagePos, new bookmarkPreviewPopup(imageItem, this) )); //static_cast<bookmarkPreviewPopup*>(fceuCustomToolTipShow( imagePos, new bookmarkPreviewPopup(imageItem, this) ));
bool item_valid = (imageItem >= 0) && (imageItem < TOTAL_BOOKMARKS);
if ( item_valid && (imageItem != bookmarkPreviewPopup::currentIndex()) )
{
bookmarkPreviewPopup *popup = new bookmarkPreviewPopup(imageItem, this);
connect( this, SIGNAL(imageIndexChanged(int)), popup, SLOT(imageIndexChanged(int)) );
popup->show();
}
} }
void BOOKMARKS::mouseMoveEvent(QMouseEvent * event) void BOOKMARKS::mouseMoveEvent(QMouseEvent * event)
@ -808,6 +818,10 @@ void BOOKMARKS::mouseMoveEvent(QMouseEvent * event)
if ( item_valid && (column == BOOKMARKSLIST_COLUMN_TIME) && bookmarks->bookmarksArray[item].notEmpty) if ( item_valid && (column == BOOKMARKSLIST_COLUMN_TIME) && bookmarks->bookmarksArray[item].notEmpty)
{ {
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item; imageItem = item;
imagePos = event->globalPos(); imagePos = event->globalPos();
imageTimer->start(); imageTimer->start();
@ -815,10 +829,36 @@ void BOOKMARKS::mouseMoveEvent(QMouseEvent * event)
} }
else else
{ {
item = -1;
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item;
imageTimer->stop(); imageTimer->stop();
} }
} }
void BOOKMARKS::focusOutEvent(QFocusEvent *event)
{
int item = -1;
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item;
}
void BOOKMARKS::leaveEvent(QEvent *event)
{
int item = -1;
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item;
}
bool BOOKMARKS::event(QEvent *event) bool BOOKMARKS::event(QEvent *event)
{ {
if (event->type() == QEvent::ToolTip) if (event->type() == QEvent::ToolTip)

View File

@ -110,6 +110,8 @@ protected:
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 focusOutEvent(QFocusEvent *event);
void leaveEvent(QEvent *event);
bool event(QEvent *event); bool event(QEvent *event);
int calcColumn( int px ); int calcColumn( int px );
@ -157,4 +159,7 @@ private:
private slots: private slots:
void showImage(void); void showImage(void);
signals:
void imageIndexChanged(int);
}; };

View File

@ -586,7 +586,18 @@ void BRANCHES::mouseReleaseEvent(QMouseEvent * event)
void BRANCHES::showImage(void) void BRANCHES::showImage(void)
{ {
fceuCriticalSection emuLock; fceuCriticalSection emuLock;
static_cast<bookmarkPreviewPopup*>(fceuCustomToolTipShow( imagePos, new bookmarkPreviewPopup(imageItem, this) )); //static_cast<bookmarkPreviewPopup*>(fceuCustomToolTipShow( imagePos, new bookmarkPreviewPopup(imageItem, this) ));
bool item_valid = (imageItem >= 0) && (imageItem < TOTAL_BOOKMARKS);
if ( item_valid && (imageItem != bookmarkPreviewPopup::currentIndex()) )
{
bookmarkPreviewPopup *popup = new bookmarkPreviewPopup(imageItem, this);
connect( this, SIGNAL(imageIndexChanged(int)), popup, SLOT(imageIndexChanged(int)) );
popup->show();
}
} }
void BRANCHES::mouseMoveEvent(QMouseEvent * event) void BRANCHES::mouseMoveEvent(QMouseEvent * event)
@ -602,6 +613,10 @@ void BRANCHES::mouseMoveEvent(QMouseEvent * event)
if ( item_valid && bookmarks->bookmarksArray[item].notEmpty) if ( item_valid && bookmarks->bookmarksArray[item].notEmpty)
{ {
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item; imageItem = item;
imagePos = event->globalPos(); imagePos = event->globalPos();
imageTimer->start(); imageTimer->start();
@ -609,6 +624,12 @@ void BRANCHES::mouseMoveEvent(QMouseEvent * event)
} }
else else
{ {
item = -1;
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item;
imageTimer->stop(); imageTimer->stop();
} }
@ -623,6 +644,30 @@ void BRANCHES::mouseMoveEvent(QMouseEvent * event)
} }
void BRANCHES::focusOutEvent(QFocusEvent *event)
{
int item = -1;
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item;
bookmarks->itemUnderMouse = ITEM_UNDER_MOUSE_NONE;
}
void BRANCHES::leaveEvent(QEvent *event)
{
int item = -1;
if ( item != imageItem )
{
emit imageIndexChanged(item);
}
imageItem = item;
bookmarks->itemUnderMouse = ITEM_UNDER_MOUSE_NONE;
}
bool BRANCHES::event(QEvent *event) bool BRANCHES::event(QEvent *event)
{ {
if (event->type() == QEvent::ToolTip) if (event->type() == QEvent::ToolTip)

View File

@ -151,6 +151,8 @@ protected:
void mouseReleaseEvent(QMouseEvent * event); void mouseReleaseEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent * event); void mouseMoveEvent(QMouseEvent * event);
void mouseDoubleClickEvent(QMouseEvent * event); void mouseDoubleClickEvent(QMouseEvent * event);
void focusOutEvent(QFocusEvent *event);
void leaveEvent(QEvent *event);
bool event(QEvent *event); bool event(QEvent *event);
private: private:
@ -214,4 +216,7 @@ private:
private slots: private slots:
void showImage(void); void showImage(void);
signals:
void imageIndexChanged(int);
}; };