summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-07-19 10:00:14 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-11-23 19:26:50 +0100
commitf54393ba70d6dc56b201cf8ff7691a4bf04626d6 (patch)
tree5733d3d33674c35fefc604ff4f23b4a142ce34ae /tests/manual
parentdabf8a0d899407c1aceb6e996f72c7c3e1b7679a (diff)
Add initial implementation of an Android icon engine
Try to use the Downloadable Font APIs from AndroidX to download the Material Symbols font. This would ideally allow us to add the official icon variations dynamically to the device's font cache. This works for several fonts from Google Fonts, but not for the fonts we need. So, for the time being, add a path where we consult the resource system for an embedded font file as well. Then an application can add e.g. the font file for the desired icons variation, and Qt will use those glyphs to render icons. Do this in the manual test, using cmake's FetchContent feature to download the font from Googlei's github repository. The incomplete mapping is based on the standard Material icons documentation at https://fonts.google.com/icons. We could in theory use the `codepoints` file that comes with the font files to create the mapping, but then we'd end up with platform specific icon names. Task-number: QTBUG-102346 Change-Id: Ibff3fe6d310a388e6111d983815ef0ddffb684c8 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/iconbrowser/CMakeLists.txt35
-rw-r--r--tests/manual/iconbrowser/main.cpp4
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/manual/iconbrowser/CMakeLists.txt b/tests/manual/iconbrowser/CMakeLists.txt
index 4bd22f7eff..eb304d25a2 100644
--- a/tests/manual/iconbrowser/CMakeLists.txt
+++ b/tests/manual/iconbrowser/CMakeLists.txt
@@ -13,3 +13,38 @@ qt_internal_add_manual_test(iconbrowser
Qt::Widgets
Qt::WidgetsPrivate
)
+
+if (ANDROID)
+ set(font_filename "MaterialIcons-Regular.ttf")
+ if (QT_ALLOW_DOWNLOAD)
+ include(FetchContent)
+
+ FetchContent_Declare(
+ MaterialIcons
+ URL
+ "https://github.com/google/material-design-icons/raw/master/font/${font_filename}"
+ DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}
+ DOWNLOAD_NAME "${font_filename}"
+ DOWNLOAD_NO_EXTRACT TRUE
+ )
+
+ FetchContent_MakeAvailable(MaterialIcons)
+ endif()
+
+ if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${font_filename}")
+ set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/${font_filename}"
+ PROPERTIES QT_RESOURCE_ALIAS ${font_filename})
+ target_compile_definitions(iconbrowser PRIVATE "ICONBROWSER_RESOURCE")
+ qt_add_resources(iconbrowser "icons"
+ PREFIX
+ "/qt-project.org/icons"
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/${font_filename}"
+ )
+ else()
+ message(WARNING "Font file ${font_filename} not found and not downloaded!\n"
+ "Make sure the font file ${font_filename} is available in ${CMAKE_CURRENT_BINARY_DIR}.\n"
+ "Consider configuring with -DQT_ALLOW_DOWNLOAD=ON to download the font automatically.")
+ endif()
+endif()
+
diff --git a/tests/manual/iconbrowser/main.cpp b/tests/manual/iconbrowser/main.cpp
index f145485329..8acff69fa2 100644
--- a/tests/manual/iconbrowser/main.cpp
+++ b/tests/manual/iconbrowser/main.cpp
@@ -534,6 +534,10 @@ int main(int argc, char* argv[])
QApplication app(argc, argv);
+#ifdef ICONBROWSER_RESOURCE
+ Q_INIT_RESOURCE(icons);
+#endif
+
IconModel model;
QTabWidget widget;