Start: Add caching for performance for thumbnails on start page (#23186)
* Start: Add caching for performance for thumbnails on start page So currently we can have a problem where we are trying to load whole image as a thumbnail, which can result in over 256MB~ of internal buffer memory. Also, even if we load smaller size - every now and then start page gets refreshed, so to check if any file got modified and refresh it in recent files. This is okay, but with large files it loads them over and over, resulting in start page lagging. Solution for that is first - load image thumbnails as scaled, small images instead of full image. Second - for performance, use caching by using `path:modtime:size` key. If the item fits this key, it means it didn't change, so just proceed further and get this item from the cache. If the key is different, it means it has been changed on the disk, so reload it. * Start: Deactivate Start page if it loses focus to stop receiving events As the title says. This prevents Start page from processing unnecessary events (mostly paint ones that were causing extreme lag previously) if it is not opened. * Start: Preserve aspect ratio of the image for the thumbnail * Start: use brace initialization when returning QString * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
#include <QStackedWidget>
|
||||
#include <QShowEvent>
|
||||
#endif
|
||||
|
||||
#include "StartView.h"
|
||||
@@ -248,6 +249,7 @@ void StartView::configureFileCardWidget(QListView* fileCardWidget)
|
||||
{
|
||||
auto delegate = gsl::owner<FileCardDelegate*>(new FileCardDelegate(fileCardWidget));
|
||||
fileCardWidget->setItemDelegate(delegate);
|
||||
|
||||
fileCardWidget->setMinimumWidth(fileCardWidget->parentWidget()->width());
|
||||
// fileCardWidget->setGridSize(
|
||||
// fileCardWidget->itemDelegate()->sizeHint(QStyleOptionViewItem(),
|
||||
@@ -442,12 +444,48 @@ void StartView::changeEvent(QEvent* event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::LanguageChange) {
|
||||
this->retranslateUi();
|
||||
}
|
||||
|
||||
Gui::MDIView::changeEvent(event);
|
||||
}
|
||||
|
||||
void StartView::showEvent(QShowEvent* event)
|
||||
{
|
||||
if (auto mainWindow = Gui::getMainWindow()) {
|
||||
if (auto mdiArea = mainWindow->findChild<QMdiArea*>()) {
|
||||
connect(mdiArea,
|
||||
&QMdiArea::subWindowActivated,
|
||||
this,
|
||||
&StartView::onMdiSubWindowActivated,
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
}
|
||||
Gui::MDIView::showEvent(event);
|
||||
}
|
||||
|
||||
void StartView::onMdiSubWindowActivated(QMdiSubWindow* subWindow)
|
||||
{
|
||||
// check if start view is activated subwindow if yes, then enable updates
|
||||
// so we can once again receive paint events
|
||||
bool isOurWindow = subWindow && subWindow->isAncestorOf(this);
|
||||
setListViewUpdatesEnabled(isOurWindow);
|
||||
}
|
||||
|
||||
void StartView::setListViewUpdatesEnabled(bool enabled)
|
||||
{
|
||||
// disable updates on all QListView widgets when inactive to prevent unnecessary paint events
|
||||
QList<QListView*> listViews = findChildren<QListView*>();
|
||||
for (QListView* listView : listViews) {
|
||||
listView->setUpdatesEnabled(enabled);
|
||||
if (listView->viewport()) {
|
||||
listView->viewport()->setUpdatesEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StartView::retranslateUi()
|
||||
{
|
||||
QString title = QCoreApplication::translate("Workbench", "Start");
|
||||
|
||||
Reference in New Issue
Block a user