NorMIT-nav  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 */
cx::ViewCollectionWidgetUsingViewContainer::~ViewCollectionWidgetUsingViewContainer
virtual ~ViewCollectionWidgetUsingViewContainer()
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:39
cx::ViewCollectionWidgetUsingViewContainer::getPosition
virtual QPoint getPosition(ViewPtr view)
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:113
cxLogger.h
cxViewContainerItem.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::ViewContainer::getOffScreenRendering
virtual bool getOffScreenRendering() const
Definition: cxViewContainer.cpp:120
cx::ViewItem
Definition: cxViewContainerItem.h:38
cx::ViewContainer::addView
ViewItem * addView(QString uid, LayoutRegion region, QString name="")
Definition: cxViewContainer.cpp:99
cx::ViewCollectionWidgetUsingViewContainer::setGridSpacing
virtual void setGridSpacing(int val)
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:88
cx::ViewCollectionWidgetUsingViewContainer::addView
ViewPtr addView(View::Type type, LayoutRegion region)
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:43
cx::ViewContainer::setModified
virtual void setModified()
Definition: cxViewContainer.cpp:78
cx::ViewCollectionWidgetUsingViewContainer::getOffScreenRendering
virtual bool getOffScreenRendering() const
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:65
cx::ViewItem::getView
ViewRepCollectionPtr getView()
Definition: cxViewContainerItem.h:43
cx::RenderWindowFactoryPtr
boost::shared_ptr< class RenderWindowFactory > RenderWindowFactoryPtr
Definition: cxForwardDeclarations.h:163
cx::ViewContainer::getGridLayout
virtual QGridLayout * getGridLayout()
Definition: cxViewContainer.cpp:67
cx::ViewCollectionWidgetUsingViewContainer::clearViews
void clearViews()
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:70
cx::ViewContainer::clear
virtual void clear()
Definition: cxViewContainer.cpp:51
cx::ViewCollectionWidgetUsingViewContainer::setModified
virtual void setModified()
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:77
cx::LayoutRegion
Definition: cxLayoutData.h:40
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::ViewCollectionWidgetUsingViewContainer::getGridSpacing
virtual int getGridSpacing() const
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:98
cx::ViewCollectionWidgetUsingViewContainer::render
virtual void render()
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:82
cx::ViewCollectionWidgetUsingViewContainer::setOffScreenRenderingAndClear
virtual void setOffScreenRenderingAndClear(bool on)
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:59
cx::ViewContainer::setOffScreenRenderingAndClear
virtual void setOffScreenRenderingAndClear(bool on)
Definition: cxViewContainer.cpp:114
cxViewCollectionWidgetUsingViewContainer.h
cx::ViewCollectionWidgetUsingViewContainer::setGridMargin
virtual void setGridMargin(int val)
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:93
cx::ViewCollectionWidgetUsingViewContainer::getGridMargin
virtual int getGridMargin() const
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:103
cx::ViewCollectionWidgetUsingViewContainer::ViewCollectionWidgetUsingViewContainer
ViewCollectionWidgetUsingViewContainer(RenderWindowFactoryPtr factory, QWidget *parent)
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:25
cx::ViewCollectionWidget::rendered
void rendered()
cx::ViewContainer
Definition: cxViewContainer.h:39
cx::ViewCollectionWidgetUsingViewContainer::getViews
virtual std::vector< ViewPtr > getViews()
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:108
cx::ViewContainer::renderAll
void renderAll()
Use this function to render all views at once. Do not call render on each view.
Definition: cxViewContainer.cpp:265
cxViewContainer.h
cx::View::Type
Type
Definition: cxView.h:52
cx::ViewCollectionWidgetUsingViewContainer::enableContextMenuForViews
virtual void enableContextMenuForViews(bool enable)
Definition: cxViewCollectionWidgetUsingViewContainer.cpp:127
cx::ViewCollectionWidget
Definition: cxViewCollectionWidget.h:39