UIMachineViewNormal.cpp revision 36545c63b2aab948161e4a712913a4f2dce17d2f
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIMachineViewNormal class implementation
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/* Global includes */
#include <QApplication>
#include <QDesktopWidget>
#include <QMainWindow>
#include <QMenuBar>
#include <QScrollBar>
#include <QTimer>
/* Local includes */
#include "VBoxGlobal.h"
#include "UISession.h"
#include "UIActionPoolRuntime.h"
#include "UIMachineLogic.h"
#include "UIMachineWindow.h"
#include "UIMachineViewNormal.h"
#include "UIFrameBuffer.h"
#ifdef VBOX_WITH_VIDEOHWACCEL
, bool bAccelerate2DVideo
#endif
)
#ifdef VBOX_WITH_VIDEOHWACCEL
#endif
)
, m_bIsGuestAutoresizeEnabled(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->isChecked())
, m_fShouldWeDoResize(false)
{
/* Load machine view settings: */
/* Prepare viewport: */
/* Prepare frame buffer: */
/* Prepare common things: */
/* Prepare event-filters: */
/* Prepare connections: */
/* Prepare console connections: */
/* Initialization: */
}
{
/* Save machine view settings: */
/* Cleanup frame buffer: */
}
{
{
/* Get machine window: */
/* If this slot is invoked directly then use the passed size otherwise get
* the available size for the guest display. We assume here that centralWidget()
* contains this view only and gives it all available space: */
QSize newSize(toSize.isValid() ? toSize : pMachineWindow ? pMachineWindow->centralWidget()->size() : QSize());
/* Do not send the same hints as we already have: */
if ((newSize.width() == storedConsoleSize().width()) && (newSize.height() == storedConsoleSize().height()))
return;
/* We only actually send the hint if either an explicit new size was given
* (e.g. if the request was triggered directly by a console resize event) or
* if no explicit size was specified but a resize is flagged as being needed
* (e.g. the autoresize was just enabled and the console was resized while it was disabled). */
{
/* Remember the new size: */
/* Send new size-hint to the guest: */
session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
}
/* We had requested resize now, rejecting other accident requests: */
m_fShouldWeDoResize = false;
}
}
{
/* Check if we should restrict minimum size: */
}
void UIMachineViewNormal::sltDesktopResized()
{
/* If the desktop geometry is set automatically, this will update it: */
}
{
{
case VBoxDefs::ResizeEventType:
{
/* Some situations require framebuffer resize events to be ignored at all,
* leaving machine-window, machine-view and framebuffer sizes preserved: */
if (uisession()->isGuestResizeIgnored())
return true;
/* We are starting to perform machine-view resize,
* we should temporary ignore other if they are trying to be: */
/* Get guest resize-event: */
/* Perform framebuffer resize: */
/* Reapply maximum size restriction for machine-view: */
/* Store the new size to prevent unwanted resize hints being sent back: */
/* Perform machine-view resize: */
/* May be we have to restrict minimum size? */
/* Let our toplevel widget calculate its sizeHint properly: */
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
/* Update machine-view sliders: */
/* Normalize machine-window geometry: */
normalizeGeometry(true /* Adjust Position? */);
/* Report to the VM thread that we finished resizing: */
/* We are finishing to perform machine-view resize: */
/* We also recalculate the desktop geometry if this is determined
* automatically. In fact, we only need this on the first resize,
* but it is done every time to keep the code simpler. */
/* Emit a signal about guest was resized: */
return true;
}
default:
break;
}
}
{
/* Who are we watching? */
#ifdef Q_WS_WIN
#endif /* Q_WS_WIN */
{
{
{
/* Set the "guest needs to resize" hint.
* This hint is acted upon when (and only when) the autoresize property is "true": */
if (!isMachineWindowResizeIgnored() && m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics())
break;
}
#if defined (Q_WS_WIN32)
# if defined (VBOX_GUI_USE_DDRAW)
{
/* Notification from our parent that it has moved. We need this in order
* to possibly adjust the direct screen blitting: */
if (frameBuffer())
break;
}
# endif /* defined (VBOX_GUI_USE_DDRAW) */
#endif /* defined (Q_WS_WIN32) */
default:
break;
}
}
#ifdef Q_WS_WIN
{
/* 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: */
{
/* If menubar gets the focus while not popped up => give it back: */
{
if (!QApplication::activePopupWidget())
setFocus();
}
default:
break;
}
}
#endif /* Q_WS_WIN */
}
void UIMachineViewNormal::prepareCommon()
{
/* Base class common settings: */
/* Setup size-policy: */
/* Maximum size to sizehint: */
}
void UIMachineViewNormal::prepareFilters()
{
/* Base class filters: */
/* Menu bar filters: */
qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->menuBar()->installEventFilter(this);
}
{
}
{
/* Base class connections: */
/* Guest additions state-change updater: */
}
{
/* Store guest size hint: */
}
{
if (m_bIsGuestAutoresizeEnabled != fEnabled)
{
}
}
{
#ifndef VBOX_GUI_WITH_CUSTOMIZATIONS1
/* Make no normalizeGeometry in case we are in manual resize mode or main window is maximized: */
if (pTopLevelWidget->isMaximized())
return;
/* Calculate client window offsets: */
/* Get the best size w/o scroll bars: */
/* Resize the frame to fit the contents: */
s -= pTopLevelWidget->size();
if (bAdjustPosition)
{
if (dwt->isVirtualDesktop())
/* Compose complex available region */
for (int i = 0; i < dwt->numScreens(); ++ i)
else
/* Get just a simple available rectangle */
frameGeo = VBoxGlobal::normalizeGeometry(frameGeo, availableGeo, vboxGlobal().vmRenderMode() != VBoxDefs::SDLMode /* can resize? */);
}
#if 0
/* Center the frame on the desktop: */
#endif
/* Finally, set the frame geometry */
pTopLevelWidget->setGeometry(frameGeo.left() + dl, frameGeo.top() + dt, frameGeo.width() - dl - dr, frameGeo.height() - dt - db);
#else /* !VBOX_GUI_WITH_CUSTOMIZATIONS1 */
#endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
}
{
}
{
/* This method should not get called until we have initially set up the desktop geometry type: */
/* If we are not doing automatic geometry calculation then there is nothing to do: */
if (desktopGeometryType() == DesktopGeo_Automatic)
{
/* The area taken up by the machine window on the desktop,
* including window frame, title, menu bar and status bar: */
/* The area taken up by the machine central widget, so excluding all decorations: */
QRect centralWidgetGeo = static_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->centralWidget()->geometry();
/* To work out how big we can make the console window while still fitting on the desktop,
* we calculate workingArea() - (windowGeo - centralWidgetGeo).
* This works because the difference between machine window and machine central widget
* (or at least its width and height) is a constant. */
}
}
{
/* Sets the minimum size restriction depending on the auto-resize feature state and the current rendering mode.
* Currently, the restriction is set only in SDL mode and only when the auto-resize feature is inactive.
* We need to do that because we cannot correctly draw in a scrolled window in SDL mode.
* In all other modes, or when auto-resize is in force, this function does nothing. */
{
else
setMinimumSize(0, 0);
}
}