mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 11:55:29 +01:00
layout + button
This commit is contained in:
parent
d277e0e8c5
commit
ba207a1c8f
3 changed files with 83 additions and 19 deletions
|
@ -25,8 +25,10 @@ local menuFile
|
||||||
local menuHelp
|
local menuHelp
|
||||||
local menuEntryExit
|
local menuEntryExit
|
||||||
local menuEntryAbout
|
local menuEntryAbout
|
||||||
|
local labelLayout
|
||||||
local appLabel1
|
local appLabel1
|
||||||
local appLabel2
|
local appLabel2
|
||||||
|
local pushButton1
|
||||||
|
|
||||||
function main()
|
function main()
|
||||||
mainWindow = createMainWindow()
|
mainWindow = createMainWindow()
|
||||||
|
@ -43,11 +45,19 @@ function main()
|
||||||
|
|
||||||
mainLayout = createLayout(VerticalLayout, mainWidget)
|
mainLayout = createLayout(VerticalLayout, mainWidget)
|
||||||
|
|
||||||
|
labelLayout = createLayout(HorizontalLayout, mainLayout)
|
||||||
|
layoutAddLayout(mainLayout, labelLayout)
|
||||||
|
|
||||||
appLabel1 = createLabel("LuaEngine greets!", mainWidget)
|
appLabel1 = createLabel("LuaEngine greets!", mainWidget)
|
||||||
layoutAddWidget(mainLayout, appLabel1)
|
layoutAddWidget(labelLayout, appLabel1)
|
||||||
|
|
||||||
appLabel2 = createLabel("..and not only one time!", mainWidget)
|
appLabel2 = createLabel("..and not only one time!", mainWidget)
|
||||||
layoutAddWidget(mainLayout, appLabel2)
|
layoutAddWidget(labelLayout, appLabel2)
|
||||||
|
|
||||||
|
pushButton1 = createPushButton("Press me hard please!", mainWidget)
|
||||||
|
layoutAddWidget(mainLayout, pushButton1)
|
||||||
|
|
||||||
|
connect(pushButton1, "clicked()", "showHarderBox")
|
||||||
|
|
||||||
showWidget(mainWindow, ShowNormal)
|
showWidget(mainWindow, ShowNormal)
|
||||||
|
|
||||||
|
@ -62,6 +72,10 @@ function showAboutBox(menuEntry)
|
||||||
showMessageBox(InfoMessageBox, "You triggered the About Box!", "LuaEngine", mainWindow)
|
showMessageBox(InfoMessageBox, "You triggered the About Box!", "LuaEngine", mainWindow)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function showHarderBox(pushButton)
|
||||||
|
showMessageBox(InfoMessageBox, "Harder pls!", "LuaEngine", mainWindow)
|
||||||
|
end
|
||||||
|
|
||||||
function testMessageBoxes()
|
function testMessageBoxes()
|
||||||
showMessageBox(InfoMessageBox, "LuaEngine Test")
|
showMessageBox(InfoMessageBox, "LuaEngine Test")
|
||||||
local returnCode = showMessageBox(QuestionMessageBox, "Do you press Yes or No?")
|
local returnCode = showMessageBox(QuestionMessageBox, "Do you press Yes or No?")
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "LuaEngineGui.h"
|
#include "LuaEngineGui.h"
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QPushButton>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
|
@ -61,8 +62,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
||||||
// Label
|
// Label
|
||||||
pushFunction(L_p, "createLabel", createLabel);
|
pushFunction(L_p, "createLabel", createLabel);
|
||||||
|
|
||||||
// Label
|
// Layout
|
||||||
pushFunction(L_p, "createLayout", createLayout);
|
pushFunction(L_p, "createLayout", createLayout);
|
||||||
|
pushFunction(L_p, "layoutAddLayout", layoutAddLayout);
|
||||||
pushFunction(L_p, "layoutAddWidget", layoutAddWidget);
|
pushFunction(L_p, "layoutAddWidget", layoutAddWidget);
|
||||||
pushVariant(L_p, "HorizontalLayout", 0);
|
pushVariant(L_p, "HorizontalLayout", 0);
|
||||||
pushVariant(L_p, "VerticalLayout", 1);
|
pushVariant(L_p, "VerticalLayout", 1);
|
||||||
|
@ -75,6 +77,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
||||||
pushFunction(L_p, "createMenu", createMenu);
|
pushFunction(L_p, "createMenu", createMenu);
|
||||||
pushFunction(L_p, "createMenuBar", createMenuBar);
|
pushFunction(L_p, "createMenuBar", createMenuBar);
|
||||||
pushFunction(L_p, "createMenuEntry", createMenuEntry);
|
pushFunction(L_p, "createMenuEntry", createMenuEntry);
|
||||||
|
|
||||||
|
// Push Button
|
||||||
|
pushFunction(L_p, "createPushButton", createPushButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaEngineGui::pushClass(LuaEngine *luaEngine)
|
void LuaEngineGui::pushClass(LuaEngine *luaEngine)
|
||||||
|
@ -172,6 +177,27 @@ int LuaEngineGui::showWidget(lua_State *L_p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaEngineGui::layoutAddLayout(lua_State *L_p)
|
||||||
|
{
|
||||||
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
|
void *pointer = getPointer(L_p, 1);
|
||||||
|
if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||||
|
void *l_pointer = getPointer(L_p, 2);
|
||||||
|
if (l_pointer!= NULL && ((QObject*)l_pointer)->inherits("QLayout")) {
|
||||||
|
if (((QObject*)pointer)->inherits("QVBoxLayout")) {
|
||||||
|
QVBoxLayout *layout = (QVBoxLayout*)pointer;
|
||||||
|
layout->addLayout((QLayout*)l_pointer);
|
||||||
|
}
|
||||||
|
else if (((QObject*)pointer)->inherits("QHBoxLayout")) {
|
||||||
|
QHBoxLayout *layout = (QHBoxLayout*)pointer;
|
||||||
|
layout->addLayout((QLayout*)l_pointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaEngineGui::layoutAddWidget(lua_State *L_p)
|
int LuaEngineGui::layoutAddWidget(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
|
@ -187,6 +213,21 @@ int LuaEngineGui::layoutAddWidget(lua_State *L_p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaEngineGui::createCentralWidget(lua_State *L_p)
|
||||||
|
{
|
||||||
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
|
void *pointer = getPointer(L_p, 1);
|
||||||
|
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||||
|
QWidget *centralWidget = new QWidget((QWidget*)pointer);
|
||||||
|
centralWidget->setObjectName(nameForPointer(centralWidget));
|
||||||
|
((QMainWindow*)pointer)->setCentralWidget(centralWidget);
|
||||||
|
pushPointer(L_p, centralWidget);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaEngineGui::createLabel(lua_State *L_p)
|
int LuaEngineGui::createLabel(lua_State *L_p)
|
||||||
{
|
{
|
||||||
QVariantList args = getArguments(L_p);
|
QVariantList args = getArguments(L_p);
|
||||||
|
@ -263,21 +304,6 @@ int LuaEngineGui::createMainWindow(lua_State *L_p)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaEngineGui::createCentralWidget(lua_State *L_p)
|
|
||||||
{
|
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
|
||||||
void *pointer = getPointer(L_p, 1);
|
|
||||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
|
||||||
QWidget *centralWidget = new QWidget((QWidget*)pointer);
|
|
||||||
centralWidget->setObjectName(nameForPointer(centralWidget));
|
|
||||||
((QMainWindow*)pointer)->setCentralWidget(centralWidget);
|
|
||||||
pushPointer(L_p, centralWidget);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int LuaEngineGui::createMenu(lua_State *L_p)
|
int LuaEngineGui::createMenu(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
|
@ -332,6 +358,28 @@ int LuaEngineGui::createMenuEntry(lua_State *L_p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaEngineGui::createPushButton(lua_State *L_p)
|
||||||
|
{
|
||||||
|
QVariantList args = getArguments(L_p);
|
||||||
|
QWidget *parent = nullptr;
|
||||||
|
QString buttonText = "LuaEngine";
|
||||||
|
if (args.length() >= 1) {
|
||||||
|
buttonText = args.at(0).toString();
|
||||||
|
if (args.length() >= 2) {
|
||||||
|
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||||
|
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||||
|
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QPushButton *pushButton = new QPushButton(parent);
|
||||||
|
pushButton->setObjectName(nameForPointer(pushButton));
|
||||||
|
pushButton->setText(buttonText);
|
||||||
|
pushPointer(L_p, pushButton);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaEngineGui::setWidgetLayout(lua_State *L_p)
|
int LuaEngineGui::setWidgetLayout(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
|
|
|
@ -33,14 +33,16 @@ public:
|
||||||
static int showMessageBox(lua_State *L_p);
|
static int showMessageBox(lua_State *L_p);
|
||||||
static int closeWidget(lua_State *L_p);
|
static int closeWidget(lua_State *L_p);
|
||||||
static int showWidget(lua_State *L_p);
|
static int showWidget(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 createCentralWidget(lua_State *L_p);
|
||||||
static int createLabel(lua_State *L_p);
|
static int createLabel(lua_State *L_p);
|
||||||
static int createLayout(lua_State *L_p);
|
static int createLayout(lua_State *L_p);
|
||||||
static int createMainWindow(lua_State *L_p);
|
static int createMainWindow(lua_State *L_p);
|
||||||
static int createCentralWidget(lua_State *L_p);
|
|
||||||
static int createMenu(lua_State *L_p);
|
static int createMenu(lua_State *L_p);
|
||||||
static int createMenuBar(lua_State *L_p);
|
static int createMenuBar(lua_State *L_p);
|
||||||
static int createMenuEntry(lua_State *L_p);
|
static int createMenuEntry(lua_State *L_p);
|
||||||
|
static int createPushButton(lua_State *L_p);
|
||||||
static int setWidgetLayout(lua_State *L_p);
|
static int setWidgetLayout(lua_State *L_p);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue