mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-09 04:30:43 +00:00
Centralize all font validation and setting into new functions in common.cpp. Add registry key to System Info (call it App Key for cross-platform compatibility).
This commit is contained in:
parent
94f71ad4c2
commit
087b18545f
@ -16,7 +16,10 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QApplication>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QFontDatabase>
|
||||||
|
#include <QMenuBar>
|
||||||
|
|
||||||
#include "SleepLib/common.h"
|
#include "SleepLib/common.h"
|
||||||
|
|
||||||
@ -30,6 +33,9 @@
|
|||||||
#include "git_info.h"
|
#include "git_info.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "profiles.h"
|
#include "profiles.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
extern MainWindow * mainwin;
|
||||||
|
|
||||||
// Used by internal settings
|
// Used by internal settings
|
||||||
|
|
||||||
@ -191,6 +197,8 @@ QStringList makeBuildInfo (QString relinfo, QString forcedEngine){
|
|||||||
branch = QObject::tr("Branch:") + " " + GIT_BRANCH + ", ";
|
branch = QObject::tr("Branch:") + " " + GIT_BRANCH + ", ";
|
||||||
}
|
}
|
||||||
buildInfo << branch + (QObject::tr("Revision")) + " " + GIT_REVISION;
|
buildInfo << branch + (QObject::tr("Revision")) + " " + GIT_REVISION;
|
||||||
|
if (GIT_BRANCH != "master")
|
||||||
|
buildInfo << (QObject::tr("App key:") + " " + getAppName());
|
||||||
buildInfo << QString("");
|
buildInfo << QString("");
|
||||||
buildInfo << (QObject::tr("Operating system:") + " " + QSysInfo::prettyProductName());
|
buildInfo << (QObject::tr("Operating system:") + " " + QSysInfo::prettyProductName());
|
||||||
buildInfo << (QObject::tr("Graphics Engine:") + " " + getOpenGLVersionString());
|
buildInfo << (QObject::tr("Graphics Engine:") + " " + getOpenGLVersionString());
|
||||||
@ -283,6 +291,83 @@ bool operator <(const ValueCount &a, const ValueCount &b)
|
|||||||
return a.value < b.value;
|
return a.value < b.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QStringList installedFontFamilies;
|
||||||
|
|
||||||
|
// Validate all fonts
|
||||||
|
void validateAllFonts () {
|
||||||
|
validateFont("Application");
|
||||||
|
validateFont("Graph");
|
||||||
|
validateFont("Title");
|
||||||
|
validateFont("Big");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate font from preference settings, and substitute system font if font in preferences cannot be found on this system
|
||||||
|
void validateFont (QString which) {
|
||||||
|
|
||||||
|
// Get list of installed font families, including system font
|
||||||
|
// Do this just once so we don't have to call font functions repeatedly
|
||||||
|
if (installedFontFamilies.length() <= 0) {
|
||||||
|
QFontDatabase database;
|
||||||
|
installedFontFamilies = database.families();
|
||||||
|
qDebug() << "validateFont found" << installedFontFamilies.count() << "families";
|
||||||
|
|
||||||
|
// macOS default system fonts are not in QFontCombobox because they are "private":
|
||||||
|
// See https://github.com/musescore/MuseScore/commit/0eecb165664a0196c2eee12e42fb273dcfc9c637
|
||||||
|
// The below makes sure any default system font is present in installedFontFamilies
|
||||||
|
QString systemFontFamily = QFontDatabase::systemFont(QFontDatabase::GeneralFont).family();
|
||||||
|
if (installedFontFamilies.indexOf(systemFontFamily) < 0) {
|
||||||
|
installedFontFamilies.insert(0, systemFontFamily);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool forceFont = false;
|
||||||
|
QString prefPrefix = "Fonts_" + which + "_";
|
||||||
|
|
||||||
|
// If a font is specified, make sure it is a valid font on this platform
|
||||||
|
if (p_pref->contains(prefPrefix + "Name")) {
|
||||||
|
QString desiredFont = (*p_pref)[prefPrefix + "Name"].toString();
|
||||||
|
if (desiredFont == "")
|
||||||
|
forceFont = true;
|
||||||
|
else {
|
||||||
|
if (installedFontFamilies.indexOf(desiredFont) == -1) {
|
||||||
|
forceFont = true;
|
||||||
|
qDebug() << "Desired font" << desiredFont << "not found in font database," << QFontDatabase::systemFont(QFontDatabase::GeneralFont) << "(system default) font used instead";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Font not valid or not specified. Set system font in its place
|
||||||
|
if (!p_pref->contains(prefPrefix + "Name") || forceFont) {
|
||||||
|
(*p_pref)[prefPrefix + "Name"] = QFontDatabase::systemFont(QFontDatabase::GeneralFont).family();
|
||||||
|
if (which == "Application") {
|
||||||
|
(*p_pref)[prefPrefix + "Size"] = 10;
|
||||||
|
(*p_pref)[prefPrefix + "Bold"] = false;
|
||||||
|
(*p_pref)[prefPrefix + "Italic"] = false;
|
||||||
|
} else if (which == "Graphs") {
|
||||||
|
(*p_pref)[prefPrefix + "Size"] = 10;
|
||||||
|
(*p_pref)[prefPrefix + "Bold"] = false;
|
||||||
|
(*p_pref)[prefPrefix + "Italic"] = false;
|
||||||
|
} else if (which == "Title") {
|
||||||
|
(*p_pref)[prefPrefix + "Size"] = 14;
|
||||||
|
(*p_pref)[prefPrefix + "Bold"] = true;
|
||||||
|
(*p_pref)[prefPrefix + "Italic"] = false;
|
||||||
|
} else if (which == "Big") {
|
||||||
|
(*p_pref)[prefPrefix + "Size"] = 35;
|
||||||
|
(*p_pref)[prefPrefix + "Bold"] = false;
|
||||||
|
(*p_pref)[prefPrefix + "Italic"] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setApplicationFont () {
|
||||||
|
QFont font = QFont(((*p_pref)["Fonts_Application_Name"]).toString());
|
||||||
|
font.setPointSize(((*p_pref)["Fonts_Application_Size"]).toInt());
|
||||||
|
font.setWeight(((*p_pref)["Fonts_Application_Bold"]).toBool() ? QFont::Bold : QFont::Normal);
|
||||||
|
font.setItalic(((*p_pref)["Fonts_Application_Italic"]).toBool());
|
||||||
|
QApplication::setFont(font);
|
||||||
|
mainwin->menuBar()->setFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
bool removeDir(const QString &path)
|
bool removeDir(const QString &path)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
@ -143,6 +143,10 @@ const QString getDeveloperName();
|
|||||||
const QString getDeveloperDomain();
|
const QString getDeveloperDomain();
|
||||||
const QString getModifiedAppData();
|
const QString getModifiedAppData();
|
||||||
|
|
||||||
|
void validateAllFonts ();
|
||||||
|
void validateFont (QString which);
|
||||||
|
void setApplicationFont ();
|
||||||
|
|
||||||
void initializeStrings();
|
void initializeStrings();
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "SleepLib/profiles.h"
|
#include "SleepLib/profiles.h"
|
||||||
#include "translation.h"
|
#include "translation.h"
|
||||||
|
#include "SleepLib/common.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@ -501,6 +502,10 @@ int main(int argc, char *argv[]) {
|
|||||||
QString language = settings.value(LangSetting, "").toString();
|
QString language = settings.value(LangSetting, "").toString();
|
||||||
AppSetting->setLanguage(language);
|
AppSetting->setLanguage(language);
|
||||||
|
|
||||||
|
// Set fonts from preferences file
|
||||||
|
validateAllFonts();
|
||||||
|
setApplicationFont();
|
||||||
|
|
||||||
// Clean up some legacy crap
|
// Clean up some legacy crap
|
||||||
// QFile lf(p_pref->Get("{home}/Layout.xml"));
|
// QFile lf(p_pref->Get("{home}/Layout.xml"));
|
||||||
// if (lf.exists()) {
|
// if (lf.exists()) {
|
||||||
@ -552,35 +557,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
AppSetting->setVersionString(VersionString);
|
AppSetting->setVersionString(VersionString);
|
||||||
|
|
||||||
// int id=QFontDatabase::addApplicationFont(":/fonts/FreeSans.ttf");
|
|
||||||
// QFontDatabase fdb;
|
|
||||||
// QStringList ffam=fdb.families();
|
|
||||||
// for (QStringList::iterator i=ffam.begin();i!=ffam.end();i++) {
|
|
||||||
// qDebug() << "Loaded Font: " << (*i);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
if (!p_pref->contains("Fonts_Application_Name")) {
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
// Windows default Sans Serif interpretation sucks
|
|
||||||
// Segoe UI is better, but that requires OS/font detection
|
|
||||||
(*p_pref)["Fonts_Application_Name"] = "Arial";
|
|
||||||
#else
|
|
||||||
(*p_pref)["Fonts_Application_Name"] = QFontDatabase::systemFont(QFontDatabase::GeneralFont).family();
|
|
||||||
#endif
|
|
||||||
(*p_pref)["Fonts_Application_Size"] = 10;
|
|
||||||
(*p_pref)["Fonts_Application_Bold"] = false;
|
|
||||||
(*p_pref)["Fonts_Application_Italic"] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QApplication::setFont(QFont((*p_pref)["Fonts_Application_Name"].toString(),
|
|
||||||
(*p_pref)["Fonts_Application_Size"].toInt(),
|
|
||||||
(*p_pref)["Fonts_Application_Bold"].toBool() ? QFont::Bold : QFont::Normal,
|
|
||||||
(*p_pref)["Fonts_Application_Italic"].toBool()));
|
|
||||||
|
|
||||||
qDebug() << "Selected Font" << QApplication::font().family();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Register Importer Modules for autoscanner
|
// Register Importer Modules for autoscanner
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user