From a22f961ac87f4fba5b61bd5ec77a5f0205078cce Mon Sep 17 00:00:00 2001 From: Syping Date: Wed, 25 Sep 2019 15:56:30 +0200 Subject: [PATCH] add readOnly --- src/luaenginegui/luaengine/LuaEngineGui.cpp | 25 +++++++++++++++++++++ src/luaenginegui/luaengine/LuaEngineGui.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index 5fc6bb4..e697f8b 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -78,6 +78,7 @@ void LuaEngineGui::pushClass(lua_State *L_p) pushFunction(L_p, "setWidgetFixed", setWidgetFixed); pushFunction(L_p, "setWidgetLayout", setWidgetLayout); pushFunction(L_p, "setWidgetText", setWidgetText); + pushFunction(L_p, "setWidgetReadOnly", setWidgetReadOnly); pushFunction(L_p, "setWidgetSize", setWidgetSize); pushVariant(L_p, "ShowCurrent", 0); pushVariant(L_p, "ShowNormal", 1); @@ -410,6 +411,30 @@ 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) { diff --git a/src/luaenginegui/luaengine/LuaEngineGui.h b/src/luaenginegui/luaengine/LuaEngineGui.h index 229aee8..ff89574 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.h +++ b/src/luaenginegui/luaengine/LuaEngineGui.h @@ -41,6 +41,7 @@ public: static int setWidgetEnabled(lua_State *L_p); static int setWidgetFixed(lua_State *L_p); static int setWidgetLayout(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 layoutAddLayout(lua_State *L_p);