make createCentralWidget not necessary

This commit is contained in:
Syping 2019-09-24 12:07:52 +02:00
parent 643b025a83
commit ba59a81d68
3 changed files with 47 additions and 19 deletions

View file

@ -22,8 +22,7 @@ local dialogLineEdit
function main()
mainWindow = createMainWindow()
local mainWidget = createCentralWidget(mainWindow)
local mainLayout = createLayout(VerticalLayout, mainWidget)
local mainLayout = createLayout(VerticalLayout, mainWindow)
local menuBar = createMenuBar(mainWindow)
local menuFile = createMenu("File", menuBar)
@ -36,15 +35,15 @@ function main()
connect(menuEntryAbout, "triggered()", "showAboutBox")
local labelLayout = createLayout(HorizontalLayout, mainLayout)
local appLabel1 = createLabel("LuaEngine greets!", mainWidget)
local appLabel1 = createLabel("LuaEngine greets!", mainWindow)
layoutAddWidget(labelLayout, appLabel1)
local appLabel2 = createLabel("..and not only one time!", mainWidget)
local appLabel2 = createLabel("..and not only one time!", mainWindow)
layoutAddWidget(labelLayout, appLabel2)
local checkBox1 = createCheckBox("Want to check me?", mainWidget)
local checkBox1 = createCheckBox("Want to check me?", mainWindow)
layoutAddWidget(mainLayout, checkBox1)
local pushButton1 = createPushButton("Press me hard please!", mainWidget)
local pushButton1 = createPushButton("Press me hard please!", mainWindow)
layoutAddWidget(mainLayout, pushButton1)
connect(pushButton1, "clicked()", "showDialog")

View file

@ -23,8 +23,7 @@ local textEditor
function main()
mainWindow = createMainWindow("LE Text Editor")
local mainWidget = createCentralWidget(mainWindow)
local mainLayout = createLayout(VerticalLayout, mainWidget)
local mainLayout = createLayout(VerticalLayout, mainWindow)
setLayoutMargins(mainLayout, 0, 0, 0, 0)
local menuBar = createMenuBar(mainWindow)
@ -49,7 +48,7 @@ function main()
setMenuShortcut(menuEntryAbout, "Ctrl+P")
connect(menuEntryAbout, "triggered()", "editorAboutBox")
textEditor = createPlainTextEdit("", mainWidget)
textEditor = createPlainTextEdit("", mainWindow)
layoutAddWidget(mainLayout, textEditor)
setWidgetSize(mainWindow, 650, 450)

View file

@ -513,7 +513,10 @@ int LuaEngineGui::createCheckBox(lua_State *L_p)
labelText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
@ -558,7 +561,10 @@ int LuaEngineGui::createLabel(lua_State *L_p)
labelText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
@ -576,7 +582,10 @@ int LuaEngineGui::createLayout(lua_State *L_p)
QLayout *layoutParent = nullptr;
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
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")) {
@ -616,7 +625,10 @@ int LuaEngineGui::createLineEdit(lua_State *L_p)
editText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
@ -632,18 +644,27 @@ int LuaEngineGui::createMainWindow(lua_State *L_p)
{
QWidget *parent = nullptr;
QString windowTitle = "LuaEngine";
bool centralWidget = true;
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;
centralWidget = getVariant(L_p, 2).toBool();
if (getArgumentCount(L_p) >= 3) {
void *pointer = getPointer(L_p, 3);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
}
}
QMainWindow *mainWindow = new QMainWindow(parent);
mainWindow->setObjectName(nameForPointer(mainWindow));
mainWindow->setWindowTitle(windowTitle);
if (centralWidget) {
QWidget *centralWidget = new QWidget(mainWindow);
centralWidget->setObjectName(nameForPointer(centralWidget));
mainWindow->setCentralWidget(centralWidget);
}
pushPointer(L_p, mainWindow);
return 1;
}
@ -723,7 +744,10 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p)
editText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
@ -743,7 +767,10 @@ int LuaEngineGui::createPushButton(lua_State *L_p)
buttonText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
@ -787,7 +814,10 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
editText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget();
}
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}