Qt 4.8
qdialog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdialog.h"
43 
44 
45 #include "qevent.h"
46 #include "qdesktopwidget.h"
47 #include "qpushbutton.h"
48 #include "qapplication.h"
49 #include "qlayout.h"
50 #include "qsizegrip.h"
51 #include "qwhatsthis.h"
52 #include "qmenu.h"
53 #include "qcursor.h"
54 #include "private/qdialog_p.h"
55 #ifndef QT_NO_ACCESSIBILITY
56 #include "qaccessible.h"
57 #endif
58 #if defined(Q_WS_WINCE)
59 #include "qt_windows.h"
60 #include "qmenubar.h"
61 #include "qpointer.h"
62 #include "qguifunctions_wince.h"
63 extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp
64 extern bool qt_wince_is_smartphone(); //is defined in qguifunctions_wce.cpp
65 #elif defined(Q_WS_X11)
66 # include "../kernel/qt_x11_p.h"
67 #elif defined(Q_OS_SYMBIAN)
68 # include "qfiledialog.h"
69 # include "qfontdialog.h"
70 # include "qwizard.h"
71 # include "private/qt_s60_p.h"
72 #elif defined(Q_OS_BLACKBERRY)
73 # include "qmessagebox.h"
74 #endif
75 
76 #if defined(Q_WS_S60)
77 #include <AknUtils.h> // AknLayoutUtils
78 #endif
79 
80 #ifndef SPI_GETSNAPTODEFBUTTON
81 # define SPI_GETSNAPTODEFBUTTON 95
82 #endif
83 
85 
268 QDialog::QDialog(QWidget *parent, Qt::WindowFlags f)
269  : QWidget(*new QDialogPrivate, parent,
270  f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0)))
271 {
272 #ifdef Q_WS_WINCE
273  if (!qt_wince_is_smartphone())
275 #endif
276 
277 #ifdef Q_WS_S60
278  if (S60->avkonComponentsSupportTransparency) {
279  bool noSystemBackground = testAttribute(Qt::WA_NoSystemBackground);
280  setAttribute(Qt::WA_TranslucentBackground); // also sets WA_NoSystemBackground
281  setAttribute(Qt::WA_NoSystemBackground, noSystemBackground); // restore system background attribute
282  }
283 #endif
284 }
285 
286 #ifdef QT3_SUPPORT
287 
291 QDialog::QDialog(QWidget *parent, const char *name, bool modal, Qt::WindowFlags f)
292  : QWidget(*new QDialogPrivate, parent,
293  f
294  | QFlag(modal ? Qt::WShowModal : Qt::WindowType(0))
296  )
297 {
299 }
300 #endif
301 
306 QDialog::QDialog(QDialogPrivate &dd, QWidget *parent, Qt::WindowFlags f)
307  : QWidget(dd, parent, f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0)))
308 {
309 #ifdef Q_WS_WINCE
310  if (!qt_wince_is_smartphone())
312 #endif
313 
314 #ifdef Q_WS_S60
315  if (S60->avkonComponentsSupportTransparency) {
316  bool noSystemBackground = testAttribute(Qt::WA_NoSystemBackground);
317  setAttribute(Qt::WA_TranslucentBackground); // also sets WA_NoSystemBackground
318  setAttribute(Qt::WA_NoSystemBackground, noSystemBackground); // restore system background attribute
319  }
320 #endif
321 }
322 
328 {
329  QT_TRY {
330  // Need to hide() here, as our (to-be) overridden hide()
331  // will not be called in ~QWidget.
332  hide();
333  } QT_CATCH(...) {
334  // we're in the destructor - just swallow the exception
335  }
336 }
337 
349 {
350  Q_Q(QDialog);
351  bool hasMain = false;
352  QList<QPushButton*> list = q->findChildren<QPushButton*>();
353  for (int i=0; i<list.size(); ++i) {
354  QPushButton *pb = list.at(i);
355  if (pb->window() == q) {
356  if (pb == mainDef)
357  hasMain = true;
358  if (pb != pushButton)
359  pb->setDefault(false);
360  }
361  }
362  if (!pushButton && hasMain)
363  mainDef->setDefault(true);
364  if (!hasMain)
365  mainDef = pushButton;
366 }
367 
377 {
378  mainDef = 0;
379  setDefault(pushButton);
380 }
381 
391 {
392  Q_Q(QDialog);
393  QList<QPushButton*> list = q->findChildren<QPushButton*>();
394  for (int i=0; i<list.size(); ++i) {
395  list.at(i)->setDefault(false);
396  }
397 }
398 
400 {
401  Q_Q(QDialog);
402  if (resetModalityTo != -1 && !q->testAttribute(Qt::WA_SetWindowModality)) {
403  // open() changed the window modality and the user didn't touch it afterwards; restore it
404  q->setWindowModality(Qt::WindowModality(resetModalityTo));
405  q->setAttribute(Qt::WA_SetWindowModality, wasModalitySet);
406 #ifdef Q_WS_MAC
407  Q_ASSERT(resetModalityTo != Qt::WindowModal);
408  q->setParent(q->parentWidget(), Qt::Dialog);
409 #endif
410  }
411  resetModalityTo = -1;
412 }
413 
414 #if defined(Q_WS_WINCE) || defined(Q_OS_SYMBIAN)
415 #ifdef Q_WS_WINCE_WM
416 void QDialogPrivate::_q_doneAction()
417 {
418  //Done...
420 }
421 #endif
422 
427 {
428  bool result = QWidget::event(e);
429 #ifdef Q_WS_WINCE
430  if (e->type() == QEvent::OkRequest) {
431  accept();
432  result = true;
433  }
434 #elif defined(Q_WS_S60)
435  if ((e->type() == QEvent::StyleChange) || (e->type() == QEvent::Resize )) {
436  if (!testAttribute(Qt::WA_Moved)) {
437  Qt::WindowStates state = windowState();
439  setAttribute(Qt::WA_Moved, false); // not really an explicit position
440  if (state != windowState())
441  setWindowState(state);
442  }
443  }
444  // TODO is Symbian, non-S60 behaviour required?
445 #endif
446  return result;
447 }
448 #endif
449 
458 int QDialog::result() const
459 {
460  Q_D(const QDialog);
461  return d->rescode;
462 }
463 
476 {
477  Q_D(QDialog);
478  d->rescode = r;
479 }
480 
493 {
494  Q_D(QDialog);
495 
496  Qt::WindowModality modality = windowModality();
497  if (modality != Qt::WindowModal) {
498  d->resetModalityTo = modality;
499  d->wasModalitySet = testAttribute(Qt::WA_SetWindowModality);
502 #ifdef Q_WS_MAC
504 #endif
505  }
506 
507  setResult(0);
508  show();
509 }
510 
525 {
526  Q_D(QDialog);
527 
528  if (d->eventLoop) {
529  qWarning("QDialog::exec: Recursive call detected");
530  return -1;
531  }
532 
533  bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
535 
536  d->resetModalitySetByOpen();
537 
538  bool wasShowModal = testAttribute(Qt::WA_ShowModal);
540  setResult(0);
541 
542 //On Windows Mobile we create an empty menu to hide the current menu
543 #ifdef Q_WS_WINCE_WM
544 #ifndef QT_NO_MENUBAR
545  QMenuBar *menuBar = 0;
546  if (!findChild<QMenuBar *>())
547  menuBar = new QMenuBar(this);
548  if (qt_wince_is_smartphone()) {
549  QAction *doneAction = new QAction(tr("Done"), this);
550  menuBar->setDefaultAction(doneAction);
551  connect(doneAction, SIGNAL(triggered()), this, SLOT(_q_doneAction()));
552  }
553 #endif //QT_NO_MENUBAR
554 #endif //Q_WS_WINCE_WM
555 
556  bool showSystemDialogFullScreen = false;
557 
558 #ifdef Q_OS_SYMBIAN
559  if (qobject_cast<QFileDialog *>(this) || qobject_cast<QFontDialog *>(this) ||
560  qobject_cast<QWizard *>(this)) {
561  showSystemDialogFullScreen = true;
562  }
563 #endif // Q_OS_SYMBIAN
564 
565 #ifdef Q_OS_BLACKBERRY
566  if (!qobject_cast<QMessageBox *>(this))
567  showSystemDialogFullScreen = true;
568 #endif // Q_OS_BLACKBERRY
569 
570  if (showSystemDialogFullScreen) {
573  }
574  show();
575 
576 #ifdef Q_WS_MAC
577  d->mac_nativeDialogModalHelp();
578 #endif
579 
580  QEventLoop eventLoop;
581  d->eventLoop = &eventLoop;
582  QPointer<QDialog> guard = this;
583  (void) eventLoop.exec(QEventLoop::DialogExec);
584  if (guard.isNull())
585  return QDialog::Rejected;
586  d->eventLoop = 0;
587 
588  setAttribute(Qt::WA_ShowModal, wasShowModal);
589 
590  int res = result();
591  if (deleteOnClose)
592  delete this;
593 #ifdef Q_WS_WINCE_WM
594 #ifndef QT_NO_MENUBAR
595  else if (menuBar)
596  delete menuBar;
597 #endif //QT_NO_MENUBAR
598 #endif //Q_WS_WINCE_WM
599  return res;
600 }
601 
602 
617 void QDialog::done(int r)
618 {
619  Q_D(QDialog);
620  hide();
621  setResult(r);
622 
623  d->close_helper(QWidgetPrivate::CloseNoEvent);
624  d->resetModalitySetByOpen();
625 
626  emit finished(r);
627  if (r == Accepted)
628  emit accepted();
629  else if (r == Rejected)
630  emit rejected();
631 }
632 
640 {
641  done(Accepted);
642 }
643 
651 {
652  done(Rejected);
653 }
654 
657 {
658  return QWidget::eventFilter(o, e);
659 }
660 
661 /*****************************************************************************
662  Event handlers
663  *****************************************************************************/
664 
665 #ifndef QT_NO_CONTEXTMENU
666 
668 {
669 #if defined(QT_NO_WHATSTHIS) || defined(QT_NO_MENU)
670  Q_UNUSED(e);
671 #else
672  QWidget *w = childAt(e->pos());
673  if (!w) {
674  w = rect().contains(e->pos()) ? this : 0;
675  if (!w)
676  return;
677  }
678  while (w && w->whatsThis().size() == 0 && !w->testAttribute(Qt::WA_CustomWhatsThis))
679  w = w->isWindow() ? 0 : w->parentWidget();
680  if (w) {
681  QWeakPointer<QMenu> p = new QMenu(this);
682  QAction *wt = p.data()->addAction(tr("What's This?"));
683  if (p.data()->exec(e->globalPos()) == wt) {
685  w->mapToGlobal(w->rect().center()));
687  }
688  delete p.data();
689  }
690 #endif
691 }
692 #endif // QT_NO_CONTEXTMENU
693 
696 {
697  // Calls reject() if Escape is pressed. Simulates a button
698  // click for the default button if Enter is pressed. Move focus
699  // for the arrow keys. Ignore the rest.
700 #ifdef Q_WS_MAC
701  if(e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) {
702  reject();
703  } else
704 #endif
705  if (!e->modifiers() || (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter)) {
706  switch (e->key()) {
707  case Qt::Key_Enter:
708  case Qt::Key_Return: {
709  QList<QPushButton*> list = findChildren<QPushButton*>();
710  for (int i=0; i<list.size(); ++i) {
711  QPushButton *pb = list.at(i);
712  if (pb->isDefault() && pb->isVisible()) {
713  if (pb->isEnabled())
714  pb->click();
715  return;
716  }
717  }
718  }
719  break;
720  case Qt::Key_Escape:
721  reject();
722  break;
723  default:
724  e->ignore();
725  return;
726  }
727  } else {
728  e->ignore();
729  }
730 }
731 
734 {
735 #ifndef QT_NO_WHATSTHIS
738 #endif
739  if (isVisible()) {
740  QPointer<QObject> that = this;
741  reject();
742  if (that && isVisible())
743  e->ignore();
744  } else {
745  e->accept();
746  }
747 }
748 
749 /*****************************************************************************
750  Geometry management.
751  *****************************************************************************/
752 
757 {
758  Q_D(QDialog);
759  if (visible) {
761  return;
762 
763  if (!testAttribute(Qt::WA_Moved)) {
764  Qt::WindowStates state = windowState();
766  setAttribute(Qt::WA_Moved, false); // not really an explicit position
767  if (state != windowState())
768  setWindowState(state);
769  }
770  QWidget::setVisible(visible);
771  showExtension(d->doShowExtension);
772  QWidget *fw = window()->focusWidget();
773  if (!fw)
774  fw = this;
775 
776  /*
777  The following block is to handle a special case, and does not
778  really follow propper logic in concern of autoDefault and TAB
779  order. However, it's here to ease usage for the users. If a
780  dialog has a default QPushButton, and first widget in the TAB
781  order also is a QPushButton, then we give focus to the main
782  default QPushButton. This simplifies code for the developers,
783  and actually catches most cases... If not, then they simply
784  have to use [widget*]->setFocus() themselves...
785  */
786  if (d->mainDef && fw->focusPolicy() == Qt::NoFocus) {
787  QWidget *first = fw;
788  while ((first = first->nextInFocusChain()) != fw && first->focusPolicy() == Qt::NoFocus)
789  ;
790  if (first != d->mainDef && qobject_cast<QPushButton*>(first))
791  d->mainDef->setFocus();
792  }
793  if (!d->mainDef && isWindow()) {
794  QWidget *w = fw;
795  while ((w = w->nextInFocusChain()) != fw) {
797  if (pb && pb->autoDefault() && pb->focusPolicy() != Qt::NoFocus) {
798  pb->setDefault(true);
799  break;
800  }
801  }
802  }
803  if (fw && !fw->hasFocus()) {
805  QApplication::sendEvent(fw, &e);
806  }
807 
808 #ifndef QT_NO_ACCESSIBILITY
810 #endif
811 
812  } else {
814  return;
815 
816 #ifndef QT_NO_ACCESSIBILITY
817  if (isVisible())
819 #endif
820 
821  // Reimplemented to exit a modal event loop when the dialog is hidden.
822  QWidget::setVisible(visible);
823  if (d->eventLoop)
824  d->eventLoop->exit();
825  }
826 #ifdef Q_WS_WIN
827  if (d->mainDef && isActiveWindow()) {
828  BOOL snapToDefault = false;
829  if (SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0, &snapToDefault, 0)) {
830  if (snapToDefault)
831  QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center()));
832  }
833  }
834 #endif
835 }
836 
839 {
840  if (!event->spontaneous() && !testAttribute(Qt::WA_Moved)) {
841  Qt::WindowStates state = windowState();
843  setAttribute(Qt::WA_Moved, false); // not really an explicit position
844  if (state != windowState())
845  setWindowState(state);
846  }
847 }
848 
851 {
852 #ifdef Q_WS_X11
853  // if the WM advertises that it will place the windows properly for us, let it do it :)
854  if (X11->isSupportedByWM(ATOM(_NET_WM_FULL_PLACEMENT)))
855  return;
856 #endif
857 
858 #ifdef Q_OS_SYMBIAN
859  if (symbianAdjustedPosition())
860  //dialog has already been positioned
861  return;
862 #endif
863 
864  QPoint p(0, 0);
865  int extraw = 0, extrah = 0, scrn = 0;
866  if (w)
867  w = w->window();
868  QRect desk;
869  if (w) {
870  scrn = QApplication::desktop()->screenNumber(w);
871  } else if (QApplication::desktop()->isVirtualDesktop()) {
873  } else {
874  scrn = QApplication::desktop()->screenNumber(this);
875  }
877 
879  for (int i = 0; (extraw == 0 || extrah == 0) && i < list.size(); ++i) {
880  QWidget * current = list.at(i);
881  if (current->isVisible()) {
882  int framew = current->geometry().x() - current->x();
883  int frameh = current->geometry().y() - current->y();
884 
885  extraw = qMax(extraw, framew);
886  extrah = qMax(extrah, frameh);
887  }
888  }
889 
890  // sanity check for decoration frames. With embedding, we
891  // might get extraordinary values
892  if (extraw == 0 || extrah == 0 || extraw >= 10 || extrah >= 40) {
893  extrah = 40;
894  extraw = 10;
895  }
896 
897 
898  if (w) {
899  // Use mapToGlobal rather than geometry() in case w might
900  // be embedded in another application
901  QPoint pp = w->mapToGlobal(QPoint(0,0));
902  p = QPoint(pp.x() + w->width()/2,
903  pp.y() + w->height()/ 2);
904  } else {
905  // p = middle of the desktop
906  p = QPoint(desk.x() + desk.width()/2, desk.y() + desk.height()/2);
907  }
908 
909  // p = origin of this
910  p = QPoint(p.x()-width()/2 - extraw,
911  p.y()-height()/2 - extrah);
912 
913 
914  if (p.x() + extraw + width() > desk.x() + desk.width())
915  p.setX(desk.x() + desk.width() - width() - extraw);
916  if (p.x() < desk.x())
917  p.setX(desk.x());
918 
919  if (p.y() + extrah + height() > desk.y() + desk.height())
920  p.setY(desk.y() + desk.height() - height() - extrah);
921  if (p.y() < desk.y())
922  p.setY(desk.y());
923 
924  move(p);
925 }
926 
927 #if defined(Q_OS_SYMBIAN)
928 
929 bool QDialog::symbianAdjustedPosition()
930 {
931 #if defined(Q_WS_S60)
932  QPoint p;
933  QPoint oldPos = pos();
934  if (isFullScreen()) {
935  p.setX(0);
936  p.setY(0);
937  } else if (isMaximized()) {
938  TRect statusPaneRect = TRect();
939  if (S60->screenHeightInPixels > S60->screenWidthInPixels) {
940  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane, statusPaneRect);
941  } else {
942  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, statusPaneRect);
943  // In some native layouts, StaCon is not used. Try to fetch the status pane
944  // height from StatusPane component.
945  if (statusPaneRect.IsEmpty())
946  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStatusPane, statusPaneRect);
947  }
948 
949  p.setX(0);
950  p.setY(statusPaneRect.Height());
951  } else {
952  // naive way to deduce screen orientation
953  if (S60->screenHeightInPixels > S60->screenWidthInPixels) {
954  int cbaHeight;
955  TRect rect;
956  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EControlPane, rect);
957  cbaHeight = rect.Height();
958  p.setY(S60->screenHeightInPixels - height() - cbaHeight);
959  p.setX(0);
960  } else {
961  const int scrollbarWidth = style()->pixelMetric(QStyle::PM_ScrollBarExtent);
962  TRect staConTopRect = TRect();
963  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect);
964  if (staConTopRect.IsEmpty()) {
965  TRect cbaRect = TRect();
966  AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EControlPane, cbaRect);
967  AknLayoutUtils::TAknCbaLocation cbaLocation = AknLayoutUtils::CbaLocation();
968  switch (cbaLocation) {
969  case AknLayoutUtils::EAknCbaLocationBottom:
970  p.setY(S60->screenHeightInPixels - height() - cbaRect.Height());
971  p.setX((S60->screenWidthInPixels - width()) >> 1);
972  break;
973  case AknLayoutUtils::EAknCbaLocationRight:
974  p.setY((S60->screenHeightInPixels - height()) >> 1);
975  p.setX(qMax(0,S60->screenWidthInPixels - width() - scrollbarWidth - cbaRect.Width()));
976  break;
977  case AknLayoutUtils::EAknCbaLocationLeft:
978  p.setY((S60->screenHeightInPixels - height()) >> 1);
979  p.setX(qMax(0,scrollbarWidth + cbaRect.Width()));
980  break;
981  }
982  } else {
983  p.setY((S60->screenHeightInPixels - height()) >> 1);
984  p.setX(qMax(0,S60->screenWidthInPixels - width()));
985  }
986  }
987  }
988  if (oldPos != p || p.y() < 0)
989  move(p);
990  return true;
991 #else
992  // TODO - check positioning requirement for Symbian, non-s60
993  return false;
994 #endif
995 }
996 #endif
997 
1016 {
1017  Q_D(QDialog);
1018  d->orientation = orientation;
1019 }
1020 
1036 {
1037  Q_D(const QDialog);
1038  return d->orientation;
1039 }
1040 
1059 {
1060  Q_D(QDialog);
1061  delete d->extension;
1062  d->extension = extension;
1063 
1064  if (!extension)
1065  return;
1066 
1067  if (extension->parentWidget() != this)
1068  extension->setParent(this);
1069  extension->hide();
1070 }
1071 
1088 {
1089  Q_D(const QDialog);
1090  return d->extension;
1091 }
1092 
1093 
1109 void QDialog::showExtension(bool showIt)
1110 {
1111  Q_D(QDialog);
1112  d->doShowExtension = showIt;
1113  if (!d->extension)
1114  return;
1116  return;
1117  if (d->extension->isVisible() == showIt)
1118  return;
1119 
1120  if (showIt) {
1121  d->size = size();
1122  d->min = minimumSize();
1123  d->max = maximumSize();
1124  if (layout())
1125  layout()->setEnabled(false);
1126  QSize s(d->extension->sizeHint()
1127  .expandedTo(d->extension->minimumSize())
1128  .boundedTo(d->extension->maximumSize()));
1129  if (d->orientation == Qt::Horizontal) {
1130  int h = qMax(height(), s.height());
1131  d->extension->setGeometry(width(), 0, s.width(), h);
1132  setFixedSize(width() + s.width(), h);
1133  } else {
1134  int w = qMax(width(), s.width());
1135  d->extension->setGeometry(0, height(), w, s.height());
1136  setFixedSize(w, height() + s.height());
1137  }
1138  d->extension->show();
1139 #ifndef QT_NO_SIZEGRIP
1140  const bool sizeGripEnabled = isSizeGripEnabled();
1141  setSizeGripEnabled(false);
1142  d->sizeGripEnabled = sizeGripEnabled;
1143 #endif
1144  } else {
1145  d->extension->hide();
1146  // workaround for CDE window manager that won't shrink with (-1,-1)
1147  setMinimumSize(d->min.expandedTo(QSize(1, 1)));
1148  setMaximumSize(d->max);
1149  resize(d->size);
1150  if (layout())
1151  layout()->setEnabled(true);
1152 #ifndef QT_NO_SIZEGRIP
1153  setSizeGripEnabled(d->sizeGripEnabled);
1154 #endif
1155  }
1156 }
1157 
1158 
1161 {
1162  Q_D(const QDialog);
1163  if (d->extension) {
1164  if (d->orientation == Qt::Horizontal)
1165  return QSize(QWidget::sizeHint().width(),
1166  qMax(QWidget::sizeHint().height(),d->extension->sizeHint().height()));
1167  else
1168  return QSize(qMax(QWidget::sizeHint().width(), d->extension->sizeHint().width()),
1170  }
1171 #if defined(Q_WS_S60)
1172  // if size is not fixed, try to adjust it according to S60 layoutting
1173  if (minimumSize() != maximumSize()) {
1174  // In S60, dialogs are always the width of screen (in portrait, regardless of current layout)
1175  return QSize(qMin(S60->screenHeightInPixels, S60->screenWidthInPixels), QWidget::sizeHint().height());
1176  } else {
1177  return QWidget::sizeHint();
1178  }
1179 #else
1180  return QWidget::sizeHint();
1181 #endif //Q_WS_S60
1182 }
1183 
1184 
1187 {
1188  Q_D(const QDialog);
1189  if (d->extension) {
1190  if (d->orientation == Qt::Horizontal)
1192  qMax(QWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height()));
1193  else
1194  return QSize(qMax(QWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width()),
1196  }
1197 
1198  return QWidget::minimumSizeHint();
1199 }
1200 
1219 {
1221 }
1222 
1223 
1225 {
1226 #ifndef QT_NO_SIZEGRIP
1227  Q_D(const QDialog);
1228  return !!d->resizer;
1229 #else
1230  return false;
1231 #endif
1232 }
1233 
1234 
1236 {
1237 #ifdef QT_NO_SIZEGRIP
1238  Q_UNUSED(enabled);
1239 #else
1240  Q_D(QDialog);
1241 #ifndef QT_NO_SIZEGRIP
1242  d->sizeGripEnabled = enabled;
1243  if (enabled && d->doShowExtension)
1244  return;
1245 #endif
1246  if (!enabled != !d->resizer) {
1247  if (enabled) {
1248  d->resizer = new QSizeGrip(this);
1249  // adjustSize() processes all events, which is suboptimal
1250  d->resizer->resize(d->resizer->sizeHint());
1251  if (isRightToLeft())
1252  d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft());
1253  else
1254  d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight());
1255  d->resizer->raise();
1256  d->resizer->show();
1257  } else {
1258  delete d->resizer;
1259  d->resizer = 0;
1260  }
1261  }
1262 #endif //QT_NO_SIZEGRIP
1263 }
1264 
1265 
1266 
1269 {
1270 #ifndef QT_NO_SIZEGRIP
1271  Q_D(QDialog);
1272  if (d->resizer) {
1273  if (isRightToLeft())
1274  d->resizer->move(rect().bottomLeft() -d->resizer->rect().bottomLeft());
1275  else
1276  d->resizer->move(rect().bottomRight() -d->resizer->rect().bottomRight());
1277  d->resizer->raise();
1278  }
1279 #endif
1280 }
1281 
1334 #include "moc_qdialog.cpp"
bool isModal() const
Definition: qwidget.h:951
QPoint pos() const
double d
Definition: qnumeric_p.h:62
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
bool sizeGripEnabled
whether the size grip is enabled
Definition: qdialog.h:61
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setEnabled(bool)
Enables this layout if enable is true, otherwise disables it.
Definition: qlayout.cpp:1563
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition: qwidget.cpp:6863
void keyPressEvent(QKeyEvent *)
Reimplemented Function
Definition: qdialog.cpp:695
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QString whatsThis
the widget&#39;s What&#39;s This help text.
Definition: qwidget.h:210
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QSizeGrip class provides a resize handle for resizing top-level windows.
Definition: qsizegrip.h:55
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
QSize size() const
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
void setWindowState(Qt::WindowStates state)
Sets the window state to windowState.
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
virtual QSize minimumSizeHint() const
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition: qpointer.h:70
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
QSize minimumSizeHint() const
Reimplemented Function
Definition: qdialog.cpp:1186
int exec()
Shows the dialog as a modal dialog, blocking until the user closes it.
Definition: qdialog.cpp:524
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
bool autoDefault
whether the push button is an auto default button
Definition: qpushbutton.h:61
bool isVisible() const
Definition: qwidget.h:1005
const QPoint & pos() const
Returns the position of the mouse pointer relative to the widget that received the event...
Definition: qevent.h:412
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
#define SLOT(a)
Definition: qobjectdefs.h:226
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition: qwidget.h:187
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition: qdialog.cpp:639
virtual void reject()
Hides the modal dialog and sets the result code to Rejected.
Definition: qdialog.cpp:650
QWidget * extension() const
Returns the dialog&#39;s extension or 0 if no extension has been defined.
Definition: qdialog.cpp:1087
void setMaximumSize(const QSize &)
Definition: qwidget.h:972
void setDefault(bool)
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QWidget * nextInFocusChain() const
Returns the next widget in this widget&#39;s focus chain.
Definition: qwidget.cpp:6873
void setMinimumSize(const QSize &)
Definition: qwidget.h:969
~QDialog()
Destroys the QDialog, deleting all its children.
Definition: qdialog.cpp:327
void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qdialog.cpp:838
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
bool isActiveWindow() const
bool hasFocus() const
Definition: qwidget.cpp:6583
T * qobject_cast(QObject *object)
Definition: qobject.h:375
bool modal
whether show() should pop up the dialog as modal or modeless
Definition: qdialog.h:62
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
WindowType
Definition: qnamespace.h:270
QAction * addAction(const QString &text)
This convenience function creates a new action with text.
Definition: qmenu.cpp:1453
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define X11
Definition: qt_x11_p.h:724
#define Q_D(Class)
Definition: qglobal.h:2482
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
int height() const
T * data() const
void setExtension(QWidget *extension)
Sets the widget, extension, to be the dialog&#39;s extension, deleting any previous extension.
Definition: qdialog.cpp:1058
Qt::FocusPolicy focusPolicy() const
The QPointer class is a template class that provides guarded pointers to QObject. ...
Definition: qpointer.h:54
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
virtual QSize sizeHint() const
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
#define ATOM(x)
Definition: qt_x11_p.h:723
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
int width() const
Returns the width.
Definition: qsize.h:126
void resizeEvent(QResizeEvent *)
Reimplemented Function
Definition: qdialog.cpp:1268
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void adjustPosition(QWidget *)
Definition: qdialog.cpp:850
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
bool visible
whether the widget is visible
Definition: qwidget.h:191
Qt::WindowModality windowModality() const
void setMainDefault(QPushButton *)
This function sets the default default push button to pushButton.
Definition: qdialog.cpp:376
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
bool qt_wince_is_smartphone()
void closeEvent(QCloseEvent *)
Reimplemented Function
Definition: qdialog.cpp:733
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
int width() const
const char * name
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget&#39;s coordinate system...
Definition: qwidget.h:934
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void setWindowFlags(Qt::WindowFlags type)
Definition: qwidget.cpp:10399
bool spontaneous() const
Returns true if the event originated outside the application (a system event); otherwise returns fals...
Definition: qcoreevent.h:304
QSize sizeHint() const
Reimplemented Function
Definition: qdialog.cpp:1160
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Q_CORE_EXPORT void qWarning(const char *,...)
void rejected()
This signal is emitted when the dialog has been rejected either by the user or by calling reject() or...
static bool inWhatsThisMode()
Returns true if the user interface is in "What&#39;s This?" mode; otherwise returns false.
Definition: qwhatsthis.cpp:648
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void setDefault(QPushButton *)
This function is called by the push button pushButton when it becomes the default button...
Definition: qdialog.cpp:348
void setWindowModality(Qt::WindowModality windowModality)
Definition: qwidget.cpp:2991
void show()
Shows the widget and its child widgets.
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
#define QT_CATCH(A)
Definition: qglobal.h:1537
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
#define SPI_GETSNAPTODEFBUTTON
Definition: qdialog.cpp:81
QRect rect() const
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
bool isEnabled() const
Definition: qwidget.h:948
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
void hide()
Hides the widget.
Definition: qwidget.h:501
bool isMaximized() const
Definition: qwidget.cpp:3074
virtual bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qobject.cpp:1375
bool isSizeGripEnabled() const
Definition: qdialog.cpp:1224
QDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a dialog with parent parent.
Definition: qdialog.cpp:268
void setDefaultAction(QAction *)
Sets the default action to act.
Definition: qmenubar.cpp:2126
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
virtual void done(int)
Closes the dialog and sets its result code to r.
Definition: qdialog.cpp:617
void setResult(int r)
Sets the modal dialog&#39;s result code to i.
Definition: qdialog.cpp:475
QAction * exec()
Executes this menu synchronously.
Definition: qmenu.cpp:2101
bool qt_wince_is_mobile()
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
void setY(int y)
Sets the y coordinate of this point to the given y coordinate.
Definition: qpoint.h:137
void hideDefault()
Hides the default button indicator.
Definition: qdialog.cpp:390
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
void setFixedSize(const QSize &)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing o...
Definition: qwidget.cpp:4284
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
bool eventFilter(QObject *, QEvent *)
Reimplemented Function
Definition: qdialog.cpp:656
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void showExtension(bool)
If showIt is true, the dialog&#39;s extension is shown; otherwise the extension is hidden.
Definition: qdialog.cpp:1109
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
bool isFullScreen() const
Definition: qwidget.cpp:3153
QSize maximumSize() const
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool event(QEvent *e)
Reimplemented Function
Definition: qdialog.cpp:426
void resetModalitySetByOpen()
Definition: qdialog.cpp:399
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
QSize minimumSize() const
bool isDefault() const
void setSizeGripEnabled(bool)
Definition: qdialog.cpp:1235
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
void accepted()
This signal is emitted when the dialog has been accepted either by the user or by calling accept() or...
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
void open()
Shows the dialog as a window modal dialog, returning immediately.
Definition: qdialog.cpp:492
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int screenNumber(const QWidget *widget=0) const
bool isRightToLeft() const
Definition: qwidget.h:428
void click()
Performs a click.
Qt::Orientation orientation() const
Returns the dialog&#39;s extension orientation.
Definition: qdialog.cpp:1035
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413
const QRect availableGeometry(int screen=-1) const
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
void setModal(bool modal)
Definition: qdialog.cpp:1218
void contextMenuEvent(QContextMenuEvent *)
Reimplemented Function
Definition: qdialog.cpp:667
Orientation
Definition: qnamespace.h:174
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void finished(int result)
This signal is emitted when the dialog&#39;s result code has been set, either by the user or by calling d...
void setX(int x)
Sets the x coordinate of this point to the given x coordinate.
Definition: qpoint.h:134
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
#define QT_TRY
Definition: qglobal.h:1536
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
WindowModality
Definition: qnamespace.h:1683
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:364
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
Definition: qeventloop.cpp:181
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
static void leaveWhatsThisMode()
If the user interface is in "What&#39;s This?" mode, this function switches back to normal mode; otherwis...
Definition: qwhatsthis.cpp:662
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
The QWeakPointer class holds a weak reference to a shared pointer.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void setOrientation(Qt::Orientation orientation)
If orientation is Qt::Horizontal, the extension will be displayed to the right of the dialog&#39;s main a...
Definition: qdialog.cpp:1015
The QHelpEvent class provides an event that is used to request helpful information about a particular...
Definition: qevent.h:586