From 97c58b72bda9731d24cc78725103a5711068519c Mon Sep 17 00:00:00 2001 From: Syping Date: Wed, 25 Sep 2019 16:18:23 +0200 Subject: [PATCH] add progressBar, setWidgetMaximum, setWidgetMinimum --- src/luaenginegui/luaengine/LuaEngineGui.cpp | 153 ++++++++++++++++---- src/luaenginegui/luaengine/LuaEngineGui.h | 4 + 2 files changed, 128 insertions(+), 29 deletions(-) diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index e697f8b..d56e608 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -18,6 +18,7 @@ #include "LuaEngineGui.h" #include #include +#include #include #include #include @@ -77,9 +78,12 @@ void LuaEngineGui::pushClass(lua_State *L_p) pushFunction(L_p, "setWidgetEnabled", setWidgetEnabled); pushFunction(L_p, "setWidgetFixed", setWidgetFixed); pushFunction(L_p, "setWidgetLayout", setWidgetLayout); - pushFunction(L_p, "setWidgetText", setWidgetText); + pushFunction(L_p, "setWidgetMaximum", setWidgetMaximum); + pushFunction(L_p, "setWidgetMinimum", setWidgetMinimum); pushFunction(L_p, "setWidgetReadOnly", setWidgetReadOnly); pushFunction(L_p, "setWidgetSize", setWidgetSize); + pushFunction(L_p, "setWidgetText", setWidgetText); + pushFunction(L_p, "setWidgetValue", setWidgetValue); pushVariant(L_p, "ShowCurrent", 0); pushVariant(L_p, "ShowNormal", 1); pushVariant(L_p, "ShowDefault", 2); @@ -121,6 +125,9 @@ void LuaEngineGui::pushClass(lua_State *L_p) // Plain Text Edit pushFunction(L_p, "createPlainTextEdit", createPlainTextEdit); + // Progress Bar + pushFunction(L_p, "createProgressBar", createProgressBar); + // Push Button pushFunction(L_p, "createPushButton", createPushButton); @@ -411,30 +418,6 @@ int LuaEngineGui::setWidgetEnabled(lua_State *L_p) return 0; } -int LuaEngineGui::setWidgetReadOnly(lua_State *L_p) -{ - if (getArgumentCount(L_p) >= 1) { - void *pointer = getPointer(L_p, 1); - if (pointer != NULL) { - bool isReadOnly = true; - if (getArgumentCount(L_p) >= 2) { - isReadOnly = getVariant(L_p, 2).toBool(); - } - if (((QObject*)pointer)->inherits("QPlainTextEdit")) { - ((QPlainTextEdit*)pointer)->setReadOnly(isReadOnly); - } - else if (((QObject*)pointer)->inherits("QTextEdit")) { - ((QTextEdit*)pointer)->setReadOnly(isReadOnly); - } - else if (((QObject*)pointer)->inherits("QLineEdit")) { - ((QLineEdit*)pointer)->setReadOnly(isReadOnly); - } - return 0; - } - } - return 0; -} - int LuaEngineGui::setWidgetFixed(lua_State *L_p) { if (getArgumentCount(L_p) >= 1) { @@ -479,6 +462,56 @@ int LuaEngineGui::setWidgetLayout(lua_State *L_p) return 0; } +int LuaEngineGui::setWidgetMaximum(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QProgressBar")) { + ((QProgressBar*)pointer)->setMaximum(getVariant(L_p, 2).toInt()); + } + } + } + return 0; +} + +int LuaEngineGui::setWidgetMinimum(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QProgressBar")) { + ((QProgressBar*)pointer)->setMinimum(getVariant(L_p, 2).toInt()); + } + } + } + return 0; +} + +int LuaEngineGui::setWidgetReadOnly(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 1) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + bool isReadOnly = true; + if (getArgumentCount(L_p) >= 2) { + isReadOnly = getVariant(L_p, 2).toBool(); + } + if (((QObject*)pointer)->inherits("QPlainTextEdit")) { + ((QPlainTextEdit*)pointer)->setReadOnly(isReadOnly); + } + else if (((QObject*)pointer)->inherits("QTextEdit")) { + ((QTextEdit*)pointer)->setReadOnly(isReadOnly); + } + else if (((QObject*)pointer)->inherits("QLineEdit")) { + ((QLineEdit*)pointer)->setReadOnly(isReadOnly); + } + return 0; + } + } + return 0; +} + int LuaEngineGui::setWidgetSize(lua_State *L_p) { if (getArgumentCount(L_p) >= 3) { @@ -518,6 +551,9 @@ int LuaEngineGui::setWidgetText(lua_State *L_p) else if (((QObject*)pointer)->inherits("QPlainTextEdit")) { ((QPlainTextEdit*)pointer)->setPlainText(getVariant(L_p, 2).toString()); } + else if (((QObject*)pointer)->inherits("QProgressBar")) { + ((QProgressBar*)pointer)->setFormat(getVariant(L_p, 2).toString()); + } else if (((QObject*)pointer)->inherits("QPushButton")) { ((QPushButton*)pointer)->setText(getVariant(L_p, 2).toString()); } @@ -538,6 +574,19 @@ int LuaEngineGui::setWidgetText(lua_State *L_p) return 0; } +int LuaEngineGui::setWidgetValue(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QProgressBar")) { + ((QProgressBar*)pointer)->setValue(getVariant(L_p, 2).toInt()); + } + } + } + return 0; +} + int LuaEngineGui::layoutAddLayout(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { @@ -891,6 +940,48 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p) return 1; } +int LuaEngineGui::createProgressBar(lua_State *L_p) +{ + QLayout *layout = nullptr; + QWidget *parent = nullptr; + int value = 0; + int minValue = 0; + int maxValue = 100; + if (getArgumentCount(L_p) >= 1) { + value = getVariant(L_p, 1).toInt(); + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 2); + 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; + } + } + if (getArgumentCount(L_p) >= 4) { + minValue = getVariant(L_p, 3).toInt(); + maxValue = getVariant(L_p, 4).toInt(); + } + } + } + QProgressBar *progressBar = new QProgressBar(parent); + progressBar->setObjectName(nameForPointer(progressBar)); + progressBar->setMinimum(minValue); + progressBar->setMaximum(maxValue); + progressBar->setValue(value); + if (layout != nullptr) { + layout->addWidget(progressBar); + } + pushPointer(L_p, progressBar); + return 1; +} + int LuaEngineGui::createPushButton(lua_State *L_p) { QLayout *layout = nullptr; @@ -1116,14 +1207,18 @@ int LuaEngineGui::getWidgetText(lua_State *L_p) pushVariant(L_p, ((QLineEdit*)pointer)->text()); return 1; } - else if (((QObject*)pointer)->inherits("QPushButton")) { - pushVariant(L_p, ((QPushButton*)pointer)->text()); - return 1; - } else if (((QObject*)pointer)->inherits("QPlainTextEdit")) { pushVariant(L_p, ((QPlainTextEdit*)pointer)->toPlainText()); return 1; } + else if (((QObject*)pointer)->inherits("QProgressBar")) { + pushVariant(L_p, ((QProgressBar*)pointer)->format()); + return 1; + } + else if (((QObject*)pointer)->inherits("QPushButton")) { + pushVariant(L_p, ((QPushButton*)pointer)->text()); + return 1; + } else if (((QObject*)pointer)->inherits("QRadioButton")) { pushVariant(L_p, ((QRadioButton*)pointer)->text()); return 1; diff --git a/src/luaenginegui/luaengine/LuaEngineGui.h b/src/luaenginegui/luaengine/LuaEngineGui.h index ff89574..b9fd380 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.h +++ b/src/luaenginegui/luaengine/LuaEngineGui.h @@ -41,9 +41,12 @@ public: static int setWidgetEnabled(lua_State *L_p); static int setWidgetFixed(lua_State *L_p); static int setWidgetLayout(lua_State *L_p); + static int setWidgetMaximum(lua_State *L_p); + static int setWidgetMinimum(lua_State *L_p); static int setWidgetReadOnly(lua_State *L_p); static int setWidgetSize(lua_State *L_p); static int setWidgetText(lua_State *L_p); + static int setWidgetValue(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); @@ -58,6 +61,7 @@ public: static int createMenuEntry(lua_State *L_p); static int createMenuSeparator(lua_State *L_p); static int createPlainTextEdit(lua_State *L_p); + static int createProgressBar(lua_State *L_p); static int createPushButton(lua_State *L_p); static int createRadioButton(lua_State *L_p); static int createSpacerItem(lua_State *L_p);