diff --git a/CMakeLists.txt b/CMakeLists.txt index 7071736..cae8606 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.6.0) +cmake_minimum_required(VERSION 3.27.0) project(qml-asteroid VERSION 2.0.0 @@ -9,6 +9,7 @@ find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) option(WITH_ASTEROIDAPP "Build the AsteroidApp class" ON) +option(WITH_MAPPLAUNCHERD "Build the AsteroidApp class with Mapplauncherd booster support" ON) option(WITH_CMAKE_MODULES "Install AsteroidOS CMake modules" ON) include(FeatureSummary) @@ -19,10 +20,12 @@ include(AsteroidCMakeSettings) set(ASTEROID_MODULES_INSTALL_DIR ${CMAKE_INSTALL_DATADIR}/asteroidapp/cmake) -find_package(Qt5 ${QT_MIN_VERSION} COMPONENTS DBus Qml Quick Svg REQUIRED) +find_package(Qt6 ${QT_MIN_VERSION} COMPONENTS DBus Qml Quick Svg ShaderTools REQUIRED) if (WITH_ASTEROIDAPP) - find_package(Mlite5 MODULE REQUIRED) - find_package(Mapplauncherd_qt5 MODULE REQUIRED) + find_package(Mlite6 MODULE REQUIRED) + if (WITH_MAPPLAUNCHERD) + find_package(Mapplauncherd_qt6 MODULE REQUIRED) + endif() endif() ecm_find_qmlmodule(QtQuick.VirtualKeyboard 2.1) diff --git a/cmake/AsteroidCMakeSettings.cmake b/cmake/AsteroidCMakeSettings.cmake index fe11c06..6e28ad5 100644 --- a/cmake/AsteroidCMakeSettings.cmake +++ b/cmake/AsteroidCMakeSettings.cmake @@ -34,5 +34,6 @@ if (NOT ASTEROID_SKIP_BUILD_SETTINGS) set(INSTALL_QML_IMPORT_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/qml" CACHE PATH "Custom QML import installation directory") - set(QT_MIN_VERSION "5.12.0") + # Ensure availability of QTP0001 (https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html) + set(QT_MIN_VERSION "6.5.0") endif() diff --git a/cmake/AsteroidTranslations.cmake b/cmake/AsteroidTranslations.cmake index 7ea83f8..26404e6 100644 --- a/cmake/AsteroidTranslations.cmake +++ b/cmake/AsteroidTranslations.cmake @@ -4,11 +4,11 @@ function(BUILD_TRANSLATIONS directory) return() endif() - find_package(Qt5LinguistTools REQUIRED) + find_package(Qt6LinguistTools REQUIRED) file(GLOB LANGUAGE_FILES_TS ${directory}/*.ts) #set_source_files_properties(${LANGUAGE_FILES_TS} PROPERTIES OUTPUT_LOCATION "i18n") - qt5_add_translation(LANGUAGE_FILES_QM ${LANGUAGE_FILES_TS} OPTIONS "-idbased") + qt_add_translation(LANGUAGE_FILES_QM ${LANGUAGE_FILES_TS} OPTIONS "-idbased") add_custom_target(build-translations ALL COMMENT "Building translations in ${director}..." DEPENDS ${LANGUAGE_FILES_QM}) diff --git a/cmake/FindMapplauncherd_qt5.cmake b/cmake/FindMapplauncherd_qt5.cmake deleted file mode 100644 index 5919cef..0000000 --- a/cmake/FindMapplauncherd_qt5.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# Try to find qdeclarative5-boostable -# Once done this will define -# MAPPLAUNCHERD_QT5_FOUND - System has qdeclarative -# MAPPLAUNCHERD_QT5_INCLUDE_DIRS - The qdeclarative include directories -# MAPPLAUNCHERD_QT5_LIBRARIES - The libraries needed to use qdeclarative -# MAPPLAUNCHERD_QT5_DEFINITIONS - Compiler switches required for using qdeclarative - -find_package(PkgConfig REQUIRED) -pkg_check_modules(PC_Mapplauncherd_qt5 QUIET qdeclarative5-boostable) -set(Mapplauncherd_qt5_DEFINITIONS ${PC_Mapplauncherd_qt5_CFLAGS_OTHER}) - -find_path(Mapplauncherd_qt5_INCLUDE_DIRS - NAMES mdeclarativecache.h - PATH_SUFFIXES mdeclarativecache5 - PATHS ${PC_Mapplauncherd_qt5_INCLUDEDIR} ${PC_Mapplauncherd_qt5_INCLUDE_DIRS}) - -find_library(Mapplauncherd_qt5_LIBRARIES - NAMES mdeclarativecache5 - PATHS ${PC_Mapplauncherd_qt5_LIBDIR} ${PC_Mapplauncherd_qt5_LIBRARY_DIRS}) - -set(Mapplauncherd_qt5_VERSION ${PC_Mapplauncherd_qt5_VERSION}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Mapplauncherd_qt5 - FOUND_VAR - Mapplauncherd_qt5_FOUND - REQUIRED_VARS - Mapplauncherd_qt5_LIBRARIES - Mapplauncherd_qt5_INCLUDE_DIRS - VERSION_VAR - Mapplauncherd_qt5_VERSION) - -mark_as_advanced(Mapplauncherd_qt5_INCLUDE_DIR Mapplauncherd_qt5_LIBRARY Mapplauncherd_qt5_VERSION) - -if(Mapplauncherd_qt5_FOUND AND NOT TARGET Mapplauncherd_qt5::Mapplauncherd_qt5) - add_library(Mapplauncherd_qt5::Mapplauncherd_qt5 UNKNOWN IMPORTED) - set_target_properties(Mapplauncherd_qt5::Mapplauncherd_qt5 PROPERTIES - IMPORTED_LOCATION "${Mapplauncherd_qt5_LIBRARIES}" - INTERFACE_INCLUDE_DIRECTORIES "${Mapplauncherd_qt5_INCLUDE_DIRS}") -endif() diff --git a/cmake/FindMapplauncherd_qt6.cmake b/cmake/FindMapplauncherd_qt6.cmake new file mode 100644 index 0000000..d181245 --- /dev/null +++ b/cmake/FindMapplauncherd_qt6.cmake @@ -0,0 +1,40 @@ +# Try to find qdeclarative6-boostable +# Once done this will define +# MAPPLAUNCHERD_QT6_FOUND - System has qdeclarative +# MAPPLAUNCHERD_QT6_INCLUDE_DIRS - The qdeclarative include directories +# MAPPLAUNCHERD_QT6_LIBRARIES - The libraries needed to use qdeclarative +# MAPPLAUNCHERD_QT6_DEFINITIONS - Compiler switches required for using qdeclarative + +find_package(PkgConfig REQUIRED) +pkg_check_modules(PC_Mapplauncherd_qt6 QUIET qdeclarative6-boostable) +set(Mapplauncherd_qt6_DEFINITIONS ${PC_Mapplauncherd_qt6_CFLAGS_OTHER}) + +find_path(Mapplauncherd_qt6_INCLUDE_DIRS + NAMES mdeclarativecache.h + PATH_SUFFIXES mdeclarativecache6 + PATHS ${PC_Mapplauncherd_qt6_INCLUDEDIR} ${PC_Mapplauncherd_qt6_INCLUDE_DIRS}) + +find_library(Mapplauncherd_qt6_LIBRARIES + NAMES mdeclarativecache6 + PATHS ${PC_Mapplauncherd_qt6_LIBDIR} ${PC_Mapplauncherd_qt6_LIBRARY_DIRS}) + +set(Mapplauncherd_qt6_VERSION ${PC_Mapplauncherd_qt6_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Mapplauncherd_qt6 + FOUND_VAR + Mapplauncherd_qt6_FOUND + REQUIRED_VARS + Mapplauncherd_qt6_LIBRARIES + Mapplauncherd_qt6_INCLUDE_DIRS + VERSION_VAR + Mapplauncherd_qt6_VERSION) + +mark_as_advanced(Mapplauncherd_qt6_INCLUDE_DIR Mapplauncherd_qt6_LIBRARY Mapplauncherd_qt6_VERSION) + +if(Mapplauncherd_qt6_FOUND AND NOT TARGET Mapplauncherd_qt6::Mapplauncherd_qt6) + add_library(Mapplauncherd_qt6::Mapplauncherd_qt6 UNKNOWN IMPORTED) + set_target_properties(Mapplauncherd_qt6::Mapplauncherd_qt6 PROPERTIES + IMPORTED_LOCATION "${Mapplauncherd_qt6_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Mapplauncherd_qt6_INCLUDE_DIRS}") +endif() diff --git a/cmake/FindMlite5.cmake b/cmake/FindMlite5.cmake deleted file mode 100644 index 3558bbd..0000000 --- a/cmake/FindMlite5.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# Try to find mlite5 -# Once done this will define -# MLITE5_FOUND - System has mlite5 -# MLITE5_INCLUDE_DIRS - The mlite5 include directories -# MLITE5_LIBRARIES - The libraries needed to use mlite5 -# MLITE5_DEFINITIONS - Compiler switches required for using mlite5 - -find_package(PkgConfig REQUIRED) -pkg_check_modules(PC_Mlite5 QUIET mlite5) -set(Mlite5_DEFINITIONS ${PC_Mlite5_CFLAGS_OTHER}) - -find_path(Mlite5_INCLUDE_DIRS - NAMES mlite-global.h - PATH_SUFFIXES mlite5 - PATHS ${PC_Mlite5_INCLUDEDIR} ${PC_Mlite5_INCLUDE_DIRS}) - -find_library(Mlite5_LIBRARIES - NAMES mlite5 - PATHS ${PC_Mlite5_LIBDIR} ${PC_Mlite5_LIBRARY_DIRS}) - -set(Mlite5_VERSION ${PC_Mlite5_VERSION}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(Mlite5 - FOUND_VAR - Mlite5_FOUND - REQUIRED_VARS - Mlite5_LIBRARIES - Mlite5_INCLUDE_DIRS - VERSION_VAR - Mlite5_VERSION) - -mark_as_advanced(Mlite5_INCLUDE_DIR Mlite5_LIBRARY Mlite5_VERSION) - -if(Mlite5_FOUND AND NOT TARGET Mlite5::Mlite5) - add_library(Mlite5::Mlite5 UNKNOWN IMPORTED) - set_target_properties(Mlite5::Mlite5 PROPERTIES - IMPORTED_LOCATION "${Mlite5_LIBRARIES}" - INTERFACE_INCLUDE_DIRECTORIES "${Mlite5_INCLUDE_DIRS}") -endif() diff --git a/cmake/FindMlite6.cmake b/cmake/FindMlite6.cmake new file mode 100644 index 0000000..e9eec54 --- /dev/null +++ b/cmake/FindMlite6.cmake @@ -0,0 +1,40 @@ +# Try to find mlite6 +# Once done this will define +# MLITE6_FOUND - System has mlite6 +# MLITE6_INCLUDE_DIRS - The mlite6 include directories +# MLITE6_LIBRARIES - The libraries needed to use mlite6 +# MLITE6_DEFINITIONS - Compiler switches required for using mlite6 + +find_package(PkgConfig REQUIRED) +pkg_check_modules(PC_Mlite6 QUIET mlite6) +set(Mlite6_DEFINITIONS ${PC_Mlite6_CFLAGS_OTHER}) + +find_path(Mlite6_INCLUDE_DIRS + NAMES mlite-global.h + PATH_SUFFIXES mlite6 + PATHS ${PC_Mlite6_INCLUDEDIR} ${PC_Mlite6_INCLUDE_DIRS}) + +find_library(Mlite6_LIBRARIES + NAMES mlite6 + PATHS ${PC_Mlite6_LIBDIR} ${PC_Mlite6_LIBRARY_DIRS}) + +set(Mlite6_VERSION ${PC_Mlite6_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Mlite6 + FOUND_VAR + Mlite6_FOUND + REQUIRED_VARS + Mlite6_LIBRARIES + Mlite6_INCLUDE_DIRS + VERSION_VAR + Mlite6_VERSION) + +mark_as_advanced(Mlite6_INCLUDE_DIR Mlite6_LIBRARY Mlite6_VERSION) + +if(Mlite6_FOUND AND NOT TARGET Mlite6::Mlite6) + add_library(Mlite6::Mlite6 UNKNOWN IMPORTED) + set_target_properties(Mlite6::Mlite6 PROPERTIES + IMPORTED_LOCATION "${Mlite6_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Mlite6_INCLUDE_DIRS}") +endif() diff --git a/generate-desktop.sh b/generate-desktop.sh index 91f550d..559cce5 100755 --- a/generate-desktop.sh +++ b/generate-desktop.sh @@ -47,7 +47,7 @@ if [ ! -f "${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h" ]; then exit 2 fi -DEFAULT_NAME=$(grep -oP '//% "\K[^"]+(?=")' "${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h") +DEFAULT_NAME=$(sed -n 's/\/\/% //p' "${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h" | cut -d'"' -f2) if [ -z "$DEFAULT_NAME" ]; then echo "Default name can not be found in ${SRC_DIR}/i18n/${APPLICATION_NAME}.desktop.h" exit 3 @@ -59,7 +59,7 @@ echo "Name=$DEFAULT_NAME" >> "$OUTPUT_FILE" for FILE in "${SRC_DIR}"/i18n/*.ts; do echo "Processing $FILE..." - PROCESSED_LANG=$(grep -oP 'language="\K[^"]+(?=")' "$FILE") + PROCESSED_LANG=$(xmllint --xpath 'string(//TS/@language)' "$FILE") if [ -z "$PROCESSED_LANG" ]; then echo "> Couldn't find a corresponding language id, aborting" continue @@ -78,7 +78,7 @@ for FILE in "${SRC_DIR}"/i18n/*.ts; do continue fi - TRANSLATED_NAME=$(echo "$TRANSLATION_LINE" | grep -oP '>\K[^<]*(?=)') + TRANSLATED_NAME=$(echo "$TRANSLATION_LINE" | xmllint --xpath 'string(//translation)' -) # TODO: 2>/dev/null ? if [ -z "$TRANSLATED_NAME" ]; then echo "> Translation is empty, aborting" continue diff --git a/src/app/AsteroidAppConfig.cmake.in b/src/app/AsteroidAppConfig.cmake.in index c1afb72..dd39dd1 100644 --- a/src/app/AsteroidAppConfig.cmake.in +++ b/src/app/AsteroidAppConfig.cmake.in @@ -1,10 +1,11 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) -find_dependency(Qt5Qml @QT_MIN_VERSION@) -find_dependency(Qt5Quick @QT_MIN_VERSION@) +find_package(Qt6 @QT_MIN_VERSION@ COMPONENTS Qml Quick REQUIRED) set(ASTEROID_MODULE_PATH "@PACKAGE_ASTEROID_MODULES_INSTALL_DIR@") include("${CMAKE_CURRENT_LIST_DIR}/AsteroidAppTargets.cmake") @PACKAGE_INCLUDE_QCHTARGETS@ + +qt_policy(SET QTP0001 NEW) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 333ffc5..be2cbfe 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -5,16 +5,17 @@ add_library(asteroidapp ${SRC} ${HEADERS}) target_link_libraries(asteroidapp PUBLIC - Qt5::Qml - Qt5::Quick + Qt6::Qml + Qt6::Quick PRIVATE - Mlite5::Mlite5 - Mapplauncherd_qt5::Mapplauncherd_qt5) + Mlite6::Mlite6 + $<$:Mapplauncherd_qt6::Mapplauncherd_qt6>) set_target_properties(asteroidapp PROPERTIES EXPORT_NAME AsteroidApp SOVERSION ${PROJECT_VERSION_MAJOR} - VERSION ${PROJECT_VERSION}) + VERSION ${PROJECT_VERSION} + COMPILE_DEFINITIONS $<$:WITH_MAPPLAUNCHERD=1>) target_include_directories(asteroidapp PUBLIC $ @@ -34,9 +35,12 @@ install(FILES asteroidapp.prf DESTINATION ${CMAKE_INSTALL_LIBDIR}/mkspecs/features COMPONENT Devel) +if (WITH_MAPPLAUNCHERD) + set(ASTEROIDAPP_PKGCONF_DEPS "qdeclarative6-boostable") +endif() ecm_generate_pkgconfig_file( BASE_NAME asteroidapp - DEPS qdeclarative5-boostable + DEPS ${ASTEROIDAPP_PKGCONF_DEPS} FILENAME_VAR asteroidapp DESCRIPTION ${PROJECT_DESCRIPTION} INSTALL) diff --git a/src/app/asteroidapp.cpp b/src/app/asteroidapp.cpp index 73e0d0a..0eeea38 100644 --- a/src/app/asteroidapp.cpp +++ b/src/app/asteroidapp.cpp @@ -33,7 +33,8 @@ #include #include #include -#include +#if WITH_MAPPLAUNCHERD +#include static QString applicationPath() { @@ -47,11 +48,16 @@ static QString applicationPath() return QCoreApplication::applicationFilePath(); } } +#endif namespace AsteroidApp { QString appName() { +#if WITH_MAPPLAUNCHERD QFileInfo exe = QFileInfo(applicationPath()); +#else + QFileInfo exe = QFileInfo(QCoreApplication::applicationFilePath()); +#endif return exe.baseName(); } @@ -60,14 +66,20 @@ namespace AsteroidApp { static QGuiApplication *app = NULL; if (app == NULL) { +#if WITH_MAPPLAUNCHERD app = MDeclarativeCache::qApplication(argc, argv); +#else + app = new QGuiApplication(argc, argv); +#endif app->setOrganizationName(appName()); app->setOrganizationDomain(appName()); app->setApplicationName(appName()); QTranslator *translator = new QTranslator(); - translator->load(QLocale(), appName(), ".", "/usr/share/translations", ".qm"); + if (!translator->load(QLocale(), appName(), ".", "/usr/share/translations", ".qm")) { + qDebug() << "Failed to load" << QLocale().name() << "translations for" << appName(); + } app->installTranslator(translator); } else { qWarning("AsteroidApp::application() called multiple times"); @@ -78,7 +90,11 @@ namespace AsteroidApp { QQuickView *createView() { +#if WITH_MAPPLAUNCHERD QQuickView *view = MDeclarativeCache::qQuickView(); +#else + QQuickView *view = new QQuickView; +#endif MDesktopEntry entry("/usr/share/applications/" + appName() + ".desktop"); if (entry.isValid()) { view->setTitle(entry.name()); @@ -94,7 +110,7 @@ namespace AsteroidApp { { QScopedPointer app(AsteroidApp::application(argc, argv)); QScopedPointer view(AsteroidApp::createView()); - view->setSource(QUrl("qrc:/main.qml")); + view->setSource(QUrl("qrc:/qt/qml/asteroidapp/main.qml")); view->resize(app->primaryScreen()->size()); view->show(); return app->exec(); diff --git a/src/app/asteroidapp.h b/src/app/asteroidapp.h index 077c39b..4f07052 100644 --- a/src/app/asteroidapp.h +++ b/src/app/asteroidapp.h @@ -43,7 +43,7 @@ namespace AsteroidApp { ASTEROIDAPP_EXPORT QGuiApplication *application(int &argc, char **argv); ASTEROIDAPP_EXPORT QQuickView *createView(); - // Very simple interface: Uses "qrc:/main.qml" as QML entry point + // Very simple interface: Uses "qrc:/qt/qml/asteroidapp/main.qml" as QML entry point ASTEROIDAPP_EXPORT int main(int &argc, char **argv); }; diff --git a/src/app/asteroidapp.prf b/src/app/asteroidapp.prf index 9a9316a..debbd4e 100644 --- a/src/app/asteroidapp.prf +++ b/src/app/asteroidapp.prf @@ -34,7 +34,7 @@ QT += quick qml target.path = /usr/bin -desktop.commands = bash $$_PRO_FILE_PWD_/i18n/generate-desktop.sh $$_PRO_FILE_PWD_ $${TARGET}.desktop +desktop.commands = sh $$_PRO_FILE_PWD_/i18n/generate-desktop.sh $$_PRO_FILE_PWD_ $${TARGET}.desktop desktop.files = $$OUT_PWD/$${TARGET}.desktop desktop.path = /usr/share/applications desktop.CONFIG = no_check_exist diff --git a/src/controls/CMakeLists.txt b/src/controls/CMakeLists.txt index d008466..36c2a05 100644 --- a/src/controls/CMakeLists.txt +++ b/src/controls/CMakeLists.txt @@ -11,9 +11,7 @@ set(HEADERS src/flatmeshnode.h src/icon.h) -add_library(asteroidcontrolsplugin ${SRC} ${HEADERS} resources.qrc) - -set(controls +set(controls Application BorderGestureArea CircularSpinner @@ -40,6 +38,44 @@ set(controls TextBase TextField ) +foreach(control ${controls}) + list(APPEND controls-qml "qml/${control}.qml") +endforeach() + +set_source_files_properties(qml/Dims.qml + PROPERTIES QT_QML_SINGLETON_TYPE TRUE) + +qt_add_qml_module(asteroidcontrolsplugin + URI org.asteroid.controls + VERSION 1.0 + PLUGIN_TARGET asteroidcontrolsplugin + NO_GENERATE_PLUGIN_SOURCE + #NO_PLUGIN_OPTIONAL + QML_FILES + ${controls-qml} + #ENABLE_TYPE_COMPILER + SOURCES + ${SRC} ${HEADERS} +) + +# TODO: drop debug once AOT produces less warnings etc +set_target_properties(asteroidcontrolsplugin PROPERTIES QT_QMLCACHEGEN_ARGUMENTS "--verbose") + +qt6_add_shaders(asteroidcontrolsplugin "asteroidcontrolsplugin_shaders" + PREFIX "/org/asteroid/controls/" + FILES "qml/Spinner.frag" + BATCHABLE + PRECOMPILE + OPTIMIZED) + +target_link_libraries(asteroidcontrolsplugin + PUBLIC + #Qt::Qml + Qt::Quick # src/{application_p,flatmesh{,node},icon}.* + PRIVATE + Qt::Svg # src/icon.cpp +) + set(controls-docs "$,PREPEND,qml->,APPEND,.html>") set(doc-dir "${CMAKE_BINARY_DIR}/doc/html") set(full-controls-docs "$") @@ -55,12 +91,7 @@ add_custom_command( COMMENT "Generating HTML format Reference documentation..." VERBATIM ) -target_link_libraries(asteroidcontrolsplugin - Qt5::Qml - Qt5::Quick - Qt5::Svg) - install(TARGETS asteroidcontrolsplugin DESTINATION ${INSTALL_QML_IMPORT_DIR}/org/asteroid/controls) -install(FILES qmldir +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir DESTINATION ${INSTALL_QML_IMPORT_DIR}/org/asteroid/controls) diff --git a/src/controls/qml/BorderGestureArea.qml b/src/controls/qml/BorderGestureArea.qml index ab39990..ffece06 100644 --- a/src/controls/qml/BorderGestureArea.qml +++ b/src/controls/qml/BorderGestureArea.qml @@ -61,7 +61,7 @@ import org.asteroid.utils 1.0 acceptsRight: true acceptsLeft: true acceptsDown: true - onGestureFinished: { + onGestureFinished: (gesture) => { if (gesture == "right") { square.color = "red" } @@ -95,7 +95,7 @@ import org.asteroid.utils 1.0 anchors.fill: parent acceptsUp: true acceptsDown: true - onGestureFinished: { + onGestureFinished: (gesture) => { if (gesture == "up") { square.color = "green" } @@ -157,7 +157,7 @@ MouseArea { property int _mouseStart property variant _gestures: ["down", "left", "up", "right"] - onPressed: { + onPressed: (mouse) => { if (mouse.x < boundary && acceptsRight) { gesture = "right" max = width - mouse.x @@ -184,7 +184,7 @@ MouseArea { gestureStarted(gesture) } - onPositionChanged: { + onPositionChanged: (mouse) => { var p = horizontal ? mouse.x : mouse.y value = Math.max(Math.min(p - _mouseStart, max), -max) } diff --git a/src/controls/qml/CircularSpinner.qml b/src/controls/qml/CircularSpinner.qml index 59fece4..6a8df90 100644 --- a/src/controls/qml/CircularSpinner.qml +++ b/src/controls/qml/CircularSpinner.qml @@ -31,7 +31,7 @@ import org.asteroid.controls 1.0 \qml import QtQuick 2.9 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 CircularSpinner { id: rating @@ -93,19 +93,6 @@ PathView { layer.enabled: true layer.effect: ShaderEffect { - fragmentShader: " - precision mediump float; - varying highp vec2 qt_TexCoord0; - uniform sampler2D source; - void main(void) - { - vec4 sourceColor = texture2D(source, qt_TexCoord0); - float alpha = 1.0; - if(qt_TexCoord0.y < 0.2) - alpha = qt_TexCoord0.y*5.0; - if(qt_TexCoord0.y > 0.8) - alpha = (1.0-qt_TexCoord0.y)*5.0; - gl_FragColor = sourceColor * alpha; - }" + fragmentShader: "Spinner.frag.qsb" } } diff --git a/src/controls/qml/Dims.qml b/src/controls/qml/Dims.qml index c4a79a6..05ceb09 100644 --- a/src/controls/qml/Dims.qml +++ b/src/controls/qml/Dims.qml @@ -41,7 +41,7 @@ pragma Singleton \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 Rectangle { width: Dims.w(80) // 80 % of screen width @@ -61,7 +61,7 @@ QtObject { \qmlmethod real w(real number) \brief Returns a dimension that is \a number percent of the screen width. */ - function w(number) { + function w(number: real): real { return (number/100)*Screen.desktopAvailableWidth } @@ -69,7 +69,7 @@ QtObject { \qmlmethod real h(real number) \brief Returns a dimension that is \a number percent of the screen height. */ - function h(number) { + function h(number: real): real { return (number/100)*(Screen.desktopAvailableHeight+DeviceInfo.flatTireHeight) } @@ -77,7 +77,7 @@ QtObject { \qmlmethod real l(real number) \brief Returns a dimension that is \a number percent of the screen width or height; whichever is smaller. */ - function l(number) { + function l(number: real): real { if(Screen.desktopAvailableWidth > (Screen.desktopAvailableHeight+DeviceInfo.flatTireHeight)) return h(number) else diff --git a/src/controls/qml/IconButton.qml b/src/controls/qml/IconButton.qml index 75be41a..46eef27 100644 --- a/src/controls/qml/IconButton.qml +++ b/src/controls/qml/IconButton.qml @@ -21,7 +21,7 @@ import org.asteroid.controls 1.0 /*! \qmltype IconButton - \inqmlmodule org.controls.asteroid 1.0 + \inqmlmodule org.asteroid.controls 1.0 \brief Provides a virtual button with settable icon. diff --git a/src/controls/qml/IntSelector.qml b/src/controls/qml/IntSelector.qml index 16bb1cb..72ae390 100644 --- a/src/controls/qml/IntSelector.qml +++ b/src/controls/qml/IntSelector.qml @@ -40,7 +40,7 @@ import org.asteroid.controls 1.0 \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 Item { IntSelector { diff --git a/src/controls/qml/Label.qml b/src/controls/qml/Label.qml index 77ce82a..ddfe7c8 100644 --- a/src/controls/qml/Label.qml +++ b/src/controls/qml/Label.qml @@ -20,7 +20,7 @@ import org.asteroid.controls 1.0 /*! \qmltype Label - \inqmlmodule org.controls.asteroid 1.0 + \inqmlmodule org.asteroid.controls 1.0 \brief Provides a way to get a text label sized for AsteroidOS. diff --git a/src/controls/qml/LabeledActionButton.qml b/src/controls/qml/LabeledActionButton.qml index 06c11ba..910ea38 100644 --- a/src/controls/qml/LabeledActionButton.qml +++ b/src/controls/qml/LabeledActionButton.qml @@ -35,7 +35,7 @@ import org.asteroid.controls 1.0 \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 Item { LabeledActionButton { diff --git a/src/controls/qml/LabeledSwitch.qml b/src/controls/qml/LabeledSwitch.qml index eee6453..9b5d15d 100644 --- a/src/controls/qml/LabeledSwitch.qml +++ b/src/controls/qml/LabeledSwitch.qml @@ -23,7 +23,7 @@ import org.asteroid.controls 1.0 /*! \qmltype LabeledSwitch - \inqmlmodule org.controls.asteroid 1.0 + \inqmlmodule org.asteroid.controls 1.0 \brief This combines \l Label and \l Switch in a convenient package. diff --git a/src/controls/qml/LayerStack.qml b/src/controls/qml/LayerStack.qml index 8ca6234..382cb41 100644 --- a/src/controls/qml/LayerStack.qml +++ b/src/controls/qml/LayerStack.qml @@ -39,7 +39,7 @@ import QtQuick 2.9 \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 Item { Component { diff --git a/src/controls/qml/Marquee.qml b/src/controls/qml/Marquee.qml index b48d054..e032a94 100644 --- a/src/controls/qml/Marquee.qml +++ b/src/controls/qml/Marquee.qml @@ -33,7 +33,7 @@ import org.asteroid.controls 1.0 \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 Item { Marquee { diff --git a/src/controls/qml/PageDot.qml b/src/controls/qml/PageDot.qml index e295699..92b2947 100644 --- a/src/controls/qml/PageDot.qml +++ b/src/controls/qml/PageDot.qml @@ -36,7 +36,7 @@ import QtQuick 2.9 \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 Item { IntSelector { diff --git a/src/controls/qml/PageHeader.qml b/src/controls/qml/PageHeader.qml index 23d9129..d1d6d11 100644 --- a/src/controls/qml/PageHeader.qml +++ b/src/controls/qml/PageHeader.qml @@ -22,7 +22,7 @@ import org.asteroid.utils 1.0 /*! \qmltype PageHeader - \inqmlmodule org.controls.asteroid 1.0 + \inqmlmodule org.asteroid.controls 1.0 \brief Provides a title on a page. diff --git a/src/controls/qml/Spinner.frag b/src/controls/qml/Spinner.frag new file mode 100644 index 0000000..0b08898 --- /dev/null +++ b/src/controls/qml/Spinner.frag @@ -0,0 +1,14 @@ +#version 440 +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; +layout(binding = 1) uniform sampler2D source; +void main(void) +{ + vec4 sourceColor = texture(source, qt_TexCoord0); + float alpha = 1.0; + if(qt_TexCoord0.y < 0.2) + alpha = qt_TexCoord0.y*5.0; + if(qt_TexCoord0.y > 0.8) + alpha = (1.0-qt_TexCoord0.y)*5.0; + fragColor = sourceColor * alpha; +} diff --git a/src/controls/qml/Spinner.qml b/src/controls/qml/Spinner.qml index c748d7a..c154d9f 100644 --- a/src/controls/qml/Spinner.qml +++ b/src/controls/qml/Spinner.qml @@ -30,7 +30,7 @@ import org.asteroid.controls 1.0 \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 Spinner { id: rating @@ -72,19 +72,6 @@ ListView { layer.enabled: true layer.effect: ShaderEffect { - fragmentShader: " - precision mediump float; - varying highp vec2 qt_TexCoord0; - uniform sampler2D source; - void main(void) - { - vec4 sourceColor = texture2D(source, qt_TexCoord0); - float alpha = 1.0; - if(qt_TexCoord0.y < 0.2) - alpha = qt_TexCoord0.y*5.0; - if(qt_TexCoord0.y > 0.8) - alpha = (1.0-qt_TexCoord0.y)*5.0; - gl_FragColor = sourceColor * alpha; - }" + fragmentShader: "Spinner.frag.qsb" } } diff --git a/src/controls/qml/StatusPage.qml b/src/controls/qml/StatusPage.qml index 322b548..ca65826 100644 --- a/src/controls/qml/StatusPage.qml +++ b/src/controls/qml/StatusPage.qml @@ -35,7 +35,7 @@ import org.asteroid.controls 1.0 \qml import QtQuick 2.0 - import org.controls.asteroid 1.0 + import org.asteroid.controls 1.0 StatusPage { text: "On fire" diff --git a/src/controls/qml/Switch.qml b/src/controls/qml/Switch.qml index 029fdf0..a28ebfe 100644 --- a/src/controls/qml/Switch.qml +++ b/src/controls/qml/Switch.qml @@ -21,7 +21,7 @@ import org.asteroid.controls 1.0 /*! \qmltype Switch - \inqmlmodule org.controls.asteroid 1.0 + \inqmlmodule org.asteroid.controls 1.0 \brief Specializes \l IconButton to provide an on/off toggle. diff --git a/src/controls/qml/TextBase.qml b/src/controls/qml/TextBase.qml index b435af0..4e4aa8f 100644 --- a/src/controls/qml/TextBase.qml +++ b/src/controls/qml/TextBase.qml @@ -45,7 +45,7 @@ FocusScope { signal enterKeyClicked - Keys.onReleased: { + Keys.onReleased: (event) => { if (event.key === Qt.Key_Return) enterKeyClicked() } diff --git a/src/controls/qmldir b/src/controls/qmldir deleted file mode 100644 index 88dfe74..0000000 --- a/src/controls/qmldir +++ /dev/null @@ -1,29 +0,0 @@ -module org.asteroid.controls - -plugin asteroidcontrolsplugin - -Application 1.0 qrc:///org/asteroid/controls/qml/Application.qml -BorderGestureArea 1.0 qrc:///org/asteroid/controls/qml/BorderGestureArea.qml -CircularSpinner 1.0 qrc:///org/asteroid/controls/qml/CircularSpinner.qml -singleton Dims 1.0 qrc:///org/asteroid/controls/qml/Dims.qml -HandWritingKeyboard 1.0 qrc:///org/asteroid/controls/qml/HandWritingKeyboard.qml -HighlightBar 1.0 qrc:///org/asteroid/controls/qml/HighlightBar.qml -IconButton 1.0 qrc:///org/asteroid/controls/qml/IconButton.qml -Indicator 1.0 qrc:///org/asteroid/controls/qml/Indicator.qml -IntSelector 1.0 qrc:///org/asteroid/controls/qml/IntSelector.qml -Label 1.0 qrc:///org/asteroid/controls/qml/Label.qml -LabeledActionButton 1.0 qrc:///org/asteroid/controls/qml/LabeledActionButton.qml -LabeledSwitch 1.0 qrc:///org/asteroid/controls/qml/LabeledSwitch.qml -LayerStack 1.0 qrc:///org/asteroid/controls/qml/LayerStack.qml -ListItem 1.0 qrc:///org/asteroid/controls/qml/ListItem.qml -Marquee 1.0 qrc:///org/asteroid/controls/qml/Marquee.qml -PageDot 1.0 qrc:///org/asteroid/controls/qml/PageDot.qml -PageHeader 1.0 qrc:///org/asteroid/controls/qml/PageHeader.qml -SegmentedArc 1.0 qrc:///org/asteroid/controls/qml/SegmentedArc.qml -Spinner 1.0 qrc:///org/asteroid/controls/qml/Spinner.qml -SpinnerDelegate 1.0 qrc:///org/asteroid/controls/qml/SpinnerDelegate.qml -StatusPage 1.0 qrc:///org/asteroid/controls/qml/StatusPage.qml -Switch 1.0 qrc:///org/asteroid/controls/qml/Switch.qml -TextArea 1.0 qrc:///org/asteroid/controls/qml/TextArea.qml -TextBase 1.0 qrc:///org/asteroid/controls/qml/TextBase.qml -TextField 1.0 qrc:///org/asteroid/controls/qml/TextField.qml diff --git a/src/controls/resources.qrc b/src/controls/resources.qrc deleted file mode 100644 index 7c19457..0000000 --- a/src/controls/resources.qrc +++ /dev/null @@ -1,29 +0,0 @@ - - - qml/Application.qml - qml/BorderGestureArea.qml - qml/CircularSpinner.qml - qml/Dims.qml - qml/ListItem.qml - qml/HandWritingKeyboard.qml - qml/HighlightBar.qml - qml/IconButton.qml - qml/Indicator.qml - qml/Label.qml - qml/LayerStack.qml - qml/Marquee.qml - qml/LabeledSwitch.qml - qml/LabeledActionButton.qml - qml/PageDot.qml - qml/PageHeader.qml - qml/IntSelector.qml - qml/SegmentedArc.qml - qml/SpinnerDelegate.qml - qml/Spinner.qml - qml/StatusPage.qml - qml/Switch.qml - qml/TextArea.qml - qml/TextBase.qml - qml/TextField.qml - - diff --git a/src/controls/src/icon.cpp b/src/controls/src/icon.cpp index e26d2ec..6135323 100644 --- a/src/controls/src/icon.cpp +++ b/src/controls/src/icon.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #define ICONS_DIRECTORY "/usr/share/icons/asteroid/" @@ -79,9 +80,10 @@ void Icon::paint(QPainter *painter) painter->drawPixmap(0, 0, width(), height(), m_pixmap); } -void Icon::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) + +void Icon::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) { - QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry); + QQuickPaintedItem::geometryChange(newGeometry, oldGeometry); if(newGeometry.size() == oldGeometry.size() || newGeometry.width() == 0 || newGeometry.height() == 0) return; updateBasePixmap(); diff --git a/src/controls/src/icon.h b/src/controls/src/icon.h index a3f9e0a..0a44554 100644 --- a/src/controls/src/icon.h +++ b/src/controls/src/icon.h @@ -52,7 +52,7 @@ class Icon : public QQuickPaintedItem void paint(QPainter *painter) override; - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; + void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; signals: void nameChanged(); diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 5ca2119..01532f4 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,22 +1,33 @@ set(SRC - src/utils_plugin.cpp src/deviceinfo.cpp src/fileinfo.cpp src/bluetoothstatus.cpp) set(HEADERS - src/utils_plugin.h src/deviceinfo.h src/fileinfo.h src/bluetoothstatus.h) -add_library(asteroidutilsplugin ${SRC} ${HEADERS}) +# TODO: ensure FileInfo 1.0 (singleton) & BluetoothStatus 1.0 (normal) QML classes work +qt_add_qml_module(asteroidutilsplugin + URI org.asteroid.utils + VERSION 1.0 + PLUGIN_TARGET asteroidutilsplugin + #NO_PLUGIN_OPTIONAL + SOURCES + ${SRC} ${HEADERS} +) + +target_include_directories(asteroidutilsplugin PRIVATE src) target_link_libraries(asteroidutilsplugin - Qt5::DBus - Qt5::Qml - Qt5::Quick) + #PUBLIC + # Qt::Qml + # Qt::Quick + PRIVATE + Qt::DBus # bluetoothstatus +) install(TARGETS asteroidutilsplugin DESTINATION ${INSTALL_QML_IMPORT_DIR}/org/asteroid/utils) -install(FILES qmldir - DESTINATION ${INSTALL_QML_IMPORT_DIR}/org/asteroid/utils) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir + DESTINATION ${INSTALL_QML_IMPORT_DIR}/org/asteroid/utils) diff --git a/src/utils/qmldir b/src/utils/qmldir deleted file mode 100644 index 6a0ed83..0000000 --- a/src/utils/qmldir +++ /dev/null @@ -1,3 +0,0 @@ -module org.asteroid.utils - -plugin asteroidutilsplugin diff --git a/src/utils/src/bluetoothstatus.h b/src/utils/src/bluetoothstatus.h index 6924bf4..eadf25b 100644 --- a/src/utils/src/bluetoothstatus.h +++ b/src/utils/src/bluetoothstatus.h @@ -23,6 +23,7 @@ #include #include #include +#include typedef QMap> InterfaceList; Q_DECLARE_METATYPE(InterfaceList) @@ -30,6 +31,7 @@ Q_DECLARE_METATYPE(InterfaceList) class BluetoothStatus : public QObject { Q_OBJECT + QML_ELEMENT Q_PROPERTY(bool powered READ getPowered WRITE setPowered NOTIFY poweredChanged) Q_PROPERTY(bool connected READ getConnected NOTIFY connectedChanged) diff --git a/src/utils/src/deviceinfo.cpp b/src/utils/src/deviceinfo.cpp index ccaf766..45aea76 100644 --- a/src/utils/src/deviceinfo.cpp +++ b/src/utils/src/deviceinfo.cpp @@ -35,7 +35,7 @@ DeviceInfo::DeviceInfo() QFile host(HOST_FILE); if (host.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&host); - in.setCodec("UTF-8"); + in.setEncoding(QStringConverter::Utf8); m_hostname = in.readLine(); host.close(); } @@ -43,7 +43,7 @@ DeviceInfo::DeviceInfo() QFile release(OS_RELEASE_FILE); if (release.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&release); - in.setCodec("UTF-8"); + in.setEncoding(QStringConverter::Utf8); QString line = in.readLine(); for (bool searching{true}; searching && !in.atEnd(); line = in.readLine()) { if (line.startsWith("BUILD_ID")) { diff --git a/src/utils/src/deviceinfo.h b/src/utils/src/deviceinfo.h index e4b1a50..44c9d6f 100644 --- a/src/utils/src/deviceinfo.h +++ b/src/utils/src/deviceinfo.h @@ -26,6 +26,8 @@ class DeviceInfo : public QObject { Q_OBJECT + QML_SINGLETON + QML_ELEMENT Q_DISABLE_COPY(DeviceInfo) Q_PROPERTY(bool hasRoundScreen READ hasRoundScreen CONSTANT) Q_PROPERTY(double borderGestureWidth READ borderGestureWidth CONSTANT) @@ -38,11 +40,8 @@ class DeviceInfo : public QObject Q_PROPERTY(QString buildID READ buildID CONSTANT) DeviceInfo(); public: - static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine) + static DeviceInfo *create(QQmlEngine *, QJSEngine *) { - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - return new DeviceInfo; } bool hasRoundScreen(); diff --git a/src/utils/src/fileinfo.h b/src/utils/src/fileinfo.h index 3aba610..a966e37 100644 --- a/src/utils/src/fileinfo.h +++ b/src/utils/src/fileinfo.h @@ -25,16 +25,16 @@ class FileInfo : public QObject { Q_OBJECT + QML_SINGLETON + QML_ELEMENT Q_DISABLE_COPY(FileInfo) FileInfo() {} public: - static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine) + static FileInfo *create(QQmlEngine *, QJSEngine *) { - Q_UNUSED(engine); - Q_UNUSED(scriptEngine); - return new FileInfo; } + // TODO: FileInfo(QObject *parent = 0); instead? Q_INVOKABLE bool exists(const QString fileName); }; diff --git a/src/utils/src/utils_plugin.cpp b/src/utils/src/utils_plugin.cpp deleted file mode 100644 index 754fee6..0000000 --- a/src/utils/src/utils_plugin.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2016 - Florent Revest - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "utils_plugin.h" -#include -#include "bluetoothstatus.h" -#include "deviceinfo.h" -#include "fileinfo.h" - -UtilsPlugin::UtilsPlugin(QObject *parent) : QQmlExtensionPlugin(parent) -{ -} - -void UtilsPlugin::registerTypes(const char *uri) -{ - Q_ASSERT(uri == QLatin1String("org.asteroid.utils")); - - qmlRegisterSingletonType(uri, 1,0, "DeviceInfo", &DeviceInfo::qmlInstance); - qmlRegisterSingletonType(uri, 1, 0, "FileInfo", &FileInfo::qmlInstance); - qmlRegisterType(uri, 1, 0, "BluetoothStatus"); -} - diff --git a/src/utils/src/utils_plugin.h b/src/utils/src/utils_plugin.h deleted file mode 100644 index e1f79ff..0000000 --- a/src/utils/src/utils_plugin.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2016 - Florent Revest - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UTILSPLUGIN_H -#define UTILSPLUGIN_H - -#include - -class UtilsPlugin : public QQmlExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") - -public: - explicit UtilsPlugin(QObject *parent = 0); - void registerTypes(const char *uri); -}; - -#endif // UTILSPLUGIN_H -