10 #include "ComposerMainWindow.h"
11 #include "ui_ComposerMainWindow.h"
14 #include <QCloseEvent>
15 #include <QDialogButtonBox>
17 #include <QToolButton>
18 #include <QApplication>
22 #include <QDesktopServices>
24 #include "GeneralPreferences.h"
26 #include "NewProjectWizard.h"
36 const int autoSaveInterval = 1 * 60 * 1000;
39 : QMainWindow(parent),
41 allDocksMutex(QMutex::Recursive),
42 localGingaProcess(this)
47 connect(&localGingaProcess, SIGNAL(finished(
int)),
48 this, SLOT(runHasFinished()));
52 runRemoteGingaVMAction.moveToThread(&runRemoteGingaVMThread);
54 connect(&runRemoteGingaVMThread, SIGNAL(started()),
55 &runRemoteGingaVMAction, SLOT(runCurrentProject()));
57 connect(&runRemoteGingaVMAction, SIGNAL(finished()),
58 &runRemoteGingaVMThread, SLOT(quit()));
60 connect(&runRemoteGingaVMThread, SIGNAL(finished()),
61 this, SLOT(runHasFinished()));
63 connect(&runRemoteGingaVMThread, SIGNAL(terminated()),
64 this, SLOT(runHasFinished()));
72 QPixmap mPix(
":/mainwindow/nclcomposer-splash");
73 QSplashScreen splash(mPix);
74 splash.setMask(mPix.mask());
75 splash.showMessage(tr(
"Loading NCL Composer..."), Qt::AlignRight, Qt::gray);
81 splash.showMessage(tr(
"Starting GUI..."), Qt::AlignRight, Qt::gray);
86 splash.showMessage(tr(
"Starting Modules and Plugins..."), Qt::AlignRight,
95 autoSaveTimer =
new QTimer(
this);
96 connect(autoSaveTimer, SIGNAL(timeout()),
97 this, SLOT(autoSaveCurrentProjects()));
99 autoSaveTimer->start(autoSaveInterval);
101 splash.showMessage(tr(
"Reloading last session..."), Qt::AlignRight,
107 connect(&app, SIGNAL(focusChanged(QWidget *, QWidget *)),
108 this, SLOT(focusChanged(QWidget *, QWidget *)),
109 Qt::DirectConnection);
114 ComposerMainWindow::~ComposerMainWindow()
117 delete menu_Perspective;
123 void ComposerMainWindow::initModules()
129 connect(pgControl,SIGNAL(notifyError(QString)),
136 connect(lgControl,SIGNAL(notifyError(QString)),
139 connect(projectControl, SIGNAL(notifyError(QString)),
142 connect(projectControl,SIGNAL(projectAlreadyOpen(QString)),
145 connect(projectControl, SIGNAL(startOpenProject(QString)),
146 this, SLOT(startOpenProject(QString)));
148 connect(projectControl, SIGNAL(endOpenProject(QString)),
this,
149 SLOT(endOpenProject(QString)));
151 connect(projectControl,SIGNAL(endOpenProject(QString)),
152 SLOT(addToRecentProjects(QString)));
157 connect(welcomeWidget, SIGNAL(userPressedRecentProject(QString)),
158 this, SLOT(userPressedRecentProject(QString)));
160 connect(projectControl,SIGNAL(projectAlreadyOpen(QString)),
163 connect(projectControl, SIGNAL(dirtyProject(QString,
bool)),
164 this, SLOT(setProjectDirty(QString,
bool)));
169 void ComposerMainWindow::readExtensions()
173 settings.beginGroup(
"extensions");
174 extensions_paths.clear();
177 if (settings.contains(
"path"))
178 extensions_paths << settings.value(
"path").toStringList();
180 extensions_paths.removeDuplicates();
184 for(
int i = 0; i < extensions_paths.size(); i++)
186 qDebug() <<
"Adding library " << extensions_paths.at(i);
187 QApplication::addLibraryPath(extensions_paths.at(i) +
"/");
191 for(
int i = 0; i < extensions_paths.size(); i++)
193 LanguageControl::getInstance()->loadProfiles(extensions_paths.at(i));
197 for(
int i = 0; i < extensions_paths.size(); i++)
199 PluginControl::getInstance()->loadPlugins(extensions_paths.at(i));
211 QList<IPluginFactory*> list =
212 PluginControl::getInstance()->getLoadedPlugins();
215 foreach(currentFactory, list)
217 preferences->addPreferencePage(currentFactory);
221 QString ComposerMainWindow::promptChooseExtDirectory()
225 mBox.setText(tr(
"The Extension Directory is not set"));
226 mBox.setInformativeText(tr(
"Do you want to try the default"
227 "directory (%1)?").arg(QDir::homePath()));
228 mBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
229 mBox.setDefaultButton(QMessageBox::Yes);
230 mBox.setIcon(QMessageBox::Question);
231 if (mBox.exec() == QMessageBox::No)
233 QString dirName = QFileDialog::getExistingDirectory(
this,
234 tr(
"Select Directory"),
235 getLastFileDialogPath(),
236 QFileDialog::ShowDirsOnly);
243 void ComposerMainWindow::readSettings()
247 settings.beginGroup(
"mainwindow");
248 restoreGeometry(settings.value(
"geometry").toByteArray());
249 restoreState(settings.value(
"windowState").toByteArray());
252 QApplication::processEvents();
254 settings.beginGroup(
"openfiles");
255 QStringList openfiles = settings.value(
"openfiles").toStringList();
258 openProjects(openfiles);
261 void ComposerMainWindow::openProjects(
const QStringList &projects)
263 qDebug() <<
"Openning files:" << projects;
264 for(
int i = 0; i < projects.size(); i++)
266 QString src = projects.at(i);
268 src = src.replace(QDir::separator(),
"/");
272 bool openCurrentFile =
true;
277 QMessageBox::question(
this,
278 tr(
"File does not exists anymore."),
279 tr(
"The File %1 does not exists, but "
280 "the last time you have closed NCL"
281 " Composer this files was open. "
282 "Do you want to create this file "
284 QMessageBox::Yes | QMessageBox::No,
287 if(resp != QMessageBox::Yes) openCurrentFile =
false;
294 ProjectControl::getInstance()->launchProject(src);
300 QStringList recentProjects = settings.value(
"recentprojects").toStringList();
301 updateRecentProjectsMenu(recentProjects);
302 welcomeWidget->updateRecentProjects(recentProjects);
305 void ComposerMainWindow::initGUI()
308 setWindowIcon(QIcon(
":/mainwindow/icon"));
310 setWindowTitle(tr(
"NCL Composer"));
311 tabProjects =
new QTabWidget(0);
313 ui->frame->layout()->addWidget(tabProjects);
316 tabProjects->setTabsClosable(
true);
323 tbPerspectiveDropList =
new QToolButton(
this);
324 tbPerspectiveDropList->setIcon(QIcon(
":/mainwindow/perspective"));
325 tbPerspectiveDropList->setToolTip(tr(
"Change your current perspective"));
326 tbPerspectiveDropList->setPopupMode(QToolButton::InstantPopup);
328 connect( tabProjects, SIGNAL(tabCloseRequested(
int)),
329 this, SLOT(tabClosed(
int)), Qt::DirectConnection);
331 connect(tabProjects, SIGNAL(currentChanged(
int)),
332 this, SLOT(currentTabChanged(
int)));
338 createAboutPlugins();
344 connect(ui->action_RunNCL, SIGNAL(triggered()),
this, SLOT(runNCL()));
345 connect(ui->action_StopNCL, SIGNAL(triggered()),
this, SLOT(stopNCL()));
347 ui->action_RunNCL->setEnabled(
true);
354 tabProjects->addTab(welcomeWidget, tr(
"Welcome"));
355 tabProjects->setTabIcon(0, QIcon());
357 connect(welcomeWidget, SIGNAL(userPressedOpenProject()),
360 connect(welcomeWidget, SIGNAL(userPressedNewProject()),
361 this, SLOT(launchProjectWizard()));
363 connect(welcomeWidget, SIGNAL(userPressedSeeInstalledPlugins()),
364 this, SLOT(aboutPlugins()));
370 taskProgressBar =
new QProgressDialog(
this);
371 taskProgressBar->setWindowTitle(tr(
"Copy content to Ginga VM."));
372 taskProgressBar->setModal(
true);
375 connect(&runRemoteGingaVMAction, SIGNAL(startTask()),
376 taskProgressBar, SLOT(show()));
378 connect(&runRemoteGingaVMAction, SIGNAL(taskDescription(QString)),
379 taskProgressBar, SLOT(setLabelText(QString)));
381 connect(&runRemoteGingaVMAction, SIGNAL(taskMaximumValue(
int)),
382 taskProgressBar, SLOT(setMaximum(
int)));
384 connect(&runRemoteGingaVMAction, SIGNAL(taskValue(
int)),
385 taskProgressBar, SLOT(setValue(
int)));
387 connect(&runRemoteGingaVMAction, SIGNAL(copyFinished()),
388 taskProgressBar, SLOT(hide()));
390 connect(&runRemoteGingaVMAction, SIGNAL(finished()),
391 taskProgressBar, SLOT(hide()));
393 connect(taskProgressBar, SIGNAL(canceled()),
394 &runRemoteGingaVMAction, SLOT(stopExecution()),
395 Qt::DirectConnection);
397 disconnect(taskProgressBar, SIGNAL(canceled()),
398 taskProgressBar, SLOT(cancel()));
400 connect(&runRemoteGingaVMAction, SIGNAL(finished()),
401 taskProgressBar, SLOT(hide()));
411 void ComposerMainWindow::keyPressEvent(QKeyEvent *event)
413 if(event->modifiers() == Qt::ControlModifier &&
event->key() == Qt::Key_Z)
418 else if(event->modifiers() == Qt::ControlModifier &&
419 event->key() == Qt::Key_Y)
427 Project *project,
int n)
430 QString location = project->getLocation();
431 QString projectId = project->getAttribute(
"id");
436 if (projectsWidgets.contains(location))
438 w = projectsWidgets[location];
440 mdiArea = (QMdiArea *)w->centralWidget();
441 mdiArea->setBackground(QBrush(QColor(
"#FFFFFF")));
444 w =
new QMainWindow(tabProjects);
446 mdiArea =
new QMdiArea;
447 mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
448 mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
449 w->setCentralWidget(mdiArea);
451 w->setDockNestingEnabled(
true);
452 w->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::West);
454 int index = tabProjects->addTab(w, projectId);
455 updateTabWithProject(index, location);
456 projectsWidgets[location] = w;
461 mdiArea->addSubWindow(pW);
462 pW->setWindowModified(
true);
463 pW->setWindowTitle(projectId +
" - " + fac->name());
465 pW->setObjectName(fac->id());
468 dock->setProperty(
"project", location);
470 dock->setAllowedAreas(Qt::AllDockWidgetAreas);
471 dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
473 connect(dock, SIGNAL(clicked()), pW, SLOT(setFocus()));
474 pW->setFocusPolicy(Qt::StrongFocus);
476 QFrame *borderFrame =
new QFrame();
477 borderFrame->setFrameShape(QFrame::NoFrame);
478 borderFrame->setFrameShadow(QFrame::Plain);
480 QVBoxLayout *layoutBorderFrame =
new QVBoxLayout();
481 layoutBorderFrame->setMargin(0);
482 layoutBorderFrame->addWidget(pW);
483 borderFrame->setLayout(layoutBorderFrame);
485 dock->setWidget(borderFrame);
486 dock->setObjectName(fac->id());
488 dock->setMinimumSize(0, 0);
489 tabProjects->setCurrentWidget(w);
491 if(firstDock.contains(location)) {
492 w->tabifyDockWidget(firstDock[location], dock);
496 w->addDockWidget(Qt::LeftDockWidgetArea, dock);
497 firstDock[location] = dock;
500 QFrame *titleBar =
new QFrame();
501 titleBar->setContentsMargins(0,0,0,0);
503 QLabel *titleLabel =
new QLabel(fac->name());
504 titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
506 QHBoxLayout *layout =
new QHBoxLayout(titleBar);
507 layout->setMargin(0);
508 layout->setSpacing(0);
510 layout->addWidget(titleLabel);
512 titleBar->setStyleSheet(
" ");
514 dock->setTitleBarWidget(titleBar);
515 allDocksMutex.lock();
516 allDocks.insert(0, dock);
517 allDocksMutex.unlock();
519 QPushButton *refresh =
new QPushButton(titleBar);
520 refresh->setIcon(QIcon(
":/mainwindow/refreshplugin"));
521 refresh->setToolTip(tr(
"Reload View Model"));
522 addButtonToDockTitleBar(titleBar, refresh);
523 connect(refresh, SIGNAL(pressed()), plugin, SLOT(updateFromModel()));
525 QPushButton *hide =
new QPushButton(titleBar);
526 connect(hide, SIGNAL(pressed()), dock, SLOT(close()));
527 hide->setIcon(QIcon(
":/mainwindow/closeplugin"));
528 hide->setToolTip(tr(
"Hide View"));
530 addButtonToDockTitleBar(titleBar, hide);
533 updateDockStyle(dock,
false);
537 void ComposerMainWindow::updateDockStyle(QDockWidget *dock,
bool selected)
539 qWarning() <<
"ComposerMainWindows::updateDockStyle ( " << dock << selected <<
")";
541 QList <QTabBar*> tabBars = this->findChildren <QTabBar *>();
544 foreach (QTabBar *tabBar, tabBars)
546 for(
int index = 0; index < tabBar->count(); index++)
548 QVariant tmp = tabBar->tabData(index);
549 QDockWidget * dockWidget =
reinterpret_cast<QDockWidget *
>(tmp.toULongLong());
550 if(dockWidget == dock)
552 if(!tabBar->property(
"activePlugin").isValid())
554 tabBar->setProperty(
"activePlugin",
"false");
555 tabBar->setStyleSheet(styleSheet());
558 bool activePlugin = tabBar->property(
"activePlugin").toBool();
563 tabBar->setProperty(
"activePlugin",
"true");
564 tabBar->setStyleSheet(styleSheet());
571 tabBar->setProperty(
"activePlugin",
"false");
572 tabBar->setStyleSheet(styleSheet());
579 QFrame *titleBar = (QFrame*) dock->titleBarWidget();
580 if(!titleBar->property(
"activePluginTitleBar").isValid())
582 titleBar->setProperty(
"activePluginTitleBar",
"false");
583 dock->setProperty(
"activePluginBorder",
"false");
584 dock->setStyleSheet(styleSheet());
587 bool activePluginTitleBar = titleBar->property(
"activePluginTitleBar").toBool();
590 if(activePluginTitleBar)
592 titleBar->setProperty(
"activePluginTitleBar",
"false");
593 dock->setProperty(
"activePluginBorder",
"false");
594 dock->setStyleSheet(styleSheet());
599 if(!activePluginTitleBar)
601 titleBar->setProperty(
"activePluginTitleBar",
"true");
602 dock->setProperty(
"activePluginBorder",
"true");
603 dock->setStyleSheet(styleSheet());
608 void ComposerMainWindow::addButtonToDockTitleBar(QFrame *titleBar,
611 button->setIconSize(QSize(18, 18));
613 titleBar->layout()->addWidget(button);
616 void ComposerMainWindow::tabClosed(
int index)
621 QString location = tabProjects->tabToolTip(index);
622 Project *project = ProjectControl::getInstance()->getOpenProject(location);
623 qDebug() << location << project;
624 if(project != NULL && project->isDirty())
626 int ret = QMessageBox::warning(
this, project->getAttribute(
"id"),
627 tr(
"The project has been modified.\n"
628 "Do you want to save your changes?"),
629 QMessageBox::Yes | QMessageBox::Default,
631 QMessageBox::Cancel|QMessageBox::Escape);
632 if (ret == QMessageBox::Yes)
634 else if (ret == QMessageBox::Cancel)
638 ProjectControl::getInstance()->closeProject(location);
643 if(projectsWidgets.contains(location))
645 QMainWindow *w = projectsWidgets[location];
647 allDocksMutex.lock();
648 QList <QDockWidget*> newAllDocks;
650 for(
int i = 0; i < allDocks.size(); i++)
652 if(allDocks.at(i)->property(
"project") == location)
658 newAllDocks.push_back(allDocks.at(i));
660 allDocks = newAllDocks;
661 allDocksMutex.unlock();
663 projectsWidgets.remove(location);
664 firstDock.remove(location);
673 qWarning() <<
"ComposerMainWindow::tabClosed ends";
676 void ComposerMainWindow::closeCurrentTab()
678 if(tabProjects->currentIndex())
680 int currentIndex = tabProjects->currentIndex();
681 tabClosed(currentIndex);
684 void ComposerMainWindow::closeAllFiles()
686 while(tabProjects->count() > 1)
689 tabProjects->removeTab(1);
695 if (!projectsWidgets.contains(location))
return;
696 QMainWindow *w = projectsWidgets[location];
697 tabProjects->setCurrentWidget(w);
700 void ComposerMainWindow::createMenus()
703 ui->menubar->setNativeMenuBar(
true);
706 ui->menu_Edit->addAction(editPreferencesAct);
708 menuBar()->addSeparator();
710 connect( ui->menu_Window, SIGNAL(aboutToShow()),
711 this, SLOT(updateViewMenu()));
713 connect(ui->action_CloseProject, SIGNAL(triggered()),
714 this, SLOT(closeCurrentTab()));
716 connect(ui->action_CloseAll, SIGNAL(triggered()),
717 this, SLOT(closeAllFiles()));
719 connect( ui->action_Save, SIGNAL(triggered()),
722 connect( ui->action_SaveAs, SIGNAL(triggered()),
725 connect ( ui->action_NewProject, SIGNAL(triggered()),
726 this, SLOT(launchProjectWizard()));
732 menu_Perspective =
new QMenu(0);
734 tbPerspectiveDropList->setMenu(menu_Perspective);
735 ui->toolBar->addWidget(tbPerspectiveDropList);
738 tabProjects->setCornerWidget(ui->toolBar, Qt::TopRightCorner);
742 updateMenuPerspectives();
745 void ComposerMainWindow::createAboutPlugins()
747 aboutPluginsDialog =
new QDialog(
this);
748 aboutPluginsDialog->setWindowTitle(tr(
"Installed Plugins"));
751 profilesExt =
new QListWidget(aboutPluginsDialog);
752 profilesExt->setAlternatingRowColors(
true);
756 pluginsExt =
new QTreeWidget(aboutPluginsDialog);
757 pluginsExt->setAlternatingRowColors(
true);
759 connect(pluginsExt, SIGNAL(itemSelectionChanged()),
760 this, SLOT(selectedAboutCurrentPluginFactory()));
763 header << tr(
"Name") << tr(
"Load") << tr(
"Version") << tr(
"Vendor");
764 pluginsExt->setHeaderLabels(header);
766 QDialogButtonBox *bOk =
new QDialogButtonBox(QDialogButtonBox::Ok |
767 QDialogButtonBox::Close,
771 detailsButton = bOk->button(QDialogButtonBox::Ok);
772 detailsButton->setText(tr(
"Details"));
773 detailsButton->setIcon(QIcon());
774 detailsButton->setEnabled(
false);
776 connect(bOk, SIGNAL(rejected()), aboutPluginsDialog, SLOT(close()));
778 connect( detailsButton, SIGNAL(pressed()),
this, SLOT(showPluginDetails()) );
780 QGridLayout *gLayout =
new QGridLayout(aboutPluginsDialog);
781 gLayout->addWidget(
new QLabel(tr(
"The <b>Composer</b> is an IDE for"
782 " Declarative Multimedia languages."),
783 aboutPluginsDialog));
786 gLayout->addWidget(
new QLabel(tr(
"<b>Installed Language Profiles</b>"),
787 aboutPluginsDialog));
788 gLayout->addWidget(profilesExt);
790 gLayout->addWidget(
new QLabel(tr(
"<b>Installed Plug-ins</b>")));
791 gLayout->addWidget(pluginsExt);
792 gLayout->addWidget(bOk);
793 aboutPluginsDialog->setLayout(gLayout);
795 aboutPluginsDialog->setModal(
true);
797 connect(aboutPluginsDialog, SIGNAL(finished(
int)),
801 void ComposerMainWindow::about()
807 void ComposerMainWindow::aboutPlugins()
809 QList<IPluginFactory*>::iterator it;
810 QList<IPluginFactory*> pList = PluginControl::getInstance()->
815 QTreeWidgetItem *treeWidgetItem;
816 QMap <QString, QTreeWidgetItem*> categories;
817 for (it = pList.begin(); it != pList.end(); it++) {
819 QString category = pF->category();
820 if(!categories.contains(category)){
821 treeWidgetItem =
new QTreeWidgetItem(pluginsExt);
822 categories.insert(category, treeWidgetItem);
823 treeWidgetItem->setText(0, category);
824 treeWidgetItem->setTextColor(0, QColor(
"#0000FF"));
828 treeWidgetItem2plFactory.clear();
829 for (it = pList.begin(); it != pList.end(); it++) {
831 treeWidgetItem =
new QTreeWidgetItem(categories.value(pF->category()));
832 treeWidgetItem2plFactory.insert(treeWidgetItem, pF);
834 treeWidgetItem->setText(0, pF->name());
838 settings.beginGroup(
"loadPlugins");
839 if(!settings.contains(pF->id()) || settings.value(pF->id()).toBool())
840 treeWidgetItem->setCheckState(1, Qt::Checked);
842 treeWidgetItem->setCheckState(1, Qt::Unchecked);
845 treeWidgetItem->setText(2, pF->version());
846 treeWidgetItem->setText(3, pF->vendor());
849 pluginsExt->expandAll();
851 pluginsExt->setColumnWidth(0, 150);
852 pluginsExt->resizeColumnToContents(1);
853 pluginsExt->resizeColumnToContents(2);
854 pluginsExt->resizeColumnToContents(3);
858 QList<ILanguageProfile*>::iterator itL;
859 QList<ILanguageProfile*> lList = LanguageControl::getInstance()->
861 profilesExt->clear();
863 for(itL = lList.begin(); itL != lList.end(); itL++)
866 profilesExt->addItem(
new QListWidgetItem(lg->getProfileName()));
870 detailsButton->setEnabled(
false);
871 aboutPluginsDialog->show();
877 qWarning() << message;
880 void ComposerMainWindow::createActions() {
882 connect(ui->action_About, SIGNAL(triggered()),
this, SLOT(about()));
884 connect( ui->action_AboutPlugins, SIGNAL(triggered()),
885 this, SLOT(aboutPlugins()));
887 fullScreenViewAct =
new QAction(tr(
"&FullScreen"),
this);
888 fullScreenViewAct->setShortcut(tr(
"F11"));
890 connect(fullScreenViewAct,SIGNAL(triggered()),
this,
891 SLOT(showCurrentWidgetFullScreen()));
893 editPreferencesAct =
new QAction(tr(
"&Preferences"),
this);
894 editPreferencesAct->setStatusTip(tr(
"Edit preferences"));
895 connect (editPreferencesAct, SIGNAL(triggered()),
this,
896 SLOT(showEditPreferencesDialog()));
898 connect(ui->action_Preferences, SIGNAL(triggered()),
899 this, SLOT(showEditPreferencesDialog()));
901 connect(ui->action_Exit, SIGNAL(triggered()),
this, SLOT(close()));
902 saveCurrentPluginsLayoutAct =
new QAction(tr(
"Save current perspective..."),
905 connect( saveCurrentPluginsLayoutAct, SIGNAL(triggered()),
906 this, SLOT(saveCurrentGeometryAsPerspective()));
908 restorePluginsLayoutAct =
new QAction(tr(
"Restore a perspective"),
this);
909 connect(restorePluginsLayoutAct, SIGNAL(triggered()),
910 this, SLOT(restorePerspective()));
912 QWidget* spacer =
new QWidget();
913 spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
917 ui->toolBar->insertWidget(ui->action_Preferences, spacer);
919 connect (ui->action_OpenProject, SIGNAL(triggered()),
922 connect (ui->action_ImportFromExistingNCL, SIGNAL(triggered()),
923 this, SLOT(importFromDocument()));
925 connect (ui->action_GoToClubeNCLWebsite, SIGNAL(triggered()),
926 this, SLOT(gotoNCLClubWebsite()));
928 connect (ui->action_Help, SIGNAL(triggered()),
this, SLOT(
showHelp()));
931 void ComposerMainWindow::createStatusBar()
933 statusBar()->showMessage(tr(
"Ready"));
936 void ComposerMainWindow::showCurrentWidgetFullScreen()
938 tabProjects->addAction(fullScreenViewAct);
940 if(!tabProjects->isFullScreen())
942 tabProjects->setWindowFlags(Qt::Window);
943 tabProjects->showFullScreen();
947 tabProjects->setParent(ui->frame, Qt::Widget);
952 void ComposerMainWindow::updateViewMenu()
954 ui->menu_Window->clear();
956 ui->menu_Window->addAction(fullScreenViewAct);
958 ui->menu_Window->addSeparator();
961 ui->menu_Views->clear();
962 ui->menu_Window->addMenu(ui->menu_Views);
963 if(tabProjects->count())
965 QString location = tabProjects->tabToolTip(tabProjects->currentIndex());
967 for(
int i = 0; i < allDocks.size(); i++)
969 if(allDocks.at(i)->property(
"project").toString() == location)
970 ui->menu_Views->addAction(allDocks.at(i)->toggleViewAction());
974 if(ui->menu_Views->isEmpty())
975 ui->menu_Views->setEnabled(
false);
977 ui->menu_Views->setEnabled(
true);
979 ui->menu_Window->addSeparator();
980 ui->menu_Window->addAction(saveCurrentPluginsLayoutAct);
981 ui->menu_Window->addAction(restorePluginsLayoutAct);
985 void ComposerMainWindow::closeEvent(QCloseEvent *event)
989 for(
int index = 1; index < tabProjects->count(); index++)
991 QString location = tabProjects->tabToolTip(index);
992 Project *project = ProjectControl::getInstance()->getOpenProject(location);
994 qDebug() << location << project;
995 if(project != NULL && project->isDirty())
997 tabProjects->setCurrentIndex(index);
998 int ret = QMessageBox::warning(
this, project->getAttribute(
"id"),
999 tr(
"The project %1 has been modified.\n"
1000 "Do you want to save your changes?").
1002 QMessageBox::Yes | QMessageBox::Default,
1004 QMessageBox::Cancel|QMessageBox::Escape);
1005 if (ret == QMessageBox::Yes)
1007 else if (ret == QMessageBox::Cancel)
1016 settings.beginGroup(
"extensions");
1017 settings.setValue(
"path", extensions_paths);
1018 settings.endGroup();
1020 settings.beginGroup(
"mainwindow");
1021 settings.setValue(
"geometry", saveGeometry());
1022 settings.setValue(
"windowState", saveState());
1023 settings.endGroup();
1025 QStringList openfiles;
1027 foreach (key, projectsWidgets.keys())
1030 settings.beginGroup(
"openfiles");
1031 if(openfiles.size())
1033 settings.setValue(
"openfiles", openfiles);
1038 settings.remove(
"openfiles");
1040 settings.endGroup();
1047 void ComposerMainWindow::cleanUp()
1049 LanguageControl::releaseInstance();
1050 ProjectControl::releaseInstance();
1051 PluginControl::releaseInstance();
1054 void ComposerMainWindow::showEditPreferencesDialog()
1056 preferences->show();
1059 void ComposerMainWindow::startOpenProject(QString project)
1063 this->setCursor(QCursor(Qt::WaitCursor));
1067 void ComposerMainWindow::endOpenProject(QString project)
1069 this->setCursor(QCursor(Qt::ArrowCursor));
1073 if(settings.contains(
"default_perspective"))
1075 QString defaultPerspective =
1076 settings.value(
"default_perspective").toString();
1079 restorePerspective(defaultPerspective);
1086 QMainWindow *window = projectsWidgets[project];
1087 QList <QDockWidget *> docks = window->findChildren <QDockWidget* >(QRegExp(
"br.*"));
1088 QMap <QString, QDockWidget*> dockByPluginId;
1089 QList <QDockWidget *> leftDocks, rightDocks, bottomDocks;
1090 for(
int i = 0; i < docks.size(); i++)
1092 dockByPluginId[docks[i]->objectName()] = docks[i];
1093 if(docks[i]->objectName() ==
"br.puc-rio.telemidia.OutlineView" ||
1094 docks[i]->objectName() ==
"br.puc-rio.telemidia.PropertiesView")
1096 leftDocks.append(docks[i]);
1098 else if(docks[i]->objectName() ==
"br.puc-rio.telemidia.DebugConsole" ||
1099 docks[i]->objectName() ==
"br.ufma.deinf.laws.validator")
1101 bottomDocks.append(docks[i]);
1104 rightDocks.append(docks[i]);
1107 for(
int i = leftDocks.size()-1; i >= 0; i--)
1109 leftDocks[i]->widget()->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
1110 leftDocks[i]->widget()->setMinimumWidth(200);
1113 window->addDockWidget(Qt::LeftDockWidgetArea, leftDocks[i]);
1115 window->addDockWidget(Qt::LeftDockWidgetArea, leftDocks[i], Qt::Vertical);
1117 window->adjustSize();
1120 for(
int i = 0; i < rightDocks.size(); i++)
1122 rightDocks[i]->widget()->setSizePolicy(QSizePolicy::Expanding,
1123 QSizePolicy::Expanding);
1126 window->addDockWidget(Qt::RightDockWidgetArea, rightDocks[i]);
1128 window->tabifyDockWidget(rightDocks[0], rightDocks[i]);
1131 for(
int i = 0; i < bottomDocks.size(); i++)
1133 bottomDocks[i]->widget()->setSizePolicy(QSizePolicy::MinimumExpanding,
1134 QSizePolicy::MinimumExpanding);
1135 bottomDocks[i]->widget()->setMaximumHeight(200);
1136 bottomDocks[i]->widget()->setMinimumHeight(100);
1138 window->addDockWidget(Qt::RightDockWidgetArea, bottomDocks[i], Qt::Vertical);
1140 window->tabifyDockWidget(bottomDocks[0], bottomDocks[i]);
1144 this->updateGeometry();
1149 int index = tabProjects->currentIndex();
1150 bool saveAlsoNCLDocument =
true;
1154 QString location = tabProjects->tabToolTip(index);
1155 Project *project = ProjectControl::getInstance()->getOpenProject(location);
1157 PluginControl::getInstance()->savePluginsData(project);
1158 ProjectControl::getInstance()->saveProject(location);
1159 ui->action_Save->setEnabled(
false);
1161 if(saveAlsoNCLDocument)
1163 QString nclfilepath = location.mid(0, location.lastIndexOf(
".")) +
".ncl";
1164 QFile file(nclfilepath);
1165 if(file.open(QFile::WriteOnly | QIODevice::Truncate))
1168 if(project->getChildren().size())
1169 file.write(project->getChildren().at(0)->toString(0,
false).toAscii());
1177 QMessageBox box(QMessageBox::Warning,
1179 tr(
"There aren't a project to be saved."),
1188 int index = tabProjects->currentIndex();
1189 bool saveAlsoNCLDocument =
true;
1193 QString location = tabProjects->tabToolTip(index);
1195 QString destFileName = QFileDialog::getSaveFileName(
1197 tr(
"Save as NCL Composer Project"),
1198 getLastFileDialogPath(),
1199 tr(
"NCL Composer Projects (*.cpr)") );
1201 if(!destFileName.isNull() && !destFileName.isEmpty())
1203 updateLastFileDialogPath(destFileName);
1205 if(!destFileName.endsWith(
".cpr"))
1206 destFileName = destFileName +
".cpr";
1209 ProjectControl::getInstance()->moveProject(location, destFileName);
1213 ProjectControl::getInstance()->getOpenProject(destFileName);
1215 PluginControl::getInstance()->savePluginsData(project);
1216 ProjectControl::getInstance()->saveProject(destFileName);
1219 updateTabWithProject(index, destFileName);
1221 ui->action_Save->setEnabled(
false);
1223 if(saveAlsoNCLDocument)
1225 QString nclfilepath =
1226 location.mid(0, destFileName.lastIndexOf(
".")) +
".ncl";
1228 QFile file(nclfilepath);
1229 if(file.open(QFile::WriteOnly | QIODevice::Truncate))
1232 if(project->getChildren().size())
1233 file.write(project->getChildren().at(0)->toString(0,
false).toAscii());
1239 addToRecentProjects(destFileName);
1244 QMessageBox box(QMessageBox::Warning,
1246 tr(
"There aren't a project to be saved."),
1253 void ComposerMainWindow::saveCurrentGeometryAsPerspective()
1255 if(tabProjects->count())
1258 if(perspectiveManager->exec())
1266 QMessageBox box(QMessageBox::Warning,
1268 tr(
"There aren't a layout open to be saved."),
1274 updateMenuPerspectives();
1277 void ComposerMainWindow::restorePerspective()
1280 if(perspectiveManager->exec())
1286 updateMenuPerspectives();
1289 void ComposerMainWindow::savePerspective(QString layoutName)
1291 if(tabProjects->count())
1293 QString location = tabProjects->tabToolTip(tabProjects->currentIndex());
1295 QMainWindow *window = projectsWidgets[location];
1296 QSettings settings(QSettings::IniFormat,
1297 QSettings::UserScope,
1301 settings.beginGroup(
"pluginslayout");
1302 settings.setValue(layoutName, window->saveState(0));
1303 settings.endGroup();
1307 void ComposerMainWindow::saveDefaultPerspective(QString defaultPerspectiveName)
1310 settings.setValue(
"default_perspective", defaultPerspectiveName);
1313 void ComposerMainWindow::restorePerspective(QString layoutName)
1315 if(tabProjects->count())
1317 QString location = tabProjects->tabToolTip(
1318 tabProjects->currentIndex());
1320 QMainWindow *window = projectsWidgets[location];
1322 settings.beginGroup(
"pluginslayout");
1324 window->restoreState(settings.value(layoutName).toByteArray());
1326 settings.endGroup();
1330 void ComposerMainWindow::runNCL()
1333 if(localGingaProcess.state() == QProcess::Running
1335 || runRemoteGingaVMThread.isRunning()
1339 QMessageBox::StandardButton reply;
1340 reply = QMessageBox::warning(NULL, tr(
"Warning!"),
1341 tr(
"You already have an NCL application "
1342 "running. Please, stop it before you start "
1348 ui->action_RunNCL->setEnabled(
false);
1351 bool runRemote =
false;
1353 settings.beginGroup(
"runginga");
1354 if(settings.contains(
"run_remote") && settings.value(
"run_remote").toBool())
1358 settings.endGroup();
1361 runOnRemoteGingaVM();
1365 ui->action_StopNCL->setEnabled(
true);
1368 void ComposerMainWindow::runOnLocalGinga()
1371 QString command, args;
1372 settings.beginGroup(
"runginga");
1373 command = settings.value(
"local_ginga_cmd").toString();
1374 args = settings.value(
"local_ginga_args").toString();
1375 settings.endGroup();
1378 QStringList args_list;
1379 QString location = tabProjects->tabToolTip(tabProjects->currentIndex());
1381 if(location.isEmpty())
1383 QMessageBox::StandardButton reply;
1384 reply = QMessageBox::warning(
this, tr(
"Warning!"),
1385 tr(
"There aren't a current NCL project."),
1390 Project *project = ProjectControl::getInstance()->getOpenProject(location);
1391 QString nclpath = location.mid(0, location.lastIndexOf(
"/")) +
"/tmp.ncl";
1392 qDebug() <<
"Running NCL File: " << nclpath;
1394 QFile file(nclpath);
1395 if(file.open(QFile::WriteOnly | QIODevice::Truncate))
1398 if(project->getChildren().size())
1399 file.write(project->getChildren().at(0)->toString(0,
false).toAscii());
1405 args.replace(
"${nclpath}", nclpath);
1406 args_list << args.split(
"\n");
1408 localGingaProcess.start(command, args_list);
1409 QByteArray result = localGingaProcess.readAll();
1413 qWarning() <<
"Error trying to running NCL. Could not create : "
1418 void ComposerMainWindow::runOnRemoteGingaVM()
1421 int currentTab = tabProjects->currentIndex();
1425 ui->action_RunNCL->setEnabled(
false);
1427 QString location = tabProjects->tabToolTip(currentTab);
1428 Project *currentProject = ProjectControl::getInstance()->
1429 getOpenProject(location);
1431 if(currentProject->isDirty())
1440 reply = QMessageBox::warning(NULL, tr(
"Warning!"),
1441 tr(
"Your document is not saved."
1442 "Do you want to save it now?"),
1443 QMessageBox::Yes, QMessageBox::No);
1445 if(reply == QMessageBox::Yes)
1452 runRemoteGingaVMAction.setCurrentProject(currentProject);
1454 runRemoteGingaVMThread.start();
1459 QMessageBox::StandardButton reply;
1460 reply = QMessageBox::warning(NULL, tr(
"Warning!"),
1461 tr(
"There aren't a current NCL project."),
1466 QMessageBox::StandardButton reply;
1467 reply = QMessageBox::warning(NULL, tr(
"Warning!"),
1468 tr(
"Your NCL Composer was not build with Remote "
1474 void ComposerMainWindow::stopNCL()
1476 if(localGingaProcess.state() == QProcess::Running)
1477 localGingaProcess.close();
1480 if(runRemoteGingaVMThread.isRunning())
1481 stopRemoteGingaVMAction.stopRunningApplication();
1487 bool ComposerMainWindow::isRunningNCL()
1490 if(localGingaProcess.state() == QProcess::Running
1492 || runRemoteGingaVMThread.isRunning()
1501 void ComposerMainWindow::updateRunActions()
1505 ui->action_RunNCL->setEnabled(
false);
1506 ui->action_StopNCL->setEnabled(
true);
1510 ui->action_RunNCL->setEnabled(
true);
1511 ui->action_StopNCL->setEnabled(
false);
1515 void ComposerMainWindow::runHasFinished()
1517 qDebug() <<
"ComposerMainWindow::runHasFinished()";
1521 void ComposerMainWindow::launchProjectWizard()
1524 wizard.setModal(
true);
1527 if(wizard.result() == QWizard::Accepted)
1529 QString filename = wizard.getProjectFullPath();
1531 filename.replace(
"\\",
"/");
1533 if( !filename.isNull() && !filename.isEmpty())
1536 updateLastFileDialogPath(filename);
1538 if(!filename.endsWith(
".cpr"))
1539 filename = filename + QString(
".cpr");
1541 QFileInfo info(filename);
1545 if(QMessageBox::question(
this, tr(
"File already exists!"),
1546 tr(
"The file \"%1\" already exists. Do you want overwrite it?").arg(filename),
1547 QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::No)
1550 QFile::remove(filename);
1557 if(ProjectControl::getInstance()->launchProject(filename))
1561 Project *project = ProjectControl::getInstance()
1562 ->getOpenProject(filename);
1564 addDefaultStructureToProject( project,
1565 wizard.shouldCopyDefaultConnBase(),
1566 wizard.shouldCreateADefaultRegion());
1576 void ComposerMainWindow::addDefaultStructureToProject(Project *project,
1577 bool shouldCopyDefaultConnBase,
1578 bool shouldCreateADefaultRegion,
1581 const QString defaultNCLID =
"myNCLDocID";
1582 const QString defaultBodyID =
"myBodyID";
1583 const QString defaultConnBaseID =
"connBaseId";
1584 const QString defaultRegionBaseID =
"regionBase0";
1585 const QString defaultRegionID =
"region0";
1587 QMap <QString, QString> nclAttrs, headAttrs, bodyAttrs;
1588 nclAttrs.insert(
"id", defaultNCLID);
1589 nclAttrs.insert(
"xmlns",
"http://www.ncl.org.br/NCL3.0/EDTVProfile");
1593 ->getMessageControl(project);
1596 nclEntity = project->getEntitiesbyType(
"ncl").first();
1598 if(nclEntity != NULL)
1600 QString nclEntityId = nclEntity->getUniqueId();
1603 bodyAttrs.insert(
"id", defaultBodyID);
1608 if(shouldCopyDefaultConnBase)
1611 settings.beginGroup(
"importBases");
1612 QString defaultConnBase =
1613 settings.value(
"default_conn_base").toString();
1614 settings.endGroup();
1616 qDebug() <<
"[GUI] DefaultConnBase " << defaultConnBase;
1618 QFileInfo defaultConnBaseInfo(defaultConnBase);
1619 if(defaultConnBaseInfo.exists())
1621 QString filename = project->getLocation();
1622 QString newConnBase = filename. mid(0, filename.lastIndexOf(
"/")+1) +
1623 defaultConnBaseInfo.fileName();
1625 qDebug() <<
"[GUI] Copy " << defaultConnBase <<
" to "
1629 if(QFile::exists(newConnBase))
1631 QFile::remove(newConnBase);
1635 if(QFile::copy(defaultConnBase, newConnBase))
1640 QMap <QString, QString> connBaseAttrs, importBaseAttrs;
1641 connBaseAttrs.insert(
"id", defaultConnBaseID);
1642 importBaseAttrs.insert(
"alias",
"conn");
1643 importBaseAttrs.insert(
"documentURI",
1644 defaultConnBaseInfo.fileName());
1647 Entity *head = project->getEntitiesbyType(
"head").at(0);
1649 head->getUniqueId(),
1653 Entity *connectorBase =
1654 project->getEntitiesbyType(
"connectorBase").at(0);
1656 connectorBase->getUniqueId(),
1661 QMessageBox::warning(
this, tr(
"Error!"),
1662 tr(
"There was an error copying the default"
1663 "Connector Base. You will need to add a "
1664 "Connector Base by hand in your NCL "
1671 QMessageBox::warning(
this, tr(
"Error!"),
1672 tr(
"The default Connector Base %1 does not "
1673 "exists").arg(defaultConnBase),
1678 if(shouldCreateADefaultRegion)
1680 QMap <QString, QString> regionBaseAttrs, regionAttrs;
1681 QList<Entity*> regionBases = project->getEntitiesbyType(
"regionBase");
1684 if(!regionBases.size())
1686 regionBaseAttrs.insert(
"id", defaultRegionBaseID);
1687 Entity *head = project->getEntitiesbyType(
"head").at(0);
1689 head->getUniqueId(),
1694 Entity *regionBase = project->getEntitiesbyType(
"regionBase").at(0);
1695 regionAttrs.insert(
"id", defaultRegionID);
1696 regionAttrs.insert(
"top",
"0");
1697 regionAttrs.insert(
"left",
"0");
1698 regionAttrs.insert(
"width",
"100%");
1699 regionAttrs.insert(
"height",
"100%");
1700 regionAttrs.insert(
"zIndex",
"1");
1702 regionBase->getUniqueId(),
1706 if(shouldCreateADefaultRegion)
1717 QString filename = QFileDialog::getOpenFileName(
this,
1718 tr(
"Open NCL Composer Project"),
1719 getLastFileDialogPath(),
1720 tr(
"NCL Composer Projects (*.cpr)"));
1724 filename = filename.replace(
"\\",
"/");
1729 ProjectControl::getInstance()->launchProject(filename);
1731 updateLastFileDialogPath(filename);
1737 QFileInfo temporaryFileInfo(filename +
"~");
1738 QFileInfo fileInfo(filename);
1740 if(temporaryFileInfo.exists() &&
1741 temporaryFileInfo.lastModified() > fileInfo.lastModified())
1743 bool replace = QMessageBox::question(
this,
1744 tr(
"Temporary file is newer."),
1745 tr(
"There is a temporary file related to %1 that is"
1746 " newer. Do you want replace the %1 file with "
1747 " this temporary one?").arg(filename),
1748 QMessageBox::Yes | QMessageBox::No,
1753 QFile file (filename +
"~");
1754 if(!file.copy(filename))
1756 QFile oldfile (filename);
1758 file.copy(filename);
1766 QFile file(location +
"~");
1767 return file.remove();
1770 void ComposerMainWindow::updateLastFileDialogPath(QString filepath)
1772 Utilities::updateLastFileDialogPath(filepath);
1775 QString ComposerMainWindow::getLastFileDialogPath()
1777 return Utilities::getLastFileDialogPath();
1780 void ComposerMainWindow::importFromDocument()
1782 QString docFilename = QFileDialog::getOpenFileName(
1784 tr(
"Choose the NCL file to be imported"),
1785 getLastFileDialogPath(),
1786 tr(
"NCL Documents (*.ncl)") );
1788 if(docFilename !=
"")
1790 updateLastFileDialogPath(docFilename);
1792 QString projFilename = QFileDialog::getSaveFileName(
1794 tr(
"Choose the NCL Composer Project where the NCL document must be "
1796 getLastFileDialogPath(),
1797 tr(
"NCL Composer Projects (*.cpr)") );
1800 QFile f(projFilename);
1801 f.open(QIODevice::ReadWrite);
1804 if(projFilename !=
"")
1807 projFilename = projFilename.replace(QDir::separator(),
"/");
1809 ProjectControl::getInstance()->importFromDocument(docFilename,
1812 updateLastFileDialogPath(projFilename);
1817 void ComposerMainWindow::addToRecentProjects(QString projectUrl)
1820 QStringList recentProjects = settings.value(
"recentProjects").toStringList();
1822 recentProjects.push_front(projectUrl);
1823 recentProjects.removeDuplicates();
1826 while(recentProjects.size() > this->maximumRecentProjectsSize)
1827 recentProjects.pop_back();
1829 settings.setValue(
"recentProjects", recentProjects);
1831 updateRecentProjectsMenu(recentProjects);
1832 welcomeWidget->updateRecentProjects(recentProjects);
1835 void ComposerMainWindow::updateRecentProjectsMenu(QStringList &recentProjects)
1837 ui->menu_Recent_Files->clear();
1838 if(recentProjects.size() == 0 )
1840 QAction *act = ui->menu_Recent_Files->addAction(tr(
"empty"));
1841 act->setEnabled(
false);
1845 for(
int i = 0; i < recentProjects.size(); i++)
1847 QAction *act = ui->menu_Recent_Files->addAction(
1848 recentProjects.at(i));
1849 act->setData(recentProjects.at(i));
1850 connect(act, SIGNAL(triggered()),
this, SLOT(userPressedRecentProject()));
1853 ui->menu_Recent_Files->addSeparator();
1854 QAction *clearRecentProjects =
1855 ui->menu_Recent_Files->addAction(tr(
"Clear Recent Projects"));
1857 connect(clearRecentProjects, SIGNAL(triggered()),
1858 this, SLOT(clearRecentProjects()));
1863 void ComposerMainWindow::userPressedRecentProject(QString src)
1866 src = src.replace(QDir::separator(),
"/");
1870 bool openCurrentFile =
true, recreateFile =
false;
1874 QMessageBox::question(
this,
1875 tr(
"File does not exists anymore."),
1876 tr(
"The File %1 does not exists anymore. "
1877 "Do you want to create this file "
1879 QMessageBox::Yes | QMessageBox::No,
1882 if(resp != QMessageBox::Yes)
1883 openCurrentFile =
false;
1885 recreateFile =
true;
1892 ProjectControl::getInstance()->launchProject(src);
1898 bool ok = dir.mkpath(QFileInfo(src).absolutePath());
1903 QMessageBox::critical(
this, tr(
"Error!"), tr(
"Error creating directory structure"));
1908 addDefaultStructureToProject(
1909 ProjectControl::getInstance()->getOpenProject(src),
1917 void ComposerMainWindow::userPressedRecentProject()
1919 QAction *action = qobject_cast<QAction *> (QObject::sender());
1921 QString src = action->data().toString();
1923 userPressedRecentProject(src);
1926 void ComposerMainWindow::clearRecentProjects(
void)
1930 settings.remove(
"recentProjects");
1932 updateRecentProjectsMenu(empty);
1933 welcomeWidget->updateRecentProjects(empty);
1936 void ComposerMainWindow::selectedAboutCurrentPluginFactory()
1938 QList<QTreeWidgetItem*> selectedPlugins = pluginsExt->selectedItems();
1939 if(selectedPlugins.size())
1941 if(treeWidgetItem2plFactory.value(selectedPlugins.at(0)) != NULL)
1943 pluginDetailsDialog->setCurrentPlugin(
1944 treeWidgetItem2plFactory.value(selectedPlugins.at(0)));
1945 detailsButton->setEnabled(
true);
1948 detailsButton->setEnabled(
false);
1952 void ComposerMainWindow::showPluginDetails()
1954 pluginDetailsDialog->show();
1957 void ComposerMainWindow::restorePerspectiveFromMenu()
1959 QAction *action = qobject_cast<QAction*>(QObject::sender());
1960 restorePerspective(action->data().toString());
1963 void ComposerMainWindow::updateMenuPerspectives()
1966 settings.beginGroup(
"pluginslayout");
1967 QStringList keys = settings.allKeys();
1968 settings.endGroup();
1970 menu_Perspective->clear();
1972 for(
int i = 0; i < keys.size(); i++)
1974 QAction *act = menu_Perspective->addAction(keys.at(i),
1976 SLOT(restorePerspectiveFromMenu()));
1977 act->setData(keys[i]);
1981 menu_Perspective->addSeparator();
1982 menu_Perspective->addAction(saveCurrentPluginsLayoutAct);
1985 void ComposerMainWindow::updateMenuLanguages()
1987 QStringList languages;
1988 languages << tr(
"English") << tr(
"Portugues (Brasil)");
1990 for(
int i = 0; i < languages.size(); i++)
1992 QAction *act = menu_Language->addAction(languages.at(i),
1994 SLOT(changeLanguageFromMenu()));
1995 act->setData(languages[i]);
1999 void ComposerMainWindow::currentTabChanged(
int n)
2003 tbPerspectiveDropList->setEnabled(
true);
2004 saveCurrentPluginsLayoutAct->setEnabled(
true);
2005 restorePluginsLayoutAct->setEnabled(
true);
2006 ui->action_CloseProject->setEnabled(
true);
2007 ui->action_Save->setEnabled(
true);
2008 ui->action_SaveAs->setEnabled(
true);
2015 tbPerspectiveDropList->setEnabled(
false);
2016 saveCurrentPluginsLayoutAct->setEnabled(
false);
2017 restorePluginsLayoutAct->setEnabled(
false);
2018 ui->action_CloseProject->setEnabled(
false);
2019 ui->action_Save->setEnabled(
false);
2020 ui->action_SaveAs->setEnabled(
false);
2021 ui->action_RunNCL->setEnabled(
false);
2022 ui->action_StopNCL->setEnabled(
false);
2026 void ComposerMainWindow::focusChanged(QWidget *old, QWidget *now)
2031 if(qApp->activeModalWidget() != NULL)
2035 allDocksMutex.lock();
2036 for(
int i = 0; i < allDocks.size(); i++)
2039 updateDockStyle(allDocks.at(i),
false);
2041 allDocksMutex.unlock();
2045 allDocksMutex.lock();
2049 for(
int i = 0 ; i < allDocks.size(); i++)
2051 bool isAncestor =
false;
2052 QWidget *child = now;
2054 while (child && child !=
this)
2058 if (child == allDocks.at(i))
2063 child = child->parentWidget();
2068 updateDockStyle(allDocks.at(i),
true);
2071 allDocksMutex.unlock();
2075 void ComposerMainWindow::setProjectDirty(QString location,
bool isDirty)
2077 QMainWindow *window = projectsWidgets[location];
2079 ProjectControl::getInstance()->
2080 getOpenProject(location)->getAttribute(
"id");
2082 int index = tabProjects->indexOf(window);
2084 ui->action_Save->setEnabled(
true);
2088 tabProjects->setTabText(index, QString(
"*")+projectId);
2090 tabProjects->setTabText(index, projectId);
2094 void ComposerMainWindow::undo()
2096 int index = tabProjects->currentIndex();
2100 QString location = tabProjects->tabToolTip(index);
2101 Project *project = ProjectControl::getInstance()->getOpenProject(location);
2103 PluginControl::getInstance()->getMessageControl(project);
2108 void ComposerMainWindow::redo()
2110 int index = tabProjects->currentIndex();
2114 QString location = tabProjects->tabToolTip(index);
2115 Project *project = ProjectControl::getInstance()->getOpenProject(location);
2117 PluginControl::getInstance()->getMessageControl(project);
2123 void ComposerMainWindow::gotoNCLClubWebsite()
2125 QDesktopServices::openUrl(QUrl(
"http://club.ncl.org.br"));
2130 composerHelpWidget.show();
2163 void ComposerMainWindow::autoSaveCurrentProjects()
2165 for(
int i = 1; i < tabProjects->count(); i++)
2167 QString location = tabProjects->tabToolTip(i);
2168 Project *project = ProjectControl::getInstance()->getOpenProject(location);
2169 if(project->isDirty())
2171 PluginControl::getInstance()->savePluginsData(project);
2172 ProjectControl::getInstance()->saveTemporaryProject(location);
2178 void ComposerMainWindow::createLanguageMenu(
void)
2180 QActionGroup* langGroup =
new QActionGroup(menu_Language);
2181 langGroup->setExclusive(
true);
2183 connect(langGroup, SIGNAL(triggered(QAction *)),
this, SLOT(
slotLanguageChanged(QAction *)));
2186 QString defaultLocale = QLocale::system().name();
2187 defaultLocale.truncate(defaultLocale.lastIndexOf(
'_'));
2189 m_langPath = QApplication::applicationDirPath();
2190 m_langPath.append(
"/languages");
2191 QDir dir(m_langPath);
2192 QStringList fileNames = dir.entryList(QStringList(
"composer_*.qm"));
2194 qDebug() << fileNames;
2195 for (
int i = 0; i < fileNames.size(); ++i)
2199 locale = fileNames[i];
2200 locale.truncate(locale.lastIndexOf(
'.'));
2201 locale.remove(0, locale.indexOf(
'_') + 1);
2203 QString lang = QLocale::languageToString(QLocale(locale).language());
2204 QIcon ico(QString(
"%1/%2.png").arg(m_langPath).arg(locale));
2206 QAction *action =
new QAction(ico, lang,
this);
2207 action->setCheckable(
true);
2208 action->setData(locale);
2211 menu_Language->addAction(action);
2212 langGroup->addAction(action);
2215 if (defaultLocale == locale)
2217 action->setChecked(
true);
2228 loadLanguage(action->data().toString());
2229 setWindowIcon(action->icon());
2233 void ComposerMainWindow::switchTranslator(QTranslator& translator,
2234 const QString& filename)
2237 qApp->removeTranslator(&translator);
2240 if(translator.load(filename))
2241 qApp->installTranslator(&translator);
2244 void ComposerMainWindow::loadLanguage(
const QString& rLanguage)
2246 qDebug() << rLanguage;
2247 if(m_currLang != rLanguage)
2249 m_currLang = rLanguage;
2250 QLocale locale = QLocale(m_currLang);
2251 QLocale::setDefault(locale);
2252 QString languageName = QLocale::languageToString(locale.language());
2253 switchTranslator(m_translator,
2254 m_langPath +
"/" + QString(
"composer_%1.qm").arg(rLanguage));
2255 switchTranslator(m_translatorQt, QString(
"qt_%1.qm").arg(rLanguage));
2265 switch(event->type())
2268 case QEvent::LanguageChange:
2269 ui->retranslateUi(
this);
2272 case QEvent::LocaleChange:
2274 QString locale = QLocale::system().name();
2275 locale.truncate(locale.lastIndexOf(
'_'));
2276 loadLanguage(locale);
2284 QMainWindow::changeEvent(event);
2287 void ComposerMainWindow::updateTabWithProject(
int index, QString newLocation)
2289 QString oldLocation = tabProjects->tabToolTip(index);
2291 if(oldLocation == newLocation)
return;
2294 if(!oldLocation.isNull() && !oldLocation.isEmpty())
2297 if(projectsWidgets.contains(oldLocation))
2299 projectsWidgets.insert(newLocation, projectsWidgets.value(oldLocation));
2300 projectsWidgets.remove(oldLocation);
2304 if(firstDock.contains(oldLocation))
2306 firstDock.insert(newLocation, firstDock.value(oldLocation));
2307 firstDock.remove(oldLocation);
2312 tabProjects->setTabToolTip(index, newLocation);
2313 Project *project = ProjectControl::getInstance()->getOpenProject(newLocation);
2316 QString projectId = project->getAttribute(
"id");
2317 tabProjects->setTabText(index, projectId);
2324 settings.beginGroup(
"loadPlugins");
2325 QTreeWidgetItem *item;
2326 qDebug() << treeWidgetItem2plFactory.keys();
2327 foreach(item, treeWidgetItem2plFactory.keys())
2329 if(item->checkState(1))
2331 settings.setValue(treeWidgetItem2plFactory.value(item)->id(),
true);
2335 qDebug() << treeWidgetItem2plFactory.value(item) <<
"2";
2336 settings.setValue(treeWidgetItem2plFactory.value(item)->id(),
false);
2339 settings.endGroup();
2342 void ComposerMainWindow::on_actionReport_Bug_triggered()
2344 QDesktopServices::openUrl(QUrl(
"http://composer.telemidia.puc-rio.br/en/contact"));