diff options
author | Morten Johan Sørvig <morten.sorvig@theqtcompany.com> | 2015-07-09 16:32:44 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@theqtcompany.com> | 2015-10-26 09:27:54 +0000 |
commit | b2d24dc3475906d4f46c917f129fd98e883569a6 (patch) | |
tree | 02a950fd2bbac1663f106ec932a596233cddb6ac /src/plugins/platforms/android/androidjnimain.cpp | |
parent | 45bb9c29e8b70cd15b01d8ab18d1df7f9707c215 (diff) |
Android: Add opt-in high-dpi support
Opt-in by setting android.app.auto_screen_scale_factor
to true in AndroidManifest.xml. This will enable
devicePixelRatio scaling in QtGui using a scale
factor provided by Android DisplayMetrics.
Note that the Android style is not currently supported:
it already accounts for different display densities
which results in incorrect visual sizes when enabling
devicePixelRatio scaling.
Implementation: Bring DisplayMetrics::density through
to setDisplayMetrics in androidjnimain.cpp, similar
to what is done for "scaledDensity". Override
QPlatformScreen::pixelDensity(), which forwards the
scale factor to QtGui.
[The difference between "density" and "scaledDensity"
is that the former is a physical display density factor
which corresponds closely to devicePixelRatio in Qt,
while the latter also includes the Android global font
scale factor.]
Scale the global font pixel size in qandroidplatformtheme.cpp
to keep the visual font size constant.
Based on an initial patch from Daiwei Li <daiweili@suitabletech.com>
Task-number: QTBUG-46615
Change-Id: Ia51f99bf6dda485a57413949246c7b32cb47e8dd
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Diffstat (limited to 'src/plugins/platforms/android/androidjnimain.cpp')
-rw-r--r-- | src/plugins/platforms/android/androidjnimain.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 99cb58830c..d419e42cd5 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -55,6 +55,7 @@ #include <QtCore/private/qjnihelpers_p.h> #include <QtCore/private/qjni_p.h> #include <QtGui/private/qguiapplication_p.h> +#include <QtGui/private/qhighdpiscaling_p.h> #include <qpa/qwindowsysteminterface.h> @@ -109,6 +110,7 @@ static QAndroidPlatformIntegration *m_androidPlatformIntegration = nullptr; static int m_desktopWidthPixels = 0; static int m_desktopHeightPixels = 0; static double m_scaledDensity = 0; +static double m_density = 1.0; static volatile bool m_pauseApplication; @@ -157,6 +159,11 @@ namespace QtAndroid return m_scaledDensity; } + double pixelDensity() + { + return m_density; + } + JavaVM *javaVM() { return m_javaVM; @@ -547,7 +554,8 @@ static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/, jint widthPixels, jint heightPixels, jint desktopWidthPixels, jint desktopHeightPixels, - jdouble xdpi, jdouble ydpi, jdouble scaledDensity) + jdouble xdpi, jdouble ydpi, + jdouble scaledDensity, jdouble density) { // Android does not give us the correct screen size for immersive mode, but // the surface does have the right size @@ -558,6 +566,7 @@ static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/, m_desktopWidthPixels = desktopWidthPixels; m_desktopHeightPixels = desktopHeightPixels; m_scaledDensity = scaledDensity; + m_density = density; if (!m_androidPlatformIntegration) { QAndroidPlatformIntegration::setDefaultDisplayMetrics(desktopWidthPixels, @@ -683,7 +692,7 @@ static JNINativeMethod methods[] = { {"startQtApplication", "(Ljava/lang/String;Ljava/lang/String;)V", (void *)startQtApplication}, {"quitQtAndroidPlugin", "()V", (void *)quitQtAndroidPlugin}, {"terminateQt", "()V", (void *)terminateQt}, - {"setDisplayMetrics", "(IIIIDDD)V", (void *)setDisplayMetrics}, + {"setDisplayMetrics", "(IIIIDDDD)V", (void *)setDisplayMetrics}, {"setSurface", "(ILjava/lang/Object;II)V", (void *)setSurface}, {"updateWindow", "()V", (void *)updateWindow}, {"updateApplicationState", "(I)V", (void *)updateApplicationState}, |