CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
38 namespace cx
39 {
40 
42  ViewCollectionWidget(parent)
43 {
44  mLayout = new QGridLayout;
45 
46  mLayout->setSpacing(2);
47  mLayout->setMargin(4);
48 
49  this->setLayout(mLayout);
50 
51  mViewCache2D.reset(new ViewCache<ViewWidget>(this, "View2D"));
52  mViewCache3D.reset(new ViewCache<ViewWidget>(this, "View3D"));
53  mViewCacheRT.reset(new ViewCache<ViewWidget>(this, "ViewRT"));
54  mViewCache.reset(new ViewCache<ViewWidget>(this, "View"));
55 }
56 
58 {
59 }
60 
62 {
63  ViewWidget* view = this->retrieveView(type);
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 
75 ViewWidget* LayoutWidgetUsingViewWidgets::retrieveView(View::Type type)
76 {
77  if (type == View::VIEW_2D)
78  return this->mViewCache2D->retrieveView();
79  else if (type == View::VIEW_3D)
80  return this->mViewCache3D->retrieveView();
81  else if (type == View::VIEW_REAL_TIME)
82  return this->mViewCacheRT->retrieveView();
83  return this->mViewCache->retrieveView();
84 }
85 
87 {
88  mViewCache2D->clearUsedViews();
89  mViewCache3D->clearUsedViews();
90  mViewCacheRT->clearUsedViews();
91 
92  for (unsigned i=0; i<mViews.size(); ++i)
93  {
94  mViews[i]->hide();
95  mLayout->removeWidget(mViews[i]);
96  }
97  mViews.clear();
98 
99  view_utils::setStretchFactors(mLayout, LayoutRegion(0, 0, 10, 10), 0);
100 }
101 
103 {
104  for (unsigned i=0; i<mViews.size(); ++i)
105  {
106  ViewWidget* current = mViews[i];
107  current->setModified();
108  }
109 }
110 
112 {
113  for (unsigned i=0; i<mViews.size(); ++i)
114  {
115  ViewWidget* current = mViews[i];
116  current->render(); // render only changed scenegraph (shaky but smooth)
117  }
118 
119  emit rendered();
120 }
121 
123 {
124  ViewWidget* widget = this->WidgetFromView(view);
125  if (!widget)
126  {
127  CX_LOG_ERROR() << "Did not find view in layout " << view->getUid();
128  return QPoint(0,0);
129  }
130 
131  QPoint p = widget->mapToGlobal(QPoint(0,0));
132  p = this->mapFromGlobal(p);
133  return p;
134 }
135 
136 ViewWidget* LayoutWidgetUsingViewWidgets::WidgetFromView(ViewPtr view)
137 {
138  for (unsigned i=0; i<mViews.size(); ++i)
139  {
140  ViewWidget* current = mViews[i];
141  if (current->getView()==view)
142  return current;
143  }
144  return NULL;
145 }
146 
148 {
149  mLayout->setSpacing(val);
150 }
151 
153 {
154  mLayout->setMargin(val);
155 }
156 
158 {
159  return mLayout->spacing();
160 }
161 
163 {
164  return mLayout->margin();
165 }
166 
168 {
169  std::vector<ViewPtr> retval;
170  for (unsigned i=0; i<mViews.size(); ++i)
171  retval.push_back(mViews[i]->getView());
172  return retval;
173 }
174 
175 } // cx
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:114
ViewRepCollectionPtr getView()
void setStretchFactors(QGridLayout *layout, LayoutRegion region, int stretchFactor)
LayoutPosition pos
start position of region
Definition: cxLayoutData.h:66
virtual void setModified()
Definition: cxViewWidget.h:70