Changeset 10934 in vbox for trunk/src/VBox/Frontends/VirtualBox4
- Timestamp:
- Jul 29, 2008 1:57:43 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/QIMainDialog.h
r10335 r10934 38 38 public: 39 39 40 QIMainDialog (QWidget *aParent = NULL, Qt::WindowFlags aFlags = Qt::Dialog);40 QIMainDialog (QWidget *aParent = 0, Qt::WindowFlags aFlags = Qt::Dialog); 41 41 42 42 QDialog::DialogCode exec(); 43 43 QDialog::DialogCode result() const; 44 44 45 void setFileForProxyIcon (const QString &aFile);45 void setFileForProxyIcon (const QString &aFile); 46 46 QString fileForProxyIcon () const; 47 47 … … 49 49 bool isSizeGripEnabled () const; 50 50 51 void setDefaultButton (QPushButton *aButton);51 void setDefaultButton (QPushButton *aButton); 52 52 QPushButton* defaultButton () const; 53 53 -
trunk/src/VBox/Frontends/VirtualBox4/src/QIMainDialog.cpp
r10339 r10934 38 38 #include <QDialogButtonBox> 39 39 40 QIMainDialog::QIMainDialog (QWidget *aParent /* = NULL */, Qt::WindowFlags aFlags /* = Qt::Dialog */) 41 : QMainWindow (aParent, aFlags) 40 QIMainDialog::QIMainDialog (QWidget *aParent /* = 0 */, 41 Qt::WindowFlags aFlags /* = Qt::Dialog */) 42 : QMainWindow (aParent, aFlags) 42 43 , mRescode (QDialog::Rejected) 43 44 { … … 53 54 bool deleteOnClose = testAttribute (Qt::WA_DeleteOnClose); 54 55 setAttribute (Qt::WA_DeleteOnClose, false); 55 bool wasShowModal = testAttribute (Qt::WA_ShowModal); 56 bool wasShowModal = testAttribute (Qt::WA_ShowModal); 56 57 setAttribute (Qt::WA_ShowModal, true); 57 58 … … 70 71 return QDialog::Rejected; 71 72 QDialog::DialogCode res = result(); 72 /* Set the old show modal attribute */ 73 /* Set the old show modal attribute */ 73 74 setAttribute (Qt::WA_ShowModal, wasShowModal); 74 75 /* Delete us in the case we should do so on close */ … … 79 80 } 80 81 81 QDialog::DialogCode QIMainDialog::result() const 82 { 83 return mRescode; 82 QDialog::DialogCode QIMainDialog::result() const 83 { 84 return mRescode; 84 85 } 85 86 … … 89 90 } 90 91 91 QString QIMainDialog::fileForProxyIcon 92 QString QIMainDialog::fileForProxyIcon() const 92 93 { 93 94 return mFileForProxyIcon; … … 106 107 } 107 108 108 bool QIMainDialog::isSizeGripEnabled 109 bool QIMainDialog::isSizeGripEnabled() const 109 110 { 110 111 return mSizeGrip; … … 127 128 /* Exit from the event loop if there is any and we are changing our state 128 129 * from visible to invisible. */ 129 if (mEventLoop && !aVisible)130 if (mEventLoop && !aVisible) 130 131 mEventLoop->exit(); 131 132 } … … 133 134 bool QIMainDialog::event (QEvent *aEvent) 134 135 { 135 switch (aEvent->type()) 136 switch (aEvent->type()) 136 137 { 137 138 #ifdef Q_WS_MAC 138 case QEvent::IconDrag: 139 case QEvent::IconDrag: 140 { 141 Qt::KeyboardModifiers currentModifiers = qApp->keyboardModifiers(); 142 143 if (currentModifiers == Qt::NoModifier) 139 144 { 140 Qt::KeyboardModifiers currentModifiers = qApp->keyboardModifiers(); 141 142 if (currentModifiers == Qt::NoModifier) 145 if (!mFileForProxyIcon.isEmpty()) 143 146 { 144 if (!mFileForProxyIcon.isEmpty()) 147 aEvent->accept(); 148 /* Create a drag object we can use */ 149 QDrag *drag = new QDrag (this); 150 QMimeData *data = new QMimeData(); 151 /* Set the appropriate url data */ 152 data->setUrls (QList<QUrl>() << QUrl::fromLocalFile (mFileForProxyIcon)); 153 drag->setMimeData (data); 154 /* Make a nice looking DnD icon */ 155 QFileInfo fi (mFileForProxyIcon); 156 QPixmap cursorPixmap (::darwinCreateDragPixmap (QPixmap (windowIcon().pixmap (16, 16)), fi.fileName())); 157 drag->setPixmap (cursorPixmap); 158 drag->setHotSpot (QPoint (5, cursorPixmap.height() - 5)); 159 /* Start the DnD action */ 160 drag->start (Qt::LinkAction | Qt::CopyAction); 161 return true; 162 } 163 } 164 #if QT_VERSION < 0x040400 165 else if (currentModifiers == Qt::ShiftModifier) 166 #else 167 else if (currentModifiers == Qt::ControlModifier) 168 #endif 169 { 170 if (!mFileForProxyIcon.isEmpty()) 171 { 172 aEvent->accept(); 173 /* Create the proxy icon menu */ 174 QMenu menu (this); 175 connect (&menu, SIGNAL (triggered (QAction*)), 176 this, SLOT (openAction (QAction*))); 177 /* Add the file with the disk icon to the menu */ 178 QFileInfo fi (mFileForProxyIcon); 179 QAction *action = menu.addAction (fi.fileName()); 180 action->setIcon (windowIcon()); 181 /* Create some nice looking menu out of the other 182 * directory parts. */ 183 QFileIconProvider fip; 184 QDir dir (fi.absolutePath()); 185 do 145 186 { 146 aEvent->accept(); 147 /* Create a drag object we can use */ 148 QDrag *drag = new QDrag (this); 149 QMimeData *data = new QMimeData(); 150 /* Set the appropriate url data */ 151 data->setUrls(QList<QUrl>() << QUrl::fromLocalFile (mFileForProxyIcon)); 152 drag->setMimeData (data); 153 /* Make a nice looking DnD icon */ 154 QFileInfo fi (mFileForProxyIcon); 155 QPixmap cursorPixmap (::darwinCreateDragPixmap (QPixmap (windowIcon().pixmap (16, 16)), fi.fileName())); 156 drag->setPixmap (cursorPixmap); 157 drag->setHotSpot (QPoint (5, cursorPixmap.height() - 5)); 158 /* Start the DnD action */ 159 drag->start (Qt::LinkAction | Qt::CopyAction); 160 return true; 187 if (dir.isRoot()) 188 action = menu.addAction ("/"); 189 else 190 action = menu.addAction (dir.dirName()); 191 action->setIcon (fip.icon (QFileInfo (dir, ""))); 161 192 } 193 while (dir.cdUp()); 194 /* Show the menu */ 195 menu.exec (QPoint (QCursor::pos().x() - 20, frameGeometry().y() - 5)); 196 return true; 162 197 } 163 #if QT_VERSION < 0x040400164 else if (currentModifiers == Qt::ShiftModifier)165 #else166 else if (currentModifiers == Qt::ControlModifier)167 #endif168 {169 if (!mFileForProxyIcon.isEmpty())170 {171 aEvent->accept();172 /* Create the proxy icon menu */173 QMenu menu(this);174 connect(&menu, SIGNAL (triggered (QAction *)),175 this, SLOT (openAction (QAction *)));176 /* Add the file with the disk icon to the menu */177 QFileInfo fi (mFileForProxyIcon);178 QAction *action = menu.addAction (fi.fileName());179 action->setIcon (windowIcon());180 /* Create some nice looking menu out of the other181 * directory parts. */182 QFileIconProvider fip;183 QDir dir (fi.absolutePath());184 do185 {186 if (dir.isRoot())187 action = menu.addAction ("/");188 else189 action = menu.addAction (dir.dirName());190 action->setIcon (fip.icon (QFileInfo (dir, "")));191 }192 while (dir.cdUp());193 /* Show the menu */194 menu.exec (QPoint (QCursor::pos().x() - 20, frameGeometry().y() - 5));195 return true;196 }197 }198 break;199 198 } 199 break; 200 } 200 201 #endif /* Q_WS_MAC */ 201 case QEvent::Polish: 202 203 204 205 206 207 default: 202 case QEvent::Polish: 203 { 204 /* Initially search for the default button. */ 205 mDefaultButton = searchDefaultButton(); 206 break; 207 } 208 default: 208 209 break; 209 210 } … … 216 217 217 218 /* Adjust the size-grip location for the current resize event */ 218 if (mSizeGrip) 219 if (mSizeGrip) 219 220 { 220 221 if (isRightToLeft()) … … 231 232 return QMainWindow::eventFilter (aObject, aEvent); 232 233 234 if (qobject_cast<QWidget*> (aObject) && 235 qobject_cast<QWidget*> (aObject)->window() != this) 236 return QMainWindow::eventFilter (aObject, aEvent); 237 233 238 switch (aEvent->type()) 234 239 { … … 236 241 * button property into the currently focused button. */ 237 242 case QEvent::FocusIn: 243 { 244 if (qobject_cast<QPushButton*> (aObject) && 245 (aObject->parent() == centralWidget() || 246 qobject_cast<QDialogButtonBox*> (aObject->parent()))) 238 247 { 239 if (qobject_cast<QPushButton*> (aObject) && 240 (aObject->parent() == centralWidget() || 241 qobject_cast<QDialogButtonBox*> (aObject->parent()) != NULL)) 242 { 243 qobject_cast<QPushButton*> (aObject)->setDefault (aObject != mDefaultButton); 244 if (mDefaultButton) 245 mDefaultButton->setDefault (aObject == mDefaultButton); 246 } 247 break; 248 qobject_cast<QPushButton*> (aObject)->setDefault (aObject != mDefaultButton); 249 if (mDefaultButton) 250 mDefaultButton->setDefault (aObject == mDefaultButton); 248 251 } 252 break; 253 } 249 254 /* Auto-default button focus-out processor used to remove the "default" 250 255 * button property from the previously focused button. */ 251 256 case QEvent::FocusOut: 257 { 258 if (qobject_cast<QPushButton*> (aObject) && 259 (aObject->parent() == centralWidget() || 260 qobject_cast<QDialogButtonBox*> (aObject->parent()))) 252 261 { 253 if (qobject_cast<QPushButton*> (aObject) && 254 (aObject->parent() == centralWidget() || 255 qobject_cast<QDialogButtonBox*> (aObject->parent()) != NULL)) 262 if (mDefaultButton) 263 mDefaultButton->setDefault (aObject != mDefaultButton); 264 qobject_cast<QPushButton*> (aObject)->setDefault (aObject == mDefaultButton); 265 } 266 break; 267 } 268 case QEvent::KeyPress: 269 { 270 /* Make sure that we only proceed if no 271 * popup or other modal widgets are open. */ 272 if (qApp->activePopupWidget() || 273 (qApp->activeModalWidget() && qApp->activeModalWidget() != this)) 274 break; 275 276 QKeyEvent *event = static_cast<QKeyEvent*> (aEvent); 277 #ifdef Q_WS_MAC 278 if (event->modifiers() == Qt::ControlModifier && 279 event->key() == Qt::Key_Period) 280 reject(); 281 else 282 #endif 283 if (event->modifiers() == Qt::NoModifier || 284 (event->modifiers() & Qt::KeypadModifier && event->key() == Qt::Key_Enter)) 256 285 { 257 if (mDefaultButton) 258 mDefaultButton->setDefault (aObject != mDefaultButton); 259 qobject_cast<QPushButton*> (aObject)->setDefault (aObject == mDefaultButton); 260 } 261 break; 262 } 263 case QEvent::KeyPress: 264 { 265 /* Make sure that we only proceed if no 266 * popup or other modal widgets are open. */ 267 if (aObject != this || 268 qApp->activePopupWidget() != NULL || 269 !(qApp->activeModalWidget() == this || 270 qApp->activeModalWidget() == NULL)) 271 break; 272 QKeyEvent *event = static_cast<QKeyEvent*> (aEvent); 273 #ifdef Q_WS_MAC 274 if (event->modifiers() == Qt::ControlModifier && 275 event->key() == Qt::Key_Period) 276 reject(); 277 else 278 #endif 279 if (event->modifiers() == Qt::NoModifier || 280 (event->modifiers() & Qt::KeypadModifier && event->key() == Qt::Key_Enter)) 286 switch (event->key()) 281 287 { 282 switch (event->key()) 288 case Qt::Key_Enter: 289 case Qt::Key_Return: 283 290 { 284 case Qt::Key_Enter: 285 case Qt::Key_Return: 286 { 287 QPushButton *currentDefault = searchDefaultButton(); 288 if (currentDefault) 289 { 290 /* We handle this, so return true after 291 * that. */ 292 currentDefault->animateClick(); 293 return true; 294 } 295 break; 296 } 297 case Qt::Key_Escape: 298 { 299 reject(); 300 return true; 301 break; 302 } 291 QPushButton *currentDefault = searchDefaultButton(); 292 if (currentDefault) 293 { 294 /* We handle this, so return true after 295 * that. */ 296 currentDefault->animateClick(); 297 return true; 298 } 299 break; 300 } 301 case Qt::Key_Escape: 302 { 303 reject(); 304 return true; 305 break; 303 306 } 304 307 } 305 } 308 } 309 } 306 310 default: 307 311 break; … … 313 317 { 314 318 /* Search for the first default button in the dialog. */ 315 QPushButton *button = NULL;319 QPushButton *button = 0; 316 320 QList<QPushButton*> list = qFindChildren<QPushButton*> (this); 317 321 foreach (button, list) 318 if (button->isDefault() &&319 (button->parent() == centralWidget() ||320 qobject_cast<QDialogButtonBox*> (button->parent()) != NULL))322 if (button->isDefault() && 323 (button->parent() == centralWidget() || 324 qobject_cast<QDialogButtonBox*> (button->parent()))) 321 325 break; 322 326 return button; … … 324 328 325 329 326 void QIMainDialog::accept() 327 { 328 done (QDialog::Accepted); 329 } 330 331 void QIMainDialog::reject() 332 { 333 done (QDialog::Rejected); 330 void QIMainDialog::accept() 331 { 332 done (QDialog::Accepted); 333 } 334 335 void QIMainDialog::reject() 336 { 337 done (QDialog::Rejected); 334 338 } 335 339 … … 344 348 } 345 349 346 void QIMainDialog::setResult (QDialog::DialogCode aRescode) 347 { 348 mRescode = aRescode; 350 void QIMainDialog::setResult (QDialog::DialogCode aRescode) 351 { 352 mRescode = aRescode; 349 353 } 350 354
Note:
See TracChangeset
for help on using the changeset viewer.