##// END OF EJS Templates
Factorisation of the lambda connected to the side pane button
perrinel -
r138:8776db221f5e
parent child
Show More
@@ -34,6 +34,7
34 #include <QDir>
34 #include <QDir>
35 #include <QFileDialog>
35 #include <QFileDialog>
36 #include <QToolBar>
36 #include <QToolBar>
37 #include <QToolButton>
37 #include <memory.h>
38 #include <memory.h>
38
39
39 //#include <omp.h>
40 //#include <omp.h>
@@ -116,95 +117,53 MainWindow::MainWindow(QWidget *parent)
116 openLeftInspectorAction->setCheckable(true);
117 openLeftInspectorAction->setCheckable(true);
117 openRightInspectorAction->setCheckable(true);
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
122 action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"});
121 // Lambda that defines what's happened when clicking on the leftSidePaneInspector open button
122 auto openLeftInspector = [this, openLeftInspectorAction](bool checked) {
123
123
124 if (checked) {
124 auto &lastInspectorSize
125 openLeftInspectorAction->setIcon(QIcon{
125 = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize;
126 ":/icones/next.png",
126
127 });
127 auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size()
128 }
128 : m_Ui->leftMainInspectorWidget->size();
129 else {
130 openLeftInspectorAction->setIcon(QIcon{
131 ":/icones/previous.png",
132 });
133 }
134
129
135 // Update of the last opened geometry
130 // Update of the last opened geometry
136 if (checked) {
131 if (checked) {
137 impl->m_LastOpenLeftInspectorSize = m_Ui->leftMainInspectorWidget->size();
132 lastInspectorSize = nextInspectorSize;
138 }
133 }
139
134
140 auto startSize = impl->m_LastOpenLeftInspectorSize;
135 auto startSize = lastInspectorSize;
141 auto endSize = startSize;
136 auto endSize = startSize;
142 endSize.setWidth(0);
137 endSize.setWidth(0);
143
138
139 auto splitterInspectorIndex
140 = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX;
141
144 auto currentSizes = m_Ui->splitter->sizes();
142 auto currentSizes = m_Ui->splitter->sizes();
145 if (checked) {
143 if (checked) {
146 // adjust sizes individually here, e.g.
144 // adjust sizes individually here, e.g.
147 currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX]
145 currentSizes[splitterInspectorIndex] -= lastInspectorSize.width();
148 -= impl->m_LastOpenLeftInspectorSize.width();
146 currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width();
149 currentSizes[VIEWPLITTERINDEX] += impl->m_LastOpenLeftInspectorSize.width();
150 m_Ui->splitter->setSizes(currentSizes);
147 m_Ui->splitter->setSizes(currentSizes);
151 }
148 }
152 else {
149 else {
153 // adjust sizes individually here, e.g.
150 // adjust sizes individually here, e.g.
154 currentSizes[LEFTMAININSPECTORWIDGETSPLITTERINDEX]
151 currentSizes[splitterInspectorIndex] += lastInspectorSize.width();
155 += impl->m_LastOpenLeftInspectorSize.width();
152 currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width();
156 currentSizes[VIEWPLITTERINDEX] -= impl->m_LastOpenLeftInspectorSize.width();
157 m_Ui->splitter->setSizes(currentSizes);
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) {
159 connect(openLeftInspectorAction, &QAction::triggered,
166 openRightInspectorAction->setIcon(QIcon{
160 [openInspector, openLeftInspectorAction](bool checked) {
167 ":/icones/previous.png",
161 openInspector(checked, false, openLeftInspectorAction);
168 });
162 });
169 }
163 connect(openRightInspectorAction, &QAction::triggered,
170 else {
164 [openInspector, openRightInspectorAction](bool checked) {
171 openRightInspectorAction->setIcon(QIcon{
165 openInspector(checked, true, openRightInspectorAction);
172 ":/icones/next.png",
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 this->menuBar()->addAction(tr("File"));
168 this->menuBar()->addAction(tr("File"));
210 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
169 auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar"));
General Comments 0
You need to be logged in to leave comments. Login now