mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 11:55:29 +01:00
improvements
This commit is contained in:
parent
fb6a449d83
commit
ad1505251d
4 changed files with 246 additions and 62 deletions
|
@ -18,48 +18,35 @@
|
|||
--]]
|
||||
|
||||
local mainWindow
|
||||
local mainLayout
|
||||
local mainWidget
|
||||
local menuBar
|
||||
local menuFile
|
||||
local menuHelp
|
||||
local menuEntryExit
|
||||
local menuEntryAbout
|
||||
local labelLayout
|
||||
local appLabel1
|
||||
local appLabel2
|
||||
local pushButton1
|
||||
local checkBox1
|
||||
local dialogLineEdit
|
||||
|
||||
function main()
|
||||
mainWindow = createMainWindow()
|
||||
mainWidget = createCentralWidget(mainWindow)
|
||||
mainLayout = createLayout(VerticalLayout, mainWidget)
|
||||
local mainWidget = createCentralWidget(mainWindow)
|
||||
local mainLayout = createLayout(VerticalLayout, mainWidget)
|
||||
|
||||
menuBar = createMenuBar(mainWindow)
|
||||
menuFile = createMenu("File", menuBar)
|
||||
menuEntryExit = createMenuEntry("Exit", menuFile)
|
||||
local menuBar = createMenuBar(mainWindow)
|
||||
local menuFile = createMenu("File", menuBar)
|
||||
local menuEntryExit = createMenuEntry("Exit", menuFile)
|
||||
connect(menuEntryExit, "triggered()", "closeWindow")
|
||||
menuHelp = createMenu("Help", menuBar)
|
||||
menuEntryAbout = createMenuEntry("About LuaEngine", menuHelp)
|
||||
local menuHelp = createMenu("Help", menuBar)
|
||||
local menuEntryAbout = createMenuEntry("About LuaEngine", menuHelp)
|
||||
connect(menuEntryAbout, "triggered()", "showAboutBox")
|
||||
|
||||
labelLayout = createLayout(HorizontalLayout, mainLayout)
|
||||
layoutAddLayout(mainLayout, labelLayout)
|
||||
appLabel1 = createLabel("LuaEngine greets!", mainWidget)
|
||||
local labelLayout = createLayout(HorizontalLayout, mainLayout)
|
||||
local appLabel1 = createLabel("LuaEngine greets!", mainWidget)
|
||||
layoutAddWidget(labelLayout, appLabel1)
|
||||
appLabel2 = createLabel("..and not only one time!", mainWidget)
|
||||
local appLabel2 = createLabel("..and not only one time!", mainWidget)
|
||||
layoutAddWidget(labelLayout, appLabel2)
|
||||
|
||||
checkBox1 = createCheckBox("Want to check me?", mainWidget)
|
||||
local checkBox1 = createCheckBox("Want to check me?", mainWidget)
|
||||
layoutAddWidget(mainLayout, checkBox1)
|
||||
|
||||
pushButton1 = createPushButton("Press me hard please!", mainWidget)
|
||||
local pushButton1 = createPushButton("Press me hard please!", mainWidget)
|
||||
layoutAddWidget(mainLayout, pushButton1)
|
||||
connect(pushButton1, "clicked()", "showHarderBox")
|
||||
connect(pushButton1, "clicked()", "showDialog")
|
||||
|
||||
showWidget(mainWindow, ShowNormal)
|
||||
|
||||
return GuiExecuted
|
||||
end
|
||||
|
||||
|
@ -71,8 +58,25 @@ function showAboutBox(menuEntry)
|
|||
showMessageBox(InfoMessageBox, "You triggered the About Box!", "LuaEngine", mainWindow)
|
||||
end
|
||||
|
||||
function showHarderBox(pushButton)
|
||||
showMessageBox(InfoMessageBox, "Harder pls!", "LuaEngine", mainWindow)
|
||||
function showDialog(pushButton)
|
||||
local dialog = createDialog("LuaEngine", mainWindow)
|
||||
local dialogLayout = createLayout(VerticalLayout, dialog)
|
||||
local dialogLabel = createLabel("Yes, you have open a Dialog!", dialog)
|
||||
layoutAddWidget(dialogLayout, dialogLabel)
|
||||
dialogLineEdit = createLineEdit("", dialog)
|
||||
layoutAddWidget(dialogLayout, dialogLineEdit)
|
||||
local buttonLayout = createLayout(HorizontalLayout, dialogLayout)
|
||||
createSpacerItem(SizePolicyExpanding, SizePolicyMinimum, buttonLayout)
|
||||
local dialogButton = createPushButton("Close", dialog)
|
||||
layoutAddWidget(buttonLayout, dialogButton)
|
||||
connect(dialogButton, "clicked()", "closeDialog")
|
||||
executeWidget(dialog)
|
||||
delete(dialog, DeleteInstant)
|
||||
end
|
||||
|
||||
function closeDialog(pushButton)
|
||||
disconnect(pushButton, "clicked()")
|
||||
closeWidget(getParent(pushButton))
|
||||
end
|
||||
|
||||
function testMessageBoxes()
|
||||
|
|
|
@ -75,7 +75,6 @@ QLabel {
|
|||
border: 0px;
|
||||
}
|
||||
QLineEdit {
|
||||
font-size: 10pt;
|
||||
background-color: rgb(215, 120, 50);
|
||||
color: rgb(255, 255, 255);
|
||||
selection-background-color: rgb(255, 255, 255);
|
||||
|
|
|
@ -22,11 +22,16 @@
|
|||
#include <QMetaObject>
|
||||
#include <QMetaMethod>
|
||||
#include <QTextStream>
|
||||
#include <QSpacerItem>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QSizePolicy>
|
||||
#include <QEventLoop>
|
||||
#include <QLineEdit>
|
||||
#include <QCheckBox>
|
||||
#include <QMenuBar>
|
||||
#include <QProcess>
|
||||
#include <QWindow>
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
#include <QTimer>
|
||||
|
@ -52,6 +57,7 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
|
||||
// Widget
|
||||
pushFunction(L_p, "closeWidget", closeWidget);
|
||||
pushFunction(L_p, "executeWidget", executeWidget);
|
||||
pushFunction(L_p, "showWidget", showWidget);
|
||||
pushFunction(L_p, "setWidgetLayout", setWidgetLayout);
|
||||
pushVariant(L_p, "ShowCurrent", 0);
|
||||
|
@ -63,6 +69,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
// Check Box
|
||||
pushFunction(L_p, "createCheckBox", createCheckBox);
|
||||
|
||||
// Dialog
|
||||
pushFunction(L_p, "createDialog", createDialog);
|
||||
|
||||
// Label
|
||||
pushFunction(L_p, "createLabel", createLabel);
|
||||
|
||||
|
@ -73,6 +82,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
pushVariant(L_p, "HorizontalLayout", 0);
|
||||
pushVariant(L_p, "VerticalLayout", 1);
|
||||
|
||||
// Line Edit
|
||||
pushFunction(L_p, "createLineEdit", createLineEdit);
|
||||
|
||||
// Main Window
|
||||
pushFunction(L_p, "createMainWindow", createMainWindow);
|
||||
pushFunction(L_p, "createCentralWidget", createCentralWidget);
|
||||
|
@ -84,6 +96,20 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
|
||||
// Push Button
|
||||
pushFunction(L_p, "createPushButton", createPushButton);
|
||||
|
||||
// Spacer Item
|
||||
pushFunction(L_p, "createSpacerItem", createSpacerItem);
|
||||
|
||||
// Size Policy
|
||||
pushVariant(L_p, "SizePolicyFixed", (int)QSizePolicy::Fixed);
|
||||
pushVariant(L_p, "SizePolicyMinimum", (int)QSizePolicy::Minimum);
|
||||
pushVariant(L_p, "SizePolicyMaximum", (int)QSizePolicy::Maximum);
|
||||
pushVariant(L_p, "SizePolicyPreferred", (int)QSizePolicy::Preferred);
|
||||
pushVariant(L_p, "SizePolicyExpanding", (int)QSizePolicy::Expanding);
|
||||
pushVariant(L_p, "SizePolicyIgnored", (int)QSizePolicy::Ignored);
|
||||
|
||||
// Object functions
|
||||
pushFunction(L_p, "getParent", getParent);
|
||||
}
|
||||
|
||||
void LuaEngineGui::pushClass(LuaEngine *luaEngine)
|
||||
|
@ -149,31 +175,70 @@ int LuaEngineGui::closeWidget(lua_State *L_p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::executeWidget(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
QVariant isFixed = ((QObject*)pointer)->property("isFixed");
|
||||
if (isFixed.type() == QVariant::Bool && isFixed.toBool()) {
|
||||
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
|
||||
((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint());
|
||||
}
|
||||
else {
|
||||
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
|
||||
((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
}
|
||||
if (((QObject*)pointer)->inherits("QDialog")) {
|
||||
((QDialog*)pointer)->exec();
|
||||
}
|
||||
else {
|
||||
((QWidget*)pointer)->show();
|
||||
QEventLoop executeLoop;
|
||||
while (((QWidget*)pointer)->isVisible()) {
|
||||
QTimer::singleShot(100, &executeLoop, SLOT(quit()));
|
||||
executeLoop.exec();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::showWidget(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
QWidget *widget = (QWidget*)pointer;
|
||||
int showMode = 0;
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
showMode = getVariant(L_p, 2).toInt();
|
||||
}
|
||||
QVariant isFixed = ((QObject*)pointer)->property("isFixed");
|
||||
if (isFixed.type() == QVariant::Bool && isFixed.toBool()) {
|
||||
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
|
||||
((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint());
|
||||
}
|
||||
else {
|
||||
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
|
||||
((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
}
|
||||
switch (showMode) {
|
||||
case 1:
|
||||
widget->showNormal();
|
||||
((QWidget*)pointer)->showNormal();
|
||||
break;
|
||||
case 2:
|
||||
widget->showMinimized();
|
||||
((QWidget*)pointer)->showMinimized();
|
||||
break;
|
||||
case 3:
|
||||
widget->showMaximized();
|
||||
((QWidget*)pointer)->showMaximized();
|
||||
break;
|
||||
case 4:
|
||||
widget->showFullScreen();
|
||||
((QWidget*)pointer)->showFullScreen();
|
||||
break;
|
||||
default:
|
||||
widget->show();
|
||||
((QWidget*)pointer)->show();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -181,6 +246,45 @@ int LuaEngineGui::showWidget(lua_State *L_p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::setWidgetFixedSize(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
bool isFixed = true;
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
isFixed = getVariant(L_p, 2).toBool();
|
||||
}
|
||||
((QObject*)pointer)->setProperty("isFixed", isFixed);
|
||||
if (isFixed && ((QWidget*)pointer)->isVisible()) {
|
||||
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
|
||||
((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint());
|
||||
}
|
||||
else if (((QWidget*)pointer)->isVisible()) {
|
||||
((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint());
|
||||
((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::setWidgetLayout(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
QWidget *widget = (QWidget*)pointer;
|
||||
void *l_pointer = getPointer(L_p, 2);
|
||||
if (l_pointer!= NULL && ((QObject*)l_pointer)->inherits("QLayout")) {
|
||||
widget->setLayout((QLayout*)l_pointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::layoutAddLayout(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
|
@ -254,6 +358,28 @@ int LuaEngineGui::createCheckBox(lua_State *L_p)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineGui::createDialog(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString windowTitle = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
windowTitle = 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QDialog *dialog = new QDialog(parent);
|
||||
dialog->setObjectName(nameForPointer(dialog));
|
||||
dialog->setWindowTitle(windowTitle);
|
||||
pushPointer(L_p, dialog);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineGui::createLabel(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
|
@ -277,10 +403,50 @@ int LuaEngineGui::createLabel(lua_State *L_p)
|
|||
}
|
||||
|
||||
int LuaEngineGui::createLayout(lua_State *L_p)
|
||||
{
|
||||
QWidget *parent = nullptr;
|
||||
QLayout *layoutParent = nullptr;
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
layoutParent = (QLayout*)pointer;
|
||||
}
|
||||
}
|
||||
void *layout;
|
||||
int layoutType = 0;
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
layoutType = getVariant(L_p, 1).toInt();
|
||||
}
|
||||
switch (layoutType) {
|
||||
case 0:
|
||||
layout = new QHBoxLayout(parent);
|
||||
break;
|
||||
default:
|
||||
layout = new QVBoxLayout(parent);
|
||||
}
|
||||
((QObject*)layout)->setObjectName(nameForPointer(layout));
|
||||
if (layoutParent != nullptr) {
|
||||
if (layoutParent->inherits("QVBoxLayout")) {
|
||||
((QVBoxLayout*)layoutParent)->addLayout((QLayout*)layout);
|
||||
}
|
||||
else if (layoutParent->inherits("QHBoxLayout")) {
|
||||
((QHBoxLayout*)layoutParent)->addLayout((QLayout*)layout);
|
||||
}
|
||||
}
|
||||
pushPointer(L_p, layout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineGui::createLineEdit(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString editText = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
editText = 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")) {
|
||||
|
@ -289,22 +455,10 @@ int LuaEngineGui::createLayout(lua_State *L_p)
|
|||
}
|
||||
}
|
||||
}
|
||||
int layoutType = args.at(0).toInt();
|
||||
switch (layoutType) {
|
||||
case 0:
|
||||
{
|
||||
QHBoxLayout *layout = new QHBoxLayout(parent);
|
||||
layout->setObjectName(nameForPointer(layout));
|
||||
pushPointer(L_p, layout);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(parent);
|
||||
layout->setObjectName(nameForPointer(layout));
|
||||
pushPointer(L_p, layout);
|
||||
}
|
||||
}
|
||||
QLineEdit *lineEdit = new QLineEdit(parent);
|
||||
lineEdit->setObjectName(nameForPointer(lineEdit));
|
||||
lineEdit->setText(editText);
|
||||
pushPointer(L_p, lineEdit);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -406,16 +560,37 @@ int LuaEngineGui::createPushButton(lua_State *L_p)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineGui::setWidgetLayout(lua_State *L_p)
|
||||
int LuaEngineGui::createSpacerItem(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
QWidget *widget = (QWidget*)pointer;
|
||||
void *l_pointer = getPointer(L_p, 2);
|
||||
if (l_pointer!= NULL && ((QObject*)l_pointer)->inherits("QLayout")) {
|
||||
widget->setLayout((QLayout*)l_pointer);
|
||||
if (getArgumentCount(L_p) >= 3) {
|
||||
void *pointer = getPointer(L_p, 3);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
if (((QObject*)pointer)->inherits("QVBoxLayout")) {
|
||||
QSpacerItem *spacerItem = new QSpacerItem(0, 0, (QSizePolicy::Policy)getVariant(L_p, 1).toInt(), (QSizePolicy::Policy)getVariant(L_p, 2).toInt());
|
||||
QVBoxLayout *layout = (QVBoxLayout*)pointer;
|
||||
layout->addSpacerItem(spacerItem);
|
||||
pushPointer(L_p, spacerItem);
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QHBoxLayout")) {
|
||||
QSpacerItem *spacerItem = new QSpacerItem(0, 0, (QSizePolicy::Policy)getVariant(L_p, 1).toInt(), (QSizePolicy::Policy)getVariant(L_p, 2).toInt());
|
||||
QHBoxLayout *layout = (QHBoxLayout*)pointer;
|
||||
layout->addSpacerItem(spacerItem);
|
||||
pushPointer(L_p, spacerItem);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::getParent(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL) {
|
||||
pushPointer(L_p, ((QObject*)pointer)->parent());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -424,6 +599,6 @@ int LuaEngineGui::setWidgetLayout(lua_State *L_p)
|
|||
QString LuaEngineGui::nameForPointer(void *pointer)
|
||||
{
|
||||
QString nameStorage;
|
||||
QTextStream(&nameStorage) << "LuaEngineGui_" << pointer;
|
||||
QTextStream(&nameStorage) << "LuaEngineGui" << pointer;
|
||||
return nameStorage;
|
||||
}
|
||||
|
|
|
@ -32,19 +32,25 @@ public:
|
|||
static void pushClass(LuaEngine *luaEngine);
|
||||
static int showMessageBox(lua_State *L_p);
|
||||
static int closeWidget(lua_State *L_p);
|
||||
static int executeWidget(lua_State *L_p);
|
||||
static int showWidget(lua_State *L_p);
|
||||
static int setWidgetFixedSize(lua_State *L_p);
|
||||
static int setWidgetLayout(lua_State *L_p);
|
||||
static int layoutAddLayout(lua_State *L_p);
|
||||
static int layoutAddWidget(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);
|
||||
static int createLabel(lua_State *L_p);
|
||||
static int createLayout(lua_State *L_p);
|
||||
static int createLineEdit(lua_State *L_p);
|
||||
static int createMainWindow(lua_State *L_p);
|
||||
static int createMenu(lua_State *L_p);
|
||||
static int createMenuBar(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 createSpacerItem(lua_State *L_p);
|
||||
static int getParent(lua_State *L_p);
|
||||
|
||||
private:
|
||||
lua_State *L;
|
||||
|
|
Loading…
Reference in a new issue