Changeset 71870 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Apr 17, 2018 11:25:31 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r71869 r71870 441 441 src/UITakeSnapshotDialog.h \ 442 442 src/extensions/QIFlowLayout.h \ 443 src/extensions/QIMainDialog.h \444 443 src/extensions/QIManagerDialog.h \ 445 444 src/extensions/QIMenu.h \ … … 659 658 src/extensions/QILabelSeparator.h \ 660 659 src/extensions/QILineEdit.h \ 660 src/extensions/QIMainDialog.h \ 661 661 src/extensions/QIMainWindow.h \ 662 662 src/extensions/QIMessageBox.h \ … … 735 735 src/extensions/QILabelSeparator.h \ 736 736 src/extensions/QILineEdit.h \ 737 src/extensions/QIMainDialog.h \ 737 738 src/extensions/QIMainWindow.h \ 738 739 src/extensions/QIMessageBox.h \ … … 909 910 src/UITakeSnapshotDialog.cpp \ 910 911 src/extensions/QIFlowLayout.cpp \ 911 src/extensions/QIMainDialog.cpp \912 912 src/extensions/QIManagerDialog.cpp \ 913 913 src/extensions/QIMenu.cpp \ … … 1159 1159 src/extensions/QILabelSeparator.cpp \ 1160 1160 src/extensions/QILineEdit.cpp \ 1161 src/extensions/QIMainDialog.cpp \ 1161 1162 src/extensions/QIMainWindow.cpp \ 1162 1163 src/extensions/QIMessageBox.cpp \ … … 1262 1263 src/extensions/QILabelSeparator.cpp \ 1263 1264 src/extensions/QILineEdit.cpp \ 1265 src/extensions/QIMainDialog.cpp \ 1264 1266 src/extensions/QIMainWindow.cpp \ 1265 1267 src/extensions/QIMessageBox.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMainDialog.cpp
r71027 r71870 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 … … 21 21 22 22 /* Qt includes: */ 23 # include <QApplication> 24 # include <QDialogButtonBox> 23 25 # include <QDir> 24 # include <Q Url>26 # include <QEventLoop> 25 27 # include <QMenu> 26 28 # include <QProcess> 29 # include <QPushButton> 27 30 # include <QSizeGrip> 28 # include <QEventLoop> 29 # include <QPushButton> 30 # include <QApplication> 31 # include <QDialogButtonBox> 31 # include <QUrl> 32 32 33 33 /* GUI includes: */ … … 41 41 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 42 42 43 43 44 QIMainDialog::QIMainDialog(QWidget *pParent /* = 0 */, 44 Qt::WindowFlags enmFlags /* = Qt::Dialog */,45 Qt::WindowFlags fFlags /* = Qt::Dialog */, 45 46 bool fIsAutoCentering /* = true */) 46 : QMainWindow(pParent, enmFlags)47 : QMainWindow(pParent, fFlags) 47 48 , m_fIsAutoCentering(fIsAutoCentering) 48 49 , m_fPolished(false) … … 109 110 } 110 111 111 QPushButton *QIMainDialog::defaultButton() const112 QPushButton *QIMainDialog::defaultButton() const 112 113 { 113 114 return m_pDefaultButton; … … 152 153 } 153 154 154 bool QIMainDialog::event(QEvent *pEvent) 155 { 155 bool 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 156 166 /* Depending on event-type: */ 157 167 switch (pEvent->type()) 158 168 { 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 205 bool QIMainDialog::event(QEvent *pEvent) 206 { 207 /* Depending on event-type: */ 208 switch (pEvent->type()) 209 { 159 210 case QEvent::Polish: 160 211 { … … 172 223 173 224 void 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 233 void QIMainDialog::polishEvent(QShowEvent *) 174 234 { 175 235 /* Make sure we should polish dialog: */ … … 177 237 return; 178 238 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 {188 239 /* Explicit centering according to our parent: */ 189 240 if (m_fIsAutoCentering) 190 241 VBoxGlobal::centerWidget(this, parentWidget(), false); 242 243 /* Mark dialog as polished: */ 244 m_fPolished = true; 191 245 } 192 246 … … 262 316 263 317 /* 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 321 QPushButton *QIMainDialog::searchDefaultButton() const 318 322 { 319 323 /* Search for the first default-button in the dialog: */ … … 334 338 hide(); 335 339 } 336 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMainDialog.h
r71027 r71870 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - Qt extensions: QIMainDialog class implementation.3 * VBox Qt GUI - Qt extensions: QIMainDialog class declaration. 4 4 */ 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 … … 20 20 21 21 /* Qt includes: */ 22 #include <QDialog> 22 23 #include <QMainWindow> 23 24 #include <QPointer> 24 #include <QDialog> 25 26 /* GUI includes: */ 27 #include "UILibraryDefs.h" 25 28 26 29 /* Forward declarations: */ … … 30 33 31 34 /** QDialog analog based on QMainWindow. */ 32 class QIMainDialog: public QMainWindow35 class SHARED_LIBRARY_STUFF QIMainDialog : public QMainWindow 33 36 { 34 37 Q_OBJECT; … … 36 39 public: 37 40 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. */ 42 43 QIMainDialog(QWidget *pParent = 0, 43 Qt::WindowFlags enmFlags = Qt::Dialog,44 Qt::WindowFlags fFlags = Qt::Dialog, 44 45 bool fIsAutoCentering = true); 45 46 … … 51 52 QDialog::DialogCode exec(bool fApplicationModal = true); 52 53 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. */ 56 57 void setDefaultButton(QPushButton *pButton); 57 58 … … 68 69 protected: 69 70 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. */ 75 79 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);82 80 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; 85 89 86 90 protected slots: … … 101 105 102 106 /** Holds whether this dialog should be centered according it's parent. */ 103 const bool m_fIsAutoCentering;107 const bool m_fIsAutoCentering; 104 108 /** Holds whether this dialog is polished. */ 105 bool m_fPolished;109 bool m_fPolished; 106 110 107 111 /** Holds modal dialog's result code. */ 108 QDialog::DialogCode m_enmResult;112 QDialog::DialogCode m_enmResult; 109 113 /** Holds modal dialog's event-loop. */ 110 QPointer<QEventLoop> m_pEventLoop;114 QPointer<QEventLoop> m_pEventLoop; 111 115 112 /** Holds dialog's default -button. */113 QPointer<QPushButton> m_pDefaultButton;116 /** Holds dialog's default button. */ 117 QPointer<QPushButton> m_pDefaultButton; 114 118 /** Holds dialog's size-grip. */ 115 QPointer<QSizeGrip> m_pSizeGrip;119 QPointer<QSizeGrip> m_pSizeGrip; 116 120 }; 117 121
Note:
See TracChangeset
for help on using the changeset viewer.