Commit e367a39c authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: adding interface to customize toolbar buttons

WidgetInfo contains now a factory for the toolbar buttons.
The ownership of the factory is taken by the SideBarItem.

Change-Id: Iffa32359cd3f0cb5b378abc5371d810aee31649c
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
parent c9879b8f
......@@ -249,7 +249,7 @@ void DebugView::rewriterEndTransaction()
WidgetInfo DebugView::widgetInfo()
{
return createWidgetInfo(m_debugViewWidget.data(), QLatin1String("DebugView"), WidgetInfo::LeftPane, 0, tr("Debug View"));
return createWidgetInfo(m_debugViewWidget.data(), 0, QLatin1String("DebugView"), WidgetInfo::LeftPane, 0, tr("Debug View"));
}
bool DebugView::hasWidget() const
......
......@@ -277,7 +277,7 @@ void FormEditorView::bindingPropertiesChanged(const QList<BindingProperty>& prop
WidgetInfo FormEditorView::widgetInfo()
{
return createWidgetInfo(m_formEditorWidget.data(), "FormEditor", WidgetInfo::CentralPane, 0, tr("Form Editor"));
return createWidgetInfo(m_formEditorWidget.data(), 0, "FormEditor", WidgetInfo::CentralPane, 0, tr("Form Editor"));
}
FormEditorWidget *FormEditorView::formEditorWidget()
......
......@@ -53,7 +53,11 @@ WidgetInfo ItemLibraryView::widgetInfo()
if (m_widget.isNull())
m_widget = new ItemLibraryWidget;
return createWidgetInfo(m_widget.data(), QLatin1String("Library"), WidgetInfo::LeftPane, 0);
return createWidgetInfo(m_widget.data(),
new WidgetInfo::ToolBarWidgetDefaultFactory<ItemLibraryWidget>(m_widget.data()),
QLatin1String("Library"),
WidgetInfo::LeftPane,
0);
}
void ItemLibraryView::modelAttached(Model *model)
......
......@@ -106,7 +106,11 @@ bool NavigatorView::hasWidget() const
WidgetInfo NavigatorView::widgetInfo()
{
return createWidgetInfo(m_widget.data(), QLatin1String("Navigator"), WidgetInfo::LeftPane, 0);
return createWidgetInfo(m_widget.data(),
new WidgetInfo::ToolBarWidgetDefaultFactory<NavigatorWidget>(m_widget.data()),
QLatin1String("Navigator"),
WidgetInfo::LeftPane,
0);
}
void NavigatorView::modelAttached(Model *model)
......
......@@ -968,7 +968,7 @@ bool PropertyEditor::hasWidget() const
WidgetInfo PropertyEditor::widgetInfo()
{
return createWidgetInfo(m_stackedWidget, QLatin1String("Properties"), WidgetInfo::RightPane, 0);
return createWidgetInfo(m_stackedWidget, 0, QLatin1String("Properties"), WidgetInfo::RightPane, 0);
}
void PropertyEditor::actualStateChanged(const ModelNode &node)
......
......@@ -62,7 +62,7 @@ StatesEditorView::StatesEditorView(QObject *parent) :
WidgetInfo StatesEditorView::widgetInfo()
{
return createWidgetInfo(m_statesEditorWidget.data(), "StatesEditor", WidgetInfo::TopPane, 0, tr("States Editor"));
return createWidgetInfo(m_statesEditorWidget.data(), 0, "StatesEditor", WidgetInfo::TopPane, 0, tr("States Editor"));
}
void StatesEditorView::removeState(int nodeId)
......
......@@ -42,6 +42,7 @@
QT_BEGIN_NAMESPACE
class QStyle;
class QToolButton;
QT_END_NAMESPACE
namespace QmlDesigner {
......@@ -58,7 +59,32 @@ class QmlModelView;
class NodeInstanceView;
class RewriterView;
struct WidgetInfo {
class WidgetInfo {
public:
class ToolBarWidgetFactoryInterface {
public:
ToolBarWidgetFactoryInterface()
{}
virtual QList<QToolButton*> createToolBarWidgets() = 0;
};
template <class T>
class ToolBarWidgetDefaultFactory : public ToolBarWidgetFactoryInterface {
public:
ToolBarWidgetDefaultFactory(T *t ) : m_t(t)
{}
QList<QToolButton*> createToolBarWidgets()
{
return m_t->createToolBarWidgets();
}
private:
T * m_t;
};
enum PlacementHint {
NoPane,
LeftPane,
......@@ -68,11 +94,18 @@ struct WidgetInfo {
CentralPane // not used
};
WidgetInfo()
: widget(0),
toolBarWidgetFactory(0)
{
}
QString uniqueId;
QString tabName;
QWidget *widget;
int placementPriority;
PlacementHint placementHint;
ToolBarWidgetFactoryInterface *toolBarWidgetFactory;
};
......@@ -205,6 +238,7 @@ protected:
void setModel(Model * model);
void removeModel();
static WidgetInfo createWidgetInfo(QWidget *widget = 0,
WidgetInfo::ToolBarWidgetFactoryInterface *toolBarWidgetFactory = 0,
const QString &uniqueId = QString(),
WidgetInfo::PlacementHint placementHint = WidgetInfo::NoPane,
int placementPriority = 0,
......
......@@ -119,6 +119,7 @@ void AbstractView::removeModel()
}
WidgetInfo AbstractView::createWidgetInfo(QWidget *widget,
WidgetInfo::ToolBarWidgetFactoryInterface *toolBarWidgetFactory,
const QString &uniqueId,
WidgetInfo::PlacementHint placementHint,
int placementPriority,
......@@ -127,6 +128,7 @@ WidgetInfo AbstractView::createWidgetInfo(QWidget *widget,
WidgetInfo widgetInfo;
widgetInfo.widget = widget;
widgetInfo.toolBarWidgetFactory = toolBarWidgetFactory;
widgetInfo.uniqueId = uniqueId;
widgetInfo.placementHint = placementHint;
widgetInfo.placementPriority = placementPriority;
......
......@@ -149,25 +149,35 @@ QList<QToolButton *> ItemLibrarySideBarItem::createToolBarWidgets()
return qobject_cast<ItemLibraryWidget*>(widget())->createToolBarWidgets();
}
class NavigatorSideBarItem : public Core::SideBarItem
class DesignerSideBarItem : public Core::SideBarItem
{
public:
explicit NavigatorSideBarItem(QWidget *widget, const QString &id);
virtual ~NavigatorSideBarItem();
explicit DesignerSideBarItem(QWidget *widget, WidgetInfo::ToolBarWidgetFactoryInterface *createToolBarWidgets, const QString &id);
virtual ~DesignerSideBarItem();
virtual QList<QToolButton *> createToolBarWidgets();
};
NavigatorSideBarItem::NavigatorSideBarItem(QWidget *widget, const QString &id) : Core::SideBarItem(widget, id) {}
private:
WidgetInfo::ToolBarWidgetFactoryInterface *m_toolBarWidgetFactory;
};
NavigatorSideBarItem::~NavigatorSideBarItem()
DesignerSideBarItem::DesignerSideBarItem(QWidget *widget, WidgetInfo::ToolBarWidgetFactoryInterface *toolBarWidgetFactory, const QString &id)
: Core::SideBarItem(widget, id) , m_toolBarWidgetFactory(toolBarWidgetFactory)
{
}
DesignerSideBarItem::~DesignerSideBarItem()
{
delete m_toolBarWidgetFactory;
}
QList<QToolButton *> NavigatorSideBarItem::createToolBarWidgets()
QList<QToolButton *> DesignerSideBarItem::createToolBarWidgets()
{
return qobject_cast<NavigatorWidget*>(widget())->createToolBarWidgets();
if (m_toolBarWidgetFactory)
return m_toolBarWidgetFactory->createToolBarWidgets();
return QList<QToolButton *>();
}
void DocumentWarningWidget::goToError()
......@@ -357,13 +367,13 @@ void DesignModeWidget::setup()
foreach (const WidgetInfo &widgetInfo, viewManager().widgetInfos()) {
if (widgetInfo.placementHint == widgetInfo.LeftPane) {
Core::SideBarItem *sideBarItem = new NavigatorSideBarItem(widgetInfo.widget, widgetInfo.uniqueId);
Core::SideBarItem *sideBarItem = new DesignerSideBarItem(widgetInfo.widget, widgetInfo.toolBarWidgetFactory, widgetInfo.uniqueId);
sideBarItems.append(sideBarItem);
leftSideBarItems.append(sideBarItem);
}
if (widgetInfo.placementHint == widgetInfo.RightPane) {
Core::SideBarItem *sideBarItem = new NavigatorSideBarItem(widgetInfo.widget, widgetInfo.uniqueId);
Core::SideBarItem *sideBarItem = new DesignerSideBarItem(widgetInfo.widget, widgetInfo.toolBarWidgetFactory, widgetInfo.uniqueId);
sideBarItems.append(sideBarItem);
rightSideBarItems.append(sideBarItem);
}
......
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