From 4c01f31b046e8c252a60425b3d98b3cca35abbc7 Mon Sep 17 00:00:00 2001 From: Syping Date: Sat, 16 May 2020 20:00:35 +0200 Subject: [PATCH] add StackSwitch --- src/luaenginegui/luaengine/LuaEngineGui.cpp | 50 +++++++++++++++++++++ src/luaenginegui/luaengine/LuaEngineGui.h | 3 ++ 2 files changed, 53 insertions(+) diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index 398c446..b997137 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -17,6 +17,7 @@ #include "LuaEngineGui.h" #include +#include #include #include #include @@ -154,6 +155,11 @@ void LuaEngineGui::pushClass(lua_State *L_p) // Spacer Item pushFunction(L_p, "createSpacerItem", createSpacerItem); + // Stack Switcher + pushFunction(L_p, "createStackSwitch", createStackSwitch); + pushFunction(L_p, "createWidgetStack", createWidgetStack); + pushFunction(L_p, "addWidgetAsStack", addWidgetAsStack); + // Tab Bar pushFunction(L_p, "createTabBar", createTabBar); pushFunction(L_p, "createWidgetTab", createWidgetTab); @@ -701,6 +707,18 @@ int LuaEngineGui::widgetAddText(lua_State *L_p) return 0; } +int LuaEngineGui::addWidgetAsStack(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + void *w_pointer = getPointer(L_p, 1); + void *t_pointer = getPointer(L_p, 2); + if (w_pointer != NULL && t_pointer != NULL && ((QObject*)w_pointer)->inherits("QWidget") && ((QObject*)t_pointer)->inherits("QStackedWidget")) { + ((QStackedWidget*)t_pointer)->addWidget((QWidget*)w_pointer); + } + } + return 0; +} + int LuaEngineGui::addWidgetAsTab(lua_State *L_p) { if (getArgumentCount(L_p) >= 3) { @@ -1094,6 +1112,22 @@ int LuaEngineGui::createSpacerItem(lua_State *L_p) return 0; } +int LuaEngineGui::createStackSwitch(lua_State *L_p) +{ + QLayout *layout = nullptr; + QWidget *parent = nullptr; + if (getArgumentCount(L_p) >= 1) { + lpForPointer(getPointer(L_p, 1), &layout, &parent); + } + QStackedWidget *stackedWidget = new QStackedWidget(parent); + stackedWidget->setObjectName(nameForPointer(stackedWidget)); + if (layout != nullptr) { + layout->addWidget(stackedWidget); + } + pushPointer(L_p, stackedWidget); + return 1; +} + int LuaEngineGui::createTabBar(lua_State *L_p) { QLayout *layout = nullptr; @@ -1152,6 +1186,22 @@ int LuaEngineGui::createToolButton(lua_State *L_p) return 1; } +int LuaEngineGui::createWidgetStack(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + if (pointer != NULL && ((QObject*)pointer)->inherits("QStackedWidget")) { + QStackedWidget *stackedWidget = (QStackedWidget*)pointer; + QWidget *widgetStack = new QWidget(stackedWidget); + widgetStack->setObjectName(nameForPointer(widgetStack)); + stackedWidget->addWidget(widgetStack); + pushPointer(L_p, widgetStack); + return 1; + } + } + return 0; +} + int LuaEngineGui::createWidgetTab(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { diff --git a/src/luaenginegui/luaengine/LuaEngineGui.h b/src/luaenginegui/luaengine/LuaEngineGui.h index a8ed848..f8fba00 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.h +++ b/src/luaenginegui/luaengine/LuaEngineGui.h @@ -54,6 +54,7 @@ public: static int layoutAddLayout(lua_State *L_p); static int layoutAddWidget(lua_State *L_p); static int widgetAddText(lua_State *L_p); + static int addWidgetAsStack(lua_State *L_p); static int addWidgetAsTab(lua_State *L_p); static int createCentralWidget(lua_State *L_p); static int createCheckBox(lua_State *L_p); @@ -72,10 +73,12 @@ public: static int createPushButton(lua_State *L_p); static int createRadioButton(lua_State *L_p); static int createSpacerItem(lua_State *L_p); + static int createStackSwitch(lua_State *L_p); static int createTabBar(lua_State *L_p); static int createTextEdit(lua_State *L_p); static int createToolButton(lua_State *L_p); static int createWidgetTab(lua_State *L_p); + static int createWidgetStack(lua_State *L_p); static int isWidgetChecked(lua_State *L_p); static int isWidgetEnabled(lua_State *L_p); static int isWidgetVisible(lua_State *L_p);