VirtualBox

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


Ignore:
Timestamp:
Apr 17, 2018 11:25:31 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for QIMainDialog and move it to VBoxGlobal library.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r71869 r71870  
    441441        src/UITakeSnapshotDialog.h \
    442442        src/extensions/QIFlowLayout.h \
    443         src/extensions/QIMainDialog.h \
    444443        src/extensions/QIManagerDialog.h \
    445444        src/extensions/QIMenu.h \
     
    659658        src/extensions/QILabelSeparator.h \
    660659        src/extensions/QILineEdit.h \
     660        src/extensions/QIMainDialog.h \
    661661        src/extensions/QIMainWindow.h \
    662662        src/extensions/QIMessageBox.h \
     
    735735        src/extensions/QILabelSeparator.h \
    736736        src/extensions/QILineEdit.h \
     737        src/extensions/QIMainDialog.h \
    737738        src/extensions/QIMainWindow.h \
    738739        src/extensions/QIMessageBox.h \
     
    909910        src/UITakeSnapshotDialog.cpp \
    910911        src/extensions/QIFlowLayout.cpp \
    911         src/extensions/QIMainDialog.cpp \
    912912        src/extensions/QIManagerDialog.cpp \
    913913        src/extensions/QIMenu.cpp \
     
    11591159        src/extensions/QILabelSeparator.cpp \
    11601160        src/extensions/QILineEdit.cpp \
     1161        src/extensions/QIMainDialog.cpp \
    11611162        src/extensions/QIMainWindow.cpp \
    11621163        src/extensions/QIMessageBox.cpp \
     
    12621263        src/extensions/QILabelSeparator.cpp \
    12631264        src/extensions/QILineEdit.cpp \
     1265        src/extensions/QIMainDialog.cpp \
    12641266        src/extensions/QIMainWindow.cpp \
    12651267        src/extensions/QIMessageBox.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMainDialog.cpp

    r71027 r71870  
    55
    66/*
    7  * Copyright (C) 2008-2017 Oracle Corporation
     7 * Copyright (C) 2008-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121
    2222/* Qt includes: */
     23# include <QApplication>
     24# include <QDialogButtonBox>
    2325# include <QDir>
    24 # include <QUrl>
     26# include <QEventLoop>
    2527# include <QMenu>
    2628# include <QProcess>
     29# include <QPushButton>
    2730# include <QSizeGrip>
    28 # include <QEventLoop>
    29 # include <QPushButton>
    30 # include <QApplication>
    31 # include <QDialogButtonBox>
     31# include <QUrl>
    3232
    3333/* GUI includes: */
     
    4141#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4242
     43
    4344QIMainDialog::QIMainDialog(QWidget *pParent /* = 0 */,
    44                            Qt::WindowFlags enmFlags /* = Qt::Dialog */,
     45                           Qt::WindowFlags fFlags /* = Qt::Dialog */,
    4546                           bool fIsAutoCentering /* = true */)
    46     : QMainWindow(pParent, enmFlags)
     47    : QMainWindow(pParent, fFlags)
    4748    , m_fIsAutoCentering(fIsAutoCentering)
    4849    , m_fPolished(false)
     
    109110}
    110111
    111 QPushButton* QIMainDialog::defaultButton() const
     112QPushButton *QIMainDialog::defaultButton() const
    112113{
    113114    return m_pDefaultButton;
     
    152153}
    153154
    154 bool QIMainDialog::event(QEvent *pEvent)
    155 {
     155bool QIMainDialog::eventFilter(QObject *pObject, QEvent *pEvent)
     156{
     157    /* Skip for inactive window: */
     158    if (!isActiveWindow())
     159        return QMainWindow::eventFilter(pObject, pEvent);
     160
     161    /* Skip for children of other than this one window: */
     162    if (qobject_cast<QWidget*>(pObject) &&
     163        qobject_cast<QWidget*>(pObject)->window() != this)
     164        return QMainWindow::eventFilter(pObject, pEvent);
     165
    156166    /* Depending on event-type: */
    157167    switch (pEvent->type())
    158168    {
     169        /* Auto-default-button focus-in processor used to move the "default"
     170         * button property into the currently focused button. */
     171        case QEvent::FocusIn:
     172        {
     173            if (qobject_cast<QPushButton*>(pObject) &&
     174                (pObject->parent() == centralWidget() ||
     175                 qobject_cast<QDialogButtonBox*>(pObject->parent())))
     176            {
     177                qobject_cast<QPushButton*>(pObject)->setDefault(pObject != m_pDefaultButton);
     178                if (m_pDefaultButton)
     179                    m_pDefaultButton->setDefault(pObject == m_pDefaultButton);
     180            }
     181            break;
     182        }
     183        /* Auto-default-button focus-out processor used to remove the "default"
     184         * button property from the previously focused button. */
     185        case QEvent::FocusOut:
     186        {
     187            if (qobject_cast<QPushButton*>(pObject) &&
     188                (pObject->parent() == centralWidget() ||
     189                 qobject_cast<QDialogButtonBox*>(pObject->parent())))
     190            {
     191                if (m_pDefaultButton)
     192                    m_pDefaultButton->setDefault(pObject != m_pDefaultButton);
     193                qobject_cast<QPushButton*>(pObject)->setDefault(pObject == m_pDefaultButton);
     194            }
     195            break;
     196        }
     197        default:
     198            break;
     199    }
     200
     201    /* Call to base-class: */
     202    return QMainWindow::eventFilter(pObject, pEvent);
     203}
     204
     205bool QIMainDialog::event(QEvent *pEvent)
     206{
     207    /* Depending on event-type: */
     208    switch (pEvent->type())
     209    {
    159210        case QEvent::Polish:
    160211        {
     
    172223
    173224void QIMainDialog::showEvent(QShowEvent *pEvent)
     225{
     226    /* Call to polish-event: */
     227    polishEvent(pEvent);
     228
     229    /* Call to base-class: */
     230    QMainWindow::showEvent(pEvent);
     231}
     232
     233void QIMainDialog::polishEvent(QShowEvent *)
    174234{
    175235    /* Make sure we should polish dialog: */
     
    177237        return;
    178238
    179     /* Call to polish-event: */
    180     polishEvent(pEvent);
    181 
    182     /* Mark dialog as polished: */
    183     m_fPolished = true;
    184 }
    185 
    186 void QIMainDialog::polishEvent(QShowEvent*)
    187 {
    188239    /* Explicit centering according to our parent: */
    189240    if (m_fIsAutoCentering)
    190241        VBoxGlobal::centerWidget(this, parentWidget(), false);
     242
     243    /* Mark dialog as polished: */
     244    m_fPolished = true;
    191245}
    192246
     
    262316
    263317    /* Call to base-class: */
    264     return QMainWindow::keyPressEvent(pEvent);
    265 }
    266 
    267 bool QIMainDialog::eventFilter(QObject *pObject, QEvent *pEvent)
    268 {
    269     /* Skip for inactive window: */
    270     if (!isActiveWindow())
    271         return QMainWindow::eventFilter(pObject, pEvent);
    272 
    273     /* Skip for children of other than this one window: */
    274     if (qobject_cast<QWidget*>(pObject) &&
    275         qobject_cast<QWidget*>(pObject)->window() != this)
    276         return QMainWindow::eventFilter(pObject, pEvent);
    277 
    278     /* Depending on event-type: */
    279     switch (pEvent->type())
    280     {
    281         /* Auto-default-button focus-in processor used to move the "default"
    282          * button property into the currently focused button. */
    283         case QEvent::FocusIn:
    284         {
    285             if (qobject_cast<QPushButton*>(pObject) &&
    286                 (pObject->parent() == centralWidget() ||
    287                  qobject_cast<QDialogButtonBox*>(pObject->parent())))
    288             {
    289                 qobject_cast<QPushButton*>(pObject)->setDefault(pObject != m_pDefaultButton);
    290                 if (m_pDefaultButton)
    291                     m_pDefaultButton->setDefault(pObject == m_pDefaultButton);
    292             }
    293             break;
    294         }
    295         /* Auto-default-button focus-out processor used to remove the "default"
    296          * button property from the previously focused button. */
    297         case QEvent::FocusOut:
    298         {
    299             if (qobject_cast<QPushButton*>(pObject) &&
    300                 (pObject->parent() == centralWidget() ||
    301                  qobject_cast<QDialogButtonBox*>(pObject->parent())))
    302             {
    303                 if (m_pDefaultButton)
    304                     m_pDefaultButton->setDefault(pObject != m_pDefaultButton);
    305                 qobject_cast<QPushButton*>(pObject)->setDefault(pObject == m_pDefaultButton);
    306             }
    307             break;
    308         }
    309         default:
    310             break;
    311     }
    312 
    313     /* Call to base-class: */
    314     return QMainWindow::eventFilter(pObject, pEvent);
    315 }
    316 
    317 QPushButton* QIMainDialog::searchDefaultButton() const
     318    QMainWindow::keyPressEvent(pEvent);
     319}
     320
     321QPushButton *QIMainDialog::searchDefaultButton() const
    318322{
    319323    /* Search for the first default-button in the dialog: */
     
    334338    hide();
    335339}
    336 
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMainDialog.h

    r71027 r71870  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - Qt extensions: QIMainDialog class implementation.
     3 * VBox Qt GUI - Qt extensions: QIMainDialog class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2008-2017 Oracle Corporation
     7 * Copyright (C) 2008-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020
    2121/* Qt includes: */
     22#include <QDialog>
    2223#include <QMainWindow>
    2324#include <QPointer>
    24 #include <QDialog>
     25
     26/* GUI includes: */
     27#include "UILibraryDefs.h"
    2528
    2629/* Forward declarations: */
     
    3033
    3134/** QDialog analog based on QMainWindow. */
    32 class QIMainDialog: public QMainWindow
     35class SHARED_LIBRARY_STUFF QIMainDialog : public QMainWindow
    3336{
    3437    Q_OBJECT;
     
    3639public:
    3740
    38     /** Constructor.
    39       * @param pParent           holds the parent widget passed to the base-class,
    40       * @param enmFlags          holds the cumulative window flags passed to the base-class,
    41       * @param fIsAutoCentering  defines whether this dialog should be centered according it's parent. */
     41    /** Constructs main-dialog passing @a pParent and @a fFlags to the base-class.
     42      * @param  fIsAutoCentering  Brigs whether this dialog should be centered according it's parent. */
    4243    QIMainDialog(QWidget *pParent = 0,
    43                  Qt::WindowFlags enmFlags = Qt::Dialog,
     44                 Qt::WindowFlags fFlags = Qt::Dialog,
    4445                 bool fIsAutoCentering = true);
    4546
     
    5152    QDialog::DialogCode exec(bool fApplicationModal = true);
    5253
    53     /** Returns dialog's default-button. */
    54     QPushButton* defaultButton() const;
    55     /** Defines dialog's default-button. */
     54    /** Returns dialog's default button. */
     55    QPushButton *defaultButton() const;
     56    /** Defines dialog's default @a pButton. */
    5657    void setDefaultButton(QPushButton *pButton);
    5758
     
    6869protected:
    6970
    70     /** General event handler. */
    71     virtual bool event(QEvent *pEvent);
    72     /** Show event handler. */
    73     virtual void showEvent(QShowEvent *pEvent);
    74     /** Our own polish event handler. */
     71    /** Preprocesses any Qt @a pEvent for passed @a pObject. */
     72    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     73    /** Handles any Qt @a pEvent. */
     74    virtual bool event(QEvent *pEvent) /* override */;
     75
     76    /** Handles show @a pEvent. */
     77    virtual void showEvent(QShowEvent *pEvent) /* override */;
     78    /** Handles first show @a pEvent. */
    7579    virtual void polishEvent(QShowEvent *pEvent);
    76     /** Resize event handler. */
    77     virtual void resizeEvent(QResizeEvent *pEvent);
    78     /** Key-press event handler. */
    79     virtual void keyPressEvent(QKeyEvent *pEvent);
    80     /** General event filter. */
    81     virtual bool eventFilter(QObject *aObject, QEvent *pEvent);
    8280
    83     /** Function to search for dialog's default-button. */
    84     QPushButton* searchDefaultButton() const;
     81    /** Handles resize @a pEvent. */
     82    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
     83
     84    /** Handles key-press @a pEvent. */
     85    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
     86
     87    /** Searches for dialog's default button. */
     88    QPushButton *searchDefaultButton() const;
    8589
    8690protected slots:
     
    101105
    102106    /** Holds whether this dialog should be centered according it's parent. */
    103     const bool m_fIsAutoCentering;
     107    const bool  m_fIsAutoCentering;
    104108    /** Holds whether this dialog is polished. */
    105     bool m_fPolished;
     109    bool        m_fPolished;
    106110
    107111    /** Holds modal dialog's result code. */
    108     QDialog::DialogCode m_enmResult;
     112    QDialog::DialogCode   m_enmResult;
    109113    /** Holds modal dialog's event-loop. */
    110     QPointer<QEventLoop> m_pEventLoop;
     114    QPointer<QEventLoop>  m_pEventLoop;
    111115
    112     /** Holds dialog's default-button. */
    113     QPointer<QPushButton> m_pDefaultButton;
     116    /** Holds dialog's default button. */
     117    QPointer<QPushButton>  m_pDefaultButton;
    114118    /** Holds dialog's size-grip. */
    115     QPointer<QSizeGrip> m_pSizeGrip;
     119    QPointer<QSizeGrip>    m_pSizeGrip;
    116120};
    117121
Note: See TracChangeset for help on using the changeset viewer.

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