From d8c75c11a2573b6bdf62a713d06e7a45e9d53958 Mon Sep 17 00:00:00 2001 From: Syping Date: Mon, 27 Aug 2018 01:37:12 +0200 Subject: [PATCH] fixedSize improved and setWidgetSize --- src/luaengineapp/edit.lua | 1 + src/luaenginegui/luaengine/LuaEngineGui.cpp | 58 +++++++++++++++++---- src/luaenginegui/luaengine/LuaEngineGui.h | 3 +- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/luaengineapp/edit.lua b/src/luaengineapp/edit.lua index 01b4c95..8ed2cf1 100644 --- a/src/luaengineapp/edit.lua +++ b/src/luaengineapp/edit.lua @@ -52,6 +52,7 @@ function main() textEditor = createPlainTextEdit("", mainWidget) layoutAddWidget(mainLayout, textEditor) + setWidgetSize(mainWindow, 650, 450) showWidget(mainWindow, ShowNormal) return GuiExecuted end diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index 851f23a..a9dd2be 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -70,9 +70,10 @@ void LuaEngineGui::pushClass(lua_State *L_p) pushFunction(L_p, "executeWidget", executeWidget); pushFunction(L_p, "showWidget", showWidget); pushFunction(L_p, "getWidgetText", getWidgetText); - pushFunction(L_p, "setWidgetFixedSize", setWidgetFixedSize); + pushFunction(L_p, "setWidgetFixed", setWidgetFixed); pushFunction(L_p, "setWidgetLayout", setWidgetLayout); pushFunction(L_p, "setWidgetText", setWidgetText); + pushFunction(L_p, "setWidgetSize", setWidgetSize); pushVariant(L_p, "ShowCurrent", 0); pushVariant(L_p, "ShowNormal", 1); pushVariant(L_p, "ShowMinimised", 2); @@ -247,13 +248,18 @@ int LuaEngineGui::executeWidget(lua_State *L_p) void *pointer = getPointer(L_p, 1); if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { QVariant isFixed = ((QObject*)pointer)->property("isFixed"); + QVariant isSizeSet = ((QObject*)pointer)->property("isSizeSet"); if (isFixed.type() == QVariant::Bool && isFixed.toBool()) { - ((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint()); - ((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint()); + if (!(isSizeSet.type() == QVariant::Bool && isSizeSet.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 (!(isSizeSet.type() == QVariant::Bool && isSizeSet.toBool())) { + ((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint()); + ((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + } } if (((QObject*)pointer)->inherits("QDialog")) { ((QDialog*)pointer)->exec(); @@ -282,13 +288,18 @@ int LuaEngineGui::showWidget(lua_State *L_p) showMode = getVariant(L_p, 2).toInt(); } QVariant isFixed = ((QObject*)pointer)->property("isFixed"); + QVariant isSizeSet = ((QObject*)pointer)->property("isSizeSet"); if (isFixed.type() == QVariant::Bool && isFixed.toBool()) { - ((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint()); - ((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint()); + if (!(isSizeSet.type() == QVariant::Bool && isSizeSet.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 (!(isSizeSet.type() == QVariant::Bool && isSizeSet.toBool())) { + ((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint()); + ((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); + } } switch (showMode) { case 1: @@ -337,7 +348,7 @@ int LuaEngineGui::setMenuShortcut(lua_State *L_p) return 0; } -int LuaEngineGui::setWidgetFixedSize(lua_State *L_p) +int LuaEngineGui::setWidgetFixed(lua_State *L_p) { if (getArgumentCount(L_p) >= 1) { void *pointer = getPointer(L_p, 1); @@ -347,10 +358,15 @@ int LuaEngineGui::setWidgetFixedSize(lua_State *L_p) isFixed = getVariant(L_p, 2).toBool(); } ((QObject*)pointer)->setProperty("isFixed", isFixed); + QVariant isSizeSet = ((QObject*)pointer)->property("isSizeSet"); if (isFixed && ((QWidget*)pointer)->isVisible()) { ((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint()); ((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->sizeHint()); } + else if (isFixed && (isSizeSet.type() == QVariant::Bool && isSizeSet.toBool())) { + ((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->size()); + ((QWidget*)pointer)->setMaximumSize(((QWidget*)pointer)->size()); + } else if (((QWidget*)pointer)->isVisible()) { ((QWidget*)pointer)->setMinimumSize(((QWidget*)pointer)->sizeHint()); ((QWidget*)pointer)->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); @@ -376,6 +392,28 @@ int LuaEngineGui::setWidgetLayout(lua_State *L_p) return 0; } +int LuaEngineGui::setWidgetSize(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 3) { + 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(getVariant(L_p, 2).toInt(), getVariant(L_p, 3).toInt()); + ((QWidget*)pointer)->setMaximumSize(getVariant(L_p, 2).toInt(), getVariant(L_p, 3).toInt()); + ((QWidget*)pointer)->resize(getVariant(L_p, 2).toInt(), getVariant(L_p, 3).toInt()); + ((QObject*)pointer)->setProperty("isSizeSet", true); + } + else { + ((QWidget*)pointer)->resize(getVariant(L_p, 2).toInt(), getVariant(L_p, 3).toInt()); + ((QObject*)pointer)->setProperty("isSizeSet", true); + } + return 0; + } + } + return 0; +} + int LuaEngineGui::setWidgetText(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { diff --git a/src/luaenginegui/luaengine/LuaEngineGui.h b/src/luaenginegui/luaengine/LuaEngineGui.h index 7ba2504..8d339db 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.h +++ b/src/luaenginegui/luaengine/LuaEngineGui.h @@ -37,8 +37,9 @@ public: static int showWidget(lua_State *L_p); static int setLayoutMargins(lua_State *L_p); static int setMenuShortcut(lua_State *L_p); - static int setWidgetFixedSize(lua_State *L_p); + static int setWidgetFixed(lua_State *L_p); static int setWidgetLayout(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); static int layoutAddWidget(lua_State *L_p);