Changeset 561 for trunk/src/gui/widgets/qdialogbuttonbox.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/qdialogbuttonbox.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information (qt-info@nokia.com) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation (qt-info@nokia.com) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 47 47 #include <QtGui/qapplication.h> 48 48 #include <QtGui/private/qwidget_p.h> 49 #include <QtGui/qaction.h> 49 50 50 51 #include "qdialogbuttonbox.h" 52 53 #ifdef QT_SOFTKEYS_ENABLED 54 #include <QtGui/qaction.h> 55 #endif 56 51 57 52 58 QT_BEGIN_NAMESPACE … … 58 64 layout that is appropriate to the current widget style. 59 65 60 \ingroup application61 \mainclass 66 \ingroup dialog-classes 67 62 68 63 69 Dialogs and message boxes typically present buttons in a layout that … … 255 261 }; 256 262 263 class QDialogButtonEnabledProxy : public QObject 264 { 265 public: 266 QDialogButtonEnabledProxy(QObject *parent, QWidget *src, QAction *trg) : QObject(parent), source(src), target(trg) 267 { 268 source->installEventFilter(this); 269 target->setEnabled(source->isEnabled()); 270 } 271 ~QDialogButtonEnabledProxy() 272 { 273 source->removeEventFilter(this); 274 } 275 bool eventFilter(QObject *object, QEvent *event) 276 { 277 if (object == source && event->type() == QEvent::EnabledChange) { 278 target->setEnabled(source->isEnabled()); 279 } 280 return false; 281 }; 282 private: 283 QWidget *source; 284 QAction *target; 285 }; 286 287 257 288 class QDialogButtonBoxPrivate : public QWidgetPrivate 258 289 { … … 264 295 QList<QAbstractButton *> buttonLists[QDialogButtonBox::NRoles]; 265 296 QHash<QPushButton *, QDialogButtonBox::StandardButton> standardButtonHash; 297 #ifdef QT_SOFTKEYS_ENABLED 298 QHash<QAbstractButton *, QAction *> softKeyActions; 299 #endif 266 300 267 301 Qt::Orientation orientation; … … 283 317 void retranslateStrings(); 284 318 const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const; 319 #ifdef QT_SOFTKEYS_ENABLED 320 QAction *createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role); 321 #endif 285 322 }; 286 323 … … 305 342 } 306 343 307 344 int left, top, right, bottom; 308 345 setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem); 309 346 getLayoutItemMargins(&left, &top, &right, &bottom); 310 347 buttonLayout->setContentsMargins(-left, -top, -right, -bottom); 311 348 … … 346 383 { 347 384 Q_Q(QDialogButtonBox); 348 const int MacGap = 36 - 8; 385 const int MacGap = 36 - 8; // 8 is the default gap between a widget and a spacer item 349 386 350 387 for (int i = buttonLayout->count() - 1; i >= 0; --i) { … … 537 574 QObject::connect(button, SIGNAL(destroyed()), q, SLOT(_q_handleButtonDestroyed())); 538 575 buttonLists[role].append(button); 576 #ifdef QT_SOFTKEYS_ENABLED 577 QAction *action = createSoftKey(button, role); 578 softKeyActions.insert(button, action); 579 new QDialogButtonEnabledProxy(action, button, action); 580 #endif 539 581 if (doLayout) 540 582 layoutButtons(); 541 583 } 584 585 #ifdef QT_SOFTKEYS_ENABLED 586 QAction* QDialogButtonBoxPrivate::createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role) 587 { 588 Q_Q(QDialogButtonBox); 589 QAction::SoftKeyRole softkeyRole; 590 591 QAction *action = new QAction(button->text(), button); 592 593 switch (role) { 594 case ApplyRole: 595 case AcceptRole: 596 case YesRole: 597 case ActionRole: 598 case HelpRole: 599 softkeyRole = QAction::PositiveSoftKey; 600 break; 601 case RejectRole: 602 case DestructiveRole: 603 case NoRole: 604 case ResetRole: 605 softkeyRole = QAction::NegativeSoftKey; 606 break; 607 default: 608 break; 609 } 610 QObject::connect(action, SIGNAL(triggered()), button, SIGNAL(clicked())); 611 action->setSoftKeyRole(softkeyRole); 612 613 614 QWidget *dialog = 0; 615 QWidget *p = q; 616 while (p && !p->isWindow()) { 617 p = p->parentWidget(); 618 if ((dialog = qobject_cast<QDialog *>(p))) 619 break; 620 } 621 622 if (dialog) { 623 dialog->addAction(action); 624 } else { 625 q->addAction(action); 626 } 627 628 return action; 629 } 630 #endif 542 631 543 632 void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons) … … 632 721 QPushButton *button = it.key(); 633 722 button->setText(QDialogButtonBox::tr(buttonText)); 723 #ifdef QT_SOFTKEYS_ENABLED 724 QAction *action = softKeyActions.value(button, 0); 725 if (action) 726 action->setText(button->text()); 727 #endif 634 728 } 635 729 ++it; … … 824 918 { 825 919 Q_D(QDialogButtonBox); 920 #ifdef QT_SOFTKEYS_ENABLED 921 // Delete softkey actions as they have the buttons as parents 922 qDeleteAll(d->softKeyActions.values()); 923 d->softKeyActions.clear(); 924 #endif 826 925 // Remove the created standard buttons, they should be in the other lists, which will 827 926 // do the deletion … … 901 1000 } 902 1001 } 1002 #ifdef QT_SOFTKEYS_ENABLED 1003 QAction *action = d->softKeyActions.value(button, 0); 1004 if (action) { 1005 d->softKeyActions.remove(button); 1006 delete action; 1007 } 1008 #endif 903 1009 if (!d->internalRemove) 904 1010 button->setParent(0); … … 969 1075 { 970 1076 Q_D(QDialogButtonBox); 1077 #ifdef QT_SOFTKEYS_ENABLED 1078 // Delete softkey actions since they have the buttons as parents 1079 qDeleteAll(d->softKeyActions.values()); 1080 d->softKeyActions.clear(); 1081 #endif 971 1082 // Clear out all the old standard buttons, then recreate them. 972 1083 qDeleteAll(d->standardButtonHash.keys()); … … 1126 1237 if (!hasDefault && firstAcceptButton) 1127 1238 firstAcceptButton->setDefault(true); 1239 #ifdef QT_SOFTKEYS_ENABLED 1240 if (dialog) 1241 setFixedSize(0,0); 1242 #endif 1128 1243 }else if (event->type() == QEvent::LanguageChange) { 1129 1244 d->retranslateStrings(); 1130 1245 } 1246 #ifdef QT_SOFTKEYS_ENABLED 1247 else if (event->type() == QEvent::ParentChange) { 1248 QWidget *dialog = 0; 1249 QWidget *p = this; 1250 while (p && !p->isWindow()) { 1251 p = p->parentWidget(); 1252 if ((dialog = qobject_cast<QDialog *>(p))) 1253 break; 1254 } 1255 1256 // If the parent changes, then move the softkeys 1257 for (QHash<QAbstractButton *, QAction *>::const_iterator it = d->softKeyActions.constBegin(); 1258 it != d->softKeyActions.constEnd(); ++it) { 1259 QAction *current = it.value(); 1260 QList<QWidget *> widgets = current->associatedWidgets(); 1261 foreach (QWidget *w, widgets) 1262 w->removeAction(current); 1263 if (dialog) 1264 dialog->addAction(current); 1265 else 1266 addAction(current); 1267 } 1268 } 1269 #endif 1131 1270 1132 1271 return QWidget::event(event);
Note:
See TracChangeset
for help on using the changeset viewer.