diff --git a/docs/scripting-api.rst b/docs/scripting-api.rst index 0f32b5b8f2..5095e6f8b7 100644 --- a/docs/scripting-api.rst +++ b/docs/scripting-api.rst @@ -1099,6 +1099,10 @@ unlike in GUI, where row numbers start from 1 by default. - '.style' - Qt style sheet for dialog - '.height', '.width', '.x', '.y' - dialog geometry - '.label' - dialog message (can contain basic HTML) + - '.modal' - set to true to make the dialog modal (to avoid other windows to get input focus) + - '.onTop' - set to true for the dialog to stay above other windows + - '.noParent' - set to true to avoid attaching the dialog to the main window + - '.popupWindow', '.sheetWindow', '.toolWindow', '.foreignWindow' - set/unset the type of dialog window (see `Qt::WindowFlags `__ for details) :returns: Value or values from accepted dialog or ``undefined`` if dialog was canceled. diff --git a/src/scriptable/scriptableproxy.cpp b/src/scriptable/scriptableproxy.cpp index 937878d106..d682d3278c 100644 --- a/src/scriptable/scriptableproxy.cpp +++ b/src/scriptable/scriptableproxy.cpp @@ -2082,6 +2082,20 @@ int ScriptableProxy::inputDialog(const NamedValueList &values) createAndSetWidget("text", value.value, &dialog); else if (value.name == ".defaultChoice") inputDialog.defaultChoice = value.value.toString(); + else if (value.name == ".modal") + dialog.setModal(value.value.toBool()); + else if (value.name == ".onTop") + dialog.setWindowFlag(Qt::WindowStaysOnTopHint, value.value.toBool()); + else if (value.name == ".noParent") + dialog.setParent(value.value.toBool() ? nullptr : m_wnd); + else if (value.name == ".popupWindow") + dialog.setWindowFlag(Qt::Popup, value.value.toBool()); + else if (value.name == ".toolWindow") + dialog.setWindowFlag(Qt::Tool, value.value.toBool()); + else if (value.name == ".sheetWindow") + dialog.setWindowFlag(Qt::Sheet, value.value.toBool()); + else if (value.name == ".foreignWindow") + dialog.setWindowFlag(Qt::ForeignWindow, value.value.toBool()); else widgets.append( createWidget(value.name, value.value, &inputDialog) ); } diff --git a/src/tests/tests_scripts.cpp b/src/tests/tests_scripts.cpp index 606265f577..2f889b9458 100644 --- a/src/tests/tests_scripts.cpp +++ b/src/tests/tests_scripts.cpp @@ -376,6 +376,25 @@ void Tests::commandDialog() [&]() { RUN(WITH_TIMEOUT "dialog('.title', 'Remove Items', '.label', 'Remove all items?') === true", "true\n"); }, [&]() { RUN(Args() << "keys" << "focus::QPushButton in dialog_Remove Items:QDialog" << "ENTER", ""); } ); + + RUN(Args() << "keys" << clipboardBrowserId, ""); + const QByteArray script2 = R"( + dialog( + '.modal', true, + '.onTop', true, + '.noParent', true, + '.popupWindow', true, + '.toolWindow', true, + '.sheetWindow', false, + '.foreignWindow', true, + '.noParent', true, + 'text', 'DEFAULT', + ) + )"; + runMultiple( + [&]() { RUN(WITH_TIMEOUT + script2, "DEFAULT\n"); }, + [&]() { RUN(Args() << "keys" << "focus::QLineEdit in :QDialog" << "ENTER", ""); } + ); } void Tests::commandDialogCloseOnDisconnect()