46 #include "mainwindow.h"
62 #include <QFileDialog>
64 #include <QStandardPaths>
82 const char* pluginDir =
"/mne_x_plugins";
95 , m_bDisplayMax(false)
98 , m_pDynamicPluginToolBar(NULL)
99 , m_pDynamicDisplayToolBar(NULL)
102 , m_pTime(new QTime(0, 0))
103 , m_iTimeoutMSec(1000)
107 , m_eLogLevelCurrent(_LogLvMax)
111 setCentralWidget(m_pStartUpWidget);
114 setMinimumSize(400, 400);
117 setUnifiedTitleAndToolBarOnMac(
true);
119 m_pPluginManager->loadPlugins(qApp->applicationDirPath()+pluginDir);
124 createPluginDockWindow();
125 createLogDockWindow();
151 if(m_pDynamicPluginToolBar)
152 delete m_pDynamicPluginToolBar;
154 if(m_pDynamicDisplayToolBar)
155 delete m_pDynamicDisplayToolBar;
164 this->stopMeasurement();
172 QMainWindow::closeEvent(event);
179 void MainWindow::newConfiguration()
181 writeToLog(tr(
"Invoked <b>File|NewConfiguration</b>"), _LogKndMessage, _LogLvMin);
188 void MainWindow::openConfiguration()
190 writeToLog(tr(
"Invoked <b>File|OpenConfiguration</b>"), _LogKndMessage, _LogLvMin);
192 QString path = QFileDialog::getOpenFileName(
this,
193 "Open MNE-X Configuration File",
194 QStandardPaths::writableLocation(QStandardPaths::DataLocation),
195 tr(
"Configuration file (*.xml)"));
197 QFileInfo qFileInfo(path);
198 m_pPluginGui->
loadConfig(qFileInfo.path(), qFileInfo.fileName());
204 void MainWindow::saveConfiguration()
206 writeToLog(tr(
"Invoked <b>File|SaveConfiguration</b>"), _LogKndMessage, _LogLvMin);
208 QString path = QFileDialog::getSaveFileName(
210 "Save MNE-X Configuration File",
211 QStandardPaths::writableLocation(QStandardPaths::DataLocation),
212 tr(
"Configuration file (*.xml)"));
214 QFileInfo qFileInfo(path);
215 m_pPluginGui->
saveConfig(qFileInfo.path(), qFileInfo.fileName());
221 void MainWindow::helpContents()
223 writeToLog(tr(
"Invoked <b>Help|HelpContents</b>"), _LogKndMessage, _LogLvMin);
229 void MainWindow::about()
231 writeToLog(tr(
"Invoked <b>Help|About</b>"), _LogKndMessage, _LogLvMin);
233 tr(
"Copyright (C) 2013 Christoph Dinh, Martin Luessi, Limin Sun, Jens Haueisen, Matti Hamalainen. All rights reserved.\n\n"
234 "Redistribution and use in source and binary forms, with or without modification, are permitted provided that"
235 " the following conditions are met:\n"
236 "\t* Redistributions of source code must retain the above copyright notice, this list of conditions and the"
237 " following disclaimer.\n"
238 "\t* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and"
239 " the following disclaimer in the documentation and/or other materials provided with the distribution.\n"
240 "\t* Neither the name of MNE-CPP authors nor the names of its contributors may be used"
241 " to endorse or promote products derived from this software without specific prior written permission.\n\n"
242 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED"
243 " WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A"
244 " PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,"
245 " INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,"
246 " PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)"
247 " HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING"
248 " NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE"
249 " POSSIBILITY OF SUCH DAMAGE."));
255 void MainWindow::setMinLogLevel()
257 writeToLog(tr(
"minimal log level set"), _LogKndMessage, _LogLvMin);
258 m_eLogLevelCurrent = _LogLvMin;
264 void MainWindow::setNormalLogLevel()
266 writeToLog(tr(
"normal log level set"), _LogKndMessage, _LogLvMin);
267 m_eLogLevelCurrent = _LogLvNormal;
273 void MainWindow::setMaxLogLevel()
275 writeToLog(tr(
"maximal log level set"), _LogKndMessage, _LogLvMin);
276 m_eLogLevelCurrent = _LogLvMax;
281 void MainWindow::createActions()
284 m_pActionNewConfig =
new QAction(QIcon(
":/images/new.png"), tr(
"&New configuration"),
this);
285 m_pActionNewConfig->setShortcuts(QKeySequence::New);
286 m_pActionNewConfig->setStatusTip(tr(
"Create a new configuration"));
287 connect(m_pActionNewConfig, &QAction::triggered,
this, &MainWindow::newConfiguration);
289 m_pActionOpenConfig =
new QAction(tr(
"&Open configuration..."),
this);
290 m_pActionOpenConfig->setShortcuts(QKeySequence::Open);
291 m_pActionOpenConfig->setStatusTip(tr(
"Open an existing configuration"));
292 connect(m_pActionOpenConfig, &QAction::triggered,
this, &MainWindow::openConfiguration);
294 m_pActionSaveConfig =
new QAction(QIcon(
":/images/save.png"), tr(
"&Save configuration..."),
this);
295 m_pActionSaveConfig->setShortcuts(QKeySequence::Save);
296 m_pActionSaveConfig->setStatusTip(tr(
"Save the current configuration"));
297 connect(m_pActionSaveConfig, &QAction::triggered,
this, &MainWindow::saveConfiguration);
299 m_pActionExit =
new QAction(tr(
"E&xit"),
this);
300 m_pActionExit->setShortcuts(QKeySequence::Quit);
301 m_pActionExit->setStatusTip(tr(
"Exit the application"));
302 connect(m_pActionExit, &QAction::triggered,
this, &MainWindow::close);
305 m_pActionMinLgLv =
new QAction(tr(
"&Minimal"),
this);
306 m_pActionMinLgLv->setCheckable(
true);
307 m_pActionMinLgLv->setShortcut(tr(
"Ctrl+1"));
308 m_pActionMinLgLv->setStatusTip(tr(
"Open an existing file"));
309 connect(m_pActionMinLgLv, &QAction::triggered,
this, &MainWindow::setMinLogLevel);
311 m_pActionNormLgLv =
new QAction(tr(
"&Normal"),
this);
312 m_pActionNormLgLv->setCheckable(
true);
313 m_pActionNormLgLv->setShortcut(tr(
"Ctrl+2"));
314 m_pActionNormLgLv->setStatusTip(tr(
"Save the document to disk"));
315 connect(m_pActionNormLgLv, &QAction::triggered,
this, &MainWindow::setNormalLogLevel);
317 m_pActionMaxLgLv =
new QAction(tr(
"Maximal"),
this);
318 m_pActionMaxLgLv->setCheckable(
true);
319 m_pActionMaxLgLv->setShortcut(tr(
"Ctrl+3"));
320 m_pActionMaxLgLv->setStatusTip(tr(
"Exit the application"));
321 connect(m_pActionMaxLgLv, &QAction::triggered,
this, &MainWindow::setMaxLogLevel);
323 m_pActionGroupLgLv =
new QActionGroup(
this);
324 m_pActionGroupLgLv->addAction(m_pActionMinLgLv);
325 m_pActionGroupLgLv->addAction(m_pActionNormLgLv);
326 m_pActionGroupLgLv->addAction(m_pActionMaxLgLv);
327 if (m_eLogLevelCurrent == _LogLvMin){
328 m_pActionMinLgLv->setChecked(
true);}
329 else if (m_eLogLevelCurrent == _LogLvNormal){
330 m_pActionNormLgLv->setChecked(
true);}
332 m_pActionMaxLgLv->setChecked(
true);}
335 m_pActionHelpContents =
new QAction(tr(
"Help &Contents"),
this);
336 m_pActionHelpContents->setShortcuts(QKeySequence::HelpContents);
337 m_pActionHelpContents->setStatusTip(tr(
"Show the help contents"));
338 connect(m_pActionHelpContents, &QAction::triggered,
this, &MainWindow::helpContents);
340 m_pActionAbout =
new QAction(tr(
"&About"),
this);
341 m_pActionAbout->setStatusTip(tr(
"Show the application's About box"));
342 connect(m_pActionAbout, &QAction::triggered,
this, &MainWindow::about);
345 m_pActionRun =
new QAction(QIcon(
":/images/run.png"), tr(
"Run (F5)"),
this);
346 m_pActionRun->setShortcut(tr(
"F5"));
348 connect(m_pActionRun, &QAction::triggered,
this, &MainWindow::startMeasurement);
350 m_pActionStop =
new QAction(QIcon(
":/images/stop.png"), tr(
"Stop (F6)"),
this);
351 m_pActionStop->setShortcut(tr(
"F6"));
353 connect(m_pActionStop, &QAction::triggered,
this, &MainWindow::stopMeasurement);
355 m_pActionZoomStd =
new QAction(QIcon(
":/images/zoomStd.png"), tr(
"Standard Zoom (Ctrl+0)"),
this);
356 m_pActionZoomStd->setShortcut(tr(
"Ctrl+0"));
357 m_pActionZoomStd->setStatusTip(tr(
"Sets the standard Zoom (Ctrl+0)"));
358 connect(m_pActionZoomStd, &QAction::triggered,
this, &MainWindow::zoomStd);
360 m_pActionZoomIn =
new QAction(QIcon(
":/images/zoomIn.png"), tr(
"Zoom In ")+QKeySequence(QKeySequence::ZoomIn).toString(),
this);
361 m_pActionZoomIn->setShortcuts(QKeySequence::ZoomIn);
362 m_pActionZoomIn->setStatusTip(tr(
"Zooms in the magnitude ")+QKeySequence(QKeySequence::ZoomIn).toString());
363 connect(m_pActionZoomIn, &QAction::triggered,
this, &MainWindow::zoomIn);
365 m_pActionZoomOut =
new QAction(QIcon(
":/images/zoomOut.png"), tr(
"Zoom Out ")+QKeySequence(QKeySequence::ZoomOut).toString(),
this);
366 m_pActionZoomOut->setShortcuts(QKeySequence::ZoomOut);
367 m_pActionZoomOut->setStatusTip(tr(
"Zooms out the magnitude ")+QKeySequence(QKeySequence::ZoomOut).toString());
368 connect(m_pActionZoomOut, &QAction::triggered,
this, &MainWindow::zoomOut);
370 m_pActionDisplayMax =
new QAction(QIcon(
":/images/displayMax.png"), tr(
"Maximize current Display (F11)"),
this);
371 m_pActionDisplayMax->setShortcut(tr(
"F11"));
372 m_pActionDisplayMax->setStatusTip(tr(
"Maximizes the current display (F11)"));
373 connect(m_pActionDisplayMax, &QAction::triggered,
this, &MainWindow::toggleDisplayMax);
379 void MainWindow::createMenus()
381 m_pMenuFile = menuBar()->addMenu(tr(
"&File"));
382 m_pMenuFile->addAction(m_pActionNewConfig);
383 m_pMenuFile->addAction(m_pActionOpenConfig);
384 m_pMenuFile->addAction(m_pActionSaveConfig);
385 m_pMenuFile->addSeparator();
386 m_pMenuFile->addAction(m_pActionExit);
388 m_pMenuView = menuBar()->addMenu(tr(
"&View"));
389 m_pMenuLgLv = m_pMenuView->addMenu(tr(
"&Log Level"));
390 m_pMenuLgLv->addAction(m_pActionMinLgLv);
391 m_pMenuLgLv->addAction(m_pActionNormLgLv);
392 m_pMenuLgLv->addAction(m_pActionMaxLgLv);
393 m_pMenuView->addSeparator();
395 menuBar()->addSeparator();
397 m_pMenuHelp = menuBar()->addMenu(tr(
"&Help"));
398 m_pMenuHelp->addAction(m_pActionHelpContents);
399 m_pMenuHelp->addSeparator();
400 m_pMenuHelp->addAction(m_pActionAbout);
407 void MainWindow::createToolBars()
412 m_pToolBar = addToolBar(tr(
"Control"));
413 m_pToolBar->addAction(m_pActionRun);
414 m_pToolBar->addAction(m_pActionStop);
415 m_pActionStop->setEnabled(
false);
417 m_pToolBar->addSeparator();
419 m_pToolBar->addAction(m_pActionZoomStd);
420 m_pToolBar->addAction(m_pActionZoomIn);
421 m_pToolBar->addAction(m_pActionZoomOut);
422 m_pToolBar->addAction(m_pActionDisplayMax);
423 m_pActionZoomStd->setEnabled(
false);
424 m_pActionZoomIn->setEnabled(
false);
425 m_pActionZoomOut->setEnabled(
false);
426 m_pActionDisplayMax->setEnabled(
false);
428 m_pToolBar->addSeparator();
430 m_pLabelTime =
new QLabel(
this);
431 m_pToolBar->addWidget(m_pLabelTime);
432 m_pLabelTime->setText(QTime(0, 0).toString());
436 if(m_pDynamicPluginToolBar)
438 removeToolBar(m_pDynamicPluginToolBar);
439 delete m_pDynamicPluginToolBar;
440 m_pDynamicPluginToolBar = NULL;
442 if(m_qListDynamicPluginActions.size() > 0)
444 m_pDynamicPluginToolBar = addToolBar(m_sCurPluginName + tr(
"Control"));
445 for(qint32 i = 0; i < m_qListDynamicPluginActions.size(); ++i)
446 m_pDynamicPluginToolBar->addAction(m_qListDynamicPluginActions[i]);
450 if(m_pDynamicDisplayToolBar)
452 removeToolBar(m_pDynamicDisplayToolBar);
453 delete m_pDynamicDisplayToolBar;
454 m_pDynamicDisplayToolBar = NULL;
456 if(m_qListDynamicDisplayActions.size() > 0 || m_qListDynamicDisplayWidgets.size() > 0)
458 m_pDynamicDisplayToolBar = addToolBar(tr(
"Display"));
459 for(qint32 i = 0; i < m_qListDynamicDisplayActions.size(); ++i)
460 m_pDynamicDisplayToolBar->addAction(m_qListDynamicDisplayActions[i]);
461 for(qint32 i = 0; i < m_qListDynamicDisplayWidgets.size(); ++i)
462 m_pDynamicDisplayToolBar->addWidget(m_qListDynamicDisplayWidgets[i]);
470 void MainWindow::initStatusBar()
472 statusBar()->showMessage(tr(
"Ready"));
478 void MainWindow::createPluginDockWindow()
480 m_pPluginGuiDockWidget =
new QDockWidget(tr(
"Plugins"),
this);
481 m_pPluginGuiDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
483 m_pPluginGui =
new PluginGui(m_pPluginManager.data(), m_pPluginSceneManager.data());
484 m_pPluginGui->setParent(m_pPluginGuiDockWidget);
485 m_pPluginGuiDockWidget->setWidget(m_pPluginGui);
487 addDockWidget(Qt::LeftDockWidgetArea, m_pPluginGuiDockWidget);
489 connect(m_pPluginGui, &PluginGui::selectedPluginChanged,
490 this, &MainWindow::updatePluginWidget);
492 connect(m_pPluginGui, &PluginGui::selectedConnectionChanged,
493 this, &MainWindow::updateConnectionWidget);
499 void MainWindow::createLogDockWindow()
502 m_pDockWidget_Log =
new QDockWidget(tr(
"Log"),
this);
504 m_pTextBrowser_Log =
new QTextBrowser(m_pDockWidget_Log);
506 m_pDockWidget_Log->setWidget(m_pTextBrowser_Log);
508 m_pDockWidget_Log->setAllowedAreas(Qt::BottomDockWidgetArea);
509 addDockWidget(Qt::BottomDockWidgetArea, m_pDockWidget_Log);
513 m_pMenuView->addAction(m_pDockWidget_Log->toggleViewAction());
522 m_qListDynamicPluginActions.clear();
523 m_qListDynamicDisplayActions.clear();
524 m_qListDynamicDisplayWidgets.clear();
526 if(!pPlugin.isNull())
529 m_qListDynamicPluginActions.append(pPlugin->getPluginActions());
531 m_sCurPluginName = pPlugin->getName();
542 QWidget* pWidget =
new QWidget;
543 setCentralWidget(pWidget);
548 setCentralWidget(pPlugin->setupWidget());
551 m_pRunWidget =
new RunWidget( m_pDisplayManager->show(pPlugin->getOutputConnectors(), m_pTime, m_qListDynamicDisplayActions, m_qListDynamicDisplayWidgets));
553 m_pRunWidget->show();
557 m_pRunWidget->showFullScreen();
559 m_pRunWidgetClose =
new QShortcut(QKeySequence(Qt::Key_Escape), m_pRunWidget, SLOT(close()));
562 setCentralWidget(m_pRunWidget);
568 QWidget* t_pWidgetEmpty =
new QWidget;
569 setCentralWidget(t_pWidgetEmpty);
572 this->createToolBars();
580 QWidget* pWidget = pConnection->setupWidget();
581 setCentralWidget(pWidget);
589 if(lglvl<=m_eLogLevelCurrent)
591 if(lgknd == _LogKndError)
593 m_pTextBrowser_Log->insertHtml(
"<font color=red><b>Error:</b> "+logMsg+
"</font>");
596 else if(lgknd == _LogKndWarning)
598 m_pTextBrowser_Log->insertHtml(
"<font color=blue><b>Warning:</b> "+logMsg+
"</font>");
602 m_pTextBrowser_Log->insertHtml(logMsg);
604 m_pTextBrowser_Log->insertPlainText(
"\n");
606 QTextCursor c = m_pTextBrowser_Log->textCursor();
607 c.movePosition(QTextCursor::End);
608 m_pTextBrowser_Log->setTextCursor(c);
610 m_pTextBrowser_Log->verticalScrollBar()->setValue(m_pTextBrowser_Log->verticalScrollBar()->maximum());
617 void MainWindow::startMeasurement()
619 writeToLog(tr(
"Starting real-time measurement..."), _LogKndMessage, _LogLvMin);
621 if(!m_pPluginSceneManager->startPlugins())
623 QMessageBox::information(0, tr(
"MNE X - Start"), QString(QObject::tr(
"Not able to start at least one sensor plugin!")), QMessageBox::Ok);
627 m_pPluginGui->uiSetupRunningState(
true);
628 uiSetupRunningState(
true);
631 updatePluginWidget(m_pPluginGui->getCurrentPlugin());
656 void MainWindow::stopMeasurement()
658 writeToLog(tr(
"Stopping real-time measurement..."), _LogKndMessage, _LogLvMin);
660 m_pPluginSceneManager->stopPlugins();
661 m_pDisplayManager->clean();
664 m_pPluginGui->uiSetupRunningState(
false);
665 uiSetupRunningState(
false);
668 updatePluginWidget(m_pPluginGui->getCurrentPlugin());
684 void MainWindow::zoomStd()
689 m_pActionZoomStd->setEnabled(
false);
696 void MainWindow::zoomIn()
701 m_pActionZoomStd->setEnabled(
true);
708 void MainWindow::zoomOut()
713 m_pActionZoomStd->setEnabled(
true);
721 void MainWindow::toggleDisplayMax()
724 m_bDisplayMax = !m_bDisplayMax;
726 m_pActionDisplayMax->setEnabled(!m_bDisplayMax);
728 updatePluginWidget(m_pPluginGui->getCurrentPlugin());
734 void MainWindow::uiSetupRunningState(
bool state)
736 m_pActionRun->setEnabled(!state);
737 m_pActionStop->setEnabled(state);
741 m_pActionZoomStd->setEnabled(!state);
742 m_pActionZoomIn->setEnabled(state);
743 m_pActionZoomOut->setEnabled(state);
744 m_pActionDisplayMax->setEnabled(state);
748 m_pActionZoomStd->setEnabled(state);
749 m_pActionZoomIn->setEnabled(state);
750 m_pActionZoomOut->setEnabled(state);
751 m_pActionDisplayMax->setEnabled(state);
754 m_bIsRunning = state;
763 m_pTimer = QSharedPointer<QTimer>(
new QTimer(
this));
764 connect(m_pTimer.data(), &QTimer::timeout,
this, &MainWindow::updateTime);
765 m_pTimer->start(msec);
766 m_pTime->setHMS(0,0,0);
767 QString strTime = m_pTime->toString();
768 m_pLabelTime->setText(strTime);
776 disconnect(m_pTimer.data(), &QTimer::timeout,
this, &MainWindow::updateTime);
782 void MainWindow::updateTime()
784 *m_pTime = m_pTime->addMSecs(m_iTimeoutMSec);
785 QString strTime = m_pTime->toString();
786 m_pLabelTime->setText(strTime);
Contains declaration of PluginSceneManager class.
QSharedPointer< PluginConnectorConnection > SPtr
Contains the declaration of the PluginManager class.
static const QString AppNameShort()
PluginGui class declaration.
The PluginManager class provides a dynamic plugin loader. As well as the handling of the loaded plugi...
Declaration of the DisplayManager Class.
static const QString AppVersion()
void loadConfig(const QString &sPath, const QString &sFileName)
QSharedPointer< IPlugin > SPtr
void startTimer(int msec)
The PluginSceneManager class manages plugins and connections of a set of plugins. ...
The DisplayManager class handles current displayed widgets.
void writeToLog(const QString &logMsg, LogKind lgknd=_LogKndMessage, LogLevel lglvl=_LogLvNormal)
void saveConfig(const QString &sPath, const QString &sFileName)
MainWindow(QWidget *parent=0)
void closeEvent(QCloseEvent *event)