73 qCDebug(lcQpaDialogs) <<
"Asked to show" << windowModality <<
"dialog with parent" <<
parent;
75 if (m_alert.window.visible) {
76 qCDebug(lcQpaDialogs) <<
"Dialog already visible, ignoring request to show";
86 qCWarning(lcQpaDialogs,
"Cannot run window modal dialog without parent window");
95 if (!
options()->detailedText().isEmpty()) {
96 qCWarning(lcQpaDialogs,
"Message box contains detailed text");
104 qCDebug(lcQpaDialogs,
"Message box contains text in rich text format");
109 m_alert = [NSAlert
new];
113 m_alert.messageText =
text.toNSString();
116 switch (
options()->standardIcon()) {
125 m_alert.icon = [NSImage imageFromQImage:iconPixmap.
toImage()];
130 [m_alert setAlertStyle:NSAlertStyleInformational];
133 [m_alert setAlertStyle:NSAlertStyleWarning];
136 [m_alert setAlertStyle:NSAlertStyleCritical];
143 const auto addButton = [&](
auto title,
auto tag,
auto role) {
145 NSButton *
button = [m_alert addButtonWithTitle:
title.toNSString()];
154 qCDebug(lcQpaDialogs).verbosity(0) <<
"Adding button" <<
title <<
"with" << role;
159 if (
tag == defaultButton)
160 button.keyEquivalent =
@"\r";
161 else if ([
button.keyEquivalent isEqualToString:
@"\r"])
162 button.keyEquivalent =
@"";
168 if (
tag == escapeButton && ![
button.keyEquivalent isEqualToString:
@"\r"])
169 button.keyEquivalent =
@"\e";
170 else if ([
button.keyEquivalent isEqualToString:
@"\e"])
171 button.keyEquivalent =
@"";
173 if (@available(macOS 11, *))
194 std::vector<Button> buttons;
197 if (
auto standardButtons =
options()->standardButtons()) {
199 if (standardButtons & standardButton) {
200 auto title = platformTheme->standardButtonText(standardButton);
208 for (
auto customButton : customButtons)
209 buttons.push_back({customButton.label, customButton.id, customButton.role});
216 bool seenAccept =
false;
217 for (
auto &
button : buttons) {
218 if (
button.role == AcceptRole) {
222 button.role = AlternateRole;
226 std::vector<Button> orderedButtons;
227 const int *layoutEntry = buttonLayout(
Qt::Horizontal, ButtonLayout::MacLayout);
229 const auto role = ButtonRole(*layoutEntry & ~ButtonRole::Reverse);
230 const bool reverse = *layoutEntry & ButtonRole::Reverse;
234 orderedButtons.push_back(
button);
238 std::for_each(std::crbegin(buttons), std::crend(buttons), addButton);
240 std::for_each(std::cbegin(buttons), std::cend(buttons), addButton);
246 for (
auto button = orderedButtons.crbegin();
button != orderedButtons.crend(); ++
button)
252 m_alert.buttons.firstObject.keyEquivalent =
@"\r";
254 if (
auto checkBoxLabel = options()->checkBoxLabel(); !checkBoxLabel.isNull()) {
256 m_alert.suppressionButton.title = checkBoxLabel.toNSString();
257 auto state = options()->checkBoxState();
260 m_alert.showsSuppressionButton = YES;
263 qCDebug(lcQpaDialogs) <<
"Showing" << m_alert;
266 auto *cocoaWindow =
static_cast<QCocoaWindow*
>(parent->handle());
267 [m_alert beginSheetModalForWindow:cocoaWindow->nativeWindow()
269 processResponse(response);
281 if (m_alert && !m_alert.window.visible) {
282 qCDebug(lcQpaDialogs) <<
"Running deferred modal" << m_alert;
283 QCocoaEventDispatcher::clearCurrentThreadCocoaEventDispatcherInterruptFlag();
284 processResponse(runModal());
\reentrant \inmodule QtGui
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string.
QString toPlainText() const
Returns the plain text contained in the document.