Skip to content

Commit

Permalink
Add qtjsapi to the script engine (allows usage of many Qt-based class…
Browse files Browse the repository at this point in the history
…es in JS)
  • Loading branch information
Jmgr committed Jul 14, 2024
1 parent a90fcde commit 8d694db
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "actiona/3rdparty/QDarkStyleSheet"]
path = actiona/3rdparty/QDarkStyleSheet
url = https://github.com/ColinDuquesnoy/QDarkStyleSheet
[submodule "actiontools/src/3rdparty/qtjsapi"]
path = actiontools/src/3rdparty/qtjsapi
url = git@github.com:Jmgr/qtjsapi.git
[submodule "actiontools/3rdparty/qtjsapi"]
path = actiontools/3rdparty/qtjsapi
url = https://github.com/Jmgr/actiona.git
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ Monetary contributions will be used to pay for the rental of the dedicated serve

## License

Actiona is licensed under the GNU/GPLv3 License, but includes code and other resources licensed under other licenses:
Actiona is licensed under the GNU/GPLv3 license, but includes code and other resources licensed under other licenses:
* QDarkStyleSheet: [MIT License - Source Code, and Creative Commons Attribution International 4.0 - Images](https://github.com/ColinDuquesnoy/QDarkStyleSheet/blob/master/LICENSE.rst)
* QHotkey: [BSD-3-Clause License](https://github.com/Skycoder42/QHotkey/blob/master/LICENSE)
* breakpad: [BSD License](https://chromium.googlesource.com/breakpad/breakpad/+/master/LICENSE)
* mINI: [MIT License](https://github.com/pulzed/mINI/blob/master/LICENSE)
* Qxt library: Common Public License version 1 and GNU/LGPL version 2.1
* Crystal Clear icons: [GNU/LGPL](https://web.archive.org/web/20070626051615/https://www.everaldo.com/crystal/?action=license)
* qtjsapi: [MIT License](https://github.com/qcad/qtjsapi/blob/main/LICENSE.txt)
5 changes: 5 additions & 0 deletions actexec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ setup_target(${PROJECT})

find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Qml Network Widgets Core5Compat Multimedia TextToSpeech REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
5 changes: 5 additions & 0 deletions actiona/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ setup_target(${PROJECT})

find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Qml Network Widgets Core5Compat Multimedia TextToSpeech REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
5 changes: 5 additions & 0 deletions actions/data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ target_compile_definitions(${PROJECT} PRIVATE ACTIONPACKDATA_LIBRARY)

find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Qml Network Sql Widgets Core5Compat REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
5 changes: 5 additions & 0 deletions actions/device/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ target_compile_definitions(${PROJECT} PRIVATE ACTIONPACKDEVICE_LIBRARY)

find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Qml Widgets REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
5 changes: 5 additions & 0 deletions actions/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ target_compile_definitions(${PROJECT} PRIVATE ACTIONPACKINTERNAL_LIBRARY)

find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Qml Widgets REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
5 changes: 5 additions & 0 deletions actions/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS
TextToSpeech
REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
5 changes: 5 additions & 0 deletions actions/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ target_compile_definitions(${PROJECT} PRIVATE ACTIONPACKWINDOWS_LIBRARY)

find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Qml Widgets REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
1 change: 1 addition & 0 deletions actiontools/3rdparty/qtjsapi
Submodule qtjsapi added at 5ef2cc
21 changes: 20 additions & 1 deletion actiontools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include(ExternalProject)

set(PROJECT actiontools)

set(SOURCES_PREFIX src)
Expand Down Expand Up @@ -278,7 +280,7 @@ add_library(${PROJECT} SHARED
${QRC}
)

add_dependencies(${PROJECT} tools)
add_dependencies(${PROJECT} tools external_qtjsapi)

if(UNIX)
include(FindPkgConfig)
Expand All @@ -292,20 +294,36 @@ setup_target(${PROJECT})
find_package(OpenCV REQUIRED core imgproc)
find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Widgets Qml REQUIRED)

ExternalProject_Add(external_qtjsapi
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/qtjsapi
BINARY_DIR ${CMAKE_BINARY_DIR}/3rdparty/qtjsapi
INSTALL_COMMAND cmake -E echo "Skipping install step."
CMAKE_ARGS
-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/../tools/include
SYSTEM
${LIBXTST_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty
)

target_link_libraries(
${PROJECT}
tools
qtjsapi
Qt6::Widgets
Qt6::Qml
Qt6::QmlPrivate
Expand All @@ -315,3 +333,4 @@ target_link_libraries(
)

compile_translations(${PROJECT})

4 changes: 4 additions & 0 deletions actiontools/include/actiontools/scriptengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <QJSEngine>

class RJSApi;

namespace ActionTools
{
class ACTIONTOOLSSHARED_EXPORT ScriptEngine : public QObject
Expand All @@ -40,6 +42,7 @@ namespace ActionTools
};

explicit ScriptEngine(QObject *parent = nullptr);
virtual ~ScriptEngine();

QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1, QStringList *exceptionStackTrace = nullptr);
bool isEvaluating() const { return mIsEvaluating; }
Expand All @@ -56,6 +59,7 @@ namespace ActionTools
private:
static QJSEngine *mCurrent;
std::unique_ptr<QJSEngine> mEngine;
std::unique_ptr<RJSApi> mQJsApi;
bool mIsEvaluating{false};
Context mContext{Unknown};
};
Expand Down
9 changes: 8 additions & 1 deletion actiontools/src/scriptengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "actiontools/scriptengine.hpp"
#include "qtjsapi/RJSApi.h"

#include <private/qv4engine_p.h>

Expand All @@ -28,7 +29,13 @@ namespace ActionTools

ScriptEngine::ScriptEngine(QObject *parent):
QObject(parent),
mEngine(std::make_unique<QJSEngine>())
mEngine(std::make_unique<QJSEngine>()),
mQJsApi(new RJSApi(mEngine.get()))
{
mQJsApi->init();
}

ScriptEngine::~ScriptEngine()
{
}

Expand Down
5 changes: 5 additions & 0 deletions execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ setup_target(${PROJECT})

find_package(Qt6 ${ACT_MINIMUM_QT_VERSION} COMPONENTS Widgets UiTools Qml REQUIRED)

target_link_directories(${PROJECT}
PRIVATE
${CMAKE_BINARY_DIR}/3rdparty/qtjsapi/out
)

target_include_directories(${PROJECT}
PUBLIC
$<INSTALL_INTERFACE:include>
Expand Down

0 comments on commit 8d694db

Please sign in to comment.