MNE-CPP  0.1.9
A Framework for Electrophysiology
control3dview.cpp
Go to the documentation of this file.
1 //=============================================================================================================
35 //=============================================================================================================
36 // INCLUDES
37 //=============================================================================================================
38 
39 #include "ui_control3dview.h"
40 #include "control3dview.h"
41 
42 //=============================================================================================================
43 // QT INCLUDES
44 //=============================================================================================================
45 
46 #include <QMenu>
47 #include <QSettings>
48 #include <QMessageBox>
49 
50 //=============================================================================================================
51 // EIGEN INCLUDES
52 //=============================================================================================================
53 
54 //=============================================================================================================
55 // QT INCLUDES
56 //=============================================================================================================
57 
58 #include <QStyledItemDelegate>
59 #include <QStandardItemModel>
60 #include <QColorDialog>
61 
62 //=============================================================================================================
63 // USED NAMESPACES
64 //=============================================================================================================
65 
66 using namespace DISPLIB;
67 
68 //=============================================================================================================
69 // DEFINE MEMBER METHODS
70 //=============================================================================================================
71 
72 Control3DView::Control3DView(const QString& sSettingsPath,
73  QWidget* parent,
74  const QStringList& slFlags,
75  Qt::WindowType type)
76 : AbstractView(parent, type)
77 , m_pUi(new Ui::Control3DViewWidget)
78 , m_colCurrentSceneColor(QColor(0,0,0))
79 , m_colCurrentLightColor(QColor(255,255,255))
80 {
81  m_sSettingsPath = sSettingsPath;
82  m_pUi->setupUi(this);
83 
84  setFlags(slFlags);
85 
86  //Init's
87  m_pUi->m_pushButton_sceneColorPicker->setStyleSheet(QString("background-color: rgb(0, 0, 0);"));
88  m_pUi->m_pushButton_lightColorPicker->setStyleSheet(QString("background-color: rgb(255, 255, 255);"));
89 
90  this->adjustSize();
91 
92  //set context menu
93  m_pUi->m_treeView_loadedData->setContextMenuPolicy(Qt::CustomContextMenu);
94  connect(m_pUi->m_treeView_loadedData, &QWidget::customContextMenuRequested,
96 
97  loadSettings();
98 }
99 
100 //=============================================================================================================
101 
103 {
104  saveSettings();
105  delete m_pUi;
106 }
107 
108 //=============================================================================================================
109 
110 void Control3DView::setFlags(const QStringList& slFlags)
111 {
112  //Parse flags
113  if(slFlags.contains("Data")) {
114  m_pUi->m_treeView_loadedData->show();
115  } else {
116  m_pUi->m_treeView_loadedData->hide();
117  }
118 
119  if(slFlags.contains("View")) {
120  m_pUi->m_groupBox_viewOptions->show();
121 
122  connect(m_pUi->m_pushButton_sceneColorPicker, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
124  connect(m_pUi->m_checkBox_showFullScreen, &QCheckBox::clicked,
126 
127  connect(m_pUi->m_checkBox_rotate, &QCheckBox::clicked,
129 
130  connect(m_pUi->m_checkBox_coordAxis, &QCheckBox::clicked,
132 
133  connect(m_pUi->m_pushButton_takeScreenshot, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
135 
136  connect(m_pUi->m_radioButton_single, &QRadioButton::pressed,
138 
139  connect(m_pUi->m_radioButton_multi, &QRadioButton::pressed,
141  } else {
142  m_pUi->m_groupBox_viewOptions->hide();
143  }
144 
145  if(slFlags.contains("Light")) {
146  m_pUi->m_groupBox_lightOptions->show();
147 
148  connect(m_pUi->m_pushButton_lightColorPicker, static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
150  connect(m_pUi->m_doubleSpinBox_colorIntensity, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
152  } else {
153  m_pUi->m_groupBox_lightOptions->hide();
154  }
155 }
156 
157 //=============================================================================================================
158 
159 void Control3DView::setDelegate(QStyledItemDelegate *pItemDelegate)
160 {
161  //Init tree view properties
162  m_pUi->m_treeView_loadedData->setItemDelegate(pItemDelegate);
163  m_pUi->m_treeView_loadedData->setHeaderHidden(false);
164  m_pUi->m_treeView_loadedData->setEditTriggers(QAbstractItemView::CurrentChanged);
165 }
166 
167 //=============================================================================================================
168 
169 void Control3DView::setModel(QStandardItemModel* pDataTreeModel)
170 {
171  //Do the connects from this control widget to the View3D
172  m_pUi->m_treeView_loadedData->setModel(pDataTreeModel);
173 
174  //Set description hidden as default
175  //m_pUi->m_treeView_loadedData->setColumnHidden(1, true);
176 }
177 
178 //=============================================================================================================
179 
181 {
182  if(!m_pUi->m_treeView_loadedData->isHeaderHidden()) {
183  m_pUi->m_treeView_loadedData->setHeaderHidden(true);
184  } else {
185  m_pUi->m_treeView_loadedData->setHeaderHidden(false);
186  }
187 }
188 
189 //=============================================================================================================
190 
191 void Control3DView::onTreeViewRemoveItem(const QModelIndex& index)
192 {
193  if(index.isValid()) {
194  m_pUi->m_treeView_loadedData->model()->removeRow(index.row(), index.parent());
195  }
196 }
197 
198 //=============================================================================================================
199 
201 {
202  if(m_pUi->m_treeView_loadedData->isColumnHidden(1)) {
203  m_pUi->m_treeView_loadedData->setColumnHidden(1, false);
204  } else {
205  m_pUi->m_treeView_loadedData->setColumnHidden(1, true);
206  }
207 }
208 
209 //=============================================================================================================
210 
212 {
213  if(m_sSettingsPath.isEmpty()) {
214  return;
215  }
216 
217  // Save Settings
218  QSettings settings("MNECPP");
219 }
220 
221 //=============================================================================================================
222 
224 {
225  if(m_sSettingsPath.isEmpty()) {
226  return;
227  }
228 
229  // Load Settings
230  QSettings settings("MNECPP");
231 }
232 
233 //=============================================================================================================
234 
236 {
237  switch(mode) {
238  case GuiMode::Clinical:
239  break;
240  default: // default is research mode
241  break;
242  }
243 }
244 
245 //=============================================================================================================
246 
247 void Control3DView::updateProcessingMode(ProcessingMode mode)
248 {
249  switch(mode) {
250  case ProcessingMode::Offline:
251  break;
252  default: // default is realtime mode
253  break;
254  }
255 }
256 
257 //=============================================================================================================
258 
260 {
261  this->setWindowOpacity(1/(100.0/value));
262 }
263 
264 //=============================================================================================================
265 
267 {
268  QColorDialog* pDialog = new QColorDialog(this);
269  pDialog->setCurrentColor(m_colCurrentSceneColor);
270 
271  //Update all connected View3D's scene colors
272  connect(pDialog, &QColorDialog::currentColorChanged,
274 
275  pDialog->exec();
276  m_colCurrentSceneColor = pDialog->currentColor();
277 
278  //Set color of button new new scene color
279  m_pUi->m_pushButton_sceneColorPicker->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(m_colCurrentSceneColor.red()).arg(m_colCurrentSceneColor.green()).arg(m_colCurrentSceneColor.blue()));
280 }
281 
282 //=============================================================================================================
283 
285 {
286  //create custom context menu and actions
287  QMenu *menu = new QMenu(this);
288 
289  // Hide header
290  QAction* pHideHeader = menu->addAction(tr("Toggle header"));
291  connect(pHideHeader, &QAction::triggered,
293 
294  // Remove item
295  QAction* pRemoveItem = menu->addAction(tr("Remove"));
296  connect(pRemoveItem, &QAction::triggered, [=]() {
297  if (QMessageBox::question(this,
298  tr("Remove item"),
299  tr("Are you sure you want to delete the item?")) == QMessageBox::Yes) {
300  onTreeViewRemoveItem(m_pUi->m_treeView_loadedData->indexAt(pos));
301  }
302  });
303 
304 // QAction* pHideDesc = menu->addAction(tr("Toggle description"));
305 // connect(pHideDesc, &QAction::triggered,
306 // this, &Control3DView::onTreeViewDescriptionHide);
307 
308  //show context menu
309  menu->popup(m_pUi->m_treeView_loadedData->viewport()->mapToGlobal(pos));
310 }
311 
312 //=============================================================================================================
313 
315 {
316  if(state) {
317  this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
318  this->show();
319  } else {
320  this->setWindowFlags(this->windowFlags() & ~Qt::WindowStaysOnTopHint);
321  this->show();
322  }
323 }
324 
325 //=============================================================================================================
326 
327 void Control3DView::onSceneColorChanged(const QColor& color)
328 {
329  emit sceneColorChanged(color);
330 }
331 
332 //=============================================================================================================
333 
335 {
336  emit showFullScreen(checked);
337 }
338 
339 //=============================================================================================================
340 
342 {
343  emit rotationChanged(checked);
344 }
345 
346 //=============================================================================================================
347 
349 {
350  emit showCoordAxis(checked);
351 }
352 
353 //=============================================================================================================
354 
356 {
357  QColorDialog* pDialog = new QColorDialog(this);
358  pDialog->setCurrentColor(m_colCurrentLightColor);
359 
360  //Update all connected View3D's scene colors
361  connect(pDialog, &QColorDialog::currentColorChanged,
363 
364  pDialog->exec();
365  m_colCurrentLightColor = pDialog->currentColor();
366 
367  //Set color of button new new scene color
368  m_pUi->m_pushButton_lightColorPicker->setStyleSheet(QString("background-color: rgb(%1, %2, %3);").arg(m_colCurrentLightColor.red()).arg(m_colCurrentLightColor.green()).arg(m_colCurrentLightColor.blue()));
369 }
370 
371 //=============================================================================================================
372 
373 void Control3DView::onLightColorChanged(const QColor &color)
374 {
375  emit lightColorChanged(color);
376 }
377 
378 //=============================================================================================================
379 
381 {
382  emit lightIntensityChanged(value);
383 }
384 
385 //=============================================================================================================
386 
388 {
389 
390 }
DISPLIB::Control3DView::setFlags
void setFlags(const QStringList &slFlags)
Definition: control3dview.cpp:110
DISPLIB::AbstractView
The AbstractView class provides the base calss for all Disp viewers.
Definition: abstractview.h:75
DISPLIB::Control3DView::~Control3DView
~Control3DView()
Definition: control3dview.cpp:102
DISPLIB::Control3DView::onTreeViewRemoveItem
void onTreeViewRemoveItem(const QModelIndex &index)
Definition: control3dview.cpp:191
DISPLIB::Control3DView::m_colCurrentSceneColor
QColor m_colCurrentSceneColor
Definition: control3dview.h:271
DISPLIB::Control3DView::m_colCurrentLightColor
QColor m_colCurrentLightColor
Definition: control3dview.h:272
DISPLIB::Control3DView::onCustomContextMenuRequested
void onCustomContextMenuRequested(QPoint pos)
customContextMenuRequested
Definition: control3dview.cpp:284
DISPLIB::Control3DView::onShowFullScreen
void onShowFullScreen(bool checked)
Definition: control3dview.cpp:334
DISPLIB::Control3DView::sceneColorChanged
void sceneColorChanged(const QColor &color)
control3dview.h
Control3DView class declaration.
DISPLIB::Control3DView::rotationChanged
void rotationChanged(bool bRotationChanged)
DISPLIB::Control3DView::lightIntensityChanged
void lightIntensityChanged(double value)
DISPLIB::Control3DView::onLightColorChanged
void onLightColorChanged(const QColor &color)
Definition: control3dview.cpp:373
DISPLIB::Control3DView::Control3DView
Control3DView(const QString &sSettingsPath="", QWidget *parent=0, const QStringList &slFlags=QStringList()<< "Data"<< "View"<< "Light", Qt::WindowType type=Qt::Widget)
Definition: control3dview.cpp:72
DISPLIB::Control3DView::onSceneColorPicker
void onSceneColorPicker()
Definition: control3dview.cpp:266
DISPLIB::Control3DView::showCoordAxis
void showCoordAxis(bool bShowCoordAxis)
DISPLIB::Control3DView::m_pUi
Ui::Control3DViewWidget * m_pUi
Definition: control3dview.h:269
DISPLIB::Control3DView::onLightIntensityChanged
void onLightIntensityChanged(double value)
Definition: control3dview.cpp:380
DISPLIB::Control3DView::updateProcessingMode
void updateProcessingMode(ProcessingMode mode)
Definition: control3dview.cpp:247
DISPLIB::Control3DView::onAlwaysOnTop
void onAlwaysOnTop(bool state)
Definition: control3dview.cpp:314
DISPLIB::Control3DView::onLightColorPicker
void onLightColorPicker()
Definition: control3dview.cpp:355
DISPLIB::Control3DView::toggleMutiview
void toggleMutiview()
DISPLIB::AbstractView::m_sSettingsPath
QString m_sSettingsPath
Definition: abstractview.h:169
DISPLIB::Control3DView::takeScreenshotChanged
void takeScreenshotChanged()
DISPLIB::Control3DView::onSceneColorChanged
void onSceneColorChanged(const QColor &color)
Definition: control3dview.cpp:327
DISPLIB::Control3DView::onRotationClicked
void onRotationClicked(bool checked)
Definition: control3dview.cpp:341
DISPLIB::Control3DView::lightColorChanged
void lightColorChanged(const QColor &color)
DISPLIB::Control3DView::setModel
void setModel(QStandardItemModel *pDataTreeModel)
Definition: control3dview.cpp:169
DISPLIB::Control3DView::showFullScreen
void showFullScreen(bool bShowFullScreen)
DISPLIB::Control3DView::clearView
void clearView()
Definition: control3dview.cpp:387
DISPLIB::Control3DView::onTreeViewHeaderHide
void onTreeViewHeaderHide()
Definition: control3dview.cpp:180
DISPLIB::Control3DView::onTreeViewDescriptionHide
void onTreeViewDescriptionHide()
Definition: control3dview.cpp:200
DISPLIB::Control3DView::loadSettings
void loadSettings()
Definition: control3dview.cpp:223
DISPLIB::Control3DView::toggleSingleView
void toggleSingleView()
DISPLIB::Control3DView::updateGuiMode
void updateGuiMode(GuiMode mode)
Definition: control3dview.cpp:235
DISPLIB::Control3DView::onOpacityChange
void onOpacityChange(qint32 value)
Definition: control3dview.cpp:259
DISPLIB::Control3DView::saveSettings
void saveSettings()
Definition: control3dview.cpp:211
DISPLIB::Control3DView::setDelegate
void setDelegate(QStyledItemDelegate *pItemDelegate)
Definition: control3dview.cpp:159
DISPLIB::Control3DView::onCoordAxisClicked
void onCoordAxisClicked(bool checked)
Definition: control3dview.cpp:348