Avoid unnecessary re-layouts when populating thumbnails

This commit is contained in:
baldurk
2020-09-03 18:07:47 +01:00
parent c39a0bae5f
commit ec023ac660
3 changed files with 21 additions and 10 deletions
+2 -4
View File
@@ -58,10 +58,8 @@ public:
void setActive(bool b)
{
m_Active = b;
if(b)
show();
else
hide();
// we unconditionally hide the preview, the thumbnail strip will show it
hide();
}
bool isActive() { return m_Active; }
void setSize(QSize s);
+16 -6
View File
@@ -77,6 +77,9 @@ void ThumbnailStrip::showEvent(QShowEvent *event)
void ThumbnailStrip::refreshLayout()
{
if(updatesEnabled())
setUpdatesEnabled(false);
QRect avail = geometry();
avail.adjust(6, 6, -6, -6);
@@ -97,9 +100,7 @@ void ThumbnailStrip::refreshLayout()
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
delete layout;
layout = new QHBoxLayout(ui->scrollAreaWidgetContents);
for(ResourcePreview *w : m_Thumbnails)
layout->addWidget(w);
layout = new QHBoxLayout();
layout->setSpacing(6);
layout->setContentsMargins(6, 6, 6, 6);
layout->setAlignment(Qt::AlignTop);
@@ -139,9 +140,7 @@ void ThumbnailStrip::refreshLayout()
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
delete layout;
layout = new QVBoxLayout(ui->scrollAreaWidgetContents);
for(ResourcePreview *w : m_Thumbnails)
layout->addWidget(w);
layout = new QVBoxLayout();
layout->setSpacing(6);
layout->setContentsMargins(6, 6, 6, 6);
layout->setAlignment(Qt::AlignTop);
@@ -172,4 +171,15 @@ void ThumbnailStrip::refreshLayout()
c->setSize(QSize(avail.width(), aspectHeight));
}
}
for(ResourcePreview *w : m_Thumbnails)
layout->addWidget(w);
for(ResourcePreview *w : m_Thumbnails)
if(w->isActive())
w->show();
ui->scrollAreaWidgetContents->setLayout(layout);
setUpdatesEnabled(true);
}
+3
View File
@@ -3013,6 +3013,9 @@ void TextureViewer::OnEventChanged(uint32_t eventId)
int outIndex = 0;
int inIndex = 0;
ui->outputThumbs->setUpdatesEnabled(false);
ui->inputThumbs->setUpdatesEnabled(false);
bool copy = false, clear = false, compute = false;
Following::GetDrawContext(m_Ctx, copy, clear, compute);