LP-48 changes from review (2) + Missing changes
[librepilot.git] / ground / openpilotgcs / src / plugins / coreplugin / mainwindow.cpp
blobcfc13452965be74cd4a74d3f2c33de93261c6ec2
1 /**
2 ******************************************************************************
4 * @file mainwindow.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "mainwindow.h"
30 #include "actioncontainer.h"
31 #include "actionmanager_p.h"
32 #include "basemode.h"
33 #include "connectionmanager.h"
34 #include "coreimpl.h"
35 #include "coreconstants.h"
36 #include "utils/mytabwidget.h"
37 #include "generalsettings.h"
38 #include "messagemanager.h"
39 #include "modemanager.h"
40 #include "mimedatabase.h"
41 #include "outputpane.h"
42 #include "plugindialog.h"
43 #include "shortcutsettings.h"
44 #include "uavgadgetmanager.h"
45 #include "uavgadgetinstancemanager.h"
46 #include "workspacesettings.h"
48 #include "aboutdialog.h"
49 #include "baseview.h"
50 #include "ioutputpane.h"
51 #include "icorelistener.h"
52 #include "iconfigurableplugin.h"
54 #include <qstylefactory.h>
56 #include "rightpane.h"
57 #include "settingsdialog.h"
58 #include "threadmanager.h"
59 #include "uniqueidmanager.h"
60 #include "variablemanager.h"
62 #include <coreplugin/settingsdatabase.h>
63 #include <extensionsystem/pluginmanager.h>
64 #include "dialogs/iwizard.h"
65 #include <utils/pathchooser.h>
66 #include <utils/pathutils.h>
67 #include <utils/stylehelper.h>
68 #include <utils/xmlconfig.h>
69 #include "version_info/version_info.h"
71 #include <QtCore/QDebug>
72 #include <QtCore/QFileInfo>
73 #include <QtCore/QSettings>
74 #include <QtCore/QTimer>
75 #include <QtCore/QtPlugin>
76 #include <QtCore/QUrl>
78 #include <QtWidgets/QApplication>
79 #include <QCloseEvent>
80 #include <QMenu>
81 #include <QPixmap>
82 #include <QShortcut>
83 #include <QStatusBar>
84 #include <QWizard>
85 #include <QToolButton>
86 #include <QMessageBox>
87 #include <QDesktopServices>
88 #include <QElapsedTimer>
89 #include <QDir>
90 #include <QMimeData>
92 using namespace Core;
93 using namespace Core::Internal;
95 static const char *uriListMimeFormatC = "text/uri-list";
97 enum { debugMainWindow = 0 };
99 MainWindow::MainWindow() :
100 EventFilteringMainWindow(),
101 m_coreImpl(new CoreImpl(this)),
102 m_uniqueIDManager(new UniqueIDManager()),
103 m_globalContext(QList<int>() << Constants::C_GLOBAL_ID),
104 m_additionalContexts(m_globalContext),
105 // keep this in sync with main() in app/main.cpp
106 m_settings(new QSettings(this)),
107 m_globalSettings(new QSettings(XmlConfig::XmlSettingsFormat, QSettings::SystemScope,
108 m_settings->organizationName(), m_settings->applicationName(), this)),
109 m_settingsDatabase(new SettingsDatabase(QFileInfo(m_settings->fileName()).path(),
110 QFileInfo(m_settings->fileName()).baseName(),
111 this)),
112 m_dontSaveSettings(false),
113 m_actionManager(new ActionManagerPrivate(this)),
114 m_variableManager(new VariableManager(this)),
115 m_threadManager(new ThreadManager(this)),
116 m_modeManager(0),
117 m_connectionManager(0),
118 m_mimeDatabase(new MimeDatabase),
119 m_aboutDialog(0),
120 m_activeContext(0),
121 m_generalSettings(new GeneralSettings),
122 m_shortcutSettings(new ShortcutSettings),
123 m_workspaceSettings(new WorkspaceSettings),
124 m_focusToEditor(0),
125 m_newAction(0),
126 m_openAction(0),
127 m_openWithAction(0),
128 m_saveAllAction(0),
129 m_exitAction(0),
130 m_optionsAction(0),
131 #ifdef Q_WS_MAC
132 m_minimizeAction(0),
133 m_zoomAction(0),
134 #endif
135 m_toggleFullScreenAction(0)
137 setWindowTitle(QLatin1String(GCS_BIG_NAME) + " " + VersionInfo::label());
138 #ifndef Q_WS_MAC
139 qApp->setWindowIcon(QIcon(":/core/images/librepilot_logo_128.png"));
140 #endif
141 qApp->setStyle(QStyleFactory::create("Fusion"));
143 setDockNestingEnabled(true);
145 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
146 setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
148 registerDefaultContainers();
149 registerDefaultActions();
151 m_modeStack = new MyTabWidget(this);
152 m_modeStack->setIconSize(QSize(24, 24));
153 m_modeStack->setTabPosition(QTabWidget::South);
154 m_modeStack->setMovable(false);
155 m_modeStack->setMinimumWidth(512);
156 m_modeStack->setElideMode(Qt::ElideRight);
157 m_modeManager = new ModeManager(this, m_modeStack);
159 m_connectionManager = new ConnectionManager(this);
160 m_modeStack->setCornerWidget(m_connectionManager, Qt::TopRightCorner);
162 m_messageManager = new MessageManager;
163 setCentralWidget(m_modeStack);
165 connect(QApplication::instance(), SIGNAL(focusChanged(QWidget *, QWidget *)),
166 this, SLOT(updateFocusWidget(QWidget *, QWidget *)));
167 connect(m_workspaceSettings, SIGNAL(tabBarSettingsApplied(QTabWidget::TabPosition, bool)),
168 this, SLOT(applyTabBarSettings(QTabWidget::TabPosition, bool)));
169 connect(m_modeManager, SIGNAL(newModeOrder(QVector<IMode *>)), m_workspaceSettings, SLOT(newModeOrder(QVector<IMode *>)));
170 statusBar()->setProperty("p_styled", true);
171 setAcceptDrops(true);
174 MainWindow::~MainWindow()
176 if (m_connectionManager) {
177 // Pip
178 m_connectionManager->disconnectDevice();
179 m_connectionManager->suspendPolling();
182 hide();
184 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
185 if (m_uavGadgetManagers.count() > 0) {
186 foreach(UAVGadgetManager * mode, m_uavGadgetManagers) {
187 pm->removeObject(mode);
188 delete mode;
192 pm->removeObject(m_shortcutSettings);
193 pm->removeObject(m_generalSettings);
194 pm->removeObject(m_workspaceSettings);
195 delete m_messageManager;
196 m_messageManager = 0;
197 delete m_shortcutSettings;
198 m_shortcutSettings = 0;
199 delete m_generalSettings;
200 m_generalSettings = 0;
201 delete m_workspaceSettings;
202 m_workspaceSettings = 0;
203 delete m_settings;
204 m_settings = 0;
205 delete m_uniqueIDManager;
206 m_uniqueIDManager = 0;
208 pm->removeObject(m_coreImpl);
209 delete m_coreImpl;
210 m_coreImpl = 0;
212 delete m_modeManager;
213 m_modeManager = 0;
214 delete m_mimeDatabase;
215 m_mimeDatabase = 0;
218 bool MainWindow::init(QString *errorMessage)
220 Q_UNUSED(errorMessage)
222 ExtensionSystem::PluginManager * pm = ExtensionSystem::PluginManager::instance();
223 pm->addObject(m_coreImpl);
224 m_modeManager->init();
225 m_connectionManager->init();
227 pm->addObject(m_generalSettings);
228 pm->addObject(m_shortcutSettings);
229 pm->addObject(m_workspaceSettings);
231 return true;
234 void MainWindow::modeChanged(Core::IMode * /*mode*/)
237 void MainWindow::extensionsInitialized()
239 QSettings *qs = m_settings;
241 qs->beginGroup("General");
243 m_config_description = qs->value("Description", "none").toString();
244 m_config_details = qs->value("Details", "none").toString();
245 m_config_stylesheet = qs->value("StyleSheet", "none").toString();
247 qDebug() << "Configured style sheet:" << m_config_stylesheet;
248 if (m_config_stylesheet == "wide") {
249 // OP-869 just in case some user configuration still references the now obsolete "wide" style sheet
250 m_config_stylesheet = "default";
253 // Load common style sheet
254 QString style = loadStyleSheet(m_config_stylesheet + ".qss");
256 // Load and concatenate platform specific style sheet
257 QString fileName = m_config_stylesheet;
258 #ifdef Q_OS_MAC
259 fileName += "_macos.qss";
260 #elif defined(Q_OS_LINUX)
261 fileName += "_linux.qss";
262 #else
263 fileName += "_windows.qss";
264 #endif
265 style += loadStyleSheet(fileName);
267 // We'll use qApp macro to get the QApplication pointer
268 // and set the style sheet application wide.
269 // qDebug() << "Setting application style sheet to:" << style;
270 qApp->setStyleSheet(style);
272 qs->endGroup();
274 m_uavGadgetInstanceManager = new UAVGadgetInstanceManager(this);
275 m_uavGadgetInstanceManager->readSettings(qs);
277 m_messageManager->init();
278 readSettings(qs);
280 updateContext();
282 emit m_coreImpl->coreAboutToOpen();
283 show();
284 emit m_coreImpl->coreOpened();
287 QString MainWindow::loadStyleSheet(QString fileName)
289 QString style;
290 // ...to open the file
291 QFile file(Utils::GetDataPath() + QString("stylesheets/") + fileName);
293 qDebug() << "Loading style sheet file" << file.fileName();
294 if (file.open(QFile::ReadOnly)) {
295 // QTextStream...
296 QTextStream textStream(&file);
297 // ...read file to a string.
298 style = textStream.readAll();
299 file.close();
300 } else {
301 qDebug() << "Failed to open style sheet file" << file.fileName();
303 return style;
306 void MainWindow::closeEvent(QCloseEvent *event)
308 if (!m_generalSettings->saveSettingsOnExit()) {
309 m_dontSaveSettings = true;
311 if (!m_dontSaveSettings) {
312 emit m_coreImpl->saveSettingsRequested();
315 const QList<ICoreListener *> listeners = ExtensionSystem::PluginManager::instance()->getObjects<ICoreListener>();
316 foreach(ICoreListener * listener, listeners) {
317 if (!listener->coreAboutToClose()) {
318 event->ignore();
319 return;
323 emit m_coreImpl->coreAboutToClose();
325 if (!m_dontSaveSettings) {
326 saveSettings(m_settings);
327 m_uavGadgetInstanceManager->saveSettings(m_settings);
330 qApp->closeAllWindows();
332 event->accept();
335 // Check for desktop file manager file drop events
336 static bool isDesktopFileManagerDrop(const QMimeData *d, QStringList *files = 0)
338 if (files) {
339 files->clear();
341 // Extract dropped files from Mime data.
342 if (!d->hasFormat(QLatin1String(uriListMimeFormatC))) {
343 return false;
345 const QList<QUrl> urls = d->urls();
346 if (urls.empty()) {
347 return false;
349 // Try to find local files
350 bool hasFiles = false;
351 const QList<QUrl>::const_iterator cend = urls.constEnd();
352 for (QList<QUrl>::const_iterator it = urls.constBegin(); it != cend; ++it) {
353 const QString fileName = it->toLocalFile();
354 if (!fileName.isEmpty()) {
355 hasFiles = true;
356 if (files) {
357 files->push_back(fileName);
358 } else {
359 break; // No result list, sufficient for checking
363 return hasFiles;
366 void MainWindow::dragEnterEvent(QDragEnterEvent *event)
368 if (isDesktopFileManagerDrop(event->mimeData())) {
369 event->accept();
370 } else {
371 event->ignore();
375 void MainWindow::dropEvent(QDropEvent *event)
377 QStringList files;
379 if (isDesktopFileManagerDrop(event->mimeData(), &files)) {
380 event->accept();
381 // openFiles(files);
382 } else {
383 event->ignore();
387 IContext *MainWindow::currentContextObject() const
389 return m_activeContext;
392 QStatusBar *MainWindow::statusBar() const
394 return new QStatusBar(); // m_modeStack->statusBar();
397 void MainWindow::registerDefaultContainers()
399 ActionManagerPrivate *am = m_actionManager;
401 ActionContainer *menubar = am->createMenuBar(Constants::MENU_BAR);
403 #ifndef Q_WS_MAC // System menu bar on Mac
404 setMenuBar(menubar->menuBar());
405 #endif
406 menubar->appendGroup(Constants::G_FILE);
407 menubar->appendGroup(Constants::G_EDIT);
408 menubar->appendGroup(Constants::G_VIEW);
409 menubar->appendGroup(Constants::G_TOOLS);
410 menubar->appendGroup(Constants::G_WINDOW);
411 menubar->appendGroup(Constants::G_HELP);
413 // File Menu
414 ActionContainer *filemenu = am->createMenu(Constants::M_FILE);
415 menubar->addMenu(filemenu, Constants::G_FILE);
416 filemenu->menu()->setTitle(tr("&File"));
417 filemenu->appendGroup(Constants::G_FILE_NEW);
418 filemenu->appendGroup(Constants::G_FILE_OPEN);
419 filemenu->appendGroup(Constants::G_FILE_PROJECT);
420 filemenu->appendGroup(Constants::G_FILE_SAVE);
421 filemenu->appendGroup(Constants::G_FILE_CLOSE);
422 filemenu->appendGroup(Constants::G_FILE_OTHER);
423 connect(filemenu->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowRecentFiles()));
426 // Edit Menu
427 ActionContainer *medit = am->createMenu(Constants::M_EDIT);
428 menubar->addMenu(medit, Constants::G_EDIT);
429 medit->menu()->setTitle(tr("&Edit"));
430 medit->appendGroup(Constants::G_EDIT_UNDOREDO);
431 medit->appendGroup(Constants::G_EDIT_COPYPASTE);
432 medit->appendGroup(Constants::G_EDIT_SELECTALL);
433 medit->appendGroup(Constants::G_EDIT_ADVANCED);
434 medit->appendGroup(Constants::G_EDIT_FIND);
435 medit->appendGroup(Constants::G_EDIT_OTHER);
437 // Tools Menu
438 ActionContainer *ac = am->createMenu(Constants::M_TOOLS);
439 menubar->addMenu(ac, Constants::G_TOOLS);
440 ac->menu()->setTitle(tr("&Tools"));
442 // Window Menu
443 ActionContainer *mwindow = am->createMenu(Constants::M_WINDOW);
444 menubar->addMenu(mwindow, Constants::G_WINDOW);
445 mwindow->menu()->setTitle(tr("&Window"));
446 mwindow->appendGroup(Constants::G_WINDOW_SIZE);
447 mwindow->appendGroup(Constants::G_WINDOW_HIDE_TOOLBAR);
448 mwindow->appendGroup(Constants::G_WINDOW_PANES);
449 mwindow->appendGroup(Constants::G_WINDOW_SPLIT);
450 mwindow->appendGroup(Constants::G_WINDOW_NAVIGATE);
451 mwindow->appendGroup(Constants::G_WINDOW_OTHER);
453 // Help Menu
454 ac = am->createMenu(Constants::M_HELP);
455 menubar->addMenu(ac, Constants::G_HELP);
456 ac->menu()->setTitle(tr("&Help"));
457 ac->appendGroup(Constants::G_HELP_HELP);
458 ac->appendGroup(Constants::G_HELP_ABOUT);
461 static Command *createSeparator(ActionManager *am, QObject *parent, const QString &name, const QList<int> &context)
463 QAction *tmpaction = new QAction(parent);
465 tmpaction->setSeparator(true);
466 Command *cmd = am->registerAction(tmpaction, name, context);
467 return cmd;
470 void MainWindow::registerDefaultActions()
472 ActionManagerPrivate *am = m_actionManager;
473 ActionContainer *mfile = am->actionContainer(Constants::M_FILE);
474 ActionContainer *medit = am->actionContainer(Constants::M_EDIT);
475 ActionContainer *mtools = am->actionContainer(Constants::M_TOOLS);
476 ActionContainer *mwindow = am->actionContainer(Constants::M_WINDOW);
477 ActionContainer *mhelp = am->actionContainer(Constants::M_HELP);
479 // File menu separators
480 Command *cmd = createSeparator(am, this, QLatin1String("QtCreator.File.Sep.Save"), m_globalContext);
482 mfile->addAction(cmd, Constants::G_FILE_SAVE);
484 cmd = createSeparator(am, this, QLatin1String("QtCreator.File.Sep.Close"), m_globalContext);
485 mfile->addAction(cmd, Constants::G_FILE_CLOSE);
487 cmd = createSeparator(am, this, QLatin1String("QtCreator.File.Sep.Other"), m_globalContext);
488 mfile->addAction(cmd, Constants::G_FILE_OTHER);
490 // Edit menu separators
491 cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.CopyPaste"), m_globalContext);
492 medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
494 cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.SelectAll"), m_globalContext);
495 medit->addAction(cmd, Constants::G_EDIT_SELECTALL);
497 cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.Find"), m_globalContext);
498 medit->addAction(cmd, Constants::G_EDIT_FIND);
500 cmd = createSeparator(am, this, QLatin1String("QtCreator.Edit.Sep.Advanced"), m_globalContext);
501 medit->addAction(cmd, Constants::G_EDIT_ADVANCED);
503 // Tools menu separators
504 cmd = createSeparator(am, this, QLatin1String("QtCreator.Tools.Sep.Options"), m_globalContext);
505 mtools->addAction(cmd, Constants::G_DEFAULT_THREE);
507 // Help menu separators
509 // Return to editor shortcut: Note this requires Qt to fix up
510 // handling of shortcut overrides in menus, item views, combos....
511 m_focusToEditor = new QShortcut(this);
512 cmd = am->registerShortcut(m_focusToEditor, Constants::S_RETURNTOEDITOR, m_globalContext);
513 cmd->setDefaultKeySequence(QKeySequence(Qt::Key_Escape));
514 connect(m_focusToEditor, SIGNAL(activated()), this, SLOT(setFocusToEditor()));
516 // New File Action
519 m_newAction = new QAction(QIcon(Constants::ICON_NEWFILE), tr("&New File or Project..."), this);
520 cmd = am->registerAction(m_newAction, Constants::NEW, m_globalContext);
521 cmd->setDefaultKeySequence(QKeySequence::New);
522 mfile->addAction(cmd, Constants::G_FILE_NEW);
523 connect(m_newAction, SIGNAL(triggered()), this, SLOT(newFile()));
526 // Open Action
528 m_openAction = new QAction(QIcon(Constants::ICON_OPENFILE), tr("&Open File or Project..."), this);
529 cmd = am->registerAction(m_openAction, Constants::OPEN, m_globalContext);
530 cmd->setDefaultKeySequence(QKeySequence::Open);
531 mfile->addAction(cmd, Constants::G_FILE_OPEN);
532 connect(m_openAction, SIGNAL(triggered()), this, SLOT(openFile()));
535 // Open With Action
537 m_openWithAction = new QAction(tr("&Open File With..."), this);
538 cmd = am->registerAction(m_openWithAction, Constants::OPEN_WITH, m_globalContext);
539 mfile->addAction(cmd, Constants::G_FILE_OPEN);
540 connect(m_openWithAction, SIGNAL(triggered()), this, SLOT(openFileWith()));
543 // File->Recent Files Menu
545 ActionContainer *ac = am->createMenu(Constants::M_FILE_RECENTFILES);
546 mfile->addMenu(ac, Constants::G_FILE_OPEN);
547 ac->menu()->setTitle(tr("Recent Files"));
550 // Save Action
551 QAction *tmpaction = new QAction(QIcon(Constants::ICON_SAVEFILE), tr("&Save"), this);
552 cmd = am->registerAction(tmpaction, Constants::SAVE, m_globalContext);
553 cmd->setDefaultKeySequence(QKeySequence::Save);
554 cmd->setAttribute(Command::CA_UpdateText);
555 cmd->setDefaultText(tr("&Save"));
556 mfile->addAction(cmd, Constants::G_FILE_SAVE);
558 // Save As Action
559 tmpaction = new QAction(tr("Save &As..."), this);
560 cmd = am->registerAction(tmpaction, Constants::SAVEAS, m_globalContext);
561 #ifdef Q_WS_MAC
562 cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+S")));
563 #endif
564 cmd->setAttribute(Command::CA_UpdateText);
565 cmd->setDefaultText(tr("Save &As..."));
566 mfile->addAction(cmd, Constants::G_FILE_SAVE);
569 // SaveAll Action
570 m_saveAllAction = new QAction(tr("Save &GCS Default Settings"), this);
571 cmd = am->registerAction(m_saveAllAction, Constants::SAVEALL, m_globalContext);
572 #ifndef Q_WS_MAC
573 cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+S")));
574 #endif
575 mfile->addAction(cmd, Constants::G_FILE_SAVE);
576 connect(m_saveAllAction, SIGNAL(triggered()), this, SLOT(saveAll()));
578 // Exit Action
579 m_exitAction = new QAction(QIcon(Constants::ICON_EXIT), tr("E&xit"), this);
580 cmd = am->registerAction(m_exitAction, Constants::EXIT, m_globalContext);
581 cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Q")));
582 mfile->addAction(cmd, Constants::G_FILE_OTHER);
583 connect(m_exitAction, SIGNAL(triggered()), this, SLOT(exit()));
585 // Undo Action
586 QAction *tmpaction = new QAction(QIcon(Constants::ICON_UNDO), tr("&Undo"), this);
587 cmd = am->registerAction(tmpaction, Constants::UNDO, m_globalContext);
588 cmd->setDefaultKeySequence(QKeySequence::Undo);
589 cmd->setAttribute(Command::CA_UpdateText);
590 cmd->setDefaultText(tr("&Undo"));
591 medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
592 tmpaction->setEnabled(false);
594 // Redo Action
595 tmpaction = new QAction(QIcon(Constants::ICON_REDO), tr("&Redo"), this);
596 cmd = am->registerAction(tmpaction, Constants::REDO, m_globalContext);
597 cmd->setDefaultKeySequence(QKeySequence::Redo);
598 cmd->setAttribute(Command::CA_UpdateText);
599 cmd->setDefaultText(tr("&Redo"));
600 medit->addAction(cmd, Constants::G_EDIT_UNDOREDO);
601 tmpaction->setEnabled(false);
603 // Cut Action
604 tmpaction = new QAction(QIcon(Constants::ICON_CUT), tr("Cu&t"), this);
605 cmd = am->registerAction(tmpaction, Constants::CUT, m_globalContext);
606 cmd->setDefaultKeySequence(QKeySequence::Cut);
607 medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
608 tmpaction->setEnabled(false);
610 // Copy Action
611 tmpaction = new QAction(QIcon(Constants::ICON_COPY), tr("&Copy"), this);
612 cmd = am->registerAction(tmpaction, Constants::COPY, m_globalContext);
613 cmd->setDefaultKeySequence(QKeySequence::Copy);
614 medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
615 tmpaction->setEnabled(false);
617 // Paste Action
618 tmpaction = new QAction(QIcon(Constants::ICON_PASTE), tr("&Paste"), this);
619 cmd = am->registerAction(tmpaction, Constants::PASTE, m_globalContext);
620 cmd->setDefaultKeySequence(QKeySequence::Paste);
621 medit->addAction(cmd, Constants::G_EDIT_COPYPASTE);
622 tmpaction->setEnabled(false);
624 // Select All
625 tmpaction = new QAction(tr("&Select All"), this);
626 cmd = am->registerAction(tmpaction, Constants::SELECTALL, m_globalContext);
627 cmd->setDefaultKeySequence(QKeySequence::SelectAll);
628 medit->addAction(cmd, Constants::G_EDIT_SELECTALL);
629 tmpaction->setEnabled(false);
631 // Options Action
632 m_optionsAction = new QAction(QIcon(Constants::ICON_OPTIONS), tr("&Options..."), this);
633 cmd = am->registerAction(m_optionsAction, Constants::OPTIONS, m_globalContext);
634 #ifdef Q_WS_MAC
635 cmd->setDefaultKeySequence(QKeySequence("Ctrl+,"));
636 cmd->action()->setMenuRole(QAction::PreferencesRole);
637 #endif
638 mtools->addAction(cmd, Constants::G_DEFAULT_THREE);
639 connect(m_optionsAction, SIGNAL(triggered()), this, SLOT(showOptionsDialog()));
641 #ifdef Q_WS_MAC
642 // Minimize Action
643 m_minimizeAction = new QAction(tr("Minimize"), this);
644 cmd = am->registerAction(m_minimizeAction, Constants::MINIMIZE_WINDOW, m_globalContext);
645 cmd->setDefaultKeySequence(QKeySequence("Ctrl+M"));
646 mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
647 connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(showMinimized()));
649 // Zoom Action
650 m_zoomAction = new QAction(tr("Zoom"), this);
651 cmd = am->registerAction(m_zoomAction, Constants::ZOOM_WINDOW, m_globalContext);
652 mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
653 connect(m_zoomAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
655 // Window separator
656 cmd = createSeparator(am, this, QLatin1String("QtCreator.Window.Sep.Size"), m_globalContext);
657 mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
658 #endif
660 #ifndef Q_WS_MAC
661 // Full Screen Action
662 m_toggleFullScreenAction = new QAction(tr("Full Screen"), this);
663 m_toggleFullScreenAction->setCheckable(true);
664 cmd = am->registerAction(m_toggleFullScreenAction, Constants::TOGGLE_FULLSCREEN, m_globalContext);
665 cmd->setDefaultKeySequence(QKeySequence("Ctrl+Shift+F11"));
666 mwindow->addAction(cmd, Constants::G_WINDOW_SIZE);
667 connect(m_toggleFullScreenAction, SIGNAL(triggered(bool)), this, SLOT(setFullScreen(bool)));
668 #endif
671 * UavGadgetManager Actions
673 const QList<int> uavGadgetManagerContext =
674 QList<int>() << CoreImpl::instance()->uniqueIDManager()->uniqueIdentifier(Constants::C_UAVGADGETMANAGER);
675 // Window menu separators
676 QAction *tmpaction1 = new QAction(this);
677 tmpaction1->setSeparator(true);
678 cmd = am->registerAction(tmpaction1, QLatin1String("OpenPilot.Window.Sep.Split"), uavGadgetManagerContext);
679 mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
681 m_showToolbarsAction = new QAction(tr("Edit Gadgets Mode"), this);
682 m_showToolbarsAction->setCheckable(true);
683 cmd = am->registerAction(m_showToolbarsAction, Constants::HIDE_TOOLBARS, uavGadgetManagerContext);
684 cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F10")));
685 mwindow->addAction(cmd, Constants::G_WINDOW_HIDE_TOOLBAR);
687 // Window menu separators
688 QAction *tmpaction2 = new QAction(this);
689 tmpaction2->setSeparator(true);
690 cmd = am->registerAction(tmpaction2, QLatin1String("OpenPilot.Window.Sep.Split2"), uavGadgetManagerContext);
691 mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
693 #ifdef Q_WS_MAC
694 QString prefix = tr("Meta+Shift");
695 #else
696 QString prefix = tr("Ctrl+Shift");
697 #endif
699 m_splitAction = new QAction(tr("Split"), this);
700 cmd = am->registerAction(m_splitAction, Constants::SPLIT, uavGadgetManagerContext);
701 cmd->setDefaultKeySequence(QKeySequence(tr("%1+Down").arg(prefix)));
702 mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
704 m_splitSideBySideAction = new QAction(tr("Split Side by Side"), this);
705 cmd = am->registerAction(m_splitSideBySideAction, Constants::SPLIT_SIDE_BY_SIDE, uavGadgetManagerContext);
706 cmd->setDefaultKeySequence(QKeySequence(tr("%1+Right").arg(prefix)));
707 mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
709 m_removeCurrentSplitAction = new QAction(tr("Close Current View"), this);
710 cmd = am->registerAction(m_removeCurrentSplitAction, Constants::REMOVE_CURRENT_SPLIT, uavGadgetManagerContext);
711 cmd->setDefaultKeySequence(QKeySequence(tr("%1+C").arg(prefix)));
712 mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
714 m_removeAllSplitsAction = new QAction(tr("Close All Other Views"), this);
715 cmd = am->registerAction(m_removeAllSplitsAction, Constants::REMOVE_ALL_SPLITS, uavGadgetManagerContext);
716 cmd->setDefaultKeySequence(QKeySequence(tr("%1+A").arg(prefix)));
717 mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
719 m_gotoOtherSplitAction = new QAction(tr("Goto Next View"), this);
720 cmd = am->registerAction(m_gotoOtherSplitAction, Constants::GOTO_OTHER_SPLIT, uavGadgetManagerContext);
721 cmd->setDefaultKeySequence(QKeySequence(tr("%1+N").arg(prefix)));
722 mwindow->addAction(cmd, Constants::G_WINDOW_SPLIT);
724 // Help Action
725 tmpaction = new QAction(QIcon(Constants::ICON_HELP), tr("&Help..."), this);
726 cmd = am->registerAction(tmpaction, Constants::G_HELP_HELP, m_globalContext);
727 mhelp->addAction(cmd, Constants::G_HELP_HELP);
728 tmpaction->setEnabled(true);
729 connect(tmpaction, SIGNAL(triggered()), this, SLOT(showHelp()));
731 // About GCS Action
732 // Mac doesn't have the "About" actions in the Help menu
733 #ifndef Q_WS_MAC
734 tmpaction = new QAction(this);
735 tmpaction->setSeparator(true);
736 cmd = am->registerAction(tmpaction, QLatin1String("QtCreator.Help.Sep.About"), m_globalContext);
737 mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
738 #endif
740 // About Plugins Action
741 tmpaction = new QAction(QIcon(Constants::ICON_PLUGIN), tr("About &Plugins..."), this);
742 cmd = am->registerAction(tmpaction, Constants::ABOUT_PLUGINS, m_globalContext);
743 mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
744 tmpaction->setEnabled(true);
745 #ifdef Q_WS_MAC
746 cmd->action()->setMenuRole(QAction::ApplicationSpecificRole);
747 #endif
748 connect(tmpaction, SIGNAL(triggered()), this, SLOT(aboutPlugins()));
750 // Credits Action
751 tmpaction = new QAction(QIcon(Constants::ICON_PLUGIN), tr("About &%1...").arg(ORG_BIG_NAME), this);
752 cmd = am->registerAction(tmpaction, Constants::ABOUT_AUTHORS, m_globalContext);
753 mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
754 tmpaction->setEnabled(true);
755 #ifdef Q_WS_MAC
756 cmd->action()->setMenuRole(QAction::ApplicationSpecificRole);
757 #endif
758 connect(tmpaction, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
761 void MainWindow::newFile()
764 void MainWindow::openFile()
767 void MainWindow::setFocusToEditor()
770 bool MainWindow::showOptionsDialog(const QString &category, const QString &page, QWidget *parent)
772 emit m_coreImpl->optionsDialogRequested();
774 if (!parent) {
775 parent = this;
777 SettingsDialog dlg(parent, category, page);
778 return dlg.execDialog();
781 void MainWindow::saveAll()
783 if (m_dontSaveSettings) {
784 return;
787 emit m_coreImpl->saveSettingsRequested();
788 saveSettings(); // OpenPilot-specific.
791 void MainWindow::exit()
793 // this function is most likely called from a user action
794 // that is from an event handler of an object
795 // since on close we are going to delete everything
796 // so to prevent the deleting of that object we
797 // just append it
798 QTimer::singleShot(0, this, SLOT(close()));
801 void MainWindow::openFileWith()
804 void MainWindow::applyTabBarSettings(QTabWidget::TabPosition pos, bool movable)
806 if (m_modeStack->tabPosition() != pos) {
807 m_modeStack->setTabPosition(pos);
809 m_modeStack->setMovable(movable);
812 void MainWindow::showHelp()
814 QDesktopServices::openUrl(QUrl(Constants::GCS_HELP, QUrl::StrictMode));
817 ActionManager *MainWindow::actionManager() const
819 return m_actionManager;
822 UniqueIDManager *MainWindow::uniqueIDManager() const
824 return m_uniqueIDManager;
827 MessageManager *MainWindow::messageManager() const
829 return m_messageManager;
832 QSettings *MainWindow::settings(QSettings::Scope scope) const
834 if (scope == QSettings::UserScope) {
835 return m_settings;
836 } else {
837 return m_globalSettings;
841 VariableManager *MainWindow::variableManager() const
843 return m_variableManager;
846 ThreadManager *MainWindow::threadManager() const
848 return m_threadManager;
851 ConnectionManager *MainWindow::connectionManager() const
853 return m_connectionManager;
856 QList<UAVGadgetManager *> MainWindow::uavGadgetManagers() const
858 return m_uavGadgetManagers;
861 UAVGadgetInstanceManager *MainWindow::uavGadgetInstanceManager() const
863 return m_uavGadgetInstanceManager;
867 ModeManager *MainWindow::modeManager() const
869 return m_modeManager;
872 MimeDatabase *MainWindow::mimeDatabase() const
874 return m_mimeDatabase;
877 GeneralSettings *MainWindow::generalSettings() const
879 return m_generalSettings;
882 IContext *MainWindow::contextObject(QWidget *widget)
884 return m_contextWidgets.value(widget);
887 void MainWindow::addContextObject(IContext *context)
889 if (!context) {
890 return;
892 QWidget *widget = context->widget();
893 if (m_contextWidgets.contains(widget)) {
894 return;
897 m_contextWidgets.insert(widget, context);
900 void MainWindow::removeContextObject(IContext *context)
902 if (!context) {
903 return;
906 QWidget *widget = context->widget();
907 if (!m_contextWidgets.contains(widget)) {
908 return;
911 m_contextWidgets.remove(widget);
912 if (m_activeContext == context) {
913 updateContextObject(0);
917 void MainWindow::changeEvent(QEvent *e)
919 QMainWindow::changeEvent(e);
921 if (e->type() == QEvent::ActivationChange) {
922 if (isActiveWindow()) {
923 if (debugMainWindow) {
924 qDebug() << "main window activated";
926 emit windowActivated();
928 } else if (e->type() == QEvent::WindowStateChange) {
929 #ifdef Q_WS_MAC
930 bool minimized = isMinimized();
931 if (debugMainWindow) {
932 qDebug() << "main window state changed to minimized=" << minimized;
934 m_minimizeAction->setEnabled(!minimized);
935 m_zoomAction->setEnabled(!minimized);
936 #else
937 bool isFullScreen = (windowState() & Qt::WindowFullScreen) != 0;
938 m_toggleFullScreenAction->setChecked(isFullScreen);
939 #endif
943 void MainWindow::updateFocusWidget(QWidget *old, QWidget *now)
945 Q_UNUSED(old)
947 // Prevent changing the context object just because the menu is activated
948 if (qobject_cast<QMenuBar *>(now)) {
949 return;
952 IContext *newContext = 0;
953 if (focusWidget()) {
954 IContext *context = 0;
955 QWidget *p = focusWidget();
956 while (p) {
957 context = m_contextWidgets.value(p);
958 if (context) {
959 newContext = context;
960 break;
962 p = p->parentWidget();
965 updateContextObject(newContext);
968 void MainWindow::updateContextObject(IContext *context)
970 if (context == m_activeContext) {
971 return;
973 IContext *oldContext = m_activeContext;
974 m_activeContext = context;
975 if (!context || oldContext != m_activeContext) {
976 emit m_coreImpl->contextAboutToChange(context);
977 updateContext();
978 if (debugMainWindow) {
979 qDebug() << "new context object =" << context << (context ? context->widget() : 0)
980 << (context ? context->widget()->metaObject()->className() : 0);
982 emit m_coreImpl->contextChanged(context);
986 void MainWindow::resetContext()
988 updateContextObject(0);
991 void MainWindow::shutdown()
993 disconnect(QApplication::instance(), SIGNAL(focusChanged(QWidget *, QWidget *)),
994 this, SLOT(updateFocusWidget(QWidget *, QWidget *)));
995 m_activeContext = 0;
997 // We have to remove all the existing gagdets at his point, not
998 // later!
999 uavGadgetInstanceManager()->removeAllGadgets();
1002 /* Enable/disable menus for uavgadgets */
1003 void MainWindow::showUavGadgetMenus(bool show, bool hasSplitter)
1005 m_showToolbarsAction->setChecked(show);
1006 m_splitAction->setEnabled(show);
1007 m_splitSideBySideAction->setEnabled(show);
1008 m_removeCurrentSplitAction->setEnabled(show && hasSplitter);
1009 m_removeAllSplitsAction->setEnabled(show && hasSplitter);
1010 m_gotoOtherSplitAction->setEnabled(show && hasSplitter);
1013 inline int takeLeastPriorityUavGadgetManager(const QList<Core::UAVGadgetManager *> m_uavGadgetManagers)
1015 int index = 0;
1016 int prio = m_uavGadgetManagers.at(0)->priority();
1018 for (int i = 0; i < m_uavGadgetManagers.count(); i++) {
1019 int prio2 = m_uavGadgetManagers.at(i)->priority();
1020 if (prio2 < prio) {
1021 prio = prio2;
1022 index = i;
1025 return index;
1028 void MainWindow::createWorkspaces(QSettings *qs, bool diffOnly)
1030 ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
1032 Core::UAVGadgetManager *uavGadgetManager;
1034 // If diffOnly is true, we only add/remove the number of workspaces
1035 // that has changed,
1036 // otherwise a complete reload of workspaces is done
1037 int toRemoveFirst = m_uavGadgetManagers.count();
1038 int newWorkspacesNo = m_workspaceSettings->numberOfWorkspaces();
1040 if (diffOnly && m_uavGadgetManagers.count() > newWorkspacesNo) {
1041 toRemoveFirst = m_uavGadgetManagers.count() - newWorkspacesNo;
1042 } else {
1043 toRemoveFirst = 0;
1046 int removed = 0;
1048 while (!m_uavGadgetManagers.isEmpty() && (toRemoveFirst > removed)) {
1049 int index = takeLeastPriorityUavGadgetManager(m_uavGadgetManagers);
1050 uavGadgetManager = m_uavGadgetManagers.takeAt(index);
1051 uavGadgetManager->removeAllSplits();
1052 pm->removeObject(uavGadgetManager);
1053 delete uavGadgetManager;
1054 removed++;
1057 int start = 0;
1058 if (diffOnly) {
1059 start = m_uavGadgetManagers.count();
1060 } else {
1061 m_uavGadgetManagers.clear();
1064 QElapsedTimer totalTimer;
1065 totalTimer.start();
1066 for (int i = start; i < newWorkspacesNo; ++i) {
1067 QElapsedTimer timer;
1068 timer.start();
1070 const QString name = m_workspaceSettings->name(i);
1071 const QString iconName = m_workspaceSettings->iconName(i);
1072 const QString modeName = m_workspaceSettings->modeName(i);
1073 uavGadgetManager = new Core::UAVGadgetManager(CoreImpl::instance(), name, QIcon(iconName), 90 - i + 1, modeName,
1074 this);
1076 connect(uavGadgetManager, SIGNAL(showUavGadgetMenus(bool, bool)), this, SLOT(showUavGadgetMenus(bool, bool)));
1078 connect(m_showToolbarsAction, SIGNAL(triggered(bool)), uavGadgetManager, SLOT(showToolbars(bool)));
1079 connect(m_splitAction, SIGNAL(triggered()), uavGadgetManager, SLOT(split()));
1080 connect(m_splitSideBySideAction, SIGNAL(triggered()), uavGadgetManager, SLOT(splitSideBySide()));
1081 connect(m_removeCurrentSplitAction, SIGNAL(triggered()), uavGadgetManager, SLOT(removeCurrentSplit()));
1082 connect(m_removeAllSplitsAction, SIGNAL(triggered()), uavGadgetManager, SLOT(removeAllSplits()));
1083 connect(m_gotoOtherSplitAction, SIGNAL(triggered()), uavGadgetManager, SLOT(gotoOtherSplit()));
1085 pm->addObject(uavGadgetManager);
1086 m_uavGadgetManagers.append(uavGadgetManager);
1087 uavGadgetManager->readSettings(qs);
1088 qDebug() << "MainWindow::createWorkspaces - creating workspace" << name << "took" << timer.elapsed() << "ms";
1090 qDebug() << "MainWindow::createWorkspaces - creating workspaces took" << totalTimer.elapsed() << "ms";
1093 static const char *settingsGroup = "MainWindow";
1094 static const char *geometryKey = "Geometry";
1095 static const char *colorKey = "Color";
1096 static const char *maxKey = "Maximized";
1097 static const char *fullScreenKey = "FullScreen";
1098 static const char *modePriorities = "ModePriorities";
1100 void MainWindow::readSettings(QSettings *qs, bool workspaceDiffOnly)
1102 if (!qs) {
1103 qs = m_settings;
1106 if (workspaceDiffOnly) {
1107 createWorkspaces(qs, workspaceDiffOnly);
1108 return;
1111 m_generalSettings->readSettings(qs);
1112 m_actionManager->readSettings(qs);
1114 qs->beginGroup(QLatin1String(settingsGroup));
1116 Utils::StyleHelper::setBaseColor(qs->value(QLatin1String(colorKey)).value<QColor>());
1118 const QVariant geom = qs->value(QLatin1String(geometryKey));
1119 if (geom.isValid()) {
1120 setGeometry(geom.toRect());
1121 } else {
1122 resize(750, 400);
1124 if (qs->value(QLatin1String(maxKey), false).toBool()) {
1125 setWindowState(Qt::WindowMaximized);
1127 setFullScreen(qs->value(QLatin1String(fullScreenKey), false).toBool());
1129 qs->endGroup();
1131 m_workspaceSettings->readSettings(qs);
1133 createWorkspaces(qs);
1135 // Restore tab ordering
1136 qs->beginGroup(QLatin1String(modePriorities));
1138 QStringList modeNames = qs->childKeys();
1139 QMap<QString, int> map;
1140 foreach(QString modeName, modeNames) {
1141 map.insert(modeName, qs->value(modeName).toInt());
1143 m_modeManager->reorderModes(map);
1145 qs->endGroup();
1147 // Restore selected tab
1148 if (m_workspaceSettings->restoreSelectedOnStartup()) {
1149 int index = qs->value(QLatin1String("SelectedWorkspace")).toInt();
1150 m_modeStack->setCurrentIndex(index);
1155 void MainWindow::saveSettings(QSettings *qs)
1157 if (m_dontSaveSettings) {
1158 return;
1161 if (!qs) {
1162 qs = m_settings;
1165 m_workspaceSettings->saveSettings(qs);
1167 qs->beginGroup(QLatin1String(settingsGroup));
1169 qs->setValue(QLatin1String(colorKey), Utils::StyleHelper::baseColor());
1171 if (windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) {
1172 qs->setValue(QLatin1String(maxKey), (bool)(windowState() & Qt::WindowMaximized));
1173 qs->setValue(QLatin1String(fullScreenKey), (bool)(windowState() & Qt::WindowFullScreen));
1174 } else {
1175 qs->setValue(QLatin1String(maxKey), false);
1176 qs->setValue(QLatin1String(fullScreenKey), false);
1177 qs->setValue(QLatin1String(geometryKey), geometry());
1180 qs->endGroup();
1182 // Write tab ordering
1183 qs->beginGroup(QLatin1String(modePriorities));
1184 QVector<IMode *> modes = m_modeManager->modes();
1185 foreach(IMode * mode, modes) {
1186 qs->setValue(QLatin1String(mode->uniqueModeName()), mode->priority());
1188 qs->endGroup();
1190 // Write selected tab
1191 qs->setValue(QLatin1String("SelectedWorkspace"), m_modeStack->currentIndex());
1193 foreach(UAVGadgetManager * manager, m_uavGadgetManagers) {
1194 manager->saveSettings(qs);
1197 m_actionManager->saveSettings(qs);
1198 m_generalSettings->saveSettings(qs);
1200 qs->beginGroup("General");
1201 qs->setValue("Description", m_config_description);
1202 qs->setValue("Details", m_config_details);
1203 qs->setValue("StyleSheet", m_config_stylesheet);
1204 qs->endGroup();
1207 void MainWindow::readSettings(IConfigurablePlugin *plugin, QSettings *qs)
1209 if (!qs) {
1210 qs = m_settings;
1213 UAVConfigInfo configInfo;
1214 QObject *qo = reinterpret_cast<QObject *>(plugin);
1215 QString configName = qo->metaObject()->className();
1217 qs->beginGroup("Plugins");
1218 qs->beginGroup(configName);
1219 configInfo.read(qs);
1220 configInfo.setNameOfConfigurable("Plugin-" + configName);
1221 qs->beginGroup("data");
1222 plugin->readConfig(qs, &configInfo);
1224 qs->endGroup();
1225 qs->endGroup();
1226 qs->endGroup();
1229 void MainWindow::saveSettings(IConfigurablePlugin *plugin, QSettings *qs)
1231 if (m_dontSaveSettings) {
1232 return;
1235 if (!qs) {
1236 qs = m_settings;
1239 UAVConfigInfo configInfo;
1240 QString configName = plugin->metaObject()->className();
1242 qs->beginGroup("Plugins");
1243 qs->beginGroup(configName);
1244 qs->beginGroup("data");
1245 plugin->saveConfig(qs, &configInfo);
1246 qs->endGroup();
1247 configInfo.save(qs);
1248 qs->endGroup();
1249 qs->endGroup();
1252 void MainWindow::deleteSettings()
1254 m_settings->clear();
1255 m_settings->sync();
1256 m_dontSaveSettings = true;
1259 void MainWindow::addAdditionalContext(int context)
1261 if (context == 0) {
1262 return;
1265 if (!m_additionalContexts.contains(context)) {
1266 m_additionalContexts.prepend(context);
1270 void MainWindow::removeAdditionalContext(int context)
1272 if (context == 0) {
1273 return;
1276 int index = m_additionalContexts.indexOf(context);
1277 if (index != -1) {
1278 m_additionalContexts.removeAt(index);
1282 bool MainWindow::hasContext(int context) const
1284 return m_actionManager->hasContext(context);
1287 void MainWindow::updateContext()
1289 QList<int> contexts;
1291 if (m_activeContext) {
1292 contexts += m_activeContext->context();
1295 contexts += m_additionalContexts;
1297 QList<int> uniquecontexts;
1298 for (int i = 0; i < contexts.size(); ++i) {
1299 const int c = contexts.at(i);
1300 if (!uniquecontexts.contains(c)) {
1301 uniquecontexts << c;
1305 m_actionManager->setContext(uniquecontexts);
1308 void MainWindow::aboutToShowRecentFiles()
1310 ActionContainer *aci =
1311 m_actionManager->actionContainer(Constants::M_FILE_RECENTFILES);
1313 if (aci) {
1314 aci->menu()->clear();
1316 bool hasRecentFiles = false;
1318 aci->menu()->setEnabled(hasRecentFiles);
1322 void MainWindow::openRecentFile()
1324 QAction *action = qobject_cast<QAction *>(sender());
1326 if (!action) {
1327 return;
1329 QString fileName = action->data().toString();
1330 if (!fileName.isEmpty()) {}
1333 void MainWindow::showAboutDialog()
1335 if (!m_aboutDialog) {
1336 m_aboutDialog = new AboutDialog(this);
1337 connect(m_aboutDialog, SIGNAL(finished(int)),
1338 this, SLOT(destroyAboutDialog()));
1340 m_aboutDialog->show();
1343 void MainWindow::destroyAboutDialog()
1345 if (m_aboutDialog) {
1346 m_aboutDialog->deleteLater();
1347 m_aboutDialog = 0;
1351 void MainWindow::aboutPlugins()
1353 PluginDialog dialog(this);
1355 dialog.exec();
1358 void MainWindow::setFullScreen(bool on)
1360 if (bool(windowState() & Qt::WindowFullScreen) == on) {
1361 return;
1364 if (on) {
1365 setWindowState(windowState() | Qt::WindowFullScreen);
1366 } else {
1367 setWindowState(windowState() & ~Qt::WindowFullScreen);
1371 // Display a warning with an additional button to open
1372 // the debugger settings dialog if settingsId is nonempty.
1374 bool MainWindow::showWarningWithOptions(const QString &title,
1375 const QString &text,
1376 const QString &details,
1377 const QString &settingsCategory,
1378 const QString &settingsId,
1379 QWidget *parent)
1381 if (parent == 0) {
1382 parent = this;
1384 QMessageBox msgBox(QMessageBox::Warning, title, text,
1385 QMessageBox::Ok, parent);
1386 if (details.isEmpty()) {
1387 msgBox.setDetailedText(details);
1389 QAbstractButton *settingsButton = 0;
1390 if (!settingsId.isEmpty() || !settingsCategory.isEmpty()) {
1391 settingsButton = msgBox.addButton(tr("Settings..."), QMessageBox::AcceptRole);
1393 msgBox.exec();
1394 if (settingsButton && msgBox.clickedButton() == settingsButton) {
1395 return showOptionsDialog(settingsCategory, settingsId);
1397 return false;