summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/installerfw.qdoc6
-rw-r--r--src/libs/installer/settings.cpp23
-rw-r--r--tests/auto/installer/settings/data/length_units_invalid.xml7
-rw-r--r--tests/auto/installer/settings/data/length_units_valid_em.xml7
-rw-r--r--tests/auto/installer/settings/data/length_units_valid_ex.xml7
-rw-r--r--tests/auto/installer/settings/data/length_units_valid_px.xml7
-rw-r--r--tests/auto/installer/settings/settings.qrc4
-rw-r--r--tests/auto/installer/settings/tst_settings.cpp29
8 files changed, 86 insertions, 4 deletions
diff --git a/doc/installerfw.qdoc b/doc/installerfw.qdoc
index 19531b76e..196fbab10 100644
--- a/doc/installerfw.qdoc
+++ b/doc/installerfw.qdoc
@@ -222,11 +222,13 @@
\row
\li WizardDefaultWidth
\li Sets the default width of the wizard in pixels. Setting a banner image will
- override this.
+ override this. You can add the \c em or \c ex suffix to the specified value to
+ use the \e em or \e ex unit, as in a CSS file.
\row
\li WizardDefaultHeight
\li Sets the default height of the wizard in pixels. Setting a watermark image will
- override this.
+ override this. You can add the \c em or \c ex suffix to the specified value to
+ use the \e em or \e ex unit, as in a CSS file.
\row
\li TitleColor
\li Set the color of the titles and subtitles (takes an HTML color code,
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
diff --git a/tests/auto/installer/settings/data/length_units_invalid.xml b/tests/auto/installer/settings/data/length_units_invalid.xml
new file mode 100644
index 000000000..b1dc5aa62
--- /dev/null
+++ b/tests/auto/installer/settings/data/length_units_invalid.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Installer>
+ <Name>Your application</Name>
+ <Version>1.2.3</Version>
+ <WizardDefaultWidth>800pt</WizardDefaultWidth>
+ <WizardDefaultHeight>600pt</WizardDefaultHeight>
+</Installer>
diff --git a/tests/auto/installer/settings/data/length_units_valid_em.xml b/tests/auto/installer/settings/data/length_units_valid_em.xml
new file mode 100644
index 000000000..af087fdfe
--- /dev/null
+++ b/tests/auto/installer/settings/data/length_units_valid_em.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Installer>
+ <Name>Your application</Name>
+ <Version>1.2.3</Version>
+ <WizardDefaultWidth>800em</WizardDefaultWidth>
+ <WizardDefaultHeight>600em</WizardDefaultHeight>
+</Installer>
diff --git a/tests/auto/installer/settings/data/length_units_valid_ex.xml b/tests/auto/installer/settings/data/length_units_valid_ex.xml
new file mode 100644
index 000000000..3b39cf7a7
--- /dev/null
+++ b/tests/auto/installer/settings/data/length_units_valid_ex.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Installer>
+ <Name>Your application</Name>
+ <Version>1.2.3</Version>
+ <WizardDefaultWidth>800ex</WizardDefaultWidth>
+ <WizardDefaultHeight>600ex</WizardDefaultHeight>
+</Installer>
diff --git a/tests/auto/installer/settings/data/length_units_valid_px.xml b/tests/auto/installer/settings/data/length_units_valid_px.xml
new file mode 100644
index 000000000..3553dd7d8
--- /dev/null
+++ b/tests/auto/installer/settings/data/length_units_valid_px.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Installer>
+ <Name>Your application</Name>
+ <Version>1.2.3</Version>
+ <WizardDefaultWidth>800px</WizardDefaultWidth>
+ <WizardDefaultHeight>600px</WizardDefaultHeight>
+</Installer>
diff --git a/tests/auto/installer/settings/settings.qrc b/tests/auto/installer/settings/settings.qrc
index c86847993..092805980 100644
--- a/tests/auto/installer/settings/settings.qrc
+++ b/tests/auto/installer/settings/settings.qrc
@@ -9,5 +9,9 @@
<file>data/minimal_config_tag_defaults.xml</file>
<file>data/unexpectedtag_config.xml</file>
<file>data/unexpectedattribute_config.xml</file>
+ <file>data/length_units_valid_px.xml</file>
+ <file>data/length_units_valid_em.xml</file>
+ <file>data/length_units_valid_ex.xml</file>
+ <file>data/length_units_invalid.xml</file>
</qresource>
</RCC>
diff --git a/tests/auto/installer/settings/tst_settings.cpp b/tests/auto/installer/settings/tst_settings.cpp
index 036decc20..38855dccf 100644
--- a/tests/auto/installer/settings/tst_settings.cpp
+++ b/tests/auto/installer/settings/tst_settings.cpp
@@ -23,6 +23,8 @@ private slots:
void loadMinimalConfigTagDefaults();
void loadUnexpectedAttributeConfig();
void loadUnexpectedTagConfig();
+ void loadConfigWithValidLengthUnits();
+ void loadConfigWithInvalidLengthUnits();
};
void tst_Settings::loadTutorialConfig()
@@ -195,6 +197,33 @@ void tst_Settings::loadUnexpectedTagConfig()
return;
}
+void tst_Settings::loadConfigWithValidLengthUnits()
+{
+ try {
+ Settings settings = Settings::fromFileAndPrefix(":///data/length_units_valid_px.xml", ":///data");
+ QCOMPARE(settings.wizardDefaultWidth(), 800);
+ QCOMPARE(settings.wizardDefaultHeight(), 600);
+
+ // Cannot test the parsed values for these units portably since the
+ // pixel value depends on the font metrics. Let's just check for parse
+ // errors.
+ (void)Settings::fromFileAndPrefix(":///data/length_units_valid_em.xml", ":///data");
+ (void)Settings::fromFileAndPrefix(":///data/length_units_valid_ex.xml", ":///data");
+ } catch (const Error &error) {
+ QFAIL(qPrintable(QString::fromLatin1("Exception caught: %1").arg(error.message())));
+ }
+}
+
+void tst_Settings::loadConfigWithInvalidLengthUnits()
+{
+ try {
+ Settings settings = Settings::fromFileAndPrefix(":///data/length_units_invalid.xml", ":///data");
+ QCOMPARE(settings.wizardDefaultWidth(), 0);
+ QCOMPARE(settings.wizardDefaultHeight(), 0);
+ } catch (const Error &error) {
+ QFAIL(qPrintable(QString::fromLatin1("Exception caught: %1").arg(error.message())));
+ }
+}
QTEST_MAIN(tst_Settings)