Fraxinus  16.5.0-fx-rc4
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxScreenVideoProvider.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 #include "cxScreenVideoProvider.h"
33 
34 #include <QPixmap>
35 #include "cxPatientModelService.h"
36 #include <QtConcurrent>
37 #include <QDesktopWidget>
38 #include <QApplication>
39 #include "cxReporter.h"
40 #include "boost/bind.hpp"
41 #include <QScreen>
42 #include <QVBoxLayout>
43 #include "cxViewService.h"
44 //#include "cxSecondaryViewLayoutWindow.h"
45 #include "cxViewCollectionWidget.h"
46 #include "vtkRenderer.h"
47 #include "vtkWindowToImageFilter.h"
48 #include "vtkRenderWindow.h"
49 #include "vtkPNGWriter.h"
50 #include "vtkUnsignedCharArray.h"
51 #include <QPainter>
53 
54 namespace cx
55 {
56 
58  QWidget(parent),
59  mViewService(viewService),
60  mSecondaryLayoutId(1)
61 {
62  this->setLayout(new QVBoxLayout(this));
63  this->layout()->setMargin(0);
64  this->setWindowTitle("View Layout");
65 }
66 
67 void SecondaryViewLayoutWindow::showEvent(QShowEvent* event)
68 {
69  QWidget* widget = mViewService->createLayoutWidget(this, 1);
70  this->layout()->addWidget(widget);
71  if (mViewService->getActiveLayout(mSecondaryLayoutId).isEmpty())
72  mViewService->setActiveLayout("LAYOUT_OBLIQUE_3DAnyDual_x1", 1);
73 }
74 
75 void SecondaryViewLayoutWindow::hideEvent(QCloseEvent* event)
76 {
77  mViewService->setActiveLayout("", mSecondaryLayoutId);
78 }
79 
80 void SecondaryViewLayoutWindow::closeEvent(QCloseEvent *event)
81 {
82  mViewService->setActiveLayout("", mSecondaryLayoutId);
83 }
84 
85 
86 //---------------------------------------------------------
87 //---------------------------------------------------------
88 //---------------------------------------------------------
89 
91  mServices(services),
92  mWriter(services->patient())
93 {
94 
95 }
96 
97 
98 void ScreenVideoProvider::saveScreenShot(QImage image, QString id)
99 {
100  mWriter.save(image,id);
101 }
102 
104 {
105  QByteArray ba;
106  QBuffer buffer(&ba);
107  buffer.open(QIODevice::WriteOnly);
108  image.save(&buffer, "PNG"); // writes image into ba in PNG format// QString ending = "png";
109  return ba;
110 }
111 
112 QPixmap ScreenVideoProvider::grabScreen(unsigned screenid)
113 {
114  return mWriter.grab(screenid);
115 }
116 
117 
118 \
119 void ScreenVideoProvider::showSecondaryLayout(QSize size, QString layout)
120 {
121 // std::cout << "show window" << std::endl;
122  if (!mSecondaryViewLayoutWindow)
123  mSecondaryViewLayoutWindow = new SecondaryViewLayoutWindow(NULL, mServices->view());
124  mSecondaryViewLayoutWindow->show();
125 
126  this->setWidgetToNiceSizeInLowerRightCorner(size);
127 
128  if (!layout.isEmpty())
129  mServices->view()->setActiveLayout(layout, mSecondaryViewLayoutWindow->mSecondaryLayoutId);
130 }
131 
132 void ScreenVideoProvider::setWidgetToNiceSizeInLowerRightCorner(QSize size)
133 {
134  QDesktopWidget* desktop = qApp->desktop();
135  QList<QScreen*> screens = qApp->screens();
136 
137  QWidget* screen = desktop->screen(desktop->screenNumber(mSecondaryViewLayoutWindow));
138  QRect geo = screen->geometry();
139 
140  if (size.width()==0 || size.height()==0)
141  {
142  size = QSize(geo.width()/3, geo.height()/3);
143  }
144 
145  QRect rect = QRect(QPoint(geo.width()-size.width(),geo.height()-size.height()), size);
146  mSecondaryViewLayoutWindow->setGeometry(rect);
147  rect = mSecondaryViewLayoutWindow->frameGeometry();
148  mSecondaryViewLayoutWindow->move(geo.width()-rect.width(),geo.height()-rect.height());
149 }
150 
152 {
153  mSecondaryViewLayoutWindow->hide();
154  delete mSecondaryViewLayoutWindow;
155 }
156 
158 {
160  if (!widget)
161  return QImage();
162 
163  ViewCollectionImageWriter grabber(widget);
165 }
166 
168 {
169  if (!mSecondaryViewLayoutWindow)
170  return NULL;
171  QWidget* widget = mServices->view()->getLayoutWidget(mSecondaryViewLayoutWindow->mSecondaryLayoutId);
172  ViewCollectionWidget* vcWidget = dynamic_cast<ViewCollectionWidget*>(widget);
173  return vcWidget;
174 }
175 
176 } // namespace cx
QPixmap grab(unsigned screenid)
ScreenVideoProvider(VisServicesPtr services)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
QByteArray generatePNGEncoding(QImage image)
boost::shared_ptr< class ViewService > ViewServicePtr
virtual void closeEvent(QCloseEvent *event)
static QImage vtkImageData2QImage(vtkImageDataPtr input)
Experimental class for IPad usage.
void showSecondaryLayout(QSize size, QString layout)
void save(QImage image, QString id)
class ViewCollectionWidget * getSecondaryLayoutWidget()
cxLogicManager_EXPORT ViewServicePtr viewService()
void saveScreenShot(QImage image, QString id)
virtual void showEvent(QShowEvent *event)
QPixmap grabScreen(unsigned screenid)
virtual void hideEvent(QCloseEvent *event)