From 52507c9996881eca7618ff178ddeb7d3d321d6bd Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 14 Sep 2018 04:45:57 +0200 Subject: [PATCH] improvements --- src/luaengine/luaengine/LuaEngine.cpp | 26 +++++ src/luaengine/luaengine/LuaEngine.h | 1 + src/luaengineapp/edit.lua | 2 +- src/luaengineapp/main.cpp | 2 +- src/luaenginegui/luaengine/LuaEngineGui.cpp | 102 ++++++++++---------- 5 files changed, 78 insertions(+), 55 deletions(-) diff --git a/src/luaengine/luaengine/LuaEngine.cpp b/src/luaengine/luaengine/LuaEngine.cpp index f005eef..3bf2c3b 100644 --- a/src/luaengine/luaengine/LuaEngine.cpp +++ b/src/luaengine/luaengine/LuaEngine.cpp @@ -19,6 +19,7 @@ #include "LuaEngine.h" #include #include +#include LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent) { @@ -32,6 +33,7 @@ LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent) pushFunction("connect", luaTriggerConnect_p); pushFunction("disconnect", luaTriggerDisconnect_p); pushFunction("luaEngineVersion", luaEngineVersion_p); + pushFunction("luaEnginePlatform", luaEnginePlatform_p); } LuaEngine::~LuaEngine() @@ -55,6 +57,30 @@ int LuaEngine::luaEngineVersion_p(lua_State *L_p) return 1; } +int LuaEngine::luaEnginePlatform_p(lua_State *L_p) +{ +#ifdef Q_OS_ANDROID + pushVariant(L_p, "Android"); +#elif defined(Q_OS_LINUX) + pushVariant(L_p, "Linux"); +#elif defined(Q_OS_FREEBSD) + pushVariant(L_p, "FreeBSD"); +#elif defined(Q_OS_OPENBSD) + pushVariant(L_p, "OpenBSD"); +#elif defined(Q_OS_MACOS) + pushVariant(L_p, "macOS"); +#elif defined(Q_OS_DARWIN) + pushVariant(L_p, "Darwin"); +#elif defined(Q_OS_UNIX) + pushVariant(L_p, "Unix"); +#elif defined(Q_OS_WIN) + pushVariant(L_p, "Windows"); +#else + pushVariant(L_p, "Unknown"); +#endif + return 1; +} + bool LuaEngine::executeLuaScript(const QByteArray &data) { int returnCode = luaL_dostring(L, data.data()); diff --git a/src/luaengine/luaengine/LuaEngine.h b/src/luaengine/luaengine/LuaEngine.h index d16af0d..ea9f915 100644 --- a/src/luaengine/luaengine/LuaEngine.h +++ b/src/luaengine/luaengine/LuaEngine.h @@ -75,6 +75,7 @@ public: private: lua_State *L; static int luaEngineVersion_p(lua_State *L_p); + static int luaEnginePlatform_p(lua_State *L_p); static int luaDeletePointer_p(lua_State *L_p); static int luaTriggerConnect_p(lua_State *L_p); static int luaTriggerDisconnect_p(lua_State *L_p); diff --git a/src/luaengineapp/edit.lua b/src/luaengineapp/edit.lua index 8ed2cf1..10c0fea 100644 --- a/src/luaengineapp/edit.lua +++ b/src/luaengineapp/edit.lua @@ -53,7 +53,7 @@ function main() layoutAddWidget(mainLayout, textEditor) setWidgetSize(mainWindow, 650, 450) - showWidget(mainWindow, ShowNormal) + showWidget(mainWindow, ShowDefault) return GuiExecuted end diff --git a/src/luaengineapp/main.cpp b/src/luaengineapp/main.cpp index 06ae604..dd65a99 100644 --- a/src/luaengineapp/main.cpp +++ b/src/luaengineapp/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) delete luaEngineStyleFile; #endif - QFile luaScript(":/lua/app.lua"); + QFile luaScript(":/lua/edit.lua"); LuaEngineGui luaEngineGui; luaEngineGui.executeLuaScript(&luaScript); diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index f8bbf38..04f22c4 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -76,9 +76,10 @@ void LuaEngineGui::pushClass(lua_State *L_p) pushFunction(L_p, "setWidgetSize", setWidgetSize); pushVariant(L_p, "ShowCurrent", 0); pushVariant(L_p, "ShowNormal", 1); - pushVariant(L_p, "ShowMinimised", 2); - pushVariant(L_p, "ShowMaximised", 3); - pushVariant(L_p, "ShowFullscreen", 4); + pushVariant(L_p, "ShowDefault", 2); + pushVariant(L_p, "ShowMinimised", 3); + pushVariant(L_p, "ShowMaximised", 4); + pushVariant(L_p, "ShowFullscreen", 5); // Check Box pushFunction(L_p, "createCheckBox", createCheckBox); @@ -310,12 +311,19 @@ int LuaEngineGui::showWidget(lua_State *L_p) ((QWidget*)pointer)->showNormal(); break; case 2: - ((QWidget*)pointer)->showMinimized(); +#ifdef Q_OS_ANDROID + ((QWidget*)pointer)->showMaximized(); +#else + ((QWidget*)pointer)->showNormal(); +#endif break; case 3: - ((QWidget*)pointer)->showMaximized(); + ((QWidget*)pointer)->showMinimized(); break; case 4: + ((QWidget*)pointer)->showMaximized(); + break; + case 5: ((QWidget*)pointer)->showFullScreen(); break; default: @@ -499,16 +507,14 @@ int LuaEngineGui::createCentralWidget(lua_State *L_p) int LuaEngineGui::createCheckBox(lua_State *L_p) { - QVariantList args = getArguments(L_p); QWidget *parent = nullptr; QString labelText = "LuaEngine"; - if (args.length() >= 1) { - labelText = args.at(0).toString(); - if (args.length() >= 2) { - if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { - if (((QObject*)qvariant_cast(args.at(1)))->inherits("QWidget")) { - parent = (QWidget*)qvariant_cast(args.at(1)); - } + if (getArgumentCount(L_p) >= 1) { + labelText = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { + parent = (QWidget*)pointer; } } } @@ -521,16 +527,14 @@ int LuaEngineGui::createCheckBox(lua_State *L_p) int LuaEngineGui::createDialog(lua_State *L_p) { - QVariantList args = getArguments(L_p); QWidget *parent = nullptr; QString windowTitle = "LuaEngine"; - if (args.length() >= 1) { - windowTitle = args.at(0).toString(); - if (args.length() >= 2) { - if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { - if (((QObject*)qvariant_cast(args.at(1)))->inherits("QWidget")) { - parent = (QWidget*)qvariant_cast(args.at(1)); - } + if (getArgumentCount(L_p) >= 1) { + windowTitle = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { + parent = (QWidget*)pointer; } } } @@ -548,16 +552,14 @@ int LuaEngineGui::createDialog(lua_State *L_p) int LuaEngineGui::createLabel(lua_State *L_p) { - QVariantList args = getArguments(L_p); QWidget *parent = nullptr; QString labelText = "LuaEngine"; - if (args.length() >= 1) { - labelText = args.at(0).toString(); - if (args.length() >= 2) { - if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { - if (((QObject*)qvariant_cast(args.at(1)))->inherits("QWidget")) { - parent = (QWidget*)qvariant_cast(args.at(1)); - } + if (getArgumentCount(L_p) >= 1) { + labelText = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { + parent = (QWidget*)pointer; } } } @@ -608,16 +610,14 @@ int LuaEngineGui::createLayout(lua_State *L_p) int LuaEngineGui::createLineEdit(lua_State *L_p) { - QVariantList args = getArguments(L_p); QWidget *parent = nullptr; QString editText = "LuaEngine"; - if (args.length() >= 1) { - editText = args.at(0).toString(); - if (args.length() >= 2) { - if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { - if (((QObject*)qvariant_cast(args.at(1)))->inherits("QWidget")) { - parent = (QWidget*)qvariant_cast(args.at(1)); - } + if (getArgumentCount(L_p) >= 1) { + editText = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { + parent = (QWidget*)pointer; } } } @@ -630,16 +630,14 @@ int LuaEngineGui::createLineEdit(lua_State *L_p) int LuaEngineGui::createMainWindow(lua_State *L_p) { - QVariantList args = getArguments(L_p); QWidget *parent = nullptr; QString windowTitle = "LuaEngine"; - if (args.length() >= 1) { - windowTitle = args.at(0).toString(); - if (args.length() >= 2) { - if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { - if (((QObject*)qvariant_cast(args.at(1)))->inherits("QWidget")) { - parent = (QWidget*)qvariant_cast(args.at(1)); - } + if (getArgumentCount(L_p) >= 1) { + windowTitle = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { + parent = (QWidget*)pointer; } } } @@ -739,16 +737,14 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p) int LuaEngineGui::createPushButton(lua_State *L_p) { - QVariantList args = getArguments(L_p); QWidget *parent = nullptr; QString buttonText = "LuaEngine"; - if (args.length() >= 1) { - buttonText = args.at(0).toString(); - if (args.length() >= 2) { - if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { - if (((QObject*)qvariant_cast(args.at(1)))->inherits("QWidget")) { - parent = (QWidget*)qvariant_cast(args.at(1)); - } + if (getArgumentCount(L_p) >= 1) { + buttonText = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { + parent = (QWidget*)pointer; } } }