Changed: #1206 Added menu manager. Update core and example plugin.
parent
65d69747e4
commit
d86ce847d6
@ -0,0 +1,30 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
// Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef CORE_GLOBAL_H
|
||||||
|
#define CORE_GLOBAL_H
|
||||||
|
|
||||||
|
#include <QtCore/qglobal.h>
|
||||||
|
|
||||||
|
#if defined(CORE_LIBRARY)
|
||||||
|
# define CORE_EXPORT Q_DECL_EXPORT
|
||||||
|
#else
|
||||||
|
# define CORE_EXPORT Q_DECL_IMPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // CORE_GLOBAL_H
|
@ -0,0 +1,62 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef IMENU_MANAGER_H
|
||||||
|
#define IMENU_MANAGER_H
|
||||||
|
|
||||||
|
#include "core_global.h"
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QList>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QMenu;
|
||||||
|
class QAction;
|
||||||
|
class QString;
|
||||||
|
class QMenuBar;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Core
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
@interface IMenuManager
|
||||||
|
@brief The IMenuManager is an interface for providing a registration of menus and menu item.
|
||||||
|
@details The IMenuManager provides centralized access to menus and menu items.
|
||||||
|
All menus and menu items should be registered in the IMenuManager.
|
||||||
|
*/
|
||||||
|
class CORE_EXPORT IMenuManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
IMenuManager(QObject *parent = 0): QObject(parent) {}
|
||||||
|
virtual ~IMenuManager() {}
|
||||||
|
|
||||||
|
virtual void registerMenu(QMenu *menu, const QString &id) = 0;
|
||||||
|
virtual void registerAction(QAction *action, const QString &id) = 0;
|
||||||
|
|
||||||
|
virtual QMenu *menu(const QString &id) const = 0;
|
||||||
|
virtual QAction *action(const QString &id) const = 0;
|
||||||
|
|
||||||
|
virtual void unregisterMenu(const QString &id) = 0;
|
||||||
|
virtual void unregisterAction(const QString &id) = 0;
|
||||||
|
|
||||||
|
virtual QMenuBar *menuBar() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Core
|
||||||
|
|
||||||
|
#endif // IMENU_MANAGER_H
|
@ -0,0 +1,94 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "menu_manager.h"
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtGui/QMenu>
|
||||||
|
#include <QtGui/QAction>
|
||||||
|
#include <QtGui/QMenuBar>
|
||||||
|
|
||||||
|
namespace Core
|
||||||
|
{
|
||||||
|
MenuManager::MenuManager(QObject *parent)
|
||||||
|
: IMenuManager(parent),
|
||||||
|
_menuBar(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuManager::~MenuManager()
|
||||||
|
{
|
||||||
|
_menuMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuManager::registerMenu(QMenu *menu, const QString &id)
|
||||||
|
{
|
||||||
|
menu->setObjectName(id);
|
||||||
|
_menuMap.insert(id, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuManager::registerAction(QAction *action, const QString &id)
|
||||||
|
{
|
||||||
|
action->setObjectName(id);
|
||||||
|
_actionMap.insert(id, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
QMenu *MenuManager::menu(const QString &id) const
|
||||||
|
{
|
||||||
|
QMenu *result = 0;
|
||||||
|
if (_menuMap.count(id) == 0)
|
||||||
|
nlwarning("QMenu %s not found", id.toStdString().c_str());
|
||||||
|
else
|
||||||
|
result = _menuMap.value(id);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QAction *MenuManager::action(const QString &id) const
|
||||||
|
{
|
||||||
|
QAction *result = 0;
|
||||||
|
if (_actionMap.count(id) == 0)
|
||||||
|
nlwarning("QAction %s not found", id.toStdString().c_str());
|
||||||
|
else
|
||||||
|
result = _actionMap.value(id);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuManager::unregisterMenu(const QString &id)
|
||||||
|
{
|
||||||
|
_menuMap.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuManager::unregisterAction(const QString &id)
|
||||||
|
{
|
||||||
|
_actionMap.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QMenuBar *MenuManager::menuBar() const
|
||||||
|
{
|
||||||
|
return _menuBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuManager::setMenuBar(QMenuBar *menuBar)
|
||||||
|
{
|
||||||
|
_menuBar = menuBar;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace Core */
|
@ -0,0 +1,59 @@
|
|||||||
|
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef MENU_MANAGER_H
|
||||||
|
#define MENU_MANAGER_H
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "imenu_manager.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtCore/QHash>
|
||||||
|
|
||||||
|
namespace Core
|
||||||
|
{
|
||||||
|
|
||||||
|
class MenuManager : public IMenuManager
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
MenuManager(QObject *parent = 0);
|
||||||
|
virtual ~MenuManager();
|
||||||
|
|
||||||
|
virtual void registerMenu(QMenu *menu, const QString &id);
|
||||||
|
virtual void registerAction(QAction *action, const QString &id);
|
||||||
|
|
||||||
|
virtual QMenu *menu(const QString &id) const;
|
||||||
|
virtual QAction *action(const QString &id) const;
|
||||||
|
|
||||||
|
virtual void unregisterMenu(const QString &id);
|
||||||
|
virtual void unregisterAction(const QString &id);
|
||||||
|
|
||||||
|
virtual QMenuBar *menuBar() const;
|
||||||
|
void setMenuBar(QMenuBar *menuBar);
|
||||||
|
private:
|
||||||
|
QMenuBar *_menuBar;
|
||||||
|
typedef QHash<QString, QMenu *> IdMenuMap;
|
||||||
|
IdMenuMap _menuMap;
|
||||||
|
typedef QHash<QString, QAction *> IdActionMap;
|
||||||
|
IdActionMap _actionMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Core
|
||||||
|
|
||||||
|
#endif // MENU_MANAGER_H
|
Loading…
Reference in New Issue