2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
#include "actioncontainer_p.h"
|
2009-01-13 13:07:29 +01:00
|
|
|
#include "actionmanager_p.h"
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
#include "command_p.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "coreconstants.h"
|
|
|
|
|
#include "uniqueidmanager.h"
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#include <QtGui/QToolBar>
|
|
|
|
|
#include <QtGui/QMenuBar>
|
|
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(Core::Internal::MenuActionContainer*)
|
|
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 12:39:59 +01:00
|
|
|
\class ActionContainer
|
2008-12-02 12:01:29 +01:00
|
|
|
\mainclass
|
|
|
|
|
|
2009-01-14 12:39:59 +01:00
|
|
|
\brief The ActionContainer class represents a menu or menu bar in Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-04 15:09:31 +02:00
|
|
|
You don't create instances of this class directly, but instead use the
|
|
|
|
|
\l{ActionManager::createMenu()}
|
|
|
|
|
and \l{ActionManager::createMenuBar()} methods.
|
|
|
|
|
Retrieve existing action containers for an ID with
|
|
|
|
|
\l{ActionManager::actionContainer()}.
|
|
|
|
|
|
|
|
|
|
Within a menu or menu bar you can group menus and items together by defining groups
|
|
|
|
|
(the order of the groups is defined by the order of the \l{ActionContainer::appendGroup()} calls), and
|
|
|
|
|
adding menus/actions to these groups. If no custom groups are defined, an action container
|
|
|
|
|
has three default groups \c{Core::Constants::G_DEFAULT_ONE}, \c{Core::Constants::G_DEFAULT_TWO}
|
|
|
|
|
and \c{Core::Constants::G_DEFAULT_THREE}.
|
|
|
|
|
|
|
|
|
|
You can define if the menu represented by this action container should automatically disable
|
|
|
|
|
or hide whenever it only contains disabled items and submenus by setting the corresponding
|
|
|
|
|
\l{ActionContainer::setEmptyAction()}{EmptyAction}.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 12:39:59 +01:00
|
|
|
\enum ActionContainer::EmptyAction
|
2009-05-04 15:09:31 +02:00
|
|
|
Defines what happens when the represented menu is empty or contains only disabled/invisible items.
|
|
|
|
|
\omitvalue EA_Mask
|
|
|
|
|
\value EA_None
|
|
|
|
|
The menu will still be visible and active.
|
|
|
|
|
\value EA_Disable
|
|
|
|
|
The menu will be visible but disabled.
|
|
|
|
|
\value EA_Hide
|
|
|
|
|
The menu will not be visible until the state of the subitems change.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn ActionContainer::setEmptyAction(EmptyAction disableOrHide)
|
|
|
|
|
Defines if the menu represented by this action container should automatically \a disableOrHide
|
|
|
|
|
whenever it only contains disabled items and submenus.
|
|
|
|
|
\sa ActionContainer::EmptyAction
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn int ActionContainer::id() const
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn QMenu *ActionContainer::menu() const
|
|
|
|
|
Returns the QMenu instance that is represented by this action container, or
|
|
|
|
|
0 if this action container represents a menu bar.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn QMenuBar *ActionContainer::menuBar() const
|
|
|
|
|
Returns the QMenuBar instance that is represented by this action container, or
|
|
|
|
|
0 if this action container represents a menu.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn QAction *ActionContainer::insertLocation(const QString &group) const
|
|
|
|
|
Returns an action representing the \a group,
|
|
|
|
|
that could be used with \c{QWidget::insertAction}.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn void ActionContainer::appendGroup(const QString &identifier)
|
|
|
|
|
Adds a group with the given \a identifier to the action container. Using groups
|
|
|
|
|
you can segment your action container into logical parts and add actions and
|
|
|
|
|
menus directly to these parts.
|
|
|
|
|
\sa addAction()
|
|
|
|
|
\sa addMenu()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn void ActionContainer::addAction(Core::Command *action, const QString &group)
|
|
|
|
|
Add the \a action as a menu item to this action container. The action is added as the
|
|
|
|
|
last item of the specified \a group.
|
|
|
|
|
\sa appendGroup()
|
|
|
|
|
\sa addMenu()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn void ActionContainer::addMenu(Core::ActionContainer *menu, const QString &group)
|
|
|
|
|
Add the \a menu as a submenu to this action container. The menu is added as the
|
|
|
|
|
last item of the specified \a group.
|
|
|
|
|
\sa appendGroup()
|
|
|
|
|
\sa addAction()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn bool ActionContainer::update()
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-05-04 15:09:31 +02:00
|
|
|
\fn ActionContainer::~ActionContainer()
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
// ---------- ActionContainerPrivate ------------
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 12:25:54 +01:00
|
|
|
\class Core::Internal::ActionContainerPrivate
|
2009-01-14 11:25:00 +01:00
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
ActionContainerPrivate::ActionContainerPrivate(int id)
|
2009-01-14 11:25:00 +01:00
|
|
|
: m_data(CS_None), m_id(id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
void ActionContainerPrivate::setEmptyAction(EmptyAction ea)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_data = ((m_data & ~EA_Mask) | ea);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
bool ActionContainerPrivate::hasEmptyAction(EmptyAction ea) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return (m_data & EA_Mask) == ea;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
void ActionContainerPrivate::setState(ContainerState state)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_data |= state;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
bool ActionContainerPrivate::hasState(ContainerState state) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return (m_data & state);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
void ActionContainerPrivate::appendGroup(const QString &group)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-21 13:33:58 +01:00
|
|
|
int gid = UniqueIDManager::instance()->uniqueIdentifier(group);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_groups << gid;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
QAction *ActionContainerPrivate::insertLocation(const QString &group) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-21 13:33:58 +01:00
|
|
|
int grpid = UniqueIDManager::instance()->uniqueIdentifier(group);
|
2008-12-02 12:01:29 +01:00
|
|
|
int prevKey = 0;
|
|
|
|
|
int pos = ((grpid << 16) | 0xFFFF);
|
|
|
|
|
return beforeAction(pos, &prevKey);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 13:17:53 +01:00
|
|
|
void ActionContainerPrivate::addAction(Command *action, const QString &group)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (!canAddAction(action))
|
|
|
|
|
return;
|
|
|
|
|
|
2009-01-13 13:07:29 +01:00
|
|
|
ActionManagerPrivate *am = ActionManagerPrivate::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
Action *a = static_cast<Action *>(action);
|
2009-01-14 12:58:06 +01:00
|
|
|
if (a->stateFlags() & CommandPrivate::CS_PreLocation) {
|
2008-12-02 12:01:29 +01:00
|
|
|
QList<CommandLocation> locs = a->locations();
|
|
|
|
|
for (int i=0; i<locs.size(); ++i) {
|
2009-01-14 12:39:59 +01:00
|
|
|
if (ActionContainer *aci = am->actionContainer(locs.at(i).m_container)) {
|
2009-01-14 12:25:54 +01:00
|
|
|
ActionContainerPrivate *ac = static_cast<ActionContainerPrivate *>(aci);
|
2008-12-02 12:01:29 +01:00
|
|
|
ac->addAction(action, locs.at(i).m_position, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-14 12:58:06 +01:00
|
|
|
a->setStateFlags(a->stateFlags() | CommandPrivate::CS_Initialized);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2009-01-21 13:33:58 +01:00
|
|
|
UniqueIDManager *idmanager = UniqueIDManager::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
int grpid = idmanager->uniqueIdentifier(Constants::G_DEFAULT_TWO);
|
|
|
|
|
if (!group.isEmpty())
|
|
|
|
|
grpid = idmanager->uniqueIdentifier(group);
|
|
|
|
|
if (!m_groups.contains(grpid) && !am->defaultGroups().contains(grpid))
|
|
|
|
|
qWarning() << "*** addAction(): Unknown group: " << group;
|
|
|
|
|
int pos = ((grpid << 16) | 0xFFFF);
|
|
|
|
|
addAction(action, pos, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:39:59 +01:00
|
|
|
void ActionContainerPrivate::addMenu(ActionContainer *menu, const QString &group)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-14 12:25:54 +01:00
|
|
|
ActionContainerPrivate *container = static_cast<ActionContainerPrivate *>(menu);
|
2009-01-14 11:25:00 +01:00
|
|
|
if (!container->canBeAddedToMenu())
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
|
2009-01-13 13:07:29 +01:00
|
|
|
ActionManagerPrivate *am = ActionManagerPrivate::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
MenuActionContainer *mc = static_cast<MenuActionContainer *>(menu);
|
2009-01-14 12:25:54 +01:00
|
|
|
if (mc->hasState(ActionContainerPrivate::CS_PreLocation)) {
|
2008-12-02 12:01:29 +01:00
|
|
|
CommandLocation loc = mc->location();
|
2009-01-14 12:39:59 +01:00
|
|
|
if (ActionContainer *aci = am->actionContainer(loc.m_container)) {
|
2009-01-14 12:25:54 +01:00
|
|
|
ActionContainerPrivate *ac = static_cast<ActionContainerPrivate *>(aci);
|
2008-12-02 12:01:29 +01:00
|
|
|
ac->addMenu(menu, loc.m_position, false);
|
|
|
|
|
}
|
2009-01-14 12:25:54 +01:00
|
|
|
mc->setState(ActionContainerPrivate::CS_Initialized);
|
2008-12-02 12:01:29 +01:00
|
|
|
} else {
|
2009-01-21 13:33:58 +01:00
|
|
|
UniqueIDManager *idmanager = UniqueIDManager::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
int grpid = idmanager->uniqueIdentifier(Constants::G_DEFAULT_TWO);
|
|
|
|
|
if (!group.isEmpty())
|
|
|
|
|
grpid = idmanager->uniqueIdentifier(group);
|
|
|
|
|
if (!m_groups.contains(grpid) && !am->defaultGroups().contains(grpid))
|
|
|
|
|
qWarning() << "*** addMenu(): Unknown group: " << group;
|
|
|
|
|
int pos = ((grpid << 16) | 0xFFFF);
|
|
|
|
|
addMenu(menu, pos, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
int ActionContainerPrivate::id() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
QMenu *ActionContainerPrivate::menu() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
QMenuBar *ActionContainerPrivate::menuBar() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 13:17:53 +01:00
|
|
|
bool ActionContainerPrivate::canAddAction(Command *action) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-14 13:17:53 +01:00
|
|
|
if (action->type() != Command::CT_OverridableAction)
|
2008-12-02 12:01:29 +01:00
|
|
|
return false;
|
|
|
|
|
|
2009-01-14 12:58:06 +01:00
|
|
|
CommandPrivate *cmd = static_cast<CommandPrivate *>(action);
|
|
|
|
|
if (cmd->stateFlags() & CommandPrivate::CS_Initialized)
|
2008-12-02 12:01:29 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 13:17:53 +01:00
|
|
|
void ActionContainerPrivate::addAction(Command *action, int pos, bool setpos)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Action *a = static_cast<Action *>(action);
|
|
|
|
|
|
|
|
|
|
int prevKey = 0;
|
|
|
|
|
QAction *ba = beforeAction(pos, &prevKey);
|
|
|
|
|
|
|
|
|
|
if (setpos) {
|
|
|
|
|
pos = calcPosition(pos, prevKey);
|
|
|
|
|
CommandLocation loc;
|
|
|
|
|
loc.m_container = m_id;
|
|
|
|
|
loc.m_position = pos;
|
|
|
|
|
QList<CommandLocation> locs = a->locations();
|
|
|
|
|
locs.append(loc);
|
|
|
|
|
a->setLocations(locs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_commands.append(action);
|
|
|
|
|
m_posmap.insert(pos, action->id());
|
|
|
|
|
insertAction(ba, a->action());
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:39:59 +01:00
|
|
|
void ActionContainerPrivate::addMenu(ActionContainer *menu, int pos, bool setpos)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
MenuActionContainer *mc = static_cast<MenuActionContainer *>(menu);
|
|
|
|
|
|
|
|
|
|
int prevKey = 0;
|
|
|
|
|
QAction *ba = beforeAction(pos, &prevKey);
|
|
|
|
|
|
|
|
|
|
if (setpos) {
|
|
|
|
|
pos = calcPosition(pos, prevKey);
|
|
|
|
|
CommandLocation loc;
|
|
|
|
|
loc.m_container = m_id;
|
|
|
|
|
loc.m_position = pos;
|
|
|
|
|
mc->setLocation(loc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_subContainers.append(menu);
|
|
|
|
|
m_posmap.insert(pos, menu->id());
|
|
|
|
|
insertMenu(ba, mc->menu());
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
QAction *ActionContainerPrivate::beforeAction(int pos, int *prevKey) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-13 13:07:29 +01:00
|
|
|
ActionManagerPrivate *am = ActionManagerPrivate::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int baId = -1;
|
|
|
|
|
|
|
|
|
|
(*prevKey) = -1;
|
|
|
|
|
|
|
|
|
|
QMap<int, int>::const_iterator i = m_posmap.constBegin();
|
|
|
|
|
while (i != m_posmap.constEnd()) {
|
|
|
|
|
if (i.key() > pos) {
|
|
|
|
|
baId = i.value();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
(*prevKey) = i.key();
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (baId == -1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2009-01-14 13:17:53 +01:00
|
|
|
if (Command *cmd = am->command(baId))
|
2008-12-02 12:01:29 +01:00
|
|
|
return cmd->action();
|
2009-01-14 12:39:59 +01:00
|
|
|
if (ActionContainer *container = am->actionContainer(baId))
|
2008-12-02 12:01:29 +01:00
|
|
|
if (QMenu *menu = container->menu())
|
|
|
|
|
return menu->menuAction();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 12:25:54 +01:00
|
|
|
int ActionContainerPrivate::calcPosition(int pos, int prevKey) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
int grp = (pos & 0xFFFF0000);
|
|
|
|
|
if (prevKey == -1)
|
|
|
|
|
return grp;
|
|
|
|
|
|
|
|
|
|
int prevgrp = (prevKey & 0xFFFF0000);
|
|
|
|
|
|
|
|
|
|
if (grp != prevgrp)
|
|
|
|
|
return grp;
|
|
|
|
|
|
|
|
|
|
return grp + (prevKey & 0xFFFF) + 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------- MenuActionContainer ------------
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 11:25:00 +01:00
|
|
|
\class Core::Internal::MenuActionContainer
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
MenuActionContainer::MenuActionContainer(int id)
|
2009-01-14 12:25:54 +01:00
|
|
|
: ActionContainerPrivate(id), m_menu(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setEmptyAction(EA_Disable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuActionContainer::setMenu(QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
m_menu = menu;
|
|
|
|
|
|
|
|
|
|
QVariant v;
|
|
|
|
|
qVariantSetValue<MenuActionContainer*>(v, this);
|
|
|
|
|
|
|
|
|
|
m_menu->menuAction()->setData(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMenu *MenuActionContainer::menu() const
|
|
|
|
|
{
|
|
|
|
|
return m_menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuActionContainer::insertAction(QAction *before, QAction *action)
|
|
|
|
|
{
|
|
|
|
|
m_menu->insertAction(before, action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuActionContainer::insertMenu(QAction *before, QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
m_menu->insertMenu(before, menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuActionContainer::setLocation(const CommandLocation &location)
|
|
|
|
|
{
|
|
|
|
|
m_location = location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandLocation MenuActionContainer::location() const
|
|
|
|
|
{
|
|
|
|
|
return m_location;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MenuActionContainer::update()
|
|
|
|
|
{
|
|
|
|
|
if (hasEmptyAction(EA_None))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool hasitems = false;
|
|
|
|
|
|
2009-01-14 12:39:59 +01:00
|
|
|
foreach (ActionContainer *container, subContainers()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
if (container == this) {
|
|
|
|
|
qWarning() << Q_FUNC_INFO << "container" << (this->menu() ? this->menu()->title() : "") << "contains itself as subcontainer";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (container->update()) {
|
|
|
|
|
hasitems = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hasitems) {
|
2009-01-14 13:17:53 +01:00
|
|
|
foreach (Command *command, commands()) {
|
2008-12-02 12:01:29 +01:00
|
|
|
if (command->isActive()) {
|
|
|
|
|
hasitems = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasEmptyAction(EA_Hide))
|
|
|
|
|
m_menu->setVisible(hasitems);
|
|
|
|
|
else if (hasEmptyAction(EA_Disable))
|
|
|
|
|
m_menu->setEnabled(hasitems);
|
|
|
|
|
|
|
|
|
|
return hasitems;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-14 11:25:00 +01:00
|
|
|
bool MenuActionContainer::canBeAddedToMenu() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-14 12:25:54 +01:00
|
|
|
if (hasState(ActionContainerPrivate::CS_Initialized))
|
2009-01-14 11:25:00 +01:00
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-14 11:25:00 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- MenuBarActionContainer ------------
|
|
|
|
|
|
|
|
|
|
/*!
|
2009-01-14 11:25:00 +01:00
|
|
|
\class Core::Internal::MenuBarActionContainer
|
|
|
|
|
\internal
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
MenuBarActionContainer::MenuBarActionContainer(int id)
|
2009-01-14 12:25:54 +01:00
|
|
|
: ActionContainerPrivate(id), m_menuBar(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setEmptyAction(EA_None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuBarActionContainer::setMenuBar(QMenuBar *menuBar)
|
|
|
|
|
{
|
|
|
|
|
m_menuBar = menuBar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMenuBar *MenuBarActionContainer::menuBar() const
|
|
|
|
|
{
|
|
|
|
|
return m_menuBar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuBarActionContainer::insertAction(QAction *before, QAction *action)
|
|
|
|
|
{
|
|
|
|
|
m_menuBar->insertAction(before, action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuBarActionContainer::insertMenu(QAction *before, QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
m_menuBar->insertMenu(before, menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MenuBarActionContainer::update()
|
|
|
|
|
{
|
|
|
|
|
if (hasEmptyAction(EA_None))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool hasitems = false;
|
|
|
|
|
QList<QAction *> actions = m_menuBar->actions();
|
|
|
|
|
for (int i=0; i<actions.size(); ++i) {
|
|
|
|
|
if (actions.at(i)->isVisible()) {
|
|
|
|
|
hasitems = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasEmptyAction(EA_Hide))
|
|
|
|
|
m_menuBar->setVisible(hasitems);
|
|
|
|
|
else if (hasEmptyAction(EA_Disable))
|
|
|
|
|
m_menuBar->setEnabled(hasitems);
|
|
|
|
|
|
|
|
|
|
return hasitems;
|
|
|
|
|
}
|
2009-01-14 11:25:00 +01:00
|
|
|
|
|
|
|
|
bool MenuBarActionContainer::canBeAddedToMenu() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|