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