add StackSwitch

This commit is contained in:
Syping 2020-05-16 20:00:35 +02:00
parent 9e2b5acca5
commit 4c01f31b04
2 changed files with 53 additions and 0 deletions

View file

@ -17,6 +17,7 @@
#include "LuaEngineGui.h" #include "LuaEngineGui.h"
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QStackedWidget>
#include <QRadioButton> #include <QRadioButton>
#include <QProgressBar> #include <QProgressBar>
#include <QApplication> #include <QApplication>
@ -154,6 +155,11 @@ void LuaEngineGui::pushClass(lua_State *L_p)
// Spacer Item // Spacer Item
pushFunction(L_p, "createSpacerItem", createSpacerItem); pushFunction(L_p, "createSpacerItem", createSpacerItem);
// Stack Switcher
pushFunction(L_p, "createStackSwitch", createStackSwitch);
pushFunction(L_p, "createWidgetStack", createWidgetStack);
pushFunction(L_p, "addWidgetAsStack", addWidgetAsStack);
// Tab Bar // Tab Bar
pushFunction(L_p, "createTabBar", createTabBar); pushFunction(L_p, "createTabBar", createTabBar);
pushFunction(L_p, "createWidgetTab", createWidgetTab); pushFunction(L_p, "createWidgetTab", createWidgetTab);
@ -701,6 +707,18 @@ int LuaEngineGui::widgetAddText(lua_State *L_p)
return 0; 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) int LuaEngineGui::addWidgetAsTab(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 3) { if (getArgumentCount(L_p) >= 3) {
@ -1094,6 +1112,22 @@ int LuaEngineGui::createSpacerItem(lua_State *L_p)
return 0; 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) int LuaEngineGui::createTabBar(lua_State *L_p)
{ {
QLayout *layout = nullptr; QLayout *layout = nullptr;
@ -1152,6 +1186,22 @@ int LuaEngineGui::createToolButton(lua_State *L_p)
return 1; 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) int LuaEngineGui::createWidgetTab(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 2) { if (getArgumentCount(L_p) >= 2) {

View file

@ -54,6 +54,7 @@ public:
static int layoutAddLayout(lua_State *L_p); static int layoutAddLayout(lua_State *L_p);
static int layoutAddWidget(lua_State *L_p); static int layoutAddWidget(lua_State *L_p);
static int widgetAddText(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 addWidgetAsTab(lua_State *L_p);
static int createCentralWidget(lua_State *L_p); static int createCentralWidget(lua_State *L_p);
static int createCheckBox(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 createPushButton(lua_State *L_p);
static int createRadioButton(lua_State *L_p); static int createRadioButton(lua_State *L_p);
static int createSpacerItem(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 createTabBar(lua_State *L_p);
static int createTextEdit(lua_State *L_p); static int createTextEdit(lua_State *L_p);
static int createToolButton(lua_State *L_p); static int createToolButton(lua_State *L_p);
static int createWidgetTab(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 isWidgetChecked(lua_State *L_p);
static int isWidgetEnabled(lua_State *L_p); static int isWidgetEnabled(lua_State *L_p);
static int isWidgetVisible(lua_State *L_p); static int isWidgetVisible(lua_State *L_p);