##// END OF EJS Templates
Creates settings dialog and adds it to a new menu in MainWindow...
Alexandre Leroux -
r463:6a4aa86600f2
parent child
Show More
@@ -0,0 +1,27
1 #ifndef SCIQLOP_SQPSETTINGSDIALOG_H
2 #define SCIQLOP_SQPSETTINGSDIALOG_H
3
4 #include "Settings/ISqpSettingsBindable.h"
5
6 #include <QDialog>
7
8 namespace Ui {
9 class SqpSettingsDialog;
10 } // Ui
11
12 /**
13 * @brief The SqpSettingsDialog class represents the dialog in which the parameters of SciQlop are
14 * set
15 */
16 class SqpSettingsDialog : public QDialog {
17 Q_OBJECT
18
19 public:
20 explicit SqpSettingsDialog(QWidget *parent = 0);
21 virtual ~SqpSettingsDialog() noexcept;
22
23 private:
24 Ui::SqpSettingsDialog *ui;
25 };
26
27 #endif // SCIQLOP_SQPSETTINGSDIALOG_H
@@ -0,0 +1,17
1 #include "Settings/SqpSettingsDialog.h"
2 #include "ui_SqpSettingsDialog.h"
3
4 SqpSettingsDialog::SqpSettingsDialog(QWidget *parent)
5 : QDialog{parent}, ui{new Ui::SqpSettingsDialog}
6 {
7 ui->setupUi(this);
8
9 // Connection to change the current page to the selection of an entry in the list
10 connect(ui->listWidget, &QListWidget::currentRowChanged, ui->stackedWidget,
11 &QStackedWidget::setCurrentIndex);
12 }
13
14 SqpSettingsDialog::~SqpSettingsDialog() noexcept
15 {
16 delete ui;
17 }
@@ -0,0 +1,84
1 <?xml version="1.0" encoding="UTF-8"?>
2 <ui version="4.0">
3 <class>SqpSettingsDialog</class>
4 <widget class="QDialog" name="SqpSettingsDialog">
5 <property name="geometry">
6 <rect>
7 <x>0</x>
8 <y>0</y>
9 <width>572</width>
10 <height>394</height>
11 </rect>
12 </property>
13 <property name="windowTitle">
14 <string>SciQlop Settings</string>
15 </property>
16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="0">
18 <widget class="QListWidget" name="listWidget">
19 <property name="sizePolicy">
20 <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
21 <horstretch>0</horstretch>
22 <verstretch>0</verstretch>
23 </sizepolicy>
24 </property>
25 </widget>
26 </item>
27 <item row="0" column="1">
28 <widget class="QStackedWidget" name="stackedWidget">
29 <property name="sizePolicy">
30 <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
31 <horstretch>0</horstretch>
32 <verstretch>0</verstretch>
33 </sizepolicy>
34 </property>
35 </widget>
36 </item>
37 <item row="1" column="0" colspan="2">
38 <widget class="QDialogButtonBox" name="buttonBox">
39 <property name="orientation">
40 <enum>Qt::Horizontal</enum>
41 </property>
42 <property name="standardButtons">
43 <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
44 </property>
45 </widget>
46 </item>
47 </layout>
48 </widget>
49 <resources/>
50 <connections>
51 <connection>
52 <sender>buttonBox</sender>
53 <signal>accepted()</signal>
54 <receiver>SqpSettingsDialog</receiver>
55 <slot>accept()</slot>
56 <hints>
57 <hint type="sourcelabel">
58 <x>248</x>
59 <y>254</y>
60 </hint>
61 <hint type="destinationlabel">
62 <x>157</x>
63 <y>274</y>
64 </hint>
65 </hints>
66 </connection>
67 <connection>
68 <sender>buttonBox</sender>
69 <signal>rejected()</signal>
70 <receiver>SqpSettingsDialog</receiver>
71 <slot>reject()</slot>
72 <hints>
73 <hint type="sourcelabel">
74 <x>316</x>
75 <y>260</y>
76 </hint>
77 <hint type="destinationlabel">
78 <x>286</x>
79 <y>274</y>
80 </hint>
81 </hints>
82 </connection>
83 </connections>
84 </ui>
@@ -1,214 +1,236
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 #include <Settings/SqpSettingsDialog.h>
27 28 #include <SidePane/SqpSidePane.h>
28 29 #include <SqpApplication.h>
29 30 #include <Time/TimeController.h>
30 31 #include <TimeWidget/TimeWidget.h>
31 32 #include <Variable/Variable.h>
32 33 #include <Variable/VariableController.h>
33 34 #include <Visualization/VisualizationController.h>
34 35
35 36 #include <QAction>
36 37 #include <QDate>
37 38 #include <QDateTime>
38 39 #include <QDir>
39 40 #include <QFileDialog>
40 41 #include <QToolBar>
41 42 #include <QToolButton>
42 43 #include <memory.h>
43 44
44 45 #include "iostream"
45 46
46 47 Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow")
47 48
48 49 namespace {
49 50 const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0;
50 51 const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1;
51 52 const auto VIEWPLITTERINDEX = 2;
52 53 const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3;
53 54 const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4;
54 55 }
55 56
56 57 class MainWindow::MainWindowPrivate {
57 58 public:
59 explicit MainWindowPrivate(MainWindow *mainWindow)
60 : m_LastOpenLeftInspectorSize{},
61 m_LastOpenRightInspectorSize{},
62 m_SettingsDialog{new SqpSettingsDialog{mainWindow}}
63 {
64 }
65
58 66 QSize m_LastOpenLeftInspectorSize;
59 67 QSize m_LastOpenRightInspectorSize;
68 /// Settings dialog. MainWindow has the ownership
69 SqpSettingsDialog *m_SettingsDialog;
60 70 };
61 71
62 72 MainWindow::MainWindow(QWidget *parent)
63 73 : QMainWindow{parent},
64 74 m_Ui{new Ui::MainWindow},
65 impl{spimpl::make_unique_impl<MainWindowPrivate>()}
75 impl{spimpl::make_unique_impl<MainWindowPrivate>(this)}
66 76 {
67 77 m_Ui->setupUi(this);
68 78
69 79 m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false);
70 80 m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false);
71 81
72 82
73 83 auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane();
74 84 auto openLeftInspectorAction = new QAction{QIcon{
75 85 ":/icones/previous.png",
76 86 },
77 87 tr("Show/hide the left inspector"), this};
78 88
79 89
80 90 auto spacerLeftTop = new QWidget{};
81 91 spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
82 92
83 93 auto spacerLeftBottom = new QWidget{};
84 94 spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
85 95
86 96 leftSidePane->addWidget(spacerLeftTop);
87 97 leftSidePane->addAction(openLeftInspectorAction);
88 98 leftSidePane->addWidget(spacerLeftBottom);
89 99
90 100
91 101 auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane();
92 102 auto openRightInspectorAction = new QAction{QIcon{
93 103 ":/icones/next.png",
94 104 },
95 105 tr("Show/hide the right inspector"), this};
96 106
97 107 auto spacerRightTop = new QWidget{};
98 108 spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
99 109
100 110 auto spacerRightBottom = new QWidget{};
101 111 spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
102 112
103 113 rightSidePane->addWidget(spacerRightTop);
104 114 rightSidePane->addAction(openRightInspectorAction);
105 115 rightSidePane->addWidget(spacerRightBottom);
106 116
107 117 openLeftInspectorAction->setCheckable(true);
108 118 openRightInspectorAction->setCheckable(true);
109 119
110 120 auto openInspector = [this](bool checked, bool right, auto action) {
111 121
112 122 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
113 123
114 124 auto &lastInspectorSize
115 125 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
116 126
117 127 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
118 128 : m_Ui->leftMainInspectorWidget->size();
119 129
120 130 // Update of the last opened geometry
121 131 if (checked) {
122 132 lastInspectorSize = nextInspectorSize;
123 133 }
124 134
125 135 auto startSize = lastInspectorSize;
126 136 auto endSize = startSize;
127 137 endSize.setWidth(0);
128 138
129 139 auto splitterInspectorIndex
130 140 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
131 141
132 142 auto currentSizes = m_Ui->splitter->sizes();
133 143 if (checked) {
134 144 // adjust sizes individually here, e.g.
135 145 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
136 146 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
137 147 m_Ui->splitter->setSizes(currentSizes);
138 148 }
139 149 else {
140 150 // adjust sizes individually here, e.g.
141 151 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
142 152 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
143 153 m_Ui->splitter->setSizes(currentSizes);
144 154 }
145 155
146 156 };
147 157
148 158
149 159 connect(openLeftInspectorAction, &QAction::triggered,
150 160 [openInspector, openLeftInspectorAction](bool checked) {
151 161 openInspector(checked, false, openLeftInspectorAction);
152 162 });
153 163 connect(openRightInspectorAction, &QAction::triggered,
154 164 [openInspector, openRightInspectorAction](bool checked) {
155 165 openInspector(checked, true, openRightInspectorAction);
156 166 });
157 167
168 // //// //
169 // Menu //
170 // //// //
158 171 this->menuBar()->addAction(tr("File"));
172 auto toolsMenu = this->menuBar()->addMenu(tr("Tools"));
173 toolsMenu->addAction(tr("Settings..."), [this]() {
174 impl->m_SettingsDialog->exec();
175 });
176
159 177 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
160 178
161 179 auto timeWidget = new TimeWidget{};
162 180 mainToolBar->addWidget(timeWidget);
163 181
182 // /////////// //
183 // Connections //
184 // /////////// //
185
164 186 // Controllers / controllers connections
165 187 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
166 188 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
167 189
168 190 // Widgets / controllers connections
169 191
170 192 // DataSource
171 193 connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)),
172 194 m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *)));
173 195
174 196 // Time
175 197 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
176 198 SLOT(onTimeToUpdate(SqpDateTime)));
177 199
178 200 // Visualization
179 201 connect(&sqpApp->visualizationController(),
180 202 SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), m_Ui->view,
181 203 SLOT(onVariableAboutToBeDeleted(std::shared_ptr<Variable>)));
182 204
183 205 connect(&sqpApp->visualizationController(),
184 206 SIGNAL(rangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)), m_Ui->view,
185 207 SLOT(onRangeChanged(std::shared_ptr<Variable>, const SqpDateTime &)));
186 208
187 209 // Widgets / widgets connections
188 210
189 211 // For the following connections, we use DirectConnection to allow each widget that can
190 212 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
191 213 // The order of connections is also important, since it determines the order in which each
192 214 // widget will attach its menu
193 215 connect(
194 216 m_Ui->variableInspectorWidget,
195 217 SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
196 218 m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)),
197 219 Qt::DirectConnection);
198 220 }
199 221
200 222 MainWindow::~MainWindow()
201 223 {
202 224 }
203 225
204 226 void MainWindow::changeEvent(QEvent *e)
205 227 {
206 228 QMainWindow::changeEvent(e);
207 229 switch (e->type()) {
208 230 case QEvent::LanguageChange:
209 231 m_Ui->retranslateUi(this);
210 232 break;
211 233 default:
212 234 break;
213 235 }
214 236 }
General Comments 0
You need to be logged in to leave comments. Login now