qdialog.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qdialog.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7static inline int themeDialogType(const QDialog *dialog)-
8{-
9-
10 if (qobject_cast<const QFileDialog *>(dialog))-
11 return QPlatformTheme::FileDialog;-
12-
13-
14 if (qobject_cast<const QColorDialog *>(dialog))-
15 return QPlatformTheme::ColorDialog;-
16-
17-
18 if (qobject_cast<const QFontDialog *>(dialog))-
19 return QPlatformTheme::FontDialog;-
20-
21-
22 if (qobject_cast<const QMessageBox *>(dialog))-
23 return QPlatformTheme::MessageDialog;-
24-
25-
26 if (qobject_cast<const QErrorMessage *>(dialog))-
27 return QPlatformTheme::MessageDialog;-
28-
29 return -1;-
30}-
31-
32QDialogPrivate::~QDialogPrivate()-
33{-
34 delete m_platformHelper;-
35}
never executed: end of block
0
36-
37QPlatformDialogHelper *QDialogPrivate::platformHelper() const-
38{-
39-
40-
41 if (!m_platformHelperCreated
!m_platformHelperCreatedDescription
TRUEnever evaluated
FALSEnever evaluated
)&& canBeNativeDialog()
canBeNativeDialog()Description
TRUEnever evaluated
FALSEnever evaluated
)
{
0
42 m_platformHelperCreated = true;-
43 QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this);-
44 QDialog *dialog = ncThis->q_func();-
45 const int type = themeDialogType(dialog);-
46 if (type >= 0
type >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
47 m_platformHelper = QGuiApplicationPrivate::platformTheme()-
48 ->createPlatformDialogHelper(static_cast<QPlatformTheme::DialogType>(type));-
49 if (m_platformHelper
m_platformHelperDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
50 QObject::connect(m_platformHelper, qFlagLocation("2""accept()" "\0" __FILE__ ":" "96""107"), dialog, qFlagLocation("1""accept()" "\0" __FILE__ ":" "96""107"));-
51 QObject::connect(m_platformHelper, qFlagLocation("2""reject()" "\0" __FILE__ ":" "97""108"), dialog, qFlagLocation("1""reject()" "\0" __FILE__ ":" "97""108"));-
52 ncThis->initHelper(m_platformHelper);-
53 }
never executed: end of block
0
54 }
never executed: end of block
0
55 }
never executed: end of block
0
56 return
never executed: return m_platformHelper;
m_platformHelper;
never executed: return m_platformHelper;
0
57}-
58-
59bool QDialogPrivate::canBeNativeDialog() const-
60{-
61 QDialogPrivate *ncThis = const_cast<QDialogPrivate *>(this);-
62 QDialog *dialog = ncThis->q_func();-
63 const int type = themeDialogType(dialog);-
64 if (type >= 0)-
65 return QGuiApplicationPrivate::platformTheme()-
66 ->usePlatformNativeDialog(static_cast<QPlatformTheme::DialogType>(type));-
67 return false;-
68}-
69-
70QWindow *QDialogPrivate::parentWindow() const-
71{-
72 if (const QWidget *parent = q_func()->nativeParentWidget())-
73 return parent->windowHandle();-
74 return 0;-
75}-
76-
77bool QDialogPrivate::setNativeDialogVisible(bool visible)-
78{-
79 if (QPlatformDialogHelper *helper = platformHelper()) {-
80 if (visible) {-
81 QDialog * const q = q_func();-
82 helperPrepareShow(helper);-
83 nativeDialogInUse = helper->show(q->windowFlags(), q->windowModality(), parentWindow());-
84 } else if (nativeDialogInUse) {-
85 helper->hide();-
86 }-
87 }-
88 return nativeDialogInUse;-
89}-
90-
91QVariant QDialogPrivate::styleHint(QPlatformDialogHelper::StyleHint hint) const-
92{-
93 if (const QPlatformDialogHelper *helper = platformHelper())-
94 return helper->styleHint(hint);-
95 return QPlatformDialogHelper::defaultStyleHint(hint);-
96}-
97-
98void QDialogPrivate::deletePlatformHelper()-
99{-
100 delete m_platformHelper;-
101 m_platformHelper = 0;-
102 m_platformHelperCreated = false;-
103 nativeDialogInUse = false;-
104}-
105QDialog::QDialog(QWidget *parent, Qt::WindowFlags f)-
106 : QWidget(*new QDialogPrivate, parent,-
107 f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0)))-
108{-
109}-
110-
111-
112-
113-
114-
115QDialog::QDialog(QDialogPrivate &dd, QWidget *parent, Qt::WindowFlags f)-
116 : QWidget(dd, parent, f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0)))-
117{-
118}-
119-
120-
121-
122-
123-
124QDialog::~QDialog()-
125{-
126 if (true) {-
127-
128-
129 hide();-
130 } else {
dead code: { }
-
131-
132 }
dead code: { }
-
133}-
134void QDialogPrivate::setDefault(QPushButton *pushButton)-
135{-
136 QDialog * const q = q_func();-
137 bool hasMain = false;-
138 QList<QPushButton*> list = q->findChildren<QPushButton*>();-
139 for (int i=0; i<list.size(); ++i) {-
140 QPushButton *pb = list.at(i);-
141 if (pb->window() == q) {-
142 if (pb == mainDef)-
143 hasMain = true;-
144 if (pb != pushButton)-
145 pb->setDefault(false);-
146 }-
147 }-
148 if (!pushButton && hasMain)-
149 mainDef->setDefault(true);-
150 if (!hasMain)-
151 mainDef = pushButton;-
152}-
153-
154-
155-
156-
157-
158-
159void QDialogPrivate::setMainDefault(QPushButton *pushButton)-
160{-
161 mainDef = 0;-
162 setDefault(pushButton);-
163}-
164-
165-
166-
167-
168-
169-
170void QDialogPrivate::hideDefault()-
171{-
172 QDialog * const q = q_func();-
173 QList<QPushButton*> list = q->findChildren<QPushButton*>();-
174 for (int i=0; i<list.size(); ++i) {-
175 list.at(i)->setDefault(false);-
176 }-
177}-
178-
179void QDialogPrivate::resetModalitySetByOpen()-
180{-
181 QDialog * const q = q_func();-
182 if (resetModalityTo != -1 && !q->testAttribute(Qt::WA_SetWindowModality)) {-
183-
184 q->setWindowModality(Qt::WindowModality(resetModalityTo));-
185 q->setAttribute(Qt::WA_SetWindowModality, wasModalitySet);-
186-
187-
188-
189-
190 }-
191 resetModalityTo = -1;-
192}-
193int QDialog::result() const-
194{-
195 const QDialogPrivate * const d = d_func();-
196 return d->rescode;-
197}-
198void QDialog::setResult(int r)-
199{-
200 QDialogPrivate * const d = d_func();-
201 d->rescode = r;-
202}-
203void QDialog::open()-
204{-
205 QDialogPrivate * const d = d_func();-
206-
207 Qt::WindowModality modality = windowModality();-
208 if (modality != Qt::WindowModal) {-
209 d->resetModalityTo = modality;-
210 d->wasModalitySet = testAttribute(Qt::WA_SetWindowModality);-
211 setWindowModality(Qt::WindowModal);-
212 setAttribute(Qt::WA_SetWindowModality, false);-
213-
214-
215-
216 }-
217-
218 setResult(0);-
219 show();-
220}-
221int QDialog::exec()-
222{-
223 QDialogPrivate * const d = d_func();-
224-
225 if (__builtin_expect(!!(
__builtin_expe...tLoop), false)Description
TRUEnever evaluated
FALSEnever evaluated
d->eventLoop)), false)
__builtin_expe...tLoop), false)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
226 QMessageLogger(__FILE__, 520531, __PRETTY_FUNCTION__).warning("QDialog::exec: Recursive call detected");-
227 return
never executed: return -1;
-1;
never executed: return -1;
0
228 }-
229-
230 bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose);-
231 setAttribute(Qt::WA_DeleteOnClose, false);-
232-
233 d->resetModalitySetByOpen();-
234-
235 bool wasShowModal = testAttribute(Qt::WA_ShowModal);-
236 setAttribute(Qt::WA_ShowModal, true);-
237 setResult(0);-
238-
239 show();-
240-
241 QPointer<QDialog> guard = this;-
242 if (d->nativeDialogInUse
d->nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
243 d->platformHelper()->exec();-
244 }
never executed: end of block
else {
0
245 QEventLoop eventLoop;-
246 d->eventLoop = &eventLoop;-
247 (void) eventLoop.exec(QEventLoop::DialogExec);-
248 }
never executed: end of block
0
249 if (guard.isNull()
guard.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
250 return
never executed: return QDialog::Rejected;
QDialog::Rejected;
never executed: return QDialog::Rejected;
0
251 d->eventLoop = 0;-
252-
253 setAttribute(Qt::WA_ShowModal, wasShowModal);-
254-
255 int res = result();-
256 if (d->nativeDialogInUse
d->nativeDialogInUseDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
257 d->helperDone(static_cast<QDialog::DialogCode>(res), d->platformHelper());
never executed: d->helperDone(static_cast<QDialog::DialogCode>(res), d->platformHelper());
0
258 if (deleteOnClose
deleteOnCloseDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
259 delete this;
never executed: delete this;
0
260 return
never executed: return res;
res;
never executed: return res;
0
261}-
262void QDialog::done(int r)-
263{-
264 QDialogPrivate * const d = d_func();-
265 hide();-
266 setResult(r);-
267-
268 d->close_helper(QWidgetPrivate::CloseNoEvent);-
269 d->resetModalitySetByOpen();-
270-
271 finished(r);-
272 if (r == Accepted)-
273 accepted();-
274 else if (r == Rejected)-
275 rejected();-
276}-
277-
278-
279-
280-
281-
282-
283-
284void QDialog::accept()-
285{-
286 done(Accepted);-
287}-
288-
289-
290-
291-
292-
293-
294-
295void QDialog::reject()-
296{-
297 done(Rejected);-
298}-
299-
300-
301bool QDialog::eventFilter(QObject *o, QEvent *e)-
302{-
303 return QWidget::eventFilter(o, e);-
304}-
305-
306-
307-
308-
309-
310-
311-
312void QDialog::contextMenuEvent(QContextMenuEvent *e)-
313{-
314-
315-
316-
317 QWidget *w = childAt(e->pos());-
318 if (!w) {-
319 w = rect().contains(e->pos()) ? this : 0;-
320 if (!w)-
321 return;-
322 }-
323 while (w && w->whatsThis().size() == 0 && !w->testAttribute(Qt::WA_CustomWhatsThis))-
324 w = w->isWindow() ? 0 : w->parentWidget();-
325 if (w) {-
326 QPointer<QMenu> p = new QMenu(this);-
327 QAction *wt = p.data()->addAction(tr("What's This?"));-
328 if (p.data()->exec(e->globalPos()) == wt) {-
329 QHelpEvent e(QEvent::WhatsThis, w->rect().center(),-
330 w->mapToGlobal(w->rect().center()));-
331 QApplication::sendEvent(w, &e);-
332 }-
333 delete p.data();-
334 }-
335-
336}-
337-
338-
339-
340void QDialog::keyPressEvent(QKeyEvent *e)-
341{-
342-
343-
344-
345 if (e->matches(QKeySequence::Cancel)) {-
346 reject();-
347 } else-
348 if (!e->modifiers() || (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter)) {-
349 switch (e->key()) {-
350 case Qt::Key_Enter:-
351 case Qt::Key_Return: {-
352 QList<QPushButton*> list = findChildren<QPushButton*>();-
353 for (int i=0; i<list.size(); ++i) {-
354 QPushButton *pb = list.at(i);-
355 if (pb->isDefault() && pb->isVisible()) {-
356 if (pb->isEnabled())-
357 pb->click();-
358 return;-
359 }-
360 }-
361 }-
362 break;-
363 default:-
364 e->ignore();-
365 return;-
366 }-
367 } else {-
368 e->ignore();-
369 }-
370}-
371-
372-
373void QDialog::closeEvent(QCloseEvent *e)-
374{-
375-
376 if (isModal() && QWhatsThis::inWhatsThisMode())-
377 QWhatsThis::leaveWhatsThisMode();-
378-
379 if (isVisible()) {-
380 QPointer<QObject> that = this;-
381 reject();-
382 if (that && isVisible())-
383 e->ignore();-
384 } else {-
385 e->accept();-
386 }-
387}-
388void QDialog::setVisible(bool visible)-
389{-
390 QDialogPrivate * const d = d_func();-
391 if (!testAttribute(Qt::WA_DontShowOnScreen) && d->canBeNativeDialog() && d->setNativeDialogVisible(visible))-
392 return;-
393-
394 if (visible) {-
395 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))-
396 return;-
397-
398 QWidget::setVisible(visible);-
399 showExtension(d->doShowExtension);-
400 QWidget *fw = window()->focusWidget();-
401 if (!fw)-
402 fw = this;-
403 if (d->mainDef && fw->focusPolicy() == Qt::NoFocus) {-
404 QWidget *first = fw;-
405 while ((first = first->nextInFocusChain()) != fw && first->focusPolicy() == Qt::NoFocus)-
406 ;-
407 if (first != d->mainDef && qobject_cast<QPushButton*>(first))-
408 d->mainDef->setFocus();-
409 }-
410 if (!d->mainDef && isWindow()) {-
411 QWidget *w = fw;-
412 while ((w = w->nextInFocusChain()) != fw) {-
413 QPushButton *pb = qobject_cast<QPushButton *>(w);-
414 if (pb && pb->autoDefault() && pb->focusPolicy() != Qt::NoFocus) {-
415 pb->setDefault(true);-
416 break;-
417 }-
418 }-
419 }-
420 if (fw && !fw->hasFocus()) {-
421 QFocusEvent e(QEvent::FocusIn, Qt::TabFocusReason);-
422 QApplication::sendEvent(fw, &e);-
423 }-
424-
425-
426 QAccessibleEvent event(this, QAccessible::DialogStart);-
427 QAccessible::updateAccessibility(&event);-
428-
429-
430 } else {-
431 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))-
432 return;-
433-
434-
435 if (isVisible()) {-
436 QAccessibleEvent event(this, QAccessible::DialogEnd);-
437 QAccessible::updateAccessibility(&event);-
438 }-
439-
440-
441-
442 QWidget::setVisible(visible);-
443 if (d->eventLoop)-
444 d->eventLoop->exit();-
445 }-
446-
447 const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();-
448 if (d->mainDef && isActiveWindow()-
449 && theme->themeHint(QPlatformTheme::DialogSnapToDefaultButton).toBool())-
450 QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center()));-
451}-
452-
453-
454void QDialog::showEvent(QShowEvent *event)-
455{-
456 if (!event->spontaneous() && !testAttribute(Qt::WA_Moved)) {-
457 Qt::WindowStates state = windowState();-
458 adjustPosition(parentWidget());-
459 setAttribute(Qt::WA_Moved, false);-
460 if (state != windowState())-
461 setWindowState(state);-
462 }-
463}-
464-
465-
466void QDialog::adjustPosition(QWidget* w)-
467{-
468-
469 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())-
470 if (theme->themeHint(QPlatformTheme::WindowAutoPlacement).toBool())-
471 return;-
472 QPoint p(0, 0);-
473 int extraw = 0, extrah = 0, scrn = 0;-
474 if (w)-
475 w = w->window();-
476 QRect desk;-
477 if (w) {-
478 scrn = QApplication::desktop()->screenNumber(w);-
479 } else if (QApplication::desktop()->isVirtualDesktop()) {-
480 scrn = QApplication::desktop()->screenNumber(QCursor::pos());-
481 } else {-
482 scrn = QApplication::desktop()->screenNumber(this);-
483 }-
484 desk = QApplication::desktop()->availableGeometry(scrn);-
485-
486 QWidgetList list = QApplication::topLevelWidgets();-
487 for (int i = 0; (extraw == 0 || extrah == 0) && i < list.size(); ++i) {-
488 QWidget * current = list.at(i);-
489 if (current->isVisible()) {-
490 int framew = current->geometry().x() - current->x();-
491 int frameh = current->geometry().y() - current->y();-
492-
493 extraw = qMax(extraw, framew);-
494 extrah = qMax(extrah, frameh);-
495 }-
496 }-
497-
498-
499-
500 if (extraw == 0 || extrah == 0 || extraw >= 10 || extrah >= 40) {-
501 extrah = 40;-
502 extraw = 10;-
503 }-
504-
505-
506 if (w) {-
507-
508 QPoint pp;-
509 if (w->windowHandle() && w->windowHandle()->property("_q_embedded_native_parent_handle").value<WId>())-
510 pp = w->pos();-
511 else-
512 pp = w->mapToGlobal(QPoint(0,0));-
513 p = QPoint(pp.x() + w->width()/2,-
514 pp.y() + w->height()/ 2);-
515 } else {-
516-
517 p = QPoint(desk.x() + desk.width()/2, desk.y() + desk.height()/2);-
518 }-
519-
520-
521 p = QPoint(p.x()-width()/2 - extraw,-
522 p.y()-height()/2 - extrah);-
523-
524-
525 if (p.x() + extraw + width() > desk.x() + desk.width())-
526 p.setX(desk.x() + desk.width() - width() - extraw);-
527 if (p.x() < desk.x())-
528 p.setX(desk.x());-
529-
530 if (p.y() + extrah + height() > desk.y() + desk.height())-
531 p.setY(desk.y() + desk.height() - height() - extrah);-
532 if (p.y() < desk.y())-
533 p.setY(desk.y());-
534-
535-
536-
537-
538 if (scrn >= 0) {-
539 if (QWindow *window = windowHandle())-
540 window->setScreen(QGuiApplication::screens().at(scrn));-
541 }-
542-
543 move(p);-
544}-
545void QDialog::setOrientation(Qt::Orientation orientation)-
546{-
547 QDialogPrivate * const d = d_func();-
548 d->orientation = orientation;-
549}-
550Qt::Orientation QDialog::orientation() const-
551{-
552 const QDialogPrivate * const d = d_func();-
553 return d->orientation;-
554}-
555void QDialog::setExtension(QWidget* extension)-
556{-
557 QDialogPrivate * const d = d_func();-
558 delete d->extension;-
559 d->extension = extension;-
560-
561 if (!extension)-
562 return;-
563-
564 if (extension->parentWidget() != this)-
565 extension->setParent(this);-
566 extension->hide();-
567}-
568QWidget* QDialog::extension() const-
569{-
570 const QDialogPrivate * const d = d_func();-
571 return d->extension;-
572}-
573void QDialog::showExtension(bool showIt)-
574{-
575 QDialogPrivate * const d = d_func();-
576 d->doShowExtension = showIt;-
577 if (!d->extension)-
578 return;-
579 if (!testAttribute(Qt::WA_WState_Visible))-
580 return;-
581 if (d->extension->isVisible() == showIt)-
582 return;-
583-
584 if (showIt) {-
585 d->size = size();-
586 d->min = minimumSize();-
587 d->max = maximumSize();-
588 if (layout())-
589 layout()->setEnabled(false);-
590 QSize s(d->extension->sizeHint()-
591 .expandedTo(d->extension->minimumSize())-
592 .boundedTo(d->extension->maximumSize()));-
593 if (d->orientation == Qt::Horizontal) {-
594 int h = qMax(height(), s.height());-
595 d->extension->setGeometry(width(), 0, s.width(), h);-
596 setFixedSize(width() + s.width(), h);-
597 } else {-
598 int w = qMax(width(), s.width());-
599 d->extension->setGeometry(0, height(), w, s.height());-
600 setFixedSize(w, height() + s.height());-
601 }-
602 d->extension->show();-
603-
604 const bool sizeGripEnabled = isSizeGripEnabled();-
605 setSizeGripEnabled(false);-
606 d->sizeGripEnabled = sizeGripEnabled;-
607-
608 } else {-
609 d->extension->hide();-
610-
611 setMinimumSize(d->min.expandedTo(QSize(1, 1)));-
612 setMaximumSize(d->max);-
613 resize(d->size);-
614 if (layout())-
615 layout()->setEnabled(true);-
616-
617 setSizeGripEnabled(d->sizeGripEnabled);-
618-
619 }-
620}-
621-
622-
623-
624QSize QDialog::sizeHint() const-
625{-
626 const QDialogPrivate * const d = d_func();-
627 if (d->extension) {-
628 if (d->orientation == Qt::Horizontal)-
629 return QSize(QWidget::sizeHint().width(),-
630 qMax(QWidget::sizeHint().height(),d->extension->sizeHint().height()));-
631 else-
632 return QSize(qMax(QWidget::sizeHint().width(), d->extension->sizeHint().width()),-
633 QWidget::sizeHint().height());-
634 }-
635 return QWidget::sizeHint();-
636}-
637-
638-
639-
640QSize QDialog::minimumSizeHint() const-
641{-
642 const QDialogPrivate * const d = d_func();-
643 if (d->extension) {-
644 if (d->orientation == Qt::Horizontal)-
645 return QSize(QWidget::minimumSizeHint().width(),-
646 qMax(QWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height()));-
647 else-
648 return QSize(qMax(QWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width()),-
649 QWidget::minimumSizeHint().height());-
650 }-
651-
652 return QWidget::minimumSizeHint();-
653}-
654void QDialog::setModal(bool modal)-
655{-
656 setAttribute(Qt::WA_ShowModal, modal);-
657}-
658-
659-
660bool QDialog::isSizeGripEnabled() const-
661{-
662-
663 const QDialogPrivate * const d = d_func();-
664 return !!d->resizer;-
665-
666-
667-
668}-
669-
670-
671void QDialog::setSizeGripEnabled(bool enabled)-
672{-
673-
674-
675-
676 QDialogPrivate * const d = d_func();-
677-
678 d->sizeGripEnabled = enabled;-
679 if (enabled && d->doShowExtension)-
680 return;-
681-
682 if (!enabled != !d->resizer) {-
683 if (enabled) {-
684 d->resizer = new QSizeGrip(this);-
685-
686 d->resizer->resize(d->resizer->sizeHint());-
687 if (isRightToLeft())-
688 d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft());-
689 else-
690 d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight());-
691 d->resizer->raise();-
692 d->resizer->show();-
693 } else {-
694 delete d->resizer;-
695 d->resizer = 0;-
696 }-
697 }-
698-
699}-
700-
701-
702-
703-
704void QDialog::resizeEvent(QResizeEvent *)-
705{-
706-
707 QDialogPrivate * const d = d_func();-
708 if (d->resizer) {-
709 if (isRightToLeft())-
710 d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft());-
711 else-
712 d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight());-
713 d->resizer->raise();-
714 }-
715-
716}-
717-
Switch to Source codePreprocessed file

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