mainwindow.cpp
367 lines
| 14.3 KiB
| text/x-c
|
CppLexer
/ src / mainwindow.cpp
Jeandet Alexis
|
r0 | /*------------------------------------------------------------------------------ | ||
-- This file is a part of the SocExplorer Software | ||||
r91 | -- Copyright (C) 2011-2015, Plasma Physics Laboratory - CNRS | |||
Jeandet Alexis
|
r0 | -- | ||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@lpp.polytechnique.fr | ||||
----------------------------------------------------------------------------*/ | ||||
#include "mainwindow.h" | ||||
#include <QDockWidget> | ||||
r91 | #include <socexplorersettings.h> | |||
#include <socexplorerconfigkeys.h> | ||||
Jeandet Alexis
|
r0 | |||
Jeandet Alexis
|
r13 | SocExplorerMainWindow::SocExplorerMainWindow(QString ScriptToEval, QWidget *parent) | ||
Jeandet Alexis
|
r0 | : QMainWindow(parent) | ||
{ | ||||
QCoreApplication::setApplicationName("SocExplorer"); | ||||
QCoreApplication::setOrganizationName("LPP"); | ||||
QCoreApplication::setOrganizationDomain("lpp.fr"); | ||||
this->makeObjects(ScriptToEval); | ||||
this->makeLayout(); | ||||
this->makeMenu(); | ||||
r91 | SocExplorerSettings::init(); | |||
Jeandet Alexis
|
r0 | this->makeConnections(); | ||
r71 | this->setWindowIcon(QIcon(":/images/icon.png")); | |||
Jeandet Alexis
|
r0 | this->setAcceptDrops(true); | ||
this->pluginManager->setRootLoadable(true); | ||||
this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval); | ||||
Jeandet Alexis
|
r15 | QFile file(":/styles/SocExplorer.css"); | ||
if(file.open(QIODevice::ReadOnly | QIODevice::Text)) | ||||
{ | ||||
qApp->setStyleSheet(file.readAll()); | ||||
file.close(); | ||||
} | ||||
Jeandet Alexis
|
r0 | } | ||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::makeObjects(QString ScriptToEval) | ||
Jeandet Alexis
|
r0 | { | ||
Q_UNUSED(ScriptToEval) | ||||
Jeandet Alexis
|
r12 | this->p_pluginGUIlist = new QList<QDockWidget*>(); | ||
Jeandet Alexis
|
r0 | pluginsDockContainer = new QMainWindow; | ||
Jeandet Alexis
|
r94 | pluginsDockContainer->setObjectName("pluginsDockContainer"); | ||
Jeandet Alexis
|
r0 | pluginsDockContainer->setWindowFlags(Qt::Widget); | ||
pluginsDockContainer->setDockNestingEnabled(true); | ||||
Jeandet Alexis
|
r95 | this->sessionsActions = new QActionGroup(this); | ||
this->sessionManagerAction =new QAction(tr("&Session manager"),this); | ||||
Jeandet Alexis
|
r0 | this->mainWidget = new QSplitter(Qt::Vertical); | ||
this->appTranslator = new QTranslator; | ||||
this->Quit = new QAction(tr("&Quit"),this); | ||||
this->Quit->setShortcut(tr("CTRL+Q")); | ||||
this->ManagePlugins = new QAction(tr("&Manage Plugins"),this); | ||||
this->ManagePlugins->setShortcut(tr("CTRL+P")); | ||||
this->regsManager = new QAction(tr("&Manage registers"),this); | ||||
this->exploreRegs = new QAction(tr("&Explore registers"),this); | ||||
this->help = new QAction(tr("&Help"),this); | ||||
this->help->setShortcut(tr("CTRL+H")); | ||||
this->about = new QAction(tr("&About"),this); | ||||
Jeandet Alexis
|
r92 | this->p_SessionManagerDialog = new SessionManagerDialog(); | ||
Jeandet Alexis
|
r0 | socexplorerproxy::setMainWindow(this); | ||
SocExplorerEngine::setMainWindow(this); | ||||
SocExplorerEngine::xmlModel()->scanXmlFiles(); | ||||
r79 | this->regExplorer = new RegsExplorer(); | |||
Jeandet Alexis
|
r0 | this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas); | ||
Jeandet Alexis
|
r94 | this->regExplorer->setObjectName("regExplorer"); | ||
r10 | this->addPluginInterface(this->regExplorer); | |||
Jeandet Alexis
|
r0 | this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self()); | ||
this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self()); | ||||
this->pluginManager = new dockablePluginManager(); | ||||
this->toolpane = new toolBar; | ||||
Jeandet Alexis
|
r94 | this->toolpane->setObjectName("toolpane"); | ||
Jeandet Alexis
|
r0 | this->p_about = new aboutsocexplorer(); | ||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::makeLayout() | ||
Jeandet Alexis
|
r0 | { | ||
this->mainWidget->addWidget(pluginsDockContainer); | ||||
this->mainWidget->addWidget(this->PythonConsoleInst); | ||||
this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); | ||||
this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane); | ||||
this->toolpane->addTool(this->pluginManager); | ||||
this->setCentralWidget(this->mainWidget); | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::makeConnections() | ||
Jeandet Alexis
|
r0 | { | ||
connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu())); | ||||
connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText())); | ||||
connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*))); | ||||
Jeandet Alexis
|
r12 | connect(socexplorerproxy::self(),SIGNAL(removePluginGUI(QDockWidget*)),this,SLOT(removePluginInterface(QDockWidget*))); | ||
Jeandet Alexis
|
r0 | connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager())); | ||
connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit())); | ||||
connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString))); | ||||
connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString))); | ||||
connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree())); | ||||
connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>))); | ||||
connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString))); | ||||
connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString))); | ||||
connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString))); | ||||
connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString))); | ||||
r10 | connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString))); | |||
Jeandet Alexis
|
r0 | connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox())); | ||
connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show())); | ||||
r10 | ||||
Jeandet Alexis
|
r94 | connect(this->sessionManagerAction, SIGNAL(triggered(bool)),this,SLOT(showSessionManager(bool))); | ||
connect(this->p_SessionManagerDialog, SIGNAL(switchSession(QString)),this,SLOT(setActiveSession(QString))); | ||||
r97 | connect(this->p_SessionManagerDialog, SIGNAL(sessionRenamed(QString,QString)),this,SLOT(renameSession(QString,QString))); | |||
connect(this->p_SessionManagerDialog, SIGNAL(sessionAdded(QString)),this,SLOT(addSession(QString))); | ||||
connect(this->p_SessionManagerDialog, SIGNAL(sessionRemoved(QString)),this,SLOT(removeSession(QString))); | ||||
Jeandet Alexis
|
r95 | connect(this->sessionsActions,SIGNAL(triggered(QAction*)),this,SLOT(setActiveSession(QAction*))); | ||
Jeandet Alexis
|
r92 | |||
Jeandet Alexis
|
r0 | this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString))); | ||
this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString))); | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::launchPluginManager() | ||
Jeandet Alexis
|
r0 | { | ||
if(this->pluginManager->isHidden()) | ||||
{ | ||||
this->pluginManager->setHidden(false); | ||||
} | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::addPluginInterface(QDockWidget *plugin) | ||
Jeandet Alexis
|
r0 | { | ||
plugin->setAllowedAreas(Qt::AllDockWidgetAreas); | ||||
this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin); | ||||
Jeandet Alexis
|
r12 | if(p_pluginGUIlist->count()!=0) | ||
this->pluginsDockContainer->tabifyDockWidget(p_pluginGUIlist->last(),plugin); | ||||
p_pluginGUIlist->append(plugin); | ||||
Jeandet Alexis
|
r0 | } | ||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::removePluginInterface(QDockWidget *plugin) | ||
Jeandet Alexis
|
r12 | { | ||
p_pluginGUIlist->removeOne(plugin); | ||||
this->pluginsDockContainer->removeDockWidget(plugin); | ||||
} | ||||
Jeandet Alexis
|
r0 | |||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::clearMenu() | ||
Jeandet Alexis
|
r0 | { | ||
this->menuBar()->clear(); | ||||
this->makeMenu(); | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::makeMenu() | ||
Jeandet Alexis
|
r0 | { | ||
this->FileMenu = menuBar()->addMenu(tr("&File")); | ||||
r91 | this->SessionsMenu = this->FileMenu->addMenu(tr("&Sessions")); | |||
Jeandet Alexis
|
r94 | this->loadSessions(); | ||
Jeandet Alexis
|
r95 | this->FileMenu->addAction(this->sessionManagerAction); | ||
r91 | this->SettingsMenu = menuBar()->addMenu(tr("&Settings")); | |||
SocExplorerGUI::registerMenuBar(menuBar(),this->FileMenu,this->SettingsMenu); | ||||
Jeandet Alexis
|
r0 | this->PluginsMenu = menuBar()->addMenu(tr("&Plugins")); | ||
this->ToolsMenu = menuBar()->addMenu(tr("&Tools")); | ||||
this->ToolsMenu->addAction(this->exploreRegs); | ||||
this->FileMenu->addAction(this->Quit); | ||||
socexplorerproxy::self()->makeMenu(this->PluginsMenu); | ||||
this->PluginsMenu->addAction(this->ManagePlugins); | ||||
this->helpMenu = menuBar()->addMenu(tr("Help")); | ||||
this->helpMenu->addAction(this->help); | ||||
this->helpMenu->addAction(this->about); | ||||
} | ||||
r91 | void SocExplorerMainWindow::loadSessions() | |||
{ | ||||
Jeandet Alexis
|
r93 | p_Sessions=this->p_SessionManagerDialog->getSessionsList(); | ||
Jeandet Alexis
|
r95 | QAction* sact; | ||
Jeandet Alexis
|
r94 | QString stext; | ||
Jeandet Alexis
|
r95 | QList<QAction*> sessions=sessionsActions->actions(); | ||
foreach (sact, sessions) | ||||
Jeandet Alexis
|
r94 | { | ||
Jeandet Alexis
|
r95 | sessionsActions->removeAction(sact); | ||
Jeandet Alexis
|
r94 | SessionsMenu->removeAction(sact); | ||
delete sact; | ||||
} | ||||
foreach (stext, p_Sessions) | ||||
{ | ||||
r97 | addSession(stext); | |||
Jeandet Alexis
|
r94 | } | ||
} | ||||
void SocExplorerMainWindow::savePlugins() | ||||
{ | ||||
} | ||||
void SocExplorerMainWindow::saveCurrentSession() | ||||
{ | ||||
if(p_currentSession.isEmpty()) | ||||
{ | ||||
SocExplorerSettings::loadSession("default"); | ||||
} | ||||
SocExplorerSettings::setValue("GLOBAL","LastModified",QDate::currentDate().toString(),SocExplorerSettings::Session); | ||||
SocExplorerSettings::setValue(this,"DOCK_LOCATIONS",this->saveState(0),SocExplorerSettings::Session); | ||||
Jeandet Alexis
|
r95 | SocExplorerSettings::setValue(this,"PLUGINS_DOCK_LOCATIONS",this->pluginsDockContainer->saveState(0),SocExplorerSettings::Session); | ||
Jeandet Alexis
|
r94 | SocExplorerSettings::setValue(this,"MAIN_WINDOW_GEOMETRY",this->saveGeometry(),SocExplorerSettings::Session); | ||
QStringList plugins = socexplorerproxy::getPluginsList(); | ||||
SocExplorerSettings::setValue(this,"LOADED_PLUGINS",QVariant(plugins),SocExplorerSettings::Session); | ||||
SocExplorerSettings::sync(); | ||||
} | ||||
void SocExplorerMainWindow::loadCurrentSession() | ||||
{ | ||||
QStringList plugins = SocExplorerSettings::value(this,"LOADED_PLUGINS",QVariant(),SocExplorerSettings::Session).toStringList(); | ||||
socexplorerproxy::loadPluginsList(plugins); | ||||
this->restoreGeometry(SocExplorerSettings::value(this,"MAIN_WINDOW_GEOMETRY",QVariant(),SocExplorerSettings::Session).toByteArray()); | ||||
this->restoreState(SocExplorerSettings::value(this,"DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray()); | ||||
Jeandet Alexis
|
r95 | this->pluginsDockContainer->restoreState(SocExplorerSettings::value(this,"PLUGINS_DOCK_LOCATIONS",QVariant(),SocExplorerSettings::Session).toByteArray()); | ||
r91 | } | |||
Jeandet Alexis
|
r0 | |||
Jeandet Alexis
|
r13 | SocExplorerMainWindow::~SocExplorerMainWindow() | ||
Jeandet Alexis
|
r0 | { | ||
Jeandet Alexis
|
r94 | |||
Jeandet Alexis
|
r0 | } | ||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::setLangage(QAction *action) | ||
Jeandet Alexis
|
r0 | { | ||
QString local = action->data().toString(); | ||||
QString qmPath = QDir(QString("translations")).absolutePath(); | ||||
appTranslator->load(qmPath+"/socexplorer_"+local+".qm"); | ||||
qApp->installTranslator(appTranslator); | ||||
emit this->translateSig(); | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::createLangMenu() | ||
Jeandet Alexis
|
r0 | { | ||
this->langMenu = menuBar()->addMenu(tr("&Langue")); | ||||
this->langActionGrp = new QActionGroup(this); | ||||
connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*))); | ||||
QDir* qmDir = new QDir(QString("translations")); | ||||
QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm")); | ||||
for(int i=0;i<LangFiles.size();++i) | ||||
{ | ||||
QString Local = LangFiles[i]; | ||||
Local.remove(0,Local.indexOf('_')+1); | ||||
Local.chop(3); | ||||
QTranslator translator; | ||||
translator.load(LangFiles[i],qmDir->absolutePath()); | ||||
QString langage = translator.translate("MainWindow","English"); | ||||
QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this); | ||||
action->setCheckable(true); | ||||
action->setData(Local); | ||||
langMenu->addAction(action); | ||||
langActionGrp->addAction(action); | ||||
if(langage==tr("English")) | ||||
action->setChecked(true); | ||||
} | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::updateText() | ||
Jeandet Alexis
|
r0 | { | ||
emit this->translateSig(); | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::showAboutBox() | ||
Jeandet Alexis
|
r0 | { | ||
p_about->show(); | ||||
} | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::pluginselected(const QString &instanceName) | ||
r10 | { | |||
socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName); | ||||
Jeandet Alexis
|
r11 | if(drv) | ||
drv->raise(); | ||||
r10 | } | |||
Jeandet Alexis
|
r94 | void SocExplorerMainWindow::setActiveSession(const QString &session) | ||
{ | ||||
if(!(p_currentSession.isNull() && session=="default")) | ||||
saveCurrentSession(); | ||||
socexplorerproxy::self()->close(); | ||||
this->p_currentSession = session; | ||||
SocExplorerSettings::loadSession(session); | ||||
loadCurrentSession(); | ||||
Jeandet Alexis
|
r95 | |||
} | ||||
void SocExplorerMainWindow::setActiveSession(QAction *session) | ||||
{ | ||||
this->setActiveSession(session->text()); | ||||
Jeandet Alexis
|
r94 | } | ||
void SocExplorerMainWindow::showSessionManager(bool) | ||||
{ | ||||
this->p_SessionManagerDialog->show(); | ||||
} | ||||
r97 | void SocExplorerMainWindow::renameSession(const QString &oldName, const QString &newName) | |||
{ | ||||
for(int i=0;i<sessionsActions->actions().count();i++) | ||||
{ | ||||
if(Q_UNLIKELY(sessionsActions->actions().at(i)->text()==oldName)) | ||||
{ | ||||
sessionsActions->actions().at(i)->setText(newName); | ||||
} | ||||
} | ||||
} | ||||
void SocExplorerMainWindow::addSession(const QString &newSession) | ||||
Jeandet Alexis
|
r95 | { | ||
r97 | QAction* sact = new QAction(newSession,this); | |||
sact->setCheckable(true); | ||||
sact->setData(newSession); | ||||
if(Q_UNLIKELY(p_currentSession==newSession)) | ||||
sact->setChecked(true); | ||||
sessionsActions->addAction(sact); | ||||
SessionsMenu->addAction(sact); | ||||
} | ||||
Jeandet Alexis
|
r95 | |||
r97 | void SocExplorerMainWindow::removeSession(const QString &session) | |||
{ | ||||
QAction* sact; | ||||
foreach (sact, sessionsActions->actions()) | ||||
{ | ||||
if(Q_UNLIKELY(sact->text()==session)) | ||||
{ | ||||
sessionsActions->removeAction(sact); | ||||
SessionsMenu->removeAction(sact); | ||||
delete sact; | ||||
} | ||||
} | ||||
Jeandet Alexis
|
r95 | } | ||
Jeandet Alexis
|
r0 | |||
r97 | ||||
Jeandet Alexis
|
r13 | void SocExplorerMainWindow::closeEvent(QCloseEvent *event) | ||
Jeandet Alexis
|
r0 | { | ||
Jeandet Alexis
|
r94 | saveCurrentSession(); | ||
Jeandet Alexis
|
r0 | socexplorerproxy::self()->close(); | ||
qApp->closeAllWindows(); | ||||
event->accept(); | ||||
} | ||||