From aa5945540776f3205b47af83a6c33e3c6f963141 Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Thu, 14 Jun 2012 18:25:01 +0300
Subject: [PATCH 1/8] First implementation of Play Tool.

It's icon is temporary.

Behavior implemented:
1. Can interact with all items without showing items frames (but ToolBar shows).
2. Cannot move items, but can drag images.
3. Selected items appears deselected when Play tool chosen.
4. Play tool don't requires selecting of item before interacts.
5. Cursor looks like tool icon in text and image widgets (should be the same in any others widgets, but now in w3c is not).
---
 resources/forms/mainWindow.ui                 |  16 ++++++++++++++
 resources/images/stylusPalette/handPlay.png   | Bin 0 -> 444 bytes
 resources/images/stylusPalette/handPlayOn.png | Bin 0 -> 603 bytes
 resources/sankore.qrc                         |   2 ++
 src/api/UBWidgetUniboardAPI.cpp               |   4 ++++
 src/board/UBBoardView.cpp                     |  20 +++++++++++++++---
 src/board/UBDrawingController.cpp             |   9 ++++++++
 src/board/UBDrawingController.h               |   1 +
 src/core/UB.h                                 |   1 +
 src/domain/UBGraphicsItemDelegate.cpp         |   4 +++-
 src/domain/UBGraphicsProxyWidget.cpp          |   3 ++-
 src/domain/UBGraphicsScene.cpp                |   5 +++--
 src/gui/UBStylusPalette.cpp                   |   1 +
 src/tools/UBGraphicsCompass.cpp               |  18 ++++++++++------
 src/tools/UBGraphicsProtractor.cpp            |  14 ++++++------
 src/tools/UBGraphicsRuler.cpp                 |   5 +++--
 src/tools/UBGraphicsTriangle.cpp              |   7 ++++--
 17 files changed, 86 insertions(+), 24 deletions(-)
 create mode 100644 resources/images/stylusPalette/handPlay.png
 create mode 100644 resources/images/stylusPalette/handPlayOn.png

diff --git a/resources/forms/mainWindow.ui b/resources/forms/mainWindow.ui
index a2ac84b8..6f81085c 100644
--- a/resources/forms/mainWindow.ui
+++ b/resources/forms/mainWindow.ui
@@ -1649,6 +1649,22 @@
     <string>Group items</string>
    </property>
   </action>
+  <action name="actionPlay">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="icon">
+    <iconset resource="../sankore.qrc">
+     <normaloff>:/images/stylusPalette/handPlay.png</normaloff>
+     <normalon>:/images/stylusPalette/handPlayOn.png</normalon>:/images/stylusPalette/handPlay.png</iconset>
+   </property>
+   <property name="text">
+    <string>Play</string>
+   </property>
+   <property name="toolTip">
+    <string>Interact with items</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="../sankore.qrc"/>
diff --git a/resources/images/stylusPalette/handPlay.png b/resources/images/stylusPalette/handPlay.png
new file mode 100644
index 0000000000000000000000000000000000000000..999f7703d66dae1639681e63fc28e21af797d040
GIT binary patch
literal 444
zcmeAS@N?(olHy`uVBq!ia0vp^3Lq@N1|*eVE!z&H*pj^6UH*dsXT<kAKoQOYkH}&m
z?E%JaC$sH<j9;EEjv*QM-cCQwcSM21_2`d>|0>giAM^CGh6EVT@eK}I{QXl0@4-Tu
z<AwjkHr#!;Yf8$2XKXR%QkNK4)$A0UsIT~Z&QhT#hw51`ehf?sSZMz^RaVUBXmzyC
zJEfYbf|=6_VpiSgxF>Y1>9n<eoZp3emS4aA_-tLX;5*OBbjR$y*9t`W4hpUJ_jzso
z>L&MgQMI!Tv$XS;6`Twz)D1FNW_l#d@FqipQOydTSzq-^le%lx3;c>pj4yXTeQ3LZ
z)3vB)u^C_eH~4bDkT$gP5kH@}k9Bk2wC?Bw=M21lsEH=z9x;CS(TDk1t9%^e9WRTu
zN85XEJj{D(an7@b;oj5K0!!BFFThYxEpd$~Nl7e8wMs5Z1yT$~28M>Z24=cO1|f#V
uRwf2k21eQjMpgy}o!0HnC>nC}Q!>*kaclUIX8#|kfx*+&&t;ucLK6TUUan#Q

literal 0
HcmV?d00001

diff --git a/resources/images/stylusPalette/handPlayOn.png b/resources/images/stylusPalette/handPlayOn.png
new file mode 100644
index 0000000000000000000000000000000000000000..9191cffa6fd56a93b1671b4b0522e0cec721baf2
GIT binary patch
literal 603
zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN
z`?>!lvI6;>1s;*b3=DinK$vl=HlH+5kS)pE-Q_<Ra7KK;0~Ap$ag8WRNi0dVN-jzT
zQVd20hK9NZX1YcOA%@0QCI(gpM%o5ORt5&0*6q$H8glbfGSez?Yxt37{~zec8c!F;
zkO=p);f#|GD{!o-t^D<A%M-rcjs*wJ%%A(DT~Szby36x+{M)dMwOdz~Uc9?Dl_4QO
zY(bK?^+JXtiri9xlOm;=F3erS79Mb>pIf1MkHYN3CZ8&|_pRg5Gi>qnKcLPK&U)Rq
zO2JR_1XF^$VB}V*O@>wtULU#)Z1-D~FG(<{vWe+E>!76Fqj=|l!lA3iy+3<@y@+;P
z#*lJ3m{qai-I<+ATSZRasNSS-#V>DK?fq?yKiP`E{cuq_lf!o1Y3dYh&Rg5QHZojs
zS1&yGt#|q556k8D&hA;sCSs^`+;V-q=4BCwCu^QhsF61?&}0adonBcRvEW0+|7WUO
z=XLg2Zj{$H@-sBp?Gq7Do4-0)-$ih*&i9)KqFyQg7Gl=+*--s(2XA<>wB_~1C!6Ho
za5H>&TT_se6PaKbKEakXRQJpW*QHXyEB>nT);OHo@P*}pe#C}1JUlU+hrD}dH|1Zg
zd}4j+=>NZ_o3k4G+gGyX?oDr6%H!gYwsaQj(eM7!9<@8IZw2K7BaXq-)z4*}Q$iB}
D2Ttn+

literal 0
HcmV?d00001

diff --git a/resources/sankore.qrc b/resources/sankore.qrc
index f94729e7..ced5d120 100644
--- a/resources/sankore.qrc
+++ b/resources/sankore.qrc
@@ -125,6 +125,8 @@
         <file>images/toolbar/tools.png</file>
         <file>images/stylusPalette/arrow.png</file>
         <file>images/stylusPalette/arrowOn.png</file>
+        <file>images/stylusPalette/handPlay.png</file>
+        <file>images/stylusPalette/handPlayOn.png</file>
         <file>images/stylusPalette/eraser.png</file>
         <file>images/stylusPalette/eraserOn.png</file>
         <file>images/stylusPalette/hand.png</file>
diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp
index 260734ad..b58b3c3f 100644
--- a/src/api/UBWidgetUniboardAPI.cpp
+++ b/src/api/UBWidgetUniboardAPI.cpp
@@ -123,6 +123,10 @@ void UBWidgetUniboardAPI::setTool(const QString& toolString)
     {
         UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector);
     }
+    else if (lower == "play")
+    {
+        UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Play);
+    }
     else if (lower == "line")
     {
         UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Line);
diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index 59f4e8e5..7d898447 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -453,6 +453,12 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
             }
 
 
+            event->accept();
+        }
+        else if (currentTool == UBStylusTool::Play)
+        {
+            QGraphicsView::mousePressEvent (event);
+
             event->accept();
         }
         else if (currentTool == UBStylusTool::Text)
@@ -584,6 +590,10 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
         }
         else QGraphicsView::mouseMoveEvent (event);
     }
