debuggermainwindow.cpp 25.7 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30

#include "debuggermainwindow.h"
hjk's avatar
hjk committed
31
#include "debuggercore.h"
32
#include "debuggerengine.h"
33
#include "debuggerrunconfigurationaspect.h"
34

35
#include <utils/appmainwindow.h>
36 37 38 39 40 41 42 43 44 45 46 47 48 49
#include <utils/styledbar.h>
#include <utils/qtcassert.h>

#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/imode.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/icore.h>
#include <coreplugin/navigationwidget.h>
#include <coreplugin/outputpane.h>
#include <coreplugin/rightpane.h>

hjk's avatar
hjk committed
50
#include <projectexplorer/project.h>
51
#include <projectexplorer/projectexplorer.h>
hjk's avatar
hjk committed
52
#include <projectexplorer/runconfiguration.h>
53 54 55
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>

56
#include <QDebug>
57

58 59
#include <QDockWidget>
#include <QVBoxLayout>
hjk's avatar
hjk committed
60
#include <QToolButton>
61 62

using namespace Core;
63
using namespace ProjectExplorer;
64
using namespace Debugger::Constants;
65 66 67 68 69 70 71

namespace Debugger {
namespace Internal {

class DockWidgetEventFilter : public QObject
{
public:
hjk's avatar
hjk committed
72 73
    DockWidgetEventFilter(DebuggerMainWindowPrivate *mw) : m_mw(mw) {}
private:
74
    virtual bool eventFilter(QObject *obj, QEvent *event);
hjk's avatar
hjk committed
75
    DebuggerMainWindowPrivate *m_mw;
76 77
};

78
class DebuggerMainWindowPrivate : public QObject
79
{
80 81
    Q_OBJECT

82 83 84
public:
    explicit DebuggerMainWindowPrivate(DebuggerMainWindow *mainWindow);

85 86 87 88 89
    void activateQmlCppLayout();
    void activateCppLayout();
    void createViewsMenuItems();
    bool isQmlCppActive() const;
    bool isQmlActive() const;
90
    void setSimpleDockWidgetArrangement();
hjk's avatar
hjk committed
91
    // Debuggable languages are registered with this function.
92
    void addLanguage(DebuggerLanguage language, const Core::Context &context);
hjk's avatar
hjk committed
93

94 95 96 97 98 99 100

public slots:
    void resetDebuggerLayout();
    void updateUiForProject(ProjectExplorer::Project *project);
    void updateUiForTarget(ProjectExplorer::Target *target);
    void updateUiForRunConfiguration(ProjectExplorer::RunConfiguration *rc);
    void updateUiForCurrentRunConfiguration();
hjk's avatar
hjk committed
101 102 103
    void updateActiveLanguages();
    void updateDockWidgetSettings();
    void openMemoryEditor() { debuggerCore()->openMemoryEditor(); }
104

105 106 107 108 109
public:
    DebuggerMainWindow *q;

    QHash<QString, QVariant> m_dockWidgetActiveStateCpp;
    QHash<QString, QVariant> m_dockWidgetActiveStateQmlCpp;
hjk's avatar
hjk committed
110
    DockWidgetEventFilter m_resizeEventFilter;
111 112 113 114 115

    QMap<DebuggerLanguage, QWidget *> m_toolBars;

    DebuggerLanguages m_supportedLanguages;

116
    QWidget *m_debugToolBar;
hjk's avatar
hjk committed
117
    QToolButton *m_viewButton;
118
    QHBoxLayout *m_debugToolBarLayout;
119 120 121 122 123 124 125 126

    QHash<DebuggerLanguage, Context> m_contextsForLanguage;

    bool m_inDebugMode;
    bool m_changingUI;

    DebuggerLanguages m_previousDebugLanguages;
    DebuggerLanguages m_activeDebugLanguages;
127
    DebuggerLanguages m_engineDebugLanguages;
128 129

    ActionContainer *m_viewsMenu;
130
    QList<Command *> m_menuCommandsToAdd;
131

132 133 134
    Project *m_previousProject;
    Target *m_previousTarget;
    RunConfiguration *m_previousRunConfiguration;
135 136

    DebuggerEngine *m_engine;
137 138 139 140
};

DebuggerMainWindowPrivate::DebuggerMainWindowPrivate(DebuggerMainWindow *mw)
    : q(mw)
hjk's avatar
hjk committed
141
    , m_resizeEventFilter(this)
142
    , m_supportedLanguages(AnyLanguage)
143 144
    , m_debugToolBar(new QWidget)
    , m_debugToolBarLayout(new QHBoxLayout(m_debugToolBar))
145 146 147 148
    , m_inDebugMode(false)
    , m_changingUI(false)
    , m_previousDebugLanguages(AnyLanguage)
    , m_activeDebugLanguages(AnyLanguage)
149
    , m_engineDebugLanguages(AnyLanguage)
150
    , m_viewsMenu(0)
151 152 153
    , m_previousProject(0)
    , m_previousTarget(0)
    , m_previousRunConfiguration(0)
154
    , m_engine(0)
hjk's avatar
hjk committed
155
{
156 157
    m_debugToolBarLayout->setMargin(0);
    m_debugToolBarLayout->setSpacing(0);
hjk's avatar
hjk committed
158
    createViewsMenuItems();
159
    addLanguage(AnyLanguage, Context());
hjk's avatar
hjk committed
160 161 162
    addLanguage(CppLanguage, Context(C_CPPDEBUGGER));
    addLanguage(QmlLanguage, Context(C_QMLDEBUGGER));
}
163

164
void DebuggerMainWindowPrivate::updateUiForProject(Project *project)
165
{
166
    if (m_previousProject) {
167
        disconnect(m_previousProject,
168 169 170
            SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
            this, SLOT(updateUiForTarget(ProjectExplorer::Target*)));
    }
171
    m_previousProject = project;
172 173 174 175
    if (!project) {
        updateUiForTarget(0);
        return;
    }
176 177 178 179 180
    connect(project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
        SLOT(updateUiForTarget(ProjectExplorer::Target*)));
    updateUiForTarget(project->activeTarget());
}

181
void DebuggerMainWindowPrivate::updateUiForTarget(Target *target)
182
{
183
    if (m_previousTarget) {
184
         disconnect(m_previousTarget,
185 186 187
            SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
            this, SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
    }
188

189
    m_previousTarget = target;
190 191 192 193 194 195

    if (!target) {
        updateUiForRunConfiguration(0);
        return;
    }

196 197 198 199 200 201 202
    connect(target,
        SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
        SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
    updateUiForRunConfiguration(target->activeRunConfiguration());
}

// updates default debug language settings per run config.
203
void DebuggerMainWindowPrivate::updateUiForRunConfiguration(RunConfiguration *rc)
204
{
205
    if (m_previousRunConfiguration)
206
        disconnect(m_previousRunConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>(),
207
                   SIGNAL(requestRunActionsUpdate()),
208
                   this, SLOT(updateUiForCurrentRunConfiguration()));
209
    m_previousRunConfiguration = rc;
210 211 212
    updateUiForCurrentRunConfiguration();
    if (!rc)
        return;
213
    connect(m_previousRunConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>(),
214
            SIGNAL(requestRunActionsUpdate()),
215 216
            SLOT(updateUiForCurrentRunConfiguration()));
}
217

218 219
void DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration()
{
hjk's avatar
hjk committed
220 221 222 223 224 225 226
    updateActiveLanguages();
}

void DebuggerMainWindowPrivate::updateActiveLanguages()
{
    DebuggerLanguages newLanguages = AnyLanguage;

227
    if (m_engineDebugLanguages != AnyLanguage) {
228
        newLanguages = m_engineDebugLanguages;
229 230 231 232 233
    } else if (m_previousRunConfiguration) {
        if (m_previousRunConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useCppDebugger())
            newLanguages |= CppLanguage;
        if (m_previousRunConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>()->useQmlDebugger())
            newLanguages |= QmlLanguage;
hjk's avatar
hjk committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
    }

    if (newLanguages != m_activeDebugLanguages) {
        m_activeDebugLanguages = newLanguages;
        debuggerCore()->languagesChanged();
    }

    if (m_changingUI || !m_inDebugMode)
        return;

    m_changingUI = true;

    if (isQmlActive())
        activateQmlCppLayout();
    else
        activateCppLayout();

    m_previousDebugLanguages = m_activeDebugLanguages;

    m_changingUI = false;
254 255
}

256 257 258 259 260
} // namespace Internal

using namespace Internal;

DebuggerMainWindow::DebuggerMainWindow()
261
{
262
    d = new DebuggerMainWindowPrivate(this);
263 264 265 266 267
}

DebuggerMainWindow::~DebuggerMainWindow()
{
    delete d;
268 269
}

270 271 272
void DebuggerMainWindow::setCurrentEngine(DebuggerEngine *engine)
{
    if (d->m_engine)
273
        disconnect(d->m_engine, SIGNAL(raiseWindow()), ICore::appMainWindow(), SLOT(raiseWindow()));
274 275
    d->m_engine = engine;
    if (d->m_engine)
276
        connect(d->m_engine, SIGNAL(raiseWindow()), ICore::appMainWindow(), SLOT(raiseWindow()));
277 278
}

279 280 281 282 283
DebuggerLanguages DebuggerMainWindow::activeDebugLanguages() const
{
    return d->m_activeDebugLanguages;
}

284 285 286 287 288 289 290 291 292
void DebuggerMainWindow::setEngineDebugLanguages(DebuggerLanguages languages)
{
    if (d->m_engineDebugLanguages == languages)
        return;

    d->m_engineDebugLanguages = languages;
    d->updateActiveLanguages();
}

293 294
void DebuggerMainWindow::onModeChanged(IMode *mode)
{
295
    d->m_inDebugMode = (mode && mode->id() == Constants::MODE_DEBUG);
296 297 298
    setDockActionsVisible(d->m_inDebugMode);

    // Hide all the debugger windows if mode is different.
299
    if (d->m_inDebugMode) {
hjk's avatar
hjk committed
300 301 302 303
        readSettings();
        d->updateActiveLanguages();
    } else {
        // Hide dock widgets manually in case they are floating.
304
        foreach (QDockWidget *dockWidget, dockWidgets()) {
hjk's avatar
hjk committed
305 306 307
            if (dockWidget->isFloating())
                dockWidget->hide();
        }
308 309 310
    }
}

311
void DebuggerMainWindowPrivate::createViewsMenuItems()
312
{
Friedemann Kleint's avatar
Friedemann Kleint committed
313
    Context debugcontext(Constants::C_DEBUGMODE);
Eike Ziller's avatar
Eike Ziller committed
314
    m_viewsMenu = Core::ActionManager::actionContainer(Id(Core::Constants::M_WINDOW_VIEWS));
315
    QTC_ASSERT(m_viewsMenu, return);
316

317 318 319
    QAction *openMemoryEditorAction = new QAction(this);
    openMemoryEditorAction->setText(tr("Memory..."));
    connect(openMemoryEditorAction, SIGNAL(triggered()),
hjk's avatar
hjk committed
320
       SLOT(openMemoryEditor()));
321 322 323

    // Add menu items
    Command *cmd = 0;
Eike Ziller's avatar
Eike Ziller committed
324
    cmd = Core::ActionManager::registerAction(openMemoryEditorAction,
325
        Core::Id("Debugger.Views.OpenMemoryEditor"),
326 327
        debugcontext);
    cmd->setAttribute(Command::CA_Hide);
328 329
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);

Eike Ziller's avatar
Eike Ziller committed
330
    cmd = Core::ActionManager::registerAction(q->menuSeparator1(),
331 332 333
        Core::Id("Debugger.Views.Separator1"), debugcontext);
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
Eike Ziller's avatar
Eike Ziller committed
334
    cmd = Core::ActionManager::registerAction(q->toggleLockedAction(),
335 336 337
        Core::Id("Debugger.Views.ToggleLocked"), debugcontext);
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
Eike Ziller's avatar
Eike Ziller committed
338
    cmd = Core::ActionManager::registerAction(q->menuSeparator2(),
339 340 341
        Core::Id("Debugger.Views.Separator2"), debugcontext);
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
Eike Ziller's avatar
Eike Ziller committed
342
    cmd = Core::ActionManager::registerAction(q->resetLayoutAction(),
343 344 345
        Core::Id("Debugger.Views.ResetSimple"), debugcontext);
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
346 347
}

348 349
void DebuggerMainWindowPrivate::addLanguage(DebuggerLanguage languageId,
                                            const Context &context)
350
{
hjk's avatar
hjk committed
351 352 353
    m_supportedLanguages = m_supportedLanguages | languageId;
    m_toolBars.insert(languageId, 0);
    m_contextsForLanguage.insert(languageId, context);
354 355
}

356
void DebuggerMainWindowPrivate::activateQmlCppLayout()
357
{
358 359
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
360 361
    if (m_toolBars.value(QmlLanguage)) {
        m_debugToolBarLayout->insertWidget(1, m_toolBars.value(QmlLanguage));
362
        m_toolBars.value(QmlLanguage)->show();
363
    }
364

365 366
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
hjk's avatar
hjk committed
367
        ICore::updateAdditionalContexts(qmlCppContext, Context());
368 369
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
hjk's avatar
hjk committed
370
        ICore::updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
371
            Context());
372 373
    }

374
    q->restoreSettings(m_dockWidgetActiveStateQmlCpp);
hjk's avatar
hjk committed
375
    ICore::updateAdditionalContexts(Context(), qmlCppContext);
376 377
}

378
void DebuggerMainWindowPrivate::activateCppLayout()
379
{
380 381
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
382 383 384 385
    if (m_toolBars.value(QmlLanguage)) {
        m_toolBars.value(QmlLanguage)->hide();
        m_debugToolBarLayout->removeWidget(m_toolBars.value(QmlLanguage));
    }
386

387 388
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
hjk's avatar
hjk committed
389
        ICore::updateAdditionalContexts(qmlCppContext, Context());
390 391
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
hjk's avatar
hjk committed
392
        ICore::updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
393
            Context());
394 395
    }

396
    q->restoreSettings(m_dockWidgetActiveStateCpp);
397

398
    const Context &cppContext = m_contextsForLanguage.value(CppLanguage);
hjk's avatar
hjk committed
399
    ICore::updateAdditionalContexts(Context(), cppContext);
400 401
}

402
void DebuggerMainWindow::setToolBar(DebuggerLanguage language, QWidget *widget)
403 404 405
{
    Q_ASSERT(d->m_toolBars.contains(language));
    d->m_toolBars[language] = widget;
406 407 408 409 410 411
    if (language == CppLanguage)
        d->m_debugToolBarLayout->addWidget(widget);

    //Add widget at the end
    if (language == AnyLanguage)
        d->m_debugToolBarLayout->insertWidget(-1, widget, 10);
412 413 414 415
}

