mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2025-09-15 21:21:41 +02:00
LuaEngine imporved
This commit is contained in:
parent
7ae82a4e32
commit
3d920f6168
5 changed files with 293 additions and 105 deletions
|
@ -16,6 +16,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "LuaEngineGui.h"
|
||||
#include <QPlainTextEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
@ -25,6 +26,7 @@
|
|||
#include <QSpacerItem>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QFileDialog>
|
||||
#include <QSizePolicy>
|
||||
#include <QEventLoop>
|
||||
#include <QTextEdit>
|
||||
|
@ -47,7 +49,13 @@ LuaEngineGui::LuaEngineGui(QObject *parent, bool loadBaseLibraries) : LuaEngine(
|
|||
|
||||
void LuaEngineGui::pushClass(lua_State *L_p)
|
||||
{
|
||||
// MessageBox
|
||||
// File Dialog
|
||||
pushFunction(L_p, "showFileDialog", showFileDialog);
|
||||
pushVariant(L_p, "OpenFileDialog", 0);
|
||||
pushVariant(L_p, "SaveFileDialog", 1);
|
||||
pushVariant(L_p, "OpenFolderDialog", 2);
|
||||
|
||||
// Message Box
|
||||
pushFunction(L_p, "showMessageBox", showMessageBox);
|
||||
pushVariant(L_p, "InfoMessageBox", 0);
|
||||
pushVariant(L_p, "WarningMessageBox", 1);
|
||||
|
@ -91,6 +99,9 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
// Line Edit
|
||||
pushFunction(L_p, "createLineEdit", createLineEdit);
|
||||
|
||||
// Key Sequence
|
||||
pushFunction(L_p, "setKeySequence", setKeySequence);
|
||||
|
||||
// Main Window
|
||||
pushFunction(L_p, "createMainWindow", createMainWindow);
|
||||
pushFunction(L_p, "createCentralWidget", createCentralWidget);
|
||||
|
@ -99,6 +110,10 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
pushFunction(L_p, "createMenu", createMenu);
|
||||
pushFunction(L_p, "createMenuBar", createMenuBar);
|
||||
pushFunction(L_p, "createMenuEntry", createMenuEntry);
|
||||
pushFunction(L_p, "createMenuSeparator", createMenuSeparator);
|
||||
|
||||
// Plain Text Edit
|
||||
pushFunction(L_p, "createPlainTextEdit", createPlainTextEdit);
|
||||
|
||||
// Push Button
|
||||
pushFunction(L_p, "createPushButton", createPushButton);
|
||||
|
@ -106,7 +121,7 @@ void LuaEngineGui::pushClass(lua_State *L_p)
|
|||
// Spacer Item
|
||||
pushFunction(L_p, "createSpacerItem", createSpacerItem);
|
||||
|
||||
// Line Edit
|
||||
// Text Edit
|
||||
pushFunction(L_p, "createTextEdit", createTextEdit);
|
||||
|
||||
// Size Policy
|
||||
|
@ -126,25 +141,73 @@ void LuaEngineGui::pushClass(LuaEngine *luaEngine)
|
|||
pushClass(luaEngine->luaState());
|
||||
}
|
||||
|
||||
int LuaEngineGui::showMessageBox(lua_State *L_p)
|
||||
int LuaEngineGui::showFileDialog(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
if (args.length() >= 2) {
|
||||
QWidget *parent = nullptr;
|
||||
QString boxMessage = args.at(1).toString();
|
||||
QString boxTitle = "LuaEngine";
|
||||
if (args.length() >= 3) {
|
||||
boxTitle = args.at(2).toString();
|
||||
if (args.length() >= 4) {
|
||||
if ((QMetaType::Type)args.at(3).type() == QMetaType::Void || (QMetaType::Type)args.at(3).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(3)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(3));
|
||||
QWidget *parent = nullptr;
|
||||
QString dialogTitle = "LuaEngine";
|
||||
QString fileFormats = "All files (*)";
|
||||
QFileDialog::FileMode fileMode = QFileDialog::ExistingFile;
|
||||
QFileDialog::Options fileOptions = QFileDialog::DontUseNativeDialog;
|
||||
QFileDialog::AcceptMode fileAcceptMode = QFileDialog::AcceptOpen;
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
switch (getVariant(L_p, 1).toInt()) {
|
||||
case 1:
|
||||
fileMode = QFileDialog::AnyFile;
|
||||
fileAcceptMode = QFileDialog::AcceptSave;
|
||||
break;
|
||||
case 2:
|
||||
fileMode = QFileDialog::Directory;
|
||||
fileOptions = QFileDialog::ShowDirsOnly | QFileDialog::DontUseNativeDialog;
|
||||
break;
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
dialogTitle = getVariant(L_p, 2).toString();
|
||||
if (getArgumentCount(L_p) >= 3) {
|
||||
fileFormats = getVariant(L_p, 3).toString();
|
||||
if (getArgumentCount(L_p) >= 4) {
|
||||
void *pointer = getPointer(L_p, 4);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QFileDialog fileDialog(parent);
|
||||
fileDialog.setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
||||
fileDialog.setWindowTitle(dialogTitle);
|
||||
fileDialog.setAcceptMode(fileAcceptMode);
|
||||
fileDialog.setNameFilter(fileFormats);
|
||||
fileDialog.setFileMode(fileMode);
|
||||
fileDialog.setOptions(fileOptions);
|
||||
if (fileDialog.exec()) {
|
||||
int returnInt = 0;
|
||||
switch (args.at(0).toInt()) {
|
||||
for (const QString &fileName : fileDialog.selectedFiles()) {
|
||||
returnInt++;
|
||||
pushVariant(L_p, fileName);
|
||||
}
|
||||
return returnInt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::showMessageBox(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
QWidget *parent = nullptr;
|
||||
QString boxMessage = getVariant(L_p, 2).toString();
|
||||
QString boxTitle = "LuaEngine";
|
||||
if (getArgumentCount(L_p) >= 3) {
|
||||
boxTitle = getVariant(L_p, 3).toString();
|
||||
if (getArgumentCount(L_p) >= 4) {
|
||||
void *pointer = getPointer(L_p, 4);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
int returnInt = 0;
|
||||
switch (getVariant(L_p, 1).toInt()) {
|
||||
case 1:
|
||||
QMessageBox::warning(parent, boxTitle, boxMessage);
|
||||
break;
|
||||
|
@ -153,11 +216,7 @@ int LuaEngineGui::showMessageBox(lua_State *L_p)
|
|||
break;
|
||||
case 3:
|
||||
{
|
||||
bool returnCode = false;
|
||||
if (QMessageBox::Yes == QMessageBox::question(parent, boxTitle, boxMessage)) {
|
||||
returnCode = true;
|
||||
}
|
||||
pushVariant(L_p, returnCode);
|
||||
pushVariant(L_p, (QMessageBox::Yes == QMessageBox::question(parent, boxTitle, boxMessage)));
|
||||
returnInt = 1;
|
||||
}
|
||||
break;
|
||||
|
@ -255,7 +314,6 @@ int LuaEngineGui::showWidget(lua_State *L_p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int LuaEngineGui::setLayoutMargins(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 5) {
|
||||
|
@ -267,6 +325,20 @@ int LuaEngineGui::setLayoutMargins(lua_State *L_p)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::setKeySequence(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QAction")) {
|
||||
((QAction*)pointer)->setShortcut(QKeySequence::fromString(getVariant(L_p, 2).toString()));
|
||||
((QAction*)pointer)->setShortcutContext(Qt::ApplicationShortcut);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::setWidgetFixedSize(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
|
@ -320,8 +392,11 @@ int LuaEngineGui::setWidgetText(lua_State *L_p)
|
|||
else if (((QObject*)pointer)->inherits("QLineEdit")) {
|
||||
((QLineEdit*)pointer)->setText(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QPlainTextEdit")) {
|
||||
((QPlainTextEdit*)pointer)->setPlainText(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QTextEdit")) {
|
||||
((QTextEdit*)pointer)->setText(getVariant(L_p, 2).toString());
|
||||
((QTextEdit*)pointer)->setHtml(getVariant(L_p, 2).toString());
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QWidget")) {
|
||||
((QWidget*)pointer)->setWindowTitle(getVariant(L_p, 2).toString());
|
||||
|
@ -420,6 +495,7 @@ int LuaEngineGui::createDialog(lua_State *L_p)
|
|||
}
|
||||
}
|
||||
QDialog *dialog = new QDialog(parent);
|
||||
dialog->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
||||
dialog->setObjectName(nameForPointer(dialog));
|
||||
dialog->setWindowTitle(windowTitle);
|
||||
pushPointer(L_p, dialog);
|
||||
|
@ -584,6 +660,39 @@ int LuaEngineGui::createMenuEntry(lua_State *L_p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineGui::createPlainTextEdit(lua_State *L_p)
|
||||
{
|
||||
QWidget *parent = nullptr;
|
||||
QString editText = "LuaEngine";
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
editText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
QPlainTextEdit *textEdit = new QPlainTextEdit(parent);
|
||||
textEdit->setObjectName(nameForPointer(textEdit));
|
||||
textEdit->setPlainText(editText);
|
||||
pushPointer(L_p, textEdit);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineGui::createPushButton(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
|
@ -632,22 +741,20 @@ int LuaEngineGui::createSpacerItem(lua_State *L_p)
|
|||
|
||||
int LuaEngineGui::createTextEdit(lua_State *L_p)
|
||||
{
|
||||
QVariantList args = getArguments(L_p);
|
||||
QWidget *parent = nullptr;
|
||||
QString editText = "LuaEngine";
|
||||
if (args.length() >= 1) {
|
||||
editText = args.at(0).toString();
|
||||
if (args.length() >= 2) {
|
||||
if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) {
|
||||
if (((QObject*)qvariant_cast<void*>(args.at(1)))->inherits("QWidget")) {
|
||||
parent = (QWidget*)qvariant_cast<void*>(args.at(1));
|
||||
}
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
editText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
QTextEdit *textEdit = new QTextEdit(parent);
|
||||
textEdit->setObjectName(nameForPointer(textEdit));
|
||||
textEdit->setText(editText);
|
||||
textEdit->setHtml(editText);
|
||||
pushPointer(L_p, textEdit);
|
||||
return 1;
|
||||
}
|
||||
|
@ -681,8 +788,12 @@ int LuaEngineGui::getWidgetText(lua_State *L_p)
|
|||
pushVariant(L_p, ((QLineEdit*)pointer)->text());
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QPlainTextEdit")) {
|
||||
pushVariant(L_p, ((QPlainTextEdit*)pointer)->toPlainText());
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QTextEdit")) {
|
||||
pushVariant(L_p, ((QTextEdit*)pointer)->toPlainText());
|
||||
pushVariant(L_p, ((QTextEdit*)pointer)->toHtml());
|
||||
return 1;
|
||||
}
|
||||
else if (((QObject*)pointer)->inherits("QWidget")) {
|
||||
|
|
|
@ -30,11 +30,13 @@ public:
|
|||
LuaEngineGui(QObject *parent = nullptr, bool loadBaseLibraries = true);
|
||||
static void pushClass(lua_State *L_p);
|
||||
static void pushClass(LuaEngine *luaEngine);
|
||||
static int showFileDialog(lua_State *L_p);
|
||||
static int showMessageBox(lua_State *L_p);
|
||||
static int closeWidget(lua_State *L_p);
|
||||
static int executeWidget(lua_State *L_p);
|
||||
static int showWidget(lua_State *L_p);
|
||||
static int setLayoutMargins(lua_State *L_p);
|
||||
static int setKeySequence(lua_State *L_p);
|
||||
static int setWidgetFixedSize(lua_State *L_p);
|
||||
static int setWidgetLayout(lua_State *L_p);
|
||||
static int setWidgetText(lua_State *L_p);
|
||||
|
@ -50,6 +52,8 @@ public:
|
|||
static int createMenu(lua_State *L_p);
|
||||
static int createMenuBar(lua_State *L_p);
|
||||
static int createMenuEntry(lua_State *L_p);
|
||||
static int createMenuSeparator(lua_State *L_p);
|
||||
static int createPlainTextEdit(lua_State *L_p);
|
||||
static int createPushButton(lua_State *L_p);
|
||||
static int createSpacerItem(lua_State *L_p);
|
||||
static int createTextEdit(lua_State *L_p);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue