Commit 5cf8673c authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Header cleanup in utils/coreplugin.

parent 1e4ce5ee
......@@ -29,20 +29,40 @@
#include "fancymainwindow.h"
#include <QtCore/QList>
#include <QtCore/QHash>
#include <QtGui/QAction>
#include <QtGui/QDockWidget>
#include <QtCore/QSettings>
using namespace Utils;
namespace Utils {
struct FancyMainWindowPrivate {
FancyMainWindowPrivate();
QList<QDockWidget *> m_dockWidgets;
QList<bool> m_dockWidgetActiveState;
bool m_locked;
bool m_handleDockVisibilityChanges; //todo
};
FancyMainWindowPrivate::FancyMainWindowPrivate() :
m_locked(true), m_handleDockVisibilityChanges(true)
{
}
FancyMainWindow::FancyMainWindow(QWidget *parent)
: QMainWindow(parent),
m_locked(true),
m_handleDockVisibilityChanges(true)
FancyMainWindow::FancyMainWindow(QWidget *parent) :
QMainWindow(parent), d(new FancyMainWindowPrivate)
{
setProperty("panelwidget", true);
}
FancyMainWindow::~FancyMainWindow()
{
delete d;
}
QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget)
{
QDockWidget *dockWidget = new QDockWidget(widget->windowTitle(), this);
......@@ -54,8 +74,8 @@ QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget)
this, SLOT(onDockVisibilityChange(bool)));
connect(dockWidget, SIGNAL(topLevelChanged(bool)),
this, SLOT(onTopLevelChanged()));
m_dockWidgets.append(dockWidget);
m_dockWidgetActiveState.append(true);
d->m_dockWidgets.append(dockWidget);
d->m_dockWidgetActiveState.append(true);
updateDockWidget(dockWidget);
return dockWidget;
}
......@@ -63,12 +83,12 @@ QDockWidget *FancyMainWindow::addDockForWidget(QWidget *widget)
void FancyMainWindow::updateDockWidget(QDockWidget *dockWidget)
{
const QDockWidget::DockWidgetFeatures features =
(m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable
(d->m_locked) ? QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable
: QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable;
QWidget *titleBarWidget = dockWidget->titleBarWidget();
if (m_locked && !titleBarWidget && !dockWidget->isFloating())
if (d->m_locked && !titleBarWidget && !dockWidget->isFloating())
titleBarWidget = new QWidget(dockWidget);
else if ((!m_locked || dockWidget->isFloating()) && titleBarWidget) {
else if ((!d->m_locked || dockWidget->isFloating()) && titleBarWidget) {
delete titleBarWidget;
titleBarWidget = 0;
}
......@@ -87,11 +107,11 @@ void FancyMainWindow::onDockActionTriggered()
void FancyMainWindow::onDockVisibilityChange(bool visible)
{
if (!m_handleDockVisibilityChanges)
if (!d->m_handleDockVisibilityChanges)
return;
QDockWidget *dockWidget = qobject_cast<QDockWidget *>(sender());
int index = m_dockWidgets.indexOf(dockWidget);
m_dockWidgetActiveState[index] = visible;
int index = d->m_dockWidgets.indexOf(dockWidget);
d->m_dockWidgetActiveState[index] = visible;
}
void FancyMainWindow::onTopLevelChanged()
......@@ -102,18 +122,18 @@ void FancyMainWindow::onTopLevelChanged()
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();
d->m_handleDockVisibilityChanges = true;
for (int i = 0; i < d->m_dockWidgets.size(); ++i)
d->m_dockWidgetActiveState[i] = d->m_dockWidgets[i]->isVisible();
} else {
m_handleDockVisibilityChanges = false;
d->m_handleDockVisibilityChanges = false;
}
}
void FancyMainWindow::setLocked(bool locked)
{
m_locked = locked;
foreach (QDockWidget *dockWidget, m_dockWidgets) {
d->m_locked = locked;
foreach (QDockWidget *dockWidget, d->m_dockWidgets) {
updateDockWidget(dockWidget);
}
}
......@@ -132,15 +152,15 @@ void FancyMainWindow::showEvent(QShowEvent *event)
void FancyMainWindow::handleVisibilityChanged(bool visible)
{
m_handleDockVisibilityChanges = false;
for (int i = 0; i < m_dockWidgets.size(); ++i) {
QDockWidget *dockWidget = m_dockWidgets.at(i);
d->m_handleDockVisibilityChanges = false;
for (int i = 0; i < d->m_dockWidgets.size(); ++i) {
QDockWidget *dockWidget = d->m_dockWidgets.at(i);
if (dockWidget->isFloating()) {
dockWidget->setVisible(visible && m_dockWidgetActiveState.at(i));
dockWidget->setVisible(visible && d->m_dockWidgetActiveState.at(i));
}
}
if (visible)
m_handleDockVisibilityChanges = true;
d->m_handleDockVisibilityChanges = true;
}
void FancyMainWindow::saveSettings(QSettings *settings) const
......@@ -165,11 +185,11 @@ void FancyMainWindow::restoreSettings(QSettings *settings)
QHash<QString, QVariant> FancyMainWindow::saveSettings() const
{
QHash<QString, QVariant> settings;
settings["State"] = saveState();
settings["Locked"] = m_locked;
for (int i = 0; i < m_dockWidgetActiveState.count(); ++i) {
settings[m_dockWidgets.at(i)->objectName()] =
m_dockWidgetActiveState.at(i);
settings.insert(QLatin1String("State"), saveState());
settings.insert(QLatin1String("Locked"), d->m_locked);
for (int i = 0; i < d->m_dockWidgetActiveState.count(); ++i) {
settings.insert(d->m_dockWidgets.at(i)->objectName(),
d->m_dockWidgetActiveState.at(i));
}
return settings;
}
......@@ -179,8 +199,20 @@ void FancyMainWindow::restoreSettings(const QHash<QString, QVariant> &settings)
QByteArray ba = settings.value("State", QByteArray()).toByteArray();
if (!ba.isEmpty())
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();
d->m_locked = settings.value("Locked", true).toBool();
for (int i = 0; i < d->m_dockWidgetActiveState.count(); ++i) {
d->m_dockWidgetActiveState[i] = settings.value(d->m_dockWidgets.at(i)->objectName(), false).toBool();
}
}
QList<QDockWidget *> FancyMainWindow::dockWidgets() const
{
return d->m_dockWidgets;
}
bool FancyMainWindow::isLocked() const
{
return d->m_locked;
}
} // namespace Utils
......@@ -32,9 +32,6 @@
#include "utils_global.h"
#include <QtCore/QList>
#include <QtCore/QHash>
#include <QtGui/QMainWindow>
QT_BEGIN_NAMESPACE
......@@ -43,18 +40,21 @@ QT_END_NAMESPACE
namespace Utils {
struct FancyMainWindowPrivate;
class QTCREATOR_UTILS_EXPORT FancyMainWindow : public QMainWindow
{
Q_OBJECT
public:
FancyMainWindow(QWidget *parent = 0);
explicit FancyMainWindow(QWidget *parent = 0);
virtual ~FancyMainWindow();
QDockWidget *addDockForWidget(QWidget *widget);
QList<QDockWidget *> dockWidgets() const { return m_dockWidgets; }
QList<QDockWidget *> dockWidgets() const;
void setTrackingEnabled(bool enabled);
bool isLocked() const { return m_locked; }
bool isLocked() const;
void saveSettings(QSettings *settings) const;
void restoreSettings(QSettings *settings);
......@@ -77,10 +77,7 @@ private:
void updateDockWidget(QDockWidget *dockWidget);
void handleVisibilityChanged(bool visible);
QList<QDockWidget *> m_dockWidgets;
QList<bool> m_dockWidgetActiveState;
bool m_locked;
bool m_handleDockVisibilityChanges; //todo
FancyMainWindowPrivate *d;
};
} // namespace Utils
......
......@@ -38,17 +38,19 @@
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/icorelistener.h>
#include <coreplugin/editormanager/ieditor.h>
#include <extensionsystem/pluginmanager.h>
#include <QtCore/QPair>
#include <QtCore/QFileInfo>
#include <QtGui/QAction>
#include <QtCore/QStringList>
#include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QPlainTextEdit>
#include <QtGui/QStackedWidget>
#include <QtCore/QDebug>
namespace Core {
class EditorManager;
......@@ -59,6 +61,15 @@ enum {
namespace Internal {
class DesignModeCoreListener : public Core::ICoreListener
{
public:
DesignModeCoreListener(DesignMode* mode);
bool coreAboutToClose();
private:
DesignMode *m_mode;
};
DesignModeCoreListener::DesignModeCoreListener(DesignMode *mode) :
m_mode(mode)
{
......@@ -72,27 +83,50 @@ bool DesignModeCoreListener::coreAboutToClose()
} // namespace Internal
struct DesignEditorInfo {
int widgetIndex;
QStringList mimeTypes;
bool preferredMode;
QWidget *widget;
};
struct DesignModePrivate {
explicit DesignModePrivate(DesignMode *q, EditorManager *editorManager);
Internal::DesignModeCoreListener *m_coreListener;
QWeakPointer<Core::IEditor> m_currentEditor;
bool m_isActive;
QList<DesignEditorInfo*> m_editors;
EditorManager *m_editorManager;
QStackedWidget *m_stackWidget;
};
DesignModePrivate::DesignModePrivate(DesignMode *q, EditorManager *editorManager) :
m_coreListener(new Internal::DesignModeCoreListener(q)),
m_isActive(false),
m_editorManager(editorManager),
m_stackWidget(new QStackedWidget)
{
}
DesignMode::DesignMode(EditorManager *editorManager) :
IMode(),
m_coreListener(new Internal::DesignModeCoreListener(this)),
m_isActive(false),
m_editorManager(editorManager),
m_stackWidget(new QStackedWidget)
IMode(), d(new DesignModePrivate(this, editorManager))
{
setEnabled(false);
ExtensionSystem::PluginManager::instance()->addObject(m_coreListener);
ExtensionSystem::PluginManager::instance()->addObject(d->m_coreListener);
connect(editorManager, SIGNAL(currentEditorChanged(Core::IEditor*)),
this, SLOT(currentEditorChanged(Core::IEditor*)));
//updateActions();
}
DesignMode::~DesignMode()
{
ExtensionSystem::PluginManager::instance()->removeObject(m_coreListener);
delete m_coreListener;
ExtensionSystem::PluginManager::instance()->removeObject(d->m_coreListener);
delete d->m_coreListener;
qDeleteAll(m_editors);
qDeleteAll(d->m_editors);
delete d;
}
QList<int> DesignMode::context() const
......@@ -104,7 +138,7 @@ QList<int> DesignMode::context() const
QWidget *DesignMode::widget()
{
return m_stackWidget;
return d->m_stackWidget;
}
QString DesignMode::displayName() const
......@@ -130,29 +164,29 @@ QString DesignMode::id() const
QStringList DesignMode::registeredMimeTypes() const
{
QStringList rc;
foreach(const DesignEditorInfo *i, m_editors)
foreach(const DesignEditorInfo *i, d->m_editors)
rc += i->mimeTypes;
return rc;
}
void DesignMode::registerDesignWidget(QWidget *widget, const QStringList &mimeTypes, bool preferDesignMode)
{
int index = m_stackWidget->addWidget(widget);
int index = d->m_stackWidget->addWidget(widget);
DesignEditorInfo *info = new DesignEditorInfo;
info->preferredMode = preferDesignMode;
info->mimeTypes = mimeTypes;
info->widgetIndex = index;
info->widget = widget;
m_editors.append(info);
d->m_editors.append(info);
}
void DesignMode::unregisterDesignWidget(QWidget *widget)
{
m_stackWidget->removeWidget(widget);
foreach(DesignEditorInfo *info, m_editors) {
d->m_stackWidget->removeWidget(widget);
foreach(DesignEditorInfo *info, d->m_editors) {
if (info->widget == widget) {
m_editors.removeAll(info);
d->m_editors.removeAll(info);
break;
}
}
......@@ -174,10 +208,10 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
foreach(DesignEditorInfo *editorInfo, m_editors) {
foreach(DesignEditorInfo *editorInfo, d->m_editors) {
foreach(QString mime, editorInfo->mimeTypes) {
if (mime == mimeType) {
m_stackWidget->setCurrentIndex(editorInfo->widgetIndex);
d->m_stackWidget->setCurrentIndex(editorInfo->widgetIndex);
mimeEditorAvailable = true;
setEnabled(true);
if (editorInfo->preferredMode && core->modeManager()->currentMode() != this) {
......@@ -200,23 +234,23 @@ void DesignMode::currentEditorChanged(Core::IEditor *editor)
core->modeManager()->activateMode(Constants::MODE_EDIT);
}
if (m_currentEditor.data() == editor)
if (d->m_currentEditor.data() == editor)
return;
if (m_currentEditor)
disconnect(m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
if (d->m_currentEditor)
disconnect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
m_currentEditor = QWeakPointer<Core::IEditor>(editor);
d->m_currentEditor = QWeakPointer<Core::IEditor>(editor);
if (m_currentEditor)
connect(m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
if (d->m_currentEditor)
connect(d->m_currentEditor.data(), SIGNAL(changed()), this, SLOT(updateActions()));
emit actionsUpdated(m_currentEditor.data());
emit actionsUpdated(d->m_currentEditor.data());
}
void DesignMode::updateActions()
{
emit actionsUpdated(m_currentEditor.data());
emit actionsUpdated(d->m_currentEditor.data());
}
} // namespace Core
......@@ -31,34 +31,13 @@
#define DESIGNMODE_H
#include <coreplugin/imode.h>
#include <coreplugin/icorelistener.h>
#include <coreplugin/editormanager/ieditor.h>
#include <QWeakPointer>
#include <QPair>
#include <QStringList>
QT_BEGIN_NAMESPACE
class QAction;
class QStackedWidget;
QT_END_NAMESPACE
namespace Core {
class EditorManager;
class DesignMode;
class IEditor;
namespace Internal {
class DesignModeCoreListener : public Core::ICoreListener
{
Q_OBJECT
public:
DesignModeCoreListener(DesignMode* mode);
bool coreAboutToClose();
private:
DesignMode *m_mode;
};
class DesignModeCoreListener;
} // namespace Internal
/**
......@@ -67,13 +46,16 @@ private:
* and giving a list of mimetypes that the editor understands, as well as an instance
* to the main editor widget itself.
*/
struct DesignModePrivate;
class CORE_EXPORT DesignMode : public Core::IMode
{
Q_OBJECT
public:
DesignMode(EditorManager *editorManager);
~DesignMode();
explicit DesignMode(EditorManager *editorManager);
virtual ~DesignMode();
void registerDesignWidget(QWidget *widget, const QStringList &mimeTypes,
bool preferDesignMode = false);
......@@ -99,26 +81,10 @@ private slots:
void updateActions();
private:
Internal::DesignModeCoreListener *m_coreListener;
QWeakPointer<Core::IEditor> m_currentEditor;
bool m_isActive;
struct DesignEditorInfo {
int widgetIndex;
QStringList mimeTypes;
bool preferredMode;
QWidget *widget;
};
QList<DesignEditorInfo*> m_editors;
EditorManager *m_editorManager;
QStackedWidget *m_stackWidget;
DesignModePrivate *d;
friend class Internal::DesignModeCoreListener;
};
} // namespace Core
#endif // DESIGNMODE_H
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