From 9d045413f9e44a1faef0a185b577cb366a045706 Mon Sep 17 00:00:00 2001 From: Syping Date: Tue, 19 May 2020 16:15:42 +0200 Subject: [PATCH] add setWidgetImageSize --- src/luaenginegui/luaengine/LuaEngineGui.cpp | 142 ++++++++++++-------- src/luaenginegui/luaengine/LuaEngineGui.h | 1 + 2 files changed, 85 insertions(+), 58 deletions(-) diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index 959e4ee..27c915d 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -97,6 +97,7 @@ void LuaEngineGui::pushClass(lua_State *L_p) pushFunction(L_p, "setWidgetChecked", setWidgetChecked); pushFunction(L_p, "setWidgetEnabled", setWidgetEnabled); pushFunction(L_p, "setWidgetFixed", setWidgetFixed); + pushFunction(L_p, "setWidgetImageSize", setWidgetImageSize); pushFunction(L_p, "setWidgetLayout", setWidgetLayout); pushFunction(L_p, "setWidgetMaximum", setWidgetMaximum); pushFunction(L_p, "setWidgetMinimum", setWidgetMinimum); @@ -584,6 +585,20 @@ int LuaEngineGui::setWidgetFixed(lua_State *L_p) return 0; } +int LuaEngineGui::setWidgetImageSize(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 3) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QPushButton")) { + ((QPushButton*)pointer)->setIconSize(QSize(getVariant(L_p, 2).toInt(), getVariant(L_p, 3).toInt())); + } + return 0; + } + } + return 0; +} + int LuaEngineGui::setWidgetLayout(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { @@ -930,14 +945,16 @@ int LuaEngineGui::createLayout(lua_State *L_p) QLayout *layoutParent = nullptr; 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")) { - layoutParent = (QLayout*)pointer; + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QMainWindow")) { + parent = ((QMainWindow*)pointer)->centralWidget(); + } + else if (((QObject*)pointer)->inherits("QWidget")) { + parent = (QWidget*)pointer; + } + else if (((QObject*)pointer)->inherits("QLayout")) { + layoutParent = (QLayout*)pointer; + } } } void *layout; @@ -1019,21 +1036,23 @@ int LuaEngineGui::createMenu(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { void *pointer = getPointer(L_p, 2); - if (pointer != NULL && ((QObject*)pointer)->inherits("QMenuBar")) { - QMenu *menu = new QMenu((QWidget*)pointer); - menu->setObjectName(nameForPointer(menu)); - menu->setTitle(getVariant(L_p, 1).toString()); - ((QMenuBar*)pointer)->addAction(menu->menuAction()); - pushPointer(L_p, menu); - return 1; - } - else if (pointer != NULL && ((QObject*)pointer)->inherits("QMenu")) { - QMenu *menu = new QMenu((QWidget*)pointer); - menu->setObjectName(nameForPointer(menu)); - menu->setTitle(getVariant(L_p, 1).toString()); - ((QMenu*)pointer)->addAction(menu->menuAction()); - pushPointer(L_p, menu); - return 1; + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QMenuBar")) { + QMenu *menu = new QMenu((QWidget*)pointer); + menu->setObjectName(nameForPointer(menu)); + menu->setTitle(getVariant(L_p, 1).toString()); + ((QMenuBar*)pointer)->addAction(menu->menuAction()); + pushPointer(L_p, menu); + return 1; + } + else if (((QObject*)pointer)->inherits("QMenu")) { + QMenu *menu = new QMenu((QWidget*)pointer); + menu->setObjectName(nameForPointer(menu)); + menu->setTitle(getVariant(L_p, 1).toString()); + ((QMenu*)pointer)->addAction(menu->menuAction()); + pushPointer(L_p, menu); + return 1; + } } } return 0; @@ -1058,22 +1077,25 @@ int LuaEngineGui::createMenuEntry(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { void *pointer = getPointer(L_p, 2); - if (pointer != NULL && ((QObject*)pointer)->inherits("QMenu")) { - QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer); - action->setObjectName(nameForPointer(action)); - ((QMenu*)pointer)->addAction(action); - if (getArgumentCount(L_p) >= 3) { - action->setShortcut(QKeySequence::fromString(getVariant(L_p, 3).toString())); - action->setShortcutContext(Qt::ApplicationShortcut); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QMenu")) { + QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer); + action->setObjectName(nameForPointer(action)); + ((QMenu*)pointer)->addAction(action); + if (getArgumentCount(L_p) >= 3) { + action->setShortcut(QKeySequence::fromString(getVariant(L_p, 3).toString())); + action->setShortcutContext(Qt::ApplicationShortcut); + } + pushPointer(L_p, action); + return 1; + } + else if (((QObject*)pointer)->inherits("QToolBar")) { + QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer); + action->setObjectName(nameForPointer(action)); + ((QToolBar*)pointer)->addAction(action); + pushPointer(L_p, action); + return 1; } - pushPointer(L_p, action); - return 1; - } - else if (pointer != NULL && ((QObject*)pointer)->inherits("QToolBar")) { - QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer); - action->setObjectName(nameForPointer(action)); - ((QToolBar*)pointer)->addAction(action); - pushPointer(L_p, action); } } return 0; @@ -1083,15 +1105,17 @@ int LuaEngineGui::createMenuSeparator(lua_State *L_p) { if (getArgumentCount(L_p) >= 1) { void *pointer = getPointer(L_p, 1); - if (pointer != NULL && ((QObject*)pointer)->inherits("QMenu")) { - QAction *action = ((QMenu*)pointer)->addSeparator(); - pushPointer(L_p, action); - return 1; - } - else if (pointer != NULL && ((QObject*)pointer)->inherits("QToolBar")) { - QAction *action = ((QToolBar*)pointer)->addSeparator(); - pushPointer(L_p, action); - return 1; + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QMenu")) { + QAction *action = ((QMenu*)pointer)->addSeparator(); + pushPointer(L_p, action); + return 1; + } + else if (((QObject*)pointer)->inherits("QToolBar")) { + QAction *action = ((QToolBar*)pointer)->addSeparator(); + pushPointer(L_p, action); + return 1; + } } } return 0; @@ -1491,17 +1515,19 @@ QWidget* LuaEngineGui::windowForObject(QObject *object) void LuaEngineGui::lpForPointer(void *pointer, QLayout **layout, QWidget **parent) { - 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 (pointer != NULL) { + if (((QObject*)pointer)->inherits("QMainWindow")) { + *parent = ((QMainWindow*)pointer)->centralWidget(); + } + else if (((QObject*)pointer)->inherits("QWidget")) { + *parent = (QWidget*)pointer; + } + else if (((QObject*)pointer)->inherits("QLayout")) { + QWidget *widget = windowForObject((QObject*)pointer); + if (widget != nullptr) { + *layout = (QLayout*)pointer; + *parent = widget; + } } } } diff --git a/src/luaenginegui/luaengine/LuaEngineGui.h b/src/luaenginegui/luaengine/LuaEngineGui.h index ece8a13..a0d310c 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.h +++ b/src/luaenginegui/luaengine/LuaEngineGui.h @@ -44,6 +44,7 @@ public: static int setWidgetChecked(lua_State *L_p); static int setWidgetEnabled(lua_State *L_p); static int setWidgetFixed(lua_State *L_p); + static int setWidgetImageSize(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);