summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/settings.cpp
diff options
context:
space:
mode:
authorSlobodan Vrkacevic <slobodan@froglogic.com>2016-01-21 15:26:26 +0100
committerKatja Marttila <katja.marttila@theqtcompany.com>2016-02-29 12:22:54 +0000
commitb09fa7168314fd5ed0389eeb264c8dfdd2f97a61 (patch)
treef234b4388746015c43a124fbd2948d00b51ff4f2 /src/libs/installer/settings.cpp
parentadfdbb45b128fb7fc3d35da61bb6706551b25f01 (diff)
Allow specifying the installer size in 'em' or 'ex' units
The WizardDefaultWidth and WizardDefaultHeight configuration settings always expected pixel values. This made the installer look somewhat awkward on high DPI displays, in which case the ratio between the font size and the installer window size was such that the fonts looked very big. Let's fix this by allowing to specify the width/height of the installer using units which are defined in terms of the font size, namely 'em' ("The width of the letter M") and 'ex' ("The width of the letter x"). 'px' is supported as well and means the same thing as not specifying any unit at all: the given size is defined in pixels. We choose to *not* use the font width for 'em' and 'ex' to be consistent with what the Qt CSS parser does (see src/gui/text/qcssparser.cpp), which adheres to what the W3C document at https://www.w3.org/WAI/GL/css2em.htm describes. Change-Id: Iaeb5a29c79d437ef4b956cb318158181f6289ec9 Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/settings.cpp')
-rw-r--r--src/libs/installer/settings.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/libs/installer/settings.cpp b/src/libs/installer/settings.cpp
index 5389573fa..3f0845649 100644
--- a/src/libs/installer/settings.cpp
+++ b/src/libs/installer/settings.cpp
@@ -38,6 +38,8 @@
#include <QtCore/QFileInfo>
#include <QtCore/QStringList>
+#include <QtGui/QFontMetrics>
+#include <QtWidgets/QApplication>
#include <QRegularExpression>
#include <QXmlStreamReader>
@@ -391,14 +393,31 @@ QString Settings::titleColor() const
return d->m_data.value(scTitleColor).toString();
}
+static int lengthToInt(const QVariant &variant)
+{
+ QString length = variant.toString().trimmed();
+ if (length.endsWith(QLatin1String("em"), Qt::CaseInsensitive)) {
+ length.chop(2);
+ return qRound(length.toDouble() * QApplication::fontMetrics().height());
+ }
+ if (length.endsWith(QLatin1String("ex"), Qt::CaseInsensitive)) {
+ length.chop(2);
+ return qRound(length.toDouble() * QApplication::fontMetrics().xHeight());
+ }
+ if (length.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) {
+ length.chop(2);
+ }
+ return length.toInt();
+}
+
int Settings::wizardDefaultWidth() const
{
- return d->m_data.value(scWizardDefaultWidth).toInt();
+ return lengthToInt(d->m_data.value(scWizardDefaultWidth));
}
int Settings::wizardDefaultHeight() const
{
- return d->m_data.value(scWizardDefaultHeight).toInt();
+ return lengthToInt(d->m_data.value(scWizardDefaultHeight));
}
QString Settings::installerApplicationIcon() const