UIActionPool.cpp revision ab25abdb6c5a8a1c2e3b917fb2e44b3b738d213c
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIActionPool class implementation
*/
/*
* Copyright (C) 2010-2013 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 <QHelpEvent>
#include <QToolTip>
/* Local includes: */
#include "UIActionPool.h"
#include "UIActionPoolSelector.h"
#include "UIActionPoolRuntime.h"
#include "UIIconPool.h"
#include "UIShortcutPool.h"
#include "VBoxGlobal.h"
/* Action activation event: */
class ActivateActionEvent : public QEvent
{
public:
private:
};
/* UIAction stuff: */
{
/* By default there is no specific menu role.
* It will be set explicitly later. */
}
{
return qobject_cast<UIActionState*>(this);
}
{
/* Remember internal name: */
/* Update text according new name: */
updateText();
}
{
/* Call to base-class: */
/* Remember shortcut: */
/* Update text according new shortcut: */
updateText();
}
void UIAction::showShortcut()
{
if (!m_shortcut.isEmpty())
}
void UIAction::hideShortcut()
{
}
{
/* Action-name format depends on action-pool type: */
switch (m_actionPoolType)
{
/* Unchanged name for Selector UI: */
case UIActionPoolType_Selector: return name();
/* Filtered name for Runtime UI: */
}
/* Nothing by default: */
return QString();
}
void UIAction::updateText()
{
/* Action-text format depends on action-pool type: */
switch (m_actionPoolType)
{
/* The same as menu name for Selector UI: */
setText(nameInMenu());
break;
/* With shortcut appended for Runtime UI: */
case UIActionPoolType_Runtime:
break;
}
}
/* UIMenu stuff: */
: m_fShowToolTips(false)
{
}
{
/* Handle particular event-types: */
{
/* Tool-tip request handler: */
{
/* Get current help-event: */
/* Get action which caused help-event: */
/* If action present => show action's tool-tip if needed: */
if (pAction && m_fShowToolTips)
break;
}
default:
break;
}
/* Base-class event-handler: */
}
/* UIActionSimple stuff: */
{
}
{
setIcon(UIIconPool::iconSetFull(normalSize, smallSize, strNormalIcon, strSmallIcon, strNormalIconDis, strSmallIconDis));
}
{
}
/* UIActionState stuff: */
, m_iState(0)
{
}
, m_iState(0)
{
setIcon(UIIconPool::iconSetFull(normalSize, smallSize, strNormalIcon, strSmallIcon, strNormalIconDis, strSmallIconDis));
}
, m_iState(0)
{
}
/* UIActionToggle stuff: */
{
init();
}
{
setIcon(UIIconPool::iconSetFull(normalSize, smallSize, strNormalIcon, strSmallIcon, strNormalIconDis, strSmallIconDis));
init();
}
{
init();
}
{
init();
}
void UIActionToggle::sltUpdate()
{
}
void UIActionToggle::init()
{
setCheckable(true);
}
/* UIActionMenu stuff: */
{
}
{
}
class UIActionSimpleLogDialog : public UIActionSimple
{
public:
":/vm_show_logs_32px.png", ":/show_logs_16px.png",
":/vm_show_logs_disabled_32px.png", ":/show_logs_disabled_16px.png")
{
}
protected:
QString shortcutExtraDataID() const
{
return QString("ShowVMLog");
}
{
switch (actionPoolType)
{
case UIActionPoolType_Runtime: break;
}
return QKeySequence();
}
void retranslateUi()
{
setStatusTip(QApplication::translate("UIActionPool", "Show the log files of the selected virtual machine"));
}
};
class UIActionMenuHelp : public UIActionMenu
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class UIActionSimpleContents : public UIActionSimple
{
public:
{
}
protected:
QString shortcutExtraDataID() const
{
return QString("Help");
}
{
switch (actionPoolType)
{
case UIActionPoolType_Runtime: break;
}
return QKeySequence();
}
void retranslateUi()
{
}
};
class UIActionSimpleWebSite : public UIActionSimple
{
public:
{
}
protected:
QString shortcutExtraDataID() const
{
return QString("Web");
}
void retranslateUi()
{
setStatusTip(QApplication::translate("UIActionPool", "Open the browser and go to the VirtualBox product web site"));
}
};
class UIActionSimpleResetWarnings : public UIActionSimple
{
public:
{
}
protected:
QString shortcutExtraDataID() const
{
return QString("ResetWarnings");
}
void retranslateUi()
{
setStatusTip(QApplication::translate("UIActionPool", "Go back to showing all suppressed warnings and messages"));
}
};
class UIActionSimpleNetworkAccessManager : public UIActionSimple
{
public:
{
}
protected:
QString shortcutExtraDataID() const
{
return QString("NetworkAccessManager");
}
void retranslateUi()
{
}
};
class UIActionSimpleCheckForUpdates : public UIActionSimple
{
public:
{
}
protected:
QString shortcutExtraDataID() const
{
return QString("Update");
}
void retranslateUi()
{
}
};
class UIActionSimpleAbout : public UIActionSimple
{
public:
{
}
protected:
QString shortcutExtraDataID() const
{
return QString("About");
}
void retranslateUi()
{
}
};
/* UIActionPool stuff: */
/* static */
{
return m_pInstance;
}
/* static */
{
/* Check that instance do NOT exists: */
if (m_pInstance)
return;
/* Create instance: */
switch (type)
{
case UIActionPoolType_Selector: new UIActionPoolSelector; break;
case UIActionPoolType_Runtime: new UIActionPoolRuntime; break;
default: break;
}
/* Prepare instance: */
m_pInstance->prepare();
}
/* static */
void UIActionPool::destroy()
{
/* Check that instance exists: */
if (!m_pInstance)
return;
/* Cleanup instance: */
m_pInstance->cleanup();
/* Delete instance: */
delete m_pInstance;
}
{
/* Prepare instance: */
if (!m_pInstance)
m_pInstance = this;
}
{
/* Cleanup instance: */
if (m_pInstance == this)
m_pInstance = 0;
}
void UIActionPool::prepare()
{
/* Create actions: */
/* Create menus: */
createMenus();
/* Apply shortcuts: */
gShortcutPool->applyShortcuts(this);
}
void UIActionPool::cleanup()
{
/* Destroy pool: */
destroyPool();
}
{
/* Get the list of keys: */
/* Iterate through the whole list of keys: */
{
/* Get current action: */
/* Skip menus/separators: */
continue;
/* Get the hot key of the current action: */
{
{
/* We asynchronously post a special event instead of calling
* pAction->trigger() directly, to let key presses and
* releases be processed correctly by Qt first.
* Note: we assume that nobody will delete the menu item
* corresponding to the key sequence, so that the pointer to
* menu data posted along with the event will remain valid in
* the event handler, at least until the main window is closed. */
return true;
}
}
}
return false;
}
void UIActionPool::createActions()
{
/* Various dialog actions: */
/* 'Help' actions: */
}
void UIActionPool::createMenus()
{
/* On Mac OS X, all QMenu's are consumed by Qt after they are added to another QMenu or a QMenuBar.
* This means we have to recreate all QMenus when creating a new QMenuBar.
* For simplicity we doing this on all platforms right now. */
/* Recreate 'help' menu items as well.
* This makes sure they are removed also from the Application menu: */
delete m_pool[UIActionIndex_Simple_Contents];
delete m_pool[UIActionIndex_Simple_WebSite];
delete m_pool[UIActionIndex_Simple_ResetWarnings];
/* For whatever reason, Qt doesn't fully remove items with a
* ApplicationSpecificRole from the application menu. Although the QAction
* itself is deleted, a dummy entry is leaved back in the menu.
* Hiding before deletion helps. */
#endif
delete m_pool[UIActionIndex_Simple_About];
#endif
/* 'Help' menu itself: */
delete m_pool[UIActionIndex_Menu_Help];
}
void UIActionPool::destroyPool()
{
/* Get the list of keys: */
/* Delete all the items of the map: */
}
{
/* Depending on event-type: */
{
case ActivateActionEventType:
{
/* Process specific event: */
return true;
}
default:
break;
}
/* Pass to the base-class: */
}
#include "UIActionPool.moc"