VirtualBox

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


Ignore:
Timestamp:
Mar 15, 2018 10:21:52 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9049: Preparing to common library: Build the meta for QIDialogButtonBox, doxygen, cleanup.

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

Legend:

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

    r71346 r71348  
    318318        src/extensions/QIComboBox.h \
    319319        src/extensions/QIDialog.h \
     320        src/extensions/QIDialogButtonBox.h \
    320321        src/extensions/QIFileDialog.h \
    321322        src/extensions/QIFlowLayout.h \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialogButtonBox.cpp

    r69500 r71348  
    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
     
    3333
    3434
    35 QIDialogButtonBox::QIDialogButtonBox (StandardButtons aButtons, Qt::Orientation aOrientation, QWidget *aParent)
    36    : QIWithRetranslateUI<QDialogButtonBox> (aParent)
     35QIDialogButtonBox::QIDialogButtonBox(QWidget *pParent /* = 0 */)
     36    : QIWithRetranslateUI<QDialogButtonBox>(pParent)
    3737{
    38     setOrientation (aOrientation);
    39     setStandardButtons (aButtons);
     38}
    4039
     40QIDialogButtonBox::QIDialogButtonBox(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */)
     41    : QIWithRetranslateUI<QDialogButtonBox>(pParent)
     42{
     43    setOrientation(enmOrientation);
     44}
     45
     46QIDialogButtonBox::QIDialogButtonBox(StandardButtons enmButtonTypes, Qt::Orientation enmOrientation, QWidget *pParent)
     47   : QIWithRetranslateUI<QDialogButtonBox>(pParent)
     48{
     49    setOrientation(enmOrientation);
     50    setStandardButtons(enmButtonTypes);
    4151    retranslateUi();
    4252}
    4353
    44 QPushButton *QIDialogButtonBox::button (StandardButton aWhich) const
     54QPushButton *QIDialogButtonBox::button(StandardButton enmButtonType) const
    4555{
    46     QPushButton *button = QDialogButtonBox::button (aWhich);
    47     if (!button &&
    48         aWhich == QDialogButtonBox::Help)
    49         button = mHelpButton;
    50     return button;
     56    QPushButton *pButton = QDialogButtonBox::button(enmButtonType);
     57    if (   !pButton
     58        && enmButtonType == QDialogButtonBox::Help)
     59        pButton = m_pHelpButton;
     60    return pButton;
    5161}
    5262
    53 QPushButton *QIDialogButtonBox::addButton (const QString &aText, ButtonRole aRole)
     63QPushButton *QIDialogButtonBox::addButton(const QString &strText, ButtonRole enmRole)
    5464{
    55     QPushButton *btn = QDialogButtonBox::addButton (aText, aRole);
     65    QPushButton *pButton = QDialogButtonBox::addButton(strText, enmRole);
    5666    retranslateUi();
    57     return btn;
     67    return pButton;
    5868}
    5969
    60 QPushButton *QIDialogButtonBox::addButton (StandardButton aButton)
     70QPushButton *QIDialogButtonBox::addButton(StandardButton enmButtonType)
    6171{
    62     QPushButton *btn = QDialogButtonBox::addButton (aButton);
     72    QPushButton *pButton = QDialogButtonBox::addButton(enmButtonType);
    6373    retranslateUi();
    64     return btn;
     74    return pButton;
    6575}
    6676
    67 void QIDialogButtonBox::setStandardButtons (StandardButtons aButtons)
     77void QIDialogButtonBox::setStandardButtons(StandardButtons enmButtonTypes)
    6878{
    69     QDialogButtonBox::setStandardButtons (aButtons);
     79    QDialogButtonBox::setStandardButtons(enmButtonTypes);
    7080    retranslateUi();
    7181}
    7282
    73 void QIDialogButtonBox::addExtraWidget (QWidget* aWidget)
     83void QIDialogButtonBox::addExtraWidget(QWidget *pInsertedWidget)
    7484{
    75     QBoxLayout *layout = boxLayout();
    76     int index = findEmptySpace (layout);
    77     layout->insertWidget (index + 1, aWidget);
    78     layout->insertStretch(index + 2);
     85    QBoxLayout *pLayout = boxLayout();
     86    if (pLayout)
     87    {
     88        int iIndex = findEmptySpace(pLayout);
     89        pLayout->insertWidget(iIndex + 1, pInsertedWidget);
     90        pLayout->insertStretch(iIndex + 2);
     91    }
    7992}
    8093
     94void QIDialogButtonBox::addExtraLayout(QLayout *pInsertedLayout)
     95{
     96    QBoxLayout *pLayout = boxLayout();
     97    if (pLayout)
     98    {
     99        int iIndex = findEmptySpace(pLayout);
     100        pLayout->insertLayout(iIndex + 1, pInsertedLayout);
     101        pLayout->insertStretch(iIndex + 2);
     102    }
     103}
    81104
    82 void QIDialogButtonBox::addExtraLayout (QLayout* aLayout)
     105void QIDialogButtonBox::retranslateUi()
    83106{
    84     QBoxLayout *layout = boxLayout();
    85     int index = findEmptySpace (layout);
    86     layout->insertLayout (index + 1, aLayout);
    87     layout->insertStretch(index + 2);
     107    QPushButton *pButton = QDialogButtonBox::button(QDialogButtonBox::Help);
     108    if (pButton)
     109    {
     110        /* Use our very own help button if the user requested for one. */
     111        if (!m_pHelpButton)
     112            m_pHelpButton = new UIHelpButton;
     113        m_pHelpButton->initFrom(pButton);
     114        removeButton(pButton);
     115        QDialogButtonBox::addButton(m_pHelpButton, QDialogButtonBox::HelpRole);
     116    }
    88117}
    89118
    90119QBoxLayout *QIDialogButtonBox::boxLayout() const
    91120{
    92   QBoxLayout *boxlayout = qobject_cast<QBoxLayout*> (layout());
    93   AssertMsg (VALID_PTR (boxlayout), ("Layout of the QDialogButtonBox isn't a box layout."));
    94   return boxlayout;
     121    QBoxLayout *pLayout = qobject_cast<QBoxLayout*>(layout());
     122    AssertMsg(VALID_PTR(pLayout), ("Layout of the QDialogButtonBox isn't a box layout."));
     123    return pLayout;
    95124}
    96125
    97 int QIDialogButtonBox::findEmptySpace (QBoxLayout *aLayout) const
     126int QIDialogButtonBox::findEmptySpace(QBoxLayout *pLayout) const
    98127{
    99   /* Search for the first occurrence of QSpacerItem and return the index.
    100    * Please note that this is Qt internal, so it may change at any time. */
    101   int i=0;
    102   for (; i < aLayout->count(); ++i)
    103   {
    104       QLayoutItem *item = aLayout->itemAt(i);
    105       if (item->spacerItem())
    106           break;
    107   }
    108   return i;
     128    /* Search for the first occurrence of QSpacerItem and return the index. */
     129    int i = 0;
     130    for (; i < pLayout->count(); ++i)
     131    {
     132        QLayoutItem *pItem = pLayout->itemAt(i);
     133        if (pItem && pItem->spacerItem())
     134            break;
     135    }
     136    return i;
    109137}
    110138
    111 void QIDialogButtonBox::retranslateUi()
    112 {
    113     QPushButton *btn = QDialogButtonBox::button (QDialogButtonBox::Help);
    114     if (btn)
    115     {
    116         /* Use our very own help button if the user requested for one. */
    117         if (!mHelpButton)
    118             mHelpButton = new UIHelpButton;
    119         mHelpButton->initFrom (btn);
    120         removeButton (btn);
    121         QDialogButtonBox::addButton (mHelpButton, QDialogButtonBox::HelpRole);
    122     }
    123 }
    124 
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialogButtonBox.h

    r69500 r71348  
    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
     
    1616 */
    1717
    18 #ifndef __QIDialogButtonBox_h__
    19 #define __QIDialogButtonBox_h__
     18#ifndef ___QIDialogButtonBox_h___
     19#define ___QIDialogButtonBox_h___
    2020
    21 #include "QIWithRetranslateUI.h"
    22 
    23 /* Qt includes */
     21/* Qt includes: */
    2422#include <QDialogButtonBox>
    2523#include <QPointer>
    2624
     25/* GUI includes: */
     26#include "QIWithRetranslateUI.h"
     27
     28/* Forward declarations: */
    2729class QBoxLayout;
    28 
     30class QPushButton;
    2931class UIHelpButton;
    3032
    31 class QIDialogButtonBox: public QIWithRetranslateUI<QDialogButtonBox>
     33/** QDialogButtonBox subclass extending standard functionality. */
     34class QIDialogButtonBox : public QIWithRetranslateUI<QDialogButtonBox>
    3235{
     36    Q_OBJECT;
     37
    3338public:
    34     QIDialogButtonBox (QWidget *aParent = 0) :QIWithRetranslateUI<QDialogButtonBox> (aParent) {}
    35     QIDialogButtonBox (Qt::Orientation aOrientation, QWidget *aParent = 0) :QIWithRetranslateUI<QDialogButtonBox> (aParent) { setOrientation (aOrientation); }
    36     QIDialogButtonBox (StandardButtons aButtons, Qt::Orientation aOrientation = Qt::Horizontal, QWidget *aParent = 0);
    3739
    38     QPushButton *button (StandardButton aWhich) const;
     40    /** Constructs dialog-button-box passing @a pParent to the base-class. */
     41    QIDialogButtonBox(QWidget *pParent = 0);
     42    /** Constructs dialog-button-box passing @a pParent to the base-class.
     43      * @param  enmOrientation  Brings the button-box orientation. */
     44    QIDialogButtonBox(Qt::Orientation enmOrientation, QWidget *pParent = 0);
     45    /** Constructs dialog-button-box passing @a pParent to the base-class.
     46      * @param  enmButtonTypes  Brings the set of button types.
     47      * @param  enmOrientation  Brings the button-box orientation. */
     48    QIDialogButtonBox(StandardButtons enmButtonTypes, Qt::Orientation enmOrientation = Qt::Horizontal, QWidget *pParent = 0);
    3949
    40     QPushButton *addButton (const QString &aText, ButtonRole aRole);
    41     QPushButton *addButton (StandardButton aButton);
     50    /** Returns the button of requested @a enmButtonType. */
     51    QPushButton *button(StandardButton enmButtonType) const;
    4252
    43     void setStandardButtons (StandardButtons aButtons);
     53    /** Adds button with passed @a strText for specified @a enmRole. */
     54    QPushButton *addButton(const QString &strText, ButtonRole enmRole);
     55    /** Adds standard button of passed @a enmButtonType. */
     56    QPushButton *addButton(StandardButton enmButtonType);
    4457
    45     void addExtraWidget (QWidget *aWidget);
    46     void addExtraLayout (QLayout *aLayout);
     58    /** Defines a set of standard @a enmButtonTypes. */
     59    void setStandardButtons(StandardButtons enmButtonTypes);
     60
     61    /** Adds extra @a pWidget. */
     62    void addExtraWidget(QWidget *pWidget);
     63    /** Adds extra @a pLayout. */
     64    void addExtraLayout(QLayout *pLayout);
    4765
    4866protected:
    4967
     68    /** Handles translation event. */
     69    virtual void retranslateUi() /* override */;
     70
     71    /** Returns button layout. */
    5072    QBoxLayout *boxLayout() const;
    51     int findEmptySpace (QBoxLayout *aLayout) const;
    5273
    53     void retranslateUi();
     74    /** Searchs for empty @a pLayout space. */
     75    int findEmptySpace(QBoxLayout *pLayout) const;
    5476
    5577private:
    5678
    57     QPointer<UIHelpButton> mHelpButton;
     79    /** Holds the Help button reference. */
     80    QPointer<UIHelpButton> m_pHelpButton;
    5881};
    5982
    60 #endif /* __QIDialogButtonBox_h__ */
     83#endif /* !___QIDialogButtonBox_h___ */
    6184
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