CustusX  22.04-rc2
An IGT application
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) 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 
15 #include <QApplication>
16 #include <QDesktopWidget>
17 #include "cxTypeConversions.h"
18 #include "cxViewService.h"
19 #include "cxLogger.h"
20 #include "cxLogicManager.h"
21 
22 namespace cx
23 {
24 
26  QMainWindow(parent)
27 {
28  this->setWindowTitle("View Layout");
29 }
30 
32 {
33 }
34 
35 void print(QString header, QRect r)
36 {
37  std::cout << header << " (" << r.left() << ", " << r.top() << ", " << r.width() << ", " << r.height() << ")"<< std::endl;
38 }
39 
40 QString SecondaryViewLayoutWindow::toString(QRect r) const
41 {
42  return QString("%1, %2, %3, %4").arg(r.left()).arg(r.top()).arg(r.width()).arg(r.height());
43 }
44 
46 {
47  this->show();
48 
49  int bestScreen = this->findSmallestSecondaryScreen();
50 
51  QDesktopWidget* desktop = QApplication::desktop();
52 
53  if (desktop->primaryScreen()==bestScreen)
54  {
55  report(QString("No secondary screen found. Displaying secondary view layout on primary screen."));
56  }
57  else
58  {
59  QRect rect = desktop->screenGeometry(bestScreen);
60  report(QString("Displaying secondary view layout on fullscreen %1 of %2, size=[%3]")
61  .arg(bestScreen+1)
62  .arg(desktop->screenCount())
63  .arg(this->toString(rect)));
64  this->setGeometry(rect);
65  this->move(rect.topLeft());
66  this->setWindowState(this->windowState() | Qt::WindowFullScreen);
67  }
68 }
69 
70 int SecondaryViewLayoutWindow::findSmallestSecondaryScreen()
71 {
72  QDesktopWidget* desktop = QApplication::desktop();
73 
74  int best = 0;
75  for (int i=1; i<desktop->screenCount(); ++i)
76  {
77  if (desktop->primaryScreen()==i)
78  continue;
79  QRect last = desktop->screenGeometry(best);
80  QRect current = desktop->screenGeometry(i);
81  if (current.height()*current.width() < last.height()*last.width())
82  best = i;
83  if (desktop->primaryScreen()==best)
84  best = i;
85  }
86 
87  return best;
88 }
89 
90 void SecondaryViewLayoutWindow::showEvent(QShowEvent* event)
91 {
92  this->setCentralWidget(logicManager()->getViewService()->createLayoutWidget(this, 1));
93  if (logicManager()->getViewService()->getActiveLayout(1).isEmpty())
94  logicManager()->getViewService()->setActiveLayout("LAYOUT_OBLIQUE_3DAnyDual_x1", 1);
95 }
96 
97 void SecondaryViewLayoutWindow::hideEvent(QCloseEvent* event)
98 {
99  logicManager()->getViewService()->setActiveLayout("", 1);
100 }
101 
103 {
104  logicManager()->getViewService()->setActiveLayout("", 1);
105 }
106 
107 } // namespace cx
108 
virtual void closeEvent(QCloseEvent *event)
LogicManager * logicManager()
void report(QString msg)
Definition: cxLogger.cpp:69
ViewServicePtr getViewService()
virtual void showEvent(QShowEvent *event)
void print(QString header, QRect r)
virtual void hideEvent(QCloseEvent *event)
Namespace for all CustusX production code.