Commit d28dc2d9 authored by Pasi Hirvonen's avatar Pasi Hirvonen Committed by dt
Browse files

coreplugin: Make RightPaneWidget more widely usable.

RightPaneWidget now has setWidget() and is no longer intimately tied
to the help plugin. Help plugin now uses setWidget().

Reviewed-By: dt
parent e48cce07
......@@ -34,7 +34,6 @@
#include "rightpane.h"
#include <coreplugin/modemanager.h>
#include <extensionsystem/pluginmanager.h>
#include <QtCore/QSettings>
......@@ -129,53 +128,38 @@ void RightPanePlaceHolder::currentModeChanged(Core::IMode *mode)
RightPaneWidget *RightPaneWidget::m_instance = 0;
RightPaneWidget::RightPaneWidget()
: m_shown(true), m_width(0)
: m_shown(true), m_width(0), m_widget(0)
{
m_instance = this;
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
setLayout(layout);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
BaseRightPaneWidget *rpw = pm->getObject<BaseRightPaneWidget>();
if (rpw) {
layout->addWidget(rpw->widget());
}
connect(pm, SIGNAL(objectAdded(QObject *)),
this, SLOT(objectAdded(QObject *)));
connect(pm, SIGNAL(aboutToRemoveObject(QObject *)),
this, SLOT(aboutToRemoveObject(QObject *)));
}
RightPaneWidget::~RightPaneWidget()
{
clearWidget();
m_instance = 0;
}
void RightPaneWidget::objectAdded(QObject *obj)
RightPaneWidget *RightPaneWidget::instance()
{
BaseRightPaneWidget *rpw = qobject_cast<BaseRightPaneWidget *>(obj);
if (rpw) {
layout()->addWidget(rpw->widget());
setFocusProxy(rpw->widget());
}
return m_instance;
}
void RightPaneWidget::aboutToRemoveObject(QObject *obj)
void RightPaneWidget::setWidget(QWidget *widget)
{
BaseRightPaneWidget *rpw = qobject_cast<BaseRightPaneWidget *>(obj);
if (rpw) {
delete rpw->widget();
clearWidget();
m_widget = widget;
if (m_widget) {
m_widget->setParent(this);
layout()->addWidget(m_widget);
setFocusProxy(m_widget);
m_widget->show();
}
}
RightPaneWidget *RightPaneWidget::instance()
{
return m_instance;
}
int RightPaneWidget::storedWidth()
{
return m_width;
......@@ -227,21 +211,11 @@ bool RightPaneWidget::isShown()
return m_shown;
}
/////
// BaseRightPaneWidget
/////
BaseRightPaneWidget::BaseRightPaneWidget(QWidget *widget)
{
m_widget = widget;
}
BaseRightPaneWidget::~BaseRightPaneWidget()
{
}
QWidget *BaseRightPaneWidget::widget() const
void RightPaneWidget::clearWidget()
{
return m_widget;
if (m_widget) {
m_widget->hide();
m_widget->setParent(0);
m_widget = 0;
}
}
......@@ -47,13 +47,6 @@ namespace Core {
class IMode;
class RightPaneWidget;
// TODO: The right pane works only for the help plugin atm. It can't cope
// with more than one plugin publishing objects they want in the right pane
// For that the API would need to be different. (Might be that instead of
// adding objects to the pool, there should be a method
// RightPaneWidget::setWidget(QWidget *w) Anyway if a second plugin wants to
// show something there, redesign this API
class CORE_EXPORT RightPanePlaceHolder : public QWidget
{
friend class Core::RightPaneWidget;
......@@ -73,21 +66,6 @@ private:
static RightPanePlaceHolder* m_current;
};
class CORE_EXPORT BaseRightPaneWidget : public QObject
{
Q_OBJECT
public:
BaseRightPaneWidget(QWidget *widget);
~BaseRightPaneWidget();
QWidget *widget() const;
private:
QWidget *m_widget;
};
class CORE_EXPORT RightPaneWidget : public QWidget
{
Q_OBJECT
......@@ -104,18 +82,18 @@ public:
static RightPaneWidget *instance();
void setWidget(QWidget *widget);
int storedWidth();
protected:
void resizeEvent(QResizeEvent *);
private slots:
void objectAdded(QObject *obj);
void aboutToRemoveObject(QObject *obj);
private:
void clearWidget();
bool m_shown;
int m_width;
QWidget *m_widget;
static RightPaneWidget *m_instance;
};
......
......@@ -554,8 +554,6 @@ void HelpPlugin::createRightPaneContextViewer()
layout->addWidget(toolButton(close));
QWidget *rightPaneSideBar = new QWidget;
addAutoReleasedObject(new Core::BaseRightPaneWidget(rightPaneSideBar));
m_helpViewerForSideBar = new HelpViewer(qreal(0.0), rightPaneSideBar);
connect(m_helpViewerForSideBar, SIGNAL(openFindToolBar()), this,
SLOT(openFindToolBar()));
......@@ -834,6 +832,7 @@ HelpViewer* HelpPlugin::viewerForContextMode()
}
if (placeHolder && showSideBySide) {
RightPaneWidget::instance()->setWidget(m_helpViewerForSideBar->parentWidget());
RightPaneWidget::instance()->setShown(true);
createRightPaneContextViewer();
return m_helpViewerForSideBar;
......
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