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. 141
      src/board/UBBoardView.cpp
  2. 2
      src/board/UBBoardView.h
  3. 6
      src/core/UB.h
  4. 15
      src/domain/UBGraphicsItemDelegate.cpp
  5. 3
      src/domain/UBGraphicsItemDelegate.h
  6. 10
      src/domain/UBGraphicsScene.cpp
  7. 18
      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) if (!item)
return false; return false;
if (item->data(UBGraphicsItemData::ItemLocked).toBool()) return item->data(UBGraphicsItemData::ItemLocked).toBool();
return true;
return itemIsLocked(item->parentItem());
} }
bool UBBoardView::itemHaveParentWithType(QGraphicsItem *item, int type) 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) bool UBBoardView::itemShouldReceiveMousePressEvent(QGraphicsItem *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) if (!item)
return true; return true;
// for now background objects is not interactable, but it can be deprecated for some items in the future.
if (item == scene()->backgroundObject()) if (item == scene()->backgroundObject())
return false; return false;
if (itemIsLocked(item)) // some behavior depends on current tool.
return false;
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
if ((currentTool == UBStylusTool::Play) && UBGraphicsGroupContainerItem::Type == movingItem->type())
{
movingItem = NULL;
return false;
}
switch(item->type()) switch(item->type())
{ {
case DelegateButton::Type:
case UBGraphicsMediaItem::Type: case UBGraphicsMediaItem::Type:
return false; return false;
case UBGraphicsSvgItem::Type:
case UBGraphicsPixmapItem::Type: case UBGraphicsPixmapItem::Type:
case UBGraphicsTextItem::Type: case UBGraphicsTextItem::Type:
if ((currentTool == UBStylusTool::Selector) && item->isSelected()) if ((currentTool == UBStylusTool::Selector) && item->isSelected())
@ -470,10 +510,18 @@ bool UBBoardView::itemShouldReceiveMousePressEvent(QGraphicsItem *item)
return false; return false;
break; break;
// Groups shouldn't reacts on any presses and moves for Play tool.
case UBGraphicsGroupContainerItem::Type: 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()) if (currentTool == UBStylusTool::Selector && item->parentItem() && item->parentItem()->isSelected())
return true; return true;
if (currentTool == UBStylusTool::Selector && item->isSelected()) if (currentTool == UBStylusTool::Selector && item->isSelected())
@ -497,28 +545,27 @@ bool UBBoardView::itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item)
if (item == scene()->backgroundObject()) if (item == scene()->backgroundObject())
return false; return false;
if (itemIsLocked(item))
return false;
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
switch(item->type()) switch(item->type())
{ {
case UBGraphicsPixmapItem::Type: case UBGraphicsPixmapItem::Type:
case UBGraphicsTextItem::Type: case UBGraphicsTextItem::Type:
case UBGraphicsW3CWidgetItem::Type: case UBGraphicsWidgetItem::Type:
if (currentTool == UBStylusTool::Selector && !item->isSelected() && item->parentItem()) if (currentTool == UBStylusTool::Selector && !item->isSelected() && item->parentItem())
return true; return true;
if (currentTool == UBStylusTool::Selector && item->isSelected()) if (currentTool == UBStylusTool::Selector && item->isSelected())
return true; return true;
break; break;
case DelegateButton::Type:
case UBGraphicsMediaItem::Type: case UBGraphicsMediaItem::Type:
return true; return true;
default: default:
return false; return false;
} }
return false; return false;
} }
@ -552,6 +599,7 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item)
if(currentTool == UBStylusTool::Play) if(currentTool == UBStylusTool::Play)
return false; return false;
case UBGraphicsSvgItem::Type:
case UBGraphicsPixmapItem::Type: case UBGraphicsPixmapItem::Type:
if (item->isSelected()) if (item->isSelected())
return false; return false;
@ -565,6 +613,29 @@ bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item)
return false; 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. // determine item to interacts: item self or it's container.
QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item) QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item)
{ {
@ -612,28 +683,17 @@ void UBBoardView::handleItemMousePress(QMouseEvent *event)
// Determining item who will take mouse press event // Determining item who will take mouse press event
//all other items will be deselected and if all item will be deselected, then //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 // wrong item can catch mouse press. because selected items placed on the top
QGraphicsItem *pressedItem = determineItemToMove(movingItem); QGraphicsItem *pressedItem = determineItemToPress(movingItem);
if (movingItem handleItemsSelection(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);
}
}
}
if (mMultipleSelectionIsEnabled) if (mMultipleSelectionIsEnabled)
return; return;
if (itemShouldReceiveMousePressEvent(movingItem)) if (itemShouldReceiveMousePressEvent(movingItem))
{
QGraphicsView::mousePressEvent (event); QGraphicsView::mousePressEvent (event);
}
else else
{ {
if (movingItem) if (movingItem)
@ -991,7 +1051,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool (); UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
setToolCursor (currentTool); setToolCursor (currentTool);
// first propagate device release to the scene // first/ propagate device release to the scene
if (scene ()) if (scene ())
scene ()->inputDeviceRelease (); scene ()->inputDeviceRelease ();
@ -1012,13 +1072,14 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
movingItem = NULL; movingItem = NULL;
delete suspendedMousePressEvent; delete suspendedMousePressEvent;
suspendedMousePressEvent = NULL; suspendedMousePressEvent = NULL;
bReleaseIsNeed = true;
} }
else else
{ {
if (QGraphicsSvgItem::Type != movingItem->type() && if (QGraphicsSvgItem::Type != movingItem->type() &&
UBGraphicsDelegateFrame::Type != movingItem->type() && UBGraphicsDelegateFrame::Type != movingItem->type() &&
UBToolWidget::Type != movingItem->type() && UBToolWidget::Type != movingItem->type() &&
QGraphicsWidget::Type != movingItem->type() && QGraphicsWebView::Type != movingItem->type() && // for W3C widgets as Tools.
!(movingItem->parentItem() && UBGraphicsW3CWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type())) !(movingItem->parentItem() && UBGraphicsW3CWidgetItem::Type == movingItem->type() && UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type()))
{ {
bReleaseIsNeed = false; bReleaseIsNeed = false;
@ -1054,7 +1115,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
} }
else else
{ {
if (suspendedMousePressEvent && movingItem && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool()) if (suspendedMousePressEvent)
{ {
QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop QGraphicsView::mousePressEvent(suspendedMousePressEvent); // suspendedMousePressEvent is deleted by old Qt event loop
movingItem = NULL; movingItem = NULL;

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

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

@ -75,7 +75,6 @@ void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
// make sure delegate is selected, to avoid control being hidden // make sure delegate is selected, to avoid control being hidden
mPressedTime = QTime::currentTime(); mPressedTime = QTime::currentTime();
// mDelegated->setSelected(true);
event->setAccepted(!mIsTransparentToMouseEvent); event->setAccepted(!mIsTransparentToMouseEvent);
} }
@ -256,12 +255,7 @@ bool UBGraphicsItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
mDragPixmap = QPixmap(); mDragPixmap = QPixmap();
return true; return true;
} }
if(isLocked()) {
event->accept();
return true;
} else {
return false; return false;
}
} }
bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event) bool UBGraphicsItemDelegate::weelEvent(QGraphicsSceneWheelEvent *event)
@ -748,16 +742,7 @@ void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsI
QPainterPath path; QPainterPath path;
path.addRoundedRect(rect(), 10, 10); 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()); painter->fillPath(path, brush());
} }

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

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

@ -23,6 +23,7 @@
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
#include "board/UBBoardView.h" #include "board/UBBoardView.h"
#include "board/UBDrawingController.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/memcheck.h" #include "core/memcheck.h"
@ -85,6 +86,14 @@ QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVarian
void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) 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) if (mDelegate)
{ {
@ -164,6 +173,15 @@ void UBGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void UBGraphicsTextItem::mouseReleaseEvent(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 (mMultiClickState == 1)
{ {
if (mDelegate) if (mDelegate)

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

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

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

Loading…
Cancel
Save