CustusX  2023.01.05-dev+develop.0da12
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) 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 
14 #include <QGridLayout>
15 
16 #include "cxViewContainerItem.h"
17 #include "cxViewContainer.h"
18 #include "vtkRenderer.h"
19 #include "vtkRenderWindow.h"
20 #include "cxLogger.h"
21 
22 namespace cx
23 {
24 
26  ViewCollectionWidget(parent),
27  mViewContainer(NULL)
28 {
29  QVBoxLayout* layout = new QVBoxLayout(this);
30  this->setLayout(layout);
31  layout->setSpacing(0);
32  layout->setMargin(0);
33  mViewContainer = new ViewContainer(factory, this);
34  mViewContainer->getGridLayout()->setSpacing(2);
35  mViewContainer->getGridLayout()->setMargin(4);
36  layout->addWidget(mViewContainer);
37 }
38 
40 {
41 }
42 
44 {
45  mViewContainer->show();
46  static int nameGenerator = 0;
47  QString uid = QString("view-%1-%2")
48  .arg(nameGenerator++)
49  .arg(reinterpret_cast<long>(this));
50 
51  ViewItem* viewItem = mViewContainer->addView(uid, region, uid);
52  ViewPtr view = viewItem->getView();
53 
54  viewItem->getView()->setType(type);
55  mViews.push_back(view);
56  return view;
57 }
58 
60 {
61  this->clearViews();
62  mViewContainer->setOffScreenRenderingAndClear(on);
63 }
64 
66 {
67  return mViewContainer->getOffScreenRendering();
68 }
69 
71 {
72  mViews.clear();
73  mViewContainer->hide();
74  mViewContainer->clear();
75 }
76 
78 {
79  mViewContainer->setModified();
80 }
81 
83 {
84  mViewContainer->renderAll();
85  emit rendered();
86 }
87 
89 {
90  mViewContainer->getGridLayout()->setSpacing(val);
91 }
92 
94 {
95  mViewContainer->getGridLayout()->setMargin(val);
96 }
97 
99 {
100  return mViewContainer->getGridLayout()->spacing();
101 }
102 
104 {
105  return mViewContainer->getGridLayout()->margin();
106 }
107 
109 {
110  return mViews;
111 }
112 
114 {
115  Eigen::Array2i size(view->getRenderWindow()->GetSize());
116  Eigen::Array2i size_renderer(view->getRenderer()->GetSize());
117  Eigen::Array2i p_vc(view->getRenderer()->GetOrigin());
118  p_vc[1] += size_renderer[1] - 1; // upper left corner (add extent = size-1)
119  p_vc[1] = size[1] - p_vc[1] - 1; // flip y axis vtk->qt
120 
121  QPoint p(p_vc[0], p_vc[1]);
122  p = mViewContainer->mapToGlobal(p);
123  p = this->mapFromGlobal(p);
124  return p;
125 }
126 
128 {
129  Qt::ContextMenuPolicy policy = enable ? Qt::CustomContextMenu : Qt::PreventContextMenu;
130  mViewContainer->setContextMenuPolicy(policy);
131 }
132 
133 
134 } /* 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.