VirtualBox

Changeset 10325 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 7, 2008 2:10:40 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
32947
Message:

FE/Qt4: Fix default/auto-default button and reject behavior of the main dialog.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/QIMainDialog.h

    r10090 r10325  
    5959    virtual bool eventFilter (QObject *aObject, QEvent *aEvent);
    6060
     61    QPushButton* searchDefaultButton() const;
     62
    6163protected slots:
    6264
     
    7880
    7981    QPointer<QSizeGrip> mSizeGrip;
     82
     83    QPushButton* mDefaultButton;
    8084};
    8185
  • trunk/src/VBox/Frontends/VirtualBox4/src/QIMainDialog.cpp

    r10227 r10325  
    3636#include <QSizeGrip>
    3737#include <QPushButton>
     38#include <QDialogButtonBox>
    3839
    3940QIMainDialog::QIMainDialog (QWidget *aParent /* = NULL */, Qt::WindowFlags aFlags /* = Qt::Dialog */)
    4041    : QMainWindow (aParent, aFlags)
    4142    , mRescode (QDialog::Rejected)
     43    , mDefaultButton (NULL)
    4244{
    4345    qApp->installEventFilter (this);
     
    121123bool QIMainDialog::event (QEvent *aEvent)
    122124{
    123 #ifdef Q_WS_MAC
    124125     switch (aEvent->type())
    125126     {
     127#ifdef Q_WS_MAC
    126128          case QEvent::IconDrag:
    127129              {
     
    186188                  break;
    187189              }
     190#endif /* Q_WS_MAC */
     191          case QEvent::Polish:
     192              {
     193                  /* Initially search for the default button. */
     194                  mDefaultButton = searchDefaultButton();
     195                  break;
     196              }
    188197          default:
    189198              break;
    190199     }
    191 #endif /* Q_WS_MAC */
    192200     return QMainWindow::event (aEvent);
    193201}
     
    215223    switch (aEvent->type())
    216224    {
     225        /* Auto-default button focus-in processor used to move the "default"
     226         * button property into the currently focused button. */
     227        case QEvent::FocusIn:
     228            {
     229                if (qobject_cast<QPushButton*> (aObject) &&
     230                    (aObject->parent() == centralWidget() ||
     231                     qobject_cast<QDialogButtonBox*> (aObject->parent()) != NULL))
     232                {
     233                    qobject_cast<QPushButton*> (aObject)->setDefault (aObject != mDefaultButton);
     234                    if (mDefaultButton)
     235                        mDefaultButton->setDefault (aObject == mDefaultButton);
     236                }                                   
     237                break;
     238            }
     239        /* Auto-default button focus-out processor used to remove the "default"
     240         * button property from the previously focused button. */
     241        case QEvent::FocusOut:
     242            {
     243                if (qobject_cast<QPushButton*> (aObject) &&
     244                    (aObject->parent() == centralWidget() ||
     245                     qobject_cast<QDialogButtonBox*> (aObject->parent()) != NULL))
     246                {
     247                    if (mDefaultButton)
     248                        mDefaultButton->setDefault (aObject != mDefaultButton);
     249                    qobject_cast<QPushButton*> (aObject)->setDefault (aObject == mDefaultButton);
     250                }                     
     251                break;
     252            }
    217253        case QEvent::KeyPress:
    218254            {
     
    220256#ifdef Q_WS_MAC
    221257                if (event->modifiers() == Qt::ControlModifier &&
    222                     event->key() == Qt::Key_Period)
     258                    event->key() == Qt::Key_Period &&
     259                    aObject == this &&
     260                    qApp->activePopupWidget() == NULL  &&
     261                    qApp->activePopupWidget() == NULL &&
     262                    (qApp->activeModalWidget() == this ||
     263                     qApp->activeModalWidget() == NULL))
    223264                    reject();
    224265                else
     
    232273                            case Qt::Key_Return:
    233274                                {
    234                                     QList<QPushButton*> list = qFindChildren<QPushButton*> (this);
    235                                     for (int i=0; i < list.size(); ++i)
     275                                    QPushButton *currentDefault = searchDefaultButton();
     276                                    if (currentDefault)
    236277                                    {
    237                                         QPushButton *pb = list.at (i);
    238                                         if (pb->isDefault() && pb->isVisible())
    239                                         {
    240                                             if (pb->isEnabled())
    241                                                 pb->click();
    242                                             break;
    243                                         }
     278                                        /* We handle this, so return true after
     279                                         * that. */
     280                                        currentDefault->click();
     281                                        return true;
    244282                                    }
    245283                                    break;
     
    247285                            case Qt::Key_Escape:
    248286                                {
    249                                     reject();
     287                                    /* Make sure that we only reject if no
     288                                     * popup or other modal widgets are open. */
     289                                    if (aObject == this &&
     290                                        qApp->activePopupWidget() == NULL &&
     291                                        (qApp->activeModalWidget() == this ||
     292                                         qApp->activeModalWidget() == NULL))
     293                                    {
     294                                        reject();
     295                                        return true;
     296                                    }
    250297                                    break;
    251298                                }
     
    258305    return QMainWindow::eventFilter (aObject, aEvent);
    259306}
     307
     308QPushButton* QIMainDialog::searchDefaultButton() const
     309{
     310    /* Search for the first default button in the dialog. */
     311    QPushButton *button = NULL;
     312    QList<QPushButton*> list = qFindChildren<QPushButton*> (this);
     313    foreach (button, list)
     314        if(button->isDefault() &&
     315           (button->parent() == centralWidget() ||
     316            qobject_cast<QDialogButtonBox*> (button->parent()) != NULL))
     317            break;
     318    return button;
     319}
     320
    260321
    261322void QIMainDialog::accept()
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette