add setWidgetImageSize

This commit is contained in:
Syping 2020-05-19 16:15:42 +02:00
parent 85fb61371e
commit 9d045413f9
2 changed files with 85 additions and 58 deletions

View file

@ -97,6 +97,7 @@ void LuaEngineGui::pushClass(lua_State *L_p)
pushFunction(L_p, "setWidgetChecked", setWidgetChecked); pushFunction(L_p, "setWidgetChecked", setWidgetChecked);
pushFunction(L_p, "setWidgetEnabled", setWidgetEnabled); pushFunction(L_p, "setWidgetEnabled", setWidgetEnabled);
pushFunction(L_p, "setWidgetFixed", setWidgetFixed); pushFunction(L_p, "setWidgetFixed", setWidgetFixed);
pushFunction(L_p, "setWidgetImageSize", setWidgetImageSize);
pushFunction(L_p, "setWidgetLayout", setWidgetLayout); pushFunction(L_p, "setWidgetLayout", setWidgetLayout);
pushFunction(L_p, "setWidgetMaximum", setWidgetMaximum); pushFunction(L_p, "setWidgetMaximum", setWidgetMaximum);
pushFunction(L_p, "setWidgetMinimum", setWidgetMinimum); pushFunction(L_p, "setWidgetMinimum", setWidgetMinimum);
@ -584,6 +585,20 @@ int LuaEngineGui::setWidgetFixed(lua_State *L_p)
return 0; 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) int LuaEngineGui::setWidgetLayout(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 2) { if (getArgumentCount(L_p) >= 2) {
@ -930,16 +945,18 @@ int LuaEngineGui::createLayout(lua_State *L_p)
QLayout *layoutParent = nullptr; QLayout *layoutParent = nullptr;
if (getArgumentCount(L_p) >= 2) { if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2); void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) { if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QMainWindow")) {
parent = ((QMainWindow*)pointer)->centralWidget(); parent = ((QMainWindow*)pointer)->centralWidget();
} }
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { else if (((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer; parent = (QWidget*)pointer;
} }
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) { else if (((QObject*)pointer)->inherits("QLayout")) {
layoutParent = (QLayout*)pointer; layoutParent = (QLayout*)pointer;
} }
} }
}
void *layout; void *layout;
int layoutType = 0; int layoutType = 0;
if (getArgumentCount(L_p) >= 1) { if (getArgumentCount(L_p) >= 1) {
@ -1019,7 +1036,8 @@ int LuaEngineGui::createMenu(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 2) { if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2); void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QMenuBar")) { if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QMenuBar")) {
QMenu *menu = new QMenu((QWidget*)pointer); QMenu *menu = new QMenu((QWidget*)pointer);
menu->setObjectName(nameForPointer(menu)); menu->setObjectName(nameForPointer(menu));
menu->setTitle(getVariant(L_p, 1).toString()); menu->setTitle(getVariant(L_p, 1).toString());
@ -1027,7 +1045,7 @@ int LuaEngineGui::createMenu(lua_State *L_p)
pushPointer(L_p, menu); pushPointer(L_p, menu);
return 1; return 1;
} }
else if (pointer != NULL && ((QObject*)pointer)->inherits("QMenu")) { else if (((QObject*)pointer)->inherits("QMenu")) {
QMenu *menu = new QMenu((QWidget*)pointer); QMenu *menu = new QMenu((QWidget*)pointer);
menu->setObjectName(nameForPointer(menu)); menu->setObjectName(nameForPointer(menu));
menu->setTitle(getVariant(L_p, 1).toString()); menu->setTitle(getVariant(L_p, 1).toString());
@ -1036,6 +1054,7 @@ int LuaEngineGui::createMenu(lua_State *L_p)
return 1; return 1;
} }
} }
}
return 0; return 0;
} }
@ -1058,7 +1077,8 @@ int LuaEngineGui::createMenuEntry(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 2) { if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 2); void *pointer = getPointer(L_p, 2);
if (pointer != NULL && ((QObject*)pointer)->inherits("QMenu")) { if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QMenu")) {
QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer); QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer);
action->setObjectName(nameForPointer(action)); action->setObjectName(nameForPointer(action));
((QMenu*)pointer)->addAction(action); ((QMenu*)pointer)->addAction(action);
@ -1069,11 +1089,13 @@ int LuaEngineGui::createMenuEntry(lua_State *L_p)
pushPointer(L_p, action); pushPointer(L_p, action);
return 1; return 1;
} }
else if (pointer != NULL && ((QObject*)pointer)->inherits("QToolBar")) { else if (((QObject*)pointer)->inherits("QToolBar")) {
QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer); QAction *action = new QAction(getVariant(L_p, 1).toString(), (QObject*)pointer);
action->setObjectName(nameForPointer(action)); action->setObjectName(nameForPointer(action));
((QToolBar*)pointer)->addAction(action); ((QToolBar*)pointer)->addAction(action);
pushPointer(L_p, action); pushPointer(L_p, action);
return 1;
}
} }
} }
return 0; return 0;
@ -1083,17 +1105,19 @@ int LuaEngineGui::createMenuSeparator(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 1) { if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1); void *pointer = getPointer(L_p, 1);
if (pointer != NULL && ((QObject*)pointer)->inherits("QMenu")) { if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QMenu")) {
QAction *action = ((QMenu*)pointer)->addSeparator(); QAction *action = ((QMenu*)pointer)->addSeparator();
pushPointer(L_p, action); pushPointer(L_p, action);
return 1; return 1;
} }
else if (pointer != NULL && ((QObject*)pointer)->inherits("QToolBar")) { else if (((QObject*)pointer)->inherits("QToolBar")) {
QAction *action = ((QToolBar*)pointer)->addSeparator(); QAction *action = ((QToolBar*)pointer)->addSeparator();
pushPointer(L_p, action); pushPointer(L_p, action);
return 1; return 1;
} }
} }
}
return 0; return 0;
} }
@ -1491,13 +1515,14 @@ QWidget* LuaEngineGui::windowForObject(QObject *object)
void LuaEngineGui::lpForPointer(void *pointer, QLayout **layout, QWidget **parent) void LuaEngineGui::lpForPointer(void *pointer, QLayout **layout, QWidget **parent)
{ {
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) { if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QMainWindow")) {
*parent = ((QMainWindow*)pointer)->centralWidget(); *parent = ((QMainWindow*)pointer)->centralWidget();
} }
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) { else if (((QObject*)pointer)->inherits("QWidget")) {
*parent = (QWidget*)pointer; *parent = (QWidget*)pointer;
} }
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) { else if (((QObject*)pointer)->inherits("QLayout")) {
QWidget *widget = windowForObject((QObject*)pointer); QWidget *widget = windowForObject((QObject*)pointer);
if (widget != nullptr) { if (widget != nullptr) {
*layout = (QLayout*)pointer; *layout = (QLayout*)pointer;
@ -1505,6 +1530,7 @@ void LuaEngineGui::lpForPointer(void *pointer, QLayout **layout, QWidget **paren
} }
} }
} }
}
QString LuaEngineGui::nameForPointer(void *pointer) QString LuaEngineGui::nameForPointer(void *pointer)
{ {

View file

@ -44,6 +44,7 @@ public:
static int setWidgetChecked(lua_State *L_p); static int setWidgetChecked(lua_State *L_p);
static int setWidgetEnabled(lua_State *L_p); static int setWidgetEnabled(lua_State *L_p);
static int setWidgetFixed(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 setWidgetLayout(lua_State *L_p);
static int setWidgetMaximum(lua_State *L_p); static int setWidgetMaximum(lua_State *L_p);
static int setWidgetMinimum(lua_State *L_p); static int setWidgetMinimum(lua_State *L_p);