Commit 54da4378 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Add custom tool interface



Change-Id: I71a1063a1de3e4bb445bf9f8faa5553da3b5c4ab
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent ae409f8b
#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 ...@@ -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) void AbstractFormEditorTool::showContextMenu(QGraphicsSceneMouseEvent *event)
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "formeditoritem.h" #include "formeditoritem.h"
#include <qmldesignercorelib_global.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QGraphicsItem; class QGraphicsItem;
QT_END_NAMESPACE QT_END_NAMESPACE
...@@ -40,7 +42,7 @@ namespace QmlDesigner { ...@@ -40,7 +42,7 @@ namespace QmlDesigner {
class FormEditorView; class FormEditorView;
class AbstractFormEditorTool class QMLDESIGNERCORE_EXPORT AbstractFormEditorTool
{ {
public: public:
......
...@@ -33,7 +33,8 @@ SOURCES += formeditoritem.cpp \ ...@@ -33,7 +33,8 @@ SOURCES += formeditoritem.cpp \
formeditorgraphicsview.cpp \ formeditorgraphicsview.cpp \
numberseriesaction.cpp \ numberseriesaction.cpp \
lineeditaction.cpp \ lineeditaction.cpp \
formeditorcrumblebar.cpp formeditorcrumblebar.cpp \
abstractcustomtool.cpp
HEADERS += formeditorscene.h \ HEADERS += formeditorscene.h \
formeditorwidget.h \ formeditorwidget.h \
formeditoritem.h \ formeditoritem.h \
...@@ -65,5 +66,6 @@ HEADERS += formeditorscene.h \ ...@@ -65,5 +66,6 @@ HEADERS += formeditorscene.h \
formeditorgraphicsview.h \ formeditorgraphicsview.h \
numberseriesaction.h \ numberseriesaction.h \
lineeditaction.h \ lineeditaction.h \
formeditorcrumblebar.h formeditorcrumblebar.h \
abstractcustomtool.h
RESOURCES += formeditor.qrc RESOURCES += formeditor.qrc
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "formeditoritem.h" #include "formeditoritem.h"
#include "formeditorscene.h" #include "formeditorscene.h"
#include "toolbox.h" #include "toolbox.h"
#include "abstractcustomtool.h"
#include <designmodecontext.h> #include <designmodecontext.h>
#include <rewritertransaction.h> #include <rewritertransaction.h>
...@@ -96,7 +97,7 @@ FormEditorView::~FormEditorView() ...@@ -96,7 +97,7 @@ FormEditorView::~FormEditorView()
delete m_dragTool; delete m_dragTool;
m_dragTool = 0; m_dragTool = 0;
qDeleteAll(m_toolList); qDeleteAll(m_customToolList);
// delete scene after tools to prevent double deletion // delete scene after tools to prevent double deletion
// of items // of items
...@@ -413,9 +414,31 @@ void FormEditorView::changeToTransformTools() ...@@ -413,9 +414,31 @@ void FormEditorView::changeToTransformTools()
changeToSelectionTool(); 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*/) void FormEditorView::nodeSlidedToIndex(const NodeListProperty &listProperty, int /*newIndex*/, int /*oldIndex*/)
......
...@@ -49,6 +49,7 @@ class FormEditorScene; ...@@ -49,6 +49,7 @@ class FormEditorScene;
class NodeInstanceView; class NodeInstanceView;
class AbstractFormEditorTool; class AbstractFormEditorTool;
class AbstractCustomTool;
class MoveTool; class MoveTool;
class SelectionTool; class SelectionTool;
class ResizeTool; class ResizeTool;
...@@ -98,9 +99,9 @@ public: ...@@ -98,9 +99,9 @@ public:
void changeToSelectionTool(QGraphicsSceneMouseEvent *event); void changeToSelectionTool(QGraphicsSceneMouseEvent *event);
void changeToResizeTool(); void changeToResizeTool();
void changeToTransformTools(); void changeToTransformTools();
void changeToCustomTool(const ModelNode &modelNode);
void registerTool(AbstractCustomTool *tool);
void registerTool(AbstractFormEditorTool *tool);
void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex); void nodeSlidedToIndex(const NodeListProperty &listProperty, int newIndex, int oldIndex);
void auxiliaryDataChanged(const ModelNode &node, const PropertyName &name, const QVariant &data) QTC_OVERRIDE; void auxiliaryDataChanged(const ModelNode &node, const PropertyName &name, const QVariant &data) QTC_OVERRIDE;
...@@ -140,7 +141,7 @@ private: //functions ...@@ -140,7 +141,7 @@ private: //functions
private: //variables private: //variables
QWeakPointer<FormEditorWidget> m_formEditorWidget; QWeakPointer<FormEditorWidget> m_formEditorWidget;
QWeakPointer<FormEditorScene> m_scene; QWeakPointer<FormEditorScene> m_scene;
QList<AbstractFormEditorTool*> m_toolList; QList<AbstractCustomTool*> m_customToolList;
MoveTool *m_moveTool; MoveTool *m_moveTool;
SelectionTool *m_selectionTool; SelectionTool *m_selectionTool;
ResizeTool *m_resizeTool; ResizeTool *m_resizeTool;
......
...@@ -72,7 +72,7 @@ public: ...@@ -72,7 +72,7 @@ public:
void resetPropertyEditorView(); void resetPropertyEditorView();
void registerFormEditorTool(AbstractFormEditorTool *tool); // takes ownership void registerFormEditorTool(AbstractCustomTool *tool); // takes ownership
void registerView(AbstractView *view); void registerView(AbstractView *view);
QList<WidgetInfo> widgetInfos(); QList<WidgetInfo> widgetInfos();
......
...@@ -89,7 +89,7 @@ void ViewManager::resetPropertyEditorView() ...@@ -89,7 +89,7 @@ void ViewManager::resetPropertyEditorView()
m_propertyEditorView.resetView(); m_propertyEditorView.resetView();
} }
void ViewManager::registerFormEditorTool(AbstractFormEditorTool *tool) void ViewManager::registerFormEditorTool(AbstractCustomTool *tool)
{ {
m_formEditorView.registerTool(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