Commit b927391e authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Thomas Hartmann
Browse files

QmlDesigner.FormEditor: Change selection behavior



Task-number: QTCREATORBUG-11703
Change-Id: Ief6a7bbbb935b76700e50b60bf234c87a76e7f55
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 31964795
......@@ -31,6 +31,7 @@
#include "abstractformeditortool.h"
#include "formeditorview.h"
#include "formeditorwidget.h"
#include "formeditorscene.h"
#include <modelnodecontextmenu.h>
......@@ -169,26 +170,22 @@ FormEditorItem *AbstractFormEditorTool::topMovableFormEditorItem(const QList<QGr
return 0;
}
FormEditorItem* AbstractFormEditorTool::topFormEditorItem(const QList<QGraphicsItem*> & itemList)
FormEditorItem* AbstractFormEditorTool::nearestFormEditorItem(const QPointF &point, const QList<QGraphicsItem*> & itemList)
{
FormEditorItem* nearestItem = 0;
foreach (QGraphicsItem *item, itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem && !formEditorItem->qmlItemNode().isRootNode())
return formEditorItem;
}
return 0;
}
if (!formEditorItem || !formEditorItem->qmlItemNode().isValid())
continue;
FormEditorItem* AbstractFormEditorTool::topFormEditorItemWithRootItem(const QList<QGraphicsItem*> & itemList)
{
foreach (QGraphicsItem *item, itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem)
return formEditorItem;
if (!nearestItem)
nearestItem = formEditorItem;
else if (formEditorItem->selectionWeigth(point, 1) < nearestItem->selectionWeigth(point, 0))
nearestItem = formEditorItem;
}
return 0;
return nearestItem;
}
QList<FormEditorItem *> AbstractFormEditorTool::filterSelectedModelNodes(const QList<FormEditorItem *> &itemList) const
......@@ -225,9 +222,43 @@ void AbstractFormEditorTool::mousePressEvent(const QList<QGraphicsItem*> & /*ite
event->accept();
}
void AbstractFormEditorTool::mouseReleaseEvent(const QList<QGraphicsItem*> & /*itemList*/, QGraphicsSceneMouseEvent *event)
static bool containsItemNode(const QList<QGraphicsItem*> & itemList, const QmlItemNode &itemNode)
{
foreach (QGraphicsItem *item, itemList) {
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
if (formEditorItem && formEditorItem->qmlItemNode() == itemNode)
return true;
}
return false;
}
void AbstractFormEditorTool::mouseReleaseEvent(const QList<QGraphicsItem*> & itemList, QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
QmlItemNode currentSelectedNode;
if (view()->selectedModelNodes().count() == 1) {
currentSelectedNode = view()->selectedModelNodes().first();
if (!containsItemNode(itemList, currentSelectedNode)) {
QmlItemNode selectedNode;
FormEditorItem *formEditorItem = nearestFormEditorItem(event->scenePos(), itemList);
if (formEditorItem && formEditorItem->qmlItemNode().isValid())
selectedNode = formEditorItem->qmlItemNode();
if (selectedNode.isValid()) {
QList<ModelNode> nodeList;
nodeList.append(selectedNode);
view()->setSelectedModelNodes(nodeList);
}
}
}
showContextMenu(event);
event->accept();
}
......@@ -236,7 +267,7 @@ void AbstractFormEditorTool::mouseReleaseEvent(const QList<QGraphicsItem*> & /*i
void AbstractFormEditorTool::mouseDoubleClickEvent(const QList<QGraphicsItem*> &itemList, QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
FormEditorItem *formEditorItem = topFormEditorItem(itemList);
FormEditorItem *formEditorItem = nearestFormEditorItem(event->pos(), itemList);
if (formEditorItem) {
view()->setSelectedModelNode(formEditorItem->qmlItemNode().modelNode());
view()->changeToCustomTool();
......
......@@ -91,11 +91,10 @@ public:
bool topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList);
bool topItemIsResizeHandle(const QList<QGraphicsItem*> &itemList);
static FormEditorItem* topFormEditorItem(const QList<QGraphicsItem*> &itemList);
static FormEditorItem* topFormEditorItemWithRootItem(const QList<QGraphicsItem*> &itemList);
QList<FormEditorItem*> filterSelectedModelNodes(const QList<FormEditorItem*> &itemList) const;
FormEditorItem *nearestFormEditorItem(const QPointF &point, const QList<QGraphicsItem *> &itemList);
protected:
virtual void selectedItemsChanged(const QList<FormEditorItem*> &itemList) = 0;
virtual void showContextMenu(QGraphicsSceneMouseEvent *event);
......
......@@ -69,8 +69,6 @@ FormEditorView::FormEditorView(QObject *parent)
connect(formEditorWidget()->zoomAction(), SIGNAL(zoomLevelChanged(double)), SLOT(updateGraphicsIndicators()));
connect(formEditorWidget()->showBoundingRectAction(), SIGNAL(toggled(bool)), scene(), SLOT(setShowBoundingRects(bool)));
connect(formEditorWidget()->selectOnlyContentItemsAction(), SIGNAL(toggled(bool)), this, SLOT(setSelectOnlyContentItemsAction(bool)));
}
FormEditorScene* FormEditorView::scene() const
......
......@@ -105,15 +105,10 @@ FormEditorWidget::FormEditorWidget(FormEditorView *view)
addAction(m_showBoundingRectAction.data());
upperActions.append(m_showBoundingRectAction.data());
m_selectOnlyContentItemsAction = new QAction(tr("Only select items with content (S)."), this);
m_selectOnlyContentItemsAction->setShortcut(Qt::Key_S);
m_selectOnlyContentItemsAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
m_selectOnlyContentItemsAction->setCheckable(true);
m_selectOnlyContentItemsAction->setChecked(false);
m_selectOnlyContentItemsAction->setIcon(QPixmap(":/icon/selection/selectonlycontentitems.png"));
addAction(m_selectOnlyContentItemsAction.data());
upperActions.append(m_selectOnlyContentItemsAction.data());
separatorAction = new QAction(this);
separatorAction->setSeparator(true);
addAction(separatorAction);
upperActions.append(separatorAction);
m_rootWidthAction = new LineEditAction(tr("Width"), this);
connect(m_rootWidthAction.data(), SIGNAL(textChanged(QString)), this, SLOT(changeRootItemWidth(QString)));
......@@ -255,11 +250,6 @@ QAction *FormEditorWidget::showBoundingRectAction() const
return m_showBoundingRectAction.data();
}
QAction *FormEditorWidget::selectOnlyContentItemsAction() const
{
return m_selectOnlyContentItemsAction.data();
}
QAction *FormEditorWidget::snappingAction() const
{
return m_snappingAction.data();
......
......@@ -58,7 +58,6 @@ public:
ZoomAction *zoomAction() const;
QAction *showBoundingRectAction() const;
QAction *selectOnlyContentItemsAction() const;
QAction *snappingAction() const;
QAction *snappingAndAnchoringAction() const;
......@@ -103,7 +102,6 @@ private:
QPointer<QAction> m_snappingAndAnchoringAction;
QPointer<QAction> m_noSnappingAction;
QPointer<QAction> m_showBoundingRectAction;
QPointer<QAction> m_selectOnlyContentItemsAction;
QPointer<LineEditAction> m_rootWidthAction;
QPointer<LineEditAction> m_rootHeightAction;
QPointer<BackgroundAction> m_backgroundAction;
......
......@@ -52,8 +52,7 @@ SelectionTool::SelectionTool(FormEditorView *editorView)
m_resizeIndicator(editorView->scene()->manipulatorLayerItem()),
m_anchorIndicator(editorView->scene()->manipulatorLayerItem()),
m_bindingIndicator(editorView->scene()->manipulatorLayerItem()),
m_contentNotEditableIndicator(editorView->scene()->manipulatorLayerItem()),
m_selectOnlyContentItems(false)
m_contentNotEditableIndicator(editorView->scene()->manipulatorLayerItem())
{
m_selectionIndicator.setCursor(Qt::ArrowCursor);
}
......@@ -68,28 +67,28 @@ void SelectionTool::mousePressEvent(const QList<QGraphicsItem*> &itemList,
{
if (event->button() == Qt::LeftButton) {
m_mousePressTimer.start();
FormEditorItem* formEditorItem = topFormEditorItem(itemList);
FormEditorItem* formEditorItem = nearestFormEditorItem(event->scenePos(), 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);
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection);
else if (event->modifiers().testFlag(Qt::ShiftModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection);
else
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection);
} else {
if (event->modifiers().testFlag(Qt::AltModifier)) {
m_singleSelectionManipulator.begin(event->scenePos());
if (event->modifiers().testFlag(Qt::ControlModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection);
else if (event->modifiers().testFlag(Qt::ShiftModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection);
else
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection);
m_singleSelectionManipulator.end(event->scenePos());
view()->changeToMoveTool(event->scenePos());
......@@ -130,7 +129,7 @@ void SelectionTool::mouseMoveEvent(const QList<QGraphicsItem*> &/*itemList*/,
}
void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
QGraphicsSceneMouseEvent * /*event*/)
QGraphicsSceneMouseEvent * event)
{
if (!itemList.isEmpty()) {
......@@ -146,7 +145,7 @@ void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
}
}
FormEditorItem *topSelectableItem = topMovableFormEditorItem(itemList, m_selectOnlyContentItems);
FormEditorItem *topSelectableItem = nearestFormEditorItem(event->scenePos(), itemList);
scene()->highlightBoundingRect(topSelectableItem);
......@@ -156,6 +155,7 @@ void SelectionTool::hoverMoveEvent(const QList<QGraphicsItem*> &itemList,
void SelectionTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
if (m_singleSelectionManipulator.isActive()) {
m_singleSelectionManipulator.end(event->scenePos());
} else if (m_rubberbandSelectionManipulator.isActive()) {
......@@ -165,11 +165,11 @@ void SelectionTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
m_singleSelectionManipulator.begin(event->scenePos());
if (event->modifiers().testFlag(Qt::ControlModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection);
else if (event->modifiers().testFlag(Qt::ShiftModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection);
else
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection);
m_singleSelectionManipulator.end(event->scenePos());
} else {
......@@ -185,6 +185,7 @@ void SelectionTool::mouseReleaseEvent(const QList<QGraphicsItem*> &itemList,
m_rubberbandSelectionManipulator.end();
}
}
}
AbstractFormEditorTool::mouseReleaseEvent(itemList, event);
}
......@@ -220,11 +221,6 @@ void SelectionTool::dragMoveEvent(const QList<QGraphicsItem*> &/*itemList*/, QGr
{
}
void SelectionTool::setSelectOnlyContentItems(bool selectOnlyContentItems)
{
m_selectOnlyContentItems = selectOnlyContentItems;
}
void SelectionTool::itemsAboutToRemoved(const QList<FormEditorItem*> &/*itemList*/)
{
......@@ -294,11 +290,11 @@ void SelectionTool::selectUnderPoint(QGraphicsSceneMouseEvent *event)
m_singleSelectionManipulator.begin(event->scenePos());
if (event->modifiers().testFlag(Qt::ControlModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::RemoveFromSelection);
else if (event->modifiers().testFlag(Qt::ShiftModifier))
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::AddToSelection);
else
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection, m_selectOnlyContentItems);
m_singleSelectionManipulator.select(SingleSelectionManipulator::ReplaceSelection);
m_singleSelectionManipulator.end(event->scenePos());
}
......
......@@ -84,8 +84,6 @@ public:
void selectUnderPoint(QGraphicsSceneMouseEvent *event);
void setSelectOnlyContentItems(bool selectOnlyContentItems);
void setCursor(const QCursor &cursor);
private:
......@@ -97,7 +95,6 @@ private:
BindingIndicator m_bindingIndicator;
ContentNotEditableIndicator m_contentNotEditableIndicator;
QTime m_mousePressTimer;
bool m_selectOnlyContentItems;
QCursor m_cursor;
};
......
......@@ -68,24 +68,16 @@ void SingleSelectionManipulator::end(const QPointF &/*updatePoint*/)
m_isActive = false;
}
void SingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems)
void SingleSelectionManipulator::select(SelectionType selectionType)
{
QList<QGraphicsItem*> itemList = m_editorView->scene()->items(m_beginPoint);
QmlItemNode selectedNode;
foreach (QGraphicsItem* item, itemList)
{
FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item);
FormEditorItem *formEditorItem = m_editorView->currentTool()->nearestFormEditorItem(m_beginPoint, itemList);
if (formEditorItem
&& formEditorItem->qmlItemNode().isValid()
&& (formEditorItem->qmlItemNode().instanceHasShowContent() || !selectOnlyContentItems))
{
if (formEditorItem && formEditorItem->qmlItemNode().isValid())
selectedNode = formEditorItem->qmlItemNode();
break;
}
}
QList<QmlItemNode> nodeList;
......
......@@ -55,7 +55,7 @@ public:
void update(const QPointF& updatePoint);
void end(const QPointF& updatePoint);
void select(SelectionType selectionType, bool selectOnlyContentItems);
void select(SelectionType selectionType);
void clear();
......
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