debuggermainwindow.cpp 25.2 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 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 "debuggerrunconfigurationaspect.h"
33

34
#include <utils/appmainwindow.h>
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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
49
50
#include <projectexplorer/project.h>
#include <projectexplorer/runconfiguration.h>
51
52
53
#include <projectexplorer/session.h>
#include <projectexplorer/target.h>

54
#include <QDebug>
55

56
57
#include <QDockWidget>
#include <QVBoxLayout>
hjk's avatar
hjk committed
58
#include <QToolButton>
59
60

using namespace Core;
61
using namespace ProjectExplorer;
62
using namespace Debugger::Constants;
63
64
65
66
67
68
69

namespace Debugger {
namespace Internal {

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

76
class DebuggerMainWindowPrivate : public QObject
77
{
78
79
    Q_OBJECT

80
81
82
public:
    explicit DebuggerMainWindowPrivate(DebuggerMainWindow *mainWindow);

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

92
93
94
95
96
97
98

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
99
100
101
    void updateActiveLanguages();
    void updateDockWidgetSettings();
    void openMemoryEditor() { debuggerCore()->openMemoryEditor(); }
102

103
104
105
106
107
public:
    DebuggerMainWindow *q;

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

    QMap<DebuggerLanguage, QWidget *> m_toolBars;

    DebuggerLanguages m_supportedLanguages;

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

    QHash<DebuggerLanguage, Context> m_contextsForLanguage;

    bool m_inDebugMode;
    bool m_changingUI;

    DebuggerLanguages m_previousDebugLanguages;
    DebuggerLanguages m_activeDebugLanguages;
125
    DebuggerLanguages m_engineDebugLanguages;
126
127

    ActionContainer *m_viewsMenu;
128
    QList<Command *> m_menuCommandsToAdd;
129

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

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

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

176
void DebuggerMainWindowPrivate::updateUiForTarget(Target *target)
177
{
178
    if (m_previousTarget) {
179
         disconnect(m_previousTarget,
180
181
182
            SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
            this, SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
    }
183

184
    m_previousTarget = target;
185
186
187
188
189
190

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

191
192
193
194
195
196
197
    connect(target,
        SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
        SLOT(updateUiForRunConfiguration(ProjectExplorer::RunConfiguration*)));
    updateUiForRunConfiguration(target->activeRunConfiguration());
}

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

213
214
void DebuggerMainWindowPrivate::updateUiForCurrentRunConfiguration()
{
hjk's avatar
hjk committed
215
216
217
218
219
220
221
    updateActiveLanguages();
}

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

222
    if (m_engineDebugLanguages != AnyLanguage) {
223
        newLanguages = m_engineDebugLanguages;
224
225
226
227
228
    } 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
    }

    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;
249
250
}

251
252
253
254
255
} // namespace Internal

using namespace Internal;

DebuggerMainWindow::DebuggerMainWindow()
256
{
257
    d = new DebuggerMainWindowPrivate(this);
258
259
260
261
262
}

DebuggerMainWindow::~DebuggerMainWindow()
{
    delete d;
263
264
265
266
267
268
269
}

DebuggerLanguages DebuggerMainWindow::activeDebugLanguages() const
{
    return d->m_activeDebugLanguages;
}

270
271
272
273
274
275
276
277
278
void DebuggerMainWindow::setEngineDebugLanguages(DebuggerLanguages languages)
{
    if (d->m_engineDebugLanguages == languages)
        return;

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

279
280
void DebuggerMainWindow::onModeChanged(IMode *mode)
{
281
    d->m_inDebugMode = (mode && mode->id() == Constants::MODE_DEBUG);
282
283
284
    setDockActionsVisible(d->m_inDebugMode);

    // Hide all the debugger windows if mode is different.
285
    if (d->m_inDebugMode) {
hjk's avatar
hjk committed
286
287
288
289
        readSettings();
        d->updateActiveLanguages();
    } else {
        // Hide dock widgets manually in case they are floating.
290
        foreach (QDockWidget *dockWidget, dockWidgets()) {
hjk's avatar
hjk committed
291
292
293
            if (dockWidget->isFloating())
                dockWidget->hide();
        }
294
295
296
    }
}

297
void DebuggerMainWindowPrivate::createViewsMenuItems()
298
{
Friedemann Kleint's avatar
Friedemann Kleint committed
299
    Context debugcontext(Constants::C_DEBUGMODE);
Eike Ziller's avatar
Eike Ziller committed
300
    m_viewsMenu = Core::ActionManager::actionContainer(Id(Core::Constants::M_WINDOW_VIEWS));
301
    QTC_ASSERT(m_viewsMenu, return);
302

303
304
305
    QAction *openMemoryEditorAction = new QAction(this);
    openMemoryEditorAction->setText(tr("Memory..."));
    connect(openMemoryEditorAction, SIGNAL(triggered()),
hjk's avatar
hjk committed
306
       SLOT(openMemoryEditor()));
307
308
309

    // Add menu items
    Command *cmd = 0;
Eike Ziller's avatar
Eike Ziller committed
310
    cmd = Core::ActionManager::registerAction(openMemoryEditorAction,
311
        "Debugger.Views.OpenMemoryEditor", debugcontext);
312
    cmd->setAttribute(Command::CA_Hide);
313
314
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);

Eike Ziller's avatar
Eike Ziller committed
315
    cmd = Core::ActionManager::registerAction(q->menuSeparator1(),
316
        "Debugger.Views.Separator1", debugcontext);
317
318
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
Eike Ziller's avatar
Eike Ziller committed
319
    cmd = Core::ActionManager::registerAction(q->toggleLockedAction(),
320
        "Debugger.Views.ToggleLocked", debugcontext);
321
322
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
Eike Ziller's avatar
Eike Ziller committed
323
    cmd = Core::ActionManager::registerAction(q->menuSeparator2(),
324
        "Debugger.Views.Separator2", debugcontext);
325
326
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
Eike Ziller's avatar
Eike Ziller committed
327
    cmd = Core::ActionManager::registerAction(q->resetLayoutAction(),
328
        "Debugger.Views.ResetSimple", debugcontext);
329
330
    cmd->setAttribute(Command::CA_Hide);
    m_viewsMenu->addAction(cmd, Core::Constants::G_DEFAULT_THREE);
331
332
}

333
334
void DebuggerMainWindowPrivate::addLanguage(DebuggerLanguage languageId,
                                            const Context &context)
335
{
hjk's avatar
hjk committed
336
337
338
    m_supportedLanguages = m_supportedLanguages | languageId;
    m_toolBars.insert(languageId, 0);
    m_contextsForLanguage.insert(languageId, context);
339
340
}

341
void DebuggerMainWindowPrivate::activateQmlCppLayout()
342
{
343
344
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
345
346
    if (m_toolBars.value(QmlLanguage)) {
        m_debugToolBarLayout->insertWidget(1, m_toolBars.value(QmlLanguage));
347
        m_toolBars.value(QmlLanguage)->show();
348
    }
349

350
351
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
hjk's avatar
hjk committed
352
        ICore::updateAdditionalContexts(qmlCppContext, Context());
353
354
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
hjk's avatar
hjk committed
355
        ICore::updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
356
            Context());
357
358
    }

359
    q->restoreSettings(m_dockWidgetActiveStateQmlCpp);
hjk's avatar
hjk committed
360
    ICore::updateAdditionalContexts(Context(), qmlCppContext);
361
362
}

363
void DebuggerMainWindowPrivate::activateCppLayout()
364
{
365
366
    Context qmlCppContext = m_contextsForLanguage.value(QmlLanguage);
    qmlCppContext.add(m_contextsForLanguage.value(CppLanguage));
367
368
369
370
    if (m_toolBars.value(QmlLanguage)) {
        m_toolBars.value(QmlLanguage)->hide();
        m_debugToolBarLayout->removeWidget(m_toolBars.value(QmlLanguage));
    }
371

372
373
    if (m_previousDebugLanguages & QmlLanguage) {
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
hjk's avatar
hjk committed
374
        ICore::updateAdditionalContexts(qmlCppContext, Context());
375
376
    } else if (m_previousDebugLanguages & CppLanguage) {
        m_dockWidgetActiveStateCpp = q->saveSettings();
hjk's avatar
hjk committed
377
        ICore::updateAdditionalContexts(m_contextsForLanguage.value(CppLanguage),
378
            Context());
379
380
    }

381
    q->restoreSettings(m_dockWidgetActiveStateCpp);
382

383
    const Context &cppContext = m_contextsForLanguage.value(CppLanguage);
hjk's avatar
hjk committed
384
    ICore::updateAdditionalContexts(Context(), cppContext);
385
386
}

387
void DebuggerMainWindow::setToolBar(DebuggerLanguage language, QWidget *widget)
388
389
390
{
    Q_ASSERT(d->m_toolBars.contains(language));
    d->m_toolBars[language] = widget;
391
392
393
394
395
396
    if (language == CppLanguage)
        d->m_debugToolBarLayout->addWidget(widget);

    //Add widget at the end
    if (language == AnyLanguage)
        d->m_debugToolBarLayout->insertWidget(-1, widget, 10);
397
398
399
400
}

QDockWidget *DebuggerMainWindow::dockWidget(const QString &objectName) const
{
401
    return findChild<QDockWidget *>(objectName);
402
403
}

404
405
406
407
408
409
bool DebuggerMainWindow::isDockVisible(const QString &objectName) const
{
    QDockWidget *dock = dockWidget(objectName);
    return dock && dock->toggleViewAction()->isChecked();
}

410
411
412
413
/*!
    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
414
    QWidget *widget)
415
416
{
    QDockWidget *dockWidget = addDockForWidget(widget);
hjk's avatar
hjk committed
417
    dockWidget->setObjectName(widget->objectName());
418
    addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
419
420
421
422
423
424
425

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

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

    QAction *toggleViewAction = dockWidget->toggleViewAction();
Eike Ziller's avatar
Eike Ziller committed
426
    Command *cmd = Core::ActionManager::registerAction(toggleViewAction,
427
             Core::Id("Debugger.").withSuffix(widget->objectName()), globalContext);
428
    cmd->setAttribute(Command::CA_Hide);
429
    d->m_menuCommandsToAdd.append(cmd);
430

hjk's avatar
hjk committed
431
    dockWidget->installEventFilter(&d->m_resizeEventFilter);
432
433

    connect(dockWidget->toggleViewAction(), SIGNAL(triggered(bool)),
hjk's avatar
hjk committed
434
        d, SLOT(updateDockWidgetSettings()));
435
    connect(dockWidget, SIGNAL(topLevelChanged(bool)),
hjk's avatar
hjk committed
436
        d, SLOT(updateDockWidgetSettings()));
437
    connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
hjk's avatar
hjk committed
438
        d, SLOT(updateDockWidgetSettings()));
439
440
441
442

    return dockWidget;
}

443
444
445
446
447
448
449
450
451
452
453
454
455
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();
}

456
457
QWidget *DebuggerMainWindow::createContents(IMode *mode)
{
hjk's avatar
hjk committed
458
    connect(SessionManager::instance(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
459
        d, SLOT(updateUiForProject(ProjectExplorer::Project*)));
460

Eike Ziller's avatar
Eike Ziller committed
461
    d->m_viewsMenu = Core::ActionManager::actionContainer(Core::Id(Core::Constants::M_WINDOW_VIEWS));
462
    QTC_ASSERT(d->m_viewsMenu, return 0);
463
464
465
466
467

    //d->m_mainWindow = new Internal::DebuggerMainWindow(this);
    setDocumentMode(true);
    setDockNestingEnabled(true);
    connect(this, SIGNAL(resetLayout()),
468
        d, SLOT(resetDebuggerLayout()));
469
    connect(toggleLockedAction(), SIGNAL(triggered()),
hjk's avatar
hjk committed
470
        d, SLOT(updateDockWidgetSettings()));
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

    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
487
488
489
490
491
492
    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);

493
494
495
496
497
    Utils::StyledBar *debugToolBar = new Utils::StyledBar;
    debugToolBar->setProperty("topBorder", true);
    QHBoxLayout *debugToolBarLayout = new QHBoxLayout(debugToolBar);
    debugToolBarLayout->setMargin(0);
    debugToolBarLayout->setSpacing(0);
498
    debugToolBarLayout->addWidget(d->m_debugToolBar);
499
    debugToolBarLayout->addWidget(new Utils::StyledSeparator);
hjk's avatar
hjk committed
500
501
502
    debugToolBarLayout->addWidget(d->m_viewButton);

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

Friedemann Kleint's avatar
Friedemann Kleint committed
504
    QDockWidget *dock = new QDockWidget(DebuggerMainWindowPrivate::tr("Debugger Toolbar"));
505
506
507
508
509
    dock->setObjectName(QLatin1String("Debugger Toolbar"));
    dock->setWidget(debugToolBar);
    dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
    dock->setAllowedAreas(Qt::BottomDockWidgetArea);
    dock->setTitleBarWidget(new QWidget(dock));
510
    dock->setProperty("managed_dockwidget", QLatin1String("true"));
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
    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);
528
529
530
    QWidget *outputPane = new OutputPanePlaceHolder(mode, mainWindowSplitter);
    outputPane->setObjectName(QLatin1String("DebuggerOutputPanePlaceHolder"));
    mainWindowSplitter->addWidget(outputPane);
531
532
533
534
535
536
537
538
539
540
    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);
541
    splitter->setObjectName(QLatin1String("DebugModeWidget"));
542
543
544
545
546
    return splitter;
}

void DebuggerMainWindow::writeSettings() const
{
hjk's avatar
hjk committed
547
    QSettings *settings = ICore::settings();
hjk's avatar
hjk committed
548
    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
549
550
551
    QHashIterator<QString, QVariant> it(d->m_dockWidgetActiveStateCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
552
        settings->setValue(it.key(), it.value());
553
    }
hjk's avatar
hjk committed
554
    settings->endGroup();
555

hjk's avatar
hjk committed
556
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
557
558
559
    it = QHashIterator<QString, QVariant>(d->m_dockWidgetActiveStateQmlCpp);
    while (it.hasNext()) {
        it.next();
hjk's avatar
hjk committed
560
        settings->setValue(it.key(), it.value());
561
    }
hjk's avatar
hjk committed
562
    settings->endGroup();
563
564
}

hjk's avatar
hjk committed
565
566
567
568
569
570
571
void DebuggerMainWindow::showViewsMenu()
{
    QMenu *menu = createPopupMenu();
    menu->exec(d->m_viewButton->mapToGlobal(QPoint()));
    delete menu;
}

572
573
void DebuggerMainWindow::readSettings()
{
hjk's avatar
hjk committed
574
    QSettings *settings = ICore::settings();
575
576
577
    d->m_dockWidgetActiveStateCpp.clear();
    d->m_dockWidgetActiveStateQmlCpp.clear();

hjk's avatar
hjk committed
578
579
580
581
    settings->beginGroup(QLatin1String("DebugMode.CppMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateCpp.insert(key, settings->value(key));
    settings->endGroup();
582

hjk's avatar
hjk committed
583
584
585
586
    settings->beginGroup(QLatin1String("DebugMode.CppQmlMode"));
    foreach (const QString &key, settings->childKeys())
        d->m_dockWidgetActiveStateQmlCpp.insert(key, settings->value(key));
    settings->endGroup();
587

588
    // Reset initial settings when there are none yet.
589
590
591
592
593
594
595
596
597
    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();
598
    }
599
    writeSettings();
600
601
}

602
void DebuggerMainWindowPrivate::resetDebuggerLayout()
603
{
604
    m_activeDebugLanguages = DebuggerLanguage(QmlLanguage | CppLanguage);
605
    setSimpleDockWidgetArrangement();
606
    m_dockWidgetActiveStateQmlCpp = q->saveSettings();
607

608
609
610
611
    m_activeDebugLanguages = CppLanguage;
    m_previousDebugLanguages = CppLanguage;
    setSimpleDockWidgetArrangement();
    // will save state in m_dockWidgetActiveStateCpp
hjk's avatar
hjk committed
612
    updateActiveLanguages();
613
614
}

hjk's avatar
hjk committed
615
void DebuggerMainWindowPrivate::updateDockWidgetSettings()
616
{
hjk's avatar
hjk committed
617
    if (!m_inDebugMode || m_changingUI)
618
619
        return;

hjk's avatar
hjk committed
620
621
    if (isQmlActive())
        m_dockWidgetActiveStateQmlCpp = q->saveSettings();
622
    else
hjk's avatar
hjk committed
623
        m_dockWidgetActiveStateCpp = q->saveSettings();
624
625
}

626
bool DebuggerMainWindowPrivate::isQmlCppActive() const
627
{
628
629
    return (m_activeDebugLanguages & CppLanguage)
        && (m_activeDebugLanguages & QmlLanguage);
630
631
}

632
bool DebuggerMainWindowPrivate::isQmlActive() const
633
{
634
    return (m_activeDebugLanguages & QmlLanguage);
635
636
637
638
}

QMenu *DebuggerMainWindow::createPopupMenu()
{
639
    return FancyMainWindow::createPopupMenu();
640
641
}

642
void DebuggerMainWindowPrivate::setSimpleDockWidgetArrangement()
643
{
hjk's avatar
hjk committed
644
    using namespace Constants;
645
646
647
    QTC_ASSERT(q, return);
    q->setTrackingEnabled(false);

648
649
    QList<QDockWidget *> dockWidgets = q->dockWidgets();
    foreach (QDockWidget *dockWidget, dockWidgets) {
650
651
652
653
        dockWidget->setFloating(false);
        q->removeDockWidget(dockWidget);
    }

654
    foreach (QDockWidget *dockWidget, dockWidgets) {
655
656
657
658
659
660
661
662
        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();
    }

663
    QDockWidget *toolBarDock = q->toolBarDockWidget();
664
665
666
667
668
669
670
671
672
673
    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
674
675
676
677
678
679
680
681
682
683

    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);
684

685
686
687
688
689
690
691
692
    // make sure main docks are visible so that split equally divides the space
    toolBarDock->show();
    stackDock->show();
    breakDock->show();
    watchDock->show();

    // toolBar
    // --------------------------------------------------------------------------------
693
    // stack,qmlinspector | breakpoints,modules,register,threads,sourceFiles,snapshots
694
695
696
697
698
699
700
701
702
703
704
705
706
707
    //
    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)) {
708
709
        if (qmlInspectorDock)
            qmlInspectorDock->show();
710
    } else {
711
        // CPP only
712
713
        threadsDock->show();
        snapshotsDock->show();
714
715
716
    }

    q->setTrackingEnabled(true);
717
    q->update();
718
719
}

hjk's avatar
hjk committed
720
721
722
723
724
725
726
727
728
729
730
731
732
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);
}

733
734
735
} // namespace Debugger

#include "debuggermainwindow.moc"