fw4spl
LineLayoutManager.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/LineLayoutManager.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwGui/registry/macros.hpp>
12 
13 #include <QBoxLayout>
14 #include <QGroupBox>
15 #include <QScrollArea>
16 #include <QStyle>
17 
18 fwGuiRegisterMacro( ::fwGui::LineLayoutManager, ::fwGui::layoutManager::LineLayoutManagerBase::REGISTRY_KEY );
19 
20 namespace fwGui
21 {
22 
23 //-----------------------------------------------------------------------------
24 
25 LineLayoutManager::LineLayoutManager(::fwGui::GuiBaseObject::Key key)
26 {
27 }
28 
29 //-----------------------------------------------------------------------------
30 
31 LineLayoutManager::~LineLayoutManager()
32 {
33 }
34 
35 //-----------------------------------------------------------------------------
36 
37 void LineLayoutManager::createLayout( ::fwGui::container::fwContainer::sptr parent )
38 {
40  m_parentContainer = ::fwGuiQt::container::QtContainer::dynamicCast(parent);
41  SLM_ASSERT("dynamicCast fwContainer to QtContainer failed", m_parentContainer);
42 
43  QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight);
44  m_parentContainer->setLayout(layout);
45  layout->setContentsMargins(0, 0, 0, 0);
46 
47  Orientation orientation = this->getOrientation();
48 
49  if( orientation == VERTICAL )
50  {
51  layout->setDirection(QBoxLayout::TopToBottom);
52  }
53 
54  const std::list< ViewInfo>& views = this->getViewsInfo();
55  for ( ViewInfo viewInfo : views)
56  {
57  if(viewInfo.m_isSpacer)
58  {
59  layout->addStretch();
60  }
61  else
62  {
63  QWidget* panel;
64  int border = viewInfo.m_border;
65  if(viewInfo.m_caption.first)
66  {
67  QGroupBox* groupbox = new QGroupBox();
68  groupbox->setTitle(QString::fromStdString(viewInfo.m_caption.second));
69  panel = groupbox;
70  border += groupbox->style()->pixelMetric(QStyle::PM_LayoutTopMargin);
71  }
72  else
73  {
74  panel = new QWidget();
75  }
76  panel->setMinimumSize(std::max(viewInfo.m_minSize.first, 0), std::max(viewInfo.m_minSize.second, 0));
77  panel->setContentsMargins(border, border, border, border);
78 
79  ::fwGuiQt::container::QtContainer::sptr subContainer = ::fwGuiQt::container::QtContainer::New();
80  subContainer->setQtContainer(panel);
81  m_subViews.push_back(subContainer);
82 
83  if(viewInfo.m_useScrollBar)
84  {
85  QScrollArea* scrollArea = new QScrollArea();
86  scrollArea->setWidget(panel);
87  scrollArea->setWidgetResizable( true );
88 
89  layout->addWidget( scrollArea );
90  layout->setStretchFactor(scrollArea, viewInfo.m_proportion);
91  }
92  else
93  {
94  layout->addWidget( panel );
95  layout->setStretchFactor(panel, viewInfo.m_proportion);
96  }
97 
98  if(false == viewInfo.m_visible)
99  {
100  subContainer->setVisible(false);
101  }
102  }
103  }
104 }
105 
106 //-----------------------------------------------------------------------------
107 
109 {
110  this->destroySubViews();
111  m_parentContainer->clean();
112 }
113 
114 //-----------------------------------------------------------------------------
115 
116 } // namespace fwGui
117 
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.
Defines the line layout manager.
#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
Orientation
Defines all possible orientation for a LineLayout.
std::vector< ::fwGui::container::fwContainer::sptr > m_subViews
All sub containers managed by this layout.
virtual FWGUIQT_API void destroyLayout() override
Destroy local layout with sub containers.
virtual FWGUI_API void destroySubViews()
Helper to destroy local sub views.
virtual FWGUIQT_API void createLayout(::fwGui::container::fwContainer::sptr parent) override
Instantiate layout with parent container.