QDockWidget *DebuggerMainWindow::dockWidget(const QString &objectName) const
{
416
    return findChild<QDockWidget *>(objectName);
417 418
}

419 420 421 422 423 424
bool DebuggerMainWindow::isDockVisible(const QString &objectName) const
{
    QDockWidget *dock = dockWidget(objectName);
    return dock && dock->toggleViewAction()->isChecked();
}

425 426 427 428
/*!
    Keep track of dock widgets so they can be shown/hidden for different languages
*/
QDockWidget *DebuggerMainWindow::createDockWidget(const DebuggerLanguage &language,
hjk's avatar
hjk committed
429
    QWidget *widget)
430 431
{
    QDockWidget *dockWidget = addDockForWidget(widget);
hjk's avatar
hjk committed
432
    dockWidget->setObjectName(widget->objectName());
433
    addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
434 435 436 437 438 439 440

    if (!(d->m_activeDebugLanguages & language))
        dockWidget->hide();

    Context globalContext(Core::Constants::C_GLOBAL);

    QAction *toggleViewAction = dockWidget->toggleViewAction();
Eike Ziller's avatar
Eike Ziller committed
441
    Command *cmd = Core::ActionManager::registerAction(toggleViewAction,
442
             Core::Id("Debugger.").withSuffix(widget->objectName()), globalContext);
443
    cmd->setAttribute(Command::CA_Hide);
444
    d->m_menuCommandsToAdd.append(cmd);
445

hjk's avatar
hjk committed
446
    dockWidget->installEventFilter(&d->m_resizeEventFilter);
447 448

    connect(dockWidget->toggleViewAction(), SIGNAL(triggered(bool)),
hjk's avatar
hjk committed
449
        d, SLOT(updateDockWidgetSettings()));
450
    connect(dockWidget, SIGNAL(topLevelChanged(bool)),
hjk's avatar
hjk committed
451
        d, SLOT(updateDockWidgetSettings()));
452
    connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
hjk's avatar
hjk committed
453
        d, SLOT(updateDockWidgetSettings()));
454 455 456 457

    return dockWidget;
}

458 459 460 461 462 463 464 465 466 467 468 469 470
static bool sortCommands(Command *cmd1, Command *cmd2)
{
    return cmd1->action()->text() < cmd2->action()->text();
}

void DebuggerMainWindow::addStagedMenuEntries()
{
    qSort(d->m_menuCommandsToAdd.begin(), d->m_menuCommandsToAdd.end(), &sortCommands);
    foreach (Command *cmd, d->m_menuCommandsToAdd)
        d->m_viewsMenu->addAction(cmd);
    d->m_menuCommandsToAdd.clear();
}

471 472
QWidget *DebuggerMainWindow::createContents(IMode *mode)
{
473
    ProjectExplorerPlugin *pe = ProjectExplorerPlugin::instance();
474
    connect(pe->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
475
        d, SLOT(updateUiForProject(ProjectExplorer::Project*)));
476

Eike Ziller's avatar
Eike Ziller committed
477
    d->m_viewsMenu = Core::ActionManager::actionContainer(Core::Id(Core::Constants::M_WINDOW_VIEWS));
478
    QTC_ASSERT(d->m_viewsMenu, return 0);
479 480 481 482 483

    //d->m_mainWindow = new Internal::DebuggerMainWindow(this);
    setDocumentMode(true);
    setDockNestingEnabled(true);
    connect(this, SIGNAL(resetLayout()),
484
        d, SLOT(resetDebuggerLayout()));
485
    connect(toggleLockedAction(), SIGNAL(triggered()),
hjk's avatar
hjk committed
486
        d, SLOT(updateDockWidgetSettings()));
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502

    QBoxLayout *editorHolderLayout = new QVBoxLayout;
    editorHolderLayout->setMargin(0);
    editorHolderLayout->setSpacing(0);

    QWidget *editorAndFindWidget = new QWidget;
    editorAndFindWidget->setLayout(editorHolderLayout);
    editorHolderLayout->addWidget(new EditorManagerPlaceHolder(mode));
    editorHolderLayout->addWidget(new FindToolBarPlaceHolder(editorAndFindWidget));

    MiniSplitter *documentAndRightPane = new MiniSplitter;
    documentAndRightPane->addWidget(editorAndFindWidget);
    documentAndRightPane->addWidget(new RightPanePlaceHolder(mode));
    documentAndRightPane->setStretchFactor(0, 1);
    documentAndRightPane->setStretchFactor(1, 0);

hjk's avatar
hjk committed
503 504 505 506 507 508
    d->m_viewButton = new QToolButton();
    // FIXME: Use real thing after string freeze.
    QString hackyName = QCoreApplication::translate("Core::Internal::MainWindow", "&Views");
    hackyName.replace(QLatin1Char('&'), QString());
    d->m_viewButton->setText(hackyName);

509 510 511 512 513
    Utils::StyledBar *debugToolBar = new Utils::StyledBar;
    debugToolBar->setProperty("topBorder", true);
    QHBoxLayout *debugToolBarLayout = new QHBoxLayout(debugToolBar);
    debugToolBarLayout->setMargin(0);
    debugToolBarLayout->setSpacing(0);
514
    debugToolBarLayout->addWidget(d->m_debugToolBar);
515
    debugToolBarLayout->addWidget(new Utils::StyledSeparator);
hjk's avatar
hjk committed
516 517 518
    debugToolBarLayout->addWidget(d->m_viewButton);

    connect(d->m_viewButton, SIGNAL(clicked()), this, SLOT(showViewsMenu()));
519

Friedemann Kleint's avatar
Friedemann Kleint committed
520
    QDockWidget *dock = new QDockWidget(DebuggerMainWindowPrivate::tr("Debugger Toolbar"));
521 522 523 524 525
    dock->setObjectName(QLatin1String("Debugger Toolbar"));
    dock->setWidget(debugToolBar);
    dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dock->setAllowedAreas(Qt::BottomDockWidgetArea);
    dock->setTitleBarWidget(new QWidget(dock));
526
    dock->setProperty("managed_dockwidget", QLatin1String("true"));
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
    addDockWidget(Qt::BottomDockWidgetArea, dock);
    setToolBarDockWidget(dock);

    QWidget *centralWidget = new QWidget;
    setCentralWidget(centralWidget);

    QVBoxLayout *centralLayout = new QVBoxLayout(centralWidget);
    centralWidget->setLayout(centralLayout);
    centralLayout->setMargin(0);
    centralLayout->setSpacing(0);
    centralLayout->addWidget(documentAndRightPane);
    centralLayout->setStretch(0, 1);
    centralLayout->setStretch(1, 0);

    // Right-side window with editor, output etc.
    MiniSplitter *mainWindowSplitter = new MiniSplitter;
    mainWindowSplitter->addWidget(this);
544 545 546
    QWidget *outputPane = new OutputPanePlaceHolder(mode, mainWindowSplitter);
    outputPane->setObjectName(QLatin1String("DebuggerOutputPanePlaceHolder"));
    mainWindowSplitter->addWidget(outputPane);
547 548 549 550 551 552 553 554 555 556
    mainWindowSplitter->setStretchFactor(0, 10);
    mainWindowSplitter->setStretchFactor(1, 0);
    mainWindowSplitter->setOrientation(Qt::Vertical);

    // Navigation and right-side window.
    MiniSplitter *splitter = new MiniSplitter;
    splitter->addWidget(new NavigationWidgetPlaceHolder(mode));
    splitter->addWidget(mainWindowSplitter);
    splitter->setStretchFactor(0, 0);
    splitter->setStretchFactor(1, 1);
557
    splitter->setObjectName(QLatin1String("DebugModeWidget"));
558 559 560 561 562
    return splitter;
}

void DebuggerMainWindow::writeSettings() const
{
hjk's avatar
hjk committed
563
    QSettings *settings = ICore::settings();
hjk's avatar
hjk committed
564
    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
565 566 567
    QHashIterator<QString, QVariant> it(d->m_dockWidgetActiveStateCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
568
        settings->setValue(it.key(), it.value());
569
    }
hjk's avatar
hjk committed
570
    settings->endGroup();
571

hjk's avatar
hjk committed
572
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
573 574 575
    it = QHashIterator<QString, QVariant>(d->m_dockWidgetActiveStateQmlCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
576
        settings->setValue(it.key(), it.value());
577
    }
hjk's avatar
hjk committed
578
    settings->endGroup();
579 580
}

hjk's avatar
hjk committed
581 582 583 584 585 586 587
void DebuggerMainWindow::showViewsMenu()
{
    QMenu *menu = createPopupMenu();
    menu->exec(d->m_viewButton->mapToGlobal(QPoint()));
    delete menu;
}

588 589
void DebuggerMainWindow::readSettings()
{
hjk's avatar
hjk committed
590
    QSettings *settings = ICore::settings();
591 592 593
    d->m_dockWidgetActiveStateCpp.clear();
    d->m_dockWidgetActiveStateQmlCpp.clear();

hjk's avatar
hjk committed
594 595 596 597
    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateCpp.insert(key, settings->value(key));
    settings->endGroup();
598

hjk's avatar
hjk committed
599 600 601 602
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateQmlCpp.insert(key, settings->value(key));
    settings->endGroup();
603

604
    // Reset initial settings when there are none yet.
605 606 607 608 609 610 611 612 613
    if (d->m_dockWidgetActiveStateQmlCpp.isEmpty()) {
        d->m_activeDebugLanguages = DebuggerLanguage(QmlLanguage|CppLanguage);
        d->setSimpleDockWidgetArrangement();
        d->m_dockWidgetActiveStateCpp = saveSettings();
    }
    if (d->m_dockWidgetActiveStateCpp.isEmpty()) {
        d->m_activeDebugLanguages = CppLanguage;
        d->setSimpleDockWidgetArrangement();
        d->m_dockWidgetActiveStateCpp = saveSettings();
614
    }
615
    writeSettings();
616 617
}

618
void DebuggerMainWindowPrivate::resetDebuggerLayout()
619
{
620
    m_activeDebugLanguages = DebuggerLanguage(QmlLanguage | CppLanguage);
621
    setSimpleDockWidgetArrangement();
622
    m_dockWidgetActiveStateQmlCpp = q->saveSettings();
623

624 625 626 627
    m_activeDebugLanguages = CppLanguage;
    m_previousDebugLanguages = CppLanguage;
    setSimpleDockWidgetArrangement();
    // will save state in m_dockWidgetActiveStateCpp
hjk's avatar
hjk committed
628
    updateActiveLanguages();
629 630
}

hjk's avatar
hjk committed
631
void DebuggerMainWindowPrivate::updateDockWidgetSettings()
632
{
hjk's avatar
hjk committed
633
    if (!m_inDebugMode || m_changingUI)
634 635
        return;

hjk's avatar
hjk committed
636 637
    if (isQmlActive())
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
638
    else
hjk's avatar
hjk committed
639
        m_dockWidgetActiveStateCpp = q->saveSettings();
640 641
}

642
bool DebuggerMainWindowPrivate::isQmlCppActive() const
643
{
644 645
    return (m_activeDebugLanguages & CppLanguage)
        && (m_activeDebugLanguages & QmlLanguage);
646 647
}

648
bool DebuggerMainWindowPrivate::isQmlActive() const
649
{
650
    return (m_activeDebugLanguages & QmlLanguage);
651 652 653 654
}

QMenu *DebuggerMainWindow::createPopupMenu()
{
655
    return FancyMainWindow::createPopupMenu();
656 657
}

658
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
659
{
hjk's avatar
hjk committed
660
    using namespace Constants;
661 662 663
    QTC_ASSERT(q, return);
    q->setTrackingEnabled(false);

664 665
    QList<QDockWidget *> dockWidgets = q->dockWidgets();
    foreach (QDockWidget *dockWidget, dockWidgets) {
666 667 668 669
        dockWidget->setFloating(false);
        q->removeDockWidget(dockWidget);
    }

670
    foreach (QDockWidget *dockWidget, dockWidgets) {
671 672 673 674 675 676 677 678
        int area = Qt::BottomDockWidgetArea;
        QVariant p = dockWidget->property(DOCKWIDGET_DEFAULT_AREA);
        if (p.isValid())
            area = Qt::DockWidgetArea(p.toInt());
        q->addDockWidget(Qt::DockWidgetArea(area), dockWidget);
        dockWidget->hide();
    }

679
    QDockWidget *toolBarDock = q->toolBarDockWidget();
680 681 682 683 684 685 686 687 688 689
    QDockWidget *breakDock = q->dockWidget(QLatin1String(DOCKWIDGET_BREAK));
    QDockWidget *stackDock = q->dockWidget(QLatin1String(DOCKWIDGET_STACK));
    QDockWidget *watchDock = q->dockWidget(QLatin1String(DOCKWIDGET_WATCHERS));
    QDockWidget *snapshotsDock = q->dockWidget(QLatin1String(DOCKWIDGET_SNAPSHOTS));
    QDockWidget *threadsDock = q->dockWidget(QLatin1String(DOCKWIDGET_THREADS));
    QDockWidget *outputDock = q->dockWidget(QLatin1String(DOCKWIDGET_OUTPUT));
    QDockWidget *qmlInspectorDock = q->dockWidget(QLatin1String(DOCKWIDGET_QML_INSPECTOR));
    QDockWidget *modulesDock = q->dockWidget(QLatin1String(DOCKWIDGET_MODULES));
    QDockWidget *registerDock = q->dockWidget(QLatin1String(DOCKWIDGET_REGISTER));
    QDockWidget *sourceFilesDock = q->dockWidget(QLatin1String(DOCKWIDGET_SOURCE_FILES));
hjk's avatar
hjk committed
690 691 692 693 694 695 696 697 698 699

    QTC_ASSERT(breakDock, return);
    QTC_ASSERT(stackDock, return);
    QTC_ASSERT(watchDock, return);
    QTC_ASSERT(snapshotsDock, return);
    QTC_ASSERT(threadsDock, return);
    QTC_ASSERT(outputDock, return);
    QTC_ASSERT(modulesDock, return);
    QTC_ASSERT(registerDock, return);
    QTC_ASSERT(sourceFilesDock, return);
700

701 702 703 704 705 706 707 708
    // make sure main docks are visible so that split equally divides the space
    toolBarDock->show();
    stackDock->show();
    breakDock->show();
    watchDock->show();

    // toolBar
    // --------------------------------------------------------------------------------
709
    // stack,qmlinspector | breakpoints,modules,register,threads,sourceFiles,snapshots
710 711 712 713 714 715 716 717 718 719 720 721 722 723
    //
    q->splitDockWidget(toolBarDock, stackDock, Qt::Vertical);
    q->splitDockWidget(stackDock, breakDock, Qt::Horizontal);

    if (qmlInspectorDock)
        q->tabifyDockWidget(stackDock, qmlInspectorDock);

    q->tabifyDockWidget(breakDock, modulesDock);
    q->tabifyDockWidget(breakDock, registerDock);
    q->tabifyDockWidget(breakDock, threadsDock);
    q->tabifyDockWidget(breakDock, sourceFilesDock);
    q->tabifyDockWidget(breakDock, snapshotsDock);

    if (m_activeDebugLanguages.testFlag(Debugger::QmlLanguage)) {
724 725
        if (qmlInspectorDock)
            qmlInspectorDock->show();
726
    } else {
727
        // CPP only
728 729
        threadsDock->show();
        snapshotsDock->show();
730 731 732
    }

    q->setTrackingEnabled(true);
733
    q->update();
734 735
}

hjk's avatar
hjk committed
736 737 738 739 740 741 742 743 744 745 746 747 748
bool DockWidgetEventFilter::eventFilter(QObject *obj, QEvent *event)
{
    switch (event->type()) {
    case QEvent::Resize:
    case QEvent::ZOrderChange:
        m_mw->updateDockWidgetSettings();
        break;
    default:
        break;
    }
    return QObject::eventFilter(obj, event);
}

749 750 751
} // namespace Debugger

#include "debuggermainwindow.moc"