+  else if (currentTool == UBStylusTool::Play)
+  {
+      QGraphicsView::mouseMoveEvent (event);
+  }
   else if ((UBDrawingController::drawingController()->isDrawingTool())
     && !mMouseButtonIsPressed)
   {
@@ -616,9 +626,6 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
 {
     UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
-    scene ()->setToolCursor (currentTool);
-    setToolCursor (currentTool);
-
   // first propagate device release to the scene
   if (scene ())
     scene ()->inputDeviceRelease ();
@@ -644,6 +651,10 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
 
       QGraphicsView::mouseReleaseEvent (event);
     }
+  else if (currentTool == UBStylusTool::Play)
+  {
+      QGraphicsView::mouseReleaseEvent (event);
+  }
   else if (currentTool == UBStylusTool::Text)
     {
       if (mRubberBand)
@@ -1027,6 +1038,9 @@ UBBoardView::setToolCursor (int tool)
     case UBStylusTool::Selector:
       controlViewport->setCursor (UBResources::resources ()->arrowCursor);
       break;
+    case UBStylusTool::Play:
+      controlViewport->setCursor (UBResources::resources ()->drawLineRulerCursor);
+      break;
     case UBStylusTool::Line:
       controlViewport->setCursor (UBResources::resources ()->penCursor);
       break;
diff --git a/src/board/UBDrawingController.cpp b/src/board/UBDrawingController.cpp
index e03ef408..70c54905 100644
--- a/src/board/UBDrawingController.cpp
+++ b/src/board/UBDrawingController.cpp
@@ -54,6 +54,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
     connect(UBApplication::mainWindow->actionEraser, SIGNAL(triggered(bool)), this, SLOT(eraserToolSelected(bool)));
     connect(UBApplication::mainWindow->actionMarker, SIGNAL(triggered(bool)), this, SLOT(markerToolSelected(bool)));
     connect(UBApplication::mainWindow->actionSelector, SIGNAL(triggered(bool)), this, SLOT(selectorToolSelected(bool)));
+    connect(UBApplication::mainWindow->actionPlay, SIGNAL(triggered(bool)), this, SLOT(playToolSelected(bool)));
     connect(UBApplication::mainWindow->actionHand, SIGNAL(triggered(bool)), this, SLOT(handToolSelected(bool)));
     connect(UBApplication::mainWindow->actionZoomIn, SIGNAL(triggered(bool)), this, SLOT(zoomInToolSelected(bool)));
     connect(UBApplication::mainWindow->actionZoomOut, SIGNAL(triggered(bool)), this, SLOT(zoomOutToolSelected(bool)));
@@ -120,6 +121,8 @@ void UBDrawingController::setStylusTool(int tool)
             UBApplication::mainWindow->actionMarker->setChecked(true);
         else if (mStylusTool == UBStylusTool::Selector)
             UBApplication::mainWindow->actionSelector->setChecked(true);
+        else if (mStylusTool == UBStylusTool::Play)
+            UBApplication::mainWindow->actionPlay->setChecked(true);
         else if (mStylusTool == UBStylusTool::Hand)
             UBApplication::mainWindow->actionHand->setChecked(true);
         else if (mStylusTool == UBStylusTool::ZoomIn)
@@ -347,6 +350,12 @@ void UBDrawingController::selectorToolSelected(bool checked)
         setStylusTool(UBStylusTool::Selector);
 }
 
+void UBDrawingController::playToolSelected(bool checked)
+{
+    if (checked)
+        setStylusTool(UBStylusTool::Play);
+}
+
 void UBDrawingController::handToolSelected(bool checked)
 {
     if (checked)
diff --git a/src/board/UBDrawingController.h b/src/board/UBDrawingController.h
index 4c620f1c..429c8b24 100644
--- a/src/board/UBDrawingController.h
+++ b/src/board/UBDrawingController.h
@@ -88,6 +88,7 @@ class UBDrawingController : public QObject
         void eraserToolSelected(bool checked);
         void markerToolSelected(bool checked);
         void selectorToolSelected(bool checked);
+        void playToolSelected(bool checked);
         void handToolSelected(bool checked);
         void zoomInToolSelected(bool checked);
         void zoomOutToolSelected(bool checked);
diff --git a/src/core/UB.h b/src/core/UB.h
index 46fa6e8c..21d635b0 100644
--- a/src/core/UB.h
+++ b/src/core/UB.h
@@ -28,6 +28,7 @@ struct UBStylusTool
 		Eraser, 
  		Marker, 
 		Selector, 
+        Play,
 		Hand, 
 		ZoomIn, 
 		ZoomOut, 
diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp
index d1759d3f..ab92ab16 100644
--- a/src/domain/UBGraphicsItemDelegate.cpp
+++ b/src/domain/UBGraphicsItemDelegate.cpp
@@ -330,7 +330,9 @@ void UBGraphicsItemDelegate::positionHandles()
         showHide(shownOnDisplay);
         lock(isLocked());
         updateFrame();
-        mFrame->show();
+
+        if (UBStylusTool::Play != UBDrawingController::drawingController()->stylusTool())
+            mFrame->show();
 
         updateButtons(true);
 
diff --git a/src/domain/UBGraphicsProxyWidget.cpp b/src/domain/UBGraphicsProxyWidget.cpp
index 7b949b19..0ed4e3aa 100644
--- a/src/domain/UBGraphicsProxyWidget.cpp
+++ b/src/domain/UBGraphicsProxyWidget.cpp
@@ -82,9 +82,10 @@ void UBGraphicsProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
     else
     {
         // QT Proxy Widget is a bit lazy, we force the selection ...
-        QGraphicsProxyWidget::mousePressEvent(event);
+
         setSelected(true);
     }
+    QGraphicsProxyWidget::mousePressEvent(event);
 }
 
 
diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp
index 0542e598..d75da6a4 100644
--- a/src/domain/UBGraphicsScene.cpp
+++ b/src/domain/UBGraphicsScene.cpp
@@ -2366,8 +2366,9 @@ void UBGraphicsScene::createPointer()
 
 void UBGraphicsScene::setToolCursor(int tool)
 {
-    if (tool != (int)UBStylusTool::Selector
-            && tool != (int)UBStylusTool::Text)
+    if (tool == (int)UBStylusTool::Selector ||
+             tool == (int)UBStylusTool::Text || 
+                tool == (int)UBStylusTool::Play)
     {
         deselectAllItems();
     }
diff --git a/src/gui/UBStylusPalette.cpp b/src/gui/UBStylusPalette.cpp
index 93073ccd..50da9720 100644
--- a/src/gui/UBStylusPalette.cpp
+++ b/src/gui/UBStylusPalette.cpp
@@ -39,6 +39,7 @@ UBStylusPalette::UBStylusPalette(QWidget *parent, Qt::Orientation orient)
     actions << UBApplication::mainWindow->actionEraser;
     actions << UBApplication::mainWindow->actionMarker;
     actions << UBApplication::mainWindow->actionSelector;
+    actions << UBApplication::mainWindow->actionPlay;
 
     actions << UBApplication::mainWindow->actionHand;
     actions << UBApplication::mainWindow->actionZoomIn;
diff --git a/src/tools/UBGraphicsCompass.cpp b/src/tools/UBGraphicsCompass.cpp
index c0386d1a..f73fd274 100644
--- a/src/tools/UBGraphicsCompass.cpp
+++ b/src/tools/UBGraphicsCompass.cpp
@@ -170,7 +170,8 @@ QVariant UBGraphicsCompass::itemChange(GraphicsItemChange change, const QVariant
 
 void UBGraphicsCompass::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
-	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
+	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector &&
+        UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Play)
 		return;
 
     if (resizeButtonRect().contains(event->pos()))
@@ -205,7 +206,8 @@ void UBGraphicsCompass::mousePressEvent(QGraphicsSceneMouseEvent *event)
 
 void UBGraphicsCompass::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
-	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
+	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector &&
+        UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Play)
 		return;
 
     if (!mResizing && !mRotating && !mDrawing)
@@ -249,7 +251,8 @@ void UBGraphicsCompass::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 
 void UBGraphicsCompass::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
-	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
+	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector &&
+        UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Play)
 		return;
 
     if (mResizing)
@@ -289,7 +292,8 @@ void UBGraphicsCompass::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 
 void UBGraphicsCompass::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 {
-	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
+	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector && 
+        UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Play)
 		return;
 
     mOuterCursor = cursor();
@@ -318,7 +322,8 @@ void UBGraphicsCompass::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 
 void UBGraphicsCompass::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
 {
-	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
+	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector &&
+        UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Play)
 		return;
 
     mShowButtons = false;
@@ -331,7 +336,8 @@ void UBGraphicsCompass::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
 
 void UBGraphicsCompass::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
 {
-	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
+	if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector &&
+        UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Play)
 		return;
 
     mShowButtons = shape().contains(event->pos());
diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp
index f00bf275..3d38a21b 100644
--- a/src/tools/UBGraphicsProtractor.cpp
+++ b/src/tools/UBGraphicsProtractor.cpp
@@ -250,13 +250,19 @@ void UBGraphicsProtractor::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
     if (scene())
         scene()->setModified(true);
 
+    if (!mShowButtons)
+    {
+        mShowButtons = true;
+        update();
+    }
+
     mCurrentTool = None;
 }
 
 
 void UBGraphicsProtractor::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 {
-    if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector)
+    if (UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Selector && UBDrawingController::drawingController ()->stylusTool() != UBStylusTool::Play)
         return;
 
     if (!mShowButtons)
@@ -292,12 +298,6 @@ void UBGraphicsProtractor::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
 
     Tool currentTool = toolFromPos(event->pos());
 
-    if (!mShowButtons)
-    {
-        mShowButtons = true;
-        update();
-    }
-
     if (currentTool == Move)
         setCursor(Qt::SizeAllCursor);
     else
diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp
index 720b7b22..97f37084 100644
--- a/src/tools/UBGraphicsRuler.cpp
+++ b/src/tools/UBGraphicsRuler.cpp
@@ -268,7 +268,7 @@ void UBGraphicsRuler::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
 {
 	UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
-	if (currentTool == UBStylusTool::Selector)
+	if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
 	{
 		mCloseSvgItem->setVisible(mShowButtons);
 		mResizeSvgItem->setVisible(mShowButtons);
@@ -376,7 +376,8 @@ void UBGraphicsRuler::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 {
 	UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
-	if (currentTool == UBStylusTool::Selector)
+	if (currentTool == UBStylusTool::Selector ||
+        currentTool == UBStylusTool::Play)
 	{
 		mCloseSvgItem->setParentItem(this);
 	    mResizeSvgItem->setParentItem(this);
diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp
index ef946af7..57d77d7f 100644
--- a/src/tools/UBGraphicsTriangle.cpp
+++ b/src/tools/UBGraphicsTriangle.cpp
@@ -763,7 +763,9 @@ void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 {
     UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
-    if (currentTool == UBStylusTool::Selector)  {
+    if (currentTool == UBStylusTool::Selector ||
+        currentTool == UBStylusTool::Play)
+    {
         mCloseSvgItem->setParentItem(this);
 
         mShowButtons = true;
@@ -813,7 +815,8 @@ void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
 {
     UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
-    if (currentTool == UBStylusTool::Selector)
+    if (currentTool == UBStylusTool::Selector ||
+        currentTool == UBStylusTool::Play)
     {
         mCloseSvgItem->setVisible(mShowButtons);
         mVFlipSvgItem->setVisible(mShowButtons);

From a3a24b746530af5a3f5c0bbda7a33a9e70a54eac Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Fri, 15 Jun 2012 11:25:55 +0300
Subject: [PATCH 2/8] Cursor upper widgets is the same as upper board. Fixed
 restoring of cursors at mouse release event on board.

---
 src/board/UBBoardView.cpp            | 2 ++
 src/domain/UBGraphicsProxyWidget.cpp | 4 ++++
 src/domain/UBGraphicsScene.cpp       | 5 -----
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index 7d898447..8a61d756 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -626,6 +626,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
 {
     UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
+  setToolCursor (currentTool);
   // first propagate device release to the scene
   if (scene ())
     scene ()->inputDeviceRelease ();
@@ -1019,6 +1020,7 @@ UBBoardView::setToolCursor (int tool)
       break;
     case UBStylusTool::Eraser:
       controlViewport->setCursor (UBResources::resources ()->eraserCursor);
+      scene()->hideEraser();
       break;
     case UBStylusTool::Marker:
       controlViewport->setCursor (UBResources::resources ()->markerCursor);
diff --git a/src/domain/UBGraphicsProxyWidget.cpp b/src/domain/UBGraphicsProxyWidget.cpp
index 0ed4e3aa..567eafa4 100644
--- a/src/domain/UBGraphicsProxyWidget.cpp
+++ b/src/domain/UBGraphicsProxyWidget.cpp
@@ -47,6 +47,10 @@ UBGraphicsProxyWidget::~UBGraphicsProxyWidget()
 
 QVariant UBGraphicsProxyWidget::itemChange(GraphicsItemChange change, const QVariant &value)
 {
+    if (change == QGraphicsItem::ItemCursorHasChanged &&  scene())
+    {
+        unsetCursor();
+    }
     if ((change == QGraphicsItem::ItemSelectedHasChanged)
               &&  scene())
     {
diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp
index d75da6a4..20d657d7 100644
--- a/src/domain/UBGraphicsScene.cpp
+++ b/src/domain/UBGraphicsScene.cpp
@@ -2372,9 +2372,4 @@ void UBGraphicsScene::setToolCursor(int tool)
     {
         deselectAllItems();
     }
-
-    if (tool != (int)UBStylusTool::Eraser)
-    {
-        hideEraser();
-    }
 }

From 714e18556420cb2bf122b85c95b80773725f5b84 Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Mon, 18 Jun 2012 13:54:51 +0300
Subject: [PATCH 3/8] Fixed behavior of locked items: - locked items is not
 editable now. - toolbar for text item hides when item is locked

Fixed behavior of toolbar:
toolbar of media items hides after 5s of idle.
---
 src/board/UBBoardView.cpp                  | 106 ++++++++++++++++++---
 src/board/UBBoardView.h                    |   4 +
 src/domain/UBGraphicsDelegateFrame.cpp     |   8 +-
 src/domain/UBGraphicsItemDelegate.cpp      |  19 +++-
 src/domain/UBGraphicsItemDelegate.h        |   9 +-
 src/domain/UBGraphicsMediaItem.cpp         |  14 +--
 src/domain/UBGraphicsMediaItem.h           |   4 +
 src/domain/UBGraphicsMediaItemDelegate.cpp |  28 +++++-
 src/domain/UBGraphicsMediaItemDelegate.h   |   6 ++
 src/domain/UBGraphicsTextItemDelegate.cpp  |  11 ++-
 10 files changed, 172 insertions(+), 37 deletions(-)

diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index 8a61d756..c07a9151 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -375,6 +375,45 @@ void UBBoardView::tabletEvent (QTabletEvent * event)
 
 }
 
+bool UBBoardView::hasToolBarAsParent(QGraphicsItem *item)
+{
+    if (!item)
+        return false;
+
+    if (!item->parentItem())
+        return hasToolBarAsParent(0); 
+
+    if (UBGraphicsToolBarItem::Type == item->parentItem()->type())
+        return true;
+
+    else 
+        return hasToolBarAsParent(item->parentItem());        
+}
+
+bool UBBoardView::itemIsLocked(QGraphicsItem *item)
+{
+    if (!item)
+        return false;
+
+    if (item->data(UBGraphicsItemData::ItemLocked).toBool())
+        return true;
+
+    return itemIsLocked(item->parentItem());
+
+}
+
+bool UBBoardView::itemHaveType(QGraphicsItem *item, int type)
+{
+    if (!item)
+        return false;
+
+    if (type == item->type())
+        return true;
+    
+    return itemHaveType(item->parentItem(), type);
+
+}
+
 void UBBoardView::mousePressEvent (QMouseEvent *event)
 {
     if (isAbsurdPoint (event->pos ()))
@@ -438,10 +477,14 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
                 || movingItem == this->scene()->backgroundObject()
                 || (movingItem->parentItem() && movingItem->parentItem()->type() == UBGraphicsGroupContainerItem::Type))
             {
-                    movingItem = NULL;
-                    QGraphicsView::mousePressEvent (event);
+                if (!itemIsLocked(movingItem)
+                    || itemHaveType(movingItem, UBGraphicsMediaItem::Type))
+                {
 
+                    QGraphicsView::mousePressEvent (event);
                 }
+                movingItem = NULL;
+            }
             else
             {
                 mLastPressedMousePos = mapToScene(event->pos());
@@ -452,12 +495,29 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
                 suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); // удалить
             }
 
-
             event->accept();
         }
         else if (currentTool == UBStylusTool::Play)
         {
-            QGraphicsView::mousePressEvent (event);
+
+            movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
+
+            mLastPressedMousePos = mapToScene(event->pos());
+
+            if (movingItem 
+                && (UBGraphicsGroupContainerItem::Type == movingItem->type()
+                    || UBGraphicsMediaItem::Type == movingItem->type()
+                    || hasToolBarAsParent(movingItem)))
+            {
+                movingItem = NULL;
+                QGraphicsView::mousePressEvent (event);
+                return;
+            }
+
+            if(movingItem && movingItem->parentItem() && movingItem->parentItem()->type() == UBGraphicsGroupContainerItem::Type)
+            {
+                movingItem = movingItem->parentItem(); 
+            }                
 
             event->accept();
         }
@@ -579,7 +639,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
           }
       }
 
-        if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed))
+        if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) &&
+            !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())
         {
             QPointF scenePos = mapToScene(event->pos());
             QPointF newPos = movingItem->pos() + scenePos - mLastPressedMousePos;
@@ -592,7 +653,18 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
     }
   else if (currentTool == UBStylusTool::Play)
   {
-      QGraphicsView::mouseMoveEvent (event);
+      if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) &&
+          !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())
+      {
+          QPointF scenePos = mapToScene(event->pos());
+          QPointF newPos = movingItem->pos() + scenePos - mLastPressedMousePos;
+          movingItem->setPos(newPos);
+          mLastPressedMousePos = scenePos;
+          mWidgetMoved = true;
+          event->accept();
+      }
+      else 
+        QGraphicsView::mouseMoveEvent (event);
   }
   else if ((UBDrawingController::drawingController()->isDrawingTool())
     && !mMouseButtonIsPressed)
@@ -638,13 +710,21 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
           mWidgetMoved = false;
           movingItem = NULL;
       }
-      else if (movingItem && suspendedMousePressEvent)
-      {
-          QGraphicsView::mousePressEvent(suspendedMousePressEvent);     // suspendedMousePressEvent is deleted by old Qt event loop
-          movingItem = NULL;
-          delete suspendedMousePressEvent;
-          suspendedMousePressEvent = NULL;
-      }
+      else 
+          if (movingItem)
+          {         
+              if (suspendedMousePressEvent && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())       
+              {
+                  QGraphicsView::mousePressEvent(suspendedMousePressEvent);     // suspendedMousePressEvent is deleted by old Qt event loop
+                  movingItem = NULL;
+                  delete suspendedMousePressEvent;
+                  suspendedMousePressEvent = NULL;
+              }
+              else 
+              {
+                  movingItem->setSelected(true);
+              }
+          }
 
       if (mUBRubberBand && mUBRubberBand->isVisible()) {
           mUBRubberBand->hide();
diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h
index 21bc12b8..faab052b 100644
--- a/src/board/UBBoardView.h
+++ b/src/board/UBBoardView.h
@@ -51,6 +51,10 @@ class UBBoardView : public QGraphicsView
 
     protected:
 
+        bool hasToolBarAsParent(QGraphicsItem *item);
+        bool itemIsLocked(QGraphicsItem *item);
+        bool itemHaveType(QGraphicsItem *item, int type);
+
         virtual bool event (QEvent * e);
 
         virtual void keyPressEvent(QKeyEvent *event);
diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp
index 3270abf9..0f98e689 100644
--- a/src/domain/UBGraphicsDelegateFrame.cpp
+++ b/src/domain/UBGraphicsDelegateFrame.cpp
@@ -249,8 +249,8 @@ bool UBGraphicsDelegateFrame::canResizeBottomRight(qreal width, qreal height, qr
 
 void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
-    if (mDelegate->delegated()->data(UBGraphicsItemData::ItemLocked).toBool())
-        return;
+    if (None == mCurrentTool)
+        return; 
 
     QLineF move(mStartingPoint, event->scenePos());
     qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
@@ -713,8 +713,8 @@ QGraphicsItem* UBGraphicsDelegateFrame::delegated()
 
 UBGraphicsDelegateFrame::FrameTool UBGraphicsDelegateFrame::toolFromPos(QPointF pos)
 {
-        if(mDelegate->isLocked())
-                return None;
+    if(mDelegate->isLocked())
+        return None;
     else if (bottomRightResizeGripRect().contains(pos))
         return ResizeBottomRight;
     else if (bottomResizeGripRect().contains(pos)){
diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp
index ab92ab16..318a9b89 100644
--- a/src/domain/UBGraphicsItemDelegate.cpp
+++ b/src/domain/UBGraphicsItemDelegate.cpp
@@ -328,7 +328,7 @@ void UBGraphicsItemDelegate::positionHandles()
     if (mDelegated->isSelected()) {
         bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control;
         showHide(shownOnDisplay);
-        lock(isLocked());
+        mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(isLocked()));
         updateFrame();
 
         if (UBStylusTool::Play != UBDrawingController::drawingController()->stylusTool())
@@ -453,6 +453,7 @@ void UBGraphicsItemDelegate::lock(bool locked)
     }
 
     mDelegated->update();
+    positionHandles();
     mFrame->positionHandles();
 }
 
@@ -678,7 +679,7 @@ UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) :
     rect.setWidth(parent->boundingRect().width());
     this->setRect(rect);
 
-    setBrush(QColor(UBSettings::paletteColor));             
+  //  setBrush(QColor(UBSettings::paletteColor));             
     setPen(Qt::NoPen);
     hide();
 
@@ -710,6 +711,17 @@ 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));
+    }
+
     painter->fillPath(path, brush());
 }
 
@@ -1217,6 +1229,7 @@ void DelegateMediaControl::mousePressEvent(QGraphicsSceneMouseEvent *event)
         seekToMousePos(event->pos());
         this->update();
         event->accept();
+        emit used();
     }
 }
 
@@ -1229,6 +1242,7 @@ void DelegateMediaControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
         seekToMousePos(event->pos());
         this->update();
         event->accept();
+        emit used();
     }
 }
 
@@ -1253,6 +1267,7 @@ void DelegateMediaControl::seekToMousePos(QPointF mousePos)
         //OSX is a bit lazy
         updateTicker(tickPos);
     }
+    emit used();
 }
 
 void DelegateMediaControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h
index 79ed8d2d..8ae131d0 100644
--- a/src/domain/UBGraphicsItemDelegate.h
+++ b/src/domain/UBGraphicsItemDelegate.h
@@ -102,8 +102,10 @@ uint smallPoint : 1;
 
 };
 
-class DelegateMediaControl: public QGraphicsRectItem
+class DelegateMediaControl: public QObject, public QGraphicsRectItem
 {
+    Q_OBJECT
+
     public:
 
         DelegateMediaControl(UBGraphicsMediaItem* pDelegated, QGraphicsItem * parent = 0);
@@ -127,7 +129,10 @@ class DelegateMediaControl: public QGraphicsRectItem
         void updateTicker(qint64 time);
         void totalTimeChanged(qint64 newTotalTime);
 
-   protected:
+    signals:
+        void used();
+
+    protected:
         void seekToMousePos(QPointF mousePos);
 
         UBGraphicsMediaItem* mDelegate;
diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp
index 08c8bd52..2228b87a 100644
--- a/src/domain/UBGraphicsMediaItem.cpp
+++ b/src/domain/UBGraphicsMediaItem.cpp
@@ -34,8 +34,8 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
         , mInitialPos(0)
         , mVideoWidget(NULL)
         , mAudioWidget(NULL)
+        , mLinkedImage(NULL)
 {
-    
     update();
 
     QString s = pMediaFileUrl.toLocalFile();
@@ -60,6 +60,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
             mVideoWidget->resize(320,240);
         }
         setWidget(mVideoWidget);
+        haveLinkedImage = true;
     }
     else    
     if (pMediaFileUrl.toLocalFile().contains("audios"))
@@ -71,6 +72,7 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte
         mAudioWidget = new QWidget();
         mAudioWidget->resize(320,26);
         setWidget(mAudioWidget);
+        haveLinkedImage = false;
     }
 
     Phonon::createPath(mMediaObject, mAudioOutput);
@@ -226,7 +228,7 @@ void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
     if (mDelegate)
     {
         mDelegate->mousePressEvent(event);
-        if (mDelegate && parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type())
+        if (parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type())
         {
             UBGraphicsGroupContainerItem *group = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(parentItem());
             if (group)
@@ -242,11 +244,6 @@ void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
             }       
 
         }
-        else
-        {
-            mDelegate->getToolBarItem()->show();
-        }
-
     }
 
     if (parentItem() && parentItem()->type() == UBGraphicsGroupContainerItem::Type)
@@ -271,9 +268,6 @@ void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
 
 void UBGraphicsMediaItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
-    if (data(UBGraphicsItemData::ItemLocked).toBool())
-        return;
-
     if(mShouldMove && (event->buttons() & Qt::LeftButton))
     {
         QPointF offset = event->scenePos() - mMousePressPos;
diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h
index 8d545944..e14e27b8 100644
--- a/src/domain/UBGraphicsMediaItem.h
+++ b/src/domain/UBGraphicsMediaItem.h
@@ -73,6 +73,8 @@ public:
         return mVideoWidget;
     }
 
+    bool hasLinkedImage(){return haveLinkedImage;}
+
     mediaType getMediaType() { return mMediaType; }
 
     virtual UBGraphicsScene* scene();
@@ -115,6 +117,8 @@ private:
     QPointF mMousePressPos;
     QPointF mMouseMovePos;
 
+    bool haveLinkedImage;
+    QGraphicsPixmapItem *mLinkedImage;
 };
 
 
diff --git a/src/domain/UBGraphicsMediaItemDelegate.cpp b/src/domain/UBGraphicsMediaItemDelegate.cpp
index f9b14639..7d164c58 100644
--- a/src/domain/UBGraphicsMediaItemDelegate.cpp
+++ b/src/domain/UBGraphicsMediaItemDelegate.cpp
@@ -33,6 +33,8 @@
 UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent)
     : UBGraphicsItemDelegate(pDelegated, parent, true, false)
     , mMedia(pMedia)
+    , mToolBarShowTimer(NULL)
+    , m_iToolBarShowingInterval(5000)
 {
     QPalette palette;
     palette.setBrush ( QPalette::Light, Qt::darkGray );
@@ -42,27 +44,47 @@ UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pD
     connect(mMedia, SIGNAL(finished()), this, SLOT(updatePlayPauseState()));
     connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64)));
     connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
+
+    if (delegated()->hasLinkedImage())
+    {
+        mToolBarShowTimer = new QTimer();
+        connect(mToolBarShowTimer, SIGNAL(timeout()), this, SLOT(hideToolBar()));
+        mToolBarShowTimer->setInterval(m_iToolBarShowingInterval);
+    }
 }
 
 bool UBGraphicsMediaItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
 {
     Q_UNUSED(event);
     mToolBarItem->show();
+
+    if (mToolBarShowTimer)
+        mToolBarShowTimer->start();
+
     return UBGraphicsItemDelegate::mousePressEvent(event);
 }
 
+void UBGraphicsMediaItemDelegate::hideToolBar()
+{
+    mToolBarItem->hide();
+}
+
 void UBGraphicsMediaItemDelegate::buildButtons()
 {
     mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
     connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause()));
+    connect(mPlayPauseButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start()));
+    
 
     mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
     connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop()));
+    connect(mStopButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start()));
 
     mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem);
     mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true);
     UBGraphicsItem::assignZValue(mMediaControl, delegated()->zValue());
-
+    connect(mMediaControl, SIGNAL(used()), mToolBarShowTimer, SLOT(start()));
+    
     if (delegated()->isMuted())
         mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
     else
@@ -70,6 +92,7 @@ void UBGraphicsMediaItemDelegate::buildButtons()
 
     connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); 
     connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); // for changing button image
+    connect(mMuteButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start()));
 
     mButtons << mPlayPauseButton << mStopButton << mMuteButton;
 
@@ -89,7 +112,8 @@ void UBGraphicsMediaItemDelegate::buildButtons()
 
 UBGraphicsMediaItemDelegate::~UBGraphicsMediaItemDelegate()
 {
-    //NOOP
+    if (mToolBarShowTimer)
+        delete mToolBarShowTimer;
 }
 
 void UBGraphicsMediaItemDelegate::positionHandles()
diff --git a/src/domain/UBGraphicsMediaItemDelegate.h b/src/domain/UBGraphicsMediaItemDelegate.h
index 63c3f058..3454e1d1 100644
--- a/src/domain/UBGraphicsMediaItemDelegate.h
+++ b/src/domain/UBGraphicsMediaItemDelegate.h
@@ -18,6 +18,7 @@
 
 #include <QtGui>
 #include <phonon/MediaObject>
+#include <QTimer>
 
 #include "core/UB.h"
 #include "UBGraphicsItemDelegate.h"
@@ -54,6 +55,8 @@ class UBGraphicsMediaItemDelegate :  public UBGraphicsItemDelegate
 
         void totalTimeChanged(qint64 newTotalTime);
 
+        void hideToolBar();
+
     protected:
         virtual void buildButtons();
 
@@ -65,6 +68,9 @@ class UBGraphicsMediaItemDelegate :  public UBGraphicsItemDelegate
         DelegateMediaControl *mMediaControl;
 
         Phonon::MediaObject* mMedia;
+
+        QTimer *mToolBarShowTimer;
+        int m_iToolBarShowingInterval;
 };
 
 #endif /* UBGRAPHICSMEDIAITEMDELEGATE_H_ */
\ No newline at end of file
diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp
index ce47c04c..a93b8c91 100644
--- a/src/domain/UBGraphicsTextItemDelegate.cpp
+++ b/src/domain/UBGraphicsTextItemDelegate.cpp
@@ -303,11 +303,14 @@ void UBGraphicsTextItemDelegate::positionHandles()
             UBGraphicsGroupContainerItem *group = qgraphicsitem_cast<UBGraphicsGroupContainerItem*>(mDelegated->parentItem());
 
             mToolBarItem->hide();
-            if (group && group->getCurrentItem() == mDelegated && group->isSelected())
-                mToolBarItem->show();
+            if (mToolBarItem->parentItem() && !mToolBarItem->parentItem()->data(UBGraphicsItemData::ItemLocked).toBool())
+            {
+                if (group && group->getCurrentItem() == mDelegated && group->isSelected())
+                    mToolBarItem->show();
 
-            if (!group)
-                 mToolBarItem->show();
+                if (!group)
+                     mToolBarItem->show();
+            }
 
         }
     }

From 73d7cc883cd5d88d0dd95e5c9de2453d1e33c95c Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Tue, 19 Jun 2012 12:01:46 +0300
Subject: [PATCH 4/8] Mouse events adjusted to 1.50 specification.

---
 src/board/UBBoardView.cpp | 94 ++++++++++++++++++++++++++-------------
 src/board/UBBoardView.h   |  4 +-
 2 files changed, 66 insertions(+), 32 deletions(-)

diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index c07a9151..e19b0d84 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -375,21 +375,6 @@ void UBBoardView::tabletEvent (QTabletEvent * event)
 
 }
 
-bool UBBoardView::hasToolBarAsParent(QGraphicsItem *item)
-{
-    if (!item)
-        return false;
-
-    if (!item->parentItem())
-        return hasToolBarAsParent(0); 
-
-    if (UBGraphicsToolBarItem::Type == item->parentItem()->type())
-        return true;
-
-    else 
-        return hasToolBarAsParent(item->parentItem());        
-}
-
 bool UBBoardView::itemIsLocked(QGraphicsItem *item)
 {
     if (!item)
@@ -402,7 +387,7 @@ bool UBBoardView::itemIsLocked(QGraphicsItem *item)
 
 }
 
-bool UBBoardView::itemHaveType(QGraphicsItem *item, int type)
+bool UBBoardView::itemHaveParentWithType(QGraphicsItem *item, int type)
 {
     if (!item)
         return false;
@@ -410,10 +395,24 @@ bool UBBoardView::itemHaveType(QGraphicsItem *item, int type)
     if (type == item->type())
         return true;
     
-    return itemHaveType(item->parentItem(), type);
+    return itemHaveParentWithType(item->parentItem(), type);
 
 }
 
+QGraphicsItem* UBBoardView::determinedItemToMove()
+{
+    // groupConteinerItem should be moved instead of it's owned items
+    if(movingItem && movingItem->parentItem() &&
+        (UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type() ||
+        UBGraphicsStrokesGroup::Type       == movingItem->parentItem()->type()    
+        )
+        )
+    {
+        movingItem = movingItem->parentItem(); 
+    }
+    return movingItem;
+}
+
 void UBBoardView::mousePressEvent (QMouseEvent *event)
 {
     if (isAbsurdPoint (event->pos ()))
@@ -477,8 +476,8 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
                 || movingItem == this->scene()->backgroundObject()
                 || (movingItem->parentItem() && movingItem->parentItem()->type() == UBGraphicsGroupContainerItem::Type))
             {
-                if (!itemIsLocked(movingItem)
-                    || itemHaveType(movingItem, UBGraphicsMediaItem::Type))
+                if (movingItem && !itemIsLocked(movingItem)
+                    || itemHaveParentWithType(movingItem, UBGraphicsMediaItem::Type))
                 {
 
                     QGraphicsView::mousePressEvent (event);
@@ -499,25 +498,41 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
         }
         else if (currentTool == UBStylusTool::Play)
         {
-
             movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
 
             mLastPressedMousePos = mapToScene(event->pos());
 
-            if (movingItem 
-                && (UBGraphicsGroupContainerItem::Type == movingItem->type()
-                    || UBGraphicsMediaItem::Type == movingItem->type()
-                    || hasToolBarAsParent(movingItem)))
+            // items, who shouldn't receive mouse press event 
+            if (movingItem &&    
+                UBGraphicsTextItem ::Type != movingItem->type()
+                )
             {
-                movingItem = NULL;
-                QGraphicsView::mousePressEvent (event);
-                return;
+                QGraphicsView::mousePressEvent(event); 
             }
 
-            if(movingItem && movingItem->parentItem() && movingItem->parentItem()->type() == UBGraphicsGroupContainerItem::Type)
+            // items, who should receive suspended mouse press event
+            if (movingItem &&
+                    UBGraphicsMediaItem::Type == movingItem->type()
+               )
+            {
+                if (suspendedMousePressEvent)
+                {
+                    delete suspendedMousePressEvent;
+                }
+                suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); // удалить
+            }
+            
+            // groups shouldn't be moved independant of items)
+            if(movingItem && 
+                  (UBGraphicsGroupContainerItem::Type == movingItem->type() ||
+                   UBGraphicsStrokesGroup::Type       == movingItem->type()
+                  )
+              )
             {
-                movingItem = movingItem->parentItem(); 
-            }                
+                movingItem = NULL;
+            }
+
+            movingItem = determinedItemToMove(); 
 
             event->accept();
         }
@@ -653,6 +668,17 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
     }
   else if (currentTool == UBStylusTool::Play)
   {
+
+      // items, who shouldn't receive mouse move events
+      if (movingItem &&
+             (UBGraphicsW3CWidgetItem::Type == movingItem->type() ||
+              itemHaveParentWithType(movingItem, UBGraphicsToolBarItem::Type)
+              )
+         )
+      {
+          movingItem = NULL;
+      }
+
       if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) &&
           !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())
       {
@@ -734,6 +760,14 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
     }
   else if (currentTool == UBStylusTool::Play)
   {
+      if (suspendedMousePressEvent && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())       
+      {
+          QGraphicsView::mousePressEvent(suspendedMousePressEvent);     // suspendedMousePressEvent is deleted by old Qt event loop
+          movingItem = NULL;
+          delete suspendedMousePressEvent;
+          suspendedMousePressEvent = NULL;
+      }
+
       QGraphicsView::mouseReleaseEvent (event);
   }
   else if (currentTool == UBStylusTool::Text)
diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h
index faab052b..b1e478ad 100644
--- a/src/board/UBBoardView.h
+++ b/src/board/UBBoardView.h
@@ -51,9 +51,9 @@ class UBBoardView : public QGraphicsView
 
     protected:
 
-        bool hasToolBarAsParent(QGraphicsItem *item);
         bool itemIsLocked(QGraphicsItem *item);
-        bool itemHaveType(QGraphicsItem *item, int type);
+        bool itemHaveParentWithType(QGraphicsItem *item, int type);
+        QGraphicsItem* determinedItemToMove();
 
         virtual bool event (QEvent * e);
 

From 6b85418aa434a57b40dddec0e5f99d67864eaee7 Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Thu, 21 Jun 2012 15:58:17 +0300
Subject: [PATCH 5/8] Reworked all behavior of PlayTool and SelectorTool
 because of not flexible architecture.

---
 src/board/UBBoardView.cpp | 357 +++++++++++++++++++++++++-------------
 src/board/UBBoardView.h   |   7 +-
 2 files changed, 240 insertions(+), 124 deletions(-)

diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index e19b0d84..ff53d529 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -57,6 +57,7 @@
 #include "tools/UBGraphicsCompass.h"
 #include "tools/UBGraphicsCache.h"
 #include "tools/UBGraphicsTriangle.h"
+#include "tools/UBGraphicsProtractor.h"
 
 #include "core/memcheck.h"
 
@@ -399,18 +400,217 @@ bool UBBoardView::itemHaveParentWithType(QGraphicsItem *item, int type)
 
 }
 
-QGraphicsItem* UBBoardView::determinedItemToMove()
+bool UBBoardView::itemShouldReceiveMousePressEvent(QGraphicsItem *item)
 {
-    // groupConteinerItem should be moved instead of it's owned items
-    if(movingItem && movingItem->parentItem() &&
-        (UBGraphicsGroupContainerItem::Type == movingItem->parentItem()->type() ||
-        UBGraphicsStrokesGroup::Type       == movingItem->parentItem()->type()    
-        )
-        )
+    if (!item) 
+        return true;
+
+    if (item == scene()->backgroundObject())
+        return true;
+
+    if (itemIsLocked(item))
+        return false;
+
+
+    UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();
+
+    if ((currentTool == UBStylusTool::Play) && UBGraphicsGroupContainerItem::Type == movingItem->type())
+        return movingItem = NULL;
+
+    switch(item->type())
+    {
+
+    case UBGraphicsMediaItem::Type:
+        return false;
+
+    case UBGraphicsPixmapItem::Type:
+    case UBGraphicsTextItem::Type:
+        if ((currentTool == UBStylusTool::Selector) && item->isSelected())
+            return true;
+        if ((currentTool == UBStylusTool::Selector) && item->parentItem() && item->parentItem()->isSelected())
+            return true;
+        if (currentTool != UBStylusTool::Selector)
+            return false;
+        break;
+
+    case UBGraphicsGroupContainerItem::Type:
+        return (currentTool == UBStylusTool::Selector);
+
+    case UBGraphicsW3CWidgetItem::Type:
+        if (currentTool == UBStylusTool::Selector && item->parentItem() && item->parentItem()->isSelected()) 
+            return true;
+        if (currentTool == UBStylusTool::Selector && item->isSelected()) 
+            return true;
+        if (currentTool == UBStylusTool::Play)
+            return true;
+        break;
+
+    default: 
+        return true;
+    }
+
+    return false;
+}
+
+bool UBBoardView::itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item)
+{
+    if (!item) 
+        return false;
+
+    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:
+        if (currentTool != UBStylusTool::Play && !item->isSelected() && item->parentItem())
+            return true;
+        if (currentTool != UBStylusTool::Play && !item->isSelected())
+            return true;
+        break;
+    
+    case UBGraphicsMediaItem::Type:
+        return true;
+
+    default:
+        return false;
+    }
+    return false;
+}
+
+bool UBBoardView::itemShouldBeMoved(QGraphicsItem *item)
+{
+    if (!item) 
+        return false;
+
+    if (item == scene()->backgroundObject())
+        return false;
+
+    if (!(mMouseButtonIsPressed || mTabletStylusIsPressed))
+        return false;
+        
+    if (movingItem->data(UBGraphicsItemData::ItemLocked).toBool())
+        return false;
+
+    UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();  
+   
+    if (movingItem->parentItem() && !movingItem->isSelected() && movingItem->parentItem()->isSelected())
+        return false;
+
+    switch(item->type())
+    {
+    case UBGraphicsGroupContainerItem::Type:
+        return true;
+
+    case UBGraphicsW3CWidgetItem::Type:
+        if(currentTool == UBStylusTool::Selector && item->isSelected()) 
+            return false;
+        if(currentTool == UBStylusTool::Play)
+            return false;
+
+    case UBGraphicsPixmapItem::Type:
+        if (item->isSelected())
+            return false;
+    case UBGraphicsMediaItem::Type:
+    case UBGraphicsStrokesGroup::Type: 
+        return true;
+    case UBGraphicsTextItem::Type:
+        return !item->isSelected();
+
+    default: 
+        false;
+    }
+
+    return false;
+}
+
+// determine item to interacts: item self or it's container.
+QGraphicsItem* UBBoardView::determineItemToMove(QGraphicsItem *item)
+{
+    if(item)
+    {
+        UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool();  
+        if ((UBStylusTool::Play == currentTool) && (UBGraphicsW3CWidgetItem::Type == item->type()))
+                return item;
+
+        if(item->parentItem() && UBGraphicsGroupContainerItem::Type == item->parentItem()->type())
+        {
+            if (UBStylusTool::Play == currentTool && item->parentItem()->isSelected())
+                return item->parentItem();
+            
+            if (item->parentItem()->isSelected())
+                return item;
+                
+               
+            if (item->isSelected())
+                return NULL;
+
+            return item->parentItem();
+        }
+
+        if(item->parentItem() && UBGraphicsStrokesGroup::Type == item->parentItem()->type())    
+            return determineItemToMove(item->parentItem());    
+    }
+
+    return item;
+}
+
+void UBBoardView::handleItemMousePress(QMouseEvent *event)
+{
+    mLastPressedMousePos = mapToScene(event->pos());
+
+    if (itemShouldReceiveMousePressEvent(movingItem))
+        QGraphicsView::mousePressEvent (event);
+    else
+    if (itemShouldReceiveSuspendedMousePressEvent(movingItem))
+    {
+        if (suspendedMousePressEvent)
+            delete suspendedMousePressEvent;
+        suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers());
+    }
+}
+
+void UBBoardView::handleItemMouseMove(QMouseEvent *event)
+{
+    if (movingItem)
+        movingItem = determineItemToMove(movingItem);
+
+    if (movingItem && itemShouldBeMoved(movingItem) && (mMouseButtonIsPressed || mTabletStylusIsPressed))       
     {
-        movingItem = movingItem->parentItem(); 
+        QPointF scenePos = mapToScene(event->pos());
+        QPointF newPos = movingItem->pos() + scenePos - mLastPressedMousePos;
+        movingItem->setPos(newPos);
+        mLastPressedMousePos = scenePos;
+        mWidgetMoved = true;
+        event->accept();
+    }
+    else 
+    {
+        QPointF posBeforeMove;
+        QPointF posAfterMove;
+
+        if (movingItem)
+            posBeforeMove = movingItem->pos();
+
+        QGraphicsView::mouseMoveEvent (event);
+
+        if (movingItem)
+          posAfterMove = movingItem->pos();
+
+        mWidgetMoved = ((posAfterMove-posBeforeMove).manhattanLength() != 0);
+
+        // a cludge for terminate moving of w3c widgets.
+        if (mWidgetMoved && UBGraphicsW3CWidgetItem::Type == movingItem->type())
+            movingItem->setPos(posBeforeMove);
+
     }
-    return movingItem;
 }
 
 void UBBoardView::mousePressEvent (QMouseEvent *event)
@@ -451,10 +651,8 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
         }
         else if (currentTool == UBStylusTool::Selector)
         {
-//            QSet<QGraphicsItem*> existingTools = scene()->tools(); why do we need to get tools here?
-
             movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
-
+            
             if (!movingItem) {
                 // Rubberband selection implementation
                 if (!mUBRubberBand) {
@@ -464,35 +662,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
                 mUBRubberBand->show();
             }
 
-            if (!movingItem
-                || movingItem->isSelected()
-                || movingItem->type() == UBGraphicsDelegateFrame::Type
-                || movingItem->type() == DelegateButton::Type
-                || movingItem->type() == UBGraphicsCompass::Type
-                || movingItem->type() == UBGraphicsPDFItem::Type
-                || movingItem->type() == UBGraphicsPolygonItem::Type
-                || movingItem->type() == UBGraphicsCache::Type
-                || movingItem->type() == UBGraphicsTriangle::Type
-                || movingItem == this->scene()->backgroundObject()
-                || (movingItem->parentItem() && movingItem->parentItem()->type() == UBGraphicsGroupContainerItem::Type))
-            {
-                if (movingItem && !itemIsLocked(movingItem)
-                    || itemHaveParentWithType(movingItem, UBGraphicsMediaItem::Type))
-                {
-
-                    QGraphicsView::mousePressEvent (event);
-                }
-                movingItem = NULL;
-            }
-            else
-            {
-                mLastPressedMousePos = mapToScene(event->pos());
-                if (suspendedMousePressEvent)
-                {
-                    delete suspendedMousePressEvent;
-                }
-                suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); // удалить
-            }
+            handleItemMousePress(event);
 
             event->accept();
         }
@@ -500,40 +670,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
         {
             movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
 
-            mLastPressedMousePos = mapToScene(event->pos());
-
-            // items, who shouldn't receive mouse press event 
-            if (movingItem &&    
-                UBGraphicsTextItem ::Type != movingItem->type()
-                )
-            {
-                QGraphicsView::mousePressEvent(event); 
-            }
-
-            // items, who should receive suspended mouse press event
-            if (movingItem &&
-                    UBGraphicsMediaItem::Type == movingItem->type()
-               )
-            {
-                if (suspendedMousePressEvent)
-                {
-                    delete suspendedMousePressEvent;
-                }
-                suspendedMousePressEvent = new QMouseEvent(event->type(), event->pos(), event->button(), event->buttons(), event->modifiers()); // удалить
-            }
-            
-            // groups shouldn't be moved independant of items)
-            if(movingItem && 
-                  (UBGraphicsGroupContainerItem::Type == movingItem->type() ||
-                   UBGraphicsStrokesGroup::Type       == movingItem->type()
-                  )
-              )
-            {
-                movingItem = NULL;
-            }
-
-            movingItem = determinedItemToMove(); 
-
+            handleItemMousePress(event);
             event->accept();
         }
         else if (currentTool == UBStylusTool::Text)
@@ -654,43 +791,11 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
           }
       }
 
-        if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) &&
-            !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())
-        {
-            QPointF scenePos = mapToScene(event->pos());
-            QPointF newPos = movingItem->pos() + scenePos - mLastPressedMousePos;
-            movingItem->setPos(newPos);
-            mLastPressedMousePos = scenePos;
-            mWidgetMoved = true;
-            event->accept();
-        }
-        else QGraphicsView::mouseMoveEvent (event);
+      handleItemMouseMove(event);
     }
   else if (currentTool == UBStylusTool::Play)
   {
-
-      // items, who shouldn't receive mouse move events
-      if (movingItem &&
-             (UBGraphicsW3CWidgetItem::Type == movingItem->type() ||
-              itemHaveParentWithType(movingItem, UBGraphicsToolBarItem::Type)
-              )
-         )
-      {
-          movingItem = NULL;
-      }
-
-      if (movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) &&
-          !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())
-      {
-          QPointF scenePos = mapToScene(event->pos());
-          QPointF newPos = movingItem->pos() + scenePos - mLastPressedMousePos;
-          movingItem->setPos(newPos);
-          mLastPressedMousePos = scenePos;
-          mWidgetMoved = true;
-          event->accept();
-      }
-      else 
-        QGraphicsView::mouseMoveEvent (event);
+      handleItemMouseMove(event);
   }
   else if ((UBDrawingController::drawingController()->isDrawingTool())
     && !mMouseButtonIsPressed)
@@ -717,6 +822,9 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
       }
       event->accept ();
     }
+
+    if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) 
+        mWidgetMoved = true;
 }
 
 void
@@ -744,31 +852,34 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
                   QGraphicsView::mousePressEvent(suspendedMousePressEvent);     // suspendedMousePressEvent is deleted by old Qt event loop
                   movingItem = NULL;
                   delete suspendedMousePressEvent;
-                  suspendedMousePressEvent = NULL;
-              }
-              else 
-              {
-                  movingItem->setSelected(true);
+                  suspendedMousePressEvent = NULL;                       
               }
           }
 
-      if (mUBRubberBand && mUBRubberBand->isVisible()) {
-          mUBRubberBand->hide();
+          if (mUBRubberBand && mUBRubberBand->isVisible()) {
+              mUBRubberBand->hide();
       }
-
-      QGraphicsView::mouseReleaseEvent (event);
+                        QGraphicsView::mouseReleaseEvent (event);
     }
   else if (currentTool == UBStylusTool::Play)
   {
-      if (suspendedMousePressEvent && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())       
+      if (mWidgetMoved)
       {
-          QGraphicsView::mousePressEvent(suspendedMousePressEvent);     // suspendedMousePressEvent is deleted by old Qt event loop
           movingItem = NULL;
-          delete suspendedMousePressEvent;
-          suspendedMousePressEvent = NULL;
+          mWidgetMoved = false;
       }
+      else
+      {
+          if (suspendedMousePressEvent && movingItem && !movingItem->data(UBGraphicsItemData::ItemLocked).toBool())       
+          {
+              QGraphicsView::mousePressEvent(suspendedMousePressEvent);     // suspendedMousePressEvent is deleted by old Qt event loop
+              movingItem = NULL;
+              delete suspendedMousePressEvent;
+              suspendedMousePressEvent = NULL;
+          }
 
-      QGraphicsView::mouseReleaseEvent (event);
+          QGraphicsView::mouseReleaseEvent (event);
+      }
   }
   else if (currentTool == UBStylusTool::Text)
     {
diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h
index b1e478ad..94d9ee4b 100644
--- a/src/board/UBBoardView.h
+++ b/src/board/UBBoardView.h
@@ -52,8 +52,13 @@ class UBBoardView : public QGraphicsView
     protected:
 
         bool itemIsLocked(QGraphicsItem *item);
+        bool itemShouldReceiveMousePressEvent(QGraphicsItem *item);
+        bool itemShouldReceiveSuspendedMousePressEvent(QGraphicsItem *item);
         bool itemHaveParentWithType(QGraphicsItem *item, int type);
-        QGraphicsItem* determinedItemToMove();
+        bool itemShouldBeMoved(QGraphicsItem *item);
+        QGraphicsItem* determineItemToMove(QGraphicsItem *item);
+        void handleItemMousePress(QMouseEvent *event);
+        void handleItemMouseMove(QMouseEvent *event);
 
         virtual bool event (QEvent * e);
 

From de18bf794efd1d449a76e2ab71ed9669060494af Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Fri, 22 Jun 2012 15:42:49 +0300
Subject: [PATCH 6/8] RubberBand is moveble and resizable by PlayTool. Items
 can be moved by RubberBand.

---
 src/board/UBBoardView.cpp |  56 ++++++++---
 src/board/UBBoardView.h   |   6 ++
 src/gui/UBRubberBand.cpp  | 199 ++++++++++++++++++++++++++++++++++++++
 src/gui/UBRubberBand.h    |  24 +++++
 4 files changed, 269 insertions(+), 16 deletions(-)

diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index ff53d529..9e4b985d 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -613,6 +613,37 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event)
     }
 }
 
+void UBBoardView::rubberItems()
+{
+    if (mUBRubberBand)
+        mRubberedItems = items(mUBRubberBand->geometry());
+}
+
+void UBBoardView::moveRubberedItems(QPointF movingVector)
+{
+//     QRect bandRect = mUBRubberBand->geometry();
+// 
+     QRectF invalidateRect = scene()->itemsBoundingRect();
+//     QList<QGraphicsItem *> rubberItems = items(bandRect);
+
+    foreach (QGraphicsItem *item, mRubberedItems) 
+    {
+
+        if (item->type() == UBGraphicsW3CWidgetItem::Type
+              || item->type() == UBGraphicsPixmapItem::Type
+              || item->type() == UBGraphicsMediaItem::Type
+              || item->type() == UBGraphicsSvgItem::Type
+              || item->type() == UBGraphicsTextItem::Type
+              || item->type() == UBGraphicsStrokesGroup::Type
+              || item->type() == UBGraphicsGroupContainerItem::Type) 
+        {
+              item->setPos(item->pos()+movingVector);       
+        }    
+    }
+
+    scene()->invalidate(invalidateRect);
+}
+
 void UBBoardView::mousePressEvent (QMouseEvent *event)
 {
     if (isAbsurdPoint (event->pos ()))
@@ -649,7 +680,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
             mPreviousPoint = event->posF ();
             event->accept ();
         }
-        else if (currentTool == UBStylusTool::Selector)
+        else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
         {
             movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
             
@@ -662,14 +693,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
                 mUBRubberBand->show();
             }
 
-            handleItemMousePress(event);
-
-            event->accept();
-        }
-        else if (currentTool == UBStylusTool::Play)
-        {
-            movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
-
             handleItemMousePress(event);
             event->accept();
         }
@@ -754,14 +777,16 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
       mPreviousPoint = eventPosition;
       event->accept ();
     }
-  else if (currentTool == UBStylusTool::Selector)
+  else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
   {
       if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) {
           return;
       }
 
-      if (mUBRubberBand && mUBRubberBand->isVisible()) {
+      if (!movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) && mUBRubberBand && mUBRubberBand->isVisible()) {
+
           QRect bandRect(mMouseDownPos, event->pos());
+
           bandRect = bandRect.normalized();
 
           mUBRubberBand->setGeometry(bandRect);
@@ -773,6 +798,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
                   mJustSelectedItems.remove(item);
               }
           }
+
+          if (currentTool == UBStylusTool::Selector)
           foreach (QGraphicsItem *item, items(bandRect)) {
 
               if (item->type() == UBGraphicsW3CWidgetItem::Type
@@ -793,10 +820,6 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
 
       handleItemMouseMove(event);
     }
-  else if (currentTool == UBStylusTool::Play)
-  {
-      handleItemMouseMove(event);
-  }
   else if ((UBDrawingController::drawingController()->isDrawingTool())
     && !mMouseButtonIsPressed)
   {
@@ -859,7 +882,8 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
           if (mUBRubberBand && mUBRubberBand->isVisible()) {
               mUBRubberBand->hide();
       }
-                        QGraphicsView::mouseReleaseEvent (event);
+
+      QGraphicsView::mouseReleaseEvent (event);
     }
   else if (currentTool == UBStylusTool::Play)
   {
diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h
index 94d9ee4b..f473ac92 100644
--- a/src/board/UBBoardView.h
+++ b/src/board/UBBoardView.h
@@ -42,6 +42,9 @@ class UBBoardView : public QGraphicsView
 
         void setToolCursor(int tool);
 
+        void rubberItems();
+        void moveRubberedItems(QPointF movingVector);
+
     signals:
 
         void resized(QResizeEvent* event);
@@ -133,7 +136,10 @@ class UBBoardView : public QGraphicsView
         QGraphicsItem *movingItem;
         QMouseEvent *suspendedMousePressEvent;
 
+        bool moveRubberBand;
         UBRubberBand *mUBRubberBand;
+        
+        QList<QGraphicsItem *> mRubberedItems;
         QSet<QGraphicsItem*> mJustSelectedItems;
 
     private slots:
diff --git a/src/gui/UBRubberBand.cpp b/src/gui/UBRubberBand.cpp
index 04fcd26c..2453d6b6 100644
--- a/src/gui/UBRubberBand.cpp
+++ b/src/gui/UBRubberBand.cpp
@@ -23,10 +23,18 @@
 #include <QtGui/QMacStyle>
 #endif
 
+#include "core/UBApplication.h"
+#include "board/UBBoardController.h"
+#include "board/UBBoardView.h"
+
 #include "core/memcheck.h"
 
 UBRubberBand::UBRubberBand(Shape s, QWidget * p)
     : QRubberBand(s, p)
+    , mResizingMode(None)
+    , mMouseIsPressed(false)
+    , mLastPressedPoint(QPoint())
+    , mResizingBorderHeight(20)
 {
     customStyle = NULL;
 
@@ -41,6 +49,8 @@ UBRubberBand::UBRubberBand(Shape s, QWidget * p)
     if (customStyle)
         QRubberBand::setStyle(customStyle);
 
+    setAttribute(Qt::WA_TransparentForMouseEvents, false);
+    setMouseTracking(true);
 }
 
 UBRubberBand::~UBRubberBand()
@@ -48,3 +58,192 @@ UBRubberBand::~UBRubberBand()
     if (customStyle)
         delete customStyle;
 }
+
+UBRubberBand::enm_resizingMode UBRubberBand::determineResizingMode(QPoint pos)
+{
+    if (mMouseIsPressed)
+        return mResizingMode;
+    
+    QRect resizerTop    (mResizingBorderHeight               , 0                             , rect().width()-2*mResizingBorderHeight, mResizingBorderHeight                    );
+    QRect resizerBottom (mResizingBorderHeight               , rect().height() - mResizingBorderHeight, rect().width()-2*mResizingBorderHeight, mResizingBorderHeight                    );
+    QRect resizerLeft   (0                          , mResizingBorderHeight                  , mResizingBorderHeight                 , rect().height() - 2*mResizingBorderHeight);
+    QRect resizerRight  (rect().width()-mResizingBorderHeight, mResizingBorderHeight                  , mResizingBorderHeight                 , rect().height() - 2*mResizingBorderHeight);
+
+    QRect resizerTopLeft    (0                          , 0                             , mResizingBorderHeight, mResizingBorderHeight);
+    QRect resizerTopRight   (rect().width()-mResizingBorderHeight, 0                             , mResizingBorderHeight, mResizingBorderHeight);
+    QRect resizerBottomLeft (0                          , rect().height() - mResizingBorderHeight, mResizingBorderHeight, mResizingBorderHeight);
+    QRect resizerBottomRight(rect().width()-mResizingBorderHeight, rect().height() - mResizingBorderHeight, mResizingBorderHeight, mResizingBorderHeight);
+
+    enm_resizingMode resizingMode;
+    
+    QTransform cursorTransrofm;
+
+    if (resizerTop.contains(pos))
+    {
+        resizingMode = Top;
+        cursorTransrofm.rotate(90);
+    }
+    else
+    if (resizerBottom.contains(pos))
+    {
+        resizingMode = Bottom;
+        cursorTransrofm.rotate(90);
+    }
+    else
+    if (resizerLeft.contains(pos))
+    {
+        resizingMode = Left;
+    }
+    else
+    if (resizerRight.contains(pos))
+    {
+        resizingMode = Right;
+    }
+    else
+    if (resizerTopLeft.contains(pos))
+    {
+        resizingMode = TopLeft;
+        cursorTransrofm.rotate(45);
+    }
+    else
+    if (resizerTopRight.contains(pos))
+    {
+        resizingMode = TopRight;
+        cursorTransrofm.rotate(-45);
+    }
+    else
+    if (resizerBottomLeft.contains(pos))
+    {
+        resizingMode = BottomLeft;
+        cursorTransrofm.rotate(-45);
+    }
+    else
+    if (resizerBottomRight.contains(pos))
+    {
+        resizingMode = BottomRight;
+        cursorTransrofm.rotate(45);
+    }
+    else
+        resizingMode = None;
+    
+    if (None != resizingMode)
+    {
+        QPixmap pix(":/images/cursors/resize.png");
+        QCursor resizeCursor  = QCursor(pix.transformed(cursorTransrofm, Qt::SmoothTransformation), pix.width() / 2,  pix.height() / 2);
+        setCursor(resizeCursor);
+    }
+    else
+        unsetCursor();
+
+    return resizingMode;
+}
+
+void UBRubberBand::mousePressEvent(QMouseEvent *event)
+{
+    mResizingMode = determineResizingMode(event->pos());
+    mMouseIsPressed = true;
+
+    mLastPressedPoint = event->pos();
+    mLastMousePos = event->pos();
+
+    if (None == mResizingMode)
+    {
+        UBApplication::boardController->controlView()->rubberItems();
+        setCursor(QCursor(Qt::SizeAllCursor));
+    }
+}
+
+void UBRubberBand::mouseMoveEvent(QMouseEvent *event)
+{
+    determineResizingMode(event->pos());
+
+    if (mMouseIsPressed)
+    {
+        UBBoardView *view = UBApplication::boardController->controlView();
+        QRect currentGeometry = geometry();
+
+        QPoint pressPoint(event->pos());
+        QPoint pressPointGlobal(view->mapToGlobal(pressPoint));
+        QPoint prevPressPointGlobal(view->mapToGlobal(mLastPressedPoint));
+        QPoint movePointGlogal = (view->mapToGlobal(mLastMousePos));
+
+        QPoint topLeftResizeVector(pressPointGlobal - prevPressPointGlobal);
+        QPoint rightBottomResizeVector(pressPointGlobal - movePointGlogal);
+
+        bool bGeometryChange = true;
+
+        switch(mResizingMode)
+        {
+        case None:
+            {
+                QPointF itemsMoveVector(view->mapToScene(pressPointGlobal) - view->mapToScene(prevPressPointGlobal));
+
+                move(pos()+pressPointGlobal - prevPressPointGlobal);
+                view->moveRubberedItems(itemsMoveVector);
+
+                bGeometryChange = false;
+                break;
+            }
+
+        case Top:
+            {
+                currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y());
+            }break;
+
+        case Bottom:
+            {
+                currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y());
+            }break;
+
+        case Left:
+            {
+                currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x());
+            }break;
+        case Right:
+            {
+                currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x());
+            }break;
+
+        case TopLeft:
+            {
+                currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x());  
+                currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y());
+            }break;
+
+        case TopRight:
+            {
+                currentGeometry.setY(currentGeometry.y()+topLeftResizeVector.y());  
+                currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x());                
+            }
+            break;
+
+        case BottomLeft:
+            {
+                currentGeometry.setX(currentGeometry.x()+topLeftResizeVector.x());
+                currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y());  
+            }break;
+
+        case BottomRight:
+            {
+                currentGeometry.setWidth(currentGeometry.width()+rightBottomResizeVector.x());
+                currentGeometry.setHeight(currentGeometry.height()+rightBottomResizeVector.y());        
+            }break;
+        
+        }
+        if(bGeometryChange)
+        {   
+            setGeometry(currentGeometry);
+        }
+
+        mLastMousePos = event->pos();
+    }
+
+    QRubberBand::mouseMoveEvent(event);
+} 
+
+void UBRubberBand::mouseReleaseEvent(QMouseEvent *event)
+{
+    Q_UNUSED(event);
+    mMouseIsPressed = false;
+    unsetCursor();
+}
\ No newline at end of file
diff --git a/src/gui/UBRubberBand.h b/src/gui/UBRubberBand.h
index e95e10bb..793524b8 100644
--- a/src/gui/UBRubberBand.h
+++ b/src/gui/UBRubberBand.h
@@ -26,8 +26,32 @@ class UBRubberBand : public QRubberBand
         UBRubberBand(Shape s, QWidget * p = 0);
         virtual ~UBRubberBand();
 
+    private:
+        enum enm_resizingMode
+        {
+            None,
+            Top,
+            TopLeft,
+            TopRight,
+            Bottom,
+            BottomLeft,
+            BottomRight,
+            Left,
+            Right
+        };
+
+        enm_resizingMode determineResizingMode(QPoint pos);
+        virtual void mousePressEvent(QMouseEvent *event);
+        virtual void mouseMoveEvent(QMouseEvent *event);
+        virtual void mouseReleaseEvent(QMouseEvent *event);
+
     private:
         QStyle* customStyle;
+        enm_resizingMode mResizingMode;
+        int mResizingBorderHeight;
+        bool mMouseIsPressed;
+        QPoint mLastPressedPoint;
+        QPoint mLastMousePos;
 };
 
 #endif /* UBRUBBERBAND_H_ */

From 3fac754e2ee3b056f1000278168f043b683a4db0 Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Fri, 22 Jun 2012 18:45:53 +0300
Subject: [PATCH 7/8] Long press implemented. PlayTool -> SelectTool SelectTool
 -> PlayTool EraiserTool -> shows EraserPalette.

---
 src/board/UBBoardPaletteManager.h |  3 +-
 src/board/UBBoardView.cpp         | 72 ++++++++++++++++++++++++++++---
 src/board/UBBoardView.h           |  6 +++
 3 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/src/board/UBBoardPaletteManager.h b/src/board/UBBoardPaletteManager.h
index cdb02870..eef04194 100644
--- a/src/board/UBBoardPaletteManager.h
+++ b/src/board/UBBoardPaletteManager.h
@@ -89,6 +89,8 @@ class UBBoardPaletteManager : public QObject
         void slot_changeMainMode(UBApplicationController::MainMode);
         void slot_changeDesktopMode(bool);
 
+        void toggleErasePalette(bool ckecked);
+
     private:
 
         void setupPalettes();
@@ -168,7 +170,6 @@ class UBBoardPaletteManager : public QObject
         void erasePaletteButtonPressed();
         void erasePaletteButtonReleased();
 
-        void toggleErasePalette(bool ckecked);
         void erasePaletteClosed();
 
         void togglePagePalette(bool ckecked);
diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index 9e4b985d..cbacf2b0 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -40,6 +40,7 @@
 #include "gui/UBTeacherGuideWidgetsTools.h"
 
 #include "board/UBBoardController.h"
+#include "board/UBBoardPaletteManager.h"
 
 #include "domain/UBGraphicsTextItem.h"
 #include "domain/UBGraphicsPixmapItem.h"
@@ -68,23 +69,33 @@ UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent)
 , mIsCreatingSceneGrabZone (false)
 , mOkOnWidget(false)
 , suspendedMousePressEvent(NULL)
+, mLongPressInterval(1000)
+, mIsDragInProgress(false)
 {
   init ();
 
   mFilterZIndex = false;
+
+  mLongPressTimer.setInterval(mLongPressInterval);
+  mLongPressTimer.setSingleShot(true);
 }
 
 UBBoardView::UBBoardView (UBBoardController* pController, int pStartLayer, int pEndLayer, QWidget* pParent)
 : QGraphicsView (pParent)
 , mController (pController)
 , suspendedMousePressEvent(NULL)
+, mLongPressInterval(1000)
+, mIsDragInProgress(false)
 {
   init ();
 
   mStartLayer = pStartLayer;
   mEndLayer = pEndLayer;
 
-  mFilterZIndex = true;
+  mFilterZIndex = true;  
+
+  mLongPressTimer.setInterval(mLongPressInterval);
+  mLongPressTimer.setSingleShot(true);
 }
 
 UBBoardView::~UBBoardView () {
@@ -621,10 +632,7 @@ void UBBoardView::rubberItems()
 
 void UBBoardView::moveRubberedItems(QPointF movingVector)
 {
-//     QRect bandRect = mUBRubberBand->geometry();
-// 
-     QRectF invalidateRect = scene()->itemsBoundingRect();
-//     QList<QGraphicsItem *> rubberItems = items(bandRect);
+    QRectF invalidateRect = scene()->itemsBoundingRect();
 
     foreach (QGraphicsItem *item, mRubberedItems) 
     {
@@ -644,8 +652,35 @@ void UBBoardView::moveRubberedItems(QPointF movingVector)
     scene()->invalidate(invalidateRect);
 }
 
+void UBBoardView::longPressEvent()
+{
+   UBDrawingController *drawingController = UBDrawingController::drawingController();
+   UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
+
+   
+   disconnect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent()));
+
+   if (UBStylusTool::Selector == currentTool)
+   {
+        drawingController->setStylusTool(UBStylusTool::Play);
+   }
+   else
+   if (currentTool == UBStylusTool::Play)
+   {
+        drawingController->setStylusTool(UBStylusTool::Selector);
+   }
+   else
+   if (UBStylusTool::Eraser == currentTool)
+   {
+       UBApplication::boardController->paletteManager()->toggleErasePalette(true);
+   }
+
+}
+
 void UBBoardView::mousePressEvent (QMouseEvent *event)
 {
+    mIsDragInProgress = false;
+
     if (isAbsurdPoint (event->pos ()))
     {
         event->accept ();
@@ -680,10 +715,18 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
             mPreviousPoint = event->posF ();
             event->accept ();
         }
+        else if (currentTool == UBStylusTool::Eraser)
+        {
+            connect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent()));
+            mLongPressTimer.start();
+        }
         else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
         {
             movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
-            
+
+            connect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent()));
+            mLongPressTimer.start();
+
             if (!movingItem) {
                 // Rubberband selection implementation
                 if (!mUBRubberBand) {
@@ -692,6 +735,10 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
                 mUBRubberBand->setGeometry (QRect (mMouseDownPos, QSize ()));
                 mUBRubberBand->show();
             }
+            else
+            {
+                mUBRubberBand->hide();
+            }
 
             handleItemMousePress(event);
             event->accept();
@@ -760,6 +807,12 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
 void
 UBBoardView::mouseMoveEvent (QMouseEvent *event)
 {
+  if(!mIsDragInProgress && ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) 
+  {
+    return;
+  }
+
+  mIsDragInProgress = true;
   UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
   if (isAbsurdPoint (event->pos ()))
@@ -777,12 +830,18 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
       mPreviousPoint = eventPosition;
       event->accept ();
     }
+  else if (currentTool == UBStylusTool::Eraser)
+  {
+      mLongPressTimer.stop();
+  }
   else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
   {
       if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) {
           return;
       }
 
+      mLongPressTimer.stop();
+
       if (!movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) && mUBRubberBand && mUBRubberBand->isVisible()) {
 
           QRect bandRect(mMouseDownPos, event->pos());
@@ -963,6 +1022,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
   mPendingStylusReleaseEvent = false;
   mTabletStylusIsPressed = false;
 
+  mLongPressTimer.stop();
 }
 
 void
diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h
index f473ac92..b8b6429f 100644
--- a/src/board/UBBoardView.h
+++ b/src/board/UBBoardView.h
@@ -142,6 +142,11 @@ class UBBoardView : public QGraphicsView
         QList<QGraphicsItem *> mRubberedItems;
         QSet<QGraphicsItem*> mJustSelectedItems;
 
+        int mLongPressInterval;
+        QTimer mLongPressTimer;
+
+        bool mIsDragInProgress;
+
     private slots:
 
         void settingChanged(QVariant newValue);
@@ -149,6 +154,7 @@ class UBBoardView : public QGraphicsView
 	public slots:
 
 		void virtualKeyboardActivated(bool b);
+        void longPressEvent();
 
 };
 

From 93bb9244f9f30f3f7329d98ba6b2cff3ddc783ed Mon Sep 17 00:00:00 2001
From: Aleksei Kanash <sc.kanash.aleksei@gmail.com>
Date: Fri, 22 Jun 2012 18:59:08 +0300
Subject: [PATCH 8/8] Fixed eraser behavior.

---
 src/board/UBBoardView.cpp | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp
index cbacf2b0..3f51560c 100644
--- a/src/board/UBBoardView.cpp
+++ b/src/board/UBBoardView.cpp
@@ -715,11 +715,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
             mPreviousPoint = event->posF ();
             event->accept ();
         }
-        else if (currentTool == UBStylusTool::Eraser)
-        {
-            connect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent()));
-            mLongPressTimer.start();
-        }
         else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
         {
             movingItem = scene()->itemAt(this->mapToScene(event->posF().toPoint()));
@@ -797,6 +792,11 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
 
             if (scene () && !mTabletStylusIsPressed)
             {
+                if (currentTool == UBStylusTool::Eraser)
+                {
+                    connect(&mLongPressTimer, SIGNAL(timeout()), this, SLOT(longPressEvent()));
+                    mLongPressTimer.start();
+                }
                 scene ()->inputDevicePress (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())));
             }
             event->accept ();
@@ -809,12 +809,14 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
 {
   if(!mIsDragInProgress && ((mapToScene(event->pos()) - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance())) 
   {
-    return;
+      return;
   }
 
   mIsDragInProgress = true;
   UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController ()->stylusTool ();
 
+  mLongPressTimer.stop();
+
   if (isAbsurdPoint (event->pos ()))
     {
       event->accept ();
@@ -830,18 +832,12 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
       mPreviousPoint = eventPosition;
       event->accept ();
     }
-  else if (currentTool == UBStylusTool::Eraser)
-  {
-      mLongPressTimer.stop();
-  }
   else if (currentTool == UBStylusTool::Selector || currentTool == UBStylusTool::Play)
   {
       if((event->pos() - mLastPressedMousePos).manhattanLength() < QApplication::startDragDistance()) {
           return;
       }
 
-      mLongPressTimer.stop();
-
       if (!movingItem && (mMouseButtonIsPressed || mTabletStylusIsPressed) && mUBRubberBand && mUBRubberBand->isVisible()) {
 
           QRect bandRect(mMouseDownPos, event->pos());
@@ -899,7 +895,7 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
   else
     {
       if (!mTabletStylusIsPressed && scene ())
-      {
+      {           
           scene ()->inputDeviceMove (mapToScene (UBGeometryUtils::pointConstrainedInRect (event->pos (), rect ())), mMouseButtonIsPressed);
       }
       event->accept ();