Skip to content

Commit

Permalink
Use QStandardPaths::locateAll to locate all font directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 authored and gonetz committed Jan 8, 2025
1 parent d5be3c6 commit 4e2052e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/GLideNUI/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,17 +1025,19 @@ void ConfigDialog::on_tabWidget_currentChanged(int tab)
ui->tabWidget->setCursor(QCursor(Qt::WaitCursor));

QMap<QString, QStringList> internalFontList;
QString fontDir = QStandardPaths::locate(QStandardPaths::FontsLocation, QString(), QStandardPaths::LocateDirectory);
QStringList fontFilter;
fontFilter << "*.ttf";
QDirIterator fontIt(fontDir, fontFilter, QDir::Files, QDirIterator::Subdirectories);
while (fontIt.hasNext()) {
QString font = fontIt.next();
int id = QFontDatabase::addApplicationFont(font);
QStringList fontListFamilies = QFontDatabase::applicationFontFamilies(id);
if (!fontListFamilies.isEmpty()) {
QString fontListFamily = fontListFamilies.at(0);
internalFontList[fontListFamily].append(font);
QStringList fontDirs = QStandardPaths::locateAll(QStandardPaths::FontsLocation, QString(), QStandardPaths::LocateDirectory);
for (const QString& fontDir : fontDirs) {
QDirIterator fontIt(fontDir, fontFilter, QDir::Files, QDirIterator::Subdirectories);
while (fontIt.hasNext()) {
QString font = fontIt.next();
int id = QFontDatabase::addApplicationFont(font);
QStringList fontListFamilies = QFontDatabase::applicationFontFamilies(id);
if (!fontListFamilies.isEmpty()) {
QString fontListFamily = fontListFamilies.at(0);
internalFontList[fontListFamily].append(font);
}
}
}

Expand Down

0 comments on commit 4e2052e

Please sign in to comment.