29 #include "maineditor.h"
30 #include "applicationview.h"
33 #include <QApplication>
34 #include <QPushButton>
38 #include <QFileDialog>
39 #include "arcs/arcsxmlhandler.h"
41 #include "arcs/arcslog.h"
43 MainEditor::MainEditor(QWidget *parent) :
47 defaultApplication = 0;
48 recentMenu =
new QMenu(
"Recent");
51 recentList = settings.value(
"recent files").toStringList();
53 connect(recentMenu,SIGNAL(triggered(QAction*)),
this,SLOT(handleRecentAction(QAction*)));
56 QMenu* fileMenu =
new QMenu(
"File",menuBar());
57 fileMenu->addAction(
"New...",
this,SLOT(newApplication()),QKeySequence(Qt::CTRL + Qt::Key_N));
58 fileMenu->addAction(
"Open",
this,SLOT(openApplication()),QKeySequence(Qt::CTRL + Qt::Key_O));
59 saveFileAction=fileMenu->addAction(
"Save",
this, SLOT(saveApplication()),QKeySequence(Qt::CTRL + Qt::Key_S));
60 saveFileAction->setEnabled(
false);
61 fileMenu->addAction(
"Save as...",
this,SLOT(saveAsApplication()));
62 fileMenu->addMenu(recentMenu);
63 fileMenu->addSeparator();
64 fileMenu->addAction(
"Exit",QApplication::instance(),SLOT(quit()),QKeySequence(Qt::CTRL + Qt::Key_Q));
67 editMenu =
new QMenu(
"Edition",menuBar());
70 menuBar()->addMenu(fileMenu);
71 menuBar()->addMenu(editMenu);
73 tbElements =
new QTabWidget(
this);
75 setCentralWidget(tbElements);
77 welcomeWidget =
new QTextEdit(
this);
79 welcomeWidget->setHtml(
"<img src=\":arcs_logo.png\"/><h1>Welcome to the ARCS Editor !</h1><p>You can start a new project by clicking <tt>File -> New...</tt>");
80 welcomeWidget->setReadOnly(
true);
83 tbElements->addTab(welcomeWidget,
"Welcome");
84 tbElements->setTabsClosable(
true);
85 connect(tbElements,SIGNAL(tabCloseRequested(
int)),
this,SLOT(removeTab(
int)));
86 connect(tbElements,SIGNAL(currentChanged(
int)),
this,SLOT(actualizeFromTab(
int)));
87 setWindowIcon(QIcon(
":arcs_logo.png"));
90 addDockWidget(Qt::BottomDockWidgetArea,logView);
94 MainEditor::~MainEditor()
97 settings.setValue(
"recent files",QStringList(recentList.mid(0,5)));
102 void MainEditor::newApplication()
105 applications.append(app);
106 addDockWidget(Qt::LeftDockWidgetArea,app);
108 connect(app,SIGNAL(requestAppIdDestroy(QVariant)),
this,SLOT(destroyAppId(QVariant)));
109 connect(app,SIGNAL(requestWidgetDestroy(QVariant,QString)),
this,SLOT(destroyWidget(QVariant,QString)));
110 setDefaultApplication(app);
114 void MainEditor::saveApplication()
116 if (!defaultApplication)
123 void MainEditor::saveAsApplication()
125 QString fileName = QFileDialog::getSaveFileName(
this,
"Save your ARCS application");
127 if (fileName.isEmpty())
130 if (recentList.contains(fileName))
131 recentList.swap(0,recentList.indexOf(fileName));
133 recentList.push_front(fileName);
138 if (defaultApplication)
146 handler.storeApplication(aac);
153 void MainEditor::openApplication(QString s)
158 fileName = QFileDialog::getOpenFileName(
this,
"Please select your ARCS application");
159 if (fileName.isEmpty())
162 if (recentList.contains(fileName))
163 recentList.swap(0,recentList.indexOf(fileName));
165 recentList.push_front(fileName);
179 app->setAssociatedFile(fileName);
180 applications.append(app);
181 app->setWindowTitle(
"Application: " + QFileInfo(fileName).fileName());
182 addDockWidget(Qt::LeftDockWidgetArea,app);
184 connect(app,SIGNAL(requestWidgetDestroy(QVariant,QString)),
this,SLOT(destroyWidget(QVariant,QString)));
185 connect(app,SIGNAL(requestAppIdDestroy(QVariant)),
this,SLOT(destroyAppId(QVariant)));
186 setDefaultApplication(app);
197 for (
int i=0; i < tbElements->count(); i++)
199 if (tbElements->tabText(i) == wdg->windowTitle() && wdg->property(
"appId") == tbElements->widget(i)->property(
"appId"))
201 tbElements->setCurrentIndex(i);
207 tbElements->addTab(wdg,wdg->windowTitle());
208 tbElements->setCurrentIndex(tbElements->count()-1);
209 connect(wdg,SIGNAL(sendLog(QString)),logView,SLOT(addLog(QString)));
210 connect(wdg,SIGNAL(addWidget(QWidget*)),
this,SLOT(
addNewTabWidget(QWidget*)));
214 void MainEditor::actualizeFromTab(
int cur)
220 editMenu->addActions(tbElements->currentWidget()->actions());
223 void MainEditor::handleRecentAction(QAction * act)
225 openApplication(act->text());
228 void MainEditor::buildRecentMenu()
230 for (
int i=0; i < recentList.count(); i++)
231 recentMenu->addAction(recentList[i]);
236 if (defaultApplication)
237 defaultApplication->setStyleSheet(
"QDockWidget { font-weight: normal; }");
238 defaultApplication = app;
239 saveFileAction->setEnabled(!app->getAssociatedFile().isEmpty());
240 app->setStyleSheet(
"QDockWidget { font-weight: bold; } ");
243 void MainEditor::destroyAppId(QVariant appId)
246 for (
int i = 0; i < applications.count(); i++)
248 if (applications[i]->property(
"appId") != appId)
249 setDefaultApplication(applications[i]);
254 applications.removeAt(
id);
255 if (applications.count() == 0)
257 saveFileAction->setEnabled(
false);
258 defaultApplication = 0;
261 for (
int i=0; i < tbElements->count(); i++)
263 if( tbElements->widget(i)->property(
"appId") == appId)
264 tbElements->removeTab(i);
268 void MainEditor::destroyWidget(QVariant appId, QString name)
270 for (
int i=0; i < tbElements->count(); i++)
272 if( tbElements->widget(i)->property(
"appId") == appId && tbElements->widget(i)->windowTitle() == name)
273 tbElements->removeTab(i);
This class represents an application.
void addNewTabWidget(QWidget *wdg)
static ARCSLog * getInstance()
returns the only instance of the logging system that is available
bool saveFile(QString s)
Saves a file given its path. The file will describe either an application or a composite component...
virtual bool loadFile(QString fn)
Defines a way to load a component description from a file.
This is an XML Handler for all ARCS native XML formats.