From fb6a449d833582a9ae1666cee5a1b4e784336af8 Mon Sep 17 00:00:00 2001 From: Syping Date: Thu, 23 Aug 2018 17:17:27 +0200 Subject: [PATCH] checkBox added --- src/luaengineapp/app.lua | 4 ++++ src/luaenginegui/luaengine/LuaEngineGui.cpp | 26 +++++++++++++++++++++ src/luaenginegui/luaengine/LuaEngineGui.h | 1 + 3 files changed, 31 insertions(+) diff --git a/src/luaengineapp/app.lua b/src/luaengineapp/app.lua index b8a832a..bb1703f 100644 --- a/src/luaengineapp/app.lua +++ b/src/luaengineapp/app.lua @@ -29,6 +29,7 @@ local labelLayout local appLabel1 local appLabel2 local pushButton1 +local checkBox1 function main() mainWindow = createMainWindow() @@ -50,6 +51,9 @@ function main() appLabel2 = createLabel("..and not only one time!", mainWidget) layoutAddWidget(labelLayout, appLabel2) + checkBox1 = createCheckBox("Want to check me?", mainWidget) + layoutAddWidget(mainLayout, checkBox1) + pushButton1 = createPushButton("Press me hard please!", mainWidget) layoutAddWidget(mainLayout, pushButton1) connect(pushButton1, "clicked()", "showHarderBox") diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index 2892057..ce67868 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,9 @@ void LuaEngineGui::pushClass(lua_State *L_p) pushVariant(L_p, "ShowMaximised", 3); pushVariant(L_p, "ShowFullscreen", 4); + // Check Box + pushFunction(L_p, "createCheckBox", createCheckBox); + // Label pushFunction(L_p, "createLabel", createLabel); @@ -228,6 +232,28 @@ int LuaEngineGui::createCentralWidget(lua_State *L_p) return 0; } +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)); + } + } + } + } + QCheckBox *checkBox = new QCheckBox(parent); + checkBox->setObjectName(nameForPointer(checkBox)); + checkBox->setText(labelText); + pushPointer(L_p, checkBox); + return 1; +} + int LuaEngineGui::createLabel(lua_State *L_p) { QVariantList args = getArguments(L_p); diff --git a/src/luaenginegui/luaengine/LuaEngineGui.h b/src/luaenginegui/luaengine/LuaEngineGui.h index dbaae57..eaf3d40 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.h +++ b/src/luaenginegui/luaengine/LuaEngineGui.h @@ -36,6 +36,7 @@ public: static int layoutAddLayout(lua_State *L_p); static int layoutAddWidget(lua_State *L_p); static int createCentralWidget(lua_State *L_p); + static int createCheckBox(lua_State *L_p); static int createLabel(lua_State *L_p); static int createLayout(lua_State *L_p); static int createMainWindow(lua_State *L_p);