UIMenuBarEditorWindow.cpp revision 77a8f1c110ad18b4b2818e03cb5a9e8fa6fb7c90
/* $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.
*/
/* Qt includes: */
#include <QHBoxLayout>
#include <QPaintEvent>
#include <QMetaEnum>
#include <QMenuBar>
#include <QPainter>
#include <QMenu>
#include <QMap>
/* GUI includes: */
#include "UIMenuBarEditorWindow.h"
#include "UIActionPoolRuntime.h"
#include "UIExtraDataManager.h"
#include "UIMachineWindow.h"
#include "UIConverter.h"
#include "UIIconPool.h"
#include "UIToolBar.h"
#include "QIWithRetranslateUI.h"
#include "QIToolButton.h"
#include "VBoxGlobal.h"
/** QWidget reimplementation
* used as menu-bar editor widget. */
{
/** Notifies about Cancel button click. */
void sigCancelClicked();
public:
/** Constructor, taking @a pActionPool argument. */
/** Returns the action-pool reference. */
private slots:
/** Handles configuration change. */
void sltHandleConfigurationChange();
/** Handles menu-bar menu click. */
void sltHandleMenuBarMenuClick();
private:
/** Prepare routine. */
void prepare();
#ifdef Q_WS_MAC
/** Prepare named menu routine. */
#endif /* Q_WS_MAC */
/** Prepare copied menu routine. */
#if 0
/** Prepare copied sub-menu routine. */
#endif
/** Prepare copied action routine. */
/** Prepare menus routine. */
void prepareMenus();
#ifdef Q_WS_MAC
/** Mac OS X: Prepare 'Application' menu routine. */
void prepareMenuApplication();
#endif /* Q_WS_MAC */
/** Prepare 'Machine' menu routine. */
void prepareMenuMachine();
/** Prepare 'View' menu routine. */
void prepareMenuView();
/** Prepare 'Devices' menu routine. */
void prepareMenuDevices();
#ifdef VBOX_WITH_DEBUGGER_GUI
/** Prepare 'Debug' menu routine. */
void prepareMenuDebug();
#endif /* VBOX_WITH_DEBUGGER_GUI */
/** Prepare 'Help' menu routine. */
void prepareMenuHelp();
/** Updates menus routine. */
void updateMenus();
#ifdef Q_WS_MAC
/** Mac OS X: Updates 'Application' menu routine. */
void updateMenuApplication();
#endif /* Q_WS_MAC */
/** Updates 'Machine' menu routine. */
void updateMenuMachine();
/** Updates 'View' menu routine. */
void updateMenuView();
/** Updates 'Devices' menu routine. */
void updateMenuDevices();
#ifdef VBOX_WITH_DEBUGGER_GUI
/** Updates 'Debug' menu routine. */
void updateMenuDebug();
#endif /* VBOX_WITH_DEBUGGER_GUI */
/** Updates 'Help' menu routine. */
void updateMenuHelp();
/** Retranslation routine. */
virtual void retranslateUi();
/** Paint event handler. */
/** @name General
* @{ */
/** Holds the action-pool reference. */
const UIActionPool *m_pActionPool;
/** @} */
/** @name Contents
* @{ */
/** Holds the main-layout instance. */
/** Holds the tool-bar instance. */
/** Holds the close-button instance. */
/** Holds tool-bar action references. */
/** @} */
};
, m_pMainLayout(0)
, m_pToolBar(0)
, m_pButtonClose(0)
{
/* Prepare: */
prepare();
}
{
/* Update menus: */
updateMenus();
}
{
/* 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(vboxGlobal().managedVMUuid());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
#ifdef Q_WS_MAC
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::MenuApplicationActionType restrictions = gEDataManager->restrictedRuntimeMenuApplicationActionTypes(vboxGlobal().managedVMUuid());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
gEDataManager->setRestrictedRuntimeMenuApplicationActionTypes(restrictions, vboxGlobal().managedVMUuid());
break;
}
#endif /* Q_WS_MAC */
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuMachineActionType restrictions = gEDataManager->restrictedRuntimeMenuMachineActionTypes(vboxGlobal().managedVMUuid());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
gEDataManager->setRestrictedRuntimeMenuMachineActionTypes(restrictions, vboxGlobal().managedVMUuid());
break;
}
case UIExtraDataMetaDefs::MenuType_View:
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuViewActionType restrictions = gEDataManager->restrictedRuntimeMenuViewActionTypes(vboxGlobal().managedVMUuid());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuDevicesActionType restrictions = gEDataManager->restrictedRuntimeMenuDevicesActionTypes(vboxGlobal().managedVMUuid());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
gEDataManager->setRestrictedRuntimeMenuDevicesActionTypes(restrictions, vboxGlobal().managedVMUuid());
break;
}
#ifdef VBOX_WITH_DEBUGGER_GUI
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::RuntimeMenuDebuggerActionType restrictions = gEDataManager->restrictedRuntimeMenuDebuggerActionTypes(vboxGlobal().managedVMUuid());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
gEDataManager->setRestrictedRuntimeMenuDebuggerActionTypes(restrictions, vboxGlobal().managedVMUuid());
break;
}
#endif /* VBOX_WITH_DEBUGGER_GUI */
case UIExtraDataMetaDefs::MenuType_Help:
{
/* Get sender type: */
/* Load current menu-bar restrictions: */
UIExtraDataMetaDefs::MenuHelpActionType restrictions = gEDataManager->restrictedRuntimeMenuHelpActionTypes(vboxGlobal().managedVMUuid());
/* Invert restriction for sender type: */
/* Save updated menu-bar restrictions: */
break;
}
default: break;
}
}
void UIMenuBarEditorWidget::prepare()
{
/* Create main-layout: */
m_pMainLayout = new QHBoxLayout(this);
{
/* Configure main-layout: */
#ifdef Q_WS_MAC
/* Standard margins on Mac OS X are too big: */
#else /* !Q_WS_MAC */
if (iTop >= 5)
iTop -= 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: */
m_pButtonClose = new QIToolButton;
{
/* Configure close-button: */
/* Add close-button into main-layout: */
}
}
/* Translate contents: */
}
void UIMenuBarEditorWidget::prepareMenus()
{
/* Create menus: */
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
#ifdef VBOX_WITH_DEBUGGER_GUI
#endif /* VBOX_WITH_DEBUGGER_GUI */
/* Listen for the menu-bar configuration changes: */
this, SLOT(sltHandleConfigurationChange()));
/* 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;
}
#ifdef Q_WS_MAC
{
/* Copy menu: */
{
}
}
#endif /* Q_WS_MAC */
{
/* Copy menu: */
{
pMenu->addSeparator();
pMenu->addSeparator();
#ifdef Q_WS_X11
#endif /* Q_WS_X11 */
pMenu->addSeparator();
}
}
void UIMenuBarEditorWidget::prepareMenuView()
{
/* Copy menu: */
{
pMenu->addSeparator();
pMenu->addSeparator();
pMenu->addSeparator();
// prepareCopiedAction(pMenu, Resize);
// prepareCopiedAction(pMenu, MultiScreen);
}
}
{
/* Copy menu: */
{
pMenu->addSeparator();
pMenu->addSeparator();
}
}
#ifdef VBOX_WITH_DEBUGGER_GUI
{
/* Copy menu: */
{
}
}
#endif /* VBOX_WITH_DEBUGGER_GUI */
void UIMenuBarEditorWidget::prepareMenuHelp()
{
/* Copy menu: */
{
pMenu->addSeparator();
pMenu->addSeparator();
#endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
#ifndef Q_WS_MAC
pMenu->addSeparator();
#endif /* !Q_WS_MAC */
}
}
void UIMenuBarEditorWidget::updateMenus()
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::MenuType restrictionsMenuBar = gEDataManager->restrictedRuntimeMenuTypes(vboxGlobal().managedVMUuid());
/* 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 Q_WS_MAC
#endif /* Q_WS_MAC */
#ifdef VBOX_WITH_DEBUGGER_GUI
#endif /* VBOX_WITH_DEBUGGER_GUI */
}
#ifdef Q_WS_MAC
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::MenuApplicationActionType restrictionsMenuApplication = gEDataManager->restrictedRuntimeMenuApplicationActionTypes(vboxGlobal().managedVMUuid());
/* 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: */
}
}
#endif /* Q_WS_MAC */
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuMachineActionType restrictionsMenuMachine = gEDataManager->restrictedRuntimeMenuMachineActionTypes(vboxGlobal().managedVMUuid());
/* 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: */
}
}
void UIMenuBarEditorWidget::updateMenuView()
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuViewActionType restrictionsMenuView = gEDataManager->restrictedRuntimeMenuViewActionTypes(vboxGlobal().managedVMUuid());
/* 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::RuntimeMenuDevicesActionType restrictionsMenuDevices = gEDataManager->restrictedRuntimeMenuDevicesActionTypes(vboxGlobal().managedVMUuid());
/* 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
void UIMenuBarEditorWidget::updateMenuDebug()
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::RuntimeMenuDebuggerActionType restrictionsMenuDebug = gEDataManager->restrictedRuntimeMenuDebuggerActionTypes(vboxGlobal().managedVMUuid());
/* 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 */
void UIMenuBarEditorWidget::updateMenuHelp()
{
/* Recache menu-bar configuration: */
const UIExtraDataMetaDefs::MenuHelpActionType restrictionsMenuHelp = gEDataManager->restrictedRuntimeMenuHelpActionTypes(vboxGlobal().managedVMUuid());
/* 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: */
}
}
void UIMenuBarEditorWidget::retranslateUi()
{
/* Translate close-button: */
}
{
/* 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(pActionPool), UISlidingToolBar::Position_Top)
#else /* Q_WS_MAC */
: UISlidingToolBar(pParent, 0, new UIMenuBarEditorWidget(pActionPool), UISlidingToolBar::Position_Top)
#endif /* Q_WS_MAC */
{
}
#include "UIMenuBarEditorWindow.moc"