MainWindow.cpp
395 lines
| 14.6 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 | |||
r1239 | #include <Catalogue/CatalogueController.h> | |||
r1410 | //#include <Catalogue/CatalogueExplorer.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 <Visualization/VisualizationController.h> | ||
Alexandre Leroux
|
r84 | |||
r21 | #include <QAction> | |||
r1239 | #include <QCloseEvent> | |||
r21 | #include <QDate> | |||
#include <QDir> | ||||
#include <QFileDialog> | ||||
r1239 | #include <QMessageBox> | |||
r101 | #include <QToolBar> | |||
r138 | #include <QToolButton> | |||
r101 | #include <memory.h> | |||
#include "iostream" | ||||
Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") | ||||
r1406 | namespace | |||
{ | ||||
r102 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; | |||
const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; | ||||
const auto VIEWPLITTERINDEX = 2; | ||||
const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; | ||||
const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; | ||||
} | ||||
r1406 | class MainWindow::MainWindowPrivate | |||
{ | ||||
r101 | public: | |||
r1406 | explicit MainWindowPrivate(MainWindow* mainWindow) | |||
: m_LastOpenLeftInspectorSize {} | ||||
, m_LastOpenRightInspectorSize {} | ||||
, m_GeneralSettingsWidget { new SqpSettingsGeneralWidget { mainWindow } } | ||||
, m_SettingsDialog { new SqpSettingsDialog { mainWindow } } | ||||
//, m_CatalogExplorer { new CatalogueExplorer { mainWindow } } | ||||
Alexandre Leroux
|
r463 | { | ||
} | ||||
r101 | QSize m_LastOpenLeftInspectorSize; | |||
QSize m_LastOpenRightInspectorSize; | ||||
Alexandre Leroux
|
r465 | /// General settings widget. MainWindow has the ownership | ||
r1406 | SqpSettingsGeneralWidget* m_GeneralSettingsWidget; | |||
Alexandre Leroux
|
r463 | /// Settings dialog. MainWindow has the ownership | ||
r1406 | SqpSettingsDialog* m_SettingsDialog; | |||
r1094 | /// Catalogue dialog. MainWindow has the ownership | |||
r1406 | // CatalogueExplorer* m_CatalogExplorer; | |||
r1239 | ||||
r1406 | bool checkDataToSave(QWidget* parentWidget); | |||
r101 | }; | |||
r1406 | MainWindow::MainWindow(QWidget* parent) | |||
: QMainWindow { parent } | ||||
, m_Ui { new Ui::MainWindow } | ||||
, 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 | ||||
r1406 | // impl->m_CatalogExplorer->setVisualizationWidget(m_Ui->view); | |||
r1375 | ||||
r133 | ||||
r1406 | auto spacerLeftTop = new QWidget {}; | |||
r133 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
r1406 | auto spacerLeftBottom = new QWidget {}; | |||
r133 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
r1406 | auto spacerRightTop = new QWidget {}; | |||
r133 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
r1406 | auto spacerRightBottom = new QWidget {}; | |||
r133 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
r138 | auto openInspector = [this](bool checked, bool right, auto action) { | |||
r1406 | action->setIcon( | |||
QIcon { (checked ^ right) ? ":/icones/next.png" : ":/icones/previous.png" }); | ||||
r133 | ||||
r1406 | auto& lastInspectorSize | |||
r138 | = 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 | ||||
r1406 | 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(); | |||
r1406 | if (checked) | |||
{ | ||||
r101 | // adjust sizes individually here, e.g. | |||
r138 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); | |||
currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); | ||||
r101 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
r1406 | else | |||
{ | ||||
r101 | // adjust sizes individually here, e.g. | |||
r138 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); | |||
currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); | ||||
r101 | m_Ui->splitter->setSizes(currentSizes); | |||
} | ||||
}; | ||||
r133 | ||||
r957 | // //////////////// // | |||
// Menu and Toolbar // | ||||
// //////////////// // | ||||
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 | ||||
r1406 | if (impl->m_SettingsDialog->exec() == QDialog::Accepted) | |||
{ | ||||
Alexandre Leroux
|
r469 | impl->m_SettingsDialog->saveSettings(); | ||
} | ||||
Alexandre Leroux
|
r463 | }); | ||
r102 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); | |||
r133 | ||||
r1406 | auto timeWidget = new TimeWidget {}; | |||
r192 | mainToolBar->addWidget(timeWidget); | |||
Alexandre Leroux
|
r84 | |||
r1094 | // Interaction modes | |||
r1406 | auto actionPointerMode = new QAction { QIcon(":/icones/pointer.png"), "Move", this }; | |||
r957 | actionPointerMode->setCheckable(true); | |||
r1406 | actionPointerMode->setChecked( | |||
sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::None); | ||||
r957 | connect(actionPointerMode, &QAction::triggered, | |||
r1406 | []() { sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::None); }); | |||
r957 | ||||
r1406 | auto actionZoomMode = new QAction { QIcon(":/icones/zoom.png"), "Zoom", this }; | |||
r957 | actionZoomMode->setCheckable(true); | |||
r1406 | actionZoomMode->setChecked( | |||
sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::ZoomBox); | ||||
connect(actionZoomMode, &QAction::triggered, | ||||
[]() { sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::ZoomBox); }); | ||||
r957 | ||||
r1406 | auto actionOrganisationMode = new QAction { QIcon(":/icones/drag.png"), "Organize", this }; | |||
r957 | actionOrganisationMode->setCheckable(true); | |||
r1406 | actionOrganisationMode->setChecked( | |||
sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::DragAndDrop); | ||||
r957 | connect(actionOrganisationMode, &QAction::triggered, []() { | |||
sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::DragAndDrop); | ||||
}); | ||||
r1406 | auto actionZonesMode = new QAction { QIcon(":/icones/rectangle.png"), "Zones", this }; | |||
r957 | actionZonesMode->setCheckable(true); | |||
r1406 | actionZonesMode->setChecked( | |||
sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones); | ||||
r957 | connect(actionZonesMode, &QAction::triggered, []() { | |||
sqpApp->setPlotsInteractionMode(SqpApplication::PlotsInteractionMode::SelectionZones); | ||||
}); | ||||
r1406 | auto modeActionGroup = new QActionGroup { this }; | |||
r957 | modeActionGroup->addAction(actionZoomMode); | |||
modeActionGroup->addAction(actionZonesMode); | ||||
modeActionGroup->addAction(actionOrganisationMode); | ||||
modeActionGroup->addAction(actionPointerMode); | ||||
modeActionGroup->setExclusive(true); | ||||
mainToolBar->addSeparator(); | ||||
mainToolBar->addAction(actionPointerMode); | ||||
mainToolBar->addAction(actionZoomMode); | ||||
mainToolBar->addAction(actionOrganisationMode); | ||||
mainToolBar->addAction(actionZonesMode); | ||||
mainToolBar->addSeparator(); | ||||
r1094 | // Cursors | |||
r1406 | auto btnCursor = new QToolButton { this }; | |||
r957 | btnCursor->setIcon(QIcon(":/icones/cursor.png")); | |||
btnCursor->setText("Cursor"); | ||||
btnCursor->setToolTip("Cursor"); | ||||
btnCursor->setPopupMode(QToolButton::InstantPopup); | ||||
auto cursorMenu = new QMenu("CursorMenu", this); | ||||
btnCursor->setMenu(cursorMenu); | ||||
auto noCursorAction = cursorMenu->addAction("No Cursor"); | ||||
noCursorAction->setCheckable(true); | ||||
r1406 | noCursorAction->setChecked( | |||
sqpApp->plotsCursorMode() == SqpApplication::PlotsCursorMode::NoCursor); | ||||
r957 | connect(noCursorAction, &QAction::triggered, | |||
r1406 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::NoCursor); }); | |||
r957 | ||||
cursorMenu->addSeparator(); | ||||
auto verticalCursorAction = cursorMenu->addAction("Vertical Cursor"); | ||||
verticalCursorAction->setCheckable(true); | ||||
r1406 | verticalCursorAction->setChecked( | |||
sqpApp->plotsCursorMode() == SqpApplication::PlotsCursorMode::Vertical); | ||||
r957 | connect(verticalCursorAction, &QAction::triggered, | |||
r1406 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Vertical); }); | |||
r957 | ||||
auto temporalCursorAction = cursorMenu->addAction("Temporal Cursor"); | ||||
temporalCursorAction->setCheckable(true); | ||||
r1406 | temporalCursorAction->setChecked( | |||
sqpApp->plotsCursorMode() == SqpApplication::PlotsCursorMode::Temporal); | ||||
r957 | connect(temporalCursorAction, &QAction::triggered, | |||
r1406 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Temporal); }); | |||
r957 | ||||
auto horizontalCursorAction = cursorMenu->addAction("Horizontal Cursor"); | ||||
horizontalCursorAction->setCheckable(true); | ||||
r1406 | horizontalCursorAction->setChecked( | |||
sqpApp->plotsCursorMode() == SqpApplication::PlotsCursorMode::Horizontal); | ||||
r957 | connect(horizontalCursorAction, &QAction::triggered, | |||
r1406 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Horizontal); }); | |||
r957 | ||||
auto crossCursorAction = cursorMenu->addAction("Cross Cursor"); | ||||
crossCursorAction->setCheckable(true); | ||||
r1406 | crossCursorAction->setChecked( | |||
sqpApp->plotsCursorMode() == SqpApplication::PlotsCursorMode::Cross); | ||||
r957 | connect(crossCursorAction, &QAction::triggered, | |||
r1406 | []() { sqpApp->setPlotsCursorMode(SqpApplication::PlotsCursorMode::Cross); }); | |||
r957 | ||||
mainToolBar->addWidget(btnCursor); | ||||
r1406 | auto cursorModeActionGroup = new QActionGroup { this }; | |||
r957 | cursorModeActionGroup->setExclusive(true); | |||
cursorModeActionGroup->addAction(noCursorAction); | ||||
cursorModeActionGroup->addAction(verticalCursorAction); | ||||
cursorModeActionGroup->addAction(temporalCursorAction); | ||||
cursorModeActionGroup->addAction(horizontalCursorAction); | ||||
cursorModeActionGroup->addAction(crossCursorAction); | ||||
r1094 | // Catalog | |||
mainToolBar->addSeparator(); | ||||
r1406 | // mainToolBar->addAction(QIcon(":/icones/catalogue.png"), "Catalogues", | |||
// [this]() { impl->m_CatalogExplorer->show(); }); | ||||
r1094 | ||||
Alexandre Leroux
|
r465 | // //////// // | ||
// Settings // | ||||
// //////// // | ||||
// Registers "general settings" widget to the settings dialog | ||||
r1406 | impl->m_SettingsDialog->registerWidget( | |||
QStringLiteral("General"), impl->m_GeneralSettingsWidget); | ||||
Alexandre Leroux
|
r465 | |||
Alexandre Leroux
|
r463 | // /////////// // | ||
// Connections // | ||||
// /////////// // | ||||
Alexandre Leroux
|
r336 | // Controllers / controllers connections | ||
r1406 | // connect(&sqpApp->timeController(), SIGNAL(timeUpdated(DateTimeRange)), | |||
// &sqpApp->variableController(), | ||||
// SLOT(onDateTimeOnSelection(DateTimeRange))); | ||||
Alexandre Leroux
|
r336 | |||
Alexandre Leroux
|
r84 | // Widgets / controllers connections | ||
r192 | ||||
// DataSource | ||||
r1406 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem*)), | |||
m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem*))); | ||||
Alexandre Leroux
|
r84 | |||
r192 | // Time | |||
r1346 | connect(timeWidget, SIGNAL(timeUpdated(DateTimeRange)), &sqpApp->timeController(), | |||
r1406 | SLOT(onTimeToUpdate(DateTimeRange))); | |||
r192 | ||||
Alexandre Leroux
|
r336 | // Visualization | ||
connect(&sqpApp->visualizationController(), | ||||
r1423 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable2>)), m_Ui->view, | |||
SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable2>))); | ||||
r304 | ||||
r437 | connect(&sqpApp->visualizationController(), | |||
r1423 | SIGNAL(rangeChanged(std::shared_ptr<Variable2>, const DateTimeRange&)), m_Ui->view, | |||
SLOT(onRangeChanged(std::shared_ptr<Variable2>, const DateTimeRange&))); | ||||
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 | ||||
r1406 | 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>>&)), | ||||
Alexandre Leroux
|
r288 | Qt::DirectConnection); | ||
r21 | } | |||
r1406 | MainWindow::~MainWindow() {} | |||
r21 | ||||
r1406 | void MainWindow::changeEvent(QEvent* e) | |||
r21 | { | |||
QMainWindow::changeEvent(e); | ||||
r1406 | switch (e->type()) | |||
{ | ||||
r21 | case QEvent::LanguageChange: | |||
r54 | m_Ui->retranslateUi(this); | |||
r21 | break; | |||
default: | ||||
break; | ||||
} | ||||
} | ||||
r1239 | ||||
r1406 | void MainWindow::closeEvent(QCloseEvent* event) | |||
r1239 | { | |||
r1406 | if (!impl->checkDataToSave(this)) | |||
{ | ||||
r1239 | event->ignore(); | |||
} | ||||
r1406 | else | |||
{ | ||||
r1239 | event->accept(); | |||
} | ||||
} | ||||
r1406 | void MainWindow::keyPressEvent(QKeyEvent* event) | |||
r1376 | { | |||
switch (event->key()) | ||||
{ | ||||
r1406 | case Qt::Key_F11: | |||
if (this->isFullScreen()) | ||||
{ | ||||
this->showNormal(); | ||||
} | ||||
else | ||||
{ | ||||
this->showFullScreen(); | ||||
} | ||||
break; | ||||
default: | ||||
break; | ||||
r1376 | } | |||
} | ||||
r1406 | bool MainWindow::MainWindowPrivate::checkDataToSave(QWidget* parentWidget) | |||
r1239 | { | |||
r1406 | // auto hasChanges = sqpApp->catalogueController().hasChanges(); | |||
// if (hasChanges) | ||||
// { | ||||
// // There are some unsaved changes | ||||
// switch (QMessageBox::question(parentWidget, tr("Save changes"), | ||||
// tr("The catalogue controller has unsaved changes.\nDo you want to save them ?"), | ||||
// QMessageBox::SaveAll | QMessageBox::Discard | QMessageBox::Cancel, | ||||
// QMessageBox::SaveAll)) | ||||
// { | ||||
// case QMessageBox::SaveAll: | ||||
// sqpApp->catalogueController().saveAll(); | ||||
// break; | ||||
// case QMessageBox::Discard: | ||||
// break; | ||||
// case QMessageBox::Cancel: | ||||
// default: | ||||
// return false; | ||||
// } | ||||
// } | ||||
r1239 | ||||
return true; | ||||
} | ||||