Commit b8d8c9c6 authored by Marco Bubke's avatar Marco Bubke Committed by Thomas Hartmann
Browse files

QmlDesigner: Add custom tool interface



Change-Id: I71a1063a1de3e4bb445bf9f8faa5553da3b5c4ab
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
(cherry picked from commit 54da4378

)
Reviewed-by: default avatarMarco Bubke <marco.bubke@digia.com>
parent 5afbdb6e
#include "abstractcustomtool.h"
#include "formeditorview.h"
namespace QmlDesigner {
AbstractCustomTool::AbstractCustomTool(FormEditorView* view)
: AbstractFormEditorTool(view)
{
}
void AbstractCustomTool::selectedItemsChanged(const QList<FormEditorItem *> &itemList)
{
view()->changeToSelectionTool();
}
} // namespace QmlDesigner
#ifndef QMLDESIGNER_ABSTRACTSINGLESELECTIONTOOL_H
#define QMLDESIGNER_ABSTRACTSINGLESELECTIONTOOL_H
#include "abstractformeditortool.h"
namespace QmlDesigner {
class QMLDESIGNERCORE_EXPORT AbstractCustomTool : public QmlDesigner::AbstractFormEditorTool
{
public:
AbstractCustomTool(FormEditorView* view);
void selectedItemsChanged(const QList<FormEditorItem *> &itemList);
virtual bool wantHandleItem(const ModelNode &modelNode) const = 0;
};
} // namespace QmlDesigner
#endif // QMLDESIGNER_ABSTRACTSINGLESELECTIONTOOL_H
......@@ -204,8 +204,11 @@ void AbstractFormEditorTool::mouseReleaseEvent(const QList<QGraphicsItem*> & /*i
}
}
void AbstractFormEditorTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &, QGraphicsSceneMouseEvent *)
void AbstractFormEditorTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *)
{
FormEditorItem *formEditorItem = topFormEditorItem(itemList);
if (formEditorItem)
view()->changeToCustomTool(formEditorItem->qmlItemNode().modelNode());
}
void AbstractFormEditorTool::showContextMenu(QGraphicsSceneMouseEvent *event)
......
......@@ -32,6 +32,8 @@
#include "formeditoritem.h"
#include <qmldesignercorelib_global.h>
QT_BEGIN_NAMESPACE
class QGraphicsItem;
QT_END_NAMESPACE
......@@ -40,7 +42,7 @@ namespace QmlDesigner {
class FormEditorView;
class AbstractFormEditorTool
class QMLDESIGNERCORE_EXPORT AbstractFormEditorTool
{
public:
......
......@@ -33,7 +33,8 @@ SOURCES += formeditoritem.cpp \
formeditorgraphicsview.cpp \
numberseriesaction.cpp \
lineeditaction.cpp \
formeditorcrumblebar.cpp
formeditorcrumblebar.cpp \
abstractcustomtool.cpp
HEADERS += formeditorscene.h \
formeditorwidget.h \
formeditoritem.h \
......@@ -65,5 +66,6 @@ HEADERS += formeditorscene.h \
formeditorgraphicsview.h \
numberseriesaction.h \
lineeditaction.h \
formeditorcrumblebar.h
formeditorcrumblebar.h \
abstractcustomtool.h
RESOURCES += formeditor.qrc
......@@ -37,6 +37,7 @@
#include "formeditoritem.h"
#include "formeditorscene.h"
#include "toolbox.h"
#include "abstractcustomtool.h"
#include <designmodecontext.h>
#include <rewritertransaction.h>
......@@ -96,7 +97,7 @@ FormEditorView::~FormEditorView()
delete m_dragTool;
m_dragTool = 0;
qDeleteAll(m_toolList);
qDeleteAll(m_customToolList);
// delete scene after tools to prevent double deletion
// of items
......@@ -413,9 +414,31 @@ void FormEditorView::changeToTransformTools()
changeToSelectionTool();
}
void FormEditorView::registerTool(AbstractFormEditorTool *tool)
void FormEditorView::changeToCustomTool(const ModelNode &modelNode)
{
m_toolList.append(tool);
int handlingRank = 0;
AbstractCustomTool *selectedCustomTool;
foreach (AbstractCustomTool *customTool, m_customToolList) {
if (customTool->wantHandleItem(modelNode) > handlingRank) {
handlingRank = customTool->wantHandleItem(modelNode);
selectedCustomTool = customTool;
}
}
if (handlingRank > 0) {
m_scene->updateAllFormEditorItems();
m_currentTool->clear();
m_currentTool = selectedCustomTool;
m_currentTool->clear();
m_currentTool->setItems(scene()->itemsForQmlItemNodes(selectedQmlItemNodes()));
}
}
void FormEditorView::registerTool(AbstractCustomTool *tool)
{
m_customToolList.append(tool);
}
void FormEditorView::nodeSlidedToIndex(const NodeListProperty &listProperty, int /*newIndex*/, int /*oldIndex*/)
......
......@@ -49,6 +49,7 @@ class FormEditorScene;
class NodeInstanceView;
class AbstractFormEditorTool;
class AbstractCustomTool;
class MoveTool;
class SelectionTool;
class ResizeTool;
......@@ -98,9 +99,9 @@ public:
void changeToSelectionTool(QGraphicsSceneMouseEvent *event);
void changeToResizeTool();
void changeToTransformTools();
void changeToCustomTool(const ModelNode &modelNode);
void registerTool(AbstractFormEditorTool *tool);
void registerTool(AbstractCustomTool *tool);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void auxiliaryDataChanged(const ModelNode &node, const PropertyName &name, const QVariant &data) QTC_OVERRIDE;
......@@ -140,7 +141,7 @@ private: //functions
private: //variables
QWeakPointer<FormEditorWidget> m_formEditorWidget;
QWeakPointer<FormEditorScene> m_scene;
QList<AbstractFormEditorTool*> m_toolList;
QList<AbstractCustomTool*> m_customToolList;
MoveTool *m_moveTool;
SelectionTool *m_selectionTool;
ResizeTool *m_resizeTool;
......
......@@ -72,7 +72,7 @@ public:
void resetPropertyEditorView();
void registerFormEditorTool(AbstractFormEditorTool *tool); // takes ownership
void registerFormEditorTool(AbstractCustomTool *tool); // takes ownership
void registerView(AbstractView *view);
QList<WidgetInfo> widgetInfos();
......
......@@ -89,7 +89,7 @@ void ViewManager::resetPropertyEditorView()
m_propertyEditorView.resetView();
}
void ViewManager::registerFormEditorTool(AbstractFormEditorTool *tool)
void ViewManager::registerFormEditorTool(AbstractCustomTool *tool)
{
m_formEditorView.registerTool(tool);
}
......
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