@@ -1,248 +1,255 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the SciQLop Software |
|
3 | 3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 2 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "MainWindow.h" |
|
23 | 23 | #include "ui_MainWindow.h" |
|
24 | 24 | |
|
25 | 25 | #include <DataSource/DataSourceController.h> |
|
26 | 26 | #include <DataSource/DataSourceWidget.h> |
|
27 | 27 | #include <Settings/SqpSettingsDialog.h> |
|
28 | 28 | #include <Settings/SqpSettingsGeneralWidget.h> |
|
29 | 29 | #include <SidePane/SqpSidePane.h> |
|
30 | 30 | #include <SqpApplication.h> |
|
31 | 31 | #include <Time/TimeController.h> |
|
32 | 32 | #include <TimeWidget/TimeWidget.h> |
|
33 | 33 | #include <Variable/Variable.h> |
|
34 | 34 | #include <Variable/VariableController.h> |
|
35 | 35 | #include <Visualization/VisualizationController.h> |
|
36 | 36 | |
|
37 | 37 | #include <QAction> |
|
38 | 38 | #include <QDate> |
|
39 | 39 | #include <QDateTime> |
|
40 | 40 | #include <QDir> |
|
41 | 41 | #include <QFileDialog> |
|
42 | 42 | #include <QToolBar> |
|
43 | 43 | #include <QToolButton> |
|
44 | 44 | #include <memory.h> |
|
45 | 45 | |
|
46 | 46 | #include "iostream" |
|
47 | 47 | |
|
48 | 48 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") |
|
49 | 49 | |
|
50 | 50 | namespace { |
|
51 | 51 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; |
|
52 | 52 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; |
|
53 | 53 | const auto VIEWPLITTERINDEX = 2; |
|
54 | 54 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; |
|
55 | 55 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | class MainWindow::MainWindowPrivate { |
|
59 | 59 | public: |
|
60 | 60 | explicit MainWindowPrivate(MainWindow *mainWindow) |
|
61 | 61 | : m_LastOpenLeftInspectorSize{}, |
|
62 | 62 | m_LastOpenRightInspectorSize{}, |
|
63 | 63 | m_GeneralSettingsWidget{new SqpSettingsGeneralWidget{mainWindow}}, |
|
64 | 64 | m_SettingsDialog{new SqpSettingsDialog{mainWindow}} |
|
65 | 65 | { |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | QSize m_LastOpenLeftInspectorSize; |
|
69 | 69 | QSize m_LastOpenRightInspectorSize; |
|
70 | 70 | /// General settings widget. MainWindow has the ownership |
|
71 | 71 | SqpSettingsGeneralWidget *m_GeneralSettingsWidget; |
|
72 | 72 | /// Settings dialog. MainWindow has the ownership |
|
73 | 73 | SqpSettingsDialog *m_SettingsDialog; |
|
74 | 74 | }; |
|
75 | 75 | |
|
76 | 76 | MainWindow::MainWindow(QWidget *parent) |
|
77 | 77 | : QMainWindow{parent}, |
|
78 | 78 | m_Ui{new Ui::MainWindow}, |
|
79 | 79 | impl{spimpl::make_unique_impl<MainWindowPrivate>(this)} |
|
80 | 80 | { |
|
81 | 81 | m_Ui->setupUi(this); |
|
82 | 82 | |
|
83 | 83 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
84 | 84 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); |
|
88 | 88 | auto openLeftInspectorAction = new QAction{QIcon{ |
|
89 | 89 | ":/icones/previous.png", |
|
90 | 90 | }, |
|
91 | 91 | tr("Show/hide the left inspector"), this}; |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | auto spacerLeftTop = new QWidget{}; |
|
95 | 95 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
96 | 96 | |
|
97 | 97 | auto spacerLeftBottom = new QWidget{}; |
|
98 | 98 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
99 | 99 | |
|
100 | 100 | leftSidePane->addWidget(spacerLeftTop); |
|
101 | 101 | leftSidePane->addAction(openLeftInspectorAction); |
|
102 | 102 | leftSidePane->addWidget(spacerLeftBottom); |
|
103 | 103 | |
|
104 | 104 | |
|
105 | 105 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); |
|
106 | 106 | auto openRightInspectorAction = new QAction{QIcon{ |
|
107 | 107 | ":/icones/next.png", |
|
108 | 108 | }, |
|
109 | 109 | tr("Show/hide the right inspector"), this}; |
|
110 | 110 | |
|
111 | 111 | auto spacerRightTop = new QWidget{}; |
|
112 | 112 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
113 | 113 | |
|
114 | 114 | auto spacerRightBottom = new QWidget{}; |
|
115 | 115 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
116 | 116 | |
|
117 | 117 | rightSidePane->addWidget(spacerRightTop); |
|
118 | 118 | rightSidePane->addAction(openRightInspectorAction); |
|
119 | 119 | rightSidePane->addWidget(spacerRightBottom); |
|
120 | 120 | |
|
121 | 121 | openLeftInspectorAction->setCheckable(true); |
|
122 | 122 | openRightInspectorAction->setCheckable(true); |
|
123 | 123 | |
|
124 | 124 | auto openInspector = [this](bool checked, bool right, auto action) { |
|
125 | 125 | |
|
126 | 126 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); |
|
127 | 127 | |
|
128 | 128 | auto &lastInspectorSize |
|
129 | 129 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; |
|
130 | 130 | |
|
131 | 131 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() |
|
132 | 132 | : m_Ui->leftMainInspectorWidget->size(); |
|
133 | 133 | |
|
134 | 134 | // Update of the last opened geometry |
|
135 | 135 | if (checked) { |
|
136 | 136 | lastInspectorSize = nextInspectorSize; |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | auto startSize = lastInspectorSize; |
|
140 | 140 | auto endSize = startSize; |
|
141 | 141 | endSize.setWidth(0); |
|
142 | 142 | |
|
143 | 143 | auto splitterInspectorIndex |
|
144 | 144 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; |
|
145 | 145 | |
|
146 | 146 | auto currentSizes = m_Ui->splitter->sizes(); |
|
147 | 147 | if (checked) { |
|
148 | 148 | // adjust sizes individually here, e.g. |
|
149 | 149 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); |
|
150 | 150 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); |
|
151 | 151 | m_Ui->splitter->setSizes(currentSizes); |
|
152 | 152 | } |
|
153 | 153 | else { |
|
154 | 154 | // adjust sizes individually here, e.g. |
|
155 | 155 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); |
|
156 | 156 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); |
|
157 | 157 | m_Ui->splitter->setSizes(currentSizes); |
|
158 | 158 | } |
|
159 | 159 | |
|
160 | 160 | }; |
|
161 | 161 | |
|
162 | 162 | |
|
163 | 163 | connect(openLeftInspectorAction, &QAction::triggered, |
|
164 | 164 | [openInspector, openLeftInspectorAction](bool checked) { |
|
165 | 165 | openInspector(checked, false, openLeftInspectorAction); |
|
166 | 166 | }); |
|
167 | 167 | connect(openRightInspectorAction, &QAction::triggered, |
|
168 | 168 | [openInspector, openRightInspectorAction](bool checked) { |
|
169 | 169 | openInspector(checked, true, openRightInspectorAction); |
|
170 | 170 | }); |
|
171 | 171 | |
|
172 | 172 | // //// // |
|
173 | 173 | // Menu // |
|
174 | 174 | // //// // |
|
175 | 175 | this->menuBar()->addAction(tr("File")); |
|
176 | 176 | auto toolsMenu = this->menuBar()->addMenu(tr("Tools")); |
|
177 | 177 | toolsMenu->addAction(tr("Settings..."), [this]() { |
|
178 | impl->m_SettingsDialog->exec(); | |
|
178 | // Loads settings | |
|
179 | impl->m_SettingsDialog->loadSettings(); | |
|
180 | ||
|
181 | // Open settings dialog and save settings if the dialog is accepted | |
|
182 | if (impl->m_SettingsDialog->exec() == QDialog::Accepted) { | |
|
183 | impl->m_SettingsDialog->saveSettings(); | |
|
184 | } | |
|
185 | ||
|
179 | 186 | }); |
|
180 | 187 | |
|
181 | 188 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); |
|
182 | 189 | |
|
183 | 190 | auto timeWidget = new TimeWidget{}; |
|
184 | 191 | mainToolBar->addWidget(timeWidget); |
|
185 | 192 | |
|
186 | 193 | // //////// // |
|
187 | 194 | // Settings // |
|
188 | 195 | // //////// // |
|
189 | 196 | |
|
190 | 197 | // Registers "general settings" widget to the settings dialog |
|
191 | 198 | impl->m_SettingsDialog->registerWidget(QStringLiteral("General"), |
|
192 | 199 | impl->m_GeneralSettingsWidget); |
|
193 | 200 | |
|
194 | 201 | // /////////// // |
|
195 | 202 | // Connections // |
|
196 | 203 | // /////////// // |
|
197 | 204 | |
|
198 | 205 | // Controllers / controllers connections |
|
199 | 206 | connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)), |
|
200 | 207 | &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime))); |
|
201 | 208 | |
|
202 | 209 | // Widgets / controllers connections |
|
203 | 210 | |
|
204 | 211 | // DataSource |
|
205 | 212 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), |
|
206 | 213 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); |
|
207 | 214 | |
|
208 | 215 | // Time |
|
209 | 216 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), |
|
210 | 217 | SLOT(onTimeToUpdate(SqpDateTime))); |
|
211 | 218 | |
|
212 | 219 | // Visualization |
|
213 | 220 | connect(&sqpApp->visualizationController(), |
|
214 | 221 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view, |
|
215 | 222 | SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>))); |
|
216 | 223 | |
|
217 | 224 | connect(&sqpApp->visualizationController(), |
|
218 | 225 | SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view, |
|
219 | 226 | SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &))); |
|
220 | 227 | |
|
221 | 228 | // Widgets / widgets connections |
|
222 | 229 | |
|
223 | 230 | // For the following connections, we use DirectConnection to allow each widget that can |
|
224 | 231 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. |
|
225 | 232 | // The order of connections is also important, since it determines the order in which each |
|
226 | 233 | // widget will attach its menu |
|
227 | 234 | connect( |
|
228 | 235 | m_Ui->variableInspectorWidget, |
|
229 | 236 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
230 | 237 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
231 | 238 | Qt::DirectConnection); |
|
232 | 239 | } |
|
233 | 240 | |
|
234 | 241 | MainWindow::~MainWindow() |
|
235 | 242 | { |
|
236 | 243 | } |
|
237 | 244 | |
|
238 | 245 | void MainWindow::changeEvent(QEvent *e) |
|
239 | 246 | { |
|
240 | 247 | QMainWindow::changeEvent(e); |
|
241 | 248 | switch (e->type()) { |
|
242 | 249 | case QEvent::LanguageChange: |
|
243 | 250 | m_Ui->retranslateUi(this); |
|
244 | 251 | break; |
|
245 | 252 | default: |
|
246 | 253 | break; |
|
247 | 254 | } |
|
248 | 255 | } |
General Comments 0
You need to be logged in to leave comments.
Login now