fw4spl
MenuBarBuilder.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 "fwGuiQt/builder/MenuBarBuilder.hpp"
8 #include "fwGuiQt/container/QtContainer.hpp"
9 #include "fwGuiQt/container/QtMenuBarContainer.hpp"
10 
11 #include <fwGui/registry/macros.hpp>
12 
13 #include <QMainWindow>
14 #include <QMenuBar>
15 
16 fwGuiRegisterMacro(::fwGui::builder::MenuBarBuilder, ::fwGui::builder::IMenuBarBuilder::REGISTRY_KEY);
17 
18 
19 namespace fwGui
20 {
21 namespace builder
22 {
23 
24 //-----------------------------------------------------------------------------
25 
26 MenuBarBuilder::MenuBarBuilder(::fwGui::GuiBaseObject::Key key)
27 {
28 }
29 
30 //-----------------------------------------------------------------------------
31 
32 MenuBarBuilder::~MenuBarBuilder()
33 {
34 }
35 
36 //-----------------------------------------------------------------------------
37 
38 void MenuBarBuilder::createMenuBar( ::fwGui::container::fwContainer::sptr parent )
39 {
40  m_parent = ::fwGuiQt::container::QtContainer::dynamicCast(parent);
41  SLM_ASSERT("The parent container is not a QtContainer", m_parent);
42  QMainWindow *window = qobject_cast<QMainWindow*> ( m_parent->getQtContainer() );
43  if ( !window )
44  {
45  window = qobject_cast<QMainWindow*> ( m_parent->getQtContainer()->parent() );
46  }
47  SLM_ASSERT("The parent container must be a QMainWindow", window );
48  if (window)
49  {
50  ::fwGuiQt::container::QtMenuBarContainer::sptr menuBarContainer =
51  ::fwGuiQt::container::QtMenuBarContainer::New();
52  QMenuBar *menuBar = new QMenuBar(0);
53  menuBarContainer->setQtMenuBar(menuBar);
54  window->setMenuBar( menuBar );
55  m_menuBar = menuBarContainer;
56  }
57 }
58 
59 //-----------------------------------------------------------------------------
60 
62 {
63  SLM_ASSERT("The menu is not initialized", m_menuBar);
64  SLM_ASSERT("The parent container is not a QtContainer", m_parent);
65  QMainWindow *window = qobject_cast<QMainWindow*> ( m_parent->getQtContainer() );
66  if ( !window )
67  {
68  window = qobject_cast<QMainWindow*> ( m_parent->getQtContainer()->parent() );
69  }
70  SLM_ASSERT("The parent container must be a QMainWindow", window );
71  if (window)
72  {
73  window->setMenuBar( NULL );
74  }
75  m_menuBar->destroyContainer();
76 }
77 
78 //-----------------------------------------------------------------------------
79 
80 
81 } // namespace builder
82 } // namespace fwGui
83 
84 
85 
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWGUIQT_API void createMenuBar(::fwGui::container::fwContainer::sptr parent) override
Instantiate layout with parent menuBar.
#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
::fwGui::container::fwMenuBar::sptr m_menuBar
MenuBar.
virtual FWGUIQT_API void destroyMenuBar() override
Destroy local layout with sub containers.
Defines the generic layout manager for IHM.