Skip to content

Commit

Permalink
Merge pull request #622 from jdpurcell/issue552
Browse files Browse the repository at this point in the history
Workaround for slow font loading on Windows
  • Loading branch information
jurplel authored Aug 27, 2023
2 parents e28cbe7 + a59696e commit e0b3e4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ void MainWindow::fileChanged()
populateOpenWithTimer->start();
disableActions();

refreshProperties();
if (info->isVisible())
refreshProperties();
buildWindowTitle();
}

Expand Down
18 changes: 16 additions & 2 deletions src/qvinfodialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ui_qvinfodialog.h"
#include <QDateTime>
#include <QMimeDatabase>
#include <QTimer>

static int getGcd (int a, int b) {
return (b == 0) ? a : getGcd(b, a%b);
Expand Down Expand Up @@ -31,8 +32,20 @@ void QVInfoDialog::setInfo(const QFileInfo &value, const int &value2, const int
width = value2;
height = value3;
frameCount = value4;
updateInfo();
window()->adjustSize();

// If the dialog is visible, it means we've just navigated to a new image. Instead of running
// updateInfo immediately, add it to the event queue. This is a workaround for a (Windows-specific?)
// delay when calling adjustSize on the window if the font contains certain characters (e.g. Chinese)
// the first time that happens for a given font. At least on Windows, by making the work happen later
// in the event loop, it allows the main window to repaint first, giving the appearance of better
// responsiveness. If the dialog is not visible, however, it means we're preparing to display for an
// image already opened. In this case there is no urgency to repaint the main window, and we need to
// process the updates here synchronously to avoid the caller showing the dialog before it's ready
// (i.e. to avoid showing outdated info or placeholder text).
if (isVisible())
QTimer::singleShot(0, this, &QVInfoDialog::updateInfo);
else
updateInfo();
}

void QVInfoDialog::updateInfo()
Expand Down Expand Up @@ -63,4 +76,5 @@ void QVInfoDialog::updateInfo()
ui->framesLabel2->hide();
ui->framesLabel->hide();
}
window()->adjustSize();
}

0 comments on commit e0b3e4a

Please sign in to comment.