Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxViewCollectionWidgetUsingViewWidgets.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 "cxGLHelpers.h"
14 #include "cxViewUtilities.h"
15 #include "cxLogger.h"
16 #include "vtkRenderWindow.h"
17 #include "cxMultiViewCache.h"
18 
19 namespace cx
20 {
21 
23  ViewCollectionWidget(parent)
24 {
25  mViewCache = MultiViewCache::create(factory);
26  mOffScreenRendering = false;
27 
28  mLayout = new QGridLayout;
29 
30  mLayout->setSpacing(2);
31  mLayout->setMargin(4);
32 
33  this->setLayout(mLayout);
34 }
35 
37 {
38 }
39 
41 {
42  ViewWidget* view = mViewCache->retrieveView(this, type, mOffScreenRendering);
43 
44  view->getView()->setType(type);
45 
46  mLayout->addWidget(view, region.pos.row, region.pos.col, region.span.row, region.span.col);
47  view_utils::setStretchFactors(mLayout, region, 1);
48  view->show();
49 
50  mViews.push_back(view);
51  return view->getView();
52 }
53 
55 {
56  this->clearViews();
57  mOffScreenRendering = on;
58 }
59 
61 {
62  return mOffScreenRendering;
63 }
64 
66 {
67  mViewCache->clearViews();
68 
69  for (unsigned i=0; i<mViews.size(); ++i)
70  {
71  mViews[i]->hide();
72  mLayout->removeWidget(mViews[i]);
73  }
74  mViews.clear();
75 
77 }
78 
80 {
81  for (unsigned i=0; i<mViews.size(); ++i)
82  {
83  ViewWidget* current = mViews[i];
84  current->setModified();
85  }
86 }
87 
89 {
90  for (unsigned i=0; i<mViews.size(); ++i)
91  {
92  ViewWidget* current = mViews[i];
93  current->render(); // render only changed scenegraph (shaky but smooth)
94  }
95 
96  emit rendered();
97 }
98 
100 {
101  ViewWidget* widget = this->WidgetFromView(view);
102  if (!widget)
103  {
104  CX_LOG_ERROR() << "Did not find view in layout " << view->getUid();
105  return QPoint(0,0);
106  }
107 
108  QPoint p = widget->mapToGlobal(QPoint(0,0));
109  p = this->mapFromGlobal(p);
110  return p;
111 }
112 
114 {
115  Qt::ContextMenuPolicy policy = enable ? Qt::CustomContextMenu : Qt::PreventContextMenu;
116  for (unsigned i=0; i<mViews.size(); ++i)
117  {
118  mViews[i]->setContextMenuPolicy(policy);
119  }
120 }
121 
122 ViewWidget* LayoutWidgetUsingViewWidgets::WidgetFromView(ViewPtr view)
123 {
124  for (unsigned i=0; i<mViews.size(); ++i)
125  {
126  ViewWidget* current = mViews[i];
127  if (current->getView()==view)
128  return current;
129  }
130  return NULL;
131 }
132 
134 {
135  mLayout->setSpacing(val);
136 }
137 
139 {
140  mLayout->setMargin(val);
141 }
142 
144 {
145  return mLayout->spacing();
146 }
147 
149 {
150  return mLayout->margin();
151 }
152 
154 {
155  std::vector<ViewPtr> retval;
156  for (unsigned i=0; i<mViews.size(); ++i)
157  retval.push_back(mViews[i]->getView());
158  return retval;
159 }
160 
161 } // cx
LayoutWidgetUsingViewWidgets(RenderWindowFactoryPtr factory, QWidget *parent)
virtual ViewPtr addView(View::Type type, LayoutRegion region)
LayoutPosition span
size of region
Definition: cxLayoutData.h:46
boost::shared_ptr< class View > ViewPtr
#define CX_LOG_ERROR
Definition: cxLogger.h:99
ViewRepCollectionPtr getView()
void setStretchFactors(QGridLayout *layout, LayoutRegion region, int stretchFactor)
static MultiViewCachePtr create(RenderWindowFactoryPtr factory)
static const int MaxGridSize
Definition: cxLayoutData.h:82
LayoutPosition pos
start position of region
Definition: cxLayoutData.h:45
virtual void setModified()
Definition: cxViewWidget.h:50
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
Namespace for all CustusX production code.