@@ -1,276 +1,235 | |||
|
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 <SidePane/SqpSidePane.h> |
|
28 | 28 | #include <SqpApplication.h> |
|
29 | 29 | #include <TimeWidget/TimeWidget.h> |
|
30 | 30 | |
|
31 | 31 | #include <QAction> |
|
32 | 32 | #include <QDate> |
|
33 | 33 | #include <QDateTime> |
|
34 | 34 | #include <QDir> |
|
35 | 35 | #include <QFileDialog> |
|
36 | 36 | #include <QToolBar> |
|
37 | #include <QToolButton> | |
|
37 | 38 | #include <memory.h> |
|
38 | 39 | |
|
39 | 40 | //#include <omp.h> |
|
40 | 41 | //#include <network/filedownloader.h> |
|
41 | 42 | //#include <qlopdatabase.h> |
|
42 | 43 | //#include <qlopsettings.h> |
|
43 | 44 | //#include <qlopgui.h> |
|
44 | 45 | //#include <spacedata.h> |
|
45 | 46 | //#include "qlopcore.h" |
|
46 | 47 | //#include "qlopcodecmanager.h" |
|
47 | 48 | //#include "cdfcodec.h" |
|
48 | 49 | //#include "amdatxtcodec.h" |
|
49 | 50 | //#include <qlopplotmanager.h> |
|
50 | 51 | |
|
51 | 52 | #include "iostream" |
|
52 | 53 | |
|
53 | 54 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") |
|
54 | 55 | |
|
55 | 56 | namespace { |
|
56 | 57 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; |
|
57 | 58 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; |
|
58 | 59 | const auto VIEWPLITTERINDEX = 2; |
|
59 | 60 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; |
|
60 | 61 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; |
|
61 | 62 | } |
|
62 | 63 | |
|
63 | 64 | class MainWindow::MainWindowPrivate { |
|
64 | 65 | public: |
|
65 | 66 | QSize m_LastOpenLeftInspectorSize; |
|
66 | 67 | QSize m_LastOpenRightInspectorSize; |
|
67 | 68 | }; |
|
68 | 69 | |
|
69 | 70 | MainWindow::MainWindow(QWidget *parent) |
|
70 | 71 | : QMainWindow{parent}, |
|
71 | 72 | m_Ui{new Ui::MainWindow}, |
|
72 | 73 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} |
|
73 | 74 | { |
|
74 | 75 | m_Ui->setupUi(this); |
|
75 | 76 | |
|
76 | 77 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
77 | 78 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
78 | 79 | |
|
79 | 80 | |
|
80 | 81 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); |
|
81 | 82 | auto openLeftInspectorAction = new QAction( |
|
82 | 83 | QIcon{ |
|
83 | 84 | ":/icones/previous.png", |
|
84 | 85 | }, |
|
85 | 86 | tr("Show/hide the left inspector"), this); |
|
86 | 87 | |
|
87 | 88 | |
|
88 | 89 | QWidget *spacerLeftTop = new QWidget(); |
|
89 | 90 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
90 | 91 | |
|
91 | 92 | QWidget *spacerLeftBottom = new QWidget(); |
|
92 | 93 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
93 | 94 | |
|
94 | 95 | leftSidePane->addWidget(spacerLeftTop); |
|
95 | 96 | leftSidePane->addAction(openLeftInspectorAction); |
|
96 | 97 | leftSidePane->addWidget(spacerLeftBottom); |
|
97 | 98 | |
|
98 | 99 | |
|
99 | 100 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); |
|
100 | 101 | auto openRightInspectorAction = new QAction( |
|
101 | 102 | QIcon{ |
|
102 | 103 | ":/icones/next.png", |
|
103 | 104 | }, |
|
104 | 105 | tr("Show/hide the right inspector"), this); |
|
105 | 106 | |
|
106 | 107 | QWidget *spacerRightTop = new QWidget(); |
|
107 | 108 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
108 | 109 | |
|
109 | 110 | QWidget *spacerRightBottom = new QWidget(); |
|
110 | 111 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
111 | 112 | |
|
112 | 113 | rightSidePane->addWidget(spacerRightTop); |
|
113 | 114 | rightSidePane->addAction(openRightInspectorAction); |
|
114 | 115 | rightSidePane->addWidget(spacerRightBottom); |
|
115 | 116 | |
|
116 | 117 | openLeftInspectorAction->setCheckable(true); |
|
117 | 118 | openRightInspectorAction->setCheckable(true); |
|
118 | 119 | |
|
120 | auto openInspector = [this](bool checked, bool right, auto action) { | |
|
119 | 121 | |
|
120 | // NOTE: These lambda could be factorized. Be careful of theirs parameters | |
|
121 | // Lambda that defines what's happened when clicking on the leftSidePaneInspector open button | |
|
122 | auto openLeftInspector = [this, openLeftInspectorAction](bool checked) { | |
|
122 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); | |
|
123 | 123 | |
|
124 | if (checked) { | |
|
125 | openLeftInspectorAction->setIcon(QIcon{ | |
|
126 | ":/icones/next.png", | |
|
127 | }); | |
|
128 | } | |
|
129 | else { | |
|
130 | openLeftInspectorAction->setIcon(QIcon{ | |
|
131 | ":/icones/previous.png", | |
|
132 | }); | |
|
133 | } | |
|
124 | auto &lastInspectorSize | |
|
125 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; | |
|
126 | ||
|
127 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() | |
|
128 | : m_Ui->leftMainInspectorWidget->size(); | |
|
134 | 129 | |
|
135 | 130 | // Update of the last opened geometry |
|
136 | 131 | if (checked) { |
|
137 |
|
|
|
132 | lastInspectorSize = nextInspectorSize; | |
|
138 | 133 | } |
|
139 | 134 | |
|
140 |
auto startSize = |
|
|
135 | auto startSize = lastInspectorSize; | |
|
141 | 136 | auto endSize = startSize; |
|
142 | 137 | endSize.setWidth(0); |
|
143 | 138 | |
|
139 | auto splitterInspectorIndex | |
|
140 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; | |
|
141 | ||
|
144 | 142 | auto currentSizes = m_Ui->splitter->sizes(); |
|
145 | 143 | if (checked) { |
|
146 | 144 | // adjust sizes individually here, e.g. |
|
147 | currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX] | |
|
148 |
|
|
|
149 | currentSizes[VIEWPLITTERINDEX] += impl->m_LastOpenLeftInspectorSize.width(); | |
|
145 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); | |
|
146 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); | |
|
150 | 147 | m_Ui->splitter->setSizes(currentSizes); |
|
151 | 148 | } |
|
152 | 149 | else { |
|
153 | 150 | // adjust sizes individually here, e.g. |
|
154 | currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX] | |
|
155 |
|
|
|
156 | currentSizes[VIEWPLITTERINDEX] -= impl->m_LastOpenLeftInspectorSize.width(); | |
|
151 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); | |
|
152 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); | |
|
157 | 153 | m_Ui->splitter->setSizes(currentSizes); |
|
158 | 154 | } |
|
159 | 155 | |
|
160 | 156 | }; |
|
161 | 157 | |
|
162 | // Lambda that defines what's happened when clicking on the SidePaneInspector open button | |
|
163 | auto openRightInspector = [this, openRightInspectorAction](bool checked) { | |
|
164 | 158 | |
|
165 | if (checked) { | |
|
166 | openRightInspectorAction->setIcon(QIcon{ | |
|
167 | ":/icones/previous.png", | |
|
159 | connect(openLeftInspectorAction, &QAction::triggered, | |
|
160 | [openInspector, openLeftInspectorAction](bool checked) { | |
|
161 | openInspector(checked, false, openLeftInspectorAction); | |
|
168 | 162 | }); |
|
169 | } | |
|
170 | else { | |
|
171 | openRightInspectorAction->setIcon(QIcon{ | |
|
172 | ":/icones/next.png", | |
|
163 | connect(openRightInspectorAction, &QAction::triggered, | |
|
164 | [openInspector, openRightInspectorAction](bool checked) { | |
|
165 | openInspector(checked, true, openRightInspectorAction); | |
|
173 | 166 | }); |
|
174 | } | |
|
175 | ||
|
176 | ||
|
177 | // Update of the last opened geometry | |
|
178 | if (checked) { | |
|
179 | impl->m_LastOpenRightInspectorSize = m_Ui->rightMainInspectorWidget->size(); | |
|
180 | } | |
|
181 | ||
|
182 | auto startSize = impl->m_LastOpenRightInspectorSize; | |
|
183 | auto endSize = startSize; | |
|
184 | endSize.setWidth(0); | |
|
185 | ||
|
186 | auto currentSizes = m_Ui->splitter->sizes(); | |
|
187 | if (checked) { | |
|
188 | // adjust sizes individually here, e.g. | |
|
189 | currentSizes[RIGHTMAININSPECTORWIDGETSPLITTERINDEX] | |
|
190 | -= impl->m_LastOpenRightInspectorSize.width(); | |
|
191 | currentSizes[VIEWPLITTERINDEX] += impl->m_LastOpenRightInspectorSize.width(); | |
|
192 | m_Ui->splitter->setSizes(currentSizes); | |
|
193 | } | |
|
194 | else { | |
|
195 | // adjust sizes individually here, e.g. | |
|
196 | currentSizes[RIGHTMAININSPECTORWIDGETSPLITTERINDEX] | |
|
197 | += impl->m_LastOpenRightInspectorSize.width(); | |
|
198 | currentSizes[VIEWPLITTERINDEX] -= impl->m_LastOpenRightInspectorSize.width(); | |
|
199 | m_Ui->splitter->setSizes(currentSizes); | |
|
200 | } | |
|
201 | ||
|
202 | }; | |
|
203 | ||
|
204 | ||
|
205 | connect(openLeftInspectorAction, &QAction::triggered, openLeftInspector); | |
|
206 | connect(openRightInspectorAction, &QAction::triggered, openRightInspector); | |
|
207 | ||
|
208 | 167 | |
|
209 | 168 | this->menuBar()->addAction(tr("File")); |
|
210 | 169 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); |
|
211 | 170 | |
|
212 | 171 | mainToolBar->addWidget(new TimeWidget()); |
|
213 | 172 | |
|
214 | 173 | // Widgets / controllers connections |
|
215 | 174 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), |
|
216 | 175 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); |
|
217 | 176 | |
|
218 | 177 | /* QLopGUI::registerMenuBar(menuBar()); |
|
219 | 178 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); |
|
220 | 179 | this->m_progressWidget = new QWidget(); |
|
221 | 180 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); |
|
222 | 181 | this->m_progressWidget->setLayout(this->m_progressLayout); |
|
223 | 182 | this->m_progressWidget->setWindowModality(Qt::WindowModal); |
|
224 | 183 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); |
|
225 | 184 | for(int i=0;i<OMP_THREADS;i++) |
|
226 | 185 | { |
|
227 | 186 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); |
|
228 | 187 | this->m_progress.last()->setMinimum(0); |
|
229 | 188 | this->m_progress.last()->setMaximum(100); |
|
230 | 189 | this->m_progressLayout->addWidget(this->m_progress.last()); |
|
231 | 190 | this->m_progressWidget->hide(); |
|
232 | 191 | this->m_progressThreadIds[i] = -1; |
|
233 | 192 | } |
|
234 | 193 | this->m_progressWidget->setWindowTitle("Loading File"); |
|
235 | 194 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() |
|
236 | 195 | << QLopCore::self() |
|
237 | 196 | << QLopPlotManager::self() |
|
238 | 197 | << QLopCodecManager::self() |
|
239 | 198 | << FileDownloader::self() |
|
240 | 199 | << QLopDataBase::self() |
|
241 | 200 | << SpaceData::self(); |
|
242 | 201 | |
|
243 | 202 | CDFCodec::registerToManager(); |
|
244 | 203 | AMDATXTCodec::registerToManager(); |
|
245 | 204 | |
|
246 | 205 | |
|
247 | 206 | for(int i=0;i<ServicesToLoad.count();i++) |
|
248 | 207 | { |
|
249 | 208 | qDebug()<<ServicesToLoad.at(i)->serviceName(); |
|
250 | 209 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI |
|
251 | 210 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); |
|
252 | 211 | if(wdgt) |
|
253 | 212 | { |
|
254 | 213 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
255 | 214 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); |
|
256 | 215 | } |
|
257 | 216 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); |
|
258 | 217 | }*/ |
|
259 | 218 | } |
|
260 | 219 | |
|
261 | 220 | MainWindow::~MainWindow() |
|
262 | 221 | { |
|
263 | 222 | } |
|
264 | 223 | |
|
265 | 224 | |
|
266 | 225 | void MainWindow::changeEvent(QEvent *e) |
|
267 | 226 | { |
|
268 | 227 | QMainWindow::changeEvent(e); |
|
269 | 228 | switch (e->type()) { |
|
270 | 229 | case QEvent::LanguageChange: |
|
271 | 230 | m_Ui->retranslateUi(this); |
|
272 | 231 | break; |
|
273 | 232 | default: |
|
274 | 233 | break; |
|
275 | 234 | } |
|
276 | 235 | } |
General Comments 0
You need to be logged in to leave comments.
Login now