CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxViewCollectionWidgetUsingViewContainer.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 
35 #include <QGridLayout>
36 
37 #include "cxViewContainerItem.h"
38 #include "cxViewContainer.h"
39 #include "vtkRenderer.h"
40 #include "vtkRenderWindow.h"
41 #include "cxLogger.h"
42 
43 namespace cx
44 {
45 
47  ViewCollectionWidget(parent),
48  mViewContainer(NULL)
49 {
50  QVBoxLayout* layout = new QVBoxLayout(this);
51  this->setLayout(layout);
52  layout->setSpacing(0);
53  layout->setMargin(0);
54  mViewContainer = new ViewContainer(this);
55  mViewContainer->getGridLayout()->setSpacing(2);
56  mViewContainer->getGridLayout()->setMargin(4);
57  layout->addWidget(mViewContainer);
58 }
59 
61 {
62 }
63 
65 {
66  mViewContainer->show();
67  static int nameGenerator = 0;
68  QString uid = QString("view-%1-%2")
69  .arg(nameGenerator++)
70  .arg(reinterpret_cast<long>(this));
71 
72  ViewItem* viewItem = mViewContainer->addView(uid, region, uid);
73  ViewPtr view = viewItem->getView();
74 
75  viewItem->getView()->setType(type);
76  mViews.push_back(view);
77  return view;
78 }
79 
81 {
82  mViews.clear();
83  mViewContainer->hide();
84  mViewContainer->clear();
85 }
86 
88 {
89  mViewContainer->setModified();
90 }
91 
93 {
94  mViewContainer->renderAll();
95  emit rendered();
96 }
97 
99 {
100  mViewContainer->getGridLayout()->setSpacing(val);
101 }
102 
104 {
105  mViewContainer->getGridLayout()->setMargin(val);
106 }
107 
109 {
110  return mViewContainer->getGridLayout()->spacing();
111 }
112 
114 {
115  return mViewContainer->getGridLayout()->margin();
116 }
117 
119 {
120  return mViews;
121 }
122 
124 {
125  Eigen::Array2i size(view->getRenderWindow()->GetSize());
126  Eigen::Array2i size_renderer(view->getRenderer()->GetSize());
127  Eigen::Array2i p_vc(view->getRenderer()->GetOrigin());
128  p_vc[1] += size_renderer[1] - 1; // upper left corner (add extent = size-1)
129  p_vc[1] = size[1] - p_vc[1] - 1; // flip y axis vtk->qt
130 
131  QPoint p(p_vc[0], p_vc[1]);
132  p = mViewContainer->mapToGlobal(p);
133  p = this->mapFromGlobal(p);
134  return p;
135 }
136 
137 
138 } /* namespace cx */
boost::shared_ptr< class View > ViewPtr
ViewItem * addView(QString uid, LayoutRegion region, QString name="")
virtual void setModified()
void renderAll()
Use this function to render all views at once. Do not call render on each view.
virtual void clear()
virtual QGridLayout * getGridLayout()
ViewRepCollectionPtr getView()