fw4spl
ToolboxLayoutManager.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/ToolboxLayoutManager.hpp"
8 
9 #include "fwGuiQt/container/QtContainer.hpp"
10 
11 #include <fwCore/base.hpp>
12 
13 #include <fwGui/registry/macros.hpp>
14 
15 #include <QScrollArea>
16 #include <QStyle>
17 #include <QVBoxLayout>
18 
19 fwGuiRegisterMacro( ::fwGui::ToolboxLayoutManager, ::fwGui::layoutManager::ToolboxLayoutManagerBase::REGISTRY_KEY );
20 
21 namespace fwGui
22 {
23 
24 //-----------------------------------------------------------------------------
25 
26 ToolboxLayoutManager::ToolboxLayoutManager(::fwGui::GuiBaseObject::Key key)
27 {
28 }
29 
30 //-----------------------------------------------------------------------------
31 
32 ToolboxLayoutManager::~ToolboxLayoutManager()
33 {
34 }
35 
36 //-----------------------------------------------------------------------------
37 
38 void ToolboxLayoutManager::createLayout( ::fwGui::container::fwContainer::sptr parent )
39 {
41 
42  ::fwGuiQt::container::QtContainer::sptr parentContainer =
43  ::fwGuiQt::container::QtContainer::dynamicCast(parent);
44 
45  QVBoxLayout* layout = new QVBoxLayout();
46  parentContainer->setLayout(layout);
47 
48  layout->setContentsMargins(0, 0, 0, 0);
49 
50  QScrollArea* sv = new QScrollArea();
51  ::fwGuiQt::widget::QfwToolBox* toolbox = new ::fwGuiQt::widget::QfwToolBox(sv);
52  sv->setWidget(toolbox);
53  sv->setWidgetResizable(true);
54  layout->addWidget(sv);
55 
56  const std::list< ViewInfo>& views = this->getViewsInfo();
57  for ( ViewInfo viewInfo : views)
58  {
59  int border = viewInfo.m_border;
60  QWidget* panel = new QWidget();
61  panel->setMinimumSize(std::max(viewInfo.m_minSize.first, 0), std::max(viewInfo.m_minSize.second, 0));
62  panel->setContentsMargins(border, border, border, border);
63 
64  ::fwGuiQt::container::QtContainer::sptr subContainer = ::fwGuiQt::container::QtContainer::New();
65  subContainer->setQtContainer(panel);
66  m_subViews.push_back(subContainer);
67 
68  int index = 0;
69  if(viewInfo.m_useScrollBar)
70  {
71  QScrollArea* scrollArea = new QScrollArea(toolbox);
72  scrollArea->setWidget(panel);
73  scrollArea->setWidgetResizable( true );
74  index = toolbox->addItem(scrollArea, QString::fromStdString(viewInfo.m_caption));
75  }
76  else
77  {
78  index = toolbox->addItem(panel, QString::fromStdString(viewInfo.m_caption));
79  }
80 
81  if(viewInfo.m_expanded)
82  {
83  toolbox->expandItem(index);
84  }
85 
86  if(false == viewInfo.m_visible)
87  {
88  subContainer->setVisible(false);
89  }
90  }
91 }
92 
93 //-----------------------------------------------------------------------------
94 
96 {
97  this->destroySubViews();
98 }
99 
100 //-----------------------------------------------------------------------------
101 
102 } // namespace fwGui
103 
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.
Defines the toolbox layout manager.
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.