##// END OF EJS Templates
Added widget focus on selection in the tree list.
Jeandet Alexis -
r11:1576f6bb2776 default
parent child
Show More
@@ -1,234 +1,234
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
3 -- Copyright (C) 2011, Laboratory of Plasmas Physic - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "mainwindow.h"
22 #include "mainwindow.h"
23 #include <QDockWidget>
23 #include <QDockWidget>
24
24
25 LPMONMainWindow::LPMONMainWindow(QString ScriptToEval, QWidget *parent)
25 LPMONMainWindow::LPMONMainWindow(QString ScriptToEval, QWidget *parent)
26 : QMainWindow(parent)
26 : QMainWindow(parent)
27 {
27 {
28 QCoreApplication::setApplicationName("SocExplorer");
28 QCoreApplication::setApplicationName("SocExplorer");
29 QCoreApplication::setOrganizationName("LPP");
29 QCoreApplication::setOrganizationName("LPP");
30 QCoreApplication::setOrganizationDomain("lpp.fr");
30 QCoreApplication::setOrganizationDomain("lpp.fr");
31 this->makeObjects(ScriptToEval);
31 this->makeObjects(ScriptToEval);
32 this->makeLayout();
32 this->makeLayout();
33 this->makeMenu();
33 this->makeMenu();
34 this->makeConnections();
34 this->makeConnections();
35 this->setWindowIcon(QIcon(tr(":/images/logolppcutted.png")));
35 this->setWindowIcon(QIcon(tr(":/images/logolppcutted.png")));
36 this->setAcceptDrops(true);
36 this->setAcceptDrops(true);
37 this->pluginManager->setRootLoadable(true);
37 this->pluginManager->setRootLoadable(true);
38 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
38 this->PythonConsoleInst->pyConsoleRunFile(ScriptToEval);
39 // QProgressBar* test = SocExplorerEngine::getProgressBar("test",10);
39 // QProgressBar* test = SocExplorerEngine::getProgressBar("test",10);
40 // statusBar()->setFixedHeight(statusBar()->height());
40 // statusBar()->setFixedHeight(statusBar()->height());
41 // SocExplorerEngine::deleteProgressBar(test);
41 // SocExplorerEngine::deleteProgressBar(test);
42 }
42 }
43
43
44
44
45 void LPMONMainWindow::makeObjects(QString ScriptToEval)
45 void LPMONMainWindow::makeObjects(QString ScriptToEval)
46 {
46 {
47 Q_UNUSED(ScriptToEval)
47 Q_UNUSED(ScriptToEval)
48 pluginsDockContainer = new QMainWindow;
48 pluginsDockContainer = new QMainWindow;
49 pluginsDockContainer->setWindowFlags(Qt::Widget);
49 pluginsDockContainer->setWindowFlags(Qt::Widget);
50 pluginsDockContainer->setDockNestingEnabled(true);
50 pluginsDockContainer->setDockNestingEnabled(true);
51 this->mainWidget = new QSplitter(Qt::Vertical);
51 this->mainWidget = new QSplitter(Qt::Vertical);
52 this->appTranslator = new QTranslator;
52 this->appTranslator = new QTranslator;
53 this->Quit = new QAction(tr("&Quit"),this);
53 this->Quit = new QAction(tr("&Quit"),this);
54 this->Quit->setShortcut(tr("CTRL+Q"));
54 this->Quit->setShortcut(tr("CTRL+Q"));
55 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
55 this->ManagePlugins = new QAction(tr("&Manage Plugins"),this);
56 this->ManagePlugins->setShortcut(tr("CTRL+P"));
56 this->ManagePlugins->setShortcut(tr("CTRL+P"));
57 this->regsManager = new QAction(tr("&Manage registers"),this);
57 this->regsManager = new QAction(tr("&Manage registers"),this);
58 this->exploreRegs = new QAction(tr("&Explore registers"),this);
58 this->exploreRegs = new QAction(tr("&Explore registers"),this);
59 this->help = new QAction(tr("&Help"),this);
59 this->help = new QAction(tr("&Help"),this);
60 this->help->setShortcut(tr("CTRL+H"));
60 this->help->setShortcut(tr("CTRL+H"));
61 this->about = new QAction(tr("&About"),this);
61 this->about = new QAction(tr("&About"),this);
62 socexplorerproxy::setMainWindow(this);
62 socexplorerproxy::setMainWindow(this);
63 SocExplorerEngine::setMainWindow(this);
63 SocExplorerEngine::setMainWindow(this);
64 SocExplorerEngine::xmlModel()->scanXmlFiles();
64 SocExplorerEngine::xmlModel()->scanXmlFiles();
65 this->regExplorer = new regsExplorer();
65 this->regExplorer = new regsExplorer();
66 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
66 this->regExplorer->setAllowedAreas(Qt::AllDockWidgetAreas);
67 // this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,this->regExplorer);
67 // this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,this->regExplorer);
68 this->addPluginInterface(this->regExplorer);
68 this->addPluginInterface(this->regExplorer);
69 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
69 this->PythonConsoleInst = new PythonConsole(socexplorerproxy::self());
70 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
70 this->PythonConsoleInst->addObject("SocExplorerEngine",SocExplorerEngine::self());
71 this->pluginManager = new dockablePluginManager();
71 this->pluginManager = new dockablePluginManager();
72 this->toolpane = new toolBar;
72 this->toolpane = new toolBar;
73 this->p_about = new aboutsocexplorer();
73 this->p_about = new aboutsocexplorer();
74 }
74 }
75
75
76 void LPMONMainWindow::makeLayout()
76 void LPMONMainWindow::makeLayout()
77 {
77 {
78 this->mainWidget->addWidget(pluginsDockContainer);
78 this->mainWidget->addWidget(pluginsDockContainer);
79 this->mainWidget->addWidget(this->PythonConsoleInst);
79 this->mainWidget->addWidget(this->PythonConsoleInst);
80 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
80 this->toolpane->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
81 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
81 this->addDockWidget(Qt::LeftDockWidgetArea,this->toolpane);
82 this->toolpane->addTool(this->pluginManager);
82 this->toolpane->addTool(this->pluginManager);
83 this->setCentralWidget(this->mainWidget);
83 this->setCentralWidget(this->mainWidget);
84 }
84 }
85
85
86
86
87 void LPMONMainWindow::makeConnections()
87 void LPMONMainWindow::makeConnections()
88 {
88 {
89 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
89 connect(socexplorerproxy::self(),SIGNAL(clearMenu()),this,SLOT(clearMenu()));
90 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
90 connect(this,SIGNAL(translateSig()),socexplorerproxy::self(),SLOT(updateText()));
91 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
91 connect(socexplorerproxy::self(),SIGNAL(addPluginGUI(QDockWidget*)),this,SLOT(addPluginInterface(QDockWidget*)));
92 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
92 connect(this->ManagePlugins,SIGNAL(triggered()),this,SLOT(launchPluginManager()));
93 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
93 connect(this->Quit,SIGNAL(triggered()),qApp,SLOT(quit()));
94 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
94 connect(this,SIGNAL(registerObject(QObject*,QString)),this->PythonConsoleInst,SLOT(registerObject(QObject*,QString)));
95 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
95 connect(socexplorerproxy::self(),SIGNAL(registerObject(QObject*,QString)),this,SIGNAL(registerObject(QObject*,QString)));
96 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
96 connect(this->pluginManager,SIGNAL(geteplugintree()),socexplorerproxy::self(),SLOT(geteplugintree()));
97 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
97 connect(socexplorerproxy::self(),SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->pluginManager,SIGNAL(treeChanged(QList<socexplorerplugin*>)));
98 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
98 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),socexplorerproxy::self(),SLOT(changeSysDriverInstName(QString,QString)));
99 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
99 connect(this->pluginManager,SIGNAL(changeSysDriverInstName(QString,QString)),this->PythonConsoleInst,SLOT(changeSysDriverInstName(QString,QString)));
100 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
100 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),socexplorerproxy::self(),SLOT(closeSysDriver(QString)));
101 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
101 connect(this->pluginManager,SIGNAL(closeSysDriver(QString)),this->PythonConsoleInst,SLOT(removeDriver(QString)));
102 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
102 connect(this->pluginManager,SIGNAL(pluginselected(QString)),this,SLOT(pluginselected(QString)));
103 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
103 connect(this->about,SIGNAL(triggered()),this,SLOT(showAboutBox()));
104 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
104 connect(this->exploreRegs,SIGNAL(triggered()),this->regExplorer,SLOT(show()));
105
105
106 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
106 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDrviver(QString)),socexplorerproxy::self(),SLOT(loadSysDriver(QString)));
107 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
107 this->pluginManager->connect(this->pluginManager,SIGNAL(loadSysDriverToParent(QString,QString)),socexplorerproxy::self(),SLOT(loadSysDriverToParent(QString,QString)));
108
108
109 }
109 }
110
110
111
111
112 void LPMONMainWindow::launchPluginManager()
112 void LPMONMainWindow::launchPluginManager()
113 {
113 {
114
114
115 if(this->pluginManager->isHidden())
115 if(this->pluginManager->isHidden())
116 {
116 {
117 this->pluginManager->setHidden(false);
117 this->pluginManager->setHidden(false);
118 }
118 }
119
119
120 }
120 }
121
121
122
122
123 void LPMONMainWindow::addPluginInterface(QDockWidget *plugin)
123 void LPMONMainWindow::addPluginInterface(QDockWidget *plugin)
124 {
124 {
125 static QDockWidget* last=NULL;
125 static QDockWidget* last=NULL;
126 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
126 plugin->setAllowedAreas(Qt::AllDockWidgetAreas);
127 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
127 this->pluginsDockContainer->addDockWidget(Qt::TopDockWidgetArea,plugin);
128 if(last!=NULL)
128 if(last!=NULL)
129 this->pluginsDockContainer->tabifyDockWidget(last,plugin);
129 this->pluginsDockContainer->tabifyDockWidget(last,plugin);
130 last = plugin;
130 last = plugin;
131
131
132 }
132 }
133
133
134
134
135 void LPMONMainWindow::clearMenu()
135 void LPMONMainWindow::clearMenu()
136 {
136 {
137 this->menuBar()->clear();
137 this->menuBar()->clear();
138 this->makeMenu();
138 this->makeMenu();
139 }
139 }
140
140
141
141
142 void LPMONMainWindow::makeMenu()
142 void LPMONMainWindow::makeMenu()
143 {
143 {
144 this->FileMenu = menuBar()->addMenu(tr("&File"));
144 this->FileMenu = menuBar()->addMenu(tr("&File"));
145 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
145 this->PluginsMenu = menuBar()->addMenu(tr("&Plugins"));
146 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
146 this->ToolsMenu = menuBar()->addMenu(tr("&Tools"));
147 this->ToolsMenu->addAction(this->exploreRegs);
147 this->ToolsMenu->addAction(this->exploreRegs);
148 this->FileMenu->addAction(this->Quit);
148 this->FileMenu->addAction(this->Quit);
149 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
149 socexplorerproxy::self()->makeMenu(this->PluginsMenu);
150 this->PluginsMenu->addAction(this->ManagePlugins);
150 this->PluginsMenu->addAction(this->ManagePlugins);
151
151
152 this->helpMenu = menuBar()->addMenu(tr("Help"));
152 this->helpMenu = menuBar()->addMenu(tr("Help"));
153 this->helpMenu->addAction(this->help);
153 this->helpMenu->addAction(this->help);
154 this->helpMenu->addAction(this->about);
154 this->helpMenu->addAction(this->about);
155
155
156 }
156 }
157
157
158
158
159 LPMONMainWindow::~LPMONMainWindow()
159 LPMONMainWindow::~LPMONMainWindow()
160 {
160 {
161 delete this->p_about;
161 delete this->p_about;
162 }
162 }
163
163
164
164
165 void LPMONMainWindow::setLangage(QAction *action)
165 void LPMONMainWindow::setLangage(QAction *action)
166 {
166 {
167 QString local = action->data().toString();
167 QString local = action->data().toString();
168 QString qmPath = QDir(QString("translations")).absolutePath();
168 QString qmPath = QDir(QString("translations")).absolutePath();
169 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
169 appTranslator->load(qmPath+"/socexplorer_"+local+".qm");
170 qApp->installTranslator(appTranslator);
170 qApp->installTranslator(appTranslator);
171 emit this->translateSig();
171 emit this->translateSig();
172 }
172 }
173
173
174
174
175 void LPMONMainWindow::createLangMenu()
175 void LPMONMainWindow::createLangMenu()
176 {
176 {
177 this->langMenu = menuBar()->addMenu(tr("&Langue"));
177 this->langMenu = menuBar()->addMenu(tr("&Langue"));
178 this->langActionGrp = new QActionGroup(this);
178 this->langActionGrp = new QActionGroup(this);
179 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
179 connect(this->langActionGrp,SIGNAL(triggered(QAction*)),this,SLOT(setLangage(QAction*)));
180 QDir* qmDir = new QDir(QString("translations"));
180 QDir* qmDir = new QDir(QString("translations"));
181 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
181 QStringList LangFiles = qmDir->entryList(QStringList("socexplorer_*.qm"));
182 for(int i=0;i<LangFiles.size();++i)
182 for(int i=0;i<LangFiles.size();++i)
183 {
183 {
184 QString Local = LangFiles[i];
184 QString Local = LangFiles[i];
185 Local.remove(0,Local.indexOf('_')+1);
185 Local.remove(0,Local.indexOf('_')+1);
186 Local.chop(3);
186 Local.chop(3);
187 QTranslator translator;
187 QTranslator translator;
188 translator.load(LangFiles[i],qmDir->absolutePath());
188 translator.load(LangFiles[i],qmDir->absolutePath());
189 QString langage = translator.translate("MainWindow","English");
189 QString langage = translator.translate("MainWindow","English");
190 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
190 QAction *action = new QAction(tr("&%1 %2").arg(i+1).arg(langage),this);
191 action->setCheckable(true);
191 action->setCheckable(true);
192 action->setData(Local);
192 action->setData(Local);
193 langMenu->addAction(action);
193 langMenu->addAction(action);
194 langActionGrp->addAction(action);
194 langActionGrp->addAction(action);
195 if(langage==tr("English"))
195 if(langage==tr("English"))
196 action->setChecked(true);
196 action->setChecked(true);
197 }
197 }
198 }
198 }
199
199
200
200
201 void LPMONMainWindow::updateText()
201 void LPMONMainWindow::updateText()
202 {
202 {
203 emit this->translateSig();
203 emit this->translateSig();
204 }
204 }
205
205
206
206
207
207
208 void LPMONMainWindow::showAboutBox()
208 void LPMONMainWindow::showAboutBox()
209 {
209 {
210 p_about->show();
210 p_about->show();
211 }
211 }
212
212
213 void LPMONMainWindow::pluginselected(const QString &instanceName)
213 void LPMONMainWindow::pluginselected(const QString &instanceName)
214 {
214 {
215 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
215 socexplorerplugin* drv=socexplorerproxy::self()->getSysDriver(instanceName);
216 // if(drv)
216 if(drv)
217 // drv->activate(true);
217 drv->raise();
218 // TODO add plugin widget auto focus
218 // TODO add plugin widget auto focus
219 }
219 }
220
220
221
221
222
222
223 void LPMONMainWindow::closeEvent(QCloseEvent *event)
223 void LPMONMainWindow::closeEvent(QCloseEvent *event)
224 {
224 {
225 socexplorerproxy::self()->close();
225 socexplorerproxy::self()->close();
226 qApp->closeAllWindows();
226 qApp->closeAllWindows();
227 event->accept();
227 event->accept();
228 }
228 }
229
229
230
230
231
231
232
232
233
233
234
234
General Comments 0
You need to be logged in to leave comments. Login now