forked from qt-creator/qt-creator
QmlDesigner.formeEditor: add handler for context menu
This patch adds a handler for a context menu to AbstactFormEditorTool. Also all the tools are patched to ignore right mouse keys for now. The ResizeManipulator gets an active property. Change-Id: I66b247ce6ae8e9f88517a1c1698432fb64f70da7 Reviewed-on: http://codereview.qt.nokia.com/770 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Marco Bubke <marco.bubke@nokia.com>
This commit is contained in:
committed by
Marco Bubke
parent
a9f53ec9c5
commit
d7ed0667e9
@@ -202,6 +202,21 @@ static inline bool checkIfNodeIsAView(const ModelNode &node)
|
||||
node.metaInfo().isSubclassOf("QtQuick.PathView", -1, -1));
|
||||
}
|
||||
|
||||
void AbstractFormEditorTool::mousePressEvent(const QList<QGraphicsItem*> & /*itemList*/, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::RightButton) {
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractFormEditorTool::mouseReleaseEvent(const QList<QGraphicsItem*> & /*itemList*/, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::RightButton) {
|
||||
showContextMenu(event);
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractFormEditorTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
FormEditorItem *formEditorItem = topFormEditorItem(itemList);
|
||||
@@ -218,4 +233,9 @@ void AbstractFormEditorTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractFormEditorTool::showContextMenu(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,11 +52,12 @@ public:
|
||||
virtual ~AbstractFormEditorTool();
|
||||
|
||||
virtual void mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event) = 0;
|
||||
QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event) = 0;
|
||||
virtual void mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event) = 0;
|
||||
QGraphicsSceneMouseEvent *event);
|
||||
|
||||
virtual void mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event);
|
||||
|
||||
@@ -97,6 +98,7 @@ protected:
|
||||
|
||||
virtual void selectedItemsChanged(const QList<FormEditorItem*> &itemList) = 0;
|
||||
|
||||
virtual void showContextMenu(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
FormEditorView *view() const;
|
||||
FormEditorScene* scene() const;
|
||||
|
||||
@@ -74,6 +74,7 @@ void MoveTool::clear()
|
||||
void MoveTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
if (itemList.isEmpty())
|
||||
return;
|
||||
m_movingItems = movingItems(items());
|
||||
@@ -82,15 +83,19 @@ void MoveTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
||||
|
||||
m_moveManipulator.setItems(m_movingItems);
|
||||
m_moveManipulator.begin(event->scenePos());
|
||||
}
|
||||
|
||||
AbstractFormEditorTool::mousePressEvent(itemList, event);
|
||||
}
|
||||
|
||||
void MoveTool::mouseMoveEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (m_moveManipulator.isActive()) {
|
||||
if (m_movingItems.isEmpty())
|
||||
return;
|
||||
|
||||
// m_selectionIndicator.hide();
|
||||
// m_selectionIndicator.hide();
|
||||
m_resizeIndicator.hide();
|
||||
|
||||
FormEditorItem *containerItem = containerFormEditorItem(itemList, m_movingItems);
|
||||
@@ -114,6 +119,7 @@ void MoveTool::mouseMoveEvent(const QList<QGraphicsItem*> &itemList,
|
||||
}
|
||||
|
||||
m_moveManipulator.update(event->scenePos(), useSnapping);
|
||||
}
|
||||
}
|
||||
|
||||
void MoveTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
|
||||
@@ -195,9 +201,10 @@ void MoveTool::keyReleaseEvent(QKeyEvent *keyEvent)
|
||||
}
|
||||
}
|
||||
|
||||
void MoveTool::mouseReleaseEvent(const QList<QGraphicsItem*> &/*itemList*/,
|
||||
void MoveTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (m_moveManipulator.isActive()) {
|
||||
if (m_movingItems.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -208,7 +215,7 @@ void MoveTool::mouseReleaseEvent(const QList<QGraphicsItem*> &/*itemList*/,
|
||||
|
||||
m_moveManipulator.end(beginPoint);
|
||||
|
||||
// m_selectionIndicator.show();
|
||||
// m_selectionIndicator.show();
|
||||
m_resizeIndicator.show();
|
||||
m_movingItems.clear();
|
||||
|
||||
@@ -220,6 +227,9 @@ void MoveTool::mouseReleaseEvent(const QList<QGraphicsItem*> &/*itemList*/,
|
||||
m_resizeIndicator.show();
|
||||
m_movingItems.clear();
|
||||
}
|
||||
}
|
||||
|
||||
AbstractFormEditorTool::mouseReleaseEvent(itemList, event);
|
||||
}
|
||||
|
||||
void MoveTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *event)
|
||||
|
||||
@@ -50,7 +50,8 @@ ResizeManipulator::ResizeManipulator(LayerItem *layerItem, FormEditorView *view)
|
||||
m_beginRightMargin(0.0),
|
||||
m_beginBottomMargin(0.0),
|
||||
m_layerItem(layerItem),
|
||||
m_resizeHandle(0)
|
||||
m_resizeHandle(0),
|
||||
m_isActive(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,6 +79,7 @@ void ResizeManipulator::removeHandle()
|
||||
void ResizeManipulator::begin(const QPointF &/*beginPoint*/)
|
||||
{
|
||||
if (m_resizeController.isValid()) {
|
||||
m_isActive = true;
|
||||
m_beginBoundingRect = m_resizeController.formEditorItem()->qmlItemNode().instanceBoundingRect();
|
||||
m_beginToSceneTransform = m_resizeController.formEditorItem()->qmlItemNode().instanceSceneTransform();
|
||||
m_beginFromSceneTransform = m_beginToSceneTransform.inverted();
|
||||
@@ -392,6 +394,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
||||
|
||||
void ResizeManipulator::end()
|
||||
{
|
||||
m_isActive = false;
|
||||
m_rewriterTransaction.commit();
|
||||
clear();
|
||||
removeHandle();
|
||||
@@ -508,6 +511,11 @@ void ResizeManipulator::clear()
|
||||
removeHandle();
|
||||
}
|
||||
|
||||
bool ResizeManipulator::isActive() const
|
||||
{
|
||||
return m_isActive;
|
||||
}
|
||||
|
||||
void ResizeManipulator::setSize(QmlItemNode itemNode, const QSizeF &size)
|
||||
{
|
||||
int penWidth = (itemNode.instancePenWidth() / 2) * 2;
|
||||
|
||||
@@ -67,6 +67,8 @@ public:
|
||||
|
||||
void clear();
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
protected:
|
||||
bool isInvalidSize(const QSizeF & size);
|
||||
void deleteSnapLines();
|
||||
@@ -91,6 +93,7 @@ private:
|
||||
QWeakPointer<LayerItem> m_layerItem;
|
||||
ResizeHandleItem *m_resizeHandle;
|
||||
RewriterTransaction m_rewriterTransaction;
|
||||
bool m_isActive;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ ResizeTool::~ResizeTool()
|
||||
void ResizeTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
if (itemList.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -70,11 +71,15 @@ void ResizeTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
||||
m_resizeManipulator.begin(event->scenePos());
|
||||
m_resizeIndicator.hide();
|
||||
}
|
||||
}
|
||||
|
||||
AbstractFormEditorTool::mousePressEvent(itemList, event);
|
||||
}
|
||||
|
||||
void ResizeTool::mouseMoveEvent(const QList<QGraphicsItem*> &,
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (m_resizeManipulator.isActive()) {
|
||||
bool shouldSnapping = view()->widget()->snappingAction()->isChecked();
|
||||
bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked();
|
||||
|
||||
@@ -87,6 +92,7 @@ void ResizeTool::mouseMoveEvent(const QList<QGraphicsItem*> &,
|
||||
}
|
||||
|
||||
m_resizeManipulator.update(event->scenePos(), useSnapping);
|
||||
}
|
||||
}
|
||||
|
||||
void ResizeTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
|
||||
@@ -107,14 +113,18 @@ void ResizeTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
|
||||
}
|
||||
|
||||
void ResizeTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent * /*event*/)
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (m_resizeManipulator.isActive()) {
|
||||
if (itemList.isEmpty())
|
||||
return;
|
||||
|
||||
m_selectionIndicator.show();
|
||||
m_resizeIndicator.show();
|
||||
m_resizeManipulator.end();
|
||||
}
|
||||
|
||||
AbstractFormEditorTool::mouseReleaseEvent(itemList, event);
|
||||
}
|
||||
|
||||
void ResizeTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> & /*itemList*/,
|
||||
|
||||
@@ -67,6 +67,7 @@ SelectionTool::~SelectionTool()
|
||||
void SelectionTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
m_mousePressTimer.start();
|
||||
FormEditorItem* formEditorItem = topFormEditorItem(itemList);
|
||||
if (formEditorItem
|
||||
@@ -97,6 +98,8 @@ void SelectionTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
|
||||
m_rubberbandSelectionManipulator.begin(event->scenePos());
|
||||
}
|
||||
}
|
||||
}
|
||||
AbstractFormEditorTool::mousePressEvent(itemList, event);
|
||||
}
|
||||
|
||||
void SelectionTool::mouseMoveEvent(const QList<QGraphicsItem*> &/*itemList*/,
|
||||
@@ -161,7 +164,7 @@ void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
|
||||
scene()->highlightBoundingRect(topSelectableItem);
|
||||
}
|
||||
|
||||
void SelectionTool::mouseReleaseEvent(const QList<QGraphicsItem*> &/*itemList*/,
|
||||
void SelectionTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
|
||||
QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (m_singleSelectionManipulator.isActive()) {
|
||||
@@ -195,6 +198,7 @@ void SelectionTool::mouseReleaseEvent(const QList<QGraphicsItem*> &/*itemList*/,
|
||||
}
|
||||
}
|
||||
|
||||
AbstractFormEditorTool::mouseReleaseEvent(itemList, event);
|
||||
}
|
||||
|
||||
void SelectionTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent * event)
|
||||
|
||||
Reference in New Issue
Block a user