Changeset 41114 in vbox
- Timestamp:
- May 2, 2012 1:07:55 PM (13 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineDefs.h
r30753 r41114 35 35 enum UIVisualElement 36 36 { 37 UIVisualElement_Window Caption= RT_BIT(0),37 UIVisualElement_WindowTitle = RT_BIT(0), 38 38 UIVisualElement_MouseIntegrationStuff = RT_BIT(1), 39 39 UIVisualElement_PauseStuff = RT_BIT(2), … … 46 46 UIVisualElement_SharedFolderStuff = RT_BIT(9), 47 47 UIVisualElement_VirtualizationStuff = RT_BIT(10), 48 UIVisualElement_MiniToolBar = RT_BIT(11), 48 49 UIVisualElement_AllStuff = 0xFFFF 49 50 }; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
r41107 r41114 18 18 */ 19 19 20 /* Global includes */20 /* Global includes: */ 21 21 #include <QCloseEvent> 22 22 #include <QTimer> 23 24 23 #include <VBox/version.h> 25 24 #ifdef VBOX_BLEEDING_EDGE … … 27 26 #endif /* VBOX_BLEEDING_EDGE */ 28 27 29 /* Local includes */28 /* Local includes: */ 30 29 #include "COMDefs.h" 31 30 #include "VBoxGlobal.h" 32 31 #include "UIMessageCenter.h" 33 34 32 #include "UIKeyboardHandler.h" 33 #include "UIMachineWindow.h" 35 34 #include "UIMachineLogic.h" 36 35 #include "UIMachineView.h" 37 #include "UIMachineWindow .h"36 #include "UIMachineWindowNormal.h" 38 37 #include "UIMachineWindowFullscreen.h" 39 #include "UIMachineWindow Normal.h"38 #include "UIMachineWindowSeamless.h" 40 39 #include "UIMachineWindowScale.h" 41 #include "UIMachineWindowSeamless.h"42 40 #include "UIMouseHandler.h" 43 41 #include "UISession.h" 44 42 #include "UIVMCloseDialog.h" 45 46 43 #ifdef Q_WS_X11 47 44 # include <X11/Xlib.h> 48 #endif 49 50 UIMachineWindow* UIMachineWindow::create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType, ulong uScreenId) 51 { 52 UIMachineWindow *window = 0; 53 switch (visualStateType) 45 #endif /* Q_WS_X11 */ 46 47 /* static */ 48 UIMachineWindow* UIMachineWindow::create(UIMachineLogic *pMachineLogic, ulong uScreenId) 49 { 50 /* Create machine-window: */ 51 UIMachineWindow *pMachineWindow = 0; 52 switch (pMachineLogic->visualStateType()) 54 53 { 55 54 case UIVisualStateType_Normal: 56 window = new UIMachineWindowNormal(pMachineLogic, uScreenId);55 pMachineWindow = new UIMachineWindowNormal(pMachineLogic, uScreenId); 57 56 break; 58 57 case UIVisualStateType_Fullscreen: 59 window = new UIMachineWindowFullscreen(pMachineLogic, uScreenId);58 pMachineWindow = new UIMachineWindowFullscreen(pMachineLogic, uScreenId); 60 59 break; 61 60 case UIVisualStateType_Seamless: 62 window = new UIMachineWindowSeamless(pMachineLogic, uScreenId);61 pMachineWindow = new UIMachineWindowSeamless(pMachineLogic, uScreenId); 63 62 break; 64 63 case UIVisualStateType_Scale: 65 window = new UIMachineWindowScale(pMachineLogic, uScreenId);64 pMachineWindow = new UIMachineWindowScale(pMachineLogic, uScreenId); 66 65 break; 67 } 68 return window; 69 } 70 66 default: 67 AssertMsgFailed(("Incorrect visual state!")); 68 break; 69 } 70 /* Prepare machine-window: */ 71 pMachineWindow->prepare(); 72 /* Return machine-window: */ 73 return pMachineWindow; 74 } 75 76 /* static */ 71 77 void UIMachineWindow::destroy(UIMachineWindow *pWhichWindow) 72 78 { 79 /* Cleanup machine-window: */ 80 pWhichWindow->cleanup(); 81 /* Delete machine-window: */ 73 82 delete pWhichWindow; 74 83 } 75 84 85 void UIMachineWindow::prepare() 86 { 87 /* Prepare session-connections: */ 88 prepareSessionConnections(); 89 90 /* Prepare main-layout: */ 91 prepareMainLayout(); 92 93 /* Prepare menu: */ 94 prepareMenu(); 95 96 /* Prepare status-bar: */ 97 prepareStatusBar(); 98 99 /* Prepare machine-view: */ 100 prepareMachineView(); 101 102 /* Prepare visual-state: */ 103 prepareVisualState(); 104 105 /* Prepare handlers: */ 106 prepareHandlers(); 107 108 /* Load settings: */ 109 loadSettings(); 110 111 /* Retranslate window: */ 112 retranslateUi(); 113 114 /* Update all the elements: */ 115 updateAppearanceOf(UIVisualElement_AllStuff); 116 117 /* Show: */ 118 showInNecessaryMode(); 119 } 120 121 void UIMachineWindow::cleanup() 122 { 123 /* Save window settings: */ 124 saveSettings(); 125 126 /* Cleanup handlers: */ 127 cleanupHandlers(); 128 129 /* Cleanup visual-state: */ 130 cleanupVisualState(); 131 132 /* Cleanup machine-view: */ 133 cleanupMachineView(); 134 135 /* Cleanup status-bar: */ 136 cleanupStatusBar(); 137 138 /* Cleanup menu: */ 139 cleanupMenu(); 140 141 /* Cleanup main layout: */ 142 cleanupMainLayout(); 143 144 /* Cleanup session connections: */ 145 cleanupSessionConnections(); 146 } 147 148 void UIMachineWindow::sltMachineStateChanged() 149 { 150 /* Update window-title: */ 151 updateAppearanceOf(UIVisualElement_WindowTitle); 152 } 153 154 void UIMachineWindow::sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect /* screenGeo */) 155 { 156 /* Ignore change events for other screens: */ 157 if (uScreenId != m_uScreenId) 158 return; 159 /* Ignore KGuestMonitorChangedEventType_NewOrigin change event: */ 160 if (changeType == KGuestMonitorChangedEventType_NewOrigin) 161 return; 162 163 /* Process KGuestMonitorChangedEventType_Enabled change event: */ 164 if (isHidden() && changeType == KGuestMonitorChangedEventType_Enabled) 165 showInNecessaryMode(); 166 /* Process KGuestMonitorChangedEventType_Disabled change event: */ 167 else if (!isHidden() && changeType == KGuestMonitorChangedEventType_Disabled) 168 hide(); 169 } 170 76 171 void UIMachineWindow::sltTryClose() 77 172 { 78 /* Do not try to close if restricted: */173 /* Do not try to close window if restricted: */ 79 174 if (machineLogic()->isPreventAutoClose()) 80 175 return; 81 176 82 /* First close any open modal & popup widgets. 177 #if 0 178 // TODO: Is that really needed? 179 /* This thing here is from Qt3. 180 * First close any open modal & popup widgets. 83 181 * Use a single shot with timeout 0 to allow the widgets to cleanly close and test then again. 84 182 * If all open widgets are closed destroy ourself: */ 85 QWidget *widget = QApplication::activeModalWidget() ? 86 QApplication::activeModalWidget() : 87 QApplication::activePopupWidget() ? 88 QApplication::activePopupWidget() : 0; 89 if (widget) 90 { 91 widget->close(); 183 QWidget *pWidget = QApplication::activeModalWidget() ? QApplication::activeModalWidget() : 184 QApplication::activePopupWidget() ? QApplication::activePopupWidget() : 0; 185 if (pWidget) 186 { 187 pWidget->close(); 92 188 QTimer::singleShot(0, this, SLOT(sltTryClose())); 93 189 } 94 190 else 95 close(); 191 #endif 192 193 close(); 96 194 } 97 195 … … 99 197 : QIWithRetranslateUI2<QMainWindow>(0, windowFlags(pMachineLogic->visualStateType())) 100 198 , m_pMachineLogic(pMachineLogic) 199 , m_pMachineView(0) 101 200 , m_uScreenId(uScreenId) 102 , m_pMa chineViewContainer(0)201 , m_pMainLayout(0) 103 202 , m_pTopSpacer(0) 104 203 , m_pBottomSpacer(0) 105 204 , m_pLeftSpacer(0) 106 205 , m_pRightSpacer(0) 107 , m_pMachineView(0) 108 { 206 { 207 #ifndef Q_WS_MAC 208 /* On Mac OS X application icon referenced in info.plist is used. */ 209 210 /* Set default application icon (will be changed to VM-specific icon little bit later): */ 211 setWindowIcon(QIcon(":/VirtualBox_48px.png")); 212 213 /* Set VM-specific application icon: */ 214 setWindowIcon(vboxGlobal().vmGuestOSTypeIcon(machine().GetOSTypeId())); 215 #endif /* !Q_WS_MAC */ 216 217 /* Set the main application window for VBoxGlobal: */ 218 if (m_uScreenId == 0) 219 vboxGlobal().setMainWindow(this); 109 220 } 110 221 111 222 UIMachineWindow::~UIMachineWindow() 112 223 { 113 /* Close any opened modal & popup widgets: */ 224 #if 0 225 // TODO: Is that really needed? 226 /* This thing here is from Qt3. 227 * Close any opened modal & popup widgets: */ 114 228 while (QWidget *pWidget = QApplication::activeModalWidget() ? QApplication::activeModalWidget() : 115 229 QApplication::activePopupWidget() ? QApplication::activePopupWidget() : 0) … … 126 240 pWidget->deleteLater(); 127 241 } 242 #endif 128 243 } 129 244 … … 138 253 } 139 254 255 CMachine UIMachineWindow::machine() const 256 { 257 return session().GetMachine(); 258 } 259 140 260 void UIMachineWindow::retranslateUi() 141 261 { 262 /* Compose window-title prefix: */ 142 263 m_strWindowTitlePrefix = VBOX_PRODUCT; 143 264 #ifdef VBOX_BLEEDING_EDGE 144 m_strWindowTitlePrefix += UIMachine Logic::tr(" EXPERIMENTAL build %1r%2 - %3")265 m_strWindowTitlePrefix += UIMachineWindow::tr(" EXPERIMENTAL build %1r%2 - %3") 145 266 .arg(RTBldCfgVersion()) 146 267 .arg(RTBldCfgRevisionStr()) 147 268 .arg(VBOX_BLEEDING_EDGE); 148 #endif 149 updateAppearanceOf(UIVisualElement_WindowCaption); 269 #endif /* VBOX_BLEEDING_EDGE */ 270 /* Update appearance of the window-title: */ 271 updateAppearanceOf(UIVisualElement_WindowTitle); 150 272 } 151 273 … … 153 275 bool UIMachineWindow::x11Event(XEvent *pEvent) 154 276 { 155 // TODO: Check if that is still required!277 // TODO: Is that really needed? 156 278 /* Qt bug: when the machine-view grabs the keyboard, 157 279 * FocusIn, FocusOut, WindowActivate and WindowDeactivate Qt events are … … 171 293 return false; 172 294 } 173 #endif 295 #endif /* Q_WS_X11 */ 174 296 175 297 void UIMachineWindow::closeEvent(QCloseEvent *pEvent) 176 298 { 177 /* Always ignore close 299 /* Always ignore close-event: */ 178 300 pEvent->ignore(); 179 301 180 302 /* Should we close application? */ 181 303 bool fCloseApplication = false; 182 183 304 switch (uisession()->machineState()) 184 305 { … … 191 312 { 192 313 /* Get the machine: */ 193 CMachine m achine = session().GetMachine();314 CMachine m = machine(); 194 315 195 316 /* Check if there is a close hock script defined. */ 196 const QString& strScript = m achine.GetExtraData(VBoxDefs::GUI_CloseActionHook);317 const QString& strScript = m.GetExtraData(VBoxDefs::GUI_CloseActionHook); 197 318 if (!strScript.isEmpty()) 198 319 { 199 QProcess::startDetached(strScript, QStringList() << m achine.GetId());320 QProcess::startDetached(strScript, QStringList() << m.GetId()); 200 321 return; 201 322 } 202 /* Prepare close dialog: */ 323 324 /* Prepare close-dialog: */ 203 325 UIVMCloseDialog dlg(this); 204 326 205 327 /* Assign close-dialog pixmap: */ 206 dlg.pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m achine.GetOSTypeId()));328 dlg.pmIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m.GetOSTypeId())); 207 329 208 330 /* Check which close actions are disallowed: */ 209 QStringList restictedActionsList = m achine.GetExtraData(VBoxDefs::GUI_RestrictedCloseActions).split(',');331 QStringList restictedActionsList = m.GetExtraData(VBoxDefs::GUI_RestrictedCloseActions).split(','); 210 332 bool fIsStateSavingAllowed = !restictedActionsList.contains("SaveState", Qt::CaseInsensitive); 211 333 bool fIsACPIShutdownAllowed = !restictedActionsList.contains("Shutdown", Qt::CaseInsensitive); … … 231 353 232 354 /* Make the Restore Snapshot checkbox visible/hidden depending on snapshots count & restrictions: */ 233 dlg.mCbDiscardCurState->setVisible(fIsPowerOffAndRestoreAllowed && m achine.GetSnapshotCount() > 0);234 if (!m achine.GetCurrentSnapshot().isNull())235 dlg.mCbDiscardCurState->setText(dlg.mCbDiscardCurState->text().arg(m achine.GetCurrentSnapshot().GetName()));355 dlg.mCbDiscardCurState->setVisible(fIsPowerOffAndRestoreAllowed && m.GetSnapshotCount() > 0); 356 if (!m.GetCurrentSnapshot().isNull()) 357 dlg.mCbDiscardCurState->setText(dlg.mCbDiscardCurState->text().arg(m.GetCurrentSnapshot().GetName())); 236 358 237 359 /* Choice string tags for close-dialog: */ … … 242 364 243 365 /* Read the last user's choice for the given VM: */ 244 QStringList lastAction = m achine.GetExtraData(VBoxDefs::GUI_LastCloseAction).split(',');366 QStringList lastAction = m.GetExtraData(VBoxDefs::GUI_LastCloseAction).split(','); 245 367 246 368 /* Check which button should be initially chosen: */ … … 288 410 289 411 /* This flag will keep the status of every further logical operation: */ 290 bool success = true;412 bool fSuccess = true; 291 413 292 414 /* Pause before showing dialog if necessary: */ 293 415 bool fWasPaused = uisession()->isPaused() || uisession()->machineState() == KMachineState_Stuck; 294 416 if (!fWasPaused) 295 success = uisession()->pause();296 297 if ( success)417 fSuccess = uisession()->pause(); 418 419 if (fSuccess) 298 420 { 299 421 /* Preventing auto-closure: */ 300 422 machineLogic()->setPreventAutoClose(true); 301 423 302 /* If close 424 /* If close-dialog accepted: */ 303 425 if (dlg.exec() == QDialog::Accepted) 304 426 { … … 306 428 CConsole console = session().GetConsole(); 307 429 308 success = false;430 fSuccess = false; 309 431 310 432 if (dlg.mRbSave->isChecked()) … … 317 439 { 318 440 /* Show the "VM saving" progress dialog: */ 319 msgCenter().showModalProgressDialog(progress, m achine.GetName(), ":/progress_state_save_90px.png", 0, true);441 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_state_save_90px.png", 0, true); 320 442 if (progress.GetResultCode() != 0) 321 443 msgCenter().cannotSaveMachineState(progress); 322 444 else 323 success = true;445 fSuccess = true; 324 446 } 325 447 326 if ( success)448 if (fSuccess) 327 449 fCloseApplication = true; 328 450 } … … 338 460 msgCenter().cannotACPIShutdownMachine(console); 339 461 else 340 success = true;462 fSuccess = true; 341 463 } 342 464 else if (dlg.mRbPowerOff->isChecked()) … … 349 471 { 350 472 /* Show the power down progress dialog: */ 351 msgCenter().showModalProgressDialog(progress, m achine.GetName(), ":/progress_poweroff_90px.png", 0, true);473 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_poweroff_90px.png", 0, true); 352 474 if (progress.GetResultCode() != 0) 353 475 msgCenter().cannotStopMachine(progress); 354 476 else 355 success = true;477 fSuccess = true; 356 478 } 357 479 358 if ( success)480 if (fSuccess) 359 481 { 360 482 /* Discard the current state if requested: */ 361 483 if (dlg.mCbDiscardCurState->isChecked() && dlg.mCbDiscardCurState->isVisibleTo(&dlg)) 362 484 { 363 CSnapshot snapshot = m achine.GetCurrentSnapshot();485 CSnapshot snapshot = m.GetCurrentSnapshot(); 364 486 CProgress progress = console.RestoreSnapshot(snapshot); 365 487 if (!console.isOk()) … … 368 490 { 369 491 /* Show the progress dialog: */ 370 msgCenter().showModalProgressDialog(progress, m achine.GetName(), ":/progress_snapshot_discard_90px.png", 0, true);492 msgCenter().showModalProgressDialog(progress, m.GetName(), ":/progress_snapshot_discard_90px.png", 0, true); 371 493 if (progress.GetResultCode() != 0) 372 494 msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName()); … … 375 497 } 376 498 377 if ( success)499 if (fSuccess) 378 500 fCloseApplication = true; 379 501 } 380 502 381 if ( success)503 if (fSuccess) 382 504 { 383 505 /* Read the last user's choice for the given VM: */ 384 QStringList prevAction = m achine.GetExtraData(VBoxDefs::GUI_LastCloseAction).split(',');506 QStringList prevAction = m.GetExtraData(VBoxDefs::GUI_LastCloseAction).split(','); 385 507 /* Memorize the last user's choice for the given VM: */ 386 508 QString lastAction = strPowerOff; … … 396 518 if (dlg.mCbDiscardCurState->isChecked()) 397 519 (lastAction += ",") += strDiscardCurState; 398 m achine.SetExtraData(VBoxDefs::GUI_LastCloseAction, lastAction);520 m.SetExtraData(VBoxDefs::GUI_LastCloseAction, lastAction); 399 521 } 400 522 } 401 523 402 524 /* Restore the running state if needed: */ 403 if ( success && !fCloseApplication && !fWasPaused && uisession()->machineState() == KMachineState_Paused)525 if (fSuccess && !fCloseApplication && !fWasPaused && uisession()->machineState() == KMachineState_Paused) 404 526 uisession()->unpause(); 405 527 … … 407 529 machineLogic()->setPreventAutoClose(false); 408 530 } 409 410 531 break; 411 532 } 412 413 533 default: 414 534 break; 415 535 } 416 417 536 if (fCloseApplication) 418 537 { 419 /* VM has been powered off or saved. We must *safely* close theVM window(s): */538 /* VM has been powered off or saved. We must *safely* close VM window(s): */ 420 539 QTimer::singleShot(0, uisession(), SLOT(sltCloseVirtualSession())); 421 540 } 422 541 } 423 542 424 void UIMachineWindow::prepareWindowIcon() 425 { 426 #if !(defined (Q_WS_WIN) || defined (Q_WS_MAC)) 427 /* The default application icon (will be changed to VM-specific icon little bit later): 428 * 1. On Win32, it's built-in to the executable; 429 * 2. On Mac OS X the icon referenced in info.plist is used. */ 430 setWindowIcon(QIcon(":/VirtualBox_48px.png")); 431 #endif 432 433 #ifndef Q_WS_MAC 434 /* Set the VM-specific application icon except Mac OS X: */ 435 setWindowIcon(vboxGlobal().vmGuestOSTypeIcon(session().GetMachine().GetOSTypeId())); 436 #endif 437 } 438 439 void UIMachineWindow::prepareConsoleConnections() 543 void UIMachineWindow::prepareSessionConnections() 440 544 { 441 545 /* Machine state-change updater: */ 442 546 connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged())); 443 547 444 /* Guest monitor 548 /* Guest monitor-change updater: */ 445 549 connect(uisession(), SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)), 446 550 this, SLOT(sltGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect))); 447 551 } 448 552 449 void UIMachineWindow::prepareMachineViewContainer() 450 { 451 /* Create view container. 452 * After it will be passed to parent widget of some mode, 453 * there will be no need to delete it, so no need to cleanup: */ 454 m_pMachineViewContainer = new QGridLayout(); 455 m_pMachineViewContainer->setMargin(0); 456 m_pMachineViewContainer->setSpacing(0); 457 458 /* Create and add shifting spacers. 459 * After they will be inserted into layout, it will get the parentness 460 * of those spacers, so there will be no need to cleanup them. */ 553 void UIMachineWindow::prepareMainLayout() 554 { 555 /* Create central-widget: */ 556 setCentralWidget(new QWidget); 557 558 /* Create main-layout: */ 559 m_pMainLayout = new QGridLayout(centralWidget()); 560 m_pMainLayout->setMargin(0); 561 m_pMainLayout->setSpacing(0); 562 563 /* Create shifting-spacers: */ 461 564 m_pTopSpacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding); 462 565 m_pBottomSpacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding); … … 464 567 m_pRightSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed); 465 568 466 m_pMachineViewContainer->addItem(m_pTopSpacer, 0, 1); 467 m_pMachineViewContainer->addItem(m_pBottomSpacer, 2, 1); 468 m_pMachineViewContainer->addItem(m_pLeftSpacer, 1, 0); 469 m_pMachineViewContainer->addItem(m_pRightSpacer, 1, 2); 569 /* Add shifting-spacers into main-layout: */ 570 m_pMainLayout->addItem(m_pTopSpacer, 0, 1); 571 m_pMainLayout->addItem(m_pBottomSpacer, 2, 1); 572 m_pMainLayout->addItem(m_pLeftSpacer, 1, 0); 573 m_pMainLayout->addItem(m_pRightSpacer, 1, 2); 574 } 575 576 void UIMachineWindow::prepareMachineView() 577 { 578 #ifdef VBOX_WITH_VIDEOHWACCEL 579 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */ 580 bool bAccelerate2DVideo = machine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable(); 581 #endif /* VBOX_WITH_VIDEOHWACCEL */ 582 583 /* Get visual-state type: */ 584 UIVisualStateType visualStateType = machineLogic()->visualStateType(); 585 586 /* Create machine-view: */ 587 m_pMachineView = UIMachineView::create( this 588 , m_uScreenId 589 , visualStateType 590 #ifdef VBOX_WITH_VIDEOHWACCEL 591 , bAccelerate2DVideo 592 #endif /* VBOX_WITH_VIDEOHWACCEL */ 593 ); 594 595 /* Add machine-view into main-layout: */ 596 m_pMainLayout->addWidget(m_pMachineView, 1, 1, viewAlignment(visualStateType)); 470 597 } 471 598 … … 488 615 } 489 616 617 void UIMachineWindow::cleanupMachineView() 618 { 619 /* Destroy machine-view: */ 620 UIMachineView::destroy(m_pMachineView); 621 m_pMachineView = 0; 622 } 623 490 624 void UIMachineWindow::updateAppearanceOf(int iElement) 491 625 { 492 CMachine machine = session().GetMachine(); 493 494 if (iElement & UIVisualElement_WindowCaption) 495 { 626 /* Update window title: */ 627 if (iElement & UIVisualElement_WindowTitle) 628 { 629 /* Get machine: */ 630 const CMachine &m = machine(); 496 631 /* Get machine state: */ 497 632 KMachineState state = uisession()->machineState(); 498 633 /* Prepare full name: */ 499 634 QString strSnapshotName; 500 if (m achine.GetSnapshotCount() > 0)635 if (m.GetSnapshotCount() > 0) 501 636 { 502 CSnapshot snapshot = m achine.GetCurrentSnapshot();637 CSnapshot snapshot = m.GetCurrentSnapshot(); 503 638 strSnapshotName = " (" + snapshot.GetName() + ")"; 504 639 } 505 QString strMachineName = m achine.GetName() + strSnapshotName;640 QString strMachineName = m.GetName() + strSnapshotName; 506 641 if (state != KMachineState_Null) 507 642 strMachineName += " [" + vboxGlobal().toString(state) + "]"; 508 643 /* Unusual on the Mac. */ 509 644 #ifndef Q_WS_MAC 510 strMachineName += " - " + m_strWindowTitlePrefix;511 #endif /* Q_WS_MAC */512 if (m achine.GetMonitorCount() > 1)645 strMachineName += " - " + defaultWindowTitle(); 646 #endif /* !Q_WS_MAC */ 647 if (m.GetMonitorCount() > 1) 513 648 strMachineName += QString(" : %1").arg(m_uScreenId + 1); 514 649 setWindowTitle(strMachineName); … … 525 660 #endif /* VBOX_WITH_DEBUGGER_GUI */ 526 661 527 void UIMachineWindow::sltMachineStateChanged() 528 { 529 updateAppearanceOf(UIVisualElement_WindowCaption); 530 } 531 532 void UIMachineWindow::sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect /* screenGeo */) 533 { 534 /* Ignore change events for other screens: */ 535 if (uScreenId != m_uScreenId) 536 return; 537 538 /* Ignore KGuestMonitorChangedEventType_NewOrigin change event: */ 539 if (changeType == KGuestMonitorChangedEventType_NewOrigin) 540 return; 541 542 /* Process KGuestMonitorChangedEventType_Enabled change event: */ 543 if (isHidden() && changeType == KGuestMonitorChangedEventType_Enabled) 544 showInNecessaryMode(); 545 /* Process KGuestMonitorChangedEventType_Disabled change event: */ 546 else if (!isHidden() && changeType == KGuestMonitorChangedEventType_Disabled) 547 hide(); 548 } 549 662 /* static */ 550 663 Qt::WindowFlags UIMachineWindow::windowFlags(UIVisualStateType visualStateType) 551 664 { … … 561 674 } 562 675 676 /* static */ 677 Qt::Alignment UIMachineWindow::viewAlignment(UIVisualStateType visualStateType) 678 { 679 switch (visualStateType) 680 { 681 case UIVisualStateType_Normal: return 0; 682 case UIVisualStateType_Fullscreen: return Qt::AlignVCenter | Qt::AlignHCenter; 683 case UIVisualStateType_Seamless: return 0; 684 case UIVisualStateType_Scale: return 0; 685 } 686 AssertMsgFailed(("Incorrect visual state!")); 687 return 0; 688 } 689 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h
r41107 r41114 20 20 #define __UIMachineWindow_h__ 21 21 22 /* Global includes */22 /* Global includes: */ 23 23 #include <QMainWindow> 24 24 25 /* Local includes */25 /* Local includes: */ 26 26 #include "QIWithRetranslateUI.h" 27 27 #include "UIMachineDefs.h" 28 28 #include "COMDefs.h" 29 29 30 /* Global forwards */ 31 class QWidget; 30 /* Forward declarations: */ 32 31 class QGridLayout; 33 32 class QSpacerItem; 34 33 class QCloseEvent; 35 36 /* Local forwards */37 34 class CSession; 38 35 class UISession; … … 40 37 class UIMachineView; 41 38 39 /* Machine-window interface: */ 42 40 class UIMachineWindow : public QIWithRetranslateUI2<QMainWindow> 43 41 { … … 46 44 public: 47 45 48 /* Factory function to create required machine window child: */49 static UIMachineWindow* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType,ulong uScreenId = 0);46 /* Factory functions to create/destroy machine-window: */ 47 static UIMachineWindow* create(UIMachineLogic *pMachineLogic, ulong uScreenId = 0); 50 48 static void destroy(UIMachineWindow *pWhichWindow); 51 49 50 /* Prepare/cleanup machine-window: */ 51 void prepare(); 52 void cleanup(); 53 52 54 /* Public getters: */ 53 virtual UIMachineLogic* machineLogic() const { return m_pMachineLogic; }54 virtual UIMachineView* machineView() const { return m_pMachineView; }55 UIMachineView* machineView() const { return m_pMachineView; } 56 UIMachineLogic* machineLogic() const { return m_pMachineLogic; } 55 57 UISession* uisession() const; 56 58 CSession& session() const; 59 CMachine machine() const; 57 60 58 61 protected slots: … … 62 65 virtual void sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo); 63 66 64 /* Slot to safeclose machine-window: */67 /* Slot to close machine-window: */ 65 68 void sltTryClose(); 66 69 67 70 protected: 68 71 69 /* Machine window constructor/destructor: */72 /* Constructor/destructor: */ 70 73 UIMachineWindow(UIMachineLogic *pMachineLogic, ulong uScreenId); 71 virtual~UIMachineWindow();74 ~UIMachineWindow(); 72 75 73 /* Protected getters: */74 const QString& defaultWindowTitle() const { return m_strWindowTitlePrefix; }76 /* Show stuff: */ 77 virtual void showInNecessaryMode() = 0; 75 78 76 /* Translate routine: */77 v irtual void retranslateUi();79 /* Translate stuff: */ 80 void retranslateUi(); 78 81 79 /* Common machine window event handlers: */82 /* Event handlers: */ 80 83 #ifdef Q_WS_X11 81 84 bool x11Event(XEvent *pEvent); 82 #endif 85 #endif /* Q_WS_X11 */ 83 86 void closeEvent(QCloseEvent *pEvent); 84 87 85 88 /* Prepare helpers: */ 86 virtual void prepareWindowIcon(); 87 virtual void prepareConsoleConnections(); 88 virtual void prepareMachineViewContainer(); 89 //virtual void loadWindowSettings() {} 89 virtual void prepareSessionConnections(); 90 virtual void prepareMainLayout(); 91 virtual void prepareMenu() {} 92 virtual void prepareStatusBar() {} 93 virtual void prepareMachineView(); 94 virtual void prepareVisualState() {} 90 95 virtual void prepareHandlers(); 96 virtual void loadSettings() {} 91 97 92 98 /* Cleanup helpers: */ 99 virtual void saveSettings() {} 93 100 virtual void cleanupHandlers(); 94 //virtual void saveWindowSettings() {} 95 //virtual void cleanupMachineViewContainer() {} 96 //virtual void cleanupConsoleConnections() {} 97 //virtual void cleanupWindowIcon() {} 101 virtual void cleanupVisualState() {} 102 virtual void cleanupMachineView(); 103 virtual void cleanupStatusBar() {} 104 virtual void cleanupMenu() {} 105 virtual void cleanupMainLayout() {} 106 virtual void cleanupSessionConnections() {} 98 107 99 /* Update routines: */108 /* Update stuff: */ 100 109 virtual void updateAppearanceOf(int iElement); 101 110 #ifdef VBOX_WITH_DEBUGGER_GUI 102 v irtual void updateDbgWindows();111 void updateDbgWindows(); 103 112 #endif /* VBOX_WITH_DEBUGGER_GUI */ 104 113 105 114 /* Helpers: */ 106 Qt::WindowFlags windowFlags(UIVisualStateType visualStateType); 115 const QString& defaultWindowTitle() const { return m_strWindowTitlePrefix; } 116 static Qt::WindowFlags windowFlags(UIVisualStateType visualStateType); 117 static Qt::Alignment viewAlignment(UIVisualStateType visualStateType); 107 118 108 /* Show routine: */ 109 virtual void showInNecessaryMode() = 0; 110 111 /* Protected variables: */ 119 /* Variables: */ 112 120 UIMachineLogic *m_pMachineLogic; 113 114 /* Virtual screen number: */121 UIMachineView *m_pMachineView; 122 QString m_strWindowTitlePrefix; 115 123 ulong m_uScreenId; 116 117 QGridLayout *m_pMachineViewContainer; 124 QGridLayout *m_pMainLayout; 118 125 QSpacerItem *m_pTopSpacer; 119 126 QSpacerItem *m_pBottomSpacer; … … 121 128 QSpacerItem *m_pRightSpacer; 122 129 123 UIMachineView *m_pMachineView; 124 QString m_strWindowTitlePrefix; 125 130 /* Friend classes: */ 126 131 friend class UIMachineLogic; 127 132 }; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
r41064 r41114 147 147 /* Create machine window(s): */ 148 148 for (int cScreenId = 0; cScreenId < m_pScreenLayout->guestScreenCount(); ++cScreenId) 149 addMachineWindow(UIMachineWindow::create(this, visualStateType(),cScreenId));149 addMachineWindow(UIMachineWindow::create(this, cScreenId)); 150 150 151 151 /* Connect screen-layout change handler: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp
r41107 r41114 18 18 */ 19 19 20 /* Global includes */20 /* Global includes: */ 21 21 #include <QDesktopWidget> 22 22 #include <QTimer> … … 25 25 #endif /* Q_WS_MAC */ 26 26 27 /* Local includes */ 28 #include "VBoxGlobal.h" 27 /* Local includes: */ 29 28 #include "VBoxMiniToolBar.h" 30 31 29 #include "UISession.h" 32 30 #include "UIActionPoolRuntime.h" 33 31 #include "UIMachineLogicFullscreen.h" 34 32 #include "UIMachineWindowFullscreen.h" 35 #include "UIMachineView.h"36 33 37 34 UIMachineWindowFullscreen::UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId) … … 40 37 , m_pMiniToolBar(0) 41 38 { 42 /* Set the main window in VBoxGlobal: */ 43 if (uScreenId == 0) 44 vboxGlobal().setMainWindow(this); 45 46 /* Prepare fullscreen window icon: */ 47 prepareWindowIcon(); 48 49 /* Prepare console connections: */ 50 prepareConsoleConnections(); 51 52 /* Prepare fullscreen menu: */ 53 prepareMenu(); 54 55 /* Prepare machine view container: */ 56 prepareMachineViewContainer(); 57 58 /* Prepare fullscreen machine view: */ 59 prepareMachineView(); 60 61 /* Prepare handlers: */ 62 prepareHandlers(); 63 64 /* Prepare mini tool-bar: */ 65 prepareMiniToolBar(); 66 67 /* Retranslate fullscreen window finally: */ 68 retranslateUi(); 69 70 /* Update all the elements: */ 71 updateAppearanceOf(UIVisualElement_AllStuff); 72 73 /* Show fullscreen window: */ 74 showInNecessaryMode(); 75 } 76 77 UIMachineWindowFullscreen::~UIMachineWindowFullscreen() 78 { 79 /* Save window settings: */ 80 saveWindowSettings(); 81 82 /* Cleanup mini tool-bar: */ 83 cleanupMiniToolBar(); 84 85 /* Prepare handlers: */ 86 cleanupHandlers(); 87 88 /* Cleanup machine view: */ 89 cleanupMachineView(); 90 91 /* Cleanup menu: */ 92 cleanupMenu(); 39 } 40 41 void UIMachineWindowFullscreen::sltMachineStateChanged() 42 { 43 /* Call to base-class: */ 44 UIMachineWindow::sltMachineStateChanged(); 45 46 /* Update mini-toolbar: */ 47 updateAppearanceOf(UIVisualElement_MiniToolBar); 93 48 } 94 49 … … 96 51 { 97 52 /* Get corresponding screen: */ 98 int iScreen = static_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);53 int iScreen = qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId); 99 54 /* Calculate working area: */ 100 55 QRect workingArea = QApplication::desktop()->screenGeometry(iScreen); … … 109 64 void UIMachineWindowFullscreen::sltPopupMainMenu() 110 65 { 111 /* Popup main 66 /* Popup main-menu if present: */ 112 67 if (m_pMainMenu && !m_pMainMenu->isEmpty()) 113 68 { … … 119 74 void UIMachineWindowFullscreen::prepareMenu() 120 75 { 76 /* Call to base-class: */ 77 UIMachineWindow::prepareMenu(); 78 79 /* Prepare menu: */ 121 80 #ifdef Q_WS_MAC 122 81 setMenuBar(uisession()->newMenuBar()); … … 125 84 } 126 85 127 void UIMachineWindowFullscreen::prepareMiniToolBar() 128 { 129 /* Get current machine: */ 130 CMachine machine = session().GetConsole().GetMachine(); 131 /* Check if mini tool-bar should present: */ 132 bool fIsActive = machine.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no"; 133 if (fIsActive) 134 { 135 /* Get the mini tool-bar alignment: */ 136 bool fIsAtTop = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top"; 137 /* Get the mini tool-bar auto-hide feature availability: */ 138 bool fIsAutoHide = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off"; 139 m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(), 140 fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom, 141 true, fIsAutoHide); 142 m_pMiniToolBar->updateDisplay(true, true); 143 QList<QMenu*> menus; 144 QList<QAction*> actions = uisession()->newMenu()->actions(); 145 for (int i=0; i < actions.size(); ++i) 146 menus << actions.at(i)->menu(); 147 *m_pMiniToolBar << menus; 148 connect(m_pMiniToolBar, SIGNAL(minimizeAction()), this, SLOT(showMinimized())); 149 connect(m_pMiniToolBar, SIGNAL(exitAction()), 150 gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger())); 151 connect(m_pMiniToolBar, SIGNAL(closeAction()), 152 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger())); 153 } 154 } 155 156 void UIMachineWindowFullscreen::prepareMachineView() 157 { 158 #ifdef VBOX_WITH_VIDEOHWACCEL 159 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */ 160 bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable(); 161 #endif 162 163 /* Set central widget: */ 164 setCentralWidget(new QWidget); 165 166 /* Set central widget layout: */ 167 centralWidget()->setLayout(m_pMachineViewContainer); 168 169 m_pMachineView = UIMachineView::create( this 170 , m_uScreenId 171 , machineLogic()->visualStateType() 172 #ifdef VBOX_WITH_VIDEOHWACCEL 173 , bAccelerate2DVideo 174 #endif 175 ); 176 177 /* Add machine view into layout: */ 178 m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); 86 void UIMachineWindowFullscreen::prepareVisualState() 87 { 88 /* Call to base-class: */ 89 UIMachineWindow::prepareVisualState(); 179 90 180 91 /* The background has to go black: */ … … 184 95 centralWidget()->setAutoFillBackground(true); 185 96 setAutoFillBackground(true); 186 } 187 188 void UIMachineWindowFullscreen::saveWindowSettings() 97 98 /* Prepare mini-toolbar: */ 99 prepareMiniToolbar(); 100 } 101 102 void UIMachineWindowFullscreen::prepareMiniToolbar() 189 103 { 190 104 /* Get machine: */ 191 CMachine machine = session().GetConsole().GetMachine(); 192 193 /* Save extra-data settings: */ 194 { 195 /* Save mini tool-bar settings: */ 196 if (m_pMiniToolBar) 197 machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off"); 198 } 199 } 200 201 void UIMachineWindowFullscreen::cleanupMachineView() 202 { 203 /* Do not cleanup machine view if it is not present: */ 204 if (!machineView()) 105 CMachine m = machine(); 106 107 /* Make sure mini-toolbar is necessary: */ 108 bool fIsActive = m.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no"; 109 if (!fIsActive) 205 110 return; 206 111 207 UIMachineView::destroy(m_pMachineView); 208 m_pMachineView = 0; 209 } 210 211 void UIMachineWindowFullscreen::cleanupMiniToolBar() 212 { 213 if (m_pMiniToolBar) 214 { 215 delete m_pMiniToolBar; 216 m_pMiniToolBar = 0; 217 } 112 /* Get the mini-toolbar alignment: */ 113 bool fIsAtTop = m.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top"; 114 /* Get the mini-toolbar auto-hide feature availability: */ 115 bool fIsAutoHide = m.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off"; 116 m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(), 117 fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom, 118 true, fIsAutoHide); 119 m_pMiniToolBar->updateDisplay(true, true); 120 QList<QMenu*> menus; 121 QList<QAction*> actions = uisession()->newMenu()->actions(); 122 for (int i=0; i < actions.size(); ++i) 123 menus << actions.at(i)->menu(); 124 *m_pMiniToolBar << menus; 125 connect(m_pMiniToolBar, SIGNAL(minimizeAction()), this, SLOT(showMinimized())); 126 connect(m_pMiniToolBar, SIGNAL(exitAction()), 127 gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger())); 128 connect(m_pMiniToolBar, SIGNAL(closeAction()), 129 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger())); 130 } 131 132 void UIMachineWindowFullscreen::cleanupMiniToolbar() 133 { 134 /* Make sure mini-toolbar was created: */ 135 if (!m_pMiniToolBar) 136 return; 137 138 /* Save mini-toolbar settings: */ 139 machine().SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off"); 140 /* Delete mini-toolbar: */ 141 delete m_pMiniToolBar; 142 m_pMiniToolBar = 0; 143 } 144 145 void UIMachineWindowFullscreen::cleanupVisualState() 146 { 147 /* Cleanup mini-toolbar: */ 148 cleanupMiniToolbar(); 149 150 /* Call to base-class: */ 151 UIMachineWindow::cleanupVisualState(); 218 152 } 219 153 220 154 void UIMachineWindowFullscreen::cleanupMenu() 221 155 { 156 /* Cleanup menu: */ 222 157 delete m_pMainMenu; 223 158 m_pMainMenu = 0; 224 } 225 226 void UIMachineWindowFullscreen::updateAppearanceOf(int iElement) 227 { 228 /* Base class update: */ 229 UIMachineWindow::updateAppearanceOf(iElement); 230 231 /* If mini tool-bar is present: */ 232 if (m_pMiniToolBar) 233 { 234 /* Get machine: */ 235 CMachine machine = session().GetConsole().GetMachine(); 236 /* Get snapshot(s): */ 237 QString strSnapshotName; 238 if (machine.GetSnapshotCount() > 0) 239 { 240 CSnapshot snapshot = machine.GetCurrentSnapshot(); 241 strSnapshotName = " (" + snapshot.GetName() + ")"; 242 } 243 /* Update mini tool-bar text: */ 244 m_pMiniToolBar->setDisplayText(machine.GetName() + strSnapshotName); 245 } 159 160 /* Call to base-class: */ 161 UIMachineWindow::cleanupMenu(); 246 162 } 247 163 … … 251 167 BOOL fEnabled = true; 252 168 ULONG guestOriginX = 0, guestOriginY = 0, guestWidth = 0, guestHeight = 0; 253 session().GetMachine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled);169 machine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled); 254 170 if (fEnabled) 255 171 { … … 268 184 #ifdef Q_WS_MAC 269 185 /* Make sure it is really on the right place (especially on the Mac): */ 270 QRect r = QApplication::desktop()->screenGeometry( static_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId));186 QRect r = QApplication::desktop()->screenGeometry(qobject_cast<UIMachineLogicFullscreen*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId)); 271 187 move(r.topLeft()); 272 188 #endif /* Q_WS_MAC */ … … 274 190 } 275 191 192 void UIMachineWindowFullscreen::updateAppearanceOf(int iElement) 193 { 194 /* Call to base-class: */ 195 UIMachineWindow::updateAppearanceOf(iElement); 196 197 /* Update mini-toolbar: */ 198 if (iElement & UIVisualElement_MiniToolBar) 199 { 200 if (m_pMiniToolBar) 201 { 202 /* Get machine: */ 203 const CMachine &m = machine(); 204 /* Get snapshot(s): */ 205 QString strSnapshotName; 206 if (m.GetSnapshotCount() > 0) 207 { 208 CSnapshot snapshot = m.GetCurrentSnapshot(); 209 strSnapshotName = " (" + snapshot.GetName() + ")"; 210 } 211 /* Update mini-toolbar text: */ 212 m_pMiniToolBar->setDisplayText(m.GetName() + strSnapshotName); 213 } 214 } 215 } 216 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.h
r41107 r41114 20 20 #define __UIMachineWindowFullscreen_h__ 21 21 22 /* Local includes */22 /* Local includes: */ 23 23 #include "UIMachineWindow.h" 24 24 25 /* Local forwards*/25 /* Forward declarations: */ 26 26 class VBoxMiniToolBar; 27 27 28 /* Fullscreen machine-window implementation: */ 28 29 class UIMachineWindowFullscreen : public UIMachineWindow 29 30 { 30 31 Q_OBJECT; 31 32 32 public slots:33 34 void sltPlaceOnScreen();35 36 33 protected: 37 34 38 /* Fullscreen machine window constructor/destructor: */35 /* Constructor: */ 39 36 UIMachineWindowFullscreen(UIMachineLogic *pMachineLogic, ulong uScreenId); 40 virtual ~UIMachineWindowFullscreen();41 37 42 38 private slots: 43 39 44 /* Popup main menu: */ 40 /* Session event-handlers: */ 41 void sltMachineStateChanged(); 42 43 /* Places window on screen: */ 44 void sltPlaceOnScreen(); 45 46 /* Popup main-menu: */ 45 47 void sltPopupMainMenu(); 46 48 … … 49 51 /* Prepare helpers: */ 50 52 void prepareMenu(); 51 void prepareMiniToolBar(); 52 void prepareMachineView(); 53 //void loadWindowSettings() {} 53 void prepareVisualState(); 54 void prepareMiniToolbar(); 54 55 55 56 /* Cleanup helpers: */ 56 void saveWindowSettings(); 57 void cleanupMachineView(); 58 void cleanupMiniToolBar(); 57 void cleanupMiniToolbar(); 58 void cleanupVisualState(); 59 59 void cleanupMenu(); 60 60 61 /* Update routines: */ 61 /* Show stuff: */ 62 void showInNecessaryMode(); 63 64 /* Update stuff: */ 62 65 void updateAppearanceOf(int iElement); 63 66 64 /* Other members: */ 65 void showInNecessaryMode(); 66 67 /* Private variables: */ 67 /* Widgets: */ 68 68 QMenu *m_pMainMenu; 69 69 VBoxMiniToolBar *m_pMiniToolBar; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp
r41107 r41114 101 101 /* Create machine window(s): */ 102 102 for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId) 103 addMachineWindow(UIMachineWindow::create(this, visualStateType(),uScreenId));103 addMachineWindow(UIMachineWindow::create(this, uScreenId)); 104 104 /* Order machine window(s): */ 105 105 for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId) -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp
r41107 r41114 18 18 */ 19 19 20 /* Global includes */20 /* Global includes: */ 21 21 #include <QDesktopWidget> 22 22 #include <QMenuBar> … … 24 24 #include <QContextMenuEvent> 25 25 26 /* Local includes */26 /* Local includes: */ 27 27 #include "VBoxGlobal.h" 28 28 #include "UIMessageCenter.h" 29 29 #include "VBoxUtils.h" 30 31 30 #include "UISession.h" 32 31 #include "UIActionPoolRuntime.h" … … 44 43 # include "UIImageTools.h" 45 44 #endif /* Q_WS_MAC */ 46 47 45 #include "QIStatusBar.h" 48 46 #include "QIStateIndicator.h" … … 54 52 , m_pIdleTimer(0) 55 53 { 56 /* Set the main window in VBoxGlobal */57 if (uScreenId == 0)58 vboxGlobal().setMainWindow(this);59 60 /* Prepare window icon: */61 prepareWindowIcon();62 63 /* Prepare console connections: */64 prepareConsoleConnections();65 66 /* Prepare menu: */67 prepareMenu();68 69 /* Prepare status bar: */70 prepareStatusBar();71 72 /* Prepare connections: */73 prepareConnections();74 75 /* Retranslate normal window finally: */76 retranslateUi();77 78 /* Prepare normal machine view container: */79 prepareMachineViewContainer();80 81 /* Prepare normal machine view: */82 prepareMachineView();83 84 /* Prepare handlers: */85 prepareHandlers();86 87 /* Load normal window settings: */88 loadWindowSettings();89 90 /* Update all the elements: */91 updateAppearanceOf(UIVisualElement_AllStuff);92 93 #ifdef Q_WS_MAC94 /* Beta label? */95 if (vboxGlobal().isBeta())96 {97 QPixmap betaLabel = ::betaLabel(QSize(100, 16));98 ::darwinLabelWindow(this, &betaLabel, true);99 }100 #endif /* Q_WS_MAC */101 102 /* Show normal window: */103 showInNecessaryMode();104 }105 106 UIMachineWindowNormal::~UIMachineWindowNormal()107 {108 /* Save normal window settings: */109 saveWindowSettings();110 111 /* Prepare handlers: */112 cleanupHandlers();113 114 /* Cleanup normal machine view: */115 cleanupMachineView();116 117 /* Cleanup status-bar: */118 cleanupStatusBar();119 54 } 120 55 121 56 void UIMachineWindowNormal::sltMachineStateChanged() 122 57 { 58 /* Call to base-class: */ 123 59 UIMachineWindow::sltMachineStateChanged(); 60 61 /* Update pause and virtualization stuff: */ 124 62 updateAppearanceOf(UIVisualElement_PauseStuff | UIVisualElement_VirtualizationStuff); 125 63 } … … 127 65 void UIMachineWindowNormal::sltMediumChange(const CMediumAttachment &attachment) 128 66 { 67 /* Update corresponding medium stuff: */ 129 68 KDeviceType type = attachment.GetType(); 130 69 if (type == KDeviceType_HardDisk) … … 138 77 void UIMachineWindowNormal::sltUSBControllerChange() 139 78 { 79 /* Update USB stuff: */ 140 80 updateAppearanceOf(UIVisualElement_USBStuff); 141 81 } … … 143 83 void UIMachineWindowNormal::sltUSBDeviceStateChange() 144 84 { 85 /* Update USB stuff: */ 145 86 updateAppearanceOf(UIVisualElement_USBStuff); 146 87 } … … 148 89 void UIMachineWindowNormal::sltNetworkAdapterChange() 149 90 { 91 /* Update network stuff: */ 150 92 updateAppearanceOf(UIVisualElement_NetworkStuff); 151 93 } … … 153 95 void UIMachineWindowNormal::sltSharedFolderChange() 154 96 { 97 /* Update shared-folders stuff: */ 155 98 updateAppearanceOf(UIVisualElement_SharedFolderStuff); 156 99 } … … 158 101 void UIMachineWindowNormal::sltCPUExecutionCapChange() 159 102 { 103 /* Update virtualization stuff: */ 160 104 updateAppearanceOf(UIVisualElement_VirtualizationStuff); 161 105 } … … 163 107 void UIMachineWindowNormal::sltUpdateIndicators() 164 108 { 109 /* Update LEDs: */ 165 110 updateIndicatorState(indicatorsPool()->indicator(UIIndicatorIndex_HardDisks), KDeviceType_HardDisk); 166 111 updateIndicatorState(indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks), KDeviceType_DVD); … … 173 118 void UIMachineWindowNormal::sltShowIndicatorsContextMenu(QIStateIndicator *pIndicator, QContextMenuEvent *pEvent) 174 119 { 120 /* Show CD/DVD device LED context menu: */ 175 121 if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks)) 176 122 { … … 178 124 gActionPool->action(UIActionIndexRuntime_Menu_OpticalDevices)->menu()->exec(pEvent->globalPos()); 179 125 } 126 /* Show floppy drive LED context menu: */ 180 127 else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks)) 181 128 { … … 183 130 gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices)->menu()->exec(pEvent->globalPos()); 184 131 } 132 /* Show USB device LED context menu: */ 185 133 else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)) 186 134 { … … 188 136 gActionPool->action(UIActionIndexRuntime_Menu_USBDevices)->menu()->exec(pEvent->globalPos()); 189 137 } 138 /* Show network adapter LED context menu: */ 190 139 else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)) 191 140 { … … 193 142 gActionPool->action(UIActionIndexRuntime_Menu_NetworkAdapters)->menu()->exec(pEvent->globalPos()); 194 143 } 144 /* Show shared-folders LED context menu: */ 195 145 else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders)) 196 146 { … … 198 148 gActionPool->action(UIActionIndexRuntime_Menu_SharedFolders)->menu()->exec(pEvent->globalPos()); 199 149 } 150 /* Show mouse LED context menu: */ 200 151 else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_Mouse)) 201 152 { … … 207 158 void UIMachineWindowNormal::sltProcessGlobalSettingChange(const char * /* aPublicName */, const char * /* aName */) 208 159 { 160 /* Update host-combination LED: */ 209 161 m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo())); 210 162 } 211 163 212 void UIMachineWindowNormal::retranslateUi() 213 { 214 /* Translate parent class: */ 215 UIMachineWindow::retranslateUi(); 216 217 m_pNameHostkey->setToolTip( 218 QApplication::translate("UIMachineWindowNormal", "Shows the currently assigned Host key.<br>" 219 "This key, when pressed alone, toggles the keyboard and mouse " 220 "capture state. It can also be used in combination with other keys " 221 "to quickly perform actions from the main menu.")); 222 m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo())); 223 } 224 225 void UIMachineWindowNormal::updateAppearanceOf(int iElement) 226 { 227 /* Update parent-class window: */ 228 UIMachineWindow::updateAppearanceOf(iElement); 229 230 /* Update that machine window: */ 231 if (iElement & UIVisualElement_PauseStuff) 232 { 233 if (!statusBar()->isHidden()) 234 { 235 if (uisession()->isPaused() && m_pIdleTimer->isActive()) 236 m_pIdleTimer->stop(); 237 else if (uisession()->isRunning() && !m_pIdleTimer->isActive()) 238 m_pIdleTimer->start(100); 239 sltUpdateIndicators(); 240 } 241 } 242 if (iElement & UIVisualElement_HDStuff) 243 indicatorsPool()->indicator(UIIndicatorIndex_HardDisks)->updateAppearance(); 244 if (iElement & UIVisualElement_CDStuff) 245 indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks)->updateAppearance(); 246 if (iElement & UIVisualElement_FDStuff) 247 indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks)->updateAppearance(); 248 if (iElement & UIVisualElement_USBStuff && 249 !indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->isHidden()) 250 indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->updateAppearance(); 251 if (iElement & UIVisualElement_NetworkStuff) 252 indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)->updateAppearance(); 253 if (iElement & UIVisualElement_SharedFolderStuff) 254 indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders)->updateAppearance(); 255 if (iElement & UIVisualElement_VirtualizationStuff) 256 indicatorsPool()->indicator(UIIndicatorIndex_Virtualization)->updateAppearance(); 257 } 258 259 bool UIMachineWindowNormal::event(QEvent *pEvent) 260 { 261 switch (pEvent->type()) 262 { 263 case QEvent::Resize: 264 { 265 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); 266 if (!isMaximizedChecked()) 267 { 268 m_normalGeometry.setSize(pResizeEvent->size()); 269 #ifdef VBOX_WITH_DEBUGGER_GUI 270 /* Update debugger window position */ 271 updateDbgWindows(); 272 #endif 273 } 274 break; 275 } 276 case QEvent::Move: 277 { 278 if (!isMaximizedChecked()) 279 { 280 m_normalGeometry.moveTo(geometry().x(), geometry().y()); 281 #ifdef VBOX_WITH_DEBUGGER_GUI 282 /* Update debugger window position */ 283 updateDbgWindows(); 284 #endif 285 } 286 break; 287 } 288 default: 289 break; 290 } 291 return QIWithRetranslateUI2<QMainWindow>::event(pEvent); 292 } 293 294 void UIMachineWindowNormal::prepareConsoleConnections() 295 { 296 /* Base-class connections: */ 297 UIMachineWindow::prepareConsoleConnections(); 164 void UIMachineWindowNormal::prepareSessionConnections() 165 { 166 /* Call to base-class: */ 167 UIMachineWindow::prepareSessionConnections(); 298 168 299 169 /* Medium change updater: */ … … 324 194 void UIMachineWindowNormal::prepareMenu() 325 195 { 196 /* Call to base-class: */ 197 UIMachineWindow::prepareMenu(); 198 199 /* Prepare menu-bar: */ 326 200 setMenuBar(uisession()->newMenuBar()); 327 201 } … … 329 203 void UIMachineWindowNormal::prepareStatusBar() 330 204 { 331 /* Common setup: */ 205 /* Call to base-class: */ 206 UIMachineWindow::prepareStatusBar(); 207 208 /* Setup: */ 332 209 setStatusBar(new QIStatusBar(this)); 333 210 QWidget *pIndicatorBox = new QWidget; … … 393 270 pHostkeyLedContainerLayout->addWidget(m_pNameHostkey); 394 271 395 /* Add to status bar: */272 /* Add to status-bar: */ 396 273 statusBar()->addPermanentWidget(pIndicatorBox, 0); 397 274 … … 402 279 403 280 #ifdef Q_WS_MAC 404 /* For the status 281 /* For the status-bar on Cocoa: */ 405 282 setUnifiedTitleAndToolBarOnMac(true); 406 #endif 407 } 408 409 void UIMachineWindowNormal::prepareConnections() 410 { 411 /* Setup global settings change updater: */ 412 connect(&vboxGlobal().settings(), SIGNAL(propertyChanged(const char *, const char *)), 413 this, SLOT(sltProcessGlobalSettingChange(const char *, const char *))); 414 } 415 416 void UIMachineWindowNormal::prepareMachineView() 417 { 418 #ifdef VBOX_WITH_VIDEOHWACCEL 419 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */ 420 bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable(); 421 #endif 422 423 /* Set central widget: */ 424 setCentralWidget(new QWidget); 425 426 /* Set central widget layout: */ 427 centralWidget()->setLayout(m_pMachineViewContainer); 428 429 m_pMachineView = UIMachineView::create( this 430 , m_uScreenId 431 , machineLogic()->visualStateType() 432 #ifdef VBOX_WITH_VIDEOHWACCEL 433 , bAccelerate2DVideo 434 #endif 435 ); 436 437 /* Add machine view into layout: */ 438 m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1); 439 440 /* Setup machine view connections: */ 441 if (machineView()) 442 { 443 /* Keyboard state-change updater: */ 444 connect(machineLogic()->keyboardHandler(), SIGNAL(keyboardStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Hostkey), SLOT(setState(int))); 445 446 /* Mouse state-change updater: */ 447 connect(machineLogic()->mouseHandler(), SIGNAL(mouseStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Mouse), SLOT(setState(int))); 448 449 /* Early initialize required connections: */ 450 indicatorsPool()->indicator(UIIndicatorIndex_Hostkey)->setState(machineLogic()->keyboardHandler()->keyboardState()); 451 indicatorsPool()->indicator(UIIndicatorIndex_Mouse)->setState(machineLogic()->mouseHandler()->mouseState()); 452 } 283 #endif /* Q_WS_MAC */ 284 } 285 286 void UIMachineWindowNormal::prepareVisualState() 287 { 288 /* Call to base-class: */ 289 UIMachineWindow::prepareVisualState(); 453 290 454 291 #ifdef VBOX_GUI_WITH_CUSTOMIZATIONS1 … … 460 297 setAutoFillBackground(true); 461 298 #endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */ 462 } 463 464 void UIMachineWindowNormal::loadWindowSettings() 465 { 466 /* Load normal window settings: */ 467 CMachine machine = session().GetMachine(); 299 300 /* Make sure host-combination LED will be updated: */ 301 connect(&vboxGlobal().settings(), SIGNAL(propertyChanged(const char *, const char *)), 302 this, SLOT(sltProcessGlobalSettingChange(const char *, const char *))); 303 304 #ifdef Q_WS_MAC 305 /* Beta label? */ 306 if (vboxGlobal().isBeta()) 307 { 308 QPixmap betaLabel = ::betaLabel(QSize(100, 16)); 309 ::darwinLabelWindow(this, &betaLabel, true); 310 } 311 #endif /* Q_WS_MAC */ 312 } 313 314 void UIMachineWindowNormal::prepareHandlers() 315 { 316 /* Call to base-class: */ 317 UIMachineWindow::prepareHandlers(); 318 319 /* Keyboard state-change updater: */ 320 connect(machineLogic()->keyboardHandler(), SIGNAL(keyboardStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Hostkey), SLOT(setState(int))); 321 /* Mouse state-change updater: */ 322 connect(machineLogic()->mouseHandler(), SIGNAL(mouseStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Mouse), SLOT(setState(int))); 323 /* Early initialize required connections: */ 324 indicatorsPool()->indicator(UIIndicatorIndex_Hostkey)->setState(machineLogic()->keyboardHandler()->keyboardState()); 325 indicatorsPool()->indicator(UIIndicatorIndex_Mouse)->setState(machineLogic()->mouseHandler()->mouseState()); 326 } 327 328 void UIMachineWindowNormal::loadSettings() 329 { 330 /* Call to base-class: */ 331 UIMachineWindow::loadSettings(); 332 333 /* Get machine: */ 334 CMachine m = machine(); 468 335 469 336 /* Load extra-data settings: */ 470 337 { 338 /* Load window position settings: */ 471 339 QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastNormalWindowPosition) : 472 340 QString("%1%2").arg(VBoxDefs::GUI_LastNormalWindowPosition).arg(m_uScreenId); 473 QStringList strPositionSettings = machine.GetExtraDataStringList(strPositionAddress); 474 341 QStringList strPositionSettings = m.GetExtraDataStringList(strPositionAddress); 475 342 bool ok = !strPositionSettings.isEmpty(), max = false; 476 343 int x = 0, y = 0, w = 0, h = 0; 477 478 344 if (ok && strPositionSettings.size() > 0) 479 345 x = strPositionSettings[0].toInt(&ok); … … 490 356 if (ok && strPositionSettings.size() > 4) 491 357 max = strPositionSettings[4] == VBoxDefs::GUI_LastWindowState_Max; 492 493 358 QRect ar = ok ? QApplication::desktop()->availableGeometry(QPoint(x, y)) : 494 359 QApplication::desktop()->availableGeometry(this); … … 498 363 { 499 364 /* If previous machine state is SAVED: */ 500 if (m achine.GetState() == KMachineState_Saved)365 if (m.GetState() == KMachineState_Saved) 501 366 { 502 367 /* Restore window size and position: */ … … 504 369 setGeometry(m_normalGeometry); 505 370 } 506 /* If previous machine state is not SAVED: */371 /* If previous machine state was not SAVED: */ 507 372 else 508 373 { … … 511 376 setGeometry(m_normalGeometry); 512 377 if (machineView()) 513 machineView()->normalizeGeometry(false /* adjust position? */);378 machineView()->normalizeGeometry(false); 514 379 } 515 380 /* Maximize if needed: */ … … 521 386 /* Normalize view early to the optimal size: */ 522 387 if (machineView()) 523 machineView()->normalizeGeometry(true /* adjust position? */);388 machineView()->normalizeGeometry(true); 524 389 /* Move newly created window to the screen center: */ 525 390 m_normalGeometry = geometry(); … … 528 393 } 529 394 530 /* Normalize view to the optimal size: 531 * Note: Cause of the async behavior of X11 (at least GNOME) we have to delay this a little bit. 532 * On Mac OS X and MS Windows this is not necessary and create even wrong resize events. 533 * So there we set the geometry immediately. */ 395 /* Normalize view to the optimal size: */ 534 396 if (machineView()) 535 #ifdef Q_WS_X11536 QTimer::singleShot(0, machineView(), SLOT(sltNormalizeGeometry()));537 #else /* Q_WS_X11 */538 397 machineView()->normalizeGeometry(true); 539 #endif /* !Q_WS_X11 */540 398 } 541 399 … … 543 401 { 544 402 /* USB Stuff: */ 545 const CUSBController &usbController = m achine.GetUSBController();403 const CUSBController &usbController = m.GetUSBController(); 546 404 if ( usbController.isNull() 547 405 || !usbController.GetEnabled() 548 406 || !usbController.GetProxyAvailable()) 549 407 { 550 /* Hide USB Menu: */408 /* Hide USB menu: */ 551 409 indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->setHidden(true); 552 410 } … … 569 427 } 570 428 571 void UIMachineWindowNormal::saveWindowSettings() 572 { 573 CMachine machine = session().GetMachine(); 429 void UIMachineWindowNormal::saveSettings() 430 { 431 /* Get machine: */ 432 CMachine m = machine(); 574 433 575 434 /* Save extra-data settings: */ … … 582 441 QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastNormalWindowPosition) : 583 442 QString("%1%2").arg(VBoxDefs::GUI_LastNormalWindowPosition).arg(m_uScreenId); 584 machine.SetExtraData(strPositionAddress, strWindowPosition); 585 } 586 } 587 588 void UIMachineWindowNormal::cleanupMachineView() 589 { 590 /* Do not cleanup machine view if it is not present: */ 591 if (!machineView()) 592 return; 593 594 UIMachineView::destroy(m_pMachineView); 595 m_pMachineView = 0; 443 m.SetExtraData(strPositionAddress, strWindowPosition); 444 } 445 446 /* Call to base-class: */ 447 UIMachineWindow::saveSettings(); 596 448 } 597 449 … … 601 453 m_pIdleTimer->stop(); 602 454 m_pIdleTimer->disconnect(SIGNAL(timeout()), this, SLOT(sltUpdateIndicators())); 455 456 /* Call to base-class: */ 457 UIMachineWindow::cleanupStatusBar(); 458 } 459 460 void UIMachineWindowNormal::retranslateUi() 461 { 462 /* Call to base-class: */ 463 UIMachineWindow::retranslateUi(); 464 465 /* Translate host-combo LED: */ 466 m_pNameHostkey->setToolTip( 467 QApplication::translate("UIMachineWindowNormal", "Shows the currently assigned Host key.<br>" 468 "This key, when pressed alone, toggles the keyboard and mouse " 469 "capture state. It can also be used in combination with other keys " 470 "to quickly perform actions from the main menu.")); 471 m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo())); 472 } 473 474 bool UIMachineWindowNormal::event(QEvent *pEvent) 475 { 476 switch (pEvent->type()) 477 { 478 case QEvent::Resize: 479 { 480 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); 481 if (!isMaximizedChecked()) 482 { 483 m_normalGeometry.setSize(pResizeEvent->size()); 484 #ifdef VBOX_WITH_DEBUGGER_GUI 485 /* Update debugger window position: */ 486 updateDbgWindows(); 487 #endif /* VBOX_WITH_DEBUGGER_GUI */ 488 } 489 break; 490 } 491 case QEvent::Move: 492 { 493 if (!isMaximizedChecked()) 494 { 495 m_normalGeometry.moveTo(geometry().x(), geometry().y()); 496 #ifdef VBOX_WITH_DEBUGGER_GUI 497 /* Update debugger window position: */ 498 updateDbgWindows(); 499 #endif /* VBOX_WITH_DEBUGGER_GUI */ 500 } 501 break; 502 } 503 default: 504 break; 505 } 506 return UIMachineWindow::event(pEvent); 603 507 } 604 508 … … 608 512 BOOL fEnabled = true; 609 513 ULONG guestOriginX = 0, guestOriginY = 0, guestWidth = 0, guestHeight = 0; 610 session().GetMachine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled);514 machine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled); 611 515 if (fEnabled) 612 516 show(); 517 } 518 519 void UIMachineWindowNormal::updateAppearanceOf(int iElement) 520 { 521 /* Call to base-class: */ 522 UIMachineWindow::updateAppearanceOf(iElement); 523 524 /* Update machine window content: */ 525 if (iElement & UIVisualElement_PauseStuff) 526 { 527 if (!statusBar()->isHidden()) 528 { 529 if (uisession()->isPaused() && m_pIdleTimer->isActive()) 530 m_pIdleTimer->stop(); 531 else if (uisession()->isRunning() && !m_pIdleTimer->isActive()) 532 m_pIdleTimer->start(100); 533 sltUpdateIndicators(); 534 } 535 } 536 if (iElement & UIVisualElement_HDStuff) 537 indicatorsPool()->indicator(UIIndicatorIndex_HardDisks)->updateAppearance(); 538 if (iElement & UIVisualElement_CDStuff) 539 indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks)->updateAppearance(); 540 if (iElement & UIVisualElement_FDStuff) 541 indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks)->updateAppearance(); 542 if (iElement & UIVisualElement_NetworkStuff) 543 indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)->updateAppearance(); 544 if (iElement & UIVisualElement_USBStuff && 545 !indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->isHidden()) 546 indicatorsPool()->indicator(UIIndicatorIndex_USBDevices)->updateAppearance(); 547 if (iElement & UIVisualElement_SharedFolderStuff) 548 indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders)->updateAppearance(); 549 if (iElement & UIVisualElement_VirtualizationStuff) 550 indicatorsPool()->indicator(UIIndicatorIndex_Virtualization)->updateAppearance(); 613 551 } 614 552 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.h
r41107 r41114 20 20 #define __UIMachineWindowNormal_h__ 21 21 22 /* Global includes */22 /* Global includes: */ 23 23 #include <QLabel> 24 24 25 /* Local includes */25 /* Local includes: */ 26 26 #include "UIMachineWindow.h" 27 27 28 /* Local forwards*/28 /* Forward declarations: */ 29 29 class CMediumAttachment; 30 30 class UIIndicatorsPool; 31 31 class QIStateIndicator; 32 32 33 /* Normal machine-window implementation: */ 33 34 class UIMachineWindowNormal : public UIMachineWindow 34 35 { … … 37 38 protected: 38 39 39 /* Normal machine window constructor/destructor: */40 /* Constructor: */ 40 41 UIMachineWindowNormal(UIMachineLogic *pMachineLogic, ulong uScreenId); 41 virtual ~UIMachineWindowNormal();42 42 43 43 private slots: 44 44 45 /* Console callbackhandlers: */45 /* Session event-handlers: */ 46 46 void sltMachineStateChanged(); 47 47 void sltMediumChange(const CMediumAttachment &attachment); … … 59 59 private: 60 60 61 /* Translate routine: */62 void retranslateUi();63 64 /* Update routines: */65 void updateAppearanceOf(int aElement);66 67 /* Event handlers: */68 bool event(QEvent *pEvent);69 70 /* Private getters: */71 UIIndicatorsPool* indicatorsPool() { return m_pIndicatorsPool; }72 73 61 /* Prepare helpers: */ 74 void prepare ConsoleConnections();62 void prepareSessionConnections(); 75 63 void prepareMenu(); 76 64 void prepareStatusBar(); 77 void prepare Connections();78 void prepare MachineView();79 void load WindowSettings();65 void prepareVisualState(); 66 void prepareHandlers(); 67 void loadSettings(); 80 68 81 69 /* Cleanup helpers: */ 82 void save WindowSettings();83 void cleanupMachineView();84 // void cleanupConnections() {}70 void saveSettings(); 71 //void cleanupHandlers() {} 72 //coid cleanupVisualState() {} 85 73 void cleanupStatusBar(); 86 74 //void cleanupMenu() {} 87 75 //void cleanupConsoleConnections() {} 88 76 89 /* Other members: */ 77 /* Translate stuff: */ 78 void retranslateUi(); 79 80 /* Show stuff: */ 90 81 void showInNecessaryMode(); 82 83 /* Update stuff: */ 84 void updateAppearanceOf(int aElement); 85 86 /* Event handler: */ 87 bool event(QEvent *pEvent); 88 89 /* Helpers: */ 90 UIIndicatorsPool* indicatorsPool() { return m_pIndicatorsPool; } 91 91 bool isMaximizedChecked(); 92 92 void updateIndicatorState(QIStateIndicator *pIndicator, KDeviceType deviceType); 93 93 94 /* Indicators pool: */94 /* Widgets: */ 95 95 UIIndicatorsPool *m_pIndicatorsPool; 96 /* Other QWidgets: */97 96 QWidget *m_pCntHostkey; 98 97 QLabel *m_pNameHostkey; 99 /* Other QObjects: */ 98 99 /* Variables: */ 100 100 QTimer *m_pIdleTimer; 101 /* Other members: */102 101 QRect m_normalGeometry; 103 102 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp
r41107 r41114 81 81 /* Create machine window(s): */ 82 82 for (ulong uScreenId = 0; uScreenId < uMonitorCount; ++ uScreenId) 83 addMachineWindow(UIMachineWindow::create(this, visualStateType(),uScreenId));83 addMachineWindow(UIMachineWindow::create(this, uScreenId)); 84 84 /* Order machine window(s): */ 85 85 for (ulong uScreenId = uMonitorCount; uScreenId > 0; -- uScreenId) -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp
r41107 r41114 18 18 */ 19 19 20 /* Global includes */20 /* Global includes: */ 21 21 #include <QDesktopWidget> 22 #include <QMenuBar>23 22 #include <QTimer> 24 23 #include <QContextMenuEvent> 25 26 /* Local includes */ 24 #ifdef Q_WS_MAC 25 # include <QMenuBar> 26 #endif /* Q_WS_MAC */ 27 28 /* Local includes: */ 27 29 #include "VBoxGlobal.h" 28 30 #include "UIMessageCenter.h" 29 31 #include "VBoxUtils.h" 30 31 32 #include "UISession.h" 32 33 #include "UIMachineLogic.h" … … 41 42 , m_pMainMenu(0) 42 43 { 43 /* Set the main window in VBoxGlobal */44 if (uScreenId == 0)45 vboxGlobal().setMainWindow(this);46 47 /* Prepare window icon: */48 prepareWindowIcon();49 50 /* Prepare console connections: */51 prepareConsoleConnections();52 53 /* Prepare menu: */54 prepareMenu();55 56 /* Retranslate normal window finally: */57 retranslateUi();58 59 /* Prepare normal machine view container: */60 prepareMachineViewContainer();61 62 /* Prepare normal machine view: */63 prepareMachineView();64 65 /* Prepare handlers: */66 prepareHandlers();67 68 /* Load normal window settings: */69 loadWindowSettings();70 71 /* Update all the elements: */72 updateAppearanceOf(UIVisualElement_AllStuff);73 74 #ifdef Q_WS_MAC75 /* Install the resize delegate for keeping the aspect ratio. */76 ::darwinInstallResizeDelegate(this);77 /* Beta label? */78 if (vboxGlobal().isBeta())79 {80 QPixmap betaLabel = ::betaLabel(QSize(100, 16));81 ::darwinLabelWindow(this, &betaLabel, true);82 }83 #endif /* Q_WS_MAC */84 85 /* Show scaled window: */86 showInNecessaryMode();87 }88 89 UIMachineWindowScale::~UIMachineWindowScale()90 {91 #ifdef Q_WS_MAC92 /* Uninstall the resize delegate for keeping the aspect ratio. */93 ::darwinUninstallResizeDelegate(this);94 #endif /* Q_WS_MAC */95 96 /* Save normal window settings: */97 saveWindowSettings();98 99 /* Prepare handlers: */100 cleanupHandlers();101 102 /* Cleanup normal machine view: */103 cleanupMachineView();104 44 } 105 45 106 46 void UIMachineWindowScale::sltPopupMainMenu() 107 47 { 108 /* Popup main 48 /* Popup main-menu if present: */ 109 49 if (m_pMainMenu && !m_pMainMenu->isEmpty()) 110 50 { … … 114 54 } 115 55 116 bool UIMachineWindowScale::event(QEvent *pEvent) 117 { 118 switch (pEvent->type()) 119 { 120 case QEvent::Resize: 121 { 122 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); 123 if (!isMaximizedChecked()) 124 { 125 m_normalGeometry.setSize(pResizeEvent->size()); 126 #ifdef VBOX_WITH_DEBUGGER_GUI 127 /* Update debugger window position */ 128 updateDbgWindows(); 129 #endif 130 } 131 break; 132 } 133 case QEvent::Move: 134 { 135 if (!isMaximizedChecked()) 136 { 137 m_normalGeometry.moveTo(geometry().x(), geometry().y()); 138 #ifdef VBOX_WITH_DEBUGGER_GUI 139 /* Update debugger window position */ 140 updateDbgWindows(); 141 #endif 142 } 143 break; 144 } 145 default: 146 break; 147 } 148 return QIWithRetranslateUI2<QMainWindow>::event(pEvent); 149 } 150 151 #ifdef Q_WS_WIN 152 bool UIMachineWindowScale::winEvent(MSG *pMessage, long *pResult) 153 { 154 /* Try to keep aspect ratio during window resize if: 155 * 1. machine view exists and 2. event-type is WM_SIZING and 3. shift key is NOT pressed: */ 156 if (machineView() && pMessage->message == WM_SIZING && !(QApplication::keyboardModifiers() & Qt::ShiftModifier)) 157 { 158 if (double dAspectRatio = machineView()->aspectRatio()) 159 { 160 RECT *pRect = reinterpret_cast<RECT*>(pMessage->lParam); 161 switch (pMessage->wParam) 162 { 163 case WMSZ_LEFT: 164 case WMSZ_RIGHT: 165 { 166 pRect->bottom = pRect->top + (double)(pRect->right - pRect->left) / dAspectRatio; 167 break; 168 } 169 case WMSZ_TOP: 170 case WMSZ_BOTTOM: 171 { 172 pRect->right = pRect->left + (double)(pRect->bottom - pRect->top) * dAspectRatio; 173 break; 174 } 175 case WMSZ_BOTTOMLEFT: 176 case WMSZ_BOTTOMRIGHT: 177 { 178 pRect->bottom = pRect->top + (double)(pRect->right - pRect->left) / dAspectRatio; 179 break; 180 } 181 case WMSZ_TOPLEFT: 182 case WMSZ_TOPRIGHT: 183 { 184 pRect->top = pRect->bottom - (double)(pRect->right - pRect->left) / dAspectRatio; 185 break; 186 } 187 default: 188 break; 189 } 190 } 191 } 192 /* Pass event to base-class: */ 193 return QMainWindow::winEvent(pMessage, pResult); 194 } 195 #endif /* Q_WS_WIN */ 196 197 void UIMachineWindowScale::prepareMenu() 198 { 199 #ifdef Q_WS_MAC 200 setMenuBar(uisession()->newMenuBar()); 201 #endif /* Q_WS_MAC */ 202 m_pMainMenu = uisession()->newMenu(); 203 } 204 205 void UIMachineWindowScale::prepareMachineViewContainer() 206 { 207 /* Call to base-class: */ 208 UIMachineWindow::prepareMachineViewContainer(); 56 void UIMachineWindowScale::prepareMainLayout() 57 { 58 /* Call to base-class: */ 59 UIMachineWindow::prepareMainLayout(); 209 60 210 61 /* Strict spacers to hide them, they are not necessary for scale-mode: */ … … 215 66 } 216 67 217 void UIMachineWindowScale::prepareMachineView() 218 { 219 #ifdef VBOX_WITH_VIDEOHWACCEL 220 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */ 221 bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable(); 222 #endif 223 224 /* Set central widget: */ 225 setCentralWidget(new QWidget); 226 227 /* Set central widget layout: */ 228 centralWidget()->setLayout(m_pMachineViewContainer); 229 230 m_pMachineView = UIMachineView::create( this 231 , m_uScreenId 232 , machineLogic()->visualStateType() 233 #ifdef VBOX_WITH_VIDEOHWACCEL 234 , bAccelerate2DVideo 235 #endif 236 ); 237 238 /* Add machine view into layout: */ 239 m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1); 240 } 241 242 void UIMachineWindowScale::loadWindowSettings() 243 { 68 void UIMachineWindowScale::prepareMenu() 69 { 70 /* Call to base-class: */ 71 UIMachineWindow::prepareMenu(); 72 73 #ifdef Q_WS_MAC 74 setMenuBar(uisession()->newMenuBar()); 75 #endif /* Q_WS_MAC */ 76 m_pMainMenu = uisession()->newMenu(); 77 } 78 79 #ifdef Q_WS_MAC 80 void UIMachineWindowScale::prepareVisualState() 81 { 82 /* Call to base-class: */ 83 UIMachineWindow::prepareVisualState(); 84 85 /* Install the resize delegate for keeping the aspect ratio. */ 86 ::darwinInstallResizeDelegate(this); 87 /* Beta label? */ 88 if (vboxGlobal().isBeta()) 89 { 90 QPixmap betaLabel = ::betaLabel(QSize(100, 16)); 91 ::darwinLabelWindow(this, &betaLabel, true); 92 } 93 } 94 #endif /* Q_WS_MAC */ 95 96 void UIMachineWindowScale::loadSettings() 97 { 98 /* Call to base-class: */ 99 UIMachineWindow::loadSettings(); 100 244 101 /* Load scale window settings: */ 245 CMachine m achine = session().GetMachine();102 CMachine m = machine(); 246 103 247 104 /* Load extra-data settings: */ … … 249 106 QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastScaleWindowPosition) : 250 107 QString("%1%2").arg(VBoxDefs::GUI_LastScaleWindowPosition).arg(m_uScreenId); 251 QStringList strPositionSettings = m achine.GetExtraDataStringList(strPositionAddress);108 QStringList strPositionSettings = m.GetExtraDataStringList(strPositionAddress); 252 109 253 110 bool ok = !strPositionSettings.isEmpty(), max = false; … … 295 152 } 296 153 297 void UIMachineWindowScale::saveWindowSettings() 298 { 299 CMachine machine = session().GetMachine(); 154 void UIMachineWindowScale::saveSettings() 155 { 156 /* Get machine: */ 157 CMachine m = machine(); 300 158 301 159 /* Save extra-data settings: */ … … 308 166 QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastScaleWindowPosition) : 309 167 QString("%1%2").arg(VBoxDefs::GUI_LastScaleWindowPosition).arg(m_uScreenId); 310 machine.SetExtraData(strPositionAddress, strWindowPosition); 311 } 312 } 313 314 void UIMachineWindowScale::cleanupMachineView() 315 { 316 /* Do not cleanup machine view if it is not present: */ 317 if (!machineView()) 318 return; 319 320 UIMachineView::destroy(m_pMachineView); 321 m_pMachineView = 0; 322 } 168 m.SetExtraData(strPositionAddress, strWindowPosition); 169 } 170 171 /* Call to base-class: */ 172 UIMachineWindow::saveSettings(); 173 } 174 175 #ifdef Q_WS_MAC 176 void UIMachineWindowScale::cleanupVisualState() 177 { 178 /* Uninstall the resize delegate for keeping the aspect ratio. */ 179 ::darwinUninstallResizeDelegate(this); 180 181 /* Call to base-class: */ 182 UIMachineWindow::cleanupVisualState(); 183 } 184 #endif /* Q_WS_MAC */ 323 185 324 186 void UIMachineWindowScale::cleanupMenu() 325 187 { 188 /* Cleanup menu: */ 326 189 delete m_pMainMenu; 327 190 m_pMainMenu = 0; 191 192 /* Call to base-class: */ 193 UIMachineWindow::cleanupMenu(); 328 194 } 329 195 … … 333 199 BOOL fEnabled = true; 334 200 ULONG guestOriginX = 0, guestOriginY = 0, guestWidth = 0, guestHeight = 0; 335 session().GetMachine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled);201 machine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled); 336 202 if (fEnabled) 337 203 show(); 338 204 } 205 206 bool UIMachineWindowScale::event(QEvent *pEvent) 207 { 208 switch (pEvent->type()) 209 { 210 case QEvent::Resize: 211 { 212 QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); 213 if (!isMaximizedChecked()) 214 { 215 m_normalGeometry.setSize(pResizeEvent->size()); 216 #ifdef VBOX_WITH_DEBUGGER_GUI 217 /* Update debugger window position: */ 218 updateDbgWindows(); 219 #endif /* VBOX_WITH_DEBUGGER_GUI */ 220 } 221 break; 222 } 223 case QEvent::Move: 224 { 225 if (!isMaximizedChecked()) 226 { 227 m_normalGeometry.moveTo(geometry().x(), geometry().y()); 228 #ifdef VBOX_WITH_DEBUGGER_GUI 229 /* Update debugger window position: */ 230 updateDbgWindows(); 231 #endif /* VBOX_WITH_DEBUGGER_GUI */ 232 } 233 break; 234 } 235 default: 236 break; 237 } 238 return UIMachineWindow::event(pEvent); 239 } 240 241 #ifdef Q_WS_WIN 242 bool UIMachineWindowScale::winEvent(MSG *pMessage, long *pResult) 243 { 244 /* Try to keep aspect ratio during window resize if: 245 * 1. machine view exists and 2. event-type is WM_SIZING and 3. shift key is NOT pressed: */ 246 if (machineView() && pMessage->message == WM_SIZING && !(QApplication::keyboardModifiers() & Qt::ShiftModifier)) 247 { 248 if (double dAspectRatio = machineView()->aspectRatio()) 249 { 250 RECT *pRect = reinterpret_cast<RECT*>(pMessage->lParam); 251 switch (pMessage->wParam) 252 { 253 case WMSZ_LEFT: 254 case WMSZ_RIGHT: 255 { 256 pRect->bottom = pRect->top + (double)(pRect->right - pRect->left) / dAspectRatio; 257 break; 258 } 259 case WMSZ_TOP: 260 case WMSZ_BOTTOM: 261 { 262 pRect->right = pRect->left + (double)(pRect->bottom - pRect->top) * dAspectRatio; 263 break; 264 } 265 case WMSZ_BOTTOMLEFT: 266 case WMSZ_BOTTOMRIGHT: 267 { 268 pRect->bottom = pRect->top + (double)(pRect->right - pRect->left) / dAspectRatio; 269 break; 270 } 271 case WMSZ_TOPLEFT: 272 case WMSZ_TOPRIGHT: 273 { 274 pRect->top = pRect->bottom - (double)(pRect->right - pRect->left) / dAspectRatio; 275 break; 276 } 277 default: 278 break; 279 } 280 } 281 } 282 /* Call to base-class: */ 283 return UIMachineWindow::winEvent(pMessage, pResult); 284 } 285 #endif /* Q_WS_WIN */ 339 286 340 287 bool UIMachineWindowScale::isMaximizedChecked() -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.h
r41107 r41114 20 20 #define __UIMachineWindowScale_h__ 21 21 22 /* Local includes */22 /* Local includes: */ 23 23 #include "UIMachineWindow.h" 24 24 25 /* Scale machine-window implementation: */ 25 26 class UIMachineWindowScale : public UIMachineWindow 26 27 { … … 29 30 protected: 30 31 31 /* Scale machine window constructor/destructor: */32 /* Constructor: */ 32 33 UIMachineWindowScale(UIMachineLogic *pMachineLogic, ulong uScreenId); 33 virtual ~UIMachineWindowScale();34 34 35 35 private slots: 36 36 37 /* Popup main 37 /* Popup main-menu: */ 38 38 void sltPopupMainMenu(); 39 39 40 40 private: 41 42 /* Prepare helpers: */ 43 void prepareMainLayout(); 44 void prepareMenu(); 45 #ifdef Q_WS_MAC 46 void prepareVisualState(); 47 #endif /* Q_WS_MAC */ 48 void loadSettings(); 49 50 /* Cleanup helpers: */ 51 void saveSettings(); 52 #ifdef Q_WS_MAC 53 void cleanupVisualState(); 54 #endif /* Q_WS_MAC */ 55 void cleanupMenu(); 56 //void cleanupMainLayout() {} 57 58 /* Show stuff: */ 59 void showInNecessaryMode(); 41 60 42 61 /* Event handlers: */ … … 44 63 #ifdef Q_WS_WIN 45 64 bool winEvent(MSG *pMessage, long *pResult); 46 #endif 65 #endif /* Q_WS_WIN */ 47 66 48 /* Prepare helpers: */ 49 void prepareMenu(); 50 void prepareMachineViewContainer(); 51 void prepareMachineView(); 52 void loadWindowSettings(); 53 54 /* Cleanup helpers: */ 55 void saveWindowSettings(); 56 void cleanupMachineView(); 57 //void cleanupMachineViewContainer() {} 58 void cleanupMenu(); 59 60 /* Other members: */ 61 void showInNecessaryMode(); 67 /* Helpers: */ 62 68 bool isMaximizedChecked(); 63 69 64 /* Other members: */70 /* Widgets: */ 65 71 QMenu *m_pMainMenu; 72 73 /* Variables: */ 66 74 QRect m_normalGeometry; 67 75 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp
r41064 r41114 130 130 /* Create machine window(s): */ 131 131 for (int cScreenId = 0; cScreenId < m_pScreenLayout->guestScreenCount(); ++cScreenId) 132 addMachineWindow(UIMachineWindow::create(this, visualStateType(),cScreenId));132 addMachineWindow(UIMachineWindow::create(this, cScreenId)); 133 133 134 134 /* Connect screen-layout change handler: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineWindowSeamless.cpp
r41107 r41114 18 18 */ 19 19 20 /* Global includes */20 /* Global includes: */ 21 21 #include <QDesktopWidget> 22 22 #include <QTimer> … … 25 25 #endif /* Q_WS_MAC */ 26 26 27 /* Local includes */27 /* Local includes: */ 28 28 #include "VBoxGlobal.h" 29 29 #ifndef Q_WS_MAC 30 30 # include "VBoxMiniToolBar.h" 31 #endif /* Q_WS_MAC */ 32 31 #endif /* !Q_WS_MAC */ 33 32 #include "UISession.h" 34 33 #include "UIActionPoolRuntime.h" … … 36 35 #include "UIMachineWindowSeamless.h" 37 36 #include "UIMachineViewSeamless.h" 38 39 37 #ifdef Q_WS_MAC 40 38 # include "VBoxUtils.h" … … 46 44 #ifndef Q_WS_MAC 47 45 , m_pMiniToolBar(0) 48 #endif /* Q_WS_MAC */ 49 { 50 /* Set the main window in VBoxGlobal: */ 51 if (uScreenId == 0) 52 vboxGlobal().setMainWindow(this); 53 54 /* Prepare seamless window icon: */ 55 prepareWindowIcon(); 56 57 /* Prepare console connections: */ 58 prepareConsoleConnections(); 59 60 /* Prepare seamless window: */ 61 prepareSeamless(); 62 63 /* Prepare seamless menu: */ 64 prepareMenu(); 65 66 /* Prepare machine view container: */ 67 prepareMachineViewContainer(); 68 69 /* Prepare seamless machine view: */ 70 prepareMachineView(); 71 72 /* Prepare handlers: */ 73 prepareHandlers(); 74 75 #ifndef Q_WS_MAC 76 /* Prepare mini tool-bar: */ 77 prepareMiniToolBar(); 78 #endif /* Q_WS_MAC */ 79 80 /* Retranslate fullscreen window finally: */ 81 retranslateUi(); 82 83 #ifdef Q_WS_MAC 84 /* Load seamless window settings: */ 85 loadWindowSettings(); 86 #endif /* Q_WS_MAC */ 87 88 /* Update all the elements: */ 89 updateAppearanceOf(UIVisualElement_AllStuff); 90 91 /* Show seamless window: */ 92 showInNecessaryMode(); 93 } 94 95 UIMachineWindowSeamless::~UIMachineWindowSeamless() 96 { 97 /* Save window settings: */ 98 saveWindowSettings(); 99 100 #ifndef Q_WS_MAC 101 /* Cleanup mini tool-bar: */ 102 cleanupMiniToolBar(); 103 #endif /* Q_WS_MAC */ 104 105 /* Prepare handlers: */ 106 cleanupHandlers(); 107 108 /* Cleanup machine view: */ 109 cleanupMachineView(); 110 111 /* Cleanup menu: */ 112 cleanupMenu(); 113 } 46 #endif /* !Q_WS_MAC */ 47 { 48 } 49 50 #ifndef Q_WS_MAC 51 void UIMachineWindowSeamless::sltMachineStateChanged() 52 { 53 /* Call to base-class: */ 54 UIMachineWindow::sltMachineStateChanged(); 55 56 /* Update mini-toolbar: */ 57 updateAppearanceOf(UIVisualElement_MiniToolBar); 58 } 59 #endif /* !Q_WS_MAC */ 114 60 115 61 void UIMachineWindowSeamless::sltPlaceOnScreen() 116 62 { 117 63 /* Get corresponding screen: */ 118 int iScreen = static_cast<UIMachineLogicSeamless*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId);64 int iScreen = qobject_cast<UIMachineLogicSeamless*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId); 119 65 /* Calculate working area: */ 120 66 QRect workingArea = vboxGlobal().availableGeometry(iScreen); … … 129 75 void UIMachineWindowSeamless::sltPopupMainMenu() 130 76 { 131 /* Popup main 77 /* Popup main-menu if present: */ 132 78 if (m_pMainMenu && !m_pMainMenu->isEmpty()) 133 79 { … … 140 86 void UIMachineWindowSeamless::sltUpdateMiniToolBarMask() 141 87 { 142 if (m_pMiniToolBar )88 if (m_pMiniToolBar && machineView()) 143 89 setMask(qobject_cast<UIMachineViewSeamless*>(machineView())->lastVisibleRegion()); 144 90 } 145 #endif /* Q_WS_MAC */ 91 #endif /* !Q_WS_MAC */ 92 93 void UIMachineWindowSeamless::prepareMenu() 94 { 95 /* Call to base-class: */ 96 UIMachineWindow::prepareMenu(); 97 98 /* Prepare menu: */ 99 #ifdef Q_WS_MAC 100 setMenuBar(uisession()->newMenuBar()); 101 #endif /* Q_WS_MAC */ 102 m_pMainMenu = uisession()->newMenu(); 103 } 104 105 void UIMachineWindowSeamless::prepareVisualState() 106 { 107 /* Call to base-class: */ 108 UIMachineWindow::prepareVisualState(); 109 110 /* This might be required to correctly mask: */ 111 centralWidget()->setAutoFillBackground(false); 112 113 #ifdef Q_WS_WIN 114 /* Get corresponding screen: */ 115 int iScreen = qobject_cast<UIMachineLogicSeamless*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId); 116 /* Prepare previous region: */ 117 m_prevRegion = vboxGlobal().availableGeometry(iScreen); 118 #endif /* Q_WS_WIN */ 119 120 #ifdef Q_WS_MAC 121 /* Please note: All the stuff below has to be done after the window has 122 * switched to fullscreen. Qt changes the winId on the fullscreen 123 * switch and make this stuff useless with the old winId. So please be 124 * careful on rearrangement of the method calls. */ 125 ::darwinSetShowsWindowTransparent(this, true); 126 #endif /* Q_WS_MAC */ 127 128 #ifndef Q_WS_MAC 129 /* Prepare mini-toolbar: */ 130 prepareMiniToolbar(); 131 #endif /* !Q_WS_MAC */ 132 } 133 134 #ifndef Q_WS_MAC 135 void UIMachineWindowSeamless::prepareMiniToolbar() 136 { 137 /* Get machine: */ 138 CMachine m = machine(); 139 140 /* Make sure mini-toolbar is necessary: */ 141 bool fIsActive = m.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no"; 142 if (!fIsActive) 143 return; 144 145 /* Get the mini-toolbar alignment: */ 146 bool fIsAtTop = m.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top"; 147 /* Get the mini-toolbar auto-hide feature availability: */ 148 bool fIsAutoHide = m.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off"; 149 m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(), 150 fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom, 151 true, fIsAutoHide); 152 m_pMiniToolBar->setSeamlessMode(true); 153 m_pMiniToolBar->updateDisplay(true, true); 154 QList<QMenu*> menus; 155 QList<QAction*> actions = uisession()->newMenu()->actions(); 156 for (int i=0; i < actions.size(); ++i) 157 menus << actions.at(i)->menu(); 158 *m_pMiniToolBar << menus; 159 connect(m_pMiniToolBar, SIGNAL(minimizeAction()), this, SLOT(showMinimized())); 160 connect(m_pMiniToolBar, SIGNAL(exitAction()), 161 gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SLOT(trigger())); 162 connect(m_pMiniToolBar, SIGNAL(closeAction()), 163 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger())); 164 connect(m_pMiniToolBar, SIGNAL(geometryUpdated()), this, SLOT(sltUpdateMiniToolBarMask())); 165 } 166 #endif /* !Q_WS_MAC */ 167 168 #ifdef Q_WS_MAC 169 void UIMachineWindowSeamless::loadSettings() 170 { 171 /* Call to base-class: */ 172 UIMachineWindow::loadSettings(); 173 174 /* Load global settings: */ 175 { 176 VBoxGlobalSettings settings = vboxGlobal().settings(); 177 menuBar()->setHidden(settings.isFeatureActive("noMenuBar")); 178 } 179 } 180 #endif /* Q_WS_MAC */ 181 182 #ifndef Q_WS_MAC 183 void UIMachineWindowSeamless::cleanupMiniToolbar() 184 { 185 /* Make sure mini-toolbar was created: */ 186 if (!m_pMiniToolBar) 187 return; 188 189 /* Save mini-toolbar settings: */ 190 machine().SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off"); 191 /* Delete mini-toolbar: */ 192 delete m_pMiniToolBar; 193 m_pMiniToolBar = 0; 194 } 195 #endif /* !Q_WS_MAC */ 196 197 void UIMachineWindowSeamless::cleanupVisualState() 198 { 199 #ifndef Q_WS_MAC 200 /* Cleeanup mini-toolbar: */ 201 cleanupMiniToolbar(); 202 #endif /* !Q_WS_MAC */ 203 204 /* Call to base-class: */ 205 UIMachineWindow::cleanupVisualState(); 206 } 207 208 void UIMachineWindowSeamless::cleanupMenu() 209 { 210 /* Cleanup menu: */ 211 delete m_pMainMenu; 212 m_pMainMenu = 0; 213 214 /* Call to base-class: */ 215 UIMachineWindow::cleanupMenu(); 216 } 217 218 void UIMachineWindowSeamless::showInNecessaryMode() 219 { 220 /* Make sure we really have to show window: */ 221 BOOL fEnabled = true; 222 ULONG guestOriginX = 0, guestOriginY = 0, guestWidth = 0, guestHeight = 0; 223 machine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled); 224 if (fEnabled) 225 { 226 /* Show manually maximized window: */ 227 sltPlaceOnScreen(); 228 229 /* Show normal window: */ 230 show(); 231 232 #ifdef Q_WS_MAC 233 /* Make sure it is really on the right place (especially on the Mac): */ 234 int iScreen = qobject_cast<UIMachineLogicSeamless*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId); 235 QRect r = vboxGlobal().availableGeometry(iScreen); 236 move(r.topLeft()); 237 #endif /* Q_WS_MAC */ 238 } 239 } 240 241 #ifndef Q_WS_MAC 242 void UIMachineWindowSeamless::updateAppearanceOf(int iElement) 243 { 244 /* Call to base-class: */ 245 UIMachineWindow::updateAppearanceOf(iElement); 246 247 /* Update mini-toolbar: */ 248 if (iElement & UIVisualElement_MiniToolBar) 249 { 250 if (m_pMiniToolBar) 251 { 252 /* Get machine: */ 253 const CMachine &m = machine(); 254 /* Get snapshot(s): */ 255 QString strSnapshotName; 256 if (m.GetSnapshotCount() > 0) 257 { 258 CSnapshot snapshot = m.GetCurrentSnapshot(); 259 strSnapshotName = " (" + snapshot.GetName() + ")"; 260 } 261 /* Update mini-toolbar text: */ 262 m_pMiniToolBar->setDisplayText(m.GetName() + strSnapshotName); 263 } 264 } 265 } 266 #endif /* !Q_WS_MAC */ 146 267 147 268 #ifdef Q_WS_MAC … … 159 280 break; 160 281 } 161 return QMainWindow::event(pEvent); 162 } 163 #endif /* Q_WS_MAC */ 164 165 void UIMachineWindowSeamless::prepareSeamless() 166 { 167 #ifdef Q_WS_WIN 168 /* Get corresponding screen: */ 169 int iScreen = static_cast<UIMachineLogicSeamless*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId); 170 /* Prepare previous region: */ 171 m_prevRegion = vboxGlobal().availableGeometry(iScreen); 172 #endif 173 174 #ifdef Q_WS_MAC 175 /* Please note: All the stuff below has to be done after the window has 176 * switched to fullscreen. Qt changes the winId on the fullscreen 177 * switch and make this stuff useless with the old winId. So please be 178 * careful on rearrangement of the method calls. */ 179 ::darwinSetShowsWindowTransparent(this, true); 180 #endif 181 } 182 183 void UIMachineWindowSeamless::prepareMenu() 184 { 185 #ifdef Q_WS_MAC 186 setMenuBar(uisession()->newMenuBar()); 187 #endif /* Q_WS_MAC */ 188 m_pMainMenu = uisession()->newMenu(); 189 } 190 191 #ifndef Q_WS_MAC 192 void UIMachineWindowSeamless::prepareMiniToolBar() 193 { 194 /* Get current machine: */ 195 CMachine machine = session().GetConsole().GetMachine(); 196 /* Check if mini tool-bar should present: */ 197 bool fIsActive = machine.GetExtraData(VBoxDefs::GUI_ShowMiniToolBar) != "no"; 198 if (fIsActive) 199 { 200 /* Get the mini tool-bar alignment: */ 201 bool fIsAtTop = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAlignment) == "top"; 202 /* Get the mini tool-bar auto-hide feature availability: */ 203 bool fIsAutoHide = machine.GetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide) != "off"; 204 m_pMiniToolBar = new VBoxMiniToolBar(centralWidget(), 205 fIsAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom, 206 true, fIsAutoHide); 207 m_pMiniToolBar->setSeamlessMode(true); 208 m_pMiniToolBar->updateDisplay(true, true); 209 QList<QMenu*> menus; 210 QList<QAction*> actions = uisession()->newMenu()->actions(); 211 for (int i=0; i < actions.size(); ++i) 212 menus << actions.at(i)->menu(); 213 *m_pMiniToolBar << menus; 214 connect(m_pMiniToolBar, SIGNAL(minimizeAction()), this, SLOT(showMinimized())); 215 connect(m_pMiniToolBar, SIGNAL(exitAction()), 216 gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SLOT(trigger())); 217 connect(m_pMiniToolBar, SIGNAL(closeAction()), 218 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger())); 219 connect(m_pMiniToolBar, SIGNAL(geometryUpdated()), this, SLOT(sltUpdateMiniToolBarMask())); 220 } 221 } 222 #endif /* Q_WS_MAC */ 223 224 void UIMachineWindowSeamless::prepareMachineView() 225 { 226 #ifdef VBOX_WITH_VIDEOHWACCEL 227 /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */ 228 bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable(); 229 #endif 230 231 /* Set central widget: */ 232 setCentralWidget(new QWidget); 233 234 /* Set central widget layout: */ 235 centralWidget()->setLayout(m_pMachineViewContainer); 236 237 m_pMachineView = UIMachineView::create( this 238 , m_uScreenId 239 , machineLogic()->visualStateType() 240 #ifdef VBOX_WITH_VIDEOHWACCEL 241 , bAccelerate2DVideo 242 #endif 243 ); 244 245 /* Add machine view into layout: */ 246 m_pMachineViewContainer->addWidget(m_pMachineView, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter); 247 248 /* This might be required to correctly mask: */ 249 centralWidget()->setAutoFillBackground(false); 250 } 251 252 #ifdef Q_WS_MAC 253 void UIMachineWindowSeamless::loadWindowSettings() 254 { 255 /* Load global settings: */ 256 { 257 VBoxGlobalSettings settings = vboxGlobal().settings(); 258 menuBar()->setHidden(settings.isFeatureActive("noMenuBar")); 259 } 260 } 261 #endif 262 263 void UIMachineWindowSeamless::saveWindowSettings() 264 { 265 #ifndef Q_WS_MAC 266 /* Get machine: */ 267 CMachine machine = session().GetConsole().GetMachine(); 268 269 /* Save extra-data settings: */ 270 { 271 /* Save mini tool-bar settings: */ 272 if (m_pMiniToolBar) 273 machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, m_pMiniToolBar->isAutoHide() ? QString() : "off"); 274 } 275 #endif /* Q_WS_MAC */ 276 } 277 278 void UIMachineWindowSeamless::cleanupMachineView() 279 { 280 /* Do not cleanup machine view if it is not present: */ 281 if (!machineView()) 282 return; 283 284 UIMachineView::destroy(m_pMachineView); 285 m_pMachineView = 0; 286 } 287 288 #ifndef Q_WS_MAC 289 void UIMachineWindowSeamless::cleanupMiniToolBar() 290 { 291 if (m_pMiniToolBar) 292 { 293 delete m_pMiniToolBar; 294 m_pMiniToolBar = 0; 295 } 296 } 297 #endif /* Q_WS_MAC */ 298 299 void UIMachineWindowSeamless::cleanupMenu() 300 { 301 delete m_pMainMenu; 302 m_pMainMenu = 0; 303 } 304 305 void UIMachineWindowSeamless::updateAppearanceOf(int iElement) 306 { 307 /* Base class update: */ 308 UIMachineWindow::updateAppearanceOf(iElement); 309 310 /* If mini tool-bar is present: */ 311 #ifndef Q_WS_MAC 312 if (m_pMiniToolBar) 313 { 314 /* Get machine: */ 315 CMachine machine = session().GetConsole().GetMachine(); 316 /* Get snapshot(s): */ 317 QString strSnapshotName; 318 if (machine.GetSnapshotCount() > 0) 319 { 320 CSnapshot snapshot = machine.GetCurrentSnapshot(); 321 strSnapshotName = " (" + snapshot.GetName() + ")"; 322 } 323 /* Update mini tool-bar text: */ 324 m_pMiniToolBar->setDisplayText(machine.GetName() + strSnapshotName); 325 } 326 #endif /* Q_WS_MAC */ 327 } 328 329 void UIMachineWindowSeamless::showInNecessaryMode() 330 { 331 /* Make sure we really have to show window: */ 332 BOOL fEnabled = true; 333 ULONG guestOriginX = 0, guestOriginY = 0, guestWidth = 0, guestHeight = 0; 334 session().GetMachine().QuerySavedGuestScreenInfo(m_uScreenId, guestOriginX, guestOriginY, guestWidth, guestHeight, fEnabled); 335 if (fEnabled) 336 { 337 /* Show manually maximized window: */ 338 sltPlaceOnScreen(); 339 340 /* Show normal window: */ 341 show(); 342 343 #ifdef Q_WS_MAC 344 /* Make sure it is really on the right place (especially on the Mac): */ 345 int iScreen = static_cast<UIMachineLogicSeamless*>(machineLogic())->hostScreenForGuestScreen(m_uScreenId); 346 QRect r = vboxGlobal().availableGeometry(iScreen); 347 move(r.topLeft()); 348 #endif /* Q_WS_MAC */ 349 } 350 } 282 return UIMachineWindow::event(pEvent); 283 } 284 #endif /* Q_WS_MAC */ 351 285 352 286 void UIMachineWindowSeamless::setMask(const QRegion &constRegion) … … 373 307 toolBarRegion.translate(QPoint(m_pMiniToolBar->x(), m_pMiniToolBar->y())); 374 308 375 /* Including mini tool-bar mask: */309 /* Including mini-toolbar mask: */ 376 310 region += toolBarRegion; 377 311 } 378 #endif /* Q_WS_MAC */312 #endif /* !Q_WS_MAC */ 379 313 380 314 #if 0 // TODO: Is it really needed now? … … 405 339 SetWindowRgn(winId(), newReg, FALSE); 406 340 RedrawWindow(0, 0, diffReg, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); 407 RedrawWindow(machineView()->viewport()->winId(), 0, 0, RDW_INVALIDATE); 341 if (machineView()) 342 RedrawWindow(machineView()->viewport()->winId(), 0, 0, RDW_INVALIDATE); 408 343 409 344 m_prevRegion = region; … … 436 371 // /* Now force the reshaping of the window. This is definitely necessary. */ 437 372 // ReshapeCustomWindow (reinterpret_cast <WindowPtr> (winId())); 438 QMainWindow::setMask(region);373 UIMachineWindow::setMask(region); 439 374 // HIWindowInvalidateShadow (::darwinToWindowRef (mConsole->viewport())); 440 375 } 441 376 #else 442 QMainWindow::setMask(region);377 UIMachineWindow::setMask(region); 443 378 #endif 444 379 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineWindowSeamless.h
r41107 r41114 20 20 #define __UIMachineWindowSeamless_h__ 21 21 22 /* Local includes */22 /* Local includes: */ 23 23 #include "UIMachineWindow.h" 24 24 25 /* Local forwards*/25 /* Forward declarations: */ 26 26 class VBoxMiniToolBar; 27 27 28 /* Seamless machine-window implementation: */ 28 29 class UIMachineWindowSeamless : public UIMachineWindow 29 30 { 30 31 Q_OBJECT; 31 32 32 public slots:33 34 void sltPlaceOnScreen();35 36 33 protected: 37 34 38 /* Seamless machine window constructor/destructor: */35 /* Constructor: */ 39 36 UIMachineWindowSeamless(UIMachineLogic *pMachineLogic, ulong uScreenId); 40 virtual ~UIMachineWindowSeamless();41 37 42 38 private slots: 39 40 #ifndef Q_WS_MAC 41 /* Session event-handlers: */ 42 void sltMachineStateChanged(); 43 #endif /* !Q_WS_MAC */ 44 45 /* Places window on screen: */ 46 void sltPlaceOnScreen(); 43 47 44 48 /* Popup main menu: */ 45 49 void sltPopupMainMenu(); 46 50 47 #ifndef RT_OS_DARWIN /* Something is *really* broken in regards of the moc here */51 #ifndef Q_WS_MAC 48 52 /* Update mini tool-bar mask: */ 49 53 void sltUpdateMiniToolBarMask(); 50 #endif /* RT_OS_DARWIN*/54 #endif /* !Q_WS_MAC */ 51 55 52 56 private: 53 57 58 /* Prepare helpers: */ 59 void prepareMenu(); 60 void prepareVisualState(); 61 #ifndef Q_WS_MAC 62 void prepareMiniToolbar(); 63 #endif /* !Q_WS_MAC */ 64 #ifdef Q_WS_MAC 65 void loadSettings(); 66 #endif /* Q_WS_MAC */ 67 68 /* Cleanup helpers: */ 69 #ifdef Q_WS_MAC 70 //void saveSettings() {} 71 #endif /* Q_WS_MAC */ 72 #ifndef Q_WS_MAC 73 void cleanupMiniToolbar(); 74 #endif /* !Q_WS_MAC */ 75 void cleanupVisualState(); 76 void cleanupMenu(); 77 78 /* Show stuff: */ 79 void showInNecessaryMode(); 80 81 #ifndef Q_WS_MAC 82 /* Update routines: */ 83 void updateAppearanceOf(int iElement); 84 #endif /* !Q_WS_MAC */ 85 86 #ifdef Q_WS_MAC 54 87 /* Event handlers: */ 55 #ifdef Q_WS_MAC56 88 bool event(QEvent *pEvent); 57 89 #endif /* Q_WS_MAC */ 58 90 59 /* Prepare helpers: */ 60 void prepareSeamless(); 61 void prepareMenu(); 62 #ifndef Q_WS_MAC 63 void prepareMiniToolBar(); 64 #endif /* Q_WS_MAC */ 65 void prepareMachineView(); 66 #ifdef Q_WS_MAC 67 void loadWindowSettings(); 68 #endif /* Q_WS_MAC */ 69 70 /* Cleanup helpers: */ 71 void saveWindowSettings(); 72 void cleanupMachineView(); 73 #ifndef Q_WS_MAC 74 void cleanupMiniToolBar(); 75 #endif /* Q_WS_MAC */ 76 void cleanupMenu(); 77 //void cleanupSeamless() {} 78 79 /* Update routines: */ 80 void updateAppearanceOf(int iElement); 81 82 /* Other members: */ 83 void showInNecessaryMode(); 91 /* Helpers: */ 84 92 void setMask(const QRegion ®ion); 85 93 86 /* Private variables: */94 /* Widgets: */ 87 95 QMenu *m_pMainMenu; 88 96 #ifndef Q_WS_MAC 89 97 VBoxMiniToolBar *m_pMiniToolBar; 90 #endif /* Q_WS_MAC */ 98 #endif /* !Q_WS_MAC */ 99 100 /* Variables: */ 91 101 #ifdef Q_WS_WIN 92 102 QRegion m_prevRegion;
Note:
See TracChangeset
for help on using the changeset viewer.