KWidgetsAddons

kmessagebox.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999 Waldo Bastian <[email protected]>
4  SPDX-FileCopyrightText: 2012 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-only
7 */
8 
9 #include "kmessagebox.h"
10 #include "kmessagebox_p.h"
11 
12 #include <QPointer>
13 #include <QCheckBox>
14 #include <QDialog>
15 #include <QDialogButtonBox>
16 #include <QLabel>
17 #include <QLayout>
18 #include <QListWidget>
19 #include <QPushButton>
20 #include <QDesktopWidget>
21 #include <QScrollArea>
22 #include <QScrollBar>
23 #include <QTextBrowser>
24 #include <QWindow>
25 
26 #include <qapplication.h>
27 #if 0
28 // NOTE waiting for the notification framework plan
29 #include <knotification.h>
30 #endif
31 #include <ksqueezedtextlabel.h>
32 
33 #include <KCollapsibleGroupBox>
34 // Some i18n filters, that standard button texts are piped through
35 // (the new KGuiItem object with filtered text is created from the old one).
36 
37 // Filter for the Yes-button text in standard message dialogs,
38 // after the message caption/text have been translated.
39 #define I18N_FILTER_BUTTON_YES(src, dst) \
40  KGuiItem dst(src); \
41  dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-yes" ) );
42 
43 // Filter for the No-button text in standard message dialogs,
44 // after the message caption/text have been translated.
45 #define I18N_FILTER_BUTTON_NO(src, dst) \
46  KGuiItem dst(src); \
47  dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-no" ) );
48 
49 // Filter for the Continue-button text in standard message dialogs,
50 // after the message caption/text have been translated.
51 #define I18N_FILTER_BUTTON_CONTINUE(src, dst) \
52  KGuiItem dst(src); \
53  dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-continue" ) );
54 
55 // Filter for the Cancel-button text in standard message dialogs,
56 // after the message caption/text have been translated.
57 #define I18N_FILTER_BUTTON_CANCEL(src, dst) \
58  KGuiItem dst(src); \
59  dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-cancel" ) );
60 
61 // Called after the button texts in standard message dialogs
62 // have been filtered by the messages above. Not visible to user.
63 #define I18N_POST_BUTTON_FILTER \
64  QApplication::translate( "KMessageBox", ".", "@action:button post-filter" );
65 
66 namespace KMessageBox
67 {
68 
69 /*
70  * this static is used by the createKMessageBox function to enqueue dialogs
71  * FIXME what should we do about this static?
72  */
73 QDialogButtonBox::StandardButton KWIDGETSADDONS_EXPORT(*KMessageBox_exec_hook)(QDialog *) = nullptr;
74 
75 static void applyOptions(QDialog *dialog, KMessageBox::Options options)
76 {
77  if (options & KMessageBox::WindowModal) {
79  }
80  dialog->setModal(true);
81 }
82 
83 // This method has been copied from KWindowSystem to avoid depending on it
84 static void setMainWindow(QWidget *subWidget, WId mainWindowId)
85 {
86 #ifdef Q_OS_OSX
87  if (!QWidget::find(mainWindowId)) {
88  return;
89  }
90 #endif
91  // Set the WA_NativeWindow attribute to force the creation of the QWindow.
92  // Without this QWidget::windowHandle() returns 0.
93  subWidget->setAttribute(Qt::WA_NativeWindow, true);
94  QWindow *subWindow = subWidget->windowHandle();
95  Q_ASSERT(subWindow);
96 
97  QWindow *mainWindow = QWindow::fromWinId(mainWindowId);
98  if (!mainWindow) {
99  // foreign windows not supported on all platforms
100  return;
101  }
102  // mainWindow is not the child of any object, so make sure it gets deleted at some point
103  QObject::connect(subWidget, &QObject::destroyed, mainWindow, &QObject::deleteLater);
104  subWindow->setTransientParent(mainWindow);
105 }
106 
110 static QDialog *createWIdDialog(WId parent_id)
111 {
112  QWidget *parent = QWidget::find(parent_id);
113  QDialog *dialog = new QDialog(parent, Qt::Dialog);
114  if (!parent && parent_id) {
115  setMainWindow(dialog, parent_id);
116  }
117  return dialog;
118 }
119 
120 class DialogButtonsHelper : public QObject
121 {
122  Q_OBJECT
123 public:
124  DialogButtonsHelper(QDialog *dialog, QDialogButtonBox *buttons)
125  : QObject(dialog),
126  m_dialog(dialog),
127  m_buttons(buttons),
128  m_details(nullptr)
129  {
131  this, &DialogButtonsHelper::onButtonClicked);
132  }
133 
134  void setDetailsWidget(QWidget *widget)
135  {
136  m_details = widget;
137  }
138 
139 public Q_SLOTS:
140  void onButtonClicked(QAbstractButton *button)
141  {
142  QDialogButtonBox::StandardButton code = m_buttons->standardButton(button);
143  if (code != QDialogButtonBox::NoButton) {
144  m_dialog->done(code);
145  }
146  }
147 
148 private:
149  QDialog *const m_dialog;
150  QDialogButtonBox *const m_buttons;
151  QWidget *m_details;
152 };
153 
154 QDialogButtonBox::StandardButton createKMessageBox(QDialog *dialog, QDialogButtonBox *buttons, QMessageBox::Icon icon,
155  const QString &text, const QStringList &strlist,
156  const QString &ask, bool *checkboxReturn,
157  Options options, const QString &details)
158 {
159  QIcon tmpIcon;
160  QStyle *style = dialog ? dialog->style() : QApplication::style();
161  switch (icon) {
163  tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, dialog);
164  break;
166  tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, nullptr, dialog);
167  break;
169  tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, nullptr, dialog);
170  break;
172  tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, nullptr, dialog);
173  break;
174  default:
175  break;
176  }
177 
178  return createKMessageBox(dialog, buttons, tmpIcon, text, strlist,
179  ask, checkboxReturn, options, details, icon);
180 }
181 
182 QDialogButtonBox::StandardButton createKMessageBox(QDialog *dialog, QDialogButtonBox *buttons, const QIcon &icon,
183  const QString &text, const QStringList &strlist,
184  const QString &ask, bool *checkboxReturn, Options options,
185  const QString &details, QMessageBox::Icon notifyType)
186 {
187  DialogButtonsHelper *buttonsHelper = new DialogButtonsHelper(dialog, buttons);
188 
189  QWidget *mainWidget = new QWidget(dialog);
190  QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget);
191  const int verticalSpacing = mainWidget->style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing);
192  const int horizontalSpacing = mainWidget->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
193  mainLayout->setSpacing(verticalSpacing * 2); // provide extra spacing
194  mainLayout->setContentsMargins(0, 0, 0, 0);
195  buttons->setParent(dialog);
196 
197  QHBoxLayout *hLayout = new QHBoxLayout();
198  hLayout->setContentsMargins(0, 0, 0, 0);
199  hLayout->setSpacing(-1); // use default spacing
200  mainLayout->addLayout(hLayout, 5);
201 
202  QLabel *iconLabel = new QLabel(mainWidget);
203 
204  if (!icon.isNull()) {
205  QStyleOption option;
206  option.initFrom(mainWidget);
207  iconLabel->setPixmap(icon.pixmap(mainWidget->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, mainWidget)));
208  }
209 
210  QVBoxLayout *iconLayout = new QVBoxLayout();
211  iconLayout->addStretch(1);
212  iconLayout->addWidget(iconLabel);
213  iconLayout->addStretch(5);
214 
215  hLayout->addLayout(iconLayout, 0);
216  hLayout->addSpacing(horizontalSpacing);
217 
218  QLabel *messageLabel = new QLabel(text, mainWidget);
219  messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink);
221  if (options & KMessageBox::AllowLink) {
223  }
224  messageLabel->setTextInteractionFlags(flags);
225 
226  QRect desktop = QApplication::desktop()->screenGeometry(dialog);
227  bool usingSqueezedTextLabel = false;
228  if (messageLabel->sizeHint().width() > desktop.width() * 0.5) {
229  // enable automatic wrapping of messages which are longer than 50% of screen width
230  messageLabel->setWordWrap(true);
231  // use a squeezed label if text is still too wide
232  usingSqueezedTextLabel = messageLabel->sizeHint().width() > desktop.width() * 0.85;
233  if (usingSqueezedTextLabel) {
234  delete messageLabel;
235  messageLabel = new KSqueezedTextLabel(text, mainWidget);
236  messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink);
237  messageLabel->setTextInteractionFlags(flags);
238  }
239  }
240 
241  QPalette messagePal(messageLabel->palette());
243  messageLabel->setPalette(messagePal);
244 
245  bool usingScrollArea = desktop.height() / 3 < messageLabel->sizeHint().height();
246  if (usingScrollArea) {
247  QScrollArea *messageScrollArea = new QScrollArea(mainWidget);
248  messageScrollArea->setWidget(messageLabel);
249  messageScrollArea->setFrameShape(QFrame::NoFrame);
250  messageScrollArea->setWidgetResizable(true);
251  QPalette scrollPal(messageScrollArea->palette());
253  messageScrollArea->viewport()->setPalette(scrollPal);
254  hLayout->addWidget(messageScrollArea, 5);
255  } else {
256  hLayout->addWidget(messageLabel, 5);
257  }
258 
259  const bool usingListWidget = !strlist.isEmpty();
260  if (usingListWidget) {
261  // enable automatic wrapping since the listwidget has already a good initial width
262  messageLabel->setWordWrap(true);
263  QListWidget *listWidget = new QListWidget(mainWidget);
264  listWidget->addItems(strlist);
265 
266  QStyleOptionViewItem styleOption;
267  styleOption.initFrom(listWidget);
268  QFontMetrics fm(styleOption.font);
269  int w = listWidget->width();
270  for (const QString &str : strlist) {
271  w = qMax(w, fm.boundingRect(str).width());
272  }
273  const int borderWidth = listWidget->width() - listWidget->viewport()->width() + listWidget->verticalScrollBar()->height();
274  w += borderWidth;
275  if (w > desktop.width() * 0.85) { // limit listWidget size to 85% of screen width
276  w = qRound(desktop.width() * 0.85);
277  }
278  listWidget->setMinimumWidth(w);
279 
280  mainLayout->addWidget(listWidget, usingScrollArea ? 10 : 50);
283  } else if (!usingScrollArea) {
284  mainLayout->addStretch(15);
285  }
286 
287  QPointer<QCheckBox> checkbox = nullptr;
288  if (!ask.isEmpty()) {
289  checkbox = new QCheckBox(ask, mainWidget);
290  mainLayout->addWidget(checkbox);
291  if (checkboxReturn) {
292  checkbox->setChecked(*checkboxReturn);
293  }
294  }
295 
296  QVBoxLayout *topLayout = new QVBoxLayout;
297  dialog->setLayout(topLayout);
298  topLayout->addWidget(mainWidget);
299 
300  if (!details.isEmpty()) {
301  QHBoxLayout *detailsHLayout = new QHBoxLayout();
302  detailsHLayout->addSpacing(2 * horizontalSpacing + iconLayout->sizeHint().width());
303  KCollapsibleGroupBox *detailsGroup = new KCollapsibleGroupBox();
304  detailsGroup->setTitle(QApplication::translate("KMessageBox", "Details"));
305  QVBoxLayout *detailsLayout = new QVBoxLayout(detailsGroup);
306  if (details.length() < 512) {
307  QLabel *detailsLabel = new QLabel(details);
308  detailsLabel->setOpenExternalLinks(options & KMessageBox::AllowLink);
310  if (options & KMessageBox::AllowLink) {
312  };
313  detailsLabel->setTextInteractionFlags(flags);
314  detailsLabel->setWordWrap(true);
315  detailsLabel->setMinimumSize(detailsLabel->sizeHint());
316  detailsLayout->addWidget(detailsLabel, 50);
317  } else {
318  QTextBrowser *detailTextEdit = new QTextBrowser();
319  detailTextEdit->setText(details);
320  detailTextEdit->setReadOnly(true);
321  detailTextEdit->setMinimumHeight(detailTextEdit->fontMetrics().lineSpacing() * 11);
322  detailsLayout->addWidget(detailTextEdit, 50);
323  }
324  if (!usingListWidget) {
325  mainLayout->setStretchFactor(hLayout, 10);
326  }
327  detailsHLayout->addWidget(detailsGroup);
328  topLayout->addLayout(detailsHLayout);
329  buttonsHelper->setDetailsWidget(detailsGroup);
330  }
331 
332  topLayout->addWidget(buttons);
334 
335  if (!usingListWidget && !usingScrollArea && !usingSqueezedTextLabel && details.isEmpty()) {
336  dialog->setFixedSize(dialog->sizeHint() + QSize(10, 10));
337  }
338 
339  if ((options & KMessageBox::Dangerous)) {
340  QPushButton *cancelButton = buttons->button(QDialogButtonBox::Cancel);
341  QPushButton *noButton = buttons->button(QDialogButtonBox::No);
342 
343  if (cancelButton && cancelButton->isEnabled()) {
344  cancelButton->setDefault(true);
345  cancelButton->setFocus();
346  } else if (noButton && noButton->isEnabled()) {
347  noButton->setDefault(true);
348  noButton->setFocus();
349  }
350  }
351 
352 #ifndef Q_OS_WIN // FIXME problems with KNotify on Windows
353  if ((options & KMessageBox::Notify)) {
354  QString message = text;
355  if (!strlist.isEmpty()) {
356  message += QLatin1Char('\n') + strlist.join(QLatin1Char('\n'));
357  }
358  notifyInterface()->sendNotification(notifyType, message, dialog->topLevelWidget());
359  }
360 #endif
361 
362  if (KMessageBox_exec_hook) {
363  return KMessageBox_exec_hook(dialog);
364  }
365 
366  if ((options & KMessageBox::NoExec)) {
367  return QDialogButtonBox::NoButton; // We have to return something.
368  }
369 
370  // We use a QPointer because the dialog may get deleted
371  // during exec() if the parent of the dialog gets deleted.
372  // In that case the QPointer will reset to 0.
373  QPointer<QDialog> guardedDialog = dialog;
374 
375  const QDialogButtonBox::StandardButton result = QDialogButtonBox::StandardButton(guardedDialog->exec());
376  if (checkbox && checkboxReturn) {
377  *checkboxReturn = checkbox->isChecked();
378  }
379 
380  delete guardedDialog;
381  return result;
382 }
383 
384 ButtonCode questionYesNo(QWidget *parent, const QString &text,
385  const QString &caption,
386  const KGuiItem &buttonYes,
387  const KGuiItem &buttonNo,
388  const QString &dontAskAgainName,
389  Options options)
390 {
391  return questionYesNoList(parent, text, QStringList(), caption,
392  buttonYes, buttonNo, dontAskAgainName, options);
393 }
394 
395 bool shouldBeShownYesNo(const QString &dontShowAgainName,
396  ButtonCode &result)
397 {
398  if (dontShowAgainName.isEmpty()) {
399  return true;
400  }
401  return dontAskAgainInterface()->shouldBeShownYesNo(dontShowAgainName, result);
402 }
403 
404 bool shouldBeShownContinue(const QString &dontShowAgainName)
405 {
406  if (dontShowAgainName.isEmpty()) {
407  return true;
408  }
409  return dontAskAgainInterface()->shouldBeShownContinue(dontShowAgainName);
410 }
411 
412 void saveDontShowAgainYesNo(const QString &dontShowAgainName,
413  ButtonCode result)
414 {
415  if (dontShowAgainName.isEmpty()) {
416  return;
417  }
418  dontAskAgainInterface()->saveDontShowAgainYesNo(dontShowAgainName, result);
419 }
420 
421 void saveDontShowAgainContinue(const QString &dontShowAgainName)
422 {
423  if (dontShowAgainName.isEmpty()) {
424  return;
425  }
426  dontAskAgainInterface()->saveDontShowAgainContinue(dontShowAgainName);
427 }
428 
429 void enableAllMessages()
430 {
431  dontAskAgainInterface()->enableAllMessages();
432 }
433 
434 void enableMessage(const QString &dontShowAgainName)
435 {
436  dontAskAgainInterface()->enableMessage(dontShowAgainName);
437 }
438 
439 void setDontShowAgainConfig(KConfig *cfg)
440 {
441  dontAskAgainInterface()->setConfig(cfg);
442 }
443 
444 static ButtonCode questionYesNoListInternal(QDialog *dialog, const QString &text,
445  const QStringList &strlist,
446  const QString &caption,
447  const KGuiItem &buttonYes_,
448  const KGuiItem &buttonNo_,
449  const QString &dontAskAgainName,
450  Options options)
451 {
452  ButtonCode res;
453  if (!shouldBeShownYesNo(dontAskAgainName, res)) {
454  delete dialog;
455  return res;
456  }
457 
458  I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
459  I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
460  I18N_POST_BUTTON_FILTER
461 
462  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Question") : caption);
463  dialog->setObjectName(QStringLiteral("questionYesNo"));
464 
465  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
466  buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
467  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes);
468  KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo);
469 
470  applyOptions(dialog, options);
471 
472  bool checkboxResult = false;
473  const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Question, text, strlist,
474  dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"),
475  &checkboxResult, options);
476  res = (result == QDialogButtonBox::Yes ? Yes : No);
477 
478  if (checkboxResult) {
479  saveDontShowAgainYesNo(dontAskAgainName, res);
480  }
481  return res;
482 }
483 
484 ButtonCode questionYesNoList(QWidget *parent, const QString &text,
485  const QStringList &strlist,
486  const QString &caption,
487  const KGuiItem &buttonYes,
488  const KGuiItem &buttonNo,
489  const QString &dontAskAgainName,
490  Options options)
491 {
492  return questionYesNoListInternal(new QDialog(parent), text, strlist, caption, buttonYes, buttonNo,
493  dontAskAgainName, options);
494 }
495 
496 static ButtonCode questionYesNoCancelInternal(QDialog *dialog,
497  const QString &text,
498  const QString &caption,
499  const KGuiItem &buttonYes_,
500  const KGuiItem &buttonNo_,
501  const KGuiItem &buttonCancel_,
502  const QString &dontAskAgainName,
503  Options options)
504 {
505  ButtonCode res;
506  if (!shouldBeShownYesNo(dontAskAgainName, res)) {
507  delete dialog;
508  return res;
509  }
510 
511  I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
512  I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
513  I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel)
514  I18N_POST_BUTTON_FILTER
515 
516  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Question") : caption);
517  dialog->setObjectName(QStringLiteral("questionYesNoCancel"));
518 
519  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
520  buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
521  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes);
522  KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo);
523  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), buttonCancel);
524 
525  applyOptions(dialog, options);
526 
527  bool checkboxResult = false;
528  const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Question,
529  text, QStringList(),
530  dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"),
531  &checkboxResult, options);
532 
533  if (result == QDialogButtonBox::Yes) {
534  res = Yes;
535  } else if (result == QDialogButtonBox::No) {
536  res = No;
537  } else {
538  return Cancel;
539  }
540 
541  if (checkboxResult) {
542  saveDontShowAgainYesNo(dontAskAgainName, res);
543  }
544  return res;
545 }
546 
547 ButtonCode questionYesNoCancel(QWidget *parent,
548  const QString &text,
549  const QString &caption,
550  const KGuiItem &buttonYes,
551  const KGuiItem &buttonNo,
552  const KGuiItem &buttonCancel,
553  const QString &dontAskAgainName,
554  Options options)
555 {
556  return questionYesNoCancelInternal(new QDialog(parent), text, caption, buttonYes, buttonNo, buttonCancel,
557  dontAskAgainName, options);
558 }
559 
560 ButtonCode warningYesNo(QWidget *parent, const QString &text,
561  const QString &caption,
562  const KGuiItem &buttonYes,
563  const KGuiItem &buttonNo,
564  const QString &dontAskAgainName,
565  Options options)
566 {
567  return warningYesNoList(parent, text, QStringList(), caption,
568  buttonYes, buttonNo, dontAskAgainName, options);
569 }
570 
571 static ButtonCode warningYesNoListInternal(QDialog *dialog, const QString &text,
572  const QStringList &strlist,
573  const QString &caption,
574  const KGuiItem &buttonYes_,
575  const KGuiItem &buttonNo_,
576  const QString &dontAskAgainName,
577  Options options)
578 {
579  ButtonCode res;
580  if (!shouldBeShownYesNo(dontAskAgainName, res)) {
581  delete dialog;
582  return res;
583  }
584 
585  I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
586  I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
587  I18N_POST_BUTTON_FILTER
588 
589  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Warning") : caption);
590  dialog->setObjectName(QStringLiteral("warningYesNoList"));
591 
592  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
593  buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
594  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes);
595  KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo);
596 
597  applyOptions(dialog, options);
598 
599  bool checkboxResult = false;
600  const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, strlist,
601  dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"),
602  &checkboxResult, options);
603  res = (result == QDialogButtonBox::Yes ? Yes : No);
604 
605  if (checkboxResult) {
606  saveDontShowAgainYesNo(dontAskAgainName, res);
607  }
608  return res;
609 }
610 
611 ButtonCode warningYesNoList(QWidget *parent, const QString &text,
612  const QStringList &strlist,
613  const QString &caption,
614  const KGuiItem &buttonYes,
615  const KGuiItem &buttonNo,
616  const QString &dontAskAgainName,
617  Options options)
618 {
619  return warningYesNoListInternal(new QDialog(parent), text, strlist, caption, buttonYes, buttonNo,
620  dontAskAgainName, options);
621 }
622 
623 ButtonCode warningContinueCancel(QWidget *parent,
624  const QString &text,
625  const QString &caption,
626  const KGuiItem &buttonContinue,
627  const KGuiItem &buttonCancel,
628  const QString &dontAskAgainName,
629  Options options)
630 {
631  return warningContinueCancelList(parent, text, QStringList(), caption,
632  buttonContinue, buttonCancel, dontAskAgainName, options);
633 }
634 
635 static ButtonCode warningContinueCancelListInternal(QDialog *dialog, const QString &text,
636  const QStringList &strlist,
637  const QString &caption,
638  const KGuiItem &buttonContinue_,
639  const KGuiItem &buttonCancel_,
640  const QString &dontAskAgainName,
641  Options options,
642  const QString &details)
643 {
644  if (!shouldBeShownContinue(dontAskAgainName)) {
645  delete dialog;
646  return Continue;
647  }
648 
649  I18N_FILTER_BUTTON_CONTINUE(buttonContinue_, buttonContinue)
650  I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel)
651  I18N_POST_BUTTON_FILTER
652 
653  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Warning") : caption);
654  dialog->setObjectName(QStringLiteral("warningYesNo"));
655 
656  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
657  buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
658  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonContinue);
659  KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonCancel);
660 
661  applyOptions(dialog, options);
662 
663  bool checkboxResult = false;
664  const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, strlist,
665  dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"),
666  &checkboxResult, options, details);
667 
668  if (result != QDialogButtonBox::Yes) {
669  return Cancel;
670  }
671  if (checkboxResult) {
672  saveDontShowAgainContinue(dontAskAgainName);
673  }
674  return Continue;
675 }
676 
677 ButtonCode warningContinueCancelList(QWidget *parent, const QString &text,
678  const QStringList &strlist,
679  const QString &caption,
680  const KGuiItem &buttonContinue,
681  const KGuiItem &buttonCancel,
682  const QString &dontAskAgainName,
683  Options options)
684 {
685  return warningContinueCancelListInternal(new QDialog(parent), text, strlist, caption, buttonContinue, buttonCancel,
686  dontAskAgainName, options, QString());
687 }
688 
689 
690 ButtonCode warningContinueCancelDetailed(QWidget *parent,
691  const QString &text,
692  const QString &caption,
693  const KGuiItem &buttonContinue,
694  const KGuiItem &buttonCancel,
695  const QString &dontAskAgainName,
696  Options options,
697  const QString &details)
698 {
699  return warningContinueCancelListInternal(new QDialog(parent), text, QStringList(), caption,
700  buttonContinue, buttonCancel, dontAskAgainName, options, details);
701 }
702 
703 ButtonCode warningYesNoCancel(QWidget *parent, const QString &text,
704  const QString &caption,
705  const KGuiItem &buttonYes,
706  const KGuiItem &buttonNo,
707  const KGuiItem &buttonCancel,
708  const QString &dontAskAgainName,
709  Options options)
710 {
711  return warningYesNoCancelList(parent, text, QStringList(), caption,
712  buttonYes, buttonNo, buttonCancel, dontAskAgainName, options);
713 }
714 
715 static ButtonCode warningYesNoCancelListInternal(QDialog *dialog, const QString &text,
716  const QStringList &strlist,
717  const QString &caption,
718  const KGuiItem &buttonYes_,
719  const KGuiItem &buttonNo_,
720  const KGuiItem &buttonCancel_,
721  const QString &dontAskAgainName,
722  Options options)
723 {
724  ButtonCode res;
725  if (!shouldBeShownYesNo(dontAskAgainName, res)) {
726  delete dialog;
727  return res;
728  }
729 
730  I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
731  I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
732  I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel)
733  I18N_POST_BUTTON_FILTER
734 
735  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Warning") : caption);
736  dialog->setObjectName(QStringLiteral("warningYesNoCancel"));
737 
738  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
739  buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
740  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes);
741  KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo);
742  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), buttonCancel);
743 
744  applyOptions(dialog, options);
745 
746  bool checkboxResult = false;
747  const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, strlist,
748  dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"),
749  &checkboxResult, options);
750 
751  if (result == QDialogButtonBox::Yes) {
752  res = Yes;
753  } else if (result == QDialogButtonBox::No) {
754  res = No;
755  } else {
756  return Cancel;
757  }
758 
759  if (checkboxResult) {
760  saveDontShowAgainYesNo(dontAskAgainName, res);
761  }
762  return res;
763 }
764 
765 ButtonCode warningYesNoCancelList(QWidget *parent, const QString &text,
766  const QStringList &strlist,
767  const QString &caption,
768  const KGuiItem &buttonYes,
769  const KGuiItem &buttonNo,
770  const KGuiItem &buttonCancel,
771  const QString &dontAskAgainName,
772  Options options)
773 {
774  return warningYesNoCancelListInternal(new QDialog(parent), text, strlist, caption, buttonYes, buttonNo, buttonCancel,
775  dontAskAgainName, options);
776 }
777 
778 void error(QWidget *parent, const QString &text,
779  const QString &caption, Options options)
780 {
781  errorList(parent, text, QStringList(), caption, options);
782 }
783 
784 static void errorListInternal(QDialog *dialog, const QString &text, const QStringList &strlist,
785  const QString &caption, Options options)
786 {
787  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Error") : caption);
788  dialog->setObjectName(QStringLiteral("error"));
789 
790  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
792 
793  applyOptions(dialog, options);
794 
795  createKMessageBox(dialog, buttonBox, QMessageBox::Critical, text, strlist, QString(), nullptr, options);
796 }
797 
798 void errorList(QWidget *parent, const QString &text, const QStringList &strlist,
799  const QString &caption, Options options)
800 {
801  errorListInternal(new QDialog(parent), text, strlist, caption, options);
802 }
803 
804 static void detailedErrorInternal(QDialog *dialog, const QString &text,
805  const QString &details,
806  const QString &caption, Options options)
807 {
808  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Error") : caption);
809  dialog->setObjectName(QStringLiteral("error"));
810 
811  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
812  buttonBox->addButton(QDialogButtonBox::Ok);
813  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
814 
815  applyOptions(dialog, options);
816 
817  createKMessageBox(dialog, buttonBox, QMessageBox::Critical, text, QStringList(), QString(), nullptr, options, details);
818 }
819 
820 void detailedError(QWidget *parent, const QString &text,
821  const QString &details,
822  const QString &caption, Options options)
823 {
824  detailedErrorInternal(new QDialog(parent), text, details, caption, options);
825 }
826 
827 static void sorryInternal(QDialog *dialog, const QString &text,
828  const QString &caption,
829  const KGuiItem &buttonOk_,
830  Options options)
831 {
832  I18N_FILTER_BUTTON_YES(buttonOk_, buttonOk)
833  I18N_POST_BUTTON_FILTER
834 
835  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption);
836  dialog->setObjectName(QStringLiteral("sorry"));
837 
838  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
839  buttonBox->setStandardButtons(QDialogButtonBox::Ok);
840  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), buttonOk);
841 
842  applyOptions(dialog, options);
843 
844  createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, QStringList(), QString(), nullptr, options);
845 }
846 
847 void sorry(QWidget *parent, const QString &text,
848  const QString &caption, Options options)
849 {
850  sorryInternal(new QDialog(parent), text, caption, KStandardGuiItem::ok(), options);
851 }
852 
853 void sorry(QWidget *parent, const QString &text,
854  const QString &caption, const KGuiItem &item, Options options)
855 {
856  sorryInternal(new QDialog(parent), text, caption, item, options);
857 }
858 
859 static void detailedSorryInternal(QDialog *dialog, const QString &text,
860  const QString &details,
861  const QString &caption,
862  const KGuiItem &buttonOk_,
863  Options options)
864 {
865  I18N_FILTER_BUTTON_YES(buttonOk_, buttonOk)
866  I18N_POST_BUTTON_FILTER
867 
868  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption);
869  dialog->setObjectName(QStringLiteral("sorry"));
870 
871  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
872  buttonBox->addButton(QDialogButtonBox::Ok);
873  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
874  KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), buttonOk);
875 
876  applyOptions(dialog, options);
877 
878  createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, QStringList(), QString(), nullptr, options, details);
879 }
880 
881 void detailedSorry(QWidget *parent, const QString &text,
882  const QString &details,
883  const QString &caption, Options options)
884 {
885  detailedSorryInternal(new QDialog(parent), text, details, caption, KStandardGuiItem::ok(), options);
886 }
887 
888 void detailedSorry(QWidget *parent, const QString &text,
889  const QString &details,
890  const QString &caption,
891  const KGuiItem &buttonOk,
892  Options options)
893 {
894  detailedSorryInternal(new QDialog(parent), text, details, caption, buttonOk, options);
895 }
896 
897 void information(QWidget *parent, const QString &text,
898  const QString &caption, const QString &dontShowAgainName, Options options)
899 {
900  informationList(parent, text, QStringList(), caption, dontShowAgainName, options);
901 }
902 
903 static void informationListInternal(QDialog *dialog, const QString &text, const QStringList &strlist,
904  const QString &caption, const QString &dontShowAgainName, Options options)
905 {
906  if (!shouldBeShownContinue(dontShowAgainName)) {
907  delete dialog;
908  return;
909  }
910 
911  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Information") : caption);
912  dialog->setObjectName(QStringLiteral("information"));
913 
914  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
916 
917  applyOptions(dialog, options);
918 
919  bool checkboxResult = false;
920 
921  createKMessageBox(dialog, buttonBox, QMessageBox::Information, text, strlist,
922  dontShowAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not show this message again"),
923  &checkboxResult, options);
924 
925  if (checkboxResult) {
926  saveDontShowAgainContinue(dontShowAgainName);
927  }
928 }
929 
930 void informationList(QWidget *parent, const QString &text, const QStringList &strlist,
931  const QString &caption, const QString &dontShowAgainName, Options options)
932 {
933  informationListInternal(new QDialog(parent), text, strlist, caption, dontShowAgainName, options);
934 }
935 
936 void about(QWidget *parent, const QString &text,
937  const QString &caption, Options options)
938 {
939  QDialog *dialog = new QDialog(parent, Qt::Dialog);
940  if (!caption.isEmpty()) {
941  dialog->setWindowTitle(caption);
942  }
943  dialog->setObjectName(QStringLiteral("about"));
944 
945  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
947 
948  applyOptions(dialog, options);
949 
950  if (qApp->windowIcon().isNull()) {
952  dialog->setWindowIcon(ret);
953  }
954 
955  createKMessageBox(dialog, buttonBox, qApp->windowIcon(), text, QStringList(), QString(), nullptr, options);
956 }
957 
958 static ButtonCode messageBoxInternal(QDialog *dialog, DialogType type, const QString &text,
959  const QString &caption, const KGuiItem &buttonYes,
960  const KGuiItem &buttonNo, const KGuiItem &buttonCancel,
961  const QString &dontShow, Options options)
962 {
963  switch (type) {
964  case QuestionYesNo:
965  return questionYesNoListInternal(dialog, text, QStringList(), caption,
966  buttonYes, buttonNo, dontShow, options);
967  case QuestionYesNoCancel:
968  return questionYesNoCancelInternal(dialog, text, caption,
969  buttonYes, buttonNo, buttonCancel, dontShow, options);
970  case WarningYesNo:
971  return warningYesNoListInternal(dialog, text, QStringList(), caption,
972  buttonYes, buttonNo, dontShow, options);
973  case WarningContinueCancel:
974  return warningContinueCancelListInternal(dialog, text, QStringList(), caption,
975  KGuiItem(buttonYes.text()), buttonCancel, dontShow, options, QString());
976  case WarningYesNoCancel:
977  return warningYesNoCancelListInternal(dialog, text, QStringList(), caption,
978  buttonYes, buttonNo, buttonCancel, dontShow, options);
979  case Information:
980  informationListInternal(dialog, text, QStringList(), caption, dontShow, options);
981  return KMessageBox::Ok;
982 
983  case Error:
984  errorListInternal(dialog, text, QStringList(), caption, options);
985  return KMessageBox::Ok;
986 
987  case Sorry:
988  sorryInternal(dialog, text, caption, KStandardGuiItem::ok(), options);
989  return KMessageBox::Ok;
990  }
991  return KMessageBox::Cancel;
992 }
993 
994 ButtonCode messageBox(QWidget *parent, DialogType type, const QString &text,
995  const QString &caption, const KGuiItem &buttonYes,
996  const KGuiItem &buttonNo, const KGuiItem &buttonCancel,
997  const QString &dontShow, Options options)
998 {
999  return messageBoxInternal(new QDialog(parent), type, text, caption,
1000  buttonYes, buttonNo, buttonCancel, dontShow, options);
1001 }
1002 
1003 ButtonCode questionYesNoWId(WId parent_id, const QString &text,
1004  const QString &caption,
1005  const KGuiItem &buttonYes,
1006  const KGuiItem &buttonNo,
1007  const QString &dontAskAgainName,
1008  Options options)
1009 {
1010  return questionYesNoListWId(parent_id, text, QStringList(), caption,
1011  buttonYes, buttonNo, dontAskAgainName, options);
1012 }
1013 
1014 ButtonCode questionYesNoListWId(WId parent_id, const QString &text,
1015  const QStringList &strlist,
1016  const QString &caption,
1017  const KGuiItem &buttonYes,
1018  const KGuiItem &buttonNo,
1019  const QString &dontAskAgainName,
1020  Options options)
1021 {
1022  return questionYesNoListInternal(createWIdDialog(parent_id), text, strlist, caption, buttonYes, buttonNo,
1023  dontAskAgainName, options);
1024 }
1025 
1026 ButtonCode questionYesNoCancelWId(WId parent_id,
1027  const QString &text,
1028  const QString &caption,
1029  const KGuiItem &buttonYes,
1030  const KGuiItem &buttonNo,
1031  const KGuiItem &buttonCancel,
1032  const QString &dontAskAgainName,
1033  Options options)
1034 {
1035  return questionYesNoCancelInternal(createWIdDialog(parent_id), text, caption, buttonYes, buttonNo, buttonCancel,
1036  dontAskAgainName, options);
1037 }
1038 
1039 ButtonCode warningYesNoWId(WId parent_id, const QString &text,
1040  const QString &caption,
1041  const KGuiItem &buttonYes,
1042  const KGuiItem &buttonNo,
1043  const QString &dontAskAgainName,
1044  Options options)
1045 {
1046  return warningYesNoListWId(parent_id, text, QStringList(), caption,
1047  buttonYes, buttonNo, dontAskAgainName, options);
1048 }
1049 
1050 ButtonCode warningYesNoListWId(WId parent_id, const QString &text,
1051  const QStringList &strlist,
1052  const QString &caption,
1053  const KGuiItem &buttonYes,
1054  const KGuiItem &buttonNo,
1055  const QString &dontAskAgainName,
1056  Options options)
1057 {
1058  return warningYesNoListInternal(createWIdDialog(parent_id), text, strlist, caption, buttonYes, buttonNo,
1059  dontAskAgainName, options);
1060 }
1061 
1062 ButtonCode warningContinueCancelWId(WId parent_id,
1063  const QString &text,
1064  const QString &caption,
1065  const KGuiItem &buttonContinue,
1066  const KGuiItem &buttonCancel,
1067  const QString &dontAskAgainName,
1068  Options options)
1069 {
1070  return warningContinueCancelListWId(parent_id, text, QStringList(), caption,
1071  buttonContinue, buttonCancel, dontAskAgainName, options);
1072 }
1073 
1074 ButtonCode warningContinueCancelListWId(WId parent_id, const QString &text,
1075  const QStringList &strlist,
1076  const QString &caption,
1077  const KGuiItem &buttonContinue,
1078  const KGuiItem &buttonCancel,
1079  const QString &dontAskAgainName,
1080  Options options)
1081 {
1082  return warningContinueCancelListInternal(createWIdDialog(parent_id), text, strlist, caption, buttonContinue, buttonCancel,
1083  dontAskAgainName, options, QString());
1084 }
1085 
1086 ButtonCode warningYesNoCancelWId(WId parent_id, const QString &text,
1087  const QString &caption,
1088  const KGuiItem &buttonYes,
1089  const KGuiItem &buttonNo,
1090  const KGuiItem &buttonCancel,
1091  const QString &dontAskAgainName,
1092  Options options)
1093 {
1094  return warningYesNoCancelListWId(parent_id, text, QStringList(), caption,
1095  buttonYes, buttonNo, buttonCancel, dontAskAgainName, options);
1096 }
1097 
1098 ButtonCode warningYesNoCancelListWId(WId parent_id, const QString &text,
1099  const QStringList &strlist,
1100  const QString &caption,
1101  const KGuiItem &buttonYes,
1102  const KGuiItem &buttonNo,
1103  const KGuiItem &buttonCancel,
1104  const QString &dontAskAgainName,
1105  Options options)
1106 {
1107  return warningYesNoCancelList(createWIdDialog(parent_id), text, strlist, caption, buttonYes, buttonNo, buttonCancel,
1108  dontAskAgainName, options);
1109 }
1110 
1111 void errorWId(WId parent_id, const QString &text,
1112  const QString &caption, Options options)
1113 {
1114  errorListWId(parent_id, text, QStringList(), caption, options);
1115 }
1116 
1117 void errorListWId(WId parent_id, const QString &text, const QStringList &strlist,
1118  const QString &caption, Options options)
1119 {
1120  errorListInternal(createWIdDialog(parent_id), text, strlist, caption, options);
1121 }
1122 
1123 void detailedErrorWId(WId parent_id, const QString &text,
1124  const QString &details,
1125  const QString &caption, Options options)
1126 {
1127  detailedErrorInternal(createWIdDialog(parent_id), text, details, caption, options);
1128 }
1129 
1130 void sorryWId(WId parent_id, const QString &text,
1131  const QString &caption, Options options)
1132 {
1133  QWidget *parent = QWidget::find(parent_id);
1134  QDialog *dialog = new QDialog(parent, Qt::Dialog);
1135  dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption);
1136  dialog->setObjectName(QStringLiteral("sorry"));
1137 
1138  QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
1140 
1141  applyOptions(dialog, options);
1142  if (parent == nullptr && parent_id) {
1143  setMainWindow(dialog, parent_id);
1144  }
1145 
1146  createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, QStringList(), QString(), nullptr, options);
1147 }
1148 
1149 void detailedSorryWId(WId parent_id, const QString &text,
1150  const QString &details,
1151  const QString &caption, Options options)
1152 {
1153  detailedSorryInternal(createWIdDialog(parent_id), text, details, caption, KStandardGuiItem::ok(), options);
1154 }
1155 
1156 void detailedSorryWId(WId parent_id, const QString &text,
1157  const QString &details,
1158  const QString &caption,
1159  const KGuiItem &buttonOk,
1160  Options options)
1161 {
1162  detailedSorryInternal(createWIdDialog(parent_id), text, details, caption, buttonOk, options);
1163 }
1164 
1165 void informationWId(WId parent_id, const QString &text,
1166  const QString &caption, const QString &dontShowAgainName, Options options)
1167 {
1168  informationListWId(parent_id, text, QStringList(), caption, dontShowAgainName, options);
1169 }
1170 
1171 void informationListWId(WId parent_id, const QString &text, const QStringList &strlist,
1172  const QString &caption, const QString &dontShowAgainName, Options options)
1173 {
1174  informationListInternal(createWIdDialog(parent_id), text, strlist, caption, dontShowAgainName, options);
1175 }
1176 
1177 ButtonCode messageBoxWId(WId parent_id, DialogType type, const QString &text,
1178  const QString &caption, const KGuiItem &buttonYes,
1179  const KGuiItem &buttonNo, const KGuiItem &buttonCancel,
1180  const QString &dontShow, Options options)
1181 {
1182  return messageBoxInternal(createWIdDialog(parent_id), type, text, caption,
1183  buttonYes, buttonNo, buttonCancel, dontShow, options);
1184 }
1185 
1186 } // namespace
1187 
1188 #include "kmessagebox.moc"
KCOREADDONS_EXPORT void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
void setWidget(QWidget *widget)
void setContentsMargins(int left, int top, int right, int bottom)
int width() const const
void setModal(bool modal)
void setSelectionMode(QAbstractItemView::SelectionMode mode)
virtual QSize sizeHint() const const override
void setColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QColor &color)
KGuiItem ok()
Returns the &#39;Ok&#39; gui item.
The window is to be modal relative to its parent. By default, it is application modal.
Definition: kmessagebox.h:79
void setWindowModality(Qt::WindowModality windowModality)
void setFrameShape(QFrame::Shape)
QStyle * style() const const
void addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role)
void setSizeConstraint(QLayout::SizeConstraint)
virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const const =0
void setPixmap(const QPixmap &)
void setMinimumWidth(int minw)
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QWidget * viewport() const const
int height() const const
void addSpacing(int size)
void setParent(QWidget *parent)
QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) const const
void setWindowIcon(const QIcon &icon)
void initFrom(const QWidget *widget)
void setMinimumSize(const QSize &)
bool isEnabled() const const
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setLayout(QLayout *layout)
QWidget * topLevelWidget() const const
QFlags< Option > Options
Stores a combination of Option values.
Definition: kmessagebox.h:85
Q_OBJECTQ_OBJECT
void setFocus()
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:31
ButtonCode
Button types.
Definition: kmessagebox.h:50
bool isEmpty() const const
void setObjectName(const QString &name)
QPixmap standardIcon(QMessageBox::Icon icon)
bool isEmpty() const const
Emit a KNotify event.
Definition: kmessagebox.h:74
void deleteLater()
virtual QSize sizeHint() const const override
typedef TextInteractionFlags
QScrollBar * verticalScrollBar() const const
void setSizePolicy(QSizePolicy)
A replacement for QLabel that squeezes its text into the label.
The message may contain links.
Definition: kmessagebox.h:75
virtual QIcon standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const const =0
void setFixedSize(const QSize &s)
void setWidgetResizable(bool resizable)
QWindow * windowHandle() const const
WA_NativeWindow
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
PM_LayoutVerticalSpacing
int width() const const
QFontMetrics fontMetrics() const const
void addItems(const QStringList &labels)
QStyle * style()
void setStandardButtons(QDialogButtonBox::StandardButtons buttons)
QDesktopWidget * desktop()
void addStretch(int stretch)
bool isNull() const const
QWidget * find(WId id)
void setWindowTitle(const QString &)
Do not call exec() in createKMessageBox()
Definition: kmessagebox.h:78
virtual QSize sizeHint() const const override
int height() const const
int length() const const
void setMinimumHeight(int minh)
SP_MessageBoxInformation
QPushButton * button(QDialogButtonBox::StandardButton which) const const
void setReadOnly(bool ro)
WindowModal
transparent
Q_SLOTSQ_SLOTS
void clicked(QAbstractButton *button)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
The action to be confirmed by the dialog is a potentially destructive one. The default button will be...
Definition: kmessagebox.h:76
QWindow * fromWinId(WId id)
A groupbox featuring a clickable header and arrow indicator that can be expanded and collapsed to rev...
void setText(const QString &text)
void setDefault(bool)
void setWordWrap(bool on)
void setTitle(const QString &title)
Set the title that will be permanently shown at the top of the collapsing box Mnemonics are supported...
void destroyed(QObject *obj)
bool setStretchFactor(QWidget *widget, int stretch)
int lineSpacing() const const
void setSpacing(int spacing)
const QRect screenGeometry(const QWidget *widget) const const
void addLayout(QLayout *layout, int stretch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 25 2020 22:44:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.