/* $Id$ */
/** @file
* VBox Qt GUI - UIMenuBarEditorWindow class implementation.
*/
/*
* Copyright (C) 2014 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.
*/
# include <precomp.h>
#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
/* Qt includes: */
# include <QHBoxLayout>
# include <QPaintEvent>
# include <QMetaEnum>
# include <QMenuBar>
# include <QPainter>
# include <QMenu>
# ifndef Q_WS_MAC
# include <QCheckBox>
# endif /* !Q_WS_MAC */
/* GUI includes: */
# include "UIMenuBarEditorWindow.h"
# include "UIActionPoolRuntime.h"
# include "UIExtraDataManager.h"
# include "UIMachineWindow.h"
# include "UIConverter.h"
# include "UIIconPool.h"
# include "UIToolBar.h"
# include "QIToolButton.h"
# include "VBoxGlobal.h"
#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
bool fStartedFromVMSettings /* = true */,
, m_fPrepared(false)
, m_pMainLayout(0)
, m_pToolBar(0)
, m_pButtonClose(0)
#ifndef Q_WS_MAC
, m_pCheckBoxEnable(0)
#endif /* !Q_WS_MAC */
{
/* Prepare: */
prepare();
}
{
/* Remember new machine ID: */
/* Prepare: */
prepare();
}
{
/* Remember new action-pool: */
/* Prepare: */
prepare();
}
{
/* Skip unrelated machine IDs: */
if (machineID() != strMachineID)
return;
#ifndef Q_WS_MAC
/* Update enable-checkbox: */
#endif /* !Q_WS_MAC */
/* Update menus: */
updateMenus();
}
#ifndef RT_OS_DARWIN
{
/* Toggle enable-checkbox if necessary: */
{
/* Check whether this value is really changed: */
if (fMenuBarEnabled != fEnabled)
{
/* Set new value: */
}
}
}
#endif /* !RT_OS_DARWIN */
{
/* Make sure sender is valid: */
/* Depending on triggered action class: */
{
case UIExtraDataMetaDefs::MenuType_All:
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::MenuType restrictions = gEDataManager->restrictedRuntimeMenuTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::MenuApplicationActionType restrictions = gEDataManager->restrictedRuntimeMenuApplicationActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuMachineActionType restrictions = gEDataManager->restrictedRuntimeMenuMachineActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
case UIExtraDataMetaDefs::MenuType_View:
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuViewActionType restrictions = gEDataManager->restrictedRuntimeMenuViewActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuInputActionType restrictions = gEDataManager->restrictedRuntimeMenuInputActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuDevicesActionType restrictions = gEDataManager->restrictedRuntimeMenuDevicesActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
#ifdef VBOX_WITH_DEBUGGER_GUI
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuDebuggerActionType restrictions = gEDataManager->restrictedRuntimeMenuDebuggerActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
#endif /* VBOX_WITH_DEBUGGER_GUI */
#ifdef Q_WS_MAC
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::MenuWindowActionType restrictions = gEDataManager->restrictedRuntimeMenuWindowActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
#endif /* Q_WS_MAC */
case UIExtraDataMetaDefs::MenuType_Help:
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::MenuHelpActionType restrictions = gEDataManager->restrictedRuntimeMenuHelpActionTypes(machineID());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
default: break;
}
}
{
/* Do nothing if already prepared: */
if (m_fPrepared)
return;
/* Do not prepare if machine ID or action-pool is not set: */
return;
/* Create main-layout: */
m_pMainLayout = new QHBoxLayout(this);
{
/* Configure main-layout: */
/* Standard margins should not be too big: */
/* Top margin should be smaller for the common case: */
if (iTop >= 5)
iTop -= 5;
#ifndef Q_WS_MAC
/* Right margin should be bigger for the settings case: */
iRight += 5;
#endif /* !Q_WS_MAC */
m_pMainLayout->setSpacing(0);
/* Create tool-bar: */
m_pToolBar = new UIToolBar;
{
/* Prepare menus: */
prepareMenus();
/* Add tool-bar into main-layout: */
}
/* Insert stretch: */
/* Create close-button if necessary: */
if (!m_fStartedFromVMSettings)
{
m_pButtonClose = new QIToolButton;
{
/* Configure close-button: */
/* Add close-button into main-layout: */
}
}
#ifndef Q_WS_MAC
/* Create enable-checkbox if necessary: */
else
{
m_pCheckBoxEnable = new QCheckBox;
{
/* Configure enable-checkbox: */
/* Add enable-checkbox into main-layout: */
/* Update enable-checkbox: */
}
}
#endif /* !Q_WS_MAC */
}
/* Mark as prepared: */
m_fPrepared = true;
/* Translate contents: */
}
{
/* Create menus: */
#ifdef VBOX_WITH_DEBUGGER_GUI
#endif /* VBOX_WITH_DEBUGGER_GUI */
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
/* Listen for the menu-bar configuration changes: */
/* Update menus: */
updateMenus();
}
#ifdef Q_WS_MAC
{
/* Create named menu: */
{
/* Configure named menu: */
/* Get named menu action: */
{
/* Add menu action into tool-bar: */
/* Get named menu tool-button: */
QToolButton *pNamedMenuToolButton = qobject_cast<QToolButton*>(m_pToolBar->widgetForAction(pNamedMenuAction));
{
/* Configure named menu tool-button: */
pNamedMenuToolButton->setAutoRaise(true);
/* Create spacing after named menu tool-button: */
AssertPtrReturn(pSpacing, 0);
{
/* Configure spacing: */
/* Add spacing into tool-bar: */
}
}
}
}
/* Return named menu: */
return pNamedMenu;
}
#endif /* Q_WS_MAC */
{
/* Create copied menu: */
{
/* Configure copied menu: */
/* Get copied menu action: */
{
/* Configure copied menu action: */
pCopiedMenuAction->setCheckable(true);
/* Add menu action into tool-bar: */
/* Get copied menu tool-button: */
QToolButton *pCopiedMenuToolButton = qobject_cast<QToolButton*>(m_pToolBar->widgetForAction(pCopiedMenuAction));
{
/* Configure copied menu tool-button: */
pCopiedMenuToolButton->setAutoRaise(true);
/* Create spacing after copied menu tool-button: */
AssertPtrReturn(pSpacing, 0);
{
/* Configure spacing: */
/* Add spacing into tool-bar: */
}
}
}
}
/* Return copied menu: */
return pCopiedMenu;
}
#if 0
{
/* Create copied sub-menu: */
{
/* Configure copied sub-menu: */
/* Get copied sub-menu action: */
{
/* Configure copied sub-menu: */
pCopiedMenuAction->setCheckable(true);
}
}
/* Return copied sub-menu: */
return pCopiedMenu;
}
#endif
{
/* Create copied action: */
{
/* Configure copied action: */
pCopiedAction->setCheckable(true);
}
/* Return copied action: */
return pCopiedAction;
}
{
/* Create copied action: */
{
/* Configure copied action: */
pCopiedAction->setCheckable(true);
}
/* Return copied action: */
return pCopiedAction;
}
{
/* Copy menu: */
#ifdef Q_WS_MAC
#else /* !Q_WS_MAC */
#endif /* !Q_WS_MAC */
{
#ifdef Q_WS_MAC
# ifdef VBOX_GUI_WITH_NETWORK_MANAGER
prepareCopiedAction(pMenu, actionPool()->action(UIActionIndex_M_Application_S_NetworkAccessManager));
# endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
pMenu->addSeparator();
#else /* !Q_WS_MAC */
pMenu->addSeparator();
# ifdef VBOX_GUI_WITH_NETWORK_MANAGER
prepareCopiedAction(pMenu, actionPool()->action(UIActionIndex_M_Application_S_NetworkAccessManager));
# endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
#endif /* !Q_WS_MAC */
}
}
{
/* Copy menu: */
{
pMenu->addSeparator();
}
}
{
/* Copy menu: */
{
pMenu->addSeparator();
pMenu->addSeparator();
pMenu->addSeparator();
pMenu->addSeparator();
}
}
{
/* Copy menu: */
{
pMenu->addSeparator();
}
}
{
/* Copy menu: */
{
pMenu->addSeparator();
pMenu->addSeparator();
}
}
#ifdef VBOX_WITH_DEBUGGER_GUI
{
/* Copy menu: */
{
}
}
#endif /* VBOX_WITH_DEBUGGER_GUI */
#ifdef Q_WS_MAC
{
/* Copy menu: */
{
pMenu->addSeparator();
}
}
#endif /* Q_WS_MAC */
{
/* Copy menu: */
{
pMenu->addSeparator();
#ifndef Q_WS_MAC
#endif /* !Q_WS_MAC */
}
}
#ifndef Q_WS_MAC
{
/* Update enable-checkbox if necessary: */
{
m_pCheckBoxEnable->blockSignals(true);
m_pCheckBoxEnable->blockSignals(false);
}
}
#endif /* !Q_WS_MAC */
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::MenuType restrictionsMenuBar = gEDataManager->restrictedRuntimeMenuTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::MenuType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
/* Skip MenuType_Invalid & MenuType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
/* Update known menu-bar menus: */
#ifdef VBOX_WITH_DEBUGGER_GUI
#endif /* VBOX_WITH_DEBUGGER_GUI */
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
}
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::MenuApplicationActionType restrictionsMenuApplication = gEDataManager->restrictedRuntimeMenuApplicationActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::MenuApplicationActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::MenuApplicationActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip MenuApplicationActionType_Invalid & MenuApplicationActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuMachineActionType restrictionsMenuMachine = gEDataManager->restrictedRuntimeMenuMachineActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::RuntimeMenuMachineActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::RuntimeMenuMachineActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip RuntimeMenuMachineActionType_Invalid & RuntimeMenuMachineActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuViewActionType restrictionsMenuView = gEDataManager->restrictedRuntimeMenuViewActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::RuntimeMenuViewActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::RuntimeMenuViewActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip RuntimeMenuViewActionType_Invalid & RuntimeMenuViewActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuInputActionType restrictionsMenuInput = gEDataManager->restrictedRuntimeMenuInputActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::RuntimeMenuInputActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::RuntimeMenuInputActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip RuntimeMenuInputActionType_Invalid & RuntimeMenuInputActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuDevicesActionType restrictionsMenuDevices = gEDataManager->restrictedRuntimeMenuDevicesActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::RuntimeMenuDevicesActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::RuntimeMenuDevicesActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip RuntimeMenuDevicesActionType_Invalid & RuntimeMenuDevicesActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
#ifdef VBOX_WITH_DEBUGGER_GUI
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuDebuggerActionType restrictionsMenuDebug = gEDataManager->restrictedRuntimeMenuDebuggerActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::RuntimeMenuDebuggerActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::RuntimeMenuDebuggerActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip RuntimeMenuDebuggerActionType_Invalid & RuntimeMenuDebuggerActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
#endif /* VBOX_WITH_DEBUGGER_GUI */
#ifdef Q_WS_MAC
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::MenuWindowActionType restrictionsMenuWindow = gEDataManager->restrictedRuntimeMenuWindowActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::MenuWindowActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::MenuWindowActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip MenuWindowActionType_Invalid & MenuWindowActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
#endif /* Q_WS_MAC */
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::MenuHelpActionType restrictionsMenuHelp = gEDataManager->restrictedRuntimeMenuHelpActionTypes(machineID());
/* Get static meta-object: */
/* We have UIExtraDataMetaDefs::MenuHelpActionType enum registered, so we can enumerate it: */
/* Handle other enum-values: */
{
/* Get iterated enum-value: */
static_cast<const UIExtraDataMetaDefs::MenuHelpActionType>(metaEnum.keyToValue(metaEnum.key(iKeyIndex)));
/* Skip MenuHelpActionType_Invalid & MenuHelpActionType_All enum-value: */
continue;
/* Which key required action registered under? */
continue;
/* Update action 'checked' state: */
}
}
{
/* Translate close-button if necessary: */
if (!m_fStartedFromVMSettings && m_pButtonClose)
#ifndef Q_WS_MAC
/* Translate enable-checkbox if necessary: */
#endif /* !Q_WS_MAC */
}
{
/* Prepare painter: */
/* Prepare palette colors: */
#endif /* Q_WS_WIN || Q_WS_X11 */
/* Left corner: */
{
}
/* Right corner: */
{
}
/* Bottom line: */
{
}
/* Left line: */
{
}
/* Right line: */
{
}
/* Paint frames: */
painter.drawLine(QLine(QPoint(5 + 1, height() - 1 - 5 - 1), QPoint(width() - 1 - 5 - 1, height() - 1 - 5 - 1)));
painter.drawLine(QLine(QPoint(width() - 1 - 5 - 1, height() - 1 - 5 - 1), QPoint(width() - 1 - 5 - 1, 0)));
#endif /* Q_WS_WIN || Q_WS_X11 */
}
#ifndef Q_WS_MAC
: UISlidingToolBar(pParent, pParent->menuBar(), new UIMenuBarEditorWidget(0, false, vboxGlobal().managedVMUuid(), pActionPool), UISlidingToolBar::Position_Top)
#else /* Q_WS_MAC */
: UISlidingToolBar(pParent, 0, new UIMenuBarEditorWidget(0, false, vboxGlobal().managedVMUuid(), pActionPool), UISlidingToolBar::Position_Top)
#endif /* Q_WS_MAC */
{
}