QSize UIMachineViewScale::calculateMaxGuestSize() const { /* 1) The calculation below is not reliable on some (X11) platforms until we * have been visible for a fraction of a second, so so the best we can * otherwise. * 2) We also get called early before "machineWindow" has been fully * initialised, at which time we can't perform the calculation. */ if (!isVisible()) return workingArea().size() * 0.95; /* The area taken up by the machine window on the desktop, including window * frame, title, menu bar and status bar. */ QSize windowSize = machineWindow()->frameGeometry().size(); /* The window shouldn't be allowed to expand beyond the working area * unless it already does. In that case the guest shouldn't expand it * any further though. */ QSize maximumSize = workingArea().size().expandedTo(windowSize); /* The current size of the machine display. */ QSize centralWidgetSize = machineWindow()->centralWidget()->size(); /* To work out how big the guest display can get without the window going * over the maximum size we calculated above, we work out how much space * the other parts of the window (frame, menu bar, status bar and so on) * take up and subtract that space from the maximum window size. The * central widget shouldn't be bigger than the window, but we bound it for * sanity (or insanity) reasons. */ return maximumSize - (windowSize - centralWidgetSize.boundedTo(windowSize)); }
bool UIMachineViewNormal::eventFilter(QObject *pWatched, QEvent *pEvent) { if (pWatched != 0 && pWatched == machineWindow()) { switch (pEvent->type()) { case QEvent::Resize: { /* We call this on every resize as: * * Window frame geometry can change on resize. * * On X11 we set information here which becomes available * asynchronously at an unknown time after window * creation. As long as the information is not available * we make a best guess. */ setMaxGuestSize(); if (pEvent->spontaneous() && m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics()) QTimer::singleShot(300, this, SLOT(sltPerformGuestResize())); break; } #if defined (Q_WS_WIN32) # if defined (VBOX_GUI_USE_DDRAW) case QEvent::Move: { /* Notification from our parent that it has moved. We need this in order * to possibly adjust the direct screen blitting: */ if (frameBuffer()) frameBuffer()->moveEvent(static_cast<QMoveEvent*>(pEvent)); break; } # endif /* defined (VBOX_GUI_USE_DDRAW) */ #endif /* defined (Q_WS_WIN32) */ default: break; } } #ifdef Q_WS_WIN else if (pWatched != 0 && pWatched == machineWindow()->menuBar()) { /* Due to windows host uses separate 'focus set' to let menubar to * operate while popped up (see UIMachineViewNormal::event() for details), * it also requires backward processing: */ switch (pEvent->type()) { /* If menubar gets the focus while not popped up => give it back: */ case QEvent::FocusIn: { if (!QApplication::activePopupWidget()) setFocus(); } default: break; } } #endif /* Q_WS_WIN */ return UIMachineView::eventFilter(pWatched, pEvent); }
void UIMachineViewNormal::adjustGuestScreenSize() { /* Should we adjust guest-screen size? Logging paranoia is required here to reveal the truth. */ LogRel(("GUI: UIMachineViewNormal::adjustGuestScreenSize: Adjust guest-screen size if necessary.\n")); bool fAdjust = false; /* Step 1: Is the guest-screen of another size than necessary? */ if (!fAdjust) { /* Acquire frame-buffer size: */ QSize frameBufferSize(frameBuffer()->width(), frameBuffer()->height()); /* Take the scale-factor(s) into account: */ frameBufferSize = scaledForward(frameBufferSize); /* Acquire central-widget size: */ const QSize centralWidgetSize = machineWindow()->centralWidget()->size(); if (frameBufferSize != centralWidgetSize) { LogRel2(("GUI: UIMachineViewNormal::adjustGuestScreenSize: Guest-screen is of another size than necessary, adjustment is required.\n")); fAdjust = true; } } /* Step 2: Is guest-additions supports graphics? */ if (fAdjust) { if (!uisession()->isGuestSupportsGraphics()) { LogRel2(("GUI: UIMachineViewNormal::adjustGuestScreenSize: Guest-additions are not supporting graphics, adjustment is omitted.\n")); fAdjust = false; } } /* Step 3: Is guest-screen visible? */ if (fAdjust) { if (!uisession()->isScreenVisible(screenId())) { LogRel2(("GUI: UIMachineViewNormal::adjustGuestScreenSize: Guest-screen is not visible, adjustment is omitted.\n")); fAdjust = false; } } /* Step 4: Is guest-screen auto-resize enabled? */ if (fAdjust) { if (!m_bIsGuestAutoresizeEnabled) { LogRel2(("GUI: UIMachineViewNormal::adjustGuestScreenSize: Guest-screen auto-resize is disabled, adjustment is omitted.\n")); fAdjust = false; } } /* Final step: Adjust if requested/allowed. */ if (fAdjust) { sltPerformGuestResize(machineWindow()->centralWidget()->size()); } }
bool UIMachineViewSeamless::eventFilter(QObject *pWatched, QEvent *pEvent) { if (pWatched != 0 && pWatched == machineWindow()) { switch (pEvent->type()) { case QEvent::Resize: { /* Send guest-resize hint only if top window resizing to required dimension: */ QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); if (pResizeEvent->size() != workingArea().size()) break; /* Recalculate max guest size: */ setMaxGuestSize(); /* And resize guest to that size: */ if (uisession()->isGuestSupportsGraphics()) QTimer::singleShot(0, this, SLOT(sltPerformGuestResize())); break; } default: break; } } return UIMachineView::eventFilter(pWatched, pEvent); }
bool UIMachineViewSeamless::event(QEvent *pEvent) { switch (pEvent->type()) { case SetRegionEventType: { /* Get region-update event: */ UISetRegionEvent *pSetRegionEvent = static_cast<UISetRegionEvent*>(pEvent); /* Apply new region: */ if (pSetRegionEvent->region() != m_lastVisibleRegion) { m_lastVisibleRegion = pSetRegionEvent->region(); machineWindow()->setMask(m_lastVisibleRegion); } return true; } case ResizeEventType: { return guestResizeEvent(pEvent, true); } default: break; } return UIMachineView::event(pEvent); }
void UIMachineWindowSeamless::sltPopupMainMenu() { /* Popup main menu if present: */ if (m_pMainMenu && !m_pMainMenu->isEmpty()) { m_pMainMenu->popup(machineWindow()->geometry().center()); QTimer::singleShot(0, m_pMainMenu, SLOT(sltSelectFirstAction())); } }
void UIMachineViewSeamless::prepareFilters() { /* Base class filters: */ UIMachineView::prepareFilters(); #ifdef Q_WS_MAC // TODO: Is it really needed? See UIMachineViewSeamless::eventFilter(...); /* Menu bar filter: */ machineWindow()->menuBar()->installEventFilter(this); #endif /* Q_WS_MAC */ }
QSize UIMachineViewNormal::calculateMaxGuestSize() const { /* The area taken up by the machine window on the desktop, including window * frame, title, menu bar and status bar. */ QSize windowSize = machineWindow()->frameGeometry().size(); /* The window shouldn't be allowed to expand beyond the working area * unless it already does. In that case the guest shouldn't expand it * any further though. */ QSize maximumSize = workingArea().size().expandedTo(windowSize); /* The current size of the machine display. */ QSize centralWidgetSize = machineWindow()->centralWidget()->size(); /* To work out how big the guest display can get without the window going * over the maximum size we calculated above, we work out how much space * the other parts of the window (frame, menu bar, status bar and so on) * take up and subtract that space from the maximum window size. The * central widget shouldn't be bigger than the window, but we bound it for * sanity (or insanity) reasons. */ return maximumSize - (windowSize - centralWidgetSize.boundedTo(windowSize)); }
void UIMachineViewNormal::prepareFilters() { /* Base class filters: */ UIMachineView::prepareFilters(); #ifdef Q_WS_WIN /* Install menu-bar event-filter: */ machineWindow()->menuBar()->installEventFilter(this); #endif /* Q_WS_WIN */ }
void UIMachineWindowScale::loadWindowSettings() { /* Load scale window settings: */ CMachine machine = session().GetMachine(); /* Load extra-data settings: */ { QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastScaleWindowPosition) : QString("%1%2").arg(VBoxDefs::GUI_LastScaleWindowPosition).arg(m_uScreenId); QStringList strPositionSettings = machine.GetExtraDataStringList(strPositionAddress); bool ok = !strPositionSettings.isEmpty(), max = false; int x = 0, y = 0, w = 0, h = 0; if (ok && strPositionSettings.size() > 0) x = strPositionSettings[0].toInt(&ok); else ok = false; if (ok && strPositionSettings.size() > 1) y = strPositionSettings[1].toInt(&ok); else ok = false; if (ok && strPositionSettings.size() > 2) w = strPositionSettings[2].toInt(&ok); else ok = false; if (ok && strPositionSettings.size() > 3) h = strPositionSettings[3].toInt(&ok); else ok = false; if (ok && strPositionSettings.size() > 4) max = strPositionSettings[4] == VBoxDefs::GUI_LastWindowState_Max; QRect ar = ok ? QApplication::desktop()->availableGeometry(QPoint(x, y)) : QApplication::desktop()->availableGeometry(machineWindow()); /* If previous parameters were read correctly: */ if (ok) { /* Restore window size and position: */ m_normalGeometry = QRect(x, y, w, h); setGeometry(m_normalGeometry); /* Maximize if needed: */ if (max) setWindowState(windowState() | Qt::WindowMaximized); } else { /* Resize to default size: */ resize(640, 480); qApp->processEvents(); /* Move newly created window to the screen center: */ m_normalGeometry = geometry(); m_normalGeometry.moveCenter(ar.center()); setGeometry(m_normalGeometry); } } }
bool UIMachineViewNormal::eventFilter(QObject *pWatched, QEvent *pEvent) { if (pWatched != 0 && pWatched == machineWindow()) { switch (pEvent->type()) { case QEvent::Resize: { /* Recalculate max guest size: */ setMaxGuestSize(); /* And resize guest to current window size: */ if (pEvent->spontaneous() && m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics()) QTimer::singleShot(300, this, SLOT(sltPerformGuestResize())); break; } default: break; } } return UIMachineView::eventFilter(pWatched, pEvent); }
bool UIMachineViewFullscreen::eventFilter(QObject *pWatched, QEvent *pEvent) { if (pWatched != 0 && pWatched == machineWindow()) { switch (pEvent->type()) { case QEvent::Resize: { /* Send guest-resize hint only if top window resizing to required dimension: */ QResizeEvent *pResizeEvent = static_cast<QResizeEvent*>(pEvent); if (pResizeEvent->size() != workingArea().size()) break; if (m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics()) QTimer::singleShot(0, this, SLOT(sltPerformGuestResize())); break; } default: break; } } return UIMachineView::eventFilter(pWatched, pEvent); }