improve fileDialog

This commit is contained in:
Syping 2019-09-25 19:16:30 +02:00
parent 3e4fda83ba
commit 5b5914f5b4
2 changed files with 33 additions and 3 deletions

View file

@ -84,6 +84,7 @@ void LuaEngineGui::pushClass(lua_State *L_p)
pushFunction(L_p, "setWidgetSize", setWidgetSize); pushFunction(L_p, "setWidgetSize", setWidgetSize);
pushFunction(L_p, "setWidgetText", setWidgetText); pushFunction(L_p, "setWidgetText", setWidgetText);
pushFunction(L_p, "setWidgetValue", setWidgetValue); pushFunction(L_p, "setWidgetValue", setWidgetValue);
pushFunction(L_p, "widgetAddText", widgetAddText);
pushVariant(L_p, "ShowCurrent", 0); pushVariant(L_p, "ShowCurrent", 0);
pushVariant(L_p, "ShowNormal", 1); pushVariant(L_p, "ShowNormal", 1);
pushVariant(L_p, "ShowDefault", 2); pushVariant(L_p, "ShowDefault", 2);
@ -175,6 +176,7 @@ int LuaEngineGui::showFileDialog(lua_State *L_p)
fileAcceptMode = QFileDialog::AcceptSave; fileAcceptMode = QFileDialog::AcceptSave;
break; break;
case 2: case 2:
fileFormats = QString();
fileMode = QFileDialog::Directory; fileMode = QFileDialog::Directory;
fileOptions = QFileDialog::ShowDirsOnly; fileOptions = QFileDialog::ShowDirsOnly;
break; break;
@ -182,6 +184,13 @@ int LuaEngineGui::showFileDialog(lua_State *L_p)
if (getArgumentCount(L_p) >= 2) { if (getArgumentCount(L_p) >= 2) {
dialogTitle = getVariant(L_p, 2).toString(); dialogTitle = getVariant(L_p, 2).toString();
if (getArgumentCount(L_p) >= 3) { if (getArgumentCount(L_p) >= 3) {
if (fileMode == QFileDialog::Directory) {
void *pointer = getPointer(L_p, 3);
if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
parent = (QWidget*)pointer;
}
}
else {
fileFormats = getVariant(L_p, 3).toString(); fileFormats = getVariant(L_p, 3).toString();
if (getArgumentCount(L_p) >= 4) { if (getArgumentCount(L_p) >= 4) {
void *pointer = getPointer(L_p, 4); void *pointer = getPointer(L_p, 4);
@ -192,6 +201,7 @@ int LuaEngineGui::showFileDialog(lua_State *L_p)
} }
} }
} }
}
QFileDialog fileDialog(parent); QFileDialog fileDialog(parent);
#if QT_VERSION >= 0x050900 #if QT_VERSION >= 0x050900
fileDialog.setWindowFlag(Qt::WindowContextHelpButtonHint, false); fileDialog.setWindowFlag(Qt::WindowContextHelpButtonHint, false);
@ -625,6 +635,25 @@ int LuaEngineGui::layoutAddWidget(lua_State *L_p)
return 0; return 0;
} }
int LuaEngineGui::widgetAddText(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QLineEdit")) {
((QLineEdit*)pointer)->setText(((QLineEdit*)pointer)->text() + getVariant(L_p, 2).toString());
}
else if (((QObject*)pointer)->inherits("QPlainTextEdit")) {
((QPlainTextEdit*)pointer)->appendPlainText(getVariant(L_p, 2).toString());
}
else if (((QObject*)pointer)->inherits("QTextEdit")) {
((QTextEdit*)pointer)->append(getVariant(L_p, 2).toString());
}
}
}
return 0;
}
int LuaEngineGui::createCentralWidget(lua_State *L_p) int LuaEngineGui::createCentralWidget(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 1) { if (getArgumentCount(L_p) >= 1) {

View file

@ -49,6 +49,7 @@ public:
static int setWidgetValue(lua_State *L_p); static int setWidgetValue(lua_State *L_p);
static int layoutAddLayout(lua_State *L_p); static int layoutAddLayout(lua_State *L_p);
static int layoutAddWidget(lua_State *L_p); static int layoutAddWidget(lua_State *L_p);
static int widgetAddText(lua_State *L_p);
static int createCentralWidget(lua_State *L_p); static int createCentralWidget(lua_State *L_p);
static int createCheckBox(lua_State *L_p); static int createCheckBox(lua_State *L_p);
static int createDialog(lua_State *L_p); static int createDialog(lua_State *L_p);