Changeset 10325 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jul 7, 2008 2:10:40 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 32947
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/QIMainDialog.h
r10090 r10325 59 59 virtual bool eventFilter (QObject *aObject, QEvent *aEvent); 60 60 61 QPushButton* searchDefaultButton() const; 62 61 63 protected slots: 62 64 … … 78 80 79 81 QPointer<QSizeGrip> mSizeGrip; 82 83 QPushButton* mDefaultButton; 80 84 }; 81 85 -
trunk/src/VBox/Frontends/VirtualBox4/src/QIMainDialog.cpp
r10227 r10325 36 36 #include <QSizeGrip> 37 37 #include <QPushButton> 38 #include <QDialogButtonBox> 38 39 39 40 QIMainDialog::QIMainDialog (QWidget *aParent /* = NULL */, Qt::WindowFlags aFlags /* = Qt::Dialog */) 40 41 : QMainWindow (aParent, aFlags) 41 42 , mRescode (QDialog::Rejected) 43 , mDefaultButton (NULL) 42 44 { 43 45 qApp->installEventFilter (this); … … 121 123 bool QIMainDialog::event (QEvent *aEvent) 122 124 { 123 #ifdef Q_WS_MAC124 125 switch (aEvent->type()) 125 126 { 127 #ifdef Q_WS_MAC 126 128 case QEvent::IconDrag: 127 129 { … … 186 188 break; 187 189 } 190 #endif /* Q_WS_MAC */ 191 case QEvent::Polish: 192 { 193 /* Initially search for the default button. */ 194 mDefaultButton = searchDefaultButton(); 195 break; 196 } 188 197 default: 189 198 break; 190 199 } 191 #endif /* Q_WS_MAC */192 200 return QMainWindow::event (aEvent); 193 201 } … … 215 223 switch (aEvent->type()) 216 224 { 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 } 217 253 case QEvent::KeyPress: 218 254 { … … 220 256 #ifdef Q_WS_MAC 221 257 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)) 223 264 reject(); 224 265 else … … 232 273 case Qt::Key_Return: 233 274 { 234 Q List<QPushButton*> list = qFindChildren<QPushButton*> (this);235 for (int i=0; i < list.size(); ++i)275 QPushButton *currentDefault = searchDefaultButton(); 276 if (currentDefault) 236 277 { 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; 244 282 } 245 283 break; … … 247 285 case Qt::Key_Escape: 248 286 { 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 } 250 297 break; 251 298 } … … 258 305 return QMainWindow::eventFilter (aObject, aEvent); 259 306 } 307 308 QPushButton* 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 260 321 261 322 void QIMainDialog::accept()
Note:
See TracChangeset
for help on using the changeset viewer.