NorMIT-nav  22.09
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
cxGLHelpers.h
cxLogger.h
cx::LayoutWidgetUsingViewWidgets::setGridMargin
virtual void setGridMargin(int val)
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:138
cx::LayoutRegion::span
LayoutPosition span
size of region
Definition: cxLayoutData.h:46
cxMultiViewCache.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::LayoutWidgetUsingViewWidgets::render
virtual void render()
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:88
cx::LayoutWidgetUsingViewWidgets::getOffScreenRendering
virtual bool getOffScreenRendering() const
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:60
cx::LayoutWidgetUsingViewWidgets::getPosition
virtual QPoint getPosition(ViewPtr view)
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:99
cx::LayoutWidgetUsingViewWidgets::clearViews
virtual void clearViews()
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:65
cx::LayoutPosition::col
int col
column
Definition: cxLayoutData.h:37
cx::LayoutWidgetUsingViewWidgets::getGridMargin
virtual int getGridMargin() const
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:148
cx::LayoutWidgetUsingViewWidgets::addView
virtual ViewPtr addView(View::Type type, LayoutRegion region)
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:40
cx::ViewWidget
Definition: cxViewWidget.h:29
cx::LayoutWidgetUsingViewWidgets::setGridSpacing
virtual void setGridSpacing(int val)
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:133
cx::RenderWindowFactoryPtr
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
Definition: cxForwardDeclarations.h:161
cxViewUtilities.h
cx::LayoutWidgetUsingViewWidgets::setModified
virtual void setModified()
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:79
cx::LayoutWidgetUsingViewWidgets::getViews
virtual std::vector< ViewPtr > getViews()
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:153
cx::ViewWidget::setModified
virtual void setModified()
Definition: cxViewWidget.h:50
cx::view_utils::setStretchFactors
void setStretchFactors(QGridLayout *layout, LayoutRegion region, int stretchFactor)
Definition: cxViewUtilities.cpp:20
CX_LOG_ERROR
#define CX_LOG_ERROR
Definition: cxLogger.h:99
cx::LayoutWidgetUsingViewWidgets::setOffScreenRenderingAndClear
virtual void setOffScreenRenderingAndClear(bool on)
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:54
cx::MultiViewCache::create
static MultiViewCachePtr create(RenderWindowFactoryPtr factory)
Definition: cxMultiViewCache.h:47
cx::LayoutRegion
Definition: cxLayoutData.h:40
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::LayoutWidgetUsingViewWidgets::LayoutWidgetUsingViewWidgets
LayoutWidgetUsingViewWidgets(RenderWindowFactoryPtr factory, QWidget *parent)
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:22
cx::LayoutWidgetUsingViewWidgets::getGridSpacing
virtual int getGridSpacing() const
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:143
cx::LayoutWidgetUsingViewWidgets::mViews
std::vector< ViewWidget * > mViews
Definition: cxViewCollectionWidgetUsingViewWidgets.h:60
cxViewCollectionWidgetUsingViewWidgets.h
cx::LayoutWidgetUsingViewWidgets::~LayoutWidgetUsingViewWidgets
virtual ~LayoutWidgetUsingViewWidgets()
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:36
cx::ViewWidget::render
void render()
Definition: cxViewWidget.cpp:66
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::LayoutData::MaxGridSize
static const int MaxGridSize
Definition: cxLayoutData.h:82
cx::LayoutWidgetUsingViewWidgets::enableContextMenuForViews
virtual void enableContextMenuForViews(bool enable)
Definition: cxViewCollectionWidgetUsingViewWidgets.cpp:113
cx::LayoutRegion::pos
LayoutPosition pos
start position of region
Definition: cxLayoutData.h:45
cx::View::Type
Type
Definition: cxView.h:52
cx::ViewCollectionWidget
Definition: cxViewCollectionWidget.h:39