Added logic to reuse existing preview popup window when switching quickly between bookmarks (for Qt GUI).

This commit is contained in:
mjbudd77 2021-12-30 10:47:36 -05:00
parent 04b8d8a789
commit 0ad291df75
4 changed files with 88 additions and 13 deletions

View File

@ -6484,7 +6484,6 @@ bookmarkPreviewPopup::bookmarkPreviewPopup( int index, QWidget *parent )
int p;
QPoint pos;
QVBoxLayout *vbox;
QLabel *imgLbl, *descLbl;
uint32_t *pixBuf;
uint32_t pixel;
QPixmap pixmap;
@ -6632,6 +6631,11 @@ void bookmarkPreviewPopup::periodicUpdate(void)
}
}
//----------------------------------------------------------------------------
bookmarkPreviewPopup *bookmarkPreviewPopup::currentInstance(void)
{
return instance;
}
//----------------------------------------------------------------------------
int bookmarkPreviewPopup::currentIndex(void)
{
if ( instance )
@ -6645,12 +6649,12 @@ void bookmarkPreviewPopup::imageIndexChanged(int newIndex)
{
//printf("newIndex:%i\n", newIndex );
actv = false;
actv = ( newIndex >= 0 );
if ( instance == this )
{
instance = NULL;
}
//if ( instance == this )
//{
// instance = NULL;
//}
}
//----------------------------------------------------------------------------
int bookmarkPreviewPopup::loadImage(int index)
@ -6670,6 +6674,54 @@ int bookmarkPreviewPopup::loadImage(int index)
return ret;
}
//----------------------------------------------------------------------------
int bookmarkPreviewPopup::reloadImage(int index)
{
int p, ret = 0;
uint32_t *pixBuf;
uint32_t pixel;
QPixmap pixmap;
actv = true;
imageIndex = index;
// retrieve info from the pointed bookmark's Markers
int frame = bookmarks->bookmarksArray[index].snapshot.keyFrame;
int markerID = markersManager->getMarkerAboveFrame(bookmarks->bookmarksArray[index].snapshot.markers, frame);
pixBuf = (uint32_t *)malloc( SCREENSHOT_SIZE * sizeof(uint32_t) );
loadImage(index);
p=0;
for (int h=0; h<SCREENSHOT_HEIGHT; h++)
{
for (int w=0; w<SCREENSHOT_WIDTH; w++)
{
pixel = ModernDeemphColorMap( &screenShotRaster[p], screenShotRaster, 1 );
pixBuf[p] = 0xFF000000;
pixBuf[p] |= (pixel & 0x000000FF) << 16;
pixBuf[p] |= (pixel & 0x00FF0000) >> 16;
pixBuf[p] |= (pixel & 0x0000FF00);
p++;
}
}
QImage img( (unsigned char*)pixBuf, SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT, SCREENSHOT_WIDTH*4, QImage::Format_RGBA8888 );
pixmap.convertFromImage( img );
if ( pixBuf )
{
free( pixBuf ); pixBuf = NULL;
}
imgLbl->setPixmap( pixmap );
descLbl->setText( tr(markersManager->getNoteCopy(bookmarks->bookmarksArray[index].snapshot.markers, markerID).c_str()) );
update();
return ret;
}
//----------------------------------------------------------------------------
//---- TAS Find Note Window
//----------------------------------------------------------------------------
TasFindNoteWindow::TasFindNoteWindow( QWidget *parent )

View File

@ -121,16 +121,21 @@ class bookmarkPreviewPopup : public QDialog
bookmarkPreviewPopup( int index, QWidget *parent = nullptr );
~bookmarkPreviewPopup(void);
int reloadImage(int index);
static int currentIndex(void);
static bookmarkPreviewPopup *currentInstance(void);
private:
int loadImage(int index);
int loadImage(int index);
int alpha;
int imageIndex;
bool actv;
unsigned char *screenShotRaster;
QTimer *timer;
QLabel *imgLbl, *descLbl;
static bookmarkPreviewPopup *instance;

View File

@ -811,11 +811,20 @@ void BOOKMARKS::showImage(void)
if ( item_valid && (imageItem != bookmarkPreviewPopup::currentIndex()) )
{
bookmarkPreviewPopup *popup = new bookmarkPreviewPopup(imageItem, this);
bookmarkPreviewPopup *popup = bookmarkPreviewPopup::currentInstance();
connect( this, SIGNAL(imageIndexChanged(int)), popup, SLOT(imageIndexChanged(int)) );
if ( popup == NULL )
{
popup = new bookmarkPreviewPopup(imageItem, this);
popup->show();
connect( this, SIGNAL(imageIndexChanged(int)), popup, SLOT(imageIndexChanged(int)) );
popup->show();
}
else
{
popup->reloadImage(imageItem);
}
}
}

View File

@ -597,11 +597,20 @@ void BRANCHES::showImage(void)
if ( item_valid && (imageItem != bookmarkPreviewPopup::currentIndex()) )
{
bookmarkPreviewPopup *popup = new bookmarkPreviewPopup(imageItem, this);
bookmarkPreviewPopup *popup = bookmarkPreviewPopup::currentInstance();
connect( this, SIGNAL(imageIndexChanged(int)), popup, SLOT(imageIndexChanged(int)) );
if ( popup == NULL )
{
popup = new bookmarkPreviewPopup(imageItem, this);
popup->show();
connect( this, SIGNAL(imageIndexChanged(int)), popup, SLOT(imageIndexChanged(int)) );
popup->show();
}
else
{
popup->reloadImage(imageItem);
}
}
}