MainWindow.cpp
276 lines
| 9.5 KiB
| text/x-c
|
CppLexer
r21 | /*------------------------------------------------------------------------------ | |||
r54 | -- This file is a part of the SciQLop Software | |||
-- Copyright (C) 2017, Plasma Physics Laboratory - CNRS | ||||
r21 | -- | |||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
r54 | #include "MainWindow.h" | |||
#include "ui_MainWindow.h" | ||||
|
r83 | |||
#include <DataSource/DataSourceController.h> | ||||
#include <DataSource/DataSourceWidget.h> | ||||
r98 | #include <SidePane/SqpSidePane.h> | |||
|
r83 | #include <SqpApplication.h> | ||
r125 | #include <TimeWidget/TimeWidget.h> | |||
|
r83 | |||
r21 | #include <QAction> | |||
#include <QDate> | ||||
#include <QDateTime> | ||||
#include <QDir> | ||||
#include <QFileDialog> | ||||
r98 | #include <QToolBar> | |||
#include <memory.h> | ||||
r29 | //#include <omp.h> | |||
r21 | //#include <network/filedownloader.h> | |||
//#include <qlopdatabase.h> | ||||
//#include <qlopsettings.h> | ||||
//#include <qlopgui.h> | ||||
//#include <spacedata.h> | ||||
//#include "qlopcore.h" | ||||
//#include "qlopcodecmanager.h" | ||||
//#include "cdfcodec.h" | ||||
//#include "amdatxtcodec.h" | ||||
//#include <qlopplotmanager.h> | ||||
r98 | ||||
#include "iostream" | ||||
Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | ||||
r99 | namespace { | |||
const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; | ||||
const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; | ||||
const auto VIEWPLITTERINDEX = 2; | ||||
const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; | ||||
const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; | ||||
} | ||||
r98 | class MainWindow::MainWindowPrivate { | |||
public: | ||||
QSize m_LastOpenLeftInspectorSize; | ||||
QSize m_LastOpenRightInspectorSize; | ||||
}; | ||||
MainWindow::MainWindow(QWidget *parent) | ||||
: QMainWindow{parent}, | ||||
m_Ui{new Ui::MainWindow}, | ||||
impl{spimpl::make_unique_impl<MainWindowPrivate>()} | ||||
r21 | { | |||
r54 | m_Ui->setupUi(this); | |||
r56 | ||||
r99 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); | |||
m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); | ||||
r98 | ||||
r125 | ||||
auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); | ||||
auto openLeftInspectorAction = new QAction( | ||||
QIcon{ | ||||
":/icones/previous.png", | ||||
}, | ||||
tr("Show/hide the left inspector"), this); | ||||
QWidget *spacerLeftTop = new QWidget(); | ||||
spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||||
QWidget *spacerLeftBottom = new QWidget(); | ||||
spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||||
leftSidePane->addWidget(spacerLeftTop); | ||||
leftSidePane->addAction(openLeftInspectorAction); | ||||
leftSidePane->addWidget(spacerLeftBottom); | ||||
auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); | ||||
auto openRightInspectorAction = new QAction( | ||||
QIcon{ | ||||
":/icones/next.png", | ||||
}, | ||||
tr("Show/hide the right inspector"), this); | ||||
QWidget *spacerRightTop = new QWidget(); | ||||
spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||||
QWidget *spacerRightBottom = new QWidget(); | ||||
spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||||
rightSidePane->addWidget(spacerRightTop); | ||||
rightSidePane->addAction(openRightInspectorAction); | ||||
rightSidePane->addWidget(spacerRightBottom); | ||||
openLeftInspectorAction->setCheckable(true); | ||||
openRightInspectorAction->setCheckable(true); | ||||
r99 | // NOTE: These lambda could be factorized. Be careful of theirs parameters | |||
r98 | // Lambda that defines what's happened when clicking on the leftSidePaneInspector open button | |||
r125 | auto openLeftInspector = [this, openLeftInspectorAction](bool checked) { | |||
if (checked) { | ||||
openLeftInspectorAction->setIcon(QIcon{ | ||||
":/icones/next.png", | ||||
}); | ||||
} | ||||
else { | ||||
openLeftInspectorAction->setIcon(QIcon{ | ||||
":/icones/previous.png", | ||||
}); | ||||
} | ||||
r98 | ||||
// Update of the last opened geometry | ||||
if (checked) { | ||||
impl->m_LastOpenLeftInspectorSize = m_Ui->leftMainInspectorWidget->size(); | ||||
} | ||||
auto startSize = impl->m_LastOpenLeftInspectorSize; | ||||
auto endSize = startSize; | ||||
endSize.setWidth(0); | ||||
r99 | auto currentSizes = m_Ui->splitter->sizes(); | |||
r98 | if (checked) { | |||
// adjust sizes individually here, e.g. | ||||
r99 | currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX] | |||
-= impl->m_LastOpenLeftInspectorSize.width(); | ||||
currentSizes[VIEWPLITTERINDEX] += impl->m_LastOpenLeftInspectorSize.width(); | ||||
r98 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
else { | ||||
// adjust sizes individually here, e.g. | ||||
r99 | currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX] | |||
+= impl->m_LastOpenLeftInspectorSize.width(); | ||||
currentSizes[VIEWPLITTERINDEX] -= impl->m_LastOpenLeftInspectorSize.width(); | ||||
r98 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
}; | ||||
// Lambda that defines what's happened when clicking on the SidePaneInspector open button | ||||
r125 | auto openRightInspector = [this, openRightInspectorAction](bool checked) { | |||
if (checked) { | ||||
openRightInspectorAction->setIcon(QIcon{ | ||||
":/icones/previous.png", | ||||
}); | ||||
} | ||||
else { | ||||
openRightInspectorAction->setIcon(QIcon{ | ||||
":/icones/next.png", | ||||
}); | ||||
} | ||||
r98 | ||||
// Update of the last opened geometry | ||||
if (checked) { | ||||
impl->m_LastOpenRightInspectorSize = m_Ui->rightMainInspectorWidget->size(); | ||||
} | ||||
auto startSize = impl->m_LastOpenRightInspectorSize; | ||||
auto endSize = startSize; | ||||
endSize.setWidth(0); | ||||
r99 | auto currentSizes = m_Ui->splitter->sizes(); | |||
r98 | if (checked) { | |||
// adjust sizes individually here, e.g. | ||||
r99 | currentSizes[RIGHTMAININSPECTORWIDGETSPLITTERINDEX] | |||
-= impl->m_LastOpenRightInspectorSize.width(); | ||||
currentSizes[VIEWPLITTERINDEX] += impl->m_LastOpenRightInspectorSize.width(); | ||||
r98 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
else { | ||||
// adjust sizes individually here, e.g. | ||||
r99 | currentSizes[RIGHTMAININSPECTORWIDGETSPLITTERINDEX] | |||
+= impl->m_LastOpenRightInspectorSize.width(); | ||||
currentSizes[VIEWPLITTERINDEX] -= impl->m_LastOpenRightInspectorSize.width(); | ||||
r98 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
}; | ||||
r125 | connect(openLeftInspectorAction, &QAction::triggered, openLeftInspector); | |||
connect(openRightInspectorAction, &QAction::triggered, openRightInspector); | ||||
r98 | ||||
r99 | this->menuBar()->addAction(tr("File")); | |||
auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); | ||||
r125 | ||||
mainToolBar->addWidget(new TimeWidget()); | ||||
|
r83 | |||
// Widgets / controllers connections | ||||
|
r90 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), | ||
m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); | ||||
|
r83 | |||
r21 | /* QLopGUI::registerMenuBar(menuBar()); | |||
this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); | ||||
this->m_progressWidget = new QWidget(); | ||||
this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); | ||||
this->m_progressWidget->setLayout(this->m_progressLayout); | ||||
this->m_progressWidget->setWindowModality(Qt::WindowModal); | ||||
m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); | ||||
for(int i=0;i<OMP_THREADS;i++) | ||||
{ | ||||
this->m_progress.append(new QProgressBar(this->m_progressWidget)); | ||||
this->m_progress.last()->setMinimum(0); | ||||
this->m_progress.last()->setMaximum(100); | ||||
this->m_progressLayout->addWidget(this->m_progress.last()); | ||||
this->m_progressWidget->hide(); | ||||
this->m_progressThreadIds[i] = -1; | ||||
} | ||||
this->m_progressWidget->setWindowTitle("Loading File"); | ||||
const QList<QLopService*>ServicesToLoad=QList<QLopService*>() | ||||
<< QLopCore::self() | ||||
<< QLopPlotManager::self() | ||||
<< QLopCodecManager::self() | ||||
<< FileDownloader::self() | ||||
<< QLopDataBase::self() | ||||
<< SpaceData::self(); | ||||
CDFCodec::registerToManager(); | ||||
AMDATXTCodec::registerToManager(); | ||||
for(int i=0;i<ServicesToLoad.count();i++) | ||||
{ | ||||
qDebug()<<ServicesToLoad.at(i)->serviceName(); | ||||
ServicesToLoad.at(i)->initialize(); //must be called before getGUI | ||||
QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); | ||||
if(wdgt) | ||||
{ | ||||
wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); | ||||
this->addDockWidget(Qt::TopDockWidgetArea,wdgt); | ||||
} | ||||
PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); | ||||
}*/ | ||||
} | ||||
MainWindow::~MainWindow() | ||||
{ | ||||
} | ||||
void MainWindow::changeEvent(QEvent *e) | ||||
{ | ||||
QMainWindow::changeEvent(e); | ||||
switch (e->type()) { | ||||
case QEvent::LanguageChange: | ||||
r54 | m_Ui->retranslateUi(this); | |||
r21 | break; | |||
default: | ||||
break; | ||||
} | ||||
} | ||||