always verify movingItem is not null + don't call QGraphicsView::mouseMoveEvent if movingItem is null + don't display grey rectangle with the magic finger

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent 986cbd60ab
commit ec5f202ef1
  1. 39
      src/board/UBBoardView.cpp
  2. 3
      src/domain/UBGraphicsItemDelegate.cpp

@ -486,8 +486,14 @@ void UBBoardView::handleItemsSelection(QGraphicsItem *item)
if (item) if (item)
{ {
// item has group as first parent - it is any item or UBGraphicsStrokesGroup. // item has group as first parent - it is any item or UBGraphicsStrokesGroup.
if (getMovingItem())
{
if (getMovingItem()->parentItem())
{
if(item->parentItem() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type()) if(item->parentItem() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type())
return; return;
}
}
// delegate buttons shouldn't selected // delegate buttons shouldn't selected
if (DelegateButton::Type == item->type()) if (DelegateButton::Type == item->type())
@ -653,11 +659,17 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item)
if (!(mMouseButtonIsPressed || mTabletStylusIsPressed)) if (!(mMouseButtonIsPressed || mTabletStylusIsPressed))
return false; return false;
if (getMovingItem())
{
if (getMovingItem()->data(UBGraphicsItemData::ItemLocked).toBool()) if (getMovingItem()->data(UBGraphicsItemData::ItemLocked).toBool())
return false; return false;
if (getMovingItem()->parentItem() && UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type() && !getMovingItem()->isSelected() && getMovingItem()->parentItem()->isSelected()) if (getMovingItem()->parentItem())
{
if (UBGraphicsGroupContainerItem::Type == getMovingItem()->parentItem()->type() && !getMovingItem()->isSelected() && getMovingItem()->parentItem()->isSelected())
return false; return false;
}
}
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
@ -831,21 +843,23 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event)
QPointF posAfterMove; QPointF posAfterMove;
if (getMovingItem()) if (getMovingItem())
{
posBeforeMove = getMovingItem()->pos(); posBeforeMove = getMovingItem()->pos();
QGraphicsView::mouseMoveEvent (event); QGraphicsView::mouseMoveEvent (event);
if (getMovingItem())
posAfterMove = getMovingItem()->pos(); posAfterMove = getMovingItem()->pos();
}
mWidgetMoved = ((posAfterMove-posBeforeMove).manhattanLength() != 0); mWidgetMoved = ((posAfterMove-posBeforeMove).manhattanLength() != 0);
// a cludge for terminate moving of w3c widgets. // 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, // 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. // 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()) if (getMovingItem())
{
if (mWidgetMoved && UBGraphicsW3CWidgetItem::Type == getMovingItem()->type())
getMovingItem()->setPos(posBeforeMove); getMovingItem()->setPos(posBeforeMove);
} }
}
} }
void UBBoardView::rubberItems() void UBBoardView::rubberItems()
@ -1270,7 +1284,10 @@ void UBBoardView::mouseReleaseEvent (QMouseEvent *event)
setMovingItem(nullptr); setMovingItem(nullptr);
} }
else else
if (getMovingItem() && (!isCppTool(getMovingItem()) || UBGraphicsCurtainItem::Type == getMovingItem()->type())) {
if (getMovingItem())
{
if (!isCppTool(getMovingItem()) || UBGraphicsCurtainItem::Type == getMovingItem()->type())
{ {
if (suspendedMousePressEvent) if (suspendedMousePressEvent)
{ {
@ -1315,6 +1332,10 @@ void UBBoardView::mouseReleaseEvent (QMouseEvent *event)
} }
else else
bReleaseIsNeed = true; bReleaseIsNeed = true;
}
else
bReleaseIsNeed = true;
}
if (bReleaseIsNeed) if (bReleaseIsNeed)
{ {
@ -1402,9 +1423,13 @@ void UBBoardView::mouseReleaseEvent (QMouseEvent *event)
return; return;
} }
if (mWidgetMoved) { if (mWidgetMoved)
{
if (getMovingItem())
{
getMovingItem()->setSelected(false); getMovingItem()->setSelected(false);
setMovingItem(NULL); setMovingItem(NULL);
}
mWidgetMoved = false; mWidgetMoved = false;
} }
else { else {

@ -328,6 +328,8 @@ void UBGraphicsItemDelegate::postpaint(QPainter *painter, const QStyleOptionGrap
{ {
Q_UNUSED(widget) Q_UNUSED(widget)
if (option->state & QStyle::State_Selected && !controlsExist()) { if (option->state & QStyle::State_Selected && !controlsExist()) {
if (UBStylusTool::Play != UBDrawingController::drawingController()->stylusTool())
{
painter->save(); painter->save();
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77)); painter->setBrush(QColor(0x88, 0x88, 0x88, 0x77));
@ -335,6 +337,7 @@ void UBGraphicsItemDelegate::postpaint(QPainter *painter, const QStyleOptionGrap
painter->restore(); painter->restore();
} }
}
} }
bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)

Loading…
Cancel
Save