added getWindow

This commit is contained in:
Syping 2018-09-15 02:53:35 +02:00
parent 208c53aaa0
commit 1ce6cf9059
3 changed files with 35 additions and 1 deletions

View file

@ -129,5 +129,5 @@ end
function closeDialog(pushButton)
disconnect(pushButton, "clicked()")
closeWidget(getParent(pushButton))
closeWidget(getWindow(pushButton))
end

View file

@ -131,6 +131,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
pushVariant(L_p, "SizePolicyPreferred", (int)QSizePolicy::Preferred);
pushVariant(L_p, "SizePolicyExpanding", (int)QSizePolicy::Expanding);
pushVariant(L_p, "SizePolicyIgnored", (int)QSizePolicy::Ignored);
// Object
pushFunction(L_p, "getWindow", getWindow);
}
void LuaEngineGui::pushClass(LuaEngine *luaEngine)
@ -796,6 +799,36 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
return 1;
}
int LuaEngineGui::getWindow(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
bool isWindow = false;
QObject *object = ((QObject*)pointer);
while (!isWindow) {
if (object->inherits("QDialog") || object->inherits("QMainWindow")) {
isWindow = true;
}
else {
QObject *parent = object->parent();
if (parent != NULL) {
object = parent;
}
else {
break;
}
}
}
if (isWindow) {
pushPointer(L_p, object);
return 1;
}
}
}
return 0;
}
int LuaEngineGui::getWidgetText(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {

View file

@ -59,6 +59,7 @@ public:
static int createSpacerItem(lua_State *L_p);
static int createTextEdit(lua_State *L_p);
static int getWidgetText(lua_State *L_p);
static int getWindow(lua_State *L_p);
private:
lua_State *L;