fw4spl
MenuBarLayoutManager.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <QMenu>
8 #include <QMenuBar>
9 #include <QString>
10 
11 #include <fwGui/registry/macros.hpp>
12 
13 #include "fwGuiQt/container/QtMenuContainer.hpp"
14 #include "fwGuiQt/layoutManager/MenuBarLayoutManager.hpp"
15 
16 
17 fwGuiRegisterMacro( ::fwGui::layoutManager::MenuBarLayoutManager,
18  ::fwGui::layoutManager::IMenuBarLayoutManager::REGISTRY_KEY );
19 
20 namespace fwGui
21 {
22 namespace layoutManager
23 {
24 
25 //-----------------------------------------------------------------------------
26 
27 MenuBarLayoutManager::MenuBarLayoutManager(::fwGui::GuiBaseObject::Key key)
28 {
29 }
30 
31 //-----------------------------------------------------------------------------
32 
33 MenuBarLayoutManager::~MenuBarLayoutManager()
34 {
35 }
36 
37 //-----------------------------------------------------------------------------
38 
39 void MenuBarLayoutManager::createLayout( ::fwGui::container::fwMenuBar::sptr parent )
40 {
42 
43  m_parent = ::fwGuiQt::container::QtMenuBarContainer::dynamicCast(parent);
44  SLM_ASSERT("dynamicCast fwMenuBar to QtMenuBarContainer failed", m_parent);
45 
46  QMenuBar* menuBar = m_parent->getQtMenuBar();
47 
48  for ( std::string name : m_menuNames)
49  {
50  ::fwGuiQt::container::QtMenuContainer::sptr menu = ::fwGuiQt::container::QtMenuContainer::New();
51  QMenu *qtMenu = menuBar->addMenu(QString::fromStdString( name ));
52  menu->setQtMenu(qtMenu);
53  m_menus.push_back(menu);
54  }
55 }
56 
57 //-----------------------------------------------------------------------------
58 
60 {
61  this->destroyMenus();
62  m_menus.clear();
63  m_parent->clean();
64 }
65 
66 //-----------------------------------------------------------------------------
67 
68 
69 void MenuBarLayoutManager::menuIsVisible(::fwGui::container::fwMenu::sptr fwMenu, bool isVisible)
70 {
71  ::fwGuiQt::container::QtMenuContainer::sptr menuContainer = ::fwGuiQt::container::QtMenuContainer::dynamicCast(
72  fwMenu);
73  QMenu *menu = menuContainer->getQtMenu();
74  menu->setVisible(isVisible);
75 }
76 
77 //-----------------------------------------------------------------------------
78 
79 void MenuBarLayoutManager::menuIsEnabled(::fwGui::container::fwMenu::sptr fwMenu, bool isEnabled)
80 {
81  ::fwGuiQt::container::QtMenuContainer::sptr menuContainer = ::fwGuiQt::container::QtMenuContainer::dynamicCast(
82  fwMenu);
83  QMenu *menu = menuContainer->getQtMenu();
84  menu->setEnabled(isEnabled);
85 }
86 
87 //-----------------------------------------------------------------------------
88 
89 } // namespace layoutManager
90 } // namespace fwGui
91 
92 
93 
Defines the menu bar layout manager for IHM.
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWGUIQT_API void createLayout(::fwGui::container::fwMenuBar::sptr parent) override
Instantiate menu with parent menuBar.
virtual FWGUI_API void destroyMenus()
Helper to destroy local sub views.
virtual FWGUIQT_API void menuIsEnabled(::fwGui::container::fwMenu::sptr fwMenu, bool isEnabled) override
Set the menu enable or not.
std::vector< std::string > m_menuNames
Save menu name from configuration.
virtual FWGUIQT_API void destroyLayout() override
Destroy local menus.
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
std::vector< ::fwGui::container::fwMenu::sptr > m_menus
All sub containers managed by this layout.
virtual FWGUIQT_API void menuIsVisible(::fwGui::container::fwMenu::sptr fwMenu, bool isVisible) override
Set the menu visibility.