Changeset 71348 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 15, 2018 10:21:52 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r71346 r71348 318 318 src/extensions/QIComboBox.h \ 319 319 src/extensions/QIDialog.h \ 320 src/extensions/QIDialogButtonBox.h \ 320 321 src/extensions/QIFileDialog.h \ 321 322 src/extensions/QIFlowLayout.h \ -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialogButtonBox.cpp
r69500 r71348 5 5 6 6 /* 7 * Copyright (C) 2008-201 7Oracle Corporation7 * Copyright (C) 2008-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 34 34 35 QIDialogButtonBox::QIDialogButtonBox (StandardButtons aButtons, Qt::Orientation aOrientation, QWidget *aParent)36 : QIWithRetranslateUI<QDialogButtonBox> (aParent)35 QIDialogButtonBox::QIDialogButtonBox(QWidget *pParent /* = 0 */) 36 : QIWithRetranslateUI<QDialogButtonBox>(pParent) 37 37 { 38 setOrientation (aOrientation); 39 setStandardButtons (aButtons); 38 } 40 39 40 QIDialogButtonBox::QIDialogButtonBox(Qt::Orientation enmOrientation, QWidget *pParent /* = 0 */) 41 : QIWithRetranslateUI<QDialogButtonBox>(pParent) 42 { 43 setOrientation(enmOrientation); 44 } 45 46 QIDialogButtonBox::QIDialogButtonBox(StandardButtons enmButtonTypes, Qt::Orientation enmOrientation, QWidget *pParent) 47 : QIWithRetranslateUI<QDialogButtonBox>(pParent) 48 { 49 setOrientation(enmOrientation); 50 setStandardButtons(enmButtonTypes); 41 51 retranslateUi(); 42 52 } 43 53 44 QPushButton *QIDialogButtonBox::button (StandardButton aWhich) const54 QPushButton *QIDialogButtonBox::button(StandardButton enmButtonType) const 45 55 { 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; 51 61 } 52 62 53 QPushButton *QIDialogButtonBox::addButton (const QString &aText, ButtonRole aRole)63 QPushButton *QIDialogButtonBox::addButton(const QString &strText, ButtonRole enmRole) 54 64 { 55 QPushButton * btn = QDialogButtonBox::addButton (aText, aRole);65 QPushButton *pButton = QDialogButtonBox::addButton(strText, enmRole); 56 66 retranslateUi(); 57 return btn;67 return pButton; 58 68 } 59 69 60 QPushButton *QIDialogButtonBox::addButton (StandardButton aButton)70 QPushButton *QIDialogButtonBox::addButton(StandardButton enmButtonType) 61 71 { 62 QPushButton * btn = QDialogButtonBox::addButton (aButton);72 QPushButton *pButton = QDialogButtonBox::addButton(enmButtonType); 63 73 retranslateUi(); 64 return btn;74 return pButton; 65 75 } 66 76 67 void QIDialogButtonBox::setStandardButtons (StandardButtons aButtons)77 void QIDialogButtonBox::setStandardButtons(StandardButtons enmButtonTypes) 68 78 { 69 QDialogButtonBox::setStandardButtons (aButtons);79 QDialogButtonBox::setStandardButtons(enmButtonTypes); 70 80 retranslateUi(); 71 81 } 72 82 73 void QIDialogButtonBox::addExtraWidget (QWidget* aWidget)83 void QIDialogButtonBox::addExtraWidget(QWidget *pInsertedWidget) 74 84 { 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 } 79 92 } 80 93 94 void 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 } 81 104 82 void QIDialogButtonBox:: addExtraLayout (QLayout* aLayout)105 void QIDialogButtonBox::retranslateUi() 83 106 { 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 } 88 117 } 89 118 90 119 QBoxLayout *QIDialogButtonBox::boxLayout() const 91 120 { 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; 95 124 } 96 125 97 int QIDialogButtonBox::findEmptySpace (QBoxLayout *aLayout) const126 int QIDialogButtonBox::findEmptySpace(QBoxLayout *pLayout) const 98 127 { 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; 109 137 } 110 138 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 5 5 6 6 /* 7 * Copyright (C) 2008-201 7Oracle Corporation7 * Copyright (C) 2008-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #ifndef __ QIDialogButtonBox_h__19 #define __ QIDialogButtonBox_h__18 #ifndef ___QIDialogButtonBox_h___ 19 #define ___QIDialogButtonBox_h___ 20 20 21 #include "QIWithRetranslateUI.h" 22 23 /* Qt includes */ 21 /* Qt includes: */ 24 22 #include <QDialogButtonBox> 25 23 #include <QPointer> 26 24 25 /* GUI includes: */ 26 #include "QIWithRetranslateUI.h" 27 28 /* Forward declarations: */ 27 29 class QBoxLayout; 28 30 class QPushButton; 29 31 class UIHelpButton; 30 32 31 class QIDialogButtonBox: public QIWithRetranslateUI<QDialogButtonBox> 33 /** QDialogButtonBox subclass extending standard functionality. */ 34 class QIDialogButtonBox : public QIWithRetranslateUI<QDialogButtonBox> 32 35 { 36 Q_OBJECT; 37 33 38 public: 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);37 39 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); 39 49 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; 42 52 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); 44 57 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); 47 65 48 66 protected: 49 67 68 /** Handles translation event. */ 69 virtual void retranslateUi() /* override */; 70 71 /** Returns button layout. */ 50 72 QBoxLayout *boxLayout() const; 51 int findEmptySpace (QBoxLayout *aLayout) const;52 73 53 void retranslateUi(); 74 /** Searchs for empty @a pLayout space. */ 75 int findEmptySpace(QBoxLayout *pLayout) const; 54 76 55 77 private: 56 78 57 QPointer<UIHelpButton> mHelpButton; 79 /** Holds the Help button reference. */ 80 QPointer<UIHelpButton> m_pHelpButton; 58 81 }; 59 82 60 #endif /* __QIDialogButtonBox_h__ */83 #endif /* !___QIDialogButtonBox_h___ */ 61 84
Note:
See TracChangeset
for help on using the changeset viewer.