fw4spl
TabLayoutManager.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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/layoutManager/TabLayoutManager.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwGui/registry/macros.hpp>
12 
13 #include <QBoxLayout>
14 #include <QScrollArea>
15 #include <QTabWidget>
16 
17 fwGuiRegisterMacro( ::fwGui::TabLayoutManager, ::fwGui::layoutManager::TabLayoutManagerBase::REGISTRY_KEY );
18 
19 namespace fwGui
20 {
21 
22 //-----------------------------------------------------------------------------
23 
24 TabLayoutManager::TabLayoutManager(::fwGui::GuiBaseObject::Key key)
25 {
26 }
27 
28 //-----------------------------------------------------------------------------
29 
30 TabLayoutManager::~TabLayoutManager()
31 {
32 }
33 
34 //-----------------------------------------------------------------------------
35 
36 void TabLayoutManager::createLayout( ::fwGui::container::fwContainer::sptr parent )
37 {
39  m_parentContainer = ::fwGuiQt::container::QtContainer::dynamicCast(parent);
40  SLM_ASSERT("dynamicCast fwContainer to QtContainer failed", m_parentContainer);
41 
42  QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
43  m_parentContainer->setLayout(layout);
44 
45  m_tabWidget = new QTabWidget();
46  layout->addWidget( m_tabWidget );
47 
48  const std::list< ViewInfo>& views = this->getViewsInfo();
49 
50  for ( ViewInfo viewInfo : views)
51  {
52  QWidget* widget = new QWidget(m_tabWidget);
53 
54  ::fwGuiQt::container::QtContainer::sptr subContainer = ::fwGuiQt::container::QtContainer::New();
55  subContainer->setQtContainer(widget);
56  m_subViews.push_back(subContainer);
57 
58  int idx = 0;
59  if(viewInfo.m_useScrollBar)
60  {
61  QScrollArea* scrollArea = new QScrollArea(m_tabWidget);
62  scrollArea->setWidget(widget);
63  scrollArea->setWidgetResizable( true );
64  idx = m_tabWidget->addTab( scrollArea, QString::fromStdString(viewInfo.m_caption));
65  }
66  else
67  {
68  idx = m_tabWidget->addTab( widget, QString::fromStdString(viewInfo.m_caption));
69  }
70 
71  if (viewInfo.m_isSelect )
72  {
73  m_tabWidget->setCurrentIndex(idx);
74  }
75  }
76 }
77 
78 //-----------------------------------------------------------------------------
79 
81 {
82  this->destroySubViews();
83  m_tabWidget->clear();
84  m_parentContainer->clean();
85 }
86 
87 //-----------------------------------------------------------------------------
88 
89 } // namespace fwGui
90 
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::fwContainer::sptr parent) override
Instantiate layout with parent container.
virtual FWGUIQT_API void destroyLayout() override
Destroy local layout with sub containers.
#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::fwContainer::sptr > m_subViews
All sub containers managed by this layout.
virtual FWGUI_API void destroySubViews()
Helper to destroy local sub views.
Defines the tab layout manager.