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