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

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: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarMarco Bubke <marco.bubke@nokia.com>
parent a9f53ec9
......@@ -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,46 +74,52 @@ void MoveTool::clear()
void MoveTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
QGraphicsSceneMouseEvent *event)
{
if (itemList.isEmpty())
return;
m_movingItems = movingItems(items());
if (m_movingItems.isEmpty())
return;
if (event->button() == Qt::LeftButton) {
if (itemList.isEmpty())
return;
m_movingItems = movingItems(items());
if (m_movingItems.isEmpty())
return;
m_moveManipulator.setItems(m_movingItems);
m_moveManipulator.begin(event->scenePos());
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_movingItems.isEmpty())
return;
if (m_moveManipulator.isActive()) {
if (m_movingItems.isEmpty())
return;
// m_selectionIndicator.hide();
m_resizeIndicator.hide();
// m_selectionIndicator.hide();
m_resizeIndicator.hide();
FormEditorItem *containerItem = containerFormEditorItem(itemList, m_movingItems);
if (containerItem
&& view()->currentState().isBaseState()) {
if (containerItem != m_movingItems.first()->parentItem()
&& event->modifiers().testFlag(Qt::ShiftModifier)) {
m_moveManipulator.reparentTo(containerItem);
FormEditorItem *containerItem = containerFormEditorItem(itemList, m_movingItems);
if (containerItem
&& view()->currentState().isBaseState()) {
if (containerItem != m_movingItems.first()->parentItem()
&& event->modifiers().testFlag(Qt::ShiftModifier)) {
m_moveManipulator.reparentTo(containerItem);
}
}
}
bool shouldSnapping = view()->widget()->snappingAction()->isChecked();
bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked();
bool shouldSnapping = view()->widget()->snappingAction()->isChecked();
bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked();
MoveManipulator::Snapping useSnapping = MoveManipulator::NoSnapping;
if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) {
if (shouldSnappingAndAnchoring)
useSnapping = MoveManipulator::UseSnappingAndAnchoring;
else
useSnapping = MoveManipulator::UseSnapping;
}
MoveManipulator::Snapping useSnapping = MoveManipulator::NoSnapping;
if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) {
if (shouldSnappingAndAnchoring)
useSnapping = MoveManipulator::UseSnappingAndAnchoring;
else
useSnapping = MoveManipulator::UseSnapping;
}
m_moveManipulator.update(event->scenePos(), useSnapping);
m_moveManipulator.update(event->scenePos(), useSnapping);
}
}
void MoveTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
......@@ -195,31 +201,35 @@ void MoveTool::keyReleaseEvent(QKeyEvent *keyEvent)
}
}
void MoveTool::mouseReleaseEvent(const QList<QGraphicsItem*> &/*itemList*/,
void MoveTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
QGraphicsSceneMouseEvent *event)
{
if (m_movingItems.isEmpty())
return;
if (m_moveManipulator.isActive()) {
if (m_movingItems.isEmpty())
return;
QLineF moveVector(event->scenePos(), m_moveManipulator.beginPoint());
if (moveVector.length() < QApplication::startDragDistance())
{
QPointF beginPoint(m_moveManipulator.beginPoint());
QLineF moveVector(event->scenePos(), m_moveManipulator.beginPoint());
if (moveVector.length() < QApplication::startDragDistance())
{
QPointF beginPoint(m_moveManipulator.beginPoint());
m_moveManipulator.end(beginPoint);
m_moveManipulator.end(beginPoint);
// m_selectionIndicator.show();
m_resizeIndicator.show();
m_movingItems.clear();
// m_selectionIndicator.show();
m_resizeIndicator.show();
m_movingItems.clear();
view()->changeToSelectionTool(event);
} else {
m_moveManipulator.end(event->scenePos());
view()->changeToSelectionTool(event);
} else {
m_moveManipulator.end(event->scenePos());
m_selectionIndicator.show();
m_resizeIndicator.show();
m_movingItems.clear();
m_selectionIndicator.show();
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,32 +61,38 @@ ResizeTool::~ResizeTool()
void ResizeTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
QGraphicsSceneMouseEvent *event)
{
if (itemList.isEmpty())
return;
if (event->button() == Qt::LeftButton) {
if (itemList.isEmpty())
return;
ResizeHandleItem *resizeHandle = ResizeHandleItem::fromGraphicsItem(itemList.first());
if (resizeHandle && resizeHandle->resizeController().isValid()) {
m_resizeManipulator.setHandle(resizeHandle);
m_resizeManipulator.begin(event->scenePos());
m_resizeIndicator.hide();
ResizeHandleItem *resizeHandle = ResizeHandleItem::fromGraphicsItem(itemList.first());
if (resizeHandle && resizeHandle->resizeController().isValid()) {
m_resizeManipulator.setHandle(resizeHandle);
m_resizeManipulator.begin(event->scenePos());
m_resizeIndicator.hide();
}
}
AbstractFormEditorTool::mousePressEvent(itemList, event);
}
void ResizeTool::mouseMoveEvent(const QList<QGraphicsItem*> &,
QGraphicsSceneMouseEvent *event)
{
bool shouldSnapping = view()->widget()->snappingAction()->isChecked();
bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked();
ResizeManipulator::Snapping useSnapping = ResizeManipulator::NoSnapping;
if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) {
if (shouldSnappingAndAnchoring)
useSnapping = ResizeManipulator::UseSnappingAndAnchoring;
else
useSnapping = ResizeManipulator::UseSnapping;
if (m_resizeManipulator.isActive()) {
bool shouldSnapping = view()->widget()->snappingAction()->isChecked();
bool shouldSnappingAndAnchoring = view()->widget()->snappingAndAnchoringAction()->isChecked();
ResizeManipulator::Snapping useSnapping = ResizeManipulator::NoSnapping;
if (event->modifiers().testFlag(Qt::ControlModifier) != (shouldSnapping || shouldSnappingAndAnchoring)) {
if (shouldSnappingAndAnchoring)
useSnapping = ResizeManipulator::UseSnappingAndAnchoring;
else
useSnapping = ResizeManipulator::UseSnapping;
}
m_resizeManipulator.update(event->scenePos(), useSnapping);
}
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 (itemList.isEmpty())
return;
if (m_resizeManipulator.isActive()) {
if (itemList.isEmpty())
return;
m_selectionIndicator.show();
m_resizeIndicator.show();
m_resizeManipulator.end();
}
m_selectionIndicator.show();
m_resizeIndicator.show();
m_resizeManipulator.end();
AbstractFormEditorTool::mouseReleaseEvent(itemList, event);
}
void ResizeTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> & /*itemList*/,
......
......@@ -67,21 +67,12 @@ SelectionTool::~SelectionTool()
void SelectionTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
QGraphicsSceneMouseEvent *event)
{
m_mousePressTimer.start();
FormEditorItem* formEditorItem = topFormEditorItem(itemList);
if (formEditorItem
&& formEditorItem->qmlItemNode().isValid()
&& !formEditorItem->qmlItemNode().hasChildren()) {
m_singleSelectionManipulator.begin(event->scenePos());
if (event->modifiers().testFlag(Qt::ControlModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection, m_selectOnlyContentItems);
else if (event->modifiers().testFlag(Qt::ShiftModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection, m_selectOnlyContentItems);
else
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection, m_selectOnlyContentItems);
} else {
if (event->modifiers().testFlag(Qt::AltModifier)) {
if (event->button() == Qt::LeftButton) {
m_mousePressTimer.start();
FormEditorItem* formEditorItem = topFormEditorItem(itemList);
if (formEditorItem
&& formEditorItem->qmlItemNode().isValid()
&& !formEditorItem->qmlItemNode().hasChildren()) {
m_singleSelectionManipulator.begin(event->scenePos());
if (event->modifiers().testFlag(Qt::ControlModifier))
......@@ -90,13 +81,25 @@ void SelectionTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection, m_selectOnlyContentItems);
else
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.end(event->scenePos());
view()->changeToMoveTool(event->scenePos());
} else {
m_rubberbandSelectionManipulator.begin(event->scenePos());
if (event->modifiers().testFlag(Qt::AltModifier)) {
m_singleSelectionManipulator.begin(event->scenePos());
if (event->modifiers().testFlag(Qt::ControlModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection, m_selectOnlyContentItems);
else if (event->modifiers().testFlag(Qt::ShiftModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection, m_selectOnlyContentItems);
else
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.end(event->scenePos());
view()->changeToMoveTool(event->scenePos());
} else {
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)
......
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