NorMIT-nav  22.09
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 
cx::logicManager
LogicManager * logicManager()
Definition: cxLogicManager.cpp:46
cxLogger.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::print
void print(QString header, QRect r)
Definition: cxSecondaryViewLayoutWindow.cpp:35
cx::report
void report(QString msg)
Definition: cxLogger.cpp:69
cx::SecondaryViewLayoutWindow::showEvent
virtual void showEvent(QShowEvent *event)
Definition: cxSecondaryViewLayoutWindow.cpp:90
cx::SecondaryViewLayoutWindow::closeEvent
virtual void closeEvent(QCloseEvent *event)
Definition: cxSecondaryViewLayoutWindow.cpp:102
cxSecondaryViewLayoutWindow.h
cxViewService.h
cxTypeConversions.h
cx::LogicManager::getViewService
ViewServicePtr getViewService()
Definition: cxLogicManager.cpp:273
cx::SecondaryViewLayoutWindow::~SecondaryViewLayoutWindow
~SecondaryViewLayoutWindow()
Definition: cxSecondaryViewLayoutWindow.cpp:31
cxLogicManager.h
cx::SecondaryViewLayoutWindow::hideEvent
virtual void hideEvent(QCloseEvent *event)
Definition: cxSecondaryViewLayoutWindow.cpp:97
cx::SecondaryViewLayoutWindow::tryShowOnSecondaryScreen
void tryShowOnSecondaryScreen()
Definition: cxSecondaryViewLayoutWindow.cpp:45
cx::SecondaryViewLayoutWindow::SecondaryViewLayoutWindow
SecondaryViewLayoutWindow(QWidget *parent)
Definition: cxSecondaryViewLayoutWindow.cpp:25