Skip to content

Commit

Permalink
Adds attributes for controlling the window created via dialog()
Browse files Browse the repository at this point in the history
Fixes #2947
  • Loading branch information
hluk committed Feb 6, 2025
1 parent 5956bcb commit 210425f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/scripting-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://doc.qt.io/qt-6/qt.html#WindowType-enum>`__ for details)

:returns: Value or values from accepted dialog or ``undefined`` if dialog
was canceled.
Expand Down
14 changes: 14 additions & 0 deletions src/scriptable/scriptableproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,20 @@ int ScriptableProxy::inputDialog(const NamedValueList &values)
createAndSetWidget<QLabel>("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) );
}
Expand Down
19 changes: 19 additions & 0 deletions src/tests/tests_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 210425f

Please sign in to comment.