Fraxinus  17.12-rc3
An IGT application
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(factory, 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  this->clearViews();
83  mViewContainer->setOffScreenRenderingAndClear(on);
84 }
85 
87 {
88  return mViewContainer->getOffScreenRendering();
89 }
90 
92 {
93  mViews.clear();
94  mViewContainer->hide();
95  mViewContainer->clear();
96 }
97 
99 {
100  mViewContainer->setModified();
101 }
102 
104 {
105  mViewContainer->renderAll();
106  emit rendered();
107 }
108 
110 {
111  mViewContainer->getGridLayout()->setSpacing(val);
112 }
113 
115 {
116  mViewContainer->getGridLayout()->setMargin(val);
117 }
118 
120 {
121  return mViewContainer->getGridLayout()->spacing();
122 }
123 
125 {
126  return mViewContainer->getGridLayout()->margin();
127 }
128 
130 {
131  return mViews;
132 }
133 
135 {
136  Eigen::Array2i size(view->getRenderWindow()->GetSize());
137  Eigen::Array2i size_renderer(view->getRenderer()->GetSize());
138  Eigen::Array2i p_vc(view->getRenderer()->GetOrigin());
139  p_vc[1] += size_renderer[1] - 1; // upper left corner (add extent = size-1)
140  p_vc[1] = size[1] - p_vc[1] - 1; // flip y axis vtk->qt
141 
142  QPoint p(p_vc[0], p_vc[1]);
143  p = mViewContainer->mapToGlobal(p);
144  p = this->mapFromGlobal(p);
145  return p;
146 }
147 
149 {
150  Qt::ContextMenuPolicy policy = enable ? Qt::CustomContextMenu : Qt::PreventContextMenu;
151  mViewContainer->setContextMenuPolicy(policy);
152 }
153 
154 
155 } /* namespace cx */
boost::shared_ptr< class View > ViewPtr
ViewItem * addView(QString uid, LayoutRegion region, QString name="")
ViewCollectionWidgetUsingViewContainer(RenderWindowFactoryPtr factory, QWidget *parent)
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 void setOffScreenRenderingAndClear(bool on)
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
virtual QGridLayout * getGridLayout()
ViewRepCollectionPtr getView()
virtual bool getOffScreenRendering() const
Namespace for all CustusX production code.