mirror of
				https://gitlab.com/Syping/luaengineapp.git
				synced 2025-10-31 02:20:20 +01:00 
			
		
		
		
	add widgets automatic in layout
This commit is contained in:
		
							parent
							
								
									33c32e096d
								
							
						
					
					
						commit
						c51239a3fa
					
				
					 6 changed files with 212 additions and 4 deletions
				
			
		|  | @ -537,6 +537,7 @@ int LuaEngineGui::createCentralWidget(lua_State *L_p) | |||
| 
 | ||||
| int LuaEngineGui::createCheckBox(lua_State *L_p) | ||||
| { | ||||
|     QLayout *layout = nullptr; | ||||
|     QWidget *parent = nullptr; | ||||
|     QString labelText = "LuaEngine"; | ||||
|     if (getArgumentCount(L_p) >= 1) { | ||||
|  | @ -549,11 +550,21 @@ int LuaEngineGui::createCheckBox(lua_State *L_p) | |||
|             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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     QCheckBox *checkBox = new QCheckBox(parent); | ||||
|     checkBox->setObjectName(nameForPointer(checkBox)); | ||||
|     checkBox->setText(labelText); | ||||
|     if (layout != nullptr) { | ||||
|         layout->addWidget(checkBox); | ||||
|     } | ||||
|     pushPointer(L_p, checkBox); | ||||
|     return 1; | ||||
| } | ||||
|  | @ -585,6 +596,7 @@ int LuaEngineGui::createDialog(lua_State *L_p) | |||
| 
 | ||||
| int LuaEngineGui::createLabel(lua_State *L_p) | ||||
| { | ||||
|     QLayout *layout = nullptr; | ||||
|     QWidget *parent = nullptr; | ||||
|     QString labelText = "LuaEngine"; | ||||
|     if (getArgumentCount(L_p) >= 1) { | ||||
|  | @ -597,11 +609,21 @@ int LuaEngineGui::createLabel(lua_State *L_p) | |||
|             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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     QLabel *label = new QLabel(parent); | ||||
|     label->setObjectName(nameForPointer(label)); | ||||
|     label->setText(labelText); | ||||
|     if (layout != nullptr) { | ||||
|         layout->addWidget(label); | ||||
|     } | ||||
|     pushPointer(L_p, label); | ||||
|     return 1; | ||||
| } | ||||
|  | @ -649,6 +671,7 @@ int LuaEngineGui::createLayout(lua_State *L_p) | |||
| 
 | ||||
| int LuaEngineGui::createLineEdit(lua_State *L_p) | ||||
| { | ||||
|     QLayout *layout = nullptr; | ||||
|     QWidget *parent = nullptr; | ||||
|     QString editText = "LuaEngine"; | ||||
|     if (getArgumentCount(L_p) >= 1) { | ||||
|  | @ -661,11 +684,21 @@ int LuaEngineGui::createLineEdit(lua_State *L_p) | |||
|             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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     QLineEdit *lineEdit = new QLineEdit(parent); | ||||
|     lineEdit->setObjectName(nameForPointer(lineEdit)); | ||||
|     lineEdit->setText(editText); | ||||
|     if (layout != nullptr) { | ||||
|         layout->addWidget(lineEdit); | ||||
|     } | ||||
|     pushPointer(L_p, lineEdit); | ||||
|     return 1; | ||||
| } | ||||
|  | @ -772,6 +805,7 @@ int LuaEngineGui::createMenuSeparator(lua_State *L_p) | |||
| 
 | ||||
| int LuaEngineGui::createPlainTextEdit(lua_State *L_p) | ||||
| { | ||||
|     QLayout *layout = nullptr; | ||||
|     QWidget *parent = nullptr; | ||||
|     QString editText = "LuaEngine"; | ||||
|     if (getArgumentCount(L_p) >= 1) { | ||||
|  | @ -784,17 +818,28 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p) | |||
|             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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     QPlainTextEdit *textEdit = new QPlainTextEdit(parent); | ||||
|     textEdit->setObjectName(nameForPointer(textEdit)); | ||||
|     textEdit->setPlainText(editText); | ||||
|     if (layout != nullptr) { | ||||
|         layout->addWidget(textEdit); | ||||
|     } | ||||
|     pushPointer(L_p, textEdit); | ||||
|     return 1; | ||||
| } | ||||
| 
 | ||||
| int LuaEngineGui::createPushButton(lua_State *L_p) | ||||
| { | ||||
|     QLayout *layout = nullptr; | ||||
|     QWidget *parent = nullptr; | ||||
|     QString buttonText = "LuaEngine"; | ||||
|     if (getArgumentCount(L_p) >= 1) { | ||||
|  | @ -807,17 +852,28 @@ int LuaEngineGui::createPushButton(lua_State *L_p) | |||
|             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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     QPushButton *pushButton = new QPushButton(parent); | ||||
|     pushButton->setObjectName(nameForPointer(pushButton)); | ||||
|     pushButton->setText(buttonText); | ||||
|     if (layout != nullptr) { | ||||
|         layout->addWidget(pushButton); | ||||
|     } | ||||
|     pushPointer(L_p, pushButton); | ||||
|     return 1; | ||||
| } | ||||
| 
 | ||||
| int LuaEngineGui::createRadioButton(lua_State *L_p) | ||||
| { | ||||
|     QLayout *layout = nullptr; | ||||
|     QWidget *parent = nullptr; | ||||
|     QString labelText = "LuaEngine"; | ||||
|     if (getArgumentCount(L_p) >= 1) { | ||||
|  | @ -830,11 +886,21 @@ int LuaEngineGui::createRadioButton(lua_State *L_p) | |||
|             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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     QRadioButton *radioButton = new QRadioButton(parent); | ||||
|     radioButton->setObjectName(nameForPointer(radioButton)); | ||||
|     radioButton->setText(labelText); | ||||
|     if (layout != nullptr) { | ||||
|         layout->addWidget(radioButton); | ||||
|     } | ||||
|     pushPointer(L_p, radioButton); | ||||
|     return 1; | ||||
| } | ||||
|  | @ -865,6 +931,7 @@ int LuaEngineGui::createSpacerItem(lua_State *L_p) | |||
| 
 | ||||
| int LuaEngineGui::createTextEdit(lua_State *L_p) | ||||
| { | ||||
|     QLayout *layout = nullptr; | ||||
|     QWidget *parent = nullptr; | ||||
|     QString editText = "LuaEngine"; | ||||
|     if (getArgumentCount(L_p) >= 1) { | ||||
|  | @ -877,11 +944,21 @@ int LuaEngineGui::createTextEdit(lua_State *L_p) | |||
|             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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     QTextEdit *textEdit = new QTextEdit(parent); | ||||
|     textEdit->setObjectName(nameForPointer(textEdit)); | ||||
|     textEdit->setHtml(editText); | ||||
|     if (layout != nullptr) { | ||||
|         layout->addWidget(textEdit); | ||||
|     } | ||||
|     pushPointer(L_p, textEdit); | ||||
|     return 1; | ||||
| } | ||||
|  | @ -972,6 +1049,30 @@ int LuaEngineGui::getWidgetText(lua_State *L_p) | |||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| QWidget* LuaEngineGui::windowForObject(QObject *object) | ||||
| { | ||||
|     bool isWindow = false; | ||||
|     QObject *w_object = object; | ||||
|     while (!isWindow) { | ||||
|         if (w_object->inherits("QDialog") || w_object->inherits("QMainWindow")) { | ||||
|             isWindow = true; | ||||
|         } | ||||
|         else { | ||||
|             QObject *parent = w_object->parent(); | ||||
|             if (parent != NULL) { | ||||
|                 w_object = parent; | ||||
|             } | ||||
|             else { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     if (isWindow) { | ||||
|         return (QWidget*)w_object; | ||||
|     } | ||||
|     return nullptr; | ||||
| } | ||||
| 
 | ||||
| QString LuaEngineGui::nameForPointer(void *pointer) | ||||
| { | ||||
|     QString nameStorage; | ||||
|  |  | |||
|  | @ -67,6 +67,7 @@ public: | |||
| private: | ||||
|     lua_State *L; | ||||
|     static QString nameForPointer(void *pointer); | ||||
|     static QWidget* windowForObject(QObject *object); | ||||
| }; | ||||
| 
 | ||||
| #endif // LUAENGINEGUI_H
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue