Fixed an issue with backspace on group items

preferencesAboutTextFull
Didier Clerc 11 years ago
parent c39ba64fa6
commit 0379f4394d
  1. 55
      src/domain/UBGraphicsScene.cpp
  2. 1
      src/domain/UBGraphicsScene.h

@ -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,15 +2338,30 @@ 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;
}
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; break;
} }
@ -2349,12 +2369,21 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
{ {
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)
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:
void setDocumentUpdated(); void setDocumentUpdated();
void createEraiser(); void createEraiser();
void createPointer(); void createPointer();
bool hasTextItemWithFocus(UBGraphicsGroupContainerItem* item);
QGraphicsEllipseItem* mEraser; QGraphicsEllipseItem* mEraser;
QGraphicsEllipseItem* mPointer; QGraphicsEllipseItem* mPointer;

Loading…
Cancel
Save