qmessagebox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qmessagebox.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11enum Button { Old_Ok = 1, Old_Cancel = 2, Old_Yes = 3, Old_No = 4, Old_Abort = 5, Old_Retry = 6,-
12 Old_Ignore = 7, Old_YesAll = 8, Old_NoAll = 9, Old_ButtonMask = 0xFF,-
13 NewButtonMask = 0xFFFFFC00 };-
14-
15enum DetailButtonLabel { ShowLabel = 0, HideLabel = 1 };-
16-
17class QMessageBoxDetailsText : public QWidget-
18{-
19 public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; }-
20#pragma GCC diagnostic push-
21 static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **);-
22#pragma GCC diagnostic pop-
23 struct QPrivateSignal {};-
24public:-
25 class TextEdit : public QTextEdit-
26 {-
27 public:-
28 TextEdit(QWidget *parent=0) : QTextEdit(parent) { }-
29-
30 void contextMenuEvent(QContextMenuEvent * e) override-
31 {-
32 QMenu *menu = createStandardContextMenu();-
33 menu->setAttribute(Qt::WA_DeleteOnClose);-
34 menu->popup(e->globalPos());-
35 }
never executed: end of block
0
36-
37 };-
38-
39 QMessageBoxDetailsText(QWidget *parent=0)-
40 : QWidget(parent)-
41 , copyAvailable(false)-
42 {-
43 QVBoxLayout *layout = new QVBoxLayout;-
44 layout->setMargin(0);-
45 QFrame *line = new QFrame(this);-
46 line->setFrameShape(QFrame::HLine);-
47 line->setFrameShadow(QFrame::Sunken);-
48 layout->addWidget(line);-
49 textEdit = new TextEdit();-
50 textEdit->setFixedHeight(100);-
51 textEdit->setFocusPolicy(Qt::NoFocus);-
52 textEdit->setReadOnly(true);-
53 layout->addWidget(textEdit);-
54 setLayout(layout);-
55-
56 connect(textEdit, qFlagLocation("2""copyAvailable(bool)" "\0" __FILE__ ":" "121""125"),-
57 this, qFlagLocation("1""textCopyAvailable(bool)" "\0" __FILE__ ":" "122""126"));-
58 }-
59 void setText(const QString &text) { textEdit->setPlainText(text); }-
60 QString text() const { return textEdit->toPlainText(); }-
61-
62 bool copy()-
63 {-
64-
65-
66-
67 if (!copyAvailable)-
68 return false;-
69 textEdit->copy();-
70 return true;-
71-
72 }-
73-
74 void selectAll()-
75 {-
76 textEdit->selectAll();-
77 }-
78-
79private :-
80 void textCopyAvailable(bool available)-
81 {-
82 copyAvailable = available;-
83 }-
84-
85private:-
86 bool copyAvailable;-
87 TextEdit *textEdit;-
88};-
89-
90-
91class DetailButton : public QPushButton-
92{-
93public:-
94 DetailButton(QWidget *parent) : QPushButton(label(ShowLabel), parent)-
95 {-
96 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);-
97 }-
98-
99 QString label(DetailButtonLabel label) const-
100 { return label == ShowLabel ? QMessageBox::tr("Show Details...") : QMessageBox::tr("Hide Details..."); }-
101-
102 void setLabel(DetailButtonLabel lbl)-
103 { setText(label(lbl)); }-
104-
105 QSize sizeHint() const override-
106 {-
107 ensurePolished();-
108 QStyleOptionButton opt;-
109 initStyleOption(&opt);-
110 const QFontMetrics fm = fontMetrics();-
111 opt.text = label(ShowLabel);-
112 QSize sz = fm.size(Qt::TextShowMnemonic, opt.text);-
113 QSize ret = style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this).-
114 expandedTo(QApplication::globalStrut());-
115 opt.text = label(HideLabel);-
116 sz = fm.size(Qt::TextShowMnemonic, opt.text);-
117 ret = ret.expandedTo(style()->sizeFromContents(QStyle::CT_PushButton, &opt, sz, this).-
118 expandedTo(QApplication::globalStrut()));-
119 return ret;-
120 }-
121};-
122-
123class QMessageBoxPrivate : public QDialogPrivate-
124{-
125 inline QMessageBox* q_func() { return static_cast<QMessageBox *>(q_ptr); } inline const QMessageBox* q_func() const { return static_cast<const QMessageBox *>(q_ptr); } friend class QMessageBox;-
126-
127public:-
128 QMessageBoxPrivate() : escapeButton(0), defaultButton(0), checkbox(0), clickedButton(0), detailsButton(0),-
129-
130 detailsText(0),-
131-
132 compatMode(false), autoAddOkButton(true),-
133 detectedEscapeButton(0), informativeLabel(0),-
134 options(new QMessageDialogOptions) { }-
135-
136 void init(const QString &title = QString(), const QString &text = QString());-
137 void setupLayout();-
138 void _q_buttonClicked(QAbstractButton *);-
139 void _q_clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role);-
140-
141 QAbstractButton *findButton(int button0, int button1, int button2, int flags);-
142 void addOldButtons(int button0, int button1, int button2);-
143-
144 QAbstractButton *abstractButtonForId(int id) const;-
145 int execReturnCode(QAbstractButton *button);-
146-
147 void detectEscapeButton();-
148 void updateSize();-
149 int layoutMinimumWidth();-
150 void retranslateStrings();-
151-
152-
153-
154-
155 static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,-
156 const QString &title, const QString &text,-
157 int button0, int button1, int button2);-
158 static int showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,-
159 const QString &title, const QString &text,-
160 const QString &button0Text,-
161 const QString &button1Text,-
162 const QString &button2Text,-
163 int defaultButtonNumber,-
164 int escapeButtonNumber);-
165-
166 static QMessageBox::StandardButton showNewMessageBox(QWidget *parent,-
167 QMessageBox::Icon icon, const QString& title, const QString& text,-
168 QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton);-
169-
170 static QPixmap standardIcon(QMessageBox::Icon icon, QMessageBox *mb);-
171-
172 QLabel *label;-
173 QMessageBox::Icon icon;-
174 QLabel *iconLabel;-
175 QDialogButtonBox *buttonBox;-
176 QList<QAbstractButton *> customButtonList;-
177 QAbstractButton *escapeButton;-
178 QPushButton *defaultButton;-
179 QCheckBox *checkbox;-
180 QAbstractButton *clickedButton;-
181 DetailButton *detailsButton;-
182-
183 QMessageBoxDetailsText *detailsText;-
184-
185 bool compatMode;-
186 bool autoAddOkButton;-
187 QAbstractButton *detectedEscapeButton;-
188 QLabel *informativeLabel;-
189 QPointer<QObject> receiverToDisconnectOnClose;-
190 QByteArray memberToDisconnectOnClose;-
191 QByteArray signalToDisconnectOnClose;-
192 QSharedPointer<QMessageDialogOptions> options;-
193private:-
194 void initHelper(QPlatformDialogHelper *) override;-
195 void helperPrepareShow(QPlatformDialogHelper *) override;-
196 void helperDone(QDialog::DialogCode, QPlatformDialogHelper *) override;-
197};-
198-
199void QMessageBoxPrivate::init(const QString &title, const QString &text)-
200{-
201 QMessageBox * const q = q_func();-
202-
203 label = new QLabel;-
204 label->setObjectName(QLatin1String("qt_msgbox_label"));-
205 label->setTextInteractionFlags(Qt::TextInteractionFlags(q->style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, q)));-
206 label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);-
207 label->setOpenExternalLinks(true);-
208 iconLabel = new QLabel(q);-
209 iconLabel->setObjectName(QLatin1String("qt_msgboxex_icon_label"));-
210 iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);-
211-
212 buttonBox = new QDialogButtonBox;-
213 buttonBox->setObjectName(QLatin1String("qt_msgbox_buttonbox"));-
214 buttonBox->setCenterButtons(q->style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, q));-
215 QObject::connect(buttonBox, qFlagLocation("2""clicked(QAbstractButton*)" "\0" __FILE__ ":" "280""284"),-
216 q, qFlagLocation("1""_q_buttonClicked(QAbstractButton*)" "\0" __FILE__ ":" "281""285"));-
217 setupLayout();-
218 if (!title.isEmpty() || !text.isEmpty()) {-
219 q->setWindowTitle(title);-
220 q->setText(text);-
221 }-
222 q->setModal(true);-
223-
224-
225-
226-
227-
228 icon = QMessageBox::NoIcon;-
229}-
230-
231void QMessageBoxPrivate::setupLayout()-
232{-
233 QMessageBox * const q = q_func();-
234 delete q->layout();-
235 QGridLayout *grid = new QGridLayout;-
236 bool hasIcon = iconLabel->pixmap() && !iconLabel->pixmap()->isNull();-
237-
238 if (hasIcon)-
239 grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop);-
240 iconLabel->setVisible(hasIcon);-
241-
242-
243-
244 QSpacerItem *indentSpacer = new QSpacerItem(hasIcon ? 7 : 15, 1, QSizePolicy::Fixed, QSizePolicy::Fixed);-
245-
246 grid->addItem(indentSpacer, 0, hasIcon ? 1 : 0, 2, 1);-
247 grid->addWidget(label, 0, hasIcon ? 2 : 1, 1, 1);-
248 if (informativeLabel) {-
249-
250 informativeLabel->setContentsMargins(0, 7, 0, 7);-
251-
252 grid->addWidget(informativeLabel, 1, hasIcon ? 2 : 1, 1, 1);-
253 }-
254 if (checkbox) {-
255 grid->addWidget(checkbox, informativeLabel ? 2 : 1, hasIcon ? 2 : 1, 1, 1, Qt::AlignLeft);-
256-
257-
258-
259 grid->addItem(new QSpacerItem(1, 7, QSizePolicy::Fixed, QSizePolicy::Fixed), grid->rowCount(), 0);-
260-
261 }-
262 grid->addWidget(buttonBox, grid->rowCount(), 0, 1, grid->columnCount());-
263-
264 if (detailsText)-
265 grid->addWidget(detailsText, grid->rowCount(), 0, 1, grid->columnCount());-
266 grid->setSizeConstraint(QLayout::SetNoConstraint);-
267 q->setLayout(grid);-
268-
269 retranslateStrings();-
270 updateSize();-
271}-
272-
273int QMessageBoxPrivate::layoutMinimumWidth()-
274{-
275 layout->activate();-
276 return layout->totalMinimumSize().width();-
277}-
278-
279void QMessageBoxPrivate::updateSize()-
280{-
281 QMessageBox * const q = q_func();-
282-
283 if (!q->isVisible())-
284 return;-
285-
286 QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();-
287-
288-
289-
290-
291 int hardLimit = qMin(screenSize.width() - 480, 1000);-
292-
293 if (screenSize.width() <= 1024)-
294 hardLimit = screenSize.width();-
295-
296-
297-
298-
299-
300-
301 int softLimit = qMin(screenSize.width()/2, 500);-
302-
303-
304-
305-
306-
307 if (informativeLabel)-
308 informativeLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);-
309-
310 label->setWordWrap(false);-
311 int width = layoutMinimumWidth();-
312-
313 if (width > softLimit) {-
314 label->setWordWrap(true);-
315 width = qMax(softLimit, layoutMinimumWidth());-
316-
317 if (width > hardLimit) {-
318 label->d_func()->ensureTextControl();-
319 if (QWidgetTextControl *control = label->d_func()->control) {-
320 QTextOption opt = control->document()->defaultTextOption();-
321 opt.setWrapMode(QTextOption::WrapAnywhere);-
322 control->document()->setDefaultTextOption(opt);-
323 }-
324 width = hardLimit;-
325 }-
326 }-
327-
328 if (informativeLabel) {-
329 label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);-
330 QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Preferred);-
331 policy.setHeightForWidth(true);-
332 informativeLabel->setSizePolicy(policy);-
333 width = qMax(width, layoutMinimumWidth());-
334 if (width > hardLimit) {-
335 informativeLabel->d_func()->ensureTextControl();-
336 if (QWidgetTextControl *control = informativeLabel->d_func()->control) {-
337 QTextOption opt = control->document()->defaultTextOption();-
338 opt.setWrapMode(QTextOption::WrapAnywhere);-
339 control->document()->setDefaultTextOption(opt);-
340 }-
341 width = hardLimit;-
342 }-
343 policy.setHeightForWidth(label->wordWrap());-
344 label->setSizePolicy(policy);-
345 }-
346-
347 QFontMetrics fm(QApplication::font("QMdiSubWindowTitleBar"));-
348 int windowTitleWidth = qMin(fm.width(q->windowTitle()) + 50, hardLimit);-
349 if (windowTitleWidth > width)-
350 width = windowTitleWidth;-
351-
352 layout->activate();-
353 int height = (layout->hasHeightForWidth())-
354 ? layout->totalHeightForWidth(width)-
355 : layout->totalMinimumSize().height();-
356-
357 q->setFixedSize(width, height);-
358 QCoreApplication::removePostedEvents(q, QEvent::LayoutRequest);-
359}-
360static int oldButton(int button)-
361{-
362 switch (button & QMessageBox::ButtonMask) {-
363 case QMessageBox::Ok:-
364 return Old_Ok;-
365 case QMessageBox::Cancel:-
366 return Old_Cancel;-
367 case QMessageBox::Yes:-
368 return Old_Yes;-
369 case QMessageBox::No:-
370 return Old_No;-
371 case QMessageBox::Abort:-
372 return Old_Abort;-
373 case QMessageBox::Retry:-
374 return Old_Retry;-
375 case QMessageBox::Ignore:-
376 return Old_Ignore;-
377 case QMessageBox::YesToAll:-
378 return Old_YesAll;-
379 case QMessageBox::NoToAll:-
380 return Old_NoAll;-
381 default:-
382 return 0;-
383 }-
384}-
385-
386int QMessageBoxPrivate::execReturnCode(QAbstractButton *button)-
387{-
388 int ret = buttonBox->standardButton(button);-
389 if (ret == QMessageBox::NoButton) {-
390 ret = customButtonList.indexOf(button);-
391 } else if (compatMode) {-
392 ret = oldButton(ret);-
393 }-
394 return ret;-
395}-
396-
397void QMessageBoxPrivate::_q_buttonClicked(QAbstractButton *button)-
398{-
399 QMessageBox * const q = q_func();-
400-
401 if (detailsButton && detailsText && button == detailsButton) {-
402 detailsButton->setLabel(detailsText->isHidden() ? HideLabel : ShowLabel);-
403 detailsText->setHidden(!detailsText->isHidden());-
404 updateSize();-
405 } else-
406-
407 {-
408 clickedButton = button;-
409 q->done(execReturnCode(button));-
410 q->buttonClicked(button);-
411-
412 if (receiverToDisconnectOnClose) {-
413 QObject::disconnect(q, signalToDisconnectOnClose, receiverToDisconnectOnClose,-
414 memberToDisconnectOnClose);-
415 receiverToDisconnectOnClose = 0;-
416 }-
417 signalToDisconnectOnClose.clear();-
418 memberToDisconnectOnClose.clear();-
419 }-
420}-
421-
422void QMessageBoxPrivate::_q_clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)-
423{-
424 (void)role;;-
425 QMessageBox * const q = q_func();-
426 q->done(button);-
427}-
428QMessageBox::QMessageBox(QWidget *parent)-
429 : QDialog(*new QMessageBoxPrivate, parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)-
430{-
431 QMessageBoxPrivate * const d = d_func();-
432 d->init();-
433}-
434QMessageBox::QMessageBox(Icon icon, const QString &title, const QString &text,-
435 StandardButtons buttons, QWidget *parent,-
436 Qt::WindowFlags f)-
437: QDialog(*new QMessageBoxPrivate, parent, f | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)-
438{-
439 QMessageBoxPrivate * const d = d_func();-
440 d->init(title, text);-
441 setIcon(icon);-
442 if (buttons != NoButton)-
443 setStandardButtons(buttons);-
444}-
445-
446-
447-
448-
449QMessageBox::~QMessageBox()-
450{-
451}-
452void QMessageBox::addButton(QAbstractButton *button, ButtonRole role)-
453{-
454 QMessageBoxPrivate * const d = d_func();-
455 if (!button)-
456 return;-
457 removeButton(button);-
458 d->buttonBox->addButton(button, (QDialogButtonBox::ButtonRole)role);-
459 d->customButtonList.append(button);-
460 d->autoAddOkButton = false;-
461}-
462QPushButton *QMessageBox::addButton(const QString& text, ButtonRole role)-
463{-
464 QMessageBoxPrivate * const d = d_func();-
465 QPushButton *pushButton = new QPushButton(text);-
466 addButton(pushButton, role);-
467 d->updateSize();-
468 return pushButton;-
469}-
470QPushButton *QMessageBox::addButton(StandardButton button)-
471{-
472 QMessageBoxPrivate * const d = d_func();-
473 QPushButton *pushButton = d->buttonBox->addButton((QDialogButtonBox::StandardButton)button);-
474 if (pushButton)-
475 d->autoAddOkButton = false;-
476 return pushButton;-
477}-
478void QMessageBox::removeButton(QAbstractButton *button)-
479{-
480 QMessageBoxPrivate * const d = d_func();-
481 d->customButtonList.removeAll(button);-
482 if (d->escapeButton == button)-
483 d->escapeButton = 0;-
484 if (d->defaultButton == button)-
485 d->defaultButton = 0;-
486 d->buttonBox->removeButton(button);-
487 d->updateSize();-
488}-
489void QMessageBox::setStandardButtons(StandardButtons buttons)-
490{-
491 QMessageBoxPrivate * const d = d_func();-
492 d->buttonBox->setStandardButtons(QDialogButtonBox::StandardButtons(int(buttons)));-
493-
494 QList<QAbstractButton *> buttonList = d->buttonBox->buttons();-
495 if (!buttonList.contains(d->escapeButton))-
496 d->escapeButton = 0;-
497 if (!buttonList.contains(d->defaultButton))-
498 d->defaultButton = 0;-
499 d->autoAddOkButton = false;-
500 d->updateSize();-
501}-
502-
503QMessageBox::StandardButtons QMessageBox::standardButtons() const-
504{-
505 const QMessageBoxPrivate * const d = d_func();-
506 return QMessageBox::StandardButtons(int(d->buttonBox->standardButtons()));-
507}-
508QMessageBox::StandardButton QMessageBox::standardButton(QAbstractButton *button) const-
509{-
510 const QMessageBoxPrivate * const d = d_func();-
511 return (QMessageBox::StandardButton)d->buttonBox->standardButton(button);-
512}-
513QAbstractButton *QMessageBox::button(StandardButton which) const-
514{-
515 const QMessageBoxPrivate * const d = d_func();-
516 return d->buttonBox->button(QDialogButtonBox::StandardButton(which));-
517}-
518QAbstractButton *QMessageBox::escapeButton() const-
519{-
520 const QMessageBoxPrivate * const d = d_func();-
521 return d->escapeButton;-
522}-
523void QMessageBox::setEscapeButton(QAbstractButton *button)-
524{-
525 QMessageBoxPrivate * const d = d_func();-
526 if (d->buttonBox->buttons().contains(button))-
527 d->escapeButton = button;-
528}-
529void QMessageBox::setEscapeButton(QMessageBox::StandardButton button)-
530{-
531 QMessageBoxPrivate * const d = d_func();-
532 setEscapeButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));-
533}-
534-
535void QMessageBoxPrivate::detectEscapeButton()-
536{-
537 if (escapeButton
escapeButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
538 detectedEscapeButton = escapeButton;-
539 return;
never executed: return;
0
540 }-
541-
542-
543 detectedEscapeButton = buttonBox->button(QDialogButtonBox::Cancel);-
544 if (detectedEscapeButton
detectedEscapeButtonDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
545 return;
never executed: return;
0
546-
547-
548 const QList<QAbstractButton *> buttons = buttonBox->buttons();-
549 if (buttons.count() == 1
buttons.count() == 1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
550 detectedEscapeButton = buttons.first();-
551 return;
never executed: return;
0
552 }-
553-
554-
555 for (int i = 0; i <auto *button : buttons.count(); i++)) {-
556 if (buttonBox->buttonRole(buttons.at(i))button) == QDialogButtonBox::RejectRole
buttonBox->but...ox::RejectRoleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
557 if (detectedEscapeButton
detectedEscapeButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
558 detectedEscapeButton = 0;-
559 break;
never executed: break;
0
560 }-
561 detectedEscapeButton = buttons.at(i);button;-
562 }
never executed: end of block
0
563 }
never executed: end of block
0
564 if (detectedEscapeButton
detectedEscapeButtonDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
565 return;
never executed: return;
0
566-
567-
568 for (int i = 0; i <auto *button : buttons.count(); i++)) {-
569 if (buttonBox->buttonRole(buttons.at(i))button) == QDialogButtonBox::NoRole
buttonBox->but...tonBox::NoRoleDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
570 if (detectedEscapeButton
detectedEscapeButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
571 detectedEscapeButton = 0;-
572 break;
never executed: break;
0
573 }-
574 detectedEscapeButton = buttons.at(i);button;-
575 }
never executed: end of block
0
576 }
never executed: end of block
0
577}
never executed: end of block
0
578QAbstractButton *QMessageBox::clickedButton() const-
579{-
580 const QMessageBoxPrivate * const d = d_func();-
581 return d->clickedButton;-
582}-
583QPushButton *QMessageBox::defaultButton() const-
584{-
585 const QMessageBoxPrivate * const d = d_func();-
586 return d->defaultButton;-
587}-
588void QMessageBox::setDefaultButton(QPushButton *button)-
589{-
590 QMessageBoxPrivate * const d = d_func();-
591 if (!d->buttonBox->buttons().contains(button))-
592 return;-
593 d->defaultButton = button;-
594 button->setDefault(true);-
595 button->setFocus();-
596}-
597void QMessageBox::setDefaultButton(QMessageBox::StandardButton button)-
598{-
599 QMessageBoxPrivate * const d = d_func();-
600 setDefaultButton(d->buttonBox->button(QDialogButtonBox::StandardButton(button)));-
601}-
602void QMessageBox::setCheckBox(QCheckBox *cb)-
603{-
604 QMessageBoxPrivate * const d = d_func();-
605-
606 if (cb == d->checkbox)-
607 return;-
608-
609 if (d->checkbox) {-
610 d->checkbox->hide();-
611 layout()->removeWidget(d->checkbox);-
612 if (d->checkbox->parentWidget() == this) {-
613 d->checkbox->setParent(0);-
614 d->checkbox->deleteLater();-
615 }-
616 }-
617 d->checkbox = cb;-
618 if (d->checkbox) {-
619 QSizePolicy sp = d->checkbox->sizePolicy();-
620 sp.setHorizontalPolicy(QSizePolicy::MinimumExpanding);-
621 d->checkbox->setSizePolicy(sp);-
622 }-
623 d->setupLayout();-
624}-
625QCheckBox* QMessageBox::checkBox() const-
626{-
627 const QMessageBoxPrivate * const d = d_func();-
628 return d->checkbox;-
629}-
630QString QMessageBox::text() const-
631{-
632 const QMessageBoxPrivate * const d = d_func();-
633 return d->label->text();-
634}-
635-
636void QMessageBox::setText(const QString &text)-
637{-
638 QMessageBoxPrivate * const d = d_func();-
639 d->label->setText(text);-
640 d->label->setWordWrap(d->label->textFormat() == Qt::RichText-
641 || (d->label->textFormat() == Qt::AutoText && Qt::mightBeRichText(text)));-
642 d->updateSize();-
643}-
644QMessageBox::Icon QMessageBox::icon() const-
645{-
646 const QMessageBoxPrivate * const d = d_func();-
647 return d->icon;-
648}-
649-
650void QMessageBox::setIcon(Icon icon)-
651{-
652 QMessageBoxPrivate * const d = d_func();-
653 setIconPixmap(QMessageBoxPrivate::standardIcon((QMessageBox::Icon)icon,-
654 this));-
655 d->icon = icon;-
656}-
657QPixmap QMessageBox::iconPixmap() const-
658{-
659 const QMessageBoxPrivate * const d = d_func();-
660 if (d->iconLabel && d->iconLabel->pixmap())-
661 return *d->iconLabel->pixmap();-
662 return QPixmap();-
663}-
664-
665void QMessageBox::setIconPixmap(const QPixmap &pixmap)-
666{-
667 QMessageBoxPrivate * const d = d_func();-
668 d->iconLabel->setPixmap(pixmap);-
669 d->icon = NoIcon;-
670 d->setupLayout();-
671}-
672Qt::TextFormat QMessageBox::textFormat() const-
673{-
674 const QMessageBoxPrivate * const d = d_func();-
675 return d->label->textFormat();-
676}-
677-
678void QMessageBox::setTextFormat(Qt::TextFormat format)-
679{-
680 QMessageBoxPrivate * const d = d_func();-
681 d->label->setTextFormat(format);-
682 d->label->setWordWrap(format == Qt::RichText-
683 || (format == Qt::AutoText && Qt::mightBeRichText(d->label->text())));-
684 d->updateSize();-
685}-
686Qt::TextInteractionFlags QMessageBox::textInteractionFlags() const-
687{-
688 const QMessageBoxPrivate * const d = d_func();-
689 return d->label->textInteractionFlags();-
690}-
691-
692void QMessageBox::setTextInteractionFlags(Qt::TextInteractionFlags flags)-
693{-
694 QMessageBoxPrivate * const d = d_func();-
695 d->label->setTextInteractionFlags(flags);-
696}-
697-
698-
699-
700-
701bool QMessageBox::event(QEvent *e)-
702{-
703 bool result =QDialog::event(e);-
704 switch (e->type()) {-
705 case QEvent::LayoutRequest:-
706 d_func()->updateSize();-
707 break;-
708 case QEvent::LanguageChange:-
709 d_func()->retranslateStrings();-
710 break;-
711 default:-
712 break;-
713 }-
714 return result;-
715}-
716-
717-
718-
719-
720void QMessageBox::resizeEvent(QResizeEvent *event)-
721{-
722 QDialog::resizeEvent(event);-
723}-
724-
725-
726-
727-
728void QMessageBox::closeEvent(QCloseEvent *e)-
729{-
730 QMessageBoxPrivate * const d = d_func();-
731 if (!d->detectedEscapeButton) {-
732 e->ignore();-
733 return;-
734 }-
735 QDialog::closeEvent(e);-
736 d->clickedButton = d->detectedEscapeButton;-
737 setResult(d->execReturnCode(d->detectedEscapeButton));-
738}-
739-
740-
741-
742-
743void QMessageBox::changeEvent(QEvent *ev)-
744{-
745 QMessageBoxPrivate * const d = d_func();-
746 switch (ev->type()) {-
747 case QEvent::StyleChange:-
748 {-
749 if (d->icon != NoIcon)-
750 setIcon(d->icon);-
751 Qt::TextInteractionFlags flags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this));-
752 d->label->setTextInteractionFlags(flags);-
753 d->buttonBox->setCenterButtons(style()->styleHint(QStyle::SH_MessageBox_CenterButtons, 0, this));-
754 if (d->informativeLabel)-
755 d->informativeLabel->setTextInteractionFlags(flags);-
756-
757 }-
758 case QEvent::FontChange:-
759 case QEvent::ApplicationFontChange:-
760-
761-
762-
763-
764-
765-
766-
767 default:-
768 break;-
769 }-
770 QDialog::changeEvent(ev);-
771}-
772-
773-
774-
775-
776void QMessageBox::keyPressEvent(QKeyEvent *e)-
777{-
778 QMessageBoxPrivate * const d = d_func();-
779-
780 if (e->matches(QKeySequence::Cancel)
e->matches(QKe...uence::Cancel)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
781 if (d->detectedEscapeButton
d->detectedEscapeButtonDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
782-
783-
784-
785 d->detectedEscapeButton->click();-
786-
787 }
never executed: end of block
0
788 return;
never executed: return;
0
789 }-
790-
791-
792-
793-
794-
795 if (e == QKeySequence::Copy
e == QKeySequence::CopyDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
796 if (d->detailsText
d->detailsTextDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->detailsText->isVisible()
d->detailsText->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
&& d->detailsText->copy()
d->detailsText->copy()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
797 e->setAccepted(true);-
798 return;
never executed: return;
0
799 }-
800 }
never executed: end of block
else if (e == QKeySequence::SelectAll
e == QKeySequence::SelectAllDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->detailsText
d->detailsTextDescription
TRUEnever evaluated
FALSEnever evaluated
&& d->detailsText->isVisible()
d->detailsText->isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
801 d->detailsText->selectAll();-
802 e->setAccepted(true);-
803 return;
never executed: return;
0
804 }-
805 if (!(e->modifiers() & (Qt::AltModifier | Qt::ControlModifier | Qt::MetaModifier))
!(e->modifiers...MetaModifier))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
806 int key = e->key() & ~Qt::MODIFIER_MASK;-
807 if (key
keyDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
808 const QList<QAbstractButton *> buttons = d->buttonBox->buttons();-
809 for (int i = 0; i < buttons.count(); ++i) {-
QAbstractButtonauto *pb =: buttons.at(i);) {
810 QKeySequence shortcut = pb->shortcut();-
811 if (!shortcut.isEmpty()
!shortcut.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
&& key == int(shortcut[0] & ~Qt::MODIFIER_MASK)
key == int(sho...MODIFIER_MASK)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
812 pb->animateClick();-
813 return;
never executed: return;
0
814 }-
815 }
never executed: end of block
0
816 }
never executed: end of block
0
817 }
never executed: end of block
0
818-
819 QDialog::keyPressEvent(e);-
820}
never executed: end of block
0
821void QMessageBox::open(QObject *receiver, const char *member)-
822{-
823 QMessageBoxPrivate * const d = d_func();-
824 const char *signal = member && strchr(member, '*') ? qFlagLocation("2""buttonClicked(QAbstractButton*)" "\0" __FILE__ ":" "1555")-
825 : qFlagLocation("2""finished(int)" "\0" __FILE__ ":" "1556");-
826 connect(this, signal, receiver, member);-
827 d->signalToDisconnectOnClose = signal;-
828 d->receiverToDisconnectOnClose = receiver;-
829 d->memberToDisconnectOnClose = member;-
830 QDialog::open();-
831}-
832QList<QAbstractButton *> QMessageBox::buttons() const-
833{-
834 const QMessageBoxPrivate * const d = d_func();-
835 return d->buttonBox->buttons();-
836}-
837QMessageBox::ButtonRole QMessageBox::buttonRole(QAbstractButton *button) const-
838{-
839 const QMessageBoxPrivate * const d = d_func();-
840 return QMessageBox::ButtonRole(d->buttonBox->buttonRole(button));-
841}-
842-
843-
844-
845-
846void QMessageBox::showEvent(QShowEvent *e)-
847{-
848 QMessageBoxPrivate * const d = d_func();-
849 if (d->autoAddOkButton) {-
850 addButton(Ok);-
851-
852-
853-
854 }-
855 if (d->detailsButton)-
856 addButton(d->detailsButton, QMessageBox::ActionRole);-
857 d->detectEscapeButton();-
858 d->updateSize();-
859-
860-
861 QAccessibleEvent event(this, QAccessible::Alert);-
862 QAccessible::updateAccessibility(&event);-
863-
864-
865-
866-
867-
868-
869-
870 QDialog::showEvent(e);-
871}-
872-
873-
874static QMessageBox::StandardButton showNewMessageBox(QWidget *parent,-
875 QMessageBox::Icon icon,-
876 const QString& title, const QString& text,-
877 QMessageBox::StandardButtons buttons,-
878 QMessageBox::StandardButton defaultButton)-
879{-
880-
881-
882 if (defaultButton && !(buttons & defaultButton))-
883 return (QMessageBox::StandardButton)-
884 QMessageBoxPrivate::showOldMessageBox(parent, icon, title,-
885 text, int(buttons),-
886 int(defaultButton), 0);-
887-
888 QMessageBox msgBox(icon, title, text, QMessageBox::NoButton, parent);-
889 QDialogButtonBox *buttonBox = msgBox.findChild<QDialogButtonBox*>();-
890 ((!(buttonBox != 0)) ? qt_assert("buttonBox != 0",__FILE__,1638) : qt_noop());-
891-
892 uint mask = QMessageBox::FirstButton;-
893 while (mask <= QMessageBox::LastButton) {-
894 uint sb = buttons & mask;-
895 mask <<= 1;-
896 if (!sb)-
897 continue;-
898 QPushButton *button = msgBox.addButton((QMessageBox::StandardButton)sb);-
899-
900 if (msgBox.defaultButton())-
901 continue;-
902 if ((defaultButton == QMessageBox::NoButton && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole)-
903 || (defaultButton != QMessageBox::NoButton && sb == uint(defaultButton)))-
904 msgBox.setDefaultButton(button);-
905 }-
906 if (msgBox.exec() == -1)-
907 return QMessageBox::Cancel;-
908 return msgBox.standardButton(msgBox.clickedButton());-
909}-
910QMessageBox::StandardButton QMessageBox::information(QWidget *parent, const QString &title,-
911 const QString& text, StandardButtons buttons,-
912 StandardButton defaultButton)-
913{-
914 return showNewMessageBox(parent, Information, title, text, buttons,-
915 defaultButton);-
916}-
917QMessageBox::StandardButton QMessageBox::question(QWidget *parent, const QString &title,-
918 const QString& text, StandardButtons buttons,-
919 StandardButton defaultButton)-
920{-
921 return showNewMessageBox(parent, Question, title, text, buttons, defaultButton);-
922}-
923QMessageBox::StandardButton QMessageBox::warning(QWidget *parent, const QString &title,-
924 const QString& text, StandardButtons buttons,-
925 StandardButton defaultButton)-
926{-
927 return showNewMessageBox(parent, Warning, title, text, buttons, defaultButton);-
928}-
929QMessageBox::StandardButton QMessageBox::critical(QWidget *parent, const QString &title,-
930 const QString& text, StandardButtons buttons,-
931 StandardButton defaultButton)-
932{-
933 return showNewMessageBox(parent, Critical, title, text, buttons, defaultButton);-
934}-
935void QMessageBox::about(QWidget *parent, const QString &title, const QString &text)-
936{-
937 QMessageBox *msgBox = new QMessageBox(title, text, Information, 0, 0, 0, parent-
938-
939-
940-
941 );-
942 msgBox->setAttribute(Qt::WA_DeleteOnClose);-
943 QIcon icon = msgBox->windowIcon();-
944 QSize size = icon.actualSize(QSize(64, 64));-
945 msgBox->setIconPixmap(icon.pixmap(size));-
946 msgBox->exec();-
947-
948}-
949void QMessageBox::aboutQt(QWidget *parent, const QString &title)-
950{-
951 QString translatedTextAboutQtCaption;-
952 translatedTextAboutQtCaption = QMessageBox::tr(-
953 "<h3>About Qt</h3>"-
954 "<p>This program uses Qt version %1.</p>"-
955 ).arg(QLatin1String("5.67.4"1"));-
956 QString translatedTextAboutQtText;-
957 translatedTextAboutQtText = QMessageBox::tr(-
958 "<p>Qt is a C++ toolkit for cross-platform application "-
959 "development.</p>"-
960 "<p>Qt provides single-source portability across all major desktop "-
961 "operating systems. It is also available for embedded Linux and other "-
962 "embedded and mobile operating systems.</p>"-
963 "<p>Qt is available under three different licensing options designed "-
964 "to accommodate the needs of our various users.</p>"-
965 "<p>Qt licensed under our commercial license agreement is appropriate "-
966 "for development of proprietary/commercial software where you do not "-
967 "want to share any source code with third parties or otherwise cannot "-
968 "comply with the terms of the GNU LGPL version 3 or GNU LGPL version 2.1.</p>"-
969 "<p>Qt licensed under the GNU LGPL version 3 is appropriate for the "-
970 "development of Qt&nbsp;applications provided you can comply with the terms "-
971 "and conditions of the GNU LGPL version 3.</p>"-
"<p>Qt licensed under the GNU LGPL version 2.1 is appropriate for the "
"development of Qt&nbsp;applications provided you can comply with the terms "
"and conditions of the GNU LGPL version 2.1.</p>"
972 "<p>Please see <a href=\"http://%2/\">%2</a> "-
973 "for an overview of Qt licensing.</p>"-
974 "<p>Copyright (C) %1 The Qt Company Ltd and other "-
975 "contributors.</p>"-
976 "<p>Qt and the Qt logo are trademarks of The Qt Company Ltd.</p>"-
977 "<p>Qt is The Qt Company Ltd product developed as an open source "-
978 "project. See <a href=\"http://%3/\">%3</a> for more information.</p>"-
979 ).arg(([]() -> QString { enum { Size = sizeof(u"" "2017""2016")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "2017""2016" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}()),
0
980 ([]() -> QString { enum { Size = sizeof(u"" "qt.io/licensing")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "qt.io/licensing" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}()),
0
981 ([]() -> QString { enum { Size = sizeof(u"" "qt.io")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "qt.io" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}()));
0
982 QMessageBox *msgBox = new QMessageBox(parent);-
983 msgBox->setAttribute(Qt::WA_DeleteOnClose);-
984 msgBox->setWindowTitle(title.isEmpty() ? tr("About Qt") : title);-
985 msgBox->setText(translatedTextAboutQtCaption);-
986 msgBox->setInformativeText(translatedTextAboutQtText);-
987-
988 QPixmap pm(QLatin1String(":/qt-project.org/qmessagebox/images/qtlogo-64.png"));-
989 if (!pm.isNull()
!pm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
990 msgBox->setIconPixmap(pm);
never executed: msgBox->setIconPixmap(pm);
0
991 msgBox->exec();-
992-
993}
never executed: end of block
0
994-
995-
996-
997-
998static QMessageBox::StandardButton newButton(int button)-
999{-
1000-
1001 if (button == QMessageBox::NoButton || (button & NewButtonMask))-
1002 return QMessageBox::StandardButton(button & QMessageBox::ButtonMask);-
1003 return QMessageBox::NoButton;-
1004-
1005}-
1006-
1007static bool detectedCompat(int button0, int button1, int button2)-
1008{-
1009 if (button0 != 0 && !(button0 & NewButtonMask))-
1010 return true;-
1011 if (button1 != 0 && !(button1 & NewButtonMask))-
1012 return true;-
1013 if (button2 != 0 && !(button2 & NewButtonMask))-
1014 return true;-
1015 return false;-
1016}-
1017-
1018QAbstractButton *QMessageBoxPrivate::findButton(int button0, int button1, int button2, int flags)-
1019{-
1020 QMessageBox * const q = q_func();-
1021 int button = 0;-
1022-
1023 if (button0 & flags) {-
1024 button = button0;-
1025 } else if (button1 & flags) {-
1026 button = button1;-
1027 } else if (button2 & flags) {-
1028 button = button2;-
1029 }-
1030 return q->button(newButton(button));-
1031}-
1032-
1033void QMessageBoxPrivate::addOldButtons(int button0, int button1, int button2)-
1034{-
1035 QMessageBox * const q = q_func();-
1036 q->addButton(newButton(button0));-
1037 q->addButton(newButton(button1));-
1038 q->addButton(newButton(button2));-
1039 q->setDefaultButton(-
1040 static_cast<QPushButton *>(findButton(button0, button1, button2, QMessageBox::Default)));-
1041 q->setEscapeButton(findButton(button0, button1, button2, QMessageBox::Escape));-
1042 compatMode = detectedCompat(button0, button1, button2);-
1043}-
1044-
1045QAbstractButton *QMessageBoxPrivate::abstractButtonForId(int id) const-
1046{-
1047 const QMessageBox * const q = q_func();-
1048 QAbstractButton *result = customButtonList.value(id);-
1049 if (result)-
1050 return result;-
1051 if (id & QMessageBox::FlagMask)-
1052 return 0;-
1053 return q->button(newButton(id));-
1054}-
1055-
1056int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,-
1057 const QString &title, const QString &text,-
1058 int button0, int button1, int button2)-
1059{-
1060 QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent);-
1061 messageBox.d_func()->addOldButtons(button0, button1, button2);-
1062 return messageBox.exec();-
1063}-
1064-
1065int QMessageBoxPrivate::showOldMessageBox(QWidget *parent, QMessageBox::Icon icon,-
1066 const QString &title, const QString &text,-
1067 const QString &button0Text,-
1068 const QString &button1Text,-
1069 const QString &button2Text,-
1070 int defaultButtonNumber,-
1071 int escapeButtonNumber)-
1072{-
1073 QMessageBox messageBox(icon, title, text, QMessageBox::NoButton, parent);-
1074 QString myButton0Text = button0Text;-
1075 if (myButton0Text.isEmpty())-
1076 myButton0Text = QDialogButtonBox::tr("OK");-
1077 messageBox.addButton(myButton0Text, QMessageBox::ActionRole);-
1078 if (!button1Text.isEmpty())-
1079 messageBox.addButton(button1Text, QMessageBox::ActionRole);-
1080 if (!button2Text.isEmpty())-
1081 messageBox.addButton(button2Text, QMessageBox::ActionRole);-
1082-
1083 const QList<QAbstractButton *> &buttonList = messageBox.d_func()->customButtonList;-
1084 messageBox.setDefaultButton(static_cast<QPushButton *>(buttonList.value(defaultButtonNumber)));-
1085 messageBox.setEscapeButton(buttonList.value(escapeButtonNumber));-
1086-
1087 return messageBox.exec();-
1088}-
1089-
1090void QMessageBoxPrivate::retranslateStrings()-
1091{-
1092-
1093 if (detailsButton)-
1094 detailsButton->setLabel(detailsText->isHidden() ? ShowLabel : HideLabel);-
1095-
1096}-
1097QMessageBox::QMessageBox(const QString &title, const QString &text, Icon icon,-
1098 int button0, int button1, int button2, QWidget *parent,-
1099 Qt::WindowFlags f)-
1100 : QDialog(*new QMessageBoxPrivate, parent,-
1101 f | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)-
1102{-
1103 QMessageBoxPrivate * const d = d_func();-
1104 d->init(title, text);-
1105 setIcon(icon);-
1106 d->addOldButtons(button0, button1, button2);-
1107}-
1108int QMessageBox::information(QWidget *parent, const QString &title, const QString& text,-
1109 int button0, int button1, int button2)-
1110{-
1111 return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,-
1112 button0, button1, button2);-
1113}-
1114int QMessageBox::information(QWidget *parent, const QString &title, const QString& text,-
1115 const QString& button0Text, const QString& button1Text,-
1116 const QString& button2Text, int defaultButtonNumber,-
1117 int escapeButtonNumber)-
1118{-
1119 return QMessageBoxPrivate::showOldMessageBox(parent, Information, title, text,-
1120 button0Text, button1Text, button2Text,-
1121 defaultButtonNumber, escapeButtonNumber);-
1122}-
1123int QMessageBox::question(QWidget *parent, const QString &title, const QString& text,-
1124 int button0, int button1, int button2)-
1125{-
1126 return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,-
1127 button0, button1, button2);-
1128}-
1129int QMessageBox::question(QWidget *parent, const QString &title, const QString& text,-
1130 const QString& button0Text, const QString& button1Text,-
1131 const QString& button2Text, int defaultButtonNumber,-
1132 int escapeButtonNumber)-
1133{-
1134 return QMessageBoxPrivate::showOldMessageBox(parent, Question, title, text,-
1135 button0Text, button1Text, button2Text,-
1136 defaultButtonNumber, escapeButtonNumber);-
1137}-
1138int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text,-
1139 int button0, int button1, int button2)-
1140{-
1141 return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,-
1142 button0, button1, button2);-
1143}-
1144int QMessageBox::warning(QWidget *parent, const QString &title, const QString& text,-
1145 const QString& button0Text, const QString& button1Text,-
1146 const QString& button2Text, int defaultButtonNumber,-
1147 int escapeButtonNumber)-
1148{-
1149 return QMessageBoxPrivate::showOldMessageBox(parent, Warning, title, text,-
1150 button0Text, button1Text, button2Text,-
1151 defaultButtonNumber, escapeButtonNumber);-
1152}-
1153int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text,-
1154 int button0, int button1, int button2)-
1155{-
1156 return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,-
1157 button0, button1, button2);-
1158}-
1159int QMessageBox::critical(QWidget *parent, const QString &title, const QString& text,-
1160 const QString& button0Text, const QString& button1Text,-
1161 const QString& button2Text, int defaultButtonNumber,-
1162 int escapeButtonNumber)-
1163{-
1164 return QMessageBoxPrivate::showOldMessageBox(parent, Critical, title, text,-
1165 button0Text, button1Text, button2Text,-
1166 defaultButtonNumber, escapeButtonNumber);-
1167}-
1168QString QMessageBox::buttonText(int button) const-
1169{-
1170 const QMessageBoxPrivate * const d = d_func();-
1171-
1172 if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {-
1173 return abstractButton->text();-
1174 } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {-
1175-
1176 return QDialogButtonBox::tr("OK");-
1177 }-
1178 return QString();-
1179}-
1180void QMessageBox::setButtonText(int button, const QString &text)-
1181{-
1182 QMessageBoxPrivate * const d = d_func();-
1183 if (QAbstractButton *abstractButton = d->abstractButtonForId(button)) {-
1184 abstractButton->setText(text);-
1185 } else if (d->buttonBox->buttons().isEmpty() && (button == Ok || button == Old_Ok)) {-
1186-
1187 addButton(QMessageBox::Ok)->setText(text);-
1188 }-
1189}-
1190QString QMessageBox::detailedText() const-
1191{-
1192 const QMessageBoxPrivate * const d = d_func();-
1193 return d->detailsText ? d->detailsText->text() : QString();-
1194}-
1195-
1196void QMessageBox::setDetailedText(const QString &text)-
1197{-
1198 QMessageBoxPrivate * const d = d_func();-
1199 if (text.isEmpty()) {-
1200 if (d->detailsText) {-
1201 d->detailsText->hide();-
1202 d->detailsText->deleteLater();-
1203 }-
1204 d->detailsText = 0;-
1205 removeButton(d->detailsButton);-
1206 if (d->detailsButton) {-
1207 d->detailsButton->hide();-
1208 d->detailsButton->deleteLater();-
1209 }-
1210 d->detailsButton = 0;-
1211 } else {-
1212 if (!d->detailsText) {-
1213 d->detailsText = new QMessageBoxDetailsText(this);-
1214 d->detailsText->hide();-
1215 }-
1216 if (!d->detailsButton) {-
1217 const bool autoAddOkButton = d->autoAddOkButton;-
1218 d->detailsButton = new DetailButton(this);-
1219 addButton(d->detailsButton, QMessageBox::ActionRole);-
1220 d->autoAddOkButton = autoAddOkButton;-
1221 }-
1222 d->detailsText->setText(text);-
1223 }-
1224 d->setupLayout();-
1225}-
1226QString QMessageBox::informativeText() const-
1227{-
1228 const QMessageBoxPrivate * const d = d_func();-
1229 return d->informativeLabel ? d->informativeLabel->text() : QString();-
1230}-
1231-
1232void QMessageBox::setInformativeText(const QString &text)-
1233{-
1234 QMessageBoxPrivate * const d = d_func();-
1235 if (text.isEmpty()) {-
1236 if (d->informativeLabel) {-
1237 d->informativeLabel->hide();-
1238 d->informativeLabel->deleteLater();-
1239 }-
1240 d->informativeLabel = 0;-
1241 } else {-
1242 if (!d->informativeLabel) {-
1243 QLabel *label = new QLabel;-
1244 label->setObjectName(QLatin1String("qt_msgbox_informativelabel"));-
1245 label->setTextInteractionFlags(Qt::TextInteractionFlags(style()->styleHint(QStyle::SH_MessageBox_TextInteractionFlags, 0, this)));-
1246 label->setAlignment(Qt::AlignTop | Qt::AlignLeft);-
1247 label->setOpenExternalLinks(true);-
1248 label->setWordWrap(true);-
1249-
1250-
1251-
1252-
1253 label->setWordWrap(true);-
1254 d->informativeLabel = label;-
1255 }-
1256 d->informativeLabel->setText(text);-
1257 }-
1258 d->setupLayout();-
1259}-
1260void QMessageBox::setWindowTitle(const QString &title)-
1261{-
1262-
1263-
1264 QDialog::setWindowTitle(title);-
1265-
1266-
1267-
1268}-
1269void QMessageBox::setWindowModality(Qt::WindowModality windowModality)-
1270{-
1271 QDialog::setWindowModality(windowModality);-
1272-
1273 if (parentWidget() && windowModality == Qt::WindowModal)-
1274 setParent(parentWidget(), Qt::Sheet);-
1275 else-
1276 setParent(parentWidget(), Qt::Dialog);-
1277 setDefaultButton(d_func()->defaultButton);-
1278}-
1279-
1280-
1281QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb)-
1282{-
1283 QStyle *style = mb ? mb->style() : QApplication::style();-
1284 int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, mb);-
1285 QIcon tmpIcon;-
1286 switch (icon) {-
1287 case QMessageBox::Information:-
1288 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, mb);-
1289 break;-
1290 case QMessageBox::Warning:-
1291 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, mb);-
1292 break;-
1293 case QMessageBox::Critical:-
1294 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, mb);-
1295 break;-
1296 case QMessageBox::Question:-
1297 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mb);-
1298 default:-
1299 break;-
1300 }-
1301 if (!tmpIcon.isNull()) {-
1302 QWindow *window = nullptr;-
1303 if (mb) {-
1304 window = mb->windowHandle();-
1305 if (!window) {-
1306 if (const QWidget *nativeParent = mb->nativeParentWidget())-
1307 window = nativeParent->windowHandle();-
1308 }-
1309 }-
1310 return tmpIcon.pixmap(window, QSize(iconSize, iconSize));-
1311 }-
1312 return QPixmap();-
1313}-
1314-
1315void QMessageBoxPrivate::initHelper(QPlatformDialogHelper *h)-
1316{-
1317 QMessageBox * const q = q_func();-
1318 QObject::connect(h, qFlagLocation("2""clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)" "\0" __FILE__ ":" "2697""2694"),-
1319 q, qFlagLocation("1""_q_clicked(QPlatformDialogHelper::StandardButton,QPlatformDialogHelper::ButtonRole)" "\0" __FILE__ ":" "2698""2695"));-
1320 static_cast<QPlatformMessageDialogHelper *>(h)->setOptions(options);-
1321}-
1322-
1323static QMessageDialogOptions::Icon helperIcon(QMessageBox::Icon i)-
1324{-
1325 switch (i) {-
1326 case QMessageBox::NoIcon:-
1327 return QMessageDialogOptions::NoIcon;-
1328 case QMessageBox::Information:-
1329 return QMessageDialogOptions::Information;-
1330 case QMessageBox::Warning:-
1331 return QMessageDialogOptions::Warning;-
1332 case QMessageBox::Critical:-
1333 return QMessageDialogOptions::Critical;-
1334 case QMessageBox::Question:-
1335 return QMessageDialogOptions::Question;-
1336 }-
1337 return QMessageDialogOptions::NoIcon;-
1338}-
1339-
1340static QPlatformDialogHelper::StandardButtons helperStandardButtons(QMessageBox * q)-
1341{-
1342 QPlatformDialogHelper::StandardButtons buttons(int(q->standardButtons()));-
1343 return buttons;-
1344}-
1345-
1346void QMessageBoxPrivate::helperPrepareShow(QPlatformDialogHelper *)-
1347{-
1348 QMessageBox * const q = q_func();-
1349 options->setWindowTitle(q->windowTitle());-
1350 options->setText(q->text());-
1351 options->setInformativeText(q->informativeText());-
1352 options->setDetailedText(q->detailedText());-
1353 options->setIcon(helperIcon(q->icon()));-
1354 options->setStandardButtons(helperStandardButtons(q));-
1355}-
1356-
1357void QMessageBoxPrivate::helperDone(QDialog::DialogCode code, QPlatformDialogHelper *)-
1358{-
1359 QMessageBox * const q = q_func();-
1360 clickedButton = q->button(QMessageBox::StandardButton(code));-
1361}-
1362QPixmap QMessageBox::standardIcon(Icon icon)-
1363{-
1364 return QMessageBoxPrivate::standardIcon(icon, 0);-
1365}-
1366-
1367-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9