MainWindow.cpp
252 lines
| 9.3 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" | ||||
Alexandre Leroux
|
r84 | |||
#include <DataSource/DataSourceController.h> | ||||
#include <DataSource/DataSourceWidget.h> | ||||
Alexandre Leroux
|
r463 | #include <Settings/SqpSettingsDialog.h> | ||
Alexandre Leroux
|
r465 | #include <Settings/SqpSettingsGeneralWidget.h> | ||
r101 | #include <SidePane/SqpSidePane.h> | |||
Alexandre Leroux
|
r84 | #include <SqpApplication.h> | ||
r192 | #include <Time/TimeController.h> | |||
r133 | #include <TimeWidget/TimeWidget.h> | |||
Alexandre Leroux
|
r175 | #include <Variable/Variable.h> | ||
r304 | #include <Variable/VariableController.h> | |||
Alexandre Leroux
|
r175 | #include <Visualization/VisualizationController.h> | ||
Alexandre Leroux
|
r84 | |||
r21 | #include <QAction> | |||
#include <QDate> | ||||
#include <QDir> | ||||
#include <QFileDialog> | ||||
r101 | #include <QToolBar> | |||
r138 | #include <QToolButton> | |||
r101 | #include <memory.h> | |||
#include "iostream" | ||||
Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | ||||
r102 | namespace { | |||
const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; | ||||
const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; | ||||
const auto VIEWPLITTERINDEX = 2; | ||||
const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; | ||||
const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; | ||||
r861 | } // namespace | |||
r102 | ||||
r101 | class MainWindow::MainWindowPrivate { | |||
public: | ||||
Alexandre Leroux
|
r463 | explicit MainWindowPrivate(MainWindow *mainWindow) | ||
: m_LastOpenLeftInspectorSize{}, | ||||
m_LastOpenRightInspectorSize{}, | ||||
Alexandre Leroux
|
r465 | m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}}, | ||
Alexandre Leroux
|
r463 | m_SettingsDialog{new SqpSettingsDialog{mainWindow}} | ||
{ | ||||
} | ||||
r101 | QSize m_LastOpenLeftInspectorSize; | |||
QSize m_LastOpenRightInspectorSize; | ||||
Alexandre Leroux
|
r465 | /// General settings widget. MainWindow has the ownership | ||
SqpSettingsGeneralWidget *m_GeneralSettingsWidget; | ||||
Alexandre Leroux
|
r463 | /// Settings dialog. MainWindow has the ownership | ||
SqpSettingsDialog *m_SettingsDialog; | ||||
r101 | }; | |||
MainWindow::MainWindow(QWidget *parent) | ||||
: QMainWindow{parent}, | ||||
m_Ui{new Ui::MainWindow}, | ||||
Alexandre Leroux
|
r463 | impl{spimpl::make_unique_impl<MainWindowPrivate>(this)} | ||
r21 | { | |||
r54 | m_Ui->setupUi(this); | |||
r56 | ||||
r102 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); | |||
m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); | ||||
r101 | ||||
r133 | ||||
auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); | ||||
r139 | auto openLeftInspectorAction = new QAction{QIcon{ | |||
":/icones/previous.png", | ||||
}, | ||||
tr("Show/hide the left inspector"), this}; | ||||
r133 | ||||
r139 | auto spacerLeftTop = new QWidget{}; | |||
r133 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
r139 | auto spacerLeftBottom = new QWidget{}; | |||
r133 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
leftSidePane->addWidget(spacerLeftTop); | ||||
leftSidePane->addAction(openLeftInspectorAction); | ||||
leftSidePane->addWidget(spacerLeftBottom); | ||||
auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); | ||||
r139 | auto openRightInspectorAction = new QAction{QIcon{ | |||
":/icones/next.png", | ||||
}, | ||||
tr("Show/hide the right inspector"), this}; | ||||
r133 | ||||
r139 | auto spacerRightTop = new QWidget{}; | |||
r133 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
r139 | auto spacerRightBottom = new QWidget{}; | |||
r133 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
rightSidePane->addWidget(spacerRightTop); | ||||
rightSidePane->addAction(openRightInspectorAction); | ||||
rightSidePane->addWidget(spacerRightBottom); | ||||
openLeftInspectorAction->setCheckable(true); | ||||
openRightInspectorAction->setCheckable(true); | ||||
r138 | auto openInspector = [this](bool checked, bool right, auto action) { | |||
r133 | ||||
r138 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); | |||
r133 | ||||
r138 | auto &lastInspectorSize | |||
= right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; | ||||
auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() | ||||
: m_Ui->leftMainInspectorWidget->size(); | ||||
r101 | ||||
// Update of the last opened geometry | ||||
if (checked) { | ||||
r138 | lastInspectorSize = nextInspectorSize; | |||
r101 | } | |||
r138 | auto startSize = lastInspectorSize; | |||
r101 | auto endSize = startSize; | |||
endSize.setWidth(0); | ||||
r138 | auto splitterInspectorIndex | |||
= right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; | ||||
r102 | auto currentSizes = m_Ui->splitter->sizes(); | |||
r101 | if (checked) { | |||
// adjust sizes individually here, e.g. | ||||
r138 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); | |||
currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); | ||||
r101 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
else { | ||||
// adjust sizes individually here, e.g. | ||||
r138 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); | |||
currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); | ||||
r101 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
}; | ||||
r133 | ||||
r138 | connect(openLeftInspectorAction, &QAction::triggered, | |||
[openInspector, openLeftInspectorAction](bool checked) { | ||||
openInspector(checked, false, openLeftInspectorAction); | ||||
r133 | }); | |||
r138 | connect(openRightInspectorAction, &QAction::triggered, | |||
[openInspector, openRightInspectorAction](bool checked) { | ||||
openInspector(checked, true, openRightInspectorAction); | ||||
r133 | }); | |||
r101 | ||||
Alexandre Leroux
|
r463 | // //// // | ||
// Menu // | ||||
// //// // | ||||
r102 | this->menuBar()->addAction(tr("File")); | |||
Alexandre Leroux
|
r463 | auto toolsMenu = this->menuBar()->addMenu(tr("Tools")); | ||
toolsMenu->addAction(tr("Settings..."), [this]() { | ||||
Alexandre Leroux
|
r469 | // Loads settings | ||
impl->m_SettingsDialog->loadSettings(); | ||||
// Open settings dialog and save settings if the dialog is accepted | ||||
if (impl->m_SettingsDialog->exec() == QDialog::Accepted) { | ||||
impl->m_SettingsDialog->saveSettings(); | ||||
} | ||||
Alexandre Leroux
|
r463 | }); | ||
r102 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); | |||
r133 | ||||
r192 | auto timeWidget = new TimeWidget{}; | |||
mainToolBar->addWidget(timeWidget); | ||||
Alexandre Leroux
|
r84 | |||
Alexandre Leroux
|
r465 | // //////// // | ||
// Settings // | ||||
// //////// // | ||||
// Registers "general settings" widget to the settings dialog | ||||
impl->m_SettingsDialog->registerWidget(QStringLiteral("General"), | ||||
impl->m_GeneralSettingsWidget); | ||||
Alexandre Leroux
|
r463 | // /////////// // | ||
// Connections // | ||||
// /////////// // | ||||
Alexandre Leroux
|
r336 | // Controllers / controllers connections | ||
r512 | connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpRange)), &sqpApp->variableController(), | |||
SLOT(onDateTimeOnSelection(SqpRange))); | ||||
Alexandre Leroux
|
r336 | |||
Alexandre Leroux
|
r84 | // Widgets / controllers connections | ||
r192 | ||||
// DataSource | ||||
Alexandre Leroux
|
r92 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), | ||
m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); | ||||
Alexandre Leroux
|
r84 | |||
r192 | // Time | |||
r512 | connect(timeWidget, SIGNAL(timeUpdated(SqpRange)), &sqpApp->timeController(), | |||
SLOT(onTimeToUpdate(SqpRange))); | ||||
r192 | ||||
Alexandre Leroux
|
r336 | // Visualization | ||
connect(&sqpApp->visualizationController(), | ||||
SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view, | ||||
SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>))); | ||||
r304 | ||||
r437 | connect(&sqpApp->visualizationController(), | |||
r512 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpRange &)), m_Ui->view, | |||
SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpRange &))); | ||||
r437 | ||||
Alexandre Leroux
|
r249 | // Widgets / widgets connections | ||
// For the following connections, we use DirectConnection to allow each widget that can | ||||
// potentially attach a menu to the variable's menu to do so before this menu is displayed. | ||||
// The order of connections is also important, since it determines the order in which each | ||||
// widget will attach its menu | ||||
Alexandre Leroux
|
r288 | connect( | ||
m_Ui->variableInspectorWidget, | ||||
SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | ||||
m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), | ||||
Qt::DirectConnection); | ||||
r21 | } | |||
r861 | MainWindow::~MainWindow() {} | |||
r21 | ||||
void MainWindow::changeEvent(QEvent *e) | ||||
{ | ||||
QMainWindow::changeEvent(e); | ||||
switch (e->type()) { | ||||
case QEvent::LanguageChange: | ||||
r54 | m_Ui->retranslateUi(this); | |||
r21 | break; | |||
default: | ||||
break; | ||||
} | ||||
} | ||||