Fraxinus  18.10
An IGT application
cxLogConsole.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 
12 #include "cxLogConsole.h"
13 
14 #include <QDesktopWidget>
15 #include <QApplication>
16 #include <QFileDialog>
17 #include <QAction>
18 #include <QMenu>
19 #include <QMenuBar>
20 
22 #include "cxDataLocations.h"
23 #include "cxLogFileWatcher.h"
24 
25 namespace cx
26 {
27 
29 {
30  QString optionsFile = cx::DataLocations::getPersistentWritablePath()+"/logconsole.xml";
31  mOptions = cx::XmlOptionFile(optionsFile);
32  CX_LOG_INFO() << "Options file: " << optionsFile;
34  CX_LOG_INFO() << "Log folder: " << mLog->getLoggingFolder();
35 
36  this->createMenus();
37 
38  this->updateWindowTitle();
39 
40  cx::ConsoleWidgetCollection* consoles = new cx::ConsoleWidgetCollection(NULL, "ConsoleWidgets", "Consoles", mOptions, mLog);
41  this->setCentralWidget(consoles);
42 
43  this->initializeGeometry();
44 }
45 
46 void LogConsole::initializeGeometry()
47 {
48  if (!this->restoreGeometry(this->getGeometryOption().readVariant().toByteArray()))
49  this->setDefaultGeometry();
50 }
51 
52 void LogConsole::setDefaultGeometry()
53 {
54  QDesktopWidget* desktop = dynamic_cast<QApplication*>(QApplication::instance())->desktop();
55  QRect screen = desktop->screenGeometry(desktop->primaryScreen());
56  screen.adjust(screen.width()*0.5, screen.height()*0.25, 0, 0);
57  this->setGeometry(screen);
58 }
59 
60 XmlOptionItem LogConsole::getGeometryOption()
61 {
62  return XmlOptionItem("geometry", mOptions.getElement());
63 }
64 
66 {
67  this->getGeometryOption().writeVariant(this->saveGeometry());
68 
69  mOptions.save();
70 }
71 
72 void LogConsole::createMenus()
73 {
74  //data
75  QAction* selectFolderAction = new QAction(QIcon(":/icons/open_icon_library/document-import-2.png"), tr("&Select folder"), this);
76  selectFolderAction->setShortcut(tr("Ctrl+L"));
77  selectFolderAction->setStatusTip(tr("Select folder"));
78  connect(selectFolderAction, &QAction::triggered, this, &LogConsole::onSelectFolder);
79 
80  QMenu* fileMenu = new QMenu(tr("File"), this);
81  fileMenu->addAction(selectFolderAction);
82  this->menuBar()->addMenu(fileMenu);
83 }
84 
85 void LogConsole::updateWindowTitle()
86 {
87  QString title = QString("Log Console [%1]").arg(mLog->getLoggingFolder());
88  this->setWindowTitle(title);
89 }
90 
91 void LogConsole::onSelectFolder()
92 {
93  QString folder = mLog->getLoggingFolder() + "/..";
94 
95  folder = QFileDialog::getExistingDirectory(this, "Open log folder", folder);
96  if (folder.isEmpty())
97  {
98  return;
99  }
100 
101  mLog->setLoggingFolder(folder);
102  this->updateWindowTitle();
103 }
104 
105 
106 } // namespace cx
void writeVariant(const QVariant &val)
#define CX_LOG_INFO
Definition: cxLogger.h:96
QDomElement getElement()
return the current element
Helper class for storing one string value in an xml document.
static QString getPersistentWritablePath()
Path to location usable for persistent and temporary storage of config. Do not use directly...
void save()
save entire document.
Helper class for xml files used to store ssc/cx data.
static LogFileWatcherPtr create()
Namespace for all CustusX production code.