NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSecondaryViewLayoutWindow.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 
36 #include <QApplication>
37 #include <QDesktopWidget>
38 #include "cxTypeConversions.h"
39 #include "cxLegacySingletons.h"
40 #include "cxViewService.h"
41 #include "cxLogger.h"
42 
43 namespace cx
44 {
45 
47  QMainWindow(parent)
48 {
49  this->setWindowTitle("View Layout");
50 }
51 
53 {
54 }
55 
56 void print(QString header, QRect r)
57 {
58  std::cout << header << " (" << r.left() << ", " << r.top() << ", " << r.width() << ", " << r.height() << ")"<< std::endl;
59 }
60 
61 QString SecondaryViewLayoutWindow::toString(QRect r) const
62 {
63  return QString("%1, %2, %3, %4").arg(r.left()).arg(r.top()).arg(r.width()).arg(r.height());
64 }
65 
67 {
68  this->show();
69 
70  int bestScreen = this->findSmallestSecondaryScreen();
71 
72  QDesktopWidget* desktop = QApplication::desktop();
73 
74  if (desktop->primaryScreen()==bestScreen)
75  {
76  report(QString("No secondary screen found. Displaying secondary view layout on primary screen."));
77  }
78  else
79  {
80  QRect rect = desktop->screenGeometry(bestScreen);
81  report(QString("Displaying secondary view layout on fullscreen %1 of %2, size=[%3]")
82  .arg(bestScreen+1)
83  .arg(desktop->screenCount())
84  .arg(this->toString(rect)));
85  this->setGeometry(rect);
86  this->move(rect.topLeft());
87  this->setWindowState(this->windowState() | Qt::WindowFullScreen);
88  }
89 }
90 
91 int SecondaryViewLayoutWindow::findSmallestSecondaryScreen()
92 {
93  QDesktopWidget* desktop = QApplication::desktop();
94 
95  int best = 0;
96  for (int i=1; i<desktop->screenCount(); ++i)
97  {
98  if (desktop->primaryScreen()==i)
99  continue;
100  QRect last = desktop->screenGeometry(best);
101  QRect current = desktop->screenGeometry(i);
102  if (current.height()*current.width() < last.height()*last.width())
103  best = i;
104  if (desktop->primaryScreen()==best)
105  best = i;
106  }
107 
108  return best;
109 }
110 
112 {
113  this->setCentralWidget(viewService()->createLayoutWidget(this, 1));
114  if (viewService()->getActiveLayout(1).isEmpty())
115  viewService()->setActiveLayout("LAYOUT_OBLIQUE_3DAnyDual_x1", 1);
116 }
117 
118 void SecondaryViewLayoutWindow::hideEvent(QCloseEvent* event)
119 {
120  viewService()->setActiveLayout("", 1);
121 }
122 
124 {
125  viewService()->setActiveLayout("", 1);
126 }
127 
128 } // namespace cx
129 
virtual void closeEvent(QCloseEvent *event)
cxLogicManager_EXPORT ViewServicePtr viewService()
void report(QString msg)
Definition: cxLogger.cpp:90
virtual void showEvent(QShowEvent *event)
void print(QString header, QRect r)
virtual void hideEvent(QCloseEvent *event)