Commit 0379f439 authored by Didier Clerc's avatar Didier Clerc

Fixed an issue with backspace on group items

parent c39ba64f
...@@ -2324,6 +2324,11 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) ...@@ -2324,6 +2324,11 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
if (keyEvent->matches(QKeySequence::Delete)) if (keyEvent->matches(QKeySequence::Delete))
#endif #endif
{ {
QVector<UBGraphicsItem*> ubItemsToRemove;
QVector<QGraphicsItem*> itemToRemove;
bool bRemoveOk = true;
foreach(QGraphicsItem* item, si) foreach(QGraphicsItem* item, si)
{ {
switch (item->type()) switch (item->type())
...@@ -2333,28 +2338,52 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) ...@@ -2333,28 +2338,52 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
UBGraphicsW3CWidgetItem *wc3_widget = dynamic_cast<UBGraphicsW3CWidgetItem*>(item); UBGraphicsW3CWidgetItem *wc3_widget = dynamic_cast<UBGraphicsW3CWidgetItem*>(item);
if (0 != wc3_widget) if (0 != wc3_widget)
if (!wc3_widget->hasFocus()) if (!wc3_widget->hasFocus())
wc3_widget->remove(); ubItemsToRemove << wc3_widget;
break; break;
} }
case UBGraphicsTextItem::Type: case UBGraphicsTextItem::Type:
{ {
UBGraphicsTextItem *text_item = dynamic_cast<UBGraphicsTextItem*>(item); UBGraphicsTextItem *text_item = dynamic_cast<UBGraphicsTextItem*>(item);
if (0 != text_item) if (0 != text_item){
if (!text_item->hasFocus()) if (!text_item->hasFocus())
text_item->remove(); ubItemsToRemove << text_item;
else
bRemoveOk = false;
}
break; break;
} }
case UBGraphicsGroupContainerItem::Type:
{
UBGraphicsGroupContainerItem* group_item = dynamic_cast<UBGraphicsGroupContainerItem*>(item);
if(NULL != group_item){
if(!hasTextItemWithFocus(group_item))
ubItemsToRemove << group_item;
else
bRemoveOk = false;
}
break;
}
default: default:
{ {
UBGraphicsItem *ubgi = dynamic_cast<UBGraphicsItem*>(item); UBGraphicsItem *ubgi = dynamic_cast<UBGraphicsItem*>(item);
if (0 != ubgi) if (0 != ubgi)
ubgi->remove(); ubItemsToRemove << ubgi;
else else
UBCoreGraphicsScene::removeItem(item); itemToRemove << item;
} }
} }
} }
if(bRemoveOk){
foreach(UBGraphicsItem* pUBItem, ubItemsToRemove){
pUBItem->remove();
}
foreach(QGraphicsItem* pItem, itemToRemove){
UBCoreGraphicsScene::removeItem(pItem);
}
}
} }
keyEvent->accept(); keyEvent->accept();
...@@ -2363,6 +2392,22 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) ...@@ -2363,6 +2392,22 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
QGraphicsScene::keyReleaseEvent(keyEvent); QGraphicsScene::keyReleaseEvent(keyEvent);
} }
bool UBGraphicsScene::hasTextItemWithFocus(UBGraphicsGroupContainerItem *item){
bool bHasFocus = false;
foreach(QGraphicsItem* pItem, item->childItems()){
UBGraphicsTextItem *text_item = dynamic_cast<UBGraphicsTextItem*>(pItem);
if (NULL != text_item){
if(text_item->hasFocus()){
bHasFocus = true;
break;
}
}
}
return bHasFocus;
}
void UBGraphicsScene::setDocumentUpdated() void UBGraphicsScene::setDocumentUpdated()
{ {
if (document()) if (document())
......
...@@ -374,6 +374,7 @@ public slots: ...@@ -374,6 +374,7 @@ public slots:
void setDocumentUpdated(); void setDocumentUpdated();
void createEraiser(); void createEraiser();
void createPointer(); void createPointer();
bool hasTextItemWithFocus(UBGraphicsGroupContainerItem* item);
QGraphicsEllipseItem* mEraser; QGraphicsEllipseItem* mEraser;
QGraphicsEllipseItem* mPointer; QGraphicsEllipseItem* mPointer;
......
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