Commit 0fee3776 authored by con's avatar con

Extract the special mainwindow behavior of the debug mode into class.

parent 89642119
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#include "fancymainwindow.h"
#include <QtGui/QAction>
using namespace Core::Utils;
FancyMainWindow::FancyMainWindow(QWidget *parent)
: QMainWindow(parent),
m_locked(true),
m_handleDockVisibilityChanges(true)
{
}
QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget)
{
QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), this);
dockWidget->setObjectName(widget->windowTitle());
dockWidget->setWidget(widget);
connect(dockWidget->toggleViewAction(), SIGNAL(triggered()),
this, SLOT(onDockActionTriggered()), Qt::QueuedConnection);
connect(dockWidget, SIGNAL(visibilityChanged(bool)),
this, SLOT(onDockVisibilityChange(bool)));
connect(dockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(onTopLevelChanged()));
m_dockWidgets.append(dockWidget);
m_dockWidgetActiveState.append(true);
updateDockWidget(dockWidget);
return dockWidget;
}
void FancyMainWindow::updateDockWidget(QDockWidget *dockWidget)
{
const QDockWidget::DockWidgetFeatures features =
(m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable
: QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable;
QWidget *titleBarWidget = dockWidget->titleBarWidget();
if (m_locked && !titleBarWidget && !dockWidget->isFloating())
titleBarWidget = new QWidget(dockWidget);
else if ((!m_locked || dockWidget->isFloating()) && titleBarWidget) {
delete titleBarWidget;
titleBarWidget = 0;
}
dockWidget->setTitleBarWidget(titleBarWidget);
dockWidget->setFeatures(features);
}
void FancyMainWindow::onDockActionTriggered()
{
QDockWidget *dw = qobject_cast<QDockWidget *>(sender()->parent());
if (dw) {
if (dw->isVisible())
dw->raise();
}
}
void FancyMainWindow::onDockVisibilityChange(bool visible)
{
if (!m_handleDockVisibilityChanges)
return;
QDockWidget *dockWidget = qobject_cast<QDockWidget *>(sender());
int index = m_dockWidgets.indexOf(dockWidget);
m_dockWidgetActiveState[index] = visible;
}
void FancyMainWindow::onTopLevelChanged()
{
updateDockWidget(qobject_cast<QDockWidget*>(sender()));
}
void FancyMainWindow::setTrackingEnabled(bool enabled)
{
if (enabled) {
m_handleDockVisibilityChanges = true;
for (int i = 0; i < m_dockWidgets.size(); ++i)
m_dockWidgetActiveState[i] = m_dockWidgets[i]->isVisible();
} else {
m_handleDockVisibilityChanges = false;
}
}
void FancyMainWindow::setLocked(bool locked)
{
m_locked = locked;
foreach (QDockWidget *dockWidget, m_dockWidgets) {
updateDockWidget(dockWidget);
}
}
void FancyMainWindow::hideEvent(QHideEvent *event)
{
Q_UNUSED(event)
handleVisibilityChanged(false);
}
void FancyMainWindow::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
handleVisibilityChanged(true);
}
void FancyMainWindow::handleVisibilityChanged(bool visible)
{
m_handleDockVisibilityChanges = false;
for (int i = 0; i < m_dockWidgets.size(); ++i) {
QDockWidget *dockWidget = m_dockWidgets.at(i);
if (dockWidget->isFloating()) {
dockWidget->setVisible(visible && m_dockWidgetActiveState.at(i));
}
}
if (visible)
m_handleDockVisibilityChanges = true;
}
void FancyMainWindow::saveSettings(QSettings *settings) const
{
settings->setValue("State", saveState());
settings->setValue("Locked", m_locked);
for (int i = 0; i < m_dockWidgetActiveState.count(); ++i) {
settings->setValue(m_dockWidgets.at(i)->objectName(),
m_dockWidgetActiveState.at(i));
}
}
void FancyMainWindow::restoreSettings(QSettings *settings)
{
QByteArray ba = settings->value("State", QByteArray()).toByteArray();
restoreState(ba);
m_locked = settings->value("Locked", true).toBool();
for (int i = 0; i < m_dockWidgetActiveState.count(); ++i) {
m_dockWidgetActiveState[i] = settings->value(m_dockWidgets.at(i)->objectName(), false).toBool();
}
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/
#ifndef FANCYMAINWINDOW_H
#define FANCYMAINWINDOW_H
#include "utils_global.h"
#include <QtCore/QList>
#include <QtCore/QSettings>
#include <QtGui/QMainWindow>
#include <QtGui/QDockWidget>
#include <QtCore/QSettings>
namespace Core {
namespace Utils {
class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow
{
Q_OBJECT
public:
FancyMainWindow(QWidget *parent = 0);
QDockWidget *addDockForWidget(QWidget *widget);
QList<QDockWidget *> dockWidgets() const { return m_dockWidgets; }
void setTrackingEnabled(bool enabled);
bool isLocked() const { return m_locked; }
void saveSettings(QSettings *settings) const;
void restoreSettings(QSettings *settings);
public slots:
void setLocked(bool locked);
protected:
void hideEvent(QHideEvent *event);
void showEvent(QShowEvent *event);
private slots:
void onDockActionTriggered();
void onDockVisibilityChange(bool);
void onTopLevelChanged();
private:
void updateDockWidget(QDockWidget *dockWidget);
void handleVisibilityChanged(bool visible);
QList<QDockWidget *> m_dockWidgets;
QList<bool> m_dockWidgetActiveState;
bool m_locked;
bool m_handleDockVisibilityChanges; //todo
};
} // namespace Utils
} // namespace Core
#endif // FANCYMAINWINDOW_H
......@@ -32,7 +32,8 @@ SOURCES += reloadpromptutils.cpp \
checkablemessagebox.cpp \
styledbar.cpp \
stylehelper.cpp \
welcomemodetreewidget.cpp
welcomemodetreewidget.cpp \
fancymainwindow.cpp
win32 {
SOURCES += abstractprocess_win.cpp \
consoleprocess_win.cpp \
......@@ -72,7 +73,8 @@ HEADERS += utils_global.h \
qtcassert.h \
styledbar.h \
stylehelper.h \
welcomemodetreewidget.h
welcomemodetreewidget.h \
fancymainwindow.h
FORMS += filewizardpage.ui \
projectintropage.ui \
newclasswidget.ui \
......
......@@ -57,6 +57,7 @@
#endif
#include <coreplugin/icore.h>
#include <utils/qtcassert.h>
#include <utils/fancymainwindow.h>
#include <projectexplorer/toolchain.h>
#include <QtCore/QDebug>
......@@ -73,7 +74,6 @@
#include <QtGui/QErrorMessage>
#include <QtGui/QFileDialog>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QPushButton>
......@@ -212,9 +212,6 @@ void DebuggerManager::init()
m_modulesHandler = 0;
m_registerHandler = 0;
m_locked = true;
m_handleDockVisibilityChanges = false;
m_statusLabel = new QLabel;
// FIXME: Do something to show overly long messages at least partially
//QSizePolicy policy = m_statusLabel->sizePolicy();
......@@ -234,7 +231,7 @@ void DebuggerManager::init()
//m_tooltipWindow = new WatchWindow(WatchWindow::TooltipType);
m_statusTimer = new QTimer(this);
m_mainWindow = new QMainWindow;
m_mainWindow = new Core::Utils::FancyMainWindow;
m_mainWindow->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North);
m_mainWindow->setDocumentMode(true);
......@@ -436,29 +433,29 @@ void DebuggerManager::init()
connect(theDebuggerAction(WatchPoint), SIGNAL(triggered()),
this, SLOT(watchPoint()));
m_breakDock = createDockForWidget(m_breakWindow);
m_breakDock = m_mainWindow->addDockForWidget(m_breakWindow);
m_disassemblerDock = createDockForWidget(m_disassemblerWindow);
m_disassemblerDock = m_mainWindow->addDockForWidget(m_disassemblerWindow);
connect(m_disassemblerDock->toggleViewAction(), SIGNAL(toggled(bool)),
this, SLOT(reloadDisassembler()), Qt::QueuedConnection);
m_modulesDock = createDockForWidget(m_modulesWindow);
m_modulesDock = m_mainWindow->addDockForWidget(m_modulesWindow);
connect(m_modulesDock->toggleViewAction(), SIGNAL(toggled(bool)),
this, SLOT(reloadModules()), Qt::QueuedConnection);
m_registerDock = createDockForWidget(m_registerWindow);
m_registerDock = m_mainWindow->addDockForWidget(m_registerWindow);
connect(m_registerDock->toggleViewAction(), SIGNAL(toggled(bool)),
this, SLOT(reloadRegisters()), Qt::QueuedConnection);
m_outputDock = createDockForWidget(m_outputWindow);
m_outputDock = m_mainWindow->addDockForWidget(m_outputWindow);
m_stackDock = createDockForWidget(m_stackWindow);
m_stackDock = m_mainWindow->addDockForWidget(m_stackWindow);
m_sourceFilesDock = createDockForWidget(m_sourceFilesWindow);
m_sourceFilesDock = m_mainWindow->addDockForWidget(m_sourceFilesWindow);
connect(m_sourceFilesDock->toggleViewAction(), SIGNAL(toggled(bool)),
this, SLOT(reloadSourceFiles()), Qt::QueuedConnection);
m_threadsDock = createDockForWidget(m_threadsWindow);
m_threadsDock = m_mainWindow->addDockForWidget(m_threadsWindow);
QSplitter *localsAndWatchers = new QSplitter(Qt::Vertical, 0);
localsAndWatchers->setWindowTitle(m_localsWindow->windowTitle());
......@@ -468,7 +465,7 @@ void DebuggerManager::init()
localsAndWatchers->setStretchFactor(0, 3);
localsAndWatchers->setStretchFactor(1, 1);
localsAndWatchers->setStretchFactor(2, 1);
m_watchDock = createDockForWidget(localsAndWatchers);
m_watchDock = m_mainWindow->addDockForWidget(localsAndWatchers);
setStatus(DebuggerProcessNotReady);
}
......@@ -509,30 +506,14 @@ void DebuggerManager::createNewDock(QWidget *widget)
dockWidget->show();
}
QDockWidget *DebuggerManager::createDockForWidget(QWidget *widget)
{
QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), m_mainWindow);
dockWidget->setObjectName(widget->windowTitle());
dockWidget->setWidget(widget);
connect(dockWidget->toggleViewAction(), SIGNAL(triggered()),
this, SLOT(dockActionTriggered()), Qt::QueuedConnection);
connect(dockWidget, SIGNAL(visibilityChanged(bool)),
this, SLOT(onDockVisibilityChange(bool)));
connect(dockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(onTopLevelChanged()));
m_dockWidgets.append(dockWidget);
m_dockWidgetActiveState.append(true);
updateDockWidget(dockWidget);
return dockWidget;
}
void DebuggerManager::setSimpleDockWidgetArrangement()
{
m_handleDockVisibilityChanges = false;
foreach (QDockWidget *dockWidget, m_dockWidgets)
m_mainWindow->setTrackingEnabled(false);
QList<QDockWidget *> dockWidgets = m_mainWindow->dockWidgets();
foreach (QDockWidget *dockWidget, dockWidgets)
m_mainWindow->removeDockWidget(dockWidget);
foreach (QDockWidget *dockWidget, m_dockWidgets) {
foreach (QDockWidget *dockWidget, dockWidgets) {
m_mainWindow->addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
dockWidget->show();
}
......@@ -552,69 +533,7 @@ void DebuggerManager::setSimpleDockWidgetArrangement()
m_disassemblerDock->hide();
m_modulesDock->hide();
m_outputDock->hide();
for (int i = 0; i < m_dockWidgets.size(); ++i)
m_dockWidgetActiveState[i] = m_dockWidgets[i]->isVisible();
m_handleDockVisibilityChanges = true;
}
void DebuggerManager::onDockVisibilityChange(bool visible)
{
if (!m_handleDockVisibilityChanges)
return;
QDockWidget *dockWidget = qobject_cast<QDockWidget *>(sender());
int index = m_dockWidgets.indexOf(dockWidget);
m_dockWidgetActiveState[index] = visible;
}
void DebuggerManager::modeVisibilityChanged(bool visible)
{
m_handleDockVisibilityChanges = false;
for (int i = 0; i < m_dockWidgets.size(); ++i) {
QDockWidget *dockWidget = m_dockWidgets.at(i);
if (dockWidget->isFloating()) {
dockWidget->setVisible(visible && m_dockWidgetActiveState.at(i));
}
}
if (visible)
m_handleDockVisibilityChanges = true;
}
void DebuggerManager::onTopLevelChanged()
{
updateDockWidget(qobject_cast<QDockWidget*>(sender()));
}
void DebuggerManager::setLocked(bool locked)
{
m_locked = locked;
foreach (QDockWidget *dockWidget, m_dockWidgets) {
updateDockWidget(dockWidget);
}
}
void DebuggerManager::updateDockWidget(QDockWidget *dockWidget)
{
const QDockWidget::DockWidgetFeatures features =
(m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable :
QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable;
QWidget *titleBarWidget = dockWidget->titleBarWidget();
if (m_locked && !titleBarWidget && !dockWidget->isFloating())
titleBarWidget = new QWidget(dockWidget);
else if ((!m_locked || dockWidget->isFloating()) && titleBarWidget) {
delete titleBarWidget;
titleBarWidget = 0;
}
dockWidget->setTitleBarWidget(titleBarWidget);
dockWidget->setFeatures(features);
}
void DebuggerManager::dockActionTriggered()
{
QDockWidget *dw = qobject_cast<QDockWidget *>(sender()->parent());
if (dw) {
if (dw->isVisible())
dw->raise();
}
m_mainWindow->setTrackingEnabled(true);
}
QAbstractItemModel *DebuggerManager::threadsModel()
......
......@@ -30,6 +30,8 @@
#ifndef DEBUGGER_DEBUGGERMANAGER_H
#define DEBUGGER_DEBUGGERMANAGER_H
#include <utils/fancymainwindow.h>
#include <QtCore/QByteArray>
#include <QtCore/QObject>
#include <QtCore/QStringList>
......@@ -41,7 +43,6 @@ class QAction;
class QAbstractItemModel;
class QDockWidget;
class QLabel;
class QMainWindow;
class QModelIndex;
class QPoint;
class QTimer;
......@@ -262,7 +263,7 @@ public:
~DebuggerManager();
IDebuggerManagerAccessForEngines *engineInterface();
QMainWindow *mainWindow() const { return m_mainWindow; }
Core::Utils::FancyMainWindow *mainWindow() const { return m_mainWindow; }
QLabel *statusLabel() const { return m_statusLabel; }
public slots:
......@@ -276,9 +277,6 @@ public slots:
void setQtDumperLibraryLocations(const QStringList &dl);
void setSimpleDockWidgetArrangement();
void setLocked(bool locked);
void dockActionTriggered();
void modeVisibilityChanged(bool visible);
void setBusyCursor(bool on);
void queryCurrentTextEditor(QString *fileName, int *lineNumber, QObject **ed);
......@@ -374,7 +372,6 @@ private:
// Implementation of IDebuggerManagerAccessForDebugMode
//
QWidget *threadsWindow() const { return m_threadsWindow; }
QList<QDockWidget*> dockWidgets() const { return m_dockWidgets; }
virtual bool qtDumperLibraryEnabled() const;
virtual QString qtDumperLibraryName() const;
......@@ -421,11 +418,7 @@ public:
private:
void init();
void runTest(const QString &fileName);
QDockWidget *createDockForWidget(QWidget *widget);
Q_SLOT void createNewDock(QWidget *widget);
void updateDockWidget(QDockWidget *dockWidget);
Q_SLOT void onDockVisibilityChange(bool visible);
Q_SLOT void onTopLevelChanged();
void shutdown();
......@@ -442,7 +435,7 @@ private:
/// Views
QMainWindow *m_mainWindow;
Core::Utils::FancyMainWindow *m_mainWindow;
QLabel *m_statusLabel;
QDockWidget *m_breakDock;
QDockWidget *m_disassemblerDock;
......@@ -453,10 +446,6 @@ private:
QDockWidget *m_sourceFilesDock;
QDockWidget *m_threadsDock;
QDockWidget *m_watchDock;
QList<QDockWidget*> m_dockWidgets;
QList<bool> m_dockWidgetActiveState;
bool m_locked;
bool m_handleDockVisibilityChanges;
BreakHandler *m_breakHandler;
DisassemblerHandler *m_disassemblerHandler;
......
......@@ -71,6 +71,7 @@
#include <utils/qtcassert.h>
#include <utils/styledbar.h>
#include <utils/fancymainwindow.h>
#include <QtCore/QDebug>
#include <QtCore/QObject>
......@@ -82,7 +83,6 @@
#include <QtGui/QLineEdit>
#include <QtGui/QDockWidget>
#include <QtGui/QMainWindow>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QTextBlock>
#include <QtGui/QTextCursor>
......@@ -742,8 +742,8 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
m_toggleLockedAction->setCheckable(true);
m_toggleLockedAction->setChecked(true);
connect(m_toggleLockedAction, SIGNAL(toggled(bool)),
m_manager, SLOT(setLocked(bool)));
foreach (QDockWidget *dockWidget, m_manager->dockWidgets()) {
m_manager->mainWindow(), SLOT(setLocked(bool)));
foreach (QDockWidget *dockWidget, m_manager->mainWindow()->dockWidgets()) {
cmd = am->registerAction(dockWidget->toggleViewAction(),
"Debugger." + dockWidget->objectName(), debuggercontext);
viewsMenu->addAction(cmd);
......@@ -1135,8 +1135,7 @@ void DebuggerPlugin::writeSettings() const
QSettings *s = settings();
DebuggerSettings::instance()->writeSettings(s);
s->beginGroup(QLatin1String("DebugMode"));
s->setValue("State", m_manager->mainWindow()->saveState());
s->setValue("Locked", m_toggleLockedAction->isChecked());
m_manager->mainWindow()->saveSettings(s);
s->endGroup();
}
......@@ -1154,12 +1153,9 @@ void DebuggerPlugin::readSettings()
QString defaultScript;
s->beginGroup(QLatin1String("DebugMode"));
QByteArray ba = s->value("State", QByteArray()).toByteArray();
m_toggleLockedAction->setChecked(s->value("Locked", true).toBool());
m_manager->mainWindow()->restoreSettings(s);
m_toggleLockedAction->setChecked(m_manager->mainWindow()->isLocked());
s->endGroup();
m_manager->mainWindow()->restoreState(ba);
m_manager->setLocked(m_toggleLockedAction->isChecked());
}
void DebuggerPlugin::onModeChanged(IMode *mode)
......@@ -1169,15 +1165,10 @@ void DebuggerPlugin::onModeChanged(IMode *mode)
// also on shutdown.
if (mode != m_debugMode) {
if (m_manager)
m_manager->modeVisibilityChanged(false);
return;
}
if (m_manager)
m_manager->modeVisibilityChanged(true);
EditorManager *editorManager = EditorManager::instance();
if (editorManager->currentEditor())
editorManager->currentEditor()->widget()->setFocus();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment