From ec5f202ef1ee3bf63acdf2cdb1ed312e3ce4e32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= Date: Fri, 27 Aug 2021 12:42:42 +0200 Subject: [PATCH] always verify movingItem is not null + don't call QGraphicsView::mouseMoveEvent if movingItem is null + don't display grey rectangle with the magic finger --- src/board/UBBoardView.cpp | 123 ++++++++++++++++---------- src/domain/UBGraphicsItemDelegate.cpp | 13 +-- 2 files changed, 82 insertions(+), 54 deletions(-) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 5ba68364..0e25b8b0 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -486,8 +486,14 @@ void UBBoardView::handleItemsSelection(QGraphicsItem *item) if (item) { // item has group as first parent - it is any item or UBGraphicsStrokesGroup. - if(item->parentItem() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type()) - return; + if (getMovingItem()) + { + if (getMovingItem()->parentItem()) + { + if(item->parentItem() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type()) + return; + } + } // delegate buttons shouldn't selected if (DelegateButton::Type == item->type()) @@ -653,11 +659,17 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item) if (!(mMouseButtonIsPressed || mTabletStylusIsPressed)) return false; - if (getMovingItem()->data(UBGraphicsItemData::ItemLocked).toBool()) - return false; + if (getMovingItem()) + { + if (getMovingItem()->data(UBGraphicsItemData::ItemLocked).toBool()) + return false; - if (getMovingItem()->parentItem() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type() && !getMovingItem()->isSelected() && getMovingItem()->parentItem()->isSelected()) - return false; + if (getMovingItem()->parentItem()) + { + if (UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type() && !getMovingItem()->isSelected() && getMovingItem()->parentItem()->isSelected()) + return false; + } + } UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); @@ -831,20 +843,22 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event) QPointF posAfterMove; if (getMovingItem()) + { posBeforeMove = getMovingItem()->pos(); - - QGraphicsView::mouseMoveEvent (event); - - if (getMovingItem()) + QGraphicsView::mouseMoveEvent (event); posAfterMove = getMovingItem()->pos(); + } mWidgetMoved = ((posAfterMove-posBeforeMove).manhattanLength() != 0); // a cludge for terminate moving of w3c widgets. // in some cases w3c widgets catches mouse move and doesn't sends that events to web page, // at simple - in google map widget - mouse move events doesn't comes to web page from rectangle of wearch bar on bottom right corner of widget. - if (getMovingItem() && mWidgetMoved && UBGraphicsW3CWidgetItem::Type == getMovingItem()->type()) - getMovingItem()->setPos(posBeforeMove); + if (getMovingItem()) + { + if (mWidgetMoved && UBGraphicsW3CWidgetItem::Type == getMovingItem()->type()) + getMovingItem()->setPos(posBeforeMove); + } } } @@ -1270,51 +1284,58 @@ void UBBoardView::mouseReleaseEvent (QMouseEvent *event) setMovingItem(nullptr); } else - if (getMovingItem() && (!isCppTool(getMovingItem()) || UBGraphicsCurtainItem::Type == getMovingItem()->type())) + { + if (getMovingItem()) { - if (suspendedMousePressEvent) - { - QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop - setMovingItem(NULL); - delete suspendedMousePressEvent; - suspendedMousePressEvent = NULL; - bReleaseIsNeed = true; - } - else + if (!isCppTool(getMovingItem()) || UBGraphicsCurtainItem::Type == getMovingItem()->type()) { - if (isUBItem(getMovingItem()) && - DelegateButton::Type != getMovingItem()->type() && - UBGraphicsDelegateFrame::Type != getMovingItem()->type() && - UBGraphicsCache::Type != getMovingItem()->type() && - QGraphicsWebView::Type != getMovingItem()->type() && // for W3C widgets as Tools. - !(!isMultipleSelectionEnabled() && getMovingItem()->parentItem() && UBGraphicsWidgetItem::Type == getMovingItem()->type() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type())) + if (suspendedMousePressEvent) { - bReleaseIsNeed = false; - if (getMovingItem()->isSelected() && isMultipleSelectionEnabled()) - getMovingItem()->setSelected(false); - else - if (getMovingItem()->parentItem() && getMovingItem()->parentItem()->isSelected() && isMultipleSelectionEnabled()) - getMovingItem()->parentItem()->setSelected(false); + QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop + setMovingItem(NULL); + delete suspendedMousePressEvent; + suspendedMousePressEvent = NULL; + bReleaseIsNeed = true; + } + else + { + if (isUBItem(getMovingItem()) && + DelegateButton::Type != getMovingItem()->type() && + UBGraphicsDelegateFrame::Type != getMovingItem()->type() && + UBGraphicsCache::Type != getMovingItem()->type() && + QGraphicsWebView::Type != getMovingItem()->type() && // for W3C widgets as Tools. + !(!isMultipleSelectionEnabled() && getMovingItem()->parentItem() && UBGraphicsWidgetItem::Type == getMovingItem()->type() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type())) + { + bReleaseIsNeed = false; + if (getMovingItem()->isSelected() && isMultipleSelectionEnabled()) + getMovingItem()->setSelected(false); else - { - if (getMovingItem()->isSelected()) - bReleaseIsNeed = true; - - UBGraphicsTextItem* textItem = dynamic_cast(getMovingItem()); - UBGraphicsMediaItem* movieItem = dynamic_cast(getMovingItem()); - if(textItem) - textItem->setSelected(true); - else if(movieItem) - movieItem->setSelected(true); + if (getMovingItem()->parentItem() && getMovingItem()->parentItem()->isSelected() && isMultipleSelectionEnabled()) + getMovingItem()->parentItem()->setSelected(false); else - getMovingItem()->setSelected(true); - } + { + if (getMovingItem()->isSelected()) + bReleaseIsNeed = true; + + UBGraphicsTextItem* textItem = dynamic_cast(getMovingItem()); + UBGraphicsMediaItem* movieItem = dynamic_cast(getMovingItem()); + if(textItem) + textItem->setSelected(true); + else if(movieItem) + movieItem->setSelected(true); + else + getMovingItem()->setSelected(true); + } + } } } + else + bReleaseIsNeed = true; } else bReleaseIsNeed = true; + } if (bReleaseIsNeed) { @@ -1402,9 +1423,13 @@ void UBBoardView::mouseReleaseEvent (QMouseEvent *event) return; } - if (mWidgetMoved) { - getMovingItem()->setSelected(false); - setMovingItem(NULL); + if (mWidgetMoved) + { + if (getMovingItem()) + { + getMovingItem()->setSelected(false); + setMovingItem(NULL); + } mWidgetMoved = false; } else { diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index bb19e2ca..49085698 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -328,12 +328,15 @@ void UBGraphicsItemDelegate::postpaint(QPainter *painter, const QStyleOptionGrap { Q_UNUSED(widget) if (option->state & QStyle::State_Selected && !controlsExist()) { - painter->save(); - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77)); - painter->drawRect(option->rect); + if (UBStylusTool::Play != UBDrawingController::drawingController()->stylusTool()) + { + painter->save(); + painter->setPen(Qt::NoPen); + painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77)); + painter->drawRect(option->rect); - painter->restore(); + painter->restore(); + } } }