mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-04 21:16:56 +01:00
added toolButton
This commit is contained in:
parent
847c3f2176
commit
e9b1c7b53e
2 changed files with 53 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <QPlainTextEdit>
|
||||
#include <QRadioButton>
|
||||
#include <QMainWindow>
|
||||
#include <QToolButton>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaObject>
|
||||
|
@ -130,6 +131,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
// Text Edit
|
||||
pushFunction(L_p, "createTextEdit", createTextEdit);
|
||||
|
||||
// Tool Button
|
||||
pushFunction(L_p, "createToolButton", createToolButton);
|
||||
|
||||
// Size Policy
|
||||
pushVariant(L_p, "SizePolicyFixed", (int)QSizePolicy::Fixed);
|
||||
pushVariant(L_p, "SizePolicyMinimum", (int)QSizePolicy::Minimum);
|
||||
|
@ -470,12 +474,18 @@ int LuaEngineGui::setWidgetText(lua_State *L_p)
|
|||
else if (((QObject*)pointer)->inherits("QPlainTextEdit")) {
|
||||
((QPlainTextEdit*)pointer)->setPlainText(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QPushButton")) {
|
||||
((QPushButton*)pointer)->setText(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QRadioButton")) {
|
||||
((QRadioButton*)pointer)->setText(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QTextEdit")) {
|
||||
((QTextEdit*)pointer)->setHtml(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QToolButton")) {
|
||||
((QToolButton*)pointer)->setText(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QWidget")) {
|
||||
((QWidget*)pointer)->setWindowTitle(getVariant(L_p, 2).toString());
|
||||
}
|
||||
|
@ -963,6 +973,40 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineGui::createToolButton(lua_State *L_p)
|
||||
{
|
||||
QLayout *layout = nullptr;
|
||||
QWidget *parent = nullptr;
|
||||
QString buttonText = "...";
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
buttonText = getVariant(L_p, 1).toString();
|
||||
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")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QToolButton *toolButton = new QToolButton(parent);
|
||||
toolButton->setObjectName(nameForPointer(toolButton));
|
||||
toolButton->setText(buttonText);
|
||||
if (layout != nullptr) {
|
||||
layout->addWidget(toolButton);
|
||||
}
|
||||
pushPointer(L_p, toolButton);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineGui::isWidgetChecked(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
|
@ -1028,6 +1072,10 @@ int LuaEngineGui::getWidgetText(lua_State *L_p)
|
|||
pushVariant(L_p, ((QLineEdit*)pointer)->text());
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QPushButton")) {
|
||||
pushVariant(L_p, ((QPushButton*)pointer)->text());
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QPlainTextEdit")) {
|
||||
pushVariant(L_p, ((QPlainTextEdit*)pointer)->toPlainText());
|
||||
return 1;
|
||||
|
@ -1040,6 +1088,10 @@ int LuaEngineGui::getWidgetText(lua_State *L_p)
|
|||
pushVariant(L_p, ((QTextEdit*)pointer)->toHtml());
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QToolButton")) {
|
||||
pushVariant(L_p, ((QToolButton*)pointer)->text());
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QWidget")) {
|
||||
pushVariant(L_p, ((QWidget*)pointer)->windowTitle());
|
||||
return 1;
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
static int createRadioButton(lua_State *L_p);
|
||||
static int createSpacerItem(lua_State *L_p);
|
||||
static int createTextEdit(lua_State *L_p);
|
||||
static int createToolButton(lua_State *L_p);
|
||||
static int isWidgetChecked(lua_State *L_p);
|
||||
static int getWidgetText(lua_State *L_p);
|
||||
static int getWindow(lua_State *L_p);
|
||||
|
|
Loading…
Reference in a new issue