Qt 4.8
qdialogbuttonbox.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 <QtCore/qhash.h>
43 #include <QtGui/qpushbutton.h>
44 #include <QtGui/qstyle.h>
45 #include <QtGui/qlayout.h>
46 #include <QtGui/qdialog.h>
47 #include <QtGui/qapplication.h>
48 #include <QtGui/private/qwidget_p.h>
49 #include <QtGui/qaction.h>
50 
51 #include "qdialogbuttonbox.h"
52 
53 #ifdef QT_SOFTKEYS_ENABLED
54 #include <QtGui/qaction.h>
55 #endif
56 
57 
59 
157 enum {
167 
168  AlternateRole = 0x10000000,
169  Stretch = 0x20000000,
170  EOL = 0x40000000,
171  Reverse = 0x80000000
172 };
173 
175 {
176  switch (button) {
184 
189 
192 
195 
198 
202 
206 
210 
211  case QDialogButtonBox::NoButton: // NoButton means zero buttons, not "No" button
212  ;
213  }
214 
216 }
217 
218 static const uint layouts[2][5][14] =
219 {
220  // Qt::Horizontal
221  {
222  // WinLayout
224  HelpRole, EOL, EOL, EOL },
225 
226  // MacLayout
229 
230  // KdeLayout
233 
234  // GnomeLayout
237 
238  // Mac modeless
240  },
241 
242  // Qt::Vertical
243  {
244  // WinLayout
246  HelpRole, Stretch, EOL, EOL, EOL },
247 
248  // MacLayout
250  ResetRole, HelpRole, EOL, EOL },
251 
252  // KdeLayout
255 
256  // GnomeLayout
258  ResetRole, HelpRole, EOL, EOL, EOL },
259 
260  // Mac modeless
262  }
263 };
264 
265 #if defined(QT_SOFTKEYS_ENABLED) && !defined(QT_NO_ACTION)
266 class QDialogButtonEnabledProxy : public QObject
267 {
268 public:
269  QDialogButtonEnabledProxy(QObject *parent, QWidget *src, QAction *trg) : QObject(parent), source(src), target(trg)
270  {
271  source->installEventFilter(this);
272  target->setEnabled(source->isEnabled());
273  }
274  ~QDialogButtonEnabledProxy()
275  {
276  source->removeEventFilter(this);
277  }
278  bool eventFilter(QObject *object, QEvent *event)
279  {
280  if (object == source && event->type() == QEvent::EnabledChange) {
281  target->setEnabled(source->isEnabled());
282  }
283  return false;
284  };
285 private:
286  QWidget *source;
287  QAction *target;
288 };
289 #endif
290 
292 {
294 
295 public:
297 
300 #ifdef QT_SOFTKEYS_ENABLED
302 #endif
303 
308  bool center;
309 
310  void createStandardButtons(QDialogButtonBox::StandardButtons buttons);
311 
312  void layoutButtons();
313  void initLayout();
314  void resetLayout();
315  QPushButton *createButton(QDialogButtonBox::StandardButton button, bool doLayout = true);
316  void addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role, bool doLayout = true);
317  void _q_handleButtonDestroyed();
318  void _q_handleButtonClicked();
319  void addButtonsToLayout(const QList<QAbstractButton *> &buttonList, bool reverse);
320  void retranslateStrings();
321  const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const;
322 #if defined(QT_SOFTKEYS_ENABLED) && !defined(QT_NO_ACTION)
323  QAction *createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role);
324 #endif
325 };
326 
328  : orientation(orient), buttonLayout(0), internalRemove(false), center(false)
329 {
330 }
331 
333 {
336  bool createNewLayout = buttonLayout == 0
339  if (createNewLayout) {
340  delete buttonLayout;
342  buttonLayout = new QHBoxLayout(q);
343  else
344  buttonLayout = new QVBoxLayout(q);
345  }
346 
347  int left, top, right, bottom;
349  getLayoutItemMargins(&left, &top, &right, &bottom);
350  buttonLayout->setContentsMargins(-left, -top, -right, -bottom);
351 
352  if (!q->testAttribute(Qt::WA_WState_OwnSizePolicy)) {
354  if (orientation == Qt::Vertical)
355  sp.transpose();
356  q->setSizePolicy(sp);
357  q->setAttribute(Qt::WA_WState_OwnSizePolicy, false);
358  }
359 
360  // ### move to a real init() function
361  q->setFocusPolicy(Qt::TabFocus);
362 }
363 
365 {
366  //delete buttonLayout;
367  initLayout();
368  layoutButtons();
369 }
370 
372  bool reverse)
373 {
374  int start = reverse ? buttonList.count() - 1 : 0;
375  int end = reverse ? -1 : buttonList.count();
376  int step = reverse ? -1 : 1;
377 
378  for (int i = start; i != end; i += step) {
379  QAbstractButton *button = buttonList.at(i);
380  buttonLayout->addWidget(button);
381  button->show();
382  }
383 }
384 
386 {
388  const int MacGap = 36 - 8; // 8 is the default gap between a widget and a spacer item
389 
390  for (int i = buttonLayout->count() - 1; i >= 0; --i) {
391  QLayoutItem *item = buttonLayout->takeAt(i);
392  if (QWidget *widget = item->widget())
393  widget->hide();
394  delete item;
395  }
396 
397  int tmpPolicy = layoutPolicy;
398 
399  static const int M = 5;
400  static const int ModalRoles[M] = { AcceptRole, RejectRole, DestructiveRole, YesRole, NoRole };
401  if (tmpPolicy == QDialogButtonBox::MacLayout) {
402  bool hasModalButton = false;
403  for (int i = 0; i < M; ++i) {
404  if (!buttonLists[ModalRoles[i]].isEmpty()) {
405  hasModalButton = true;
406  break;
407  }
408  }
409  if (!hasModalButton)
410  tmpPolicy = 4; // Mac modeless
411  }
412 
413  const uint *currentLayout = layouts[orientation == Qt::Vertical][tmpPolicy];
414 
415  if (center)
417 
419 
420  while (*currentLayout != EOL) {
421  int role = (*currentLayout & ~Reverse);
422  bool reverse = (*currentLayout & Reverse);
423 
424  switch (role) {
425  case Stretch:
426  if (!center)
428  break;
429  case AcceptRole: {
430  if (acceptRoleList.isEmpty())
431  break;
432  // Only the first one
433  QAbstractButton *button = acceptRoleList.first();
434  buttonLayout->addWidget(button);
435  button->show();
436  }
437  break;
438  case AlternateRole:
439  {
440  if (acceptRoleList.size() < 2)
441  break;
442  QList<QAbstractButton *> list = acceptRoleList;
443  list.removeFirst();
444  addButtonsToLayout(list, reverse);
445  }
446  break;
447  case DestructiveRole:
448  {
449  const QList<QAbstractButton *> &list = buttonLists[role];
450 
451  /*
452  Mac: Insert a gap on the left of the destructive
453  buttons to ensure that they don't get too close to
454  the help and action buttons (but only if there are
455  some buttons to the left of the destructive buttons
456  (and the stretch, whence buttonLayout->count() > 1
457  and not 0)).
458  */
459  if (tmpPolicy == QDialogButtonBox::MacLayout
460  && !list.isEmpty() && buttonLayout->count() > 1)
461  buttonLayout->addSpacing(MacGap);
462 
463  addButtonsToLayout(list, reverse);
464 
465  /*
466  Insert a gap between the destructive buttons and the
467  accept and reject buttons.
468  */
469  if (tmpPolicy == QDialogButtonBox::MacLayout && !list.isEmpty())
470  buttonLayout->addSpacing(MacGap);
471  }
472  break;
473  case RejectRole:
474  case ActionRole:
475  case HelpRole:
476  case YesRole:
477  case NoRole:
478  case ApplyRole:
479  case ResetRole:
480  addButtonsToLayout(buttonLists[role], reverse);
481  }
482  ++currentLayout;
483  }
484 
485  QWidget *lastWidget = 0;
486  q->setFocusProxy(0);
487  for (int i = 0; i < buttonLayout->count(); ++i) {
488  QLayoutItem *item = buttonLayout->itemAt(i);
489  if (QWidget *widget = item->widget()) {
490  if (lastWidget)
491  QWidget::setTabOrder(lastWidget, widget);
492  else
493  q->setFocusProxy(widget);
494  lastWidget = widget;
495  }
496  }
497 
498  if (center)
500 }
501 
503  bool doLayout)
504 {
506  const char *buttonText = 0;
507  int icon = 0;
508 
509  switch (sbutton) {
512  break;
515  break;
518  break;
521  break;
524  break;
527  break;
530  break;
533  break;
536  break;
539  break;
542  break;
550  break;
552  return 0;
553  ;
554  }
555  buttonText = standardButtonText(sbutton);
556 
557  QPushButton *button = new QPushButton(QDialogButtonBox::tr(buttonText), q);
558  QStyle *style = q->style();
559  if (style->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q) && icon != 0)
560  button->setIcon(style->standardIcon(QStyle::StandardPixmap(icon), 0, q));
561  if (style != QApplication::style()) // Propagate style
562  button->setStyle(style);
563  standardButtonHash.insert(button, sbutton);
564  if (roleFor(sbutton) != QDialogButtonBox::InvalidRole) {
565  addButton(button, roleFor(sbutton), doLayout);
566  } else {
567  qWarning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
568  }
569 
570 #ifdef Q_WS_MAC
571  // Since mnemonics is off by default on Mac, we add a Cmd-D
572  // shortcut here to e.g. make the "Don't Save" button work nativly:
573  if (sbutton == QDialogButtonBox::Discard)
574  button->setShortcut(QKeySequence(QLatin1String("Ctrl+D")));
575 #endif
576 
577  return button;
578 }
579 
581  bool doLayout)
582 {
584  QObject::connect(button, SIGNAL(clicked()), q, SLOT(_q_handleButtonClicked()));
585  QObject::connect(button, SIGNAL(destroyed()), q, SLOT(_q_handleButtonDestroyed()));
586  buttonLists[role].append(button);
587 #if defined(QT_SOFTKEYS_ENABLED) && !defined(QT_NO_ACTION)
588  QAction *action = createSoftKey(button, role);
589  softKeyActions.insert(button, action);
590  new QDialogButtonEnabledProxy(action, button, action);
591 #endif
592  if (doLayout)
593  layoutButtons();
594 }
595 
596 #if defined(QT_SOFTKEYS_ENABLED) && !defined(QT_NO_ACTION)
597 QAction* QDialogButtonBoxPrivate::createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role)
598 {
600  QAction::SoftKeyRole softkeyRole;
601 
602  QAction *action = new QAction(button->text(), button);
603 
604  switch (role) {
605  case ApplyRole:
606  case AcceptRole:
607  case YesRole:
608  case ActionRole:
609  case HelpRole:
610  softkeyRole = QAction::PositiveSoftKey;
611  break;
612  case RejectRole:
613  case DestructiveRole:
614  case NoRole:
615  case ResetRole:
616  softkeyRole = QAction::NegativeSoftKey;
617  break;
618  default:
619  break;
620  }
621  QObject::connect(action, SIGNAL(triggered()), button, SIGNAL(clicked()));
622  action->setSoftKeyRole(softkeyRole);
623 
624 
625  QWidget *dialog = 0;
626  QWidget *p = q;
627  while (p && !p->isWindow()) {
628  p = p->parentWidget();
629  if ((dialog = qobject_cast<QDialog *>(p)))
630  break;
631  }
632 
633  if (dialog) {
634  dialog->addAction(action);
635  } else {
636  q->addAction(action);
637  }
638 
639  return action;
640 }
641 #endif
642 
643 void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons)
644 {
646  while (i <= QDialogButtonBox::LastButton) {
647  if (i & buttons) {
649  }
650  i = i << 1;
651  }
652  layoutButtons();
653 }
654 
656 {
657  const char *buttonText = 0;
658  bool gnomeLayout = (layoutPolicy == QDialogButtonBox::GnomeLayout);
659  switch (sbutton) {
661  buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&OK") : QT_TRANSLATE_NOOP("QDialogButtonBox", "OK");
662  break;
664  buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Save") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Save");
665  break;
667  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Open");
668  break;
670  buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Cancel") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Cancel");
671  break;
673  buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Close") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Close");
674  break;
676  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Apply");
677  break;
679  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Reset");
680  break;
682  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Help");
683  break;
686  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Don't Save");
688  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Close without Saving");
689  else
690  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Discard");
691  break;
693  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&Yes");
694  break;
696  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Yes to &All");
697  break;
699  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&No");
700  break;
702  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "N&o to All");
703  break;
705  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Save All");
706  break;
708  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Abort");
709  break;
711  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Retry");
712  break;
714  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Ignore");
715  break;
717  buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Restore Defaults");
718  break;
720  ;
721  } // switch
722  return buttonText;
723 }
724 
726 {
727  const char *buttonText = 0;
729  while (it != standardButtonHash.end()) {
730  buttonText = standardButtonText(it.value());
731  if (buttonText) {
732  QPushButton *button = it.key();
733  button->setText(QDialogButtonBox::tr(buttonText));
734 #if defined(QT_SOFTKEYS_ENABLED) && !defined(QT_NO_ACTION)
735  QAction *action = softKeyActions.value(button, 0);
736  if (action)
737  action->setText(button->text());
738 #endif
739  }
740  ++it;
741  }
742 }
743 
750  : QWidget(*new QDialogButtonBoxPrivate(Qt::Horizontal), parent, 0)
751 {
752  d_func()->initLayout();
753 }
754 
761  : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0)
762 {
763  d_func()->initLayout();
764 }
765 
773  QWidget *parent)
774  : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0)
775 {
776  d_func()->initLayout();
777  d_func()->createStandardButtons(buttons);
778 }
779 
784 {
785 }
786 
930 {
931  return d_func()->orientation;
932 }
933 
935 {
937  if (orientation == d->orientation)
938  return;
939 
940  d->orientation = orientation;
941  d->resetLayout();
942 }
943 
950 {
952 #ifdef QT_SOFTKEYS_ENABLED
953  // Delete softkey actions as they have the buttons as parents
954  qDeleteAll(d->softKeyActions.values());
955  d->softKeyActions.clear();
956 #endif
957  // Remove the created standard buttons, they should be in the other lists, which will
958  // do the deletion
959  d->standardButtonHash.clear();
960  for (int i = 0; i < NRoles; ++i) {
961  QList<QAbstractButton *> &list = d->buttonLists[i];
962  while (list.count()) {
963  QAbstractButton *button = list.takeAt(0);
964  QObject::disconnect(button, SIGNAL(destroyed()), this, SLOT(_q_handleButtonDestroyed()));
965  delete button;
966  }
967  }
968 }
969 
976 {
977  Q_D(const QDialogButtonBox);
978  QList<QAbstractButton *> finalList;
979  for (int i = 0; i < NRoles; ++i) {
980  const QList<QAbstractButton *> &list = d->buttonLists[i];
981  for (int j = 0; j < list.count(); ++j)
982  finalList.append(list.at(j));
983  }
984  return finalList;
985 }
986 
994 {
995  Q_D(const QDialogButtonBox);
996  for (int i = 0; i < NRoles; ++i) {
997  const QList<QAbstractButton *> &list = d->buttonLists[i];
998  for (int j = 0; j < list.count(); ++j) {
999  if (list.at(j) == button)
1000  return ButtonRole(i);
1001  }
1002  }
1003  return InvalidRole;
1004 }
1005 
1012 {
1014 
1015  if (!button)
1016  return;
1017 
1018  // Remove it from the standard button hash first and then from the roles
1019  if (QPushButton *pushButton = qobject_cast<QPushButton *>(button))
1020  d->standardButtonHash.remove(pushButton);
1021  for (int i = 0; i < NRoles; ++i) {
1022  QList<QAbstractButton *> &list = d->buttonLists[i];
1023  for (int j = 0; j < list.count(); ++j) {
1024  if (list.at(j) == button) {
1025  list.takeAt(j);
1026  if (!d->internalRemove) {
1027  disconnect(button, SIGNAL(clicked()), this, SLOT(_q_handleButtonClicked()));
1028  disconnect(button, SIGNAL(destroyed()), this, SLOT(_q_handleButtonDestroyed()));
1029  }
1030  break;
1031  }
1032  }
1033  }
1034 #if defined(QT_SOFTKEYS_ENABLED) && !defined(QT_NO_ACTION)
1035  QAction *action = d->softKeyActions.value(button, 0);
1036  if (action) {
1037  d->softKeyActions.remove(button);
1038  delete action;
1039  }
1040 #endif
1041  if (!d->internalRemove)
1042  button->setParent(0);
1043 }
1044 
1057 {
1059  if (role <= InvalidRole || role >= NRoles) {
1060  qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added");
1061  return;
1062  }
1063  removeButton(button);
1064  button->setParent(this);
1065  d->addButton(button, role);
1066 }
1067 
1076 {
1078  if (role <= InvalidRole || role >= NRoles) {
1079  qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added");
1080  return 0;
1081  }
1082  QPushButton *button = new QPushButton(text, this);
1083  d->addButton(button, role);
1084  return button;
1085 }
1086 
1095 {
1097  return d->createButton(button);
1098 }
1099 
1112 {
1114 #ifdef QT_SOFTKEYS_ENABLED
1115  // Delete softkey actions since they have the buttons as parents
1116  qDeleteAll(d->softKeyActions.values());
1117  d->softKeyActions.clear();
1118 #endif
1119  // Clear out all the old standard buttons, then recreate them.
1120  qDeleteAll(d->standardButtonHash.keys());
1121  d->standardButtonHash.clear();
1122 
1123  d->createStandardButtons(buttons);
1124 }
1125 
1126 QDialogButtonBox::StandardButtons QDialogButtonBox::standardButtons() const
1127 {
1128  Q_D(const QDialogButtonBox);
1129  StandardButtons standardButtons = NoButton;
1130  QHash<QPushButton *, StandardButton>::const_iterator it = d->standardButtonHash.constBegin();
1131  while (it != d->standardButtonHash.constEnd()) {
1132  standardButtons |= it.value();
1133  ++it;
1134  }
1135  return standardButtons;
1136 }
1137 
1145 {
1146  Q_D(const QDialogButtonBox);
1147  return d->standardButtonHash.key(which);
1148 }
1149 
1157 {
1158  Q_D(const QDialogButtonBox);
1159  return d->standardButtonHash.value(static_cast<QPushButton *>(button));
1160 }
1161 
1163 {
1165  if (QAbstractButton *button = qobject_cast<QAbstractButton *>(q->sender())) {
1166  emit q->clicked(button);
1167 
1168  switch (q->buttonRole(button)) {
1169  case AcceptRole:
1170  case YesRole:
1171  emit q->accepted();
1172  break;
1173  case RejectRole:
1174  case NoRole:
1175  emit q->rejected();
1176  break;
1177  case HelpRole:
1178  emit q->helpRequested();
1179  break;
1180  default:
1181  break;
1182  }
1183  }
1184 }
1185 
1187 {
1189  if (QObject *object = q->sender()) {
1190  QBoolBlocker skippy(internalRemove);
1191  q->removeButton(static_cast<QAbstractButton *>(object));
1192  }
1193 }
1194 
1210 {
1212  if (d->center != center) {
1213  d->center = center;
1214  d->resetLayout();
1215  }
1216 }
1217 
1219 {
1220  Q_D(const QDialogButtonBox);
1221  return d->center;
1222 }
1223 
1228 {
1229  typedef QHash<QPushButton *, QDialogButtonBox::StandardButton> StandardButtonHash;
1230 
1232  switch (event->type()) {
1233  case QEvent::StyleChange: // Propagate style
1234  if (!d->standardButtonHash.empty()) {
1235  QStyle *newStyle = style();
1236  const StandardButtonHash::iterator end = d->standardButtonHash.end();
1237  for (StandardButtonHash::iterator it = d->standardButtonHash.begin(); it != end; ++it)
1238  it.key()->setStyle(newStyle);
1239  }
1240  // fallthrough intended
1241 #ifdef Q_WS_MAC
1242  case QEvent::MacSizeChange:
1243 #endif
1244  d->resetLayout();
1245  QWidget::changeEvent(event);
1246  break;
1247  default:
1248  QWidget::changeEvent(event);
1249  break;
1250  }
1251 }
1252 
1257 {
1259  if (event->type() == QEvent::Show) {
1260  QList<QAbstractButton *> acceptRoleList = d->buttonLists[AcceptRole];
1261  QPushButton *firstAcceptButton = acceptRoleList.isEmpty() ? 0 : qobject_cast<QPushButton *>(acceptRoleList.at(0));
1262  bool hasDefault = false;
1263  QWidget *dialog = 0;
1264  QWidget *p = this;
1265  while (p && !p->isWindow()) {
1266  p = p->parentWidget();
1267  if ((dialog = qobject_cast<QDialog *>(p)))
1268  break;
1269  }
1270 
1271  foreach (QPushButton *pb, (dialog ? dialog : this)->findChildren<QPushButton *>()) {
1272  if (pb->isDefault() && pb != firstAcceptButton) {
1273  hasDefault = true;
1274  break;
1275  }
1276  }
1277  if (!hasDefault && firstAcceptButton)
1278  firstAcceptButton->setDefault(true);
1279 #ifdef QT_SOFTKEYS_ENABLED
1280  if (dialog)
1281  setFixedSize(0,0);
1282 #endif
1283  }else if (event->type() == QEvent::LanguageChange) {
1284  d->retranslateStrings();
1285  }
1286 #if defined(QT_SOFTKEYS_ENABLED) && !defined(QT_NO_ACTION)
1287  else if (event->type() == QEvent::ParentChange) {
1288  QWidget *dialog = 0;
1289  QWidget *p = this;
1290  while (p && !p->isWindow()) {
1291  p = p->parentWidget();
1292  if ((dialog = qobject_cast<QDialog *>(p)))
1293  break;
1294  }
1295 
1296  // If the parent changes, then move the softkeys
1297  for (QHash<QAbstractButton *, QAction *>::const_iterator it = d->softKeyActions.constBegin();
1298  it != d->softKeyActions.constEnd(); ++it) {
1299  QAction *current = it.value();
1300  QList<QWidget *> widgets = current->associatedWidgets();
1301  foreach (QWidget *w, widgets)
1302  w->removeAction(current);
1303  if (dialog)
1304  dialog->addAction(current);
1305  else
1306  addAction(current);
1307  }
1308  }
1309 #endif
1310 
1311  return QWidget::event(event);
1312 }
1313 
1315 
1316 #include "moc_qdialogbuttonbox.cpp"
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
T qobject_cast(QObject *object)
Definition: qobject.h:375
double d
Definition: qnumeric_p.h:62
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
QLayoutItem * itemAt(int) const
Reimplemented Function
Definition: qboxlayout.cpp:778
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
The QBoxLayout class lines up child widgets horizontally or vertically.
Definition: qboxlayout.h:60
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString text() const
void setText(const QString &text)
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
EventRef event
QPointer< QWidget > widget
void addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role, bool doLayout=true)
void setShortcut(const QKeySequence &key)
#define it(className, varName)
QList< QAbstractButton * > buttonLists[QDialogButtonBox::NRoles]
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
void addButtonsToLayout(const QList< QAbstractButton *> &buttonList, bool reverse)
void removeButton(QAbstractButton *button)
Removes button from the button box without deleting it and sets its parent to zero.
static C reverse(const C &l)
void createStandardButtons(QDialogButtonBox::StandardButtons buttons)
#define SLOT(a)
Definition: qobjectdefs.h:226
static Qt::MouseButtons buttons
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void setDefault(bool)
static QDialogButtonBox::ButtonRole roleFor(QDialogButtonBox::StandardButton button)
~QDialogButtonBox()
Destroys the button box.
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QStyle * style()
Returns the application&#39;s style object.
QString text
the text shown on the button
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void setLayoutItemMargins(int left, int top, int right, int bottom)
Definition: qwidget.cpp:12860
#define Q_D(Class)
Definition: qglobal.h:2482
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
void setStyle(QStyle *)
Sets the widget&#39;s GUI style to style.
Definition: qwidget.cpp:2772
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QStyle * style() const
Definition: qwidget.cpp:2742
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
#define Q_Q(Class)
Definition: qglobal.h:2483
QPushButton * createButton(QDialogButtonBox::StandardButton button, bool doLayout=true)
Qt::Orientation orientation() const
QList< QWidget * > associatedWidgets() const
Returns a list of widgets this action has been added to.
Definition: qaction.cpp:416
QPushButton * button(StandardButton which) const
Returns the QPushButton corresponding to the standard button which, or 0 if the standard button doesn...
#define M(row, col)
void addStretch(int stretch=0)
Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const char * standardButtonText(QDialogButtonBox::StandardButton sbutton) const
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Returns an icon for the given standardIcon.
Definition: qstyle.cpp:2327
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool isEmpty(const char *str)
void clear()
Clears the button box, deleting all buttons within it.
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
int count() const
Reimplemented Function
Definition: qboxlayout.cpp:769
void setSoftKeyRole(SoftKeyRole softKeyRole)
Definition: qaction.cpp:1599
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
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
const T & value() const
Returns the current item&#39;s value.
Definition: qhash.h:420
Q_CORE_EXPORT void qWarning(const char *,...)
void setText(const QString &text)
Definition: qaction.cpp:860
unsigned int uint
Definition: qglobal.h:996
ButtonRole buttonRole(QAbstractButton *button) const
Returns the button role for the specified button.
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
QDialogButtonBox::ButtonLayout layoutPolicy
SoftKeyRole
This enum describes how an action should be placed in the softkey bar.
Definition: qaction.h:96
void show()
Shows the widget and its child widgets.
void addButton(QAbstractButton *button, ButtonRole role)
Adds the given button to the button box with the specified role.
void setCenterButtons(bool center)
void hide()
Hides the widget.
Definition: qwidget.h:501
void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const
Definition: qwidget.cpp:12848
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
QDialogButtonBoxPrivate(Qt::Orientation orient)
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QDialogButtonBox(QWidget *parent=0)
Constructs an empty, horizontal button box with the given parent.
void setFocusProxy(QWidget *)
Sets the widget&#39;s focus proxy to widget w.
Definition: qwidget.cpp:6537
QLayoutItem * takeAt(int)
Reimplemented Function
Definition: qboxlayout.cpp:787
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void setOrientation(Qt::Orientation orientation)
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
QList< QAbstractButton * > buttons() const
Returns a list of all the buttons that have been added to the button box.
void clicked(QAbstractButton *button)
This signal is emitted when a button inside the button box is clicked.
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
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
StandardButton
These enums describe flags for standard buttons.
void addSpacing(int size)
Adds a non-stretchable space (a QSpacerItem) with size size to the end of this box layout...
void changeEvent(QEvent *event)
Reimplemented Function
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
QHash< QPushButton *, QDialogButtonBox::StandardButton > standardButtonHash
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
bool event(QEvent *event)
Reimplemented Function
Definition: qnamespace.h:54
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
bool isDefault() const
T takeAt(int i)
Removes the item at index position i and returns it.
Definition: qlist.h:484
The QHBoxLayout class lines up widgets horizontally.
Definition: qboxlayout.h:129
void transpose()
Definition: qsizepolicy.h:229
ButtonRole
This enum describes the roles that can be used to describe buttons in the button box.
QObject * parent
Definition: qobject.h:92
void setContentsMargins(int left, int top, int right, int bottom)
Sets the left, top, right, and bottom margins to use around the layout.
Definition: qlayout.cpp:502
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
ButtonLayout
This enum describes the layout policy to be used when arranging the buttons contained in the button b...
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
StandardButton standardButton(QAbstractButton *button) const
Returns the standard button enum value corresponding to the given button, or NoButton if the given bu...
static void setTabOrder(QWidget *, QWidget *)
Puts the second widget after the first widget in the focus order.
Definition: qwidget.cpp:6975
static const KeyPair *const end
void setIcon(const QIcon &icon)
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
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
StandardButtons standardButtons() const
bool centerButtons() const
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
#define text
Definition: qobjectdefs.h:80
void setStandardButtons(StandardButtons buttons)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static const uint layouts[2][5][14]