Fraxinus  17.12-rc2
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 #include "cxGLHelpers.h"
35 #include "cxViewUtilities.h"
36 #include "cxLogger.h"
37 #include "vtkRenderWindow.h"
38 #include "cxMultiViewCache.h"
39 
40 namespace cx
41 {
42 
44  ViewCollectionWidget(parent)
45 {
46  mViewCache = MultiViewCache::create(factory);
47  mOffScreenRendering = false;
48 
49  mLayout = new QGridLayout;
50 
51  mLayout->setSpacing(2);
52  mLayout->setMargin(4);
53 
54  this->setLayout(mLayout);
55 }
56 
58 {
59 }
60 
62 {
63  ViewWidget* view = mViewCache->retrieveView(this, type, mOffScreenRendering);
64 
65  view->getView()->setType(type);
66 
67  mLayout->addWidget(view, region.pos.row, region.pos.col, region.span.row, region.span.col);
68  view_utils::setStretchFactors(mLayout, region, 1);
69  view->show();
70 
71  mViews.push_back(view);
72  return view->getView();
73 }
74 
76 {
77  this->clearViews();
78  mOffScreenRendering = on;
79 }
80 
82 {
83  return mOffScreenRendering;
84 }
85 
87 {
88  mViewCache->clearViews();
89 
90  for (unsigned i=0; i<mViews.size(); ++i)
91  {
92  mViews[i]->hide();
93  mLayout->removeWidget(mViews[i]);
94  }
95  mViews.clear();
96 
98 }
99 
101 {
102  for (unsigned i=0; i<mViews.size(); ++i)
103  {
104  ViewWidget* current = mViews[i];
105  current->setModified();
106  }
107 }
108 
110 {
111  for (unsigned i=0; i<mViews.size(); ++i)
112  {
113  ViewWidget* current = mViews[i];
114  current->render(); // render only changed scenegraph (shaky but smooth)
115  }
116 
117  emit rendered();
118 }
119 
121 {
122  ViewWidget* widget = this->WidgetFromView(view);
123  if (!widget)
124  {
125  CX_LOG_ERROR() << "Did not find view in layout " << view->getUid();
126  return QPoint(0,0);
127  }
128 
129  QPoint p = widget->mapToGlobal(QPoint(0,0));
130  p = this->mapFromGlobal(p);
131  return p;
132 }
133 
135 {
136  Qt::ContextMenuPolicy policy = enable ? Qt::CustomContextMenu : Qt::PreventContextMenu;
137  for (unsigned i=0; i<mViews.size(); ++i)
138  {
139  mViews[i]->setContextMenuPolicy(policy);
140  }
141 }
142 
143 ViewWidget* LayoutWidgetUsingViewWidgets::WidgetFromView(ViewPtr view)
144 {
145  for (unsigned i=0; i<mViews.size(); ++i)
146  {
147  ViewWidget* current = mViews[i];
148  if (current->getView()==view)
149  return current;
150  }
151  return NULL;
152 }
153 
155 {
156  mLayout->setSpacing(val);
157 }
158 
160 {
161  mLayout->setMargin(val);
162 }
163 
165 {
166  return mLayout->spacing();
167 }
168 
170 {
171  return mLayout->margin();
172 }
173 
175 {
176  std::vector<ViewPtr> retval;
177  for (unsigned i=0; i<mViews.size(); ++i)
178  retval.push_back(mViews[i]->getView());
179  return retval;
180 }
181 
182 } // cx
LayoutWidgetUsingViewWidgets(RenderWindowFactoryPtr factory, QWidget *parent)
virtual ViewPtr addView(View::Type type, LayoutRegion region)
LayoutPosition span
size of region
Definition: cxLayoutData.h:67
boost::shared_ptr< class View > ViewPtr
#define CX_LOG_ERROR
Definition: cxLogger.h:120
ViewRepCollectionPtr getView()
void setStretchFactors(QGridLayout *layout, LayoutRegion region, int stretchFactor)
static MultiViewCachePtr create(RenderWindowFactoryPtr factory)
static const int MaxGridSize
Definition: cxLayoutData.h:103
LayoutPosition pos
start position of region
Definition: cxLayoutData.h:66
virtual void setModified()
Definition: cxViewWidget.h:71
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
Namespace for all CustusX production code.