[Gui] font setting fixes for NaviCube

- it turned out that the current check for default font failed because of wrong check for the hinting
- fix bug that when the FontSize is not yet stored in the parameters, the dialog shows a wrong size value
This commit is contained in:
Uwe
2023-02-15 00:38:31 +01:00
parent b88fb1bcfd
commit ef29cc7657
2 changed files with 27 additions and 19 deletions

View File

@@ -144,7 +144,7 @@ void DlgSettingsNavigation::loadSettings()
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");
std::string model = hGrp->GetASCII("NavigationStyle",CADNavigationStyle::getClassTypeId().getName());
std::string model = hGrp->GetASCII("NavigationStyle", CADNavigationStyle::getClassTypeId().getName());
int index = ui->comboNavigationStyle->findData(QByteArray(model.c_str()));
if (index > -1) ui->comboNavigationStyle->setCurrentIndex(index);
@@ -196,11 +196,25 @@ void DlgSettingsNavigation::loadSettings()
QStringList familyNames = QFontDatabase::families(QFontDatabase::Any);
#endif
ui->naviCubeFontName->addItems(familyNames);
// if the parameter has not yet been set, do so immediately
// this assures it is set even if the user cancels the dialog
if (hGrp->GetASCII("FontString", "").empty())
hGrp->SetASCII("FontString", defaultSansserifFont.constData());
int indexFamilyNames = familyNames.indexOf(
QString::fromLatin1(hGrp->GetASCII("FontString", defaultSansserifFont).c_str()));
QString::fromStdString(hGrp->GetASCII("FontString", defaultSansserifFont)));
if (indexFamilyNames < 0)
indexFamilyNames = 0;
ui->naviCubeFontName->setCurrentIndex(indexFamilyNames);
// if the FontSize parameter does not yet exist, set the default value
// the default is defined in NaviCubeImplementation::getDefaultFontSize()
// but not accessible if there is no cube yet drawn
if (hGrp->GetInt("FontSize", 0) == 0) {
// the "4" is the hardcoded m_OverSample from getDefaultFontSize()
hGrp->SetInt("FontSize", int(0.18 * 4 * ui->prefCubeSize->value()));
ui->naviCubeFontSize->onRestore();
}
}
void DlgSettingsNavigation::onMouseButtonClicked()

View File

@@ -296,24 +296,18 @@ void NaviCube::setFontSize(int size)
// the Helvetica font is a good start for most OSes
QFont NaviCube::getDefaultSansserifFont()
{
QFont font(QString::fromLatin1("Helvetica"));
if (font.styleHint() & QFont::SansSerif)
// Windows versions since 2017 have the 'Bahnschrift' font (a condensed
// sans serif font, optimized for readability despite being condensed),
// we first check for that.
QFont font(QString::fromLatin1("Bahnschrift"));
if (font.exactMatch())
return font;
// on Windows 10 or newer there is no Helvetica font
// therefore if we didn't find a Helvetica font check
// for the Bahnschrift font (in all Windows since 2017)
// if this too is unavailable (on Win 7), we check for the
// DejaVu Sans fonts
font.setFamily(QString::fromLatin1("Bahnschrift"));
// on Windows 11 sansserif fonts like Bahnschrift do not have the
// styleHint QFont::SansSerif but QFont::AnyStyle
// however, in future they might have, thus allow both
if (font.styleHint() == QFont::SansSerif || font.styleHint() == QFont::AnyStyle)
return font;
font.setFamily(QString::fromLatin1("DejaVu Sans"));
if (font.styleHint() == QFont::SansSerif || font.styleHint() == QFont::AnyStyle)
return font;
return font; // We failed, but return whatever we have anyway
// On systems without 'Bahnschrift' we check for 'Helvetica' or its closest match
// as default sans serif font. (For Windows 7 this will e.g. result in 'Arial'.)
font = QString::fromLatin1("Helvetica");
font.setStyleHint(QFont::SansSerif);
return font;
}
int NaviCube::getDefaultFontSize()