Play and Selector tools behavior restored after changing of architecture of QGraphicsWidgets.

Fixed some related issues.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent 0ab928788c
commit 907f305703
  1. 147
      src/board/UBBoardView.cpp
  2. 2
      src/board/UBBoardView.h
  3. 8
      src/core/UB.h
  4. 19
      src/domain/UBGraphicsItemDelegate.cpp
  5. 3
      src/domain/UBGraphicsItemDelegate.h
  6. 10
      src/domain/UBGraphicsScene.cpp
  7. 20
      src/domain/UBGraphicsTextItem.cpp
  8. 2
      src/domain/UBGraphicsTextItemDelegate.cpp
  9. 10
      src/domain/UBGraphicsWidgetItem.cpp
  10. 17
      src/domain/UBGraphicsWidgetItem.h

@ -415,11 +415,7 @@ bool UBBoardView::itemIsLocked(QGraphicsItem *item)
if (!item)
return false;
if (item->data(UBGraphicsItemData::ItemLocked).toBool())
return true;
return itemIsLocked(item->parentItem());
return item->data(UBGraphicsItemData::ItemLocked).toBool();
}
bool UBBoardView::itemHaveParentWithType(QGraphicsItem *item, int type)
@ -434,32 +430,76 @@ bool UBBoardView::itemHaveParentWithType(QGraphicsItem *item, int type)
}
void UBBoardView::handleItemsSelection(QGraphicsItem *item)
{
// we need to select new pressed itemOnBoard and deselect all other items.
// the trouble is in:
// some items can has parents (groupped items or strokes, or strokes in groups).
// some items is already selected and we don't need to reselect them
//
// item selection managed by QGraphicsView::mousePressEvent(). It should be called later.
if (item)
{
// item has group as first parent - it is any item or UBGraphicsStrokesGroup.
if(item->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())
return;
// delegate buttons shouldn't selected
if (DelegateButton::Type == movingItem->type())
return;
// click on svg items (images on Frame) shouldn't change selection.
if (QGraphicsSvgItem::Type == movingItem->type())
return;
// Delegate frame shouldn't selected
if (UBGraphicsDelegateFrame::Type == movingItem->type())
return;
// if we need to uwe multiple selection - we shouldn't deselect other items.
if (!mMultipleSelectionIsEnabled)
{
// if Item can be selected at mouse press - then we need to deselect all other items.
foreach(QGraphicsItem *iter_item, scene()->selectedItems())
{
if (iter_item != item)
{
iter_item->setSelected(false);
}
}
}
}
}
bool UBBoardView::itemShouldReceiveMousePressEvent(QGraphicsItem *item)
{
if (!item)
/*
Some items should receive mouse press events averytime,
some items should receive that events when they are selected,
some items shouldn't receive mouse press events at mouse press, but should receive them at mouse release (suspended mouse press event)
Here we determines cases when items should to get mouse press event at pressing on mouse.
*/
if (!item)
return true;
// for now background objects is not interactable, but it can be deprecated for some items in the future.
if (item == scene()->backgroundObject())
return false;
if (itemIsLocked(item))
return false;
// some behavior depends on current tool.
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
if ((currentTool == UBStylusTool::Play) && UBGraphicsGroupContainerItem::Type == movingItem->type())
{
movingItem = NULL;
return false;
}
switch(item->type())
{
case DelegateButton::Type:
case UBGraphicsMediaItem::Type:
return false;
case UBGraphicsSvgItem::Type:
case UBGraphicsPixmapItem::Type:
case UBGraphicsTextItem::Type:
if ((currentTool == UBStylusTool::Selector) && item->isSelected())
@ -470,10 +510,18 @@ bool UBBoardView::itemShouldReceiveMousePressEvent(QGraphicsItem *item)
return false;
break;
// Groups shouldn't reacts on any presses and moves for Play tool.
case UBGraphicsGroupContainerItem::Type:
return (currentTool == UBStylusTool::Selector);
if(currentTool == UBStylusTool::Play)
{
movingItem = NULL;
return false;
}
else
return true;
break;
case UBGraphicsW3CWidgetItem::Type:
case UBGraphicsWidgetItem::Type:
if (currentTool == UBStylusTool::Selector && item->parentItem() && item->parentItem()->isSelected())
return true;
if (currentTool == UBStylusTool::Selector && item->isSelected())
@ -497,28 +545,27 @@ bool UBBoardView::itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item)
if (item == scene()->backgroundObject())
return false;
if (itemIsLocked(item))
return false;
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
switch(item->type())
{
case UBGraphicsPixmapItem::Type:
case UBGraphicsTextItem::Type:
case UBGraphicsW3CWidgetItem::Type:
case UBGraphicsWidgetItem::Type:
if (currentTool == UBStylusTool::Selector && !item->isSelected() && item->parentItem())
return true;
if (currentTool == UBStylusTool::Selector && item->isSelected())
return true;
break;
case DelegateButton::Type:
case UBGraphicsMediaItem::Type:
return true;
default:
return false;
}
return false;
}
@ -552,6 +599,7 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item)
if(currentTool == UBStylusTool::Play)
return false;
case UBGraphicsSvgItem::Type:
case UBGraphicsPixmapItem::Type:
if (item->isSelected())
return false;
@ -565,6 +613,29 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item)
return false;
}
QGraphicsItem* UBBoardView::determineItemToPress(QGraphicsItem *item)
{
if(item)
{
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
// groups should should be moved instead of strokes groups
if (item->parentItem() && UBGraphicsStrokesGroup::Type == item->type())
return item->parentItem();
// if item is on group and froup is not selected - group should take press.
if (UBStylusTool::Selector == currentTool && item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type() && !item->parentItem()->isSelected())
return item->parentItem();
// items like polygons placed in two groups nested, so we need to recursive call.
if(item->parentItem() && UBGraphicsStrokesGroup::Type == item->parentItem()->type())
return determineItemToPress(item->parentItem());
}
return item;
}
// determine item to interacts: item self or it's container.
QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item)
{
@ -599,7 +670,7 @@ QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item)
// items like polygons placed in two groups nested, so we need to recursive call.
if(item->parentItem() && UBGraphicsStrokesGroup::Type == item->parentItem()->type())
return determineItemToMove(item->parentItem());
return determineItemToMove(item->parentItem());
}
return item;
@ -612,28 +683,17 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event)
// Determining item who will take mouse press event
//all other items will be deselected and if all item will be deselected, then
// wrong item can catch mouse press. because selected items placed on the top
QGraphicsItem *pressedItem = determineItemToMove(movingItem);
QGraphicsItem *pressedItem = determineItemToPress(movingItem);
if (movingItem
&& !(movingItem->parentItem() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())
&& QGraphicsSvgItem::Type != movingItem->type()
&& UBGraphicsDelegateFrame::Type != movingItem->type()
&& !mMultipleSelectionIsEnabled)
{
foreach(QGraphicsItem *item, scene()->selectedItems())
{
if (item != pressedItem)
{
item->setSelected(false);
}
}
}
handleItemsSelection(movingItem);
if (mMultipleSelectionIsEnabled)
return;
if (itemShouldReceiveMousePressEvent(movingItem))
{
QGraphicsView::mousePressEvent (event);
}
else
{
if (movingItem)
@ -991,7 +1051,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
setToolCursor (currentTool);
// first propagate device release to the scene
// first/ propagate device release to the scene
if (scene ())
scene ()->inputDeviceRelease ();
@ -1012,13 +1072,14 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
movingItem = NULL;
delete suspendedMousePressEvent;
suspendedMousePressEvent = NULL;
bReleaseIsNeed = true;
}
else
{
if (QGraphicsSvgItem::Type != movingItem->type() &&
UBGraphicsDelegateFrame::Type != movingItem->type() &&
UBToolWidget::Type != movingItem->type() &&
QGraphicsWidget::Type != movingItem->type() &&
UBToolWidget::Type != movingItem->type() &&
QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools.
!(movingItem->parentItem() && UBGraphicsW3CWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()))
{
bReleaseIsNeed = false;
@ -1054,7 +1115,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
}
else
{
if (suspendedMousePressEvent && movingItem && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())
if (suspendedMousePressEvent)
{
QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop
movingItem = NULL;

@ -54,10 +54,12 @@ class UBBoardView : public QGraphicsView
protected:
bool itemIsLocked(QGraphicsItem *item);
void handleItemsSelection(QGraphicsItem *item);
bool itemShouldReceiveMousePressEvent(QGraphicsItem *item);
bool itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item);
bool itemHaveParentWithType(QGraphicsItem *item, int type);
bool itemShouldBeMoved(QGraphicsItem *item);
QGraphicsItem* determineItemToPress(QGraphicsItem *item);
QGraphicsItem* determineItemToMove(QGraphicsItem *item);
void handleItemMousePress(QMouseEvent *event);
void handleItemMouseMove(QMouseEvent *event);

@ -133,11 +133,10 @@ struct UBGraphicsItemType
PolygonItemType = QGraphicsItem::UserType + 1,
PixmapItemType,
SvgItemType,
DelegateButtonType,
MediaItemType,
AppleWidgetItemType,
PDFItemType,
TextItemType,
W3CWidgetItemType,
TextItemType,
CurtainItemType,
RulerItemType,
CompassItemType,
@ -147,7 +146,8 @@ struct UBGraphicsItemType
MagnifierItemType,
cacheItemType,
groupContainerType,
ToolWidgetItemType
ToolWidgetItemType,
GraphicsWidgetItemType
};
};

@ -75,7 +75,6 @@ void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// make sure delegate is selected, to avoid control being hidden
mPressedTime = QTime::currentTime();
// mDelegated->setSelected(true);
event->setAccepted(!mIsTransparentToMouseEvent);
}
@ -256,12 +255,7 @@ bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mDragPixmap = QPixmap();
return true;
}
if(isLocked()) {
event->accept();
return true;
} else {
return false;
}
return false;
}
bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event)
@ -748,16 +742,7 @@ void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsI
QPainterPath path;
path.addRoundedRect(rect(), 10, 10);
if (parentItem() && parentItem()->data(UBGraphicsItemData::ItemLocked).toBool())
{
QColor baseColor = UBSettings::paletteColor;
baseColor.setAlphaF(baseColor.alphaF() / 3);
setBrush(QBrush(baseColor));
}
else
{
setBrush(QBrush(UBSettings::paletteColor));
}
setBrush(QBrush(UBSettings::paletteColor));
painter->fillPath(path, brush());
}

@ -40,6 +40,9 @@ class DelegateButton: public QGraphicsSvgItem
virtual ~DelegateButton();
enum { Type = UBGraphicsItemType::DelegateButtonType };
virtual int type() const { return Type; }
void setTransparentToMouseEvent(bool tr)
{
mIsTransparentToMouseEvent = tr;

@ -2334,7 +2334,7 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
{
switch (item->type())
{
case UBGraphicsW3CWidgetItem::Type:
case UBGraphicsWidgetItem::Type:
{
UBGraphicsW3CWidgetItem *wc3_widget = dynamic_cast<UBGraphicsW3CWidgetItem*>(item);
if (0 != wc3_widget)
@ -2342,14 +2342,6 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent)
wc3_widget->remove();
break;
}
case UBGraphicsAppleWidgetItem::Type:
{
UBGraphicsAppleWidgetItem *Apple_widget = dynamic_cast<UBGraphicsAppleWidgetItem*>(item);
if (0 !=Apple_widget)
if (!Apple_widget->hasFocus())
Apple_widget->remove();
break;
}
case UBGraphicsTextItem::Type:
{
UBGraphicsTextItem *text_item = dynamic_cast<UBGraphicsTextItem*>(item);

@ -23,6 +23,7 @@
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "board/UBBoardView.h"
#include "board/UBDrawingController.h"
#include "core/UBSettings.h"
#include "core/memcheck.h"
@ -85,7 +86,15 @@ QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVarian
void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// scene()->itemAt(pos) returns 0 if pos is not over text, but over text item, but mouse press comes.
// It is a cludge...
if (UBStylusTool::Play == UBDrawingController::drawingController()->stylusTool())
{
event->accept();
clearFocus();
return;
}
if (mDelegate)
{
mDelegate->mousePressEvent(event);
@ -164,6 +173,15 @@ void UBGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
// scene()->itemAt(pos) returns 0 if pos is not over text, but over text item, but mouse press comes.
// It is a cludge...
if (UBStylusTool::Play == UBDrawingController::drawingController()->stylusTool())
{
event->accept();
clearFocus();
return;
}
if (mMultiClickState == 1)
{
if (mDelegate)

@ -303,7 +303,7 @@ void UBGraphicsTextItemDelegate::positionHandles()
UBGraphicsGroupContainerItem *group = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(mDelegated->parentItem());
mToolBarItem->hide();
if (mToolBarItem->parentItem() && !mToolBarItem->parentItem()->data(UBGraphicsItemData::ItemLocked).toBool())
if (mToolBarItem->parentItem())
{
if (group && group->getCurrentItem() == mDelegated && group->isSelected())
mToolBarItem->show();

@ -670,11 +670,6 @@ UBGraphicsAppleWidgetItem::~UBGraphicsAppleWidgetItem()
/* NOOP */
}
int UBGraphicsAppleWidgetItem::type() const
{
return Type;
}
void UBGraphicsAppleWidgetItem::setUuid(const QUuid &pUuid)
{
UBItem::setUuid(pUuid);
@ -871,11 +866,6 @@ UBGraphicsW3CWidgetItem::~UBGraphicsW3CWidgetItem()
/* NOOP */
}
int UBGraphicsW3CWidgetItem::type() const
{
return Type;
}
void UBGraphicsW3CWidgetItem::setUuid(const QUuid &pUuid)
{
UBItem::setUuid(pUuid);

@ -46,6 +46,10 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView
UBGraphicsWidgetItem(const QUrl &pWidgetUrl = QUrl(), QGraphicsItem *parent = 0);
~UBGraphicsWidgetItem();
enum { Type = UBGraphicsItemType::GraphicsWidgetItemType };
virtual int type() const { return Type; }
virtual void initialize();
QUrl mainHtml();
@ -179,15 +183,8 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
~UBGraphicsAppleWidgetItem();
virtual void copyItemParameters(UBItem *copy) const;
virtual int type() const;
virtual void setUuid(const QUuid &pUuid);
virtual UBItem* deepCopy() const;
enum
{
Type = UBGraphicsItemType::AppleWidgetItemType
};
};
class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
@ -227,15 +224,9 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
QString version;
};
enum
{
Type = UBGraphicsItemType::W3CWidgetItemType
};
UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
~UBGraphicsW3CWidgetItem();
virtual int type() const;
virtual void setUuid(const QUuid &pUuid);
virtual UBItem* deepCopy() const;
virtual void copyItemParameters(UBItem *copy) const;

Loading…
Cancel
Save