CustusX  15.4.0-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
33 #include "cxLogConsole.h"
34 
35 #include <QDesktopWidget>
36 #include <QApplication>
37 #include <QFileDialog>
38 #include <QAction>
39 #include <QMenu>
40 #include <QMenuBar>
41 
43 #include "cxDataLocations.h"
44 #include "cxLogFileWatcher.h"
45 
46 namespace cx
47 {
48 
50 {
51  QString optionsFile = cx::DataLocations::getPersistentWritablePath()+"/logconsole.xml";
52  mOptions = cx::XmlOptionFile(optionsFile);
53  CX_LOG_INFO() << "Options file: " << optionsFile;
55  CX_LOG_INFO() << "Log folder: " << mLog->getLoggingFolder();
56 
57  this->createMenus();
58 
59  this->updateWindowTitle();
60 
61  cx::ConsoleWidgetCollection* consoles = new cx::ConsoleWidgetCollection(NULL, "ConsoleWidgets", "Consoles", mOptions, mLog);
62  this->setCentralWidget(consoles);
63 
64  this->initializeGeometry();
65 }
66 
67 void LogConsole::initializeGeometry()
68 {
69  if (!this->restoreGeometry(this->getGeometryOption().readVariant().toByteArray()))
70  this->setDefaultGeometry();
71 }
72 
73 void LogConsole::setDefaultGeometry()
74 {
75  QDesktopWidget* desktop = dynamic_cast<QApplication*>(QApplication::instance())->desktop();
76  QScreen* screen__ = qApp->screens()[0];
77  QRect screen = desktop->screenGeometry(desktop->primaryScreen());
78  screen.adjust(screen.width()*0.5, screen.height()*0.25, 0, 0);
79  this->setGeometry(screen);
80 }
81 
82 XmlOptionItem LogConsole::getGeometryOption()
83 {
84  return XmlOptionItem("geometry", mOptions.getElement());
85 }
86 
88 {
89  this->getGeometryOption().writeVariant(this->saveGeometry());
90 
91  mOptions.save();
92 }
93 
94 void LogConsole::createMenus()
95 {
96  //data
97  QAction* selectFolderAction = new QAction(QIcon(":/icons/open_icon_library/document-import-2.png"), tr("&Select folder"), this);
98  selectFolderAction->setShortcut(tr("Ctrl+L"));
99  selectFolderAction->setStatusTip(tr("Select folder"));
100  connect(selectFolderAction, &QAction::triggered, this, &LogConsole::onSelectFolder);
101 
102  QMenu* fileMenu = new QMenu(tr("File"), this);
103  fileMenu->addAction(selectFolderAction);
104  this->menuBar()->addMenu(fileMenu);
105 }
106 
107 void LogConsole::updateWindowTitle()
108 {
109  QString title = QString("Log Console [%1]").arg(mLog->getLoggingFolder());
110  this->setWindowTitle(title);
111 }
112 
113 void LogConsole::onSelectFolder()
114 {
115  QString folder = mLog->getLoggingFolder() + "/..";
116 
117  folder = QFileDialog::getExistingDirectory(this, "Open log folder", folder);
118  if (folder.isEmpty())
119  {
120  return;
121  }
122 
123  mLog->setLoggingFolder(folder);
124  this->updateWindowTitle();
125 }
126 
127 
128 } // namespace cx
void writeVariant(const QVariant &val)
#define CX_LOG_INFO
Definition: cxLogger.h:110
QDomElement getElement()
return the current element
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()