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