basic tab functionality

This commit is contained in:
Syping 2020-05-15 13:29:47 +02:00
parent 3a6780a82f
commit f67f3c0365
2 changed files with 66 additions and 0 deletions

View file

@ -32,6 +32,7 @@
#include <QVBoxLayout>
#include <QFileDialog>
#include <QSizePolicy>
#include <QTabWidget>
#include <QEventLoop>
#include <QTextEdit>
#include <QLineEdit>
@ -150,6 +151,11 @@ void LuaEngineGui::pushClass(lua_State *L_p)
// Spacer Item
pushFunction(L_p, "createSpacerItem", createSpacerItem);
// Tab Bar
pushFunction(L_p, "createTabBar", createTabBar);
pushFunction(L_p, "createWidgetTab", createWidgetTab);
pushFunction(L_p, "addWidgetAsTab", addWidgetAsTab);
// Text Edit
pushFunction(L_p, "createTextEdit", createTextEdit);
@ -679,6 +685,18 @@ int LuaEngineGui::widgetAddText(lua_State *L_p)
return 0;
}
int LuaEngineGui::addWidgetAsTab(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 3) {
void *w_pointer = getPointer(L_p, 1);
void *t_pointer = getPointer(L_p, 3);
if (w_pointer != NULL && t_pointer != NULL && ((QObject*)w_pointer)->inherits("QWidget") && ((QObject*)t_pointer)->inherits("QTabWidget")) {
((QTabWidget*)t_pointer)->addTab(((QWidget*)w_pointer), getVariant(L_p, 2).toString());
}
}
return 0;
}
int LuaEngineGui::createCentralWidget(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
@ -1164,6 +1182,35 @@ int LuaEngineGui::createSpacerItem(lua_State *L_p)
return 0;
}
int LuaEngineGui::createTabBar(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
QWidget *widget = windowForObject((QObject*)pointer);
if (widget != nullptr) {
layout = (QLayout*)pointer;
parent = widget;
}
}
}
QTabWidget *tabWidget = new QTabWidget(parent);
tabWidget->setObjectName(nameForPointer(tabWidget));
if (layout != nullptr) {
layout->addWidget(tabWidget);
}
pushPointer(L_p, tabWidget);
return 1;
}
int LuaEngineGui::createTextEdit(lua_State *L_p)
{
QLayout *layout = nullptr;
@ -1232,6 +1279,22 @@ int LuaEngineGui::createToolButton(lua_State *L_p)
return 1;
}
int LuaEngineGui::createWidgetTab(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QTabWidget")) {
QTabWidget *tabWidget = (QTabWidget*)pointer;
QWidget *widgetTab = new QWidget(tabWidget);
widgetTab->setObjectName(nameForPointer(widgetTab));
tabWidget->addTab(widgetTab, getVariant(L_p, 1).toString());
pushPointer(L_p, widgetTab);
return 1;
}
}
return 0;
}
int LuaEngineGui::isWidgetChecked(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {

View file

@ -52,6 +52,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 addWidgetAsTab(lua_State *L_p);
static int createCentralWidget(lua_State *L_p);
static int createCheckBox(lua_State *L_p);
static int createDialog(lua_State *L_p);
@ -69,8 +70,10 @@ public:
static int createPushButton(lua_State *L_p);
static int createRadioButton(lua_State *L_p);
static int createSpacerItem(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 isWidgetChecked(lua_State *L_p);
static int getWidgetText(lua_State *L_p);
static int getWindow(lua_State *L_p);