NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxViewCollectionWidgetMixed.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include <QGridLayout>
16 #include "cxViewUtilities.h"
17 #include "vtkRenderWindow.h"
18 #include "cxGLHelpers.h"
19 #include "cxLogger.h"
20 #include "cxMultiViewCache.h"
21 #include "cxRenderWindowFactory.h"
22 
23 namespace cx
24 {
25 
27  ViewCollectionWidget(parent)
28 {
29  mLayout = new QGridLayout(this);
30  this->setLayout(mLayout);
31  mViewCache = MultiViewCache::create(factory);
32 
34  this->initBaseLayout();
35  this->setGridMargin(4);
36  this->setGridSpacing(2);
37 }
38 
40 {
41 }
42 
43 void ViewCollectionWidgetMixed::initBaseLayout()
44 {
45  this->addWidgetToLayout(mLayout, mBaseLayout, LayoutRegion(0,0));
46  mBaseRegion = LayoutRegion(-1,-1);
47  mTotalRegion = LayoutRegion(-1,-1);
48 }
49 
51 {
52  ViewPtr view;
53  mTotalRegion = merge(region, mTotalRegion);
54 
55  if (type==View::VIEW_3D)
56  {
57  //Using cached 3D view don't work if mBaseRegion covers the 3D view region (In some cases.) CX-63
58  this->mViewCache->clearCache();
59  ViewWidget* overlay = this->mViewCache->retrieveView(this, View::VIEW_3D, mBaseLayout->getOffScreenRendering());
60  overlay->getView()->setType(type);
61  overlay->show();
62  mOverlays.push_back(overlay);
63  view = overlay->getView();
64  this->addWidgetToLayout(mLayout, overlay, region);
65  }
66  else
67  {
68  mBaseRegion = merge(region, mBaseRegion);
69  view = mBaseLayout->addView(type, region);
70 
71  // re-add the base widget with updated position in grid
72  this->addWidgetToLayout(mLayout, mBaseLayout, mBaseRegion);
73  }
74  view_utils::setStretchFactors(mLayout, mTotalRegion, 1);
75 
76  return view;
77 }
78 
80 {
81  this->clearViews();
83 }
84 
86 {
88 }
89 
90 void ViewCollectionWidgetMixed::addWidgetToLayout(QGridLayout* layout, QWidget* widget, LayoutRegion region)
91 {
92  layout->addWidget(widget,
93  region.pos.row, region.pos.col,
94  region.span.row, region.span.col);
95 }
96 
98 {
99  mViewCache->clearViews();
100 
101  for (unsigned i=0; i<mOverlays.size(); ++i)
102  {
103  mOverlays[i]->hide();
104  mLayout->removeWidget(mOverlays[i]);
105  }
106  mOverlays.clear();
107 
109  mLayout->removeWidget(mBaseLayout);
110 
111  // rebuild to default state:
112  view_utils::setStretchFactors(mLayout, mTotalRegion, 0);
113  this->initBaseLayout();
114 }
115 
117 {
119  for (unsigned i=0; i<mOverlays.size(); ++i)
120  mOverlays[i]->setModified();
121 }
122 
124 {
125  mBaseLayout->render();
126 
127  for (unsigned i=0; i<mOverlays.size(); ++i)
128  {
129  mOverlays[i]->render();
130  }
131 
132  emit rendered();
133 }
134 
136 {
137  mLayout->setSpacing(val);
139 }
140 
142 {
144  mLayout->setMargin(val);
145 }
146 
148 {
149  return mLayout->spacing();
150 }
151 
153 {
154  return mLayout->margin();
155 }
156 
157 
159 {
160  std::vector<ViewPtr> retval = mBaseLayout->getViews();
161  for (unsigned i=0; i<mOverlays.size(); ++i)
162  retval.push_back(mOverlays[i]->getView());
163  return retval;
164 }
165 
167 {
168  for (unsigned i=0; i<mOverlays.size(); ++i)
169  {
170  if (mOverlays[i]->getView()==view)
171  {
172  QPoint p = mOverlays[i]->mapToGlobal(QPoint(0,0));
173  p = this->mapFromGlobal(p);
174  return p;
175  }
176  }
177 
178  QPoint p = mBaseLayout->getPosition(view);
179  p = mBaseLayout->mapToGlobal(p);
180  p = this->mapFromGlobal(p);
181  return p;
182 }
183 
185 {
187  Qt::ContextMenuPolicy policy = enable ? Qt::CustomContextMenu : Qt::PreventContextMenu;
188  for (unsigned i=0; i<mOverlays.size(); ++i)
189  {
190  mOverlays[i]->setContextMenuPolicy(policy);
191  }
192 }
193 
194 } /* namespace cx */
cx::ViewCollectionWidget::getViews
virtual std::vector< ViewPtr > getViews()=0
cx::ViewCollectionWidgetMixed::mBaseLayout
ViewCollectionWidget * mBaseLayout
Definition: cxViewCollectionWidgetMixed.h:75
cx::ViewCollectionWidgetMixed::setModified
virtual void setModified()
Definition: cxViewCollectionWidgetMixed.cpp:116
cxGLHelpers.h
cxLogger.h
cx::ViewCollectionWidgetMixed::addView
ViewPtr addView(View::Type type, LayoutRegion region)
Definition: cxViewCollectionWidgetMixed.cpp:50
cx::LayoutRegion::span
LayoutPosition span
size of region
Definition: cxLayoutData.h:46
cxMultiViewCache.h
cx::ViewCollectionWidgetUsingViewContainer
Definition: cxViewCollectionWidgetUsingViewContainer.h:35
cx::ViewCollectionWidgetMixed::clearViews
virtual void clearViews()
Definition: cxViewCollectionWidgetMixed.cpp:97
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ViewCollectionWidgetMixed::getOffScreenRendering
virtual bool getOffScreenRendering() const
Definition: cxViewCollectionWidgetMixed.cpp:85
cx::View::VIEW_3D
@ VIEW_3D
Definition: cxView.h:54
cx::ViewCollectionWidgetMixed::~ViewCollectionWidgetMixed
virtual ~ViewCollectionWidgetMixed()
Definition: cxViewCollectionWidgetMixed.cpp:39
cx::ViewCollectionWidget::enableContextMenuForViews
virtual void enableContextMenuForViews(bool enable)=0
cx::LayoutPosition::col
int col
column
Definition: cxLayoutData.h:37
cx::ViewCollectionWidgetMixed::enableContextMenuForViews
virtual void enableContextMenuForViews(bool enable)
Definition: cxViewCollectionWidgetMixed.cpp:184
cx::merge
LayoutRegion merge(LayoutRegion a, LayoutRegion b)
Definition: cxLayoutData.cpp:22
cx::ViewCollectionWidget::addView
virtual ViewPtr addView(View::Type type, LayoutRegion region)=0
cx::ViewWidget
Definition: cxViewWidget.h:29
cx::ViewCollectionWidgetMixed::setOffScreenRenderingAndClear
virtual void setOffScreenRenderingAndClear(bool on)
Definition: cxViewCollectionWidgetMixed.cpp:79
cx::ViewCollectionWidgetMixed::getPosition
virtual QPoint getPosition(ViewPtr view)
Definition: cxViewCollectionWidgetMixed.cpp:166
cx::RenderWindowFactoryPtr
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
Definition: cxForwardDeclarations.h:163
cxViewUtilities.h
cx::ViewCollectionWidget::clearViews
virtual void clearViews()=0
cx::ViewCollectionWidget::setModified
virtual void setModified()=0
cx::ViewCollectionWidgetMixed::ViewCollectionWidgetMixed
ViewCollectionWidgetMixed(RenderWindowFactoryPtr factory, QWidget *parent)
Definition: cxViewCollectionWidgetMixed.cpp:26
cxViewCollectionWidgetMixed.h
cx::ViewCollectionWidgetMixed::render
virtual void render()
Definition: cxViewCollectionWidgetMixed.cpp:123
cx::ViewCollectionWidget::getOffScreenRendering
virtual bool getOffScreenRendering() const =0
cxRenderWindowFactory.h
cx::view_utils::setStretchFactors
void setStretchFactors(QGridLayout *layout, LayoutRegion region, int stretchFactor)
Definition: cxViewUtilities.cpp:20
cx::ViewCollectionWidgetMixed::getGridMargin
virtual int getGridMargin() const
Definition: cxViewCollectionWidgetMixed.cpp:152
cx::MultiViewCache::create
static MultiViewCachePtr create(RenderWindowFactoryPtr factory)
Definition: cxMultiViewCache.h:47
cx::LayoutRegion
Definition: cxLayoutData.h:40
cx::ViewCollectionWidgetMixed::setGridMargin
virtual void setGridMargin(int val)
Definition: cxViewCollectionWidgetMixed.cpp:141
cx::ViewCollectionWidget::render
virtual void render()=0
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::ViewCollectionWidget::setOffScreenRenderingAndClear
virtual void setOffScreenRenderingAndClear(bool on)=0
cx::ViewCollectionWidget::getPosition
virtual QPoint getPosition(ViewPtr view)=0
cx::ViewCollectionWidget::setGridSpacing
virtual void setGridSpacing(int val)=0
cxViewCollectionWidgetUsingViewWidgets.h
cx::ViewCollectionWidgetMixed::getViews
virtual std::vector< ViewPtr > getViews()
Definition: cxViewCollectionWidgetMixed.cpp:158
cx::ViewCollectionWidget::setGridMargin
virtual void setGridMargin(int val)=0
cxViewCollectionWidgetUsingViewContainer.h
cx::ViewWidget::getView
ViewRepCollectionPtr getView()
Definition: cxViewWidget.cpp:51
cx::ViewCollectionWidget::rendered
void rendered()
cx::LayoutPosition::row
int row
row
Definition: cxLayoutData.h:36
cx::LayoutRegion::pos
LayoutPosition pos
start position of region
Definition: cxLayoutData.h:45
cx::View::Type
Type
Definition: cxView.h:52
cx::ViewCollectionWidgetMixed::setGridSpacing
virtual void setGridSpacing(int val)
Definition: cxViewCollectionWidgetMixed.cpp:135
cx::ViewCollectionWidgetMixed::getGridSpacing
virtual int getGridSpacing() const
Definition: cxViewCollectionWidgetMixed.cpp:147
cx::ViewCollectionWidget
Definition: cxViewCollectionWidget.h:39