2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
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
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@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"
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QDebug>
|
2010-04-22 17:36:09 +02:00
|
|
|
#include <QtCore/QTimer>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
#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
|
2010-12-16 11:49:47 +01:00
|
|
|
\l{ActionContainer::setOnAllDisabledBehavior()}{OnAllDisabledBehavior}. The default is
|
|
|
|
|
ActionContainer::Disable for menus, and ActionContainer::Show for menu bars.
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2010-12-16 11:49:47 +01:00
|
|
|
\enum ActionContainer::OnAllDisabledBehavior
|
2009-05-04 15:09:31 +02:00
|
|
|
Defines what happens when the represented menu is empty or contains only disabled/invisible items.
|
2010-12-16 11:49:47 +01:00
|
|
|
\value Disable
|
2009-05-04 15:09:31 +02:00
|
|
|
The menu will be visible but disabled.
|
2010-12-16 11:49:47 +01:00
|
|
|
\value Hide
|
2009-05-04 15:09:31 +02:00
|
|
|
The menu will not be visible until the state of the subitems change.
|
2010-12-16 11:49:47 +01:00
|
|
|
\value Show
|
|
|
|
|
The menu will still be visible and active.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn ActionContainer::setOnAllDisabledBehavior(OnAllDisabledBehavior behavior)
|
|
|
|
|
Defines the \a behavior of the menu represented by this action container for the case
|
|
|
|
|
whenever it only contains disabled items and submenus.
|
|
|
|
|
The default is ActionContainer::Disable for menus, and ActionContainer::Show for menu bars.
|
|
|
|
|
\sa ActionContainer::OnAllDisabledBehavior
|
|
|
|
|
\sa ActionContainer::onAllDisabledBehavior()
|
2008-12-02 12:01:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2010-12-16 11:49:47 +01:00
|
|
|
\fn ActionContainer::onAllDisabledBehavior() const
|
|
|
|
|
Returns the \a behavior of the menu represented by this action container for the case
|
2009-05-04 15:09:31 +02:00
|
|
|
whenever it only contains disabled items and submenus.
|
2010-12-16 11:49:47 +01:00
|
|
|
The default is ActionContainer::Disable for menus, and ActionContainer::Show for menu bars.
|
|
|
|
|
\sa ActionContainer::OnAllDisabledBehavior
|
|
|
|
|
\sa ActionContainer::setOnAllDisabledBehavior()
|
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 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)
|
2010-12-16 11:49:47 +01:00
|
|
|
: m_onAllDisabledBehavior(Disable), m_id(id), m_updateRequested(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
appendGroup(QLatin1String(Constants::G_DEFAULT_ONE));
|
|
|
|
|
appendGroup(QLatin1String(Constants::G_DEFAULT_TWO));
|
|
|
|
|
appendGroup(QLatin1String(Constants::G_DEFAULT_THREE));
|
2010-11-12 13:45:13 +01:00
|
|
|
scheduleUpdate();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-16 11:49:47 +01:00
|
|
|
void ActionContainerPrivate::setOnAllDisabledBehavior(OnAllDisabledBehavior behavior)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-12-16 11:49:47 +01:00
|
|
|
m_onAllDisabledBehavior = behavior;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-16 11:49:47 +01:00
|
|
|
ActionContainer::OnAllDisabledBehavior ActionContainerPrivate::onAllDisabledBehavior() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-12-16 11:49:47 +01:00
|
|
|
return m_onAllDisabledBehavior;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
void ActionContainerPrivate::appendGroup(const QString &groupId)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
m_groups.append(Group(groupId));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QList<Group>::const_iterator ActionContainerPrivate::findGroup(const QString &groupId) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
QList<Group>::const_iterator it = m_groups.constBegin();
|
|
|
|
|
while (it != m_groups.constEnd()) {
|
|
|
|
|
if (it->id == groupId)
|
|
|
|
|
break;
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
return it;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QAction *ActionContainerPrivate::insertLocation(const QString &groupId) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
QList<Group>::const_iterator it = findGroup(groupId);
|
|
|
|
|
QTC_ASSERT(it != m_groups.constEnd(), return 0);
|
|
|
|
|
return insertLocation(it);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QAction *ActionContainerPrivate::insertLocation(QList<Group>::const_iterator group) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
if (group == m_groups.constEnd())
|
|
|
|
|
return 0;
|
|
|
|
|
++group;
|
|
|
|
|
while (group != m_groups.constEnd()) {
|
|
|
|
|
if (!group->items.isEmpty()) {
|
|
|
|
|
QObject *item = group->items.first();
|
|
|
|
|
if (Command *cmd = qobject_cast<Command *>(item)) {
|
|
|
|
|
return cmd->action();
|
|
|
|
|
} else if (ActionContainer *container = qobject_cast<ActionContainer *>(item)) {
|
|
|
|
|
if (container->menu())
|
|
|
|
|
return container->menu()->menuAction();
|
|
|
|
|
}
|
|
|
|
|
QTC_ASSERT(false, return 0);
|
|
|
|
|
}
|
|
|
|
|
++group;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
void ActionContainerPrivate::addAction(Command *command, const QString &groupId)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
if (!canAddAction(command))
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QString actualGroupId;
|
|
|
|
|
if (groupId.isEmpty())
|
|
|
|
|
actualGroupId = QLatin1String(Constants::G_DEFAULT_TWO);
|
|
|
|
|
else
|
|
|
|
|
actualGroupId = groupId;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QList<Group>::const_iterator groupIt = findGroup(actualGroupId);
|
|
|
|
|
QTC_ASSERT(groupIt != m_groups.constEnd(), return);
|
|
|
|
|
QAction *beforeAction = insertLocation(groupIt);
|
|
|
|
|
m_groups[groupIt-m_groups.constBegin()].items.append(command);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
connect(command, SIGNAL(activeStateChanged()), this, SLOT(scheduleUpdate()));
|
2011-01-20 15:28:34 +01:00
|
|
|
connect(command, SIGNAL(destroyed()), this, SLOT(itemDestroyed()));
|
2011-01-20 14:24:44 +01:00
|
|
|
insertAction(beforeAction, command->action());
|
2010-11-12 13:45:13 +01:00
|
|
|
scheduleUpdate();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
void ActionContainerPrivate::addMenu(ActionContainer *menu, const QString &groupId)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
ActionContainerPrivate *containerPrivate = static_cast<ActionContainerPrivate *>(menu);
|
|
|
|
|
if (!containerPrivate->canBeAddedToMenu())
|
|
|
|
|
return;
|
|
|
|
|
MenuActionContainer *container = static_cast<MenuActionContainer *>(containerPrivate);
|
|
|
|
|
|
|
|
|
|
QString actualGroupId;
|
|
|
|
|
if (groupId.isEmpty())
|
|
|
|
|
actualGroupId = QLatin1String(Constants::G_DEFAULT_TWO);
|
|
|
|
|
else
|
|
|
|
|
actualGroupId = groupId;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QList<Group>::const_iterator groupIt = findGroup(actualGroupId);
|
|
|
|
|
QTC_ASSERT(groupIt != m_groups.constEnd(), return);
|
|
|
|
|
QAction *beforeAction = insertLocation(groupIt);
|
|
|
|
|
m_groups[groupIt-m_groups.constBegin()].items.append(menu);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
connect(menu, SIGNAL(destroyed()), this, SLOT(itemDestroyed()));
|
2011-01-20 14:24:44 +01:00
|
|
|
insertMenu(beforeAction, container->menu());
|
2010-11-12 13:45:13 +01:00
|
|
|
scheduleUpdate();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
void ActionContainerPrivate::clear()
|
|
|
|
|
{
|
|
|
|
|
QMutableListIterator<Group> it(m_groups);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
Group &group = it.next();
|
|
|
|
|
foreach (QObject *item, group.items) {
|
|
|
|
|
if (Command *command = qobject_cast<Command *>(item)) {
|
|
|
|
|
removeAction(command->action());
|
|
|
|
|
disconnect(command, SIGNAL(activeStateChanged()), this, SLOT(scheduleUpdate()));
|
|
|
|
|
disconnect(command, SIGNAL(destroyed()), this, SLOT(itemDestroyed()));
|
|
|
|
|
} else if (ActionContainer *container = qobject_cast<ActionContainer *>(item)) {
|
|
|
|
|
container->clear();
|
|
|
|
|
disconnect(container, SIGNAL(destroyed()), this, SLOT(itemDestroyed()));
|
|
|
|
|
removeMenu(container->menu());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
group.items.clear();
|
|
|
|
|
}
|
|
|
|
|
scheduleUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-20 15:28:34 +01:00
|
|
|
void ActionContainerPrivate::itemDestroyed()
|
|
|
|
|
{
|
|
|
|
|
QObject *obj = sender();
|
|
|
|
|
QMutableListIterator<Group> it(m_groups);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
Group &group = it.next();
|
|
|
|
|
if (group.items.removeAll(obj) > 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
int ActionContainerPrivate::id() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
return m_id;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QMenu *ActionContainerPrivate::menu() const
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QMenuBar *ActionContainerPrivate::menuBar() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-01-20 14:24:44 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
bool ActionContainerPrivate::canAddAction(Command *action) const
|
|
|
|
|
{
|
|
|
|
|
return (action->action() != 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-22 17:36:09 +02:00
|
|
|
void ActionContainerPrivate::scheduleUpdate()
|
|
|
|
|
{
|
|
|
|
|
if (m_updateRequested)
|
|
|
|
|
return;
|
|
|
|
|
m_updateRequested = true;
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(update()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ActionContainerPrivate::update()
|
|
|
|
|
{
|
|
|
|
|
updateInternal();
|
|
|
|
|
m_updateRequested = false;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ---------- 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
|
|
|
{
|
2010-12-16 11:49:47 +01:00
|
|
|
setOnAllDisabledBehavior(Disable);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuActionContainer::setMenu(QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
m_menu = menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
void MenuActionContainer::removeAction(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
m_menu->removeAction(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuActionContainer::removeMenu(QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
m_menu->removeAction(menu->menuAction());
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-22 17:36:09 +02:00
|
|
|
bool MenuActionContainer::updateInternal()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-12-16 11:49:47 +01:00
|
|
|
if (onAllDisabledBehavior() == Show)
|
2008-12-02 12:01:29 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool hasitems = false;
|
2010-06-28 17:28:10 +02:00
|
|
|
QList<QAction *> actions = m_menu->actions();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-20 14:24:44 +01:00
|
|
|
QListIterator<Group> it(m_groups);
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
const Group &group = it.next();
|
|
|
|
|
foreach (QObject *item, group.items) {
|
|
|
|
|
if (ActionContainerPrivate *container = qobject_cast<ActionContainerPrivate*>(item)) {
|
|
|
|
|
actions.removeAll(container->menu()->menuAction());
|
|
|
|
|
if (container == this) {
|
|
|
|
|
qWarning() << Q_FUNC_INFO << "container" << (this->menu() ? this->menu()->title() : "") << "contains itself as subcontainer";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (container->updateInternal()) {
|
|
|
|
|
hasitems = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (Command *command = qobject_cast<Command *>(item)) {
|
|
|
|
|
actions.removeAll(command->action());
|
|
|
|
|
if (command->isActive()) {
|
|
|
|
|
hasitems = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
QTC_ASSERT(false, continue);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-01-20 14:24:44 +01:00
|
|
|
if (hasitems)
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-06-28 17:28:10 +02:00
|
|
|
if (!hasitems) {
|
|
|
|
|
// look if there were actions added that we don't control and check if they are enabled
|
|
|
|
|
foreach (const QAction *action, actions) {
|
|
|
|
|
if (!action->isSeparator() && action->isEnabled()) {
|
|
|
|
|
hasitems = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-12-16 11:49:47 +01:00
|
|
|
if (onAllDisabledBehavior() == Hide)
|
2010-11-12 13:45:13 +01:00
|
|
|
m_menu->menuAction()->setVisible(hasitems);
|
2010-12-16 11:49:47 +01:00
|
|
|
else if (onAllDisabledBehavior() == Disable)
|
2010-11-12 13:45:13 +01:00
|
|
|
m_menu->menuAction()->setEnabled(hasitems);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
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 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
|
|
|
{
|
2010-12-16 11:49:47 +01:00
|
|
|
setOnAllDisabledBehavior(Show);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-21 10:58:06 +01:00
|
|
|
void MenuBarActionContainer::removeAction(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
m_menuBar->removeAction(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MenuBarActionContainer::removeMenu(QMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
m_menuBar->removeAction(menu->menuAction());
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-22 17:36:09 +02:00
|
|
|
bool MenuBarActionContainer::updateInternal()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-12-16 11:49:47 +01:00
|
|
|
if (onAllDisabledBehavior() == Show)
|
2008-12-02 12:01:29 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-16 11:49:47 +01:00
|
|
|
if (onAllDisabledBehavior() == Hide)
|
2008-12-02 12:01:29 +01:00
|
|
|
m_menuBar->setVisible(hasitems);
|
2010-12-16 11:49:47 +01:00
|
|
|
else if (onAllDisabledBehavior() == Disable)
|
2008-12-02 12:01:29 +01:00
|
|
|
m_menuBar->setEnabled(hasitems);
|
|
|
|
|
|
|
|
|
|
return hasitems;
|
|
|
|
|
}
|
2009-01-14 11:25:00 +01:00
|
|
|
|
|
|
|
|
bool MenuBarActionContainer::canBeAddedToMenu() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|