summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kde.org>2013-09-09 17:27:26 +0300
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-10 11:52:16 +0200
commitd6d119ac6e606a30993bfea1ac3309f74d15bedc (patch)
treeeb4eeb1ad19b3e96e7dfd3d4666e78d2d7c9ca0c /src/plugins/platforms/android
parentb0b786a2f05e9451a65519ab8904f55c35f51b7d (diff)
Fix Android Style plugin.
Task-number: QTBUG-29565 Change-Id: Iedb861962e3638bcbdf9d9a72a47bebc63b425b9 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com> Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r--src/plugins/platforms/android/src/qandroidplatformintegration.cpp7
-rw-r--r--src/plugins/platforms/android/src/qandroidplatformintegration.h2
-rw-r--r--src/plugins/platforms/android/src/qandroidplatformtheme.cpp71
-rw-r--r--src/plugins/platforms/android/src/qandroidplatformtheme.h8
4 files changed, 84 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/src/qandroidplatformintegration.cpp b/src/plugins/platforms/android/src/qandroidplatformintegration.cpp
index 045eb57148..7cd93e7a16 100644
--- a/src/plugins/platforms/android/src/qandroidplatformintegration.cpp
+++ b/src/plugins/platforms/android/src/qandroidplatformintegration.cpp
@@ -82,7 +82,10 @@ void *QAndroidPlatformNativeInterface::nativeResourceForIntegration(const QByteA
return QtAndroid::javaVM();
if (resource == "QtActivity")
return QtAndroid::activity();
-
+ if (resource == "AndroidStylePalettes")
+ return &m_palettes;
+ if (resource == "AndroidStyleFonts")
+ return &m_fonts;
return 0;
}
@@ -245,7 +248,7 @@ QStringList QAndroidPlatformIntegration::themeNames() const
QPlatformTheme *QAndroidPlatformIntegration::createPlatformTheme(const QString &name) const
{
if (androidThemeName == name)
- return new QAndroidPlatformTheme;
+ return new QAndroidPlatformTheme(m_androidPlatformNativeInterface);
return 0;
}
diff --git a/src/plugins/platforms/android/src/qandroidplatformintegration.h b/src/plugins/platforms/android/src/qandroidplatformintegration.h
index 83d7028665..20aa52cf22 100644
--- a/src/plugins/platforms/android/src/qandroidplatformintegration.h
+++ b/src/plugins/platforms/android/src/qandroidplatformintegration.h
@@ -71,6 +71,8 @@ class QAndroidPlatformNativeInterface: public QPlatformNativeInterface
{
public:
void *nativeResourceForIntegration(const QByteArray &resource);
+ QHash<int, QPalette> m_palettes;
+ QHash<int, QFont> m_fonts;
};
class QAndroidPlatformIntegration
diff --git a/src/plugins/platforms/android/src/qandroidplatformtheme.cpp b/src/plugins/platforms/android/src/qandroidplatformtheme.cpp
index 25f2ade11a..9e08440eed 100644
--- a/src/plugins/platforms/android/src/qandroidplatformtheme.cpp
+++ b/src/plugins/platforms/android/src/qandroidplatformtheme.cpp
@@ -45,6 +45,12 @@
#include "qandroidplatformmenuitem.h"
#include <QVariant>
#include <QFileInfo>
+#include <qandroidplatformintegration.h>
+
+QAndroidPlatformTheme::QAndroidPlatformTheme(QAndroidPlatformNativeInterface *androidPlatformNativeInterface)
+{
+ m_androidPlatformNativeInterface = androidPlatformNativeInterface;
+}
QPlatformMenuBar *QAndroidPlatformTheme::createPlatformMenuBar() const
{
@@ -61,13 +67,76 @@ QPlatformMenuItem *QAndroidPlatformTheme::createPlatformMenuItem() const
return new QAndroidPlatformMenuItem;
}
+static inline int paletteType(QPlatformTheme::Palette type)
+{
+ switch (type) {
+ case QPlatformTheme::ToolButtonPalette:
+ case QPlatformTheme::ButtonPalette:
+ return QPlatformTheme::ButtonPalette;
+
+ case QPlatformTheme::CheckBoxPalette:
+ return QPlatformTheme::CheckBoxPalette;
+
+ case QPlatformTheme::RadioButtonPalette:
+ return QPlatformTheme::RadioButtonPalette;
+
+ case QPlatformTheme::ComboBoxPalette:
+ return QPlatformTheme::ComboBoxPalette;
+
+ case QPlatformTheme::TextEditPalette:
+ case QPlatformTheme::TextLineEditPalette:
+ return QPlatformTheme::TextLineEditPalette;
+
+ case QPlatformTheme::ItemViewPalette:
+ return QPlatformTheme::ItemViewPalette;
+
+ default:
+ return QPlatformTheme::SystemPalette;
+ }
+}
+
+const QPalette *QAndroidPlatformTheme::palette(Palette type) const
+{
+ QHash<int, QPalette>::const_iterator it = m_androidPlatformNativeInterface->m_palettes.find(paletteType(type));
+ if (it != m_androidPlatformNativeInterface->m_palettes.end())
+ return &(it.value());
+ return 0;
+}
+
+static inline int fontType(QPlatformTheme::Font type)
+{
+ switch (type) {
+ case QPlatformTheme::LabelFont:
+ return QPlatformTheme::SystemFont;
+
+ case QPlatformTheme::ToolButtonFont:
+ return QPlatformTheme::PushButtonFont;
+
+ default:
+ return type;
+ }
+}
+
+const QFont *QAndroidPlatformTheme::font(Font type) const
+{
+ QHash<int, QFont>::const_iterator it = m_androidPlatformNativeInterface->m_fonts.find(fontType(type));
+ if (it != m_androidPlatformNativeInterface->m_fonts.end())
+ return &(it.value());
+ return 0;
+}
+
+static const QLatin1String STYLES_PATH("/data/data/org.kde.necessitas.ministro/files/dl/style/");
+static const QLatin1String STYLE_FILE("/style.json");
+
QVariant QAndroidPlatformTheme::themeHint(ThemeHint hint) const
{
switch (hint) {
case StyleNames:
if (qgetenv("QT_USE_ANDROID_NATIVE_STYLE").toInt()
&& (!qgetenv("MINISTRO_ANDROID_STYLE_PATH").isEmpty()
- || QFileInfo("/data/data/org.kde.necessitas.ministro/files/qt/style/style.json").exists())) {
+ || QFileInfo(STYLES_PATH
+ + QLatin1String(qgetenv("QT_ANDROID_THEME_DISPLAY_DPI"))
+ + STYLE_FILE).exists())) {
return QStringList("android");
}
return QStringList("fusion");
diff --git a/src/plugins/platforms/android/src/qandroidplatformtheme.h b/src/plugins/platforms/android/src/qandroidplatformtheme.h
index 263878ee16..15d2cb2000 100644
--- a/src/plugins/platforms/android/src/qandroidplatformtheme.h
+++ b/src/plugins/platforms/android/src/qandroidplatformtheme.h
@@ -43,14 +43,20 @@
#define QANDROIDPLATFORMTHEME_H
#include <qpa/qplatformtheme.h>
-
+class QAndroidPlatformNativeInterface;
class QAndroidPlatformTheme: public QPlatformTheme
{
public:
+ QAndroidPlatformTheme(QAndroidPlatformNativeInterface * androidPlatformNativeInterface);
virtual QPlatformMenuBar *createPlatformMenuBar() const;
virtual QPlatformMenu *createPlatformMenu() const;
virtual QPlatformMenuItem *createPlatformMenuItem() const;
+ virtual const QPalette *palette(Palette type = SystemPalette) const;
+ virtual const QFont *font(Font type = SystemFont) const;
virtual QVariant themeHint(ThemeHint hint) const;
+
+private:
+ QAndroidPlatformNativeInterface * m_androidPlatformNativeInterface;
};
#endif // QANDROIDPLATFORMTHEME_H