@ -70,6 +70,7 @@
# include "UBGraphicsPixmapItem.h"
# include "UBGraphicsPixmapItem.h"
# include "UBGraphicsSvgItem.h"
# include "UBGraphicsSvgItem.h"
# include "UBGraphicsPolygonItem.h"
# include "UBGraphicsPolygonItem.h"
# include "UBGraphicsVectorItem.h"
# include "UBGraphicsMediaItem.h"
# include "UBGraphicsMediaItem.h"
# include "UBGraphicsWidgetItem.h"
# include "UBGraphicsWidgetItem.h"
# include "UBGraphicsPDFItem.h"
# include "UBGraphicsPDFItem.h"
@ -539,8 +540,9 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
width / = UBApplication : : boardController - > systemScaleFactor ( ) ;
width / = UBApplication : : boardController - > systemScaleFactor ( ) ;
width / = UBApplication : : boardController - > currentZoom ( ) ;
width / = UBApplication : : boardController - > currentZoom ( ) ;
if ( currentTool = = UBStylusTool : : Line | | dc - > mActiveRuler )
if ( currentTool = = UBStylusTool : : Line | | dc - > mActiveRuler | | currentTool = = UBStylusTool : : Vector )
{
{
if ( UBDrawingController : : drawingController ( ) - > stylusTool ( ) ! = UBStylusTool : : Vector )
if ( UBDrawingController : : drawingController ( ) - > stylusTool ( ) ! = UBStylusTool : : Marker )
if ( UBDrawingController : : drawingController ( ) - > stylusTool ( ) ! = UBStylusTool : : Marker )
if ( NULL ! = mpLastPolygon & & NULL ! = mCurrentStroke & & mAddedItems . size ( ) > 0 ) {
if ( NULL ! = mpLastPolygon & & NULL ! = mCurrentStroke & & mAddedItems . size ( ) > 0 ) {
UBCoreGraphicsScene : : removeItemFromDeletion ( mpLastPolygon ) ;
UBCoreGraphicsScene : : removeItemFromDeletion ( mpLastPolygon ) ;
@ -580,7 +582,9 @@ bool UBGraphicsScene::inputDeviceMove(const QPointF& scenePos, const qreal& pres
else if ( currentTool = = UBStylusTool : : Line ) {
else if ( currentTool = = UBStylusTool : : Line ) {
drawLineTo ( position , width , true ) ;
drawLineTo ( position , width , true ) ;
}
}
else if ( currentTool = = UBStylusTool : : Vector ) {
drawLineTo ( position , width , true ) ;
}
else {
else {
bool interpolate = false ;
bool interpolate = false ;
@ -667,7 +671,16 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
if ( currentTool = = UBStylusTool : : Eraser )
if ( currentTool = = UBStylusTool : : Eraser )
hideEraser ( ) ;
hideEraser ( ) ;
if ( currentTool = = UBStylusTool : : Vector )
{
if ( mUndoRedoStackEnabled )
{ //should be deleted after scene own undo stack implemented
UBGraphicsItemUndoCommand * uc = new UBGraphicsItemUndoCommand ( this , NULL , mpLastVector ) ;
UBApplication : : undoStack - > push ( uc ) ;
mAddedItems . clear ( ) ;
}
} else {
UBDrawingController * dc = UBDrawingController : : drawingController ( ) ;
UBDrawingController * dc = UBDrawingController : : drawingController ( ) ;
@ -741,6 +754,7 @@ bool UBGraphicsScene::inputDeviceRelease(int tool)
mCurrentPolygon = 0 ;
mCurrentPolygon = 0 ;
}
}
}
}
}
if ( mRemovedItems . size ( ) > 0 | | mAddedItems . size ( ) > 0 )
if ( mRemovedItems . size ( ) > 0 | | mAddedItems . size ( ) > 0 )
{
{
@ -920,6 +934,7 @@ void UBGraphicsScene::moveTo(const QPointF &pPoint)
}
}
void UBGraphicsScene : : drawLineTo ( const QPointF & pEndPoint , const qreal & pWidth , bool bLineStyle )
void UBGraphicsScene : : drawLineTo ( const QPointF & pEndPoint , const qreal & pWidth , bool bLineStyle )
{
{
if ( UBDrawingController : : drawingController ( ) - > stylusTool ( ) = = UBStylusTool : : Vector ) bLineStyle = true ;
drawLineTo ( pEndPoint , pWidth , pWidth , bLineStyle ) ;
drawLineTo ( pEndPoint , pWidth , pWidth , bLineStyle ) ;
}
}
@ -943,8 +958,16 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &startWid
mAddedItems . clear ( ) ;
mAddedItems . clear ( ) ;
}
}
UBGraphicsPolygonItem * polygonItem = lineToPolygonItem ( QLineF ( mPreviousPoint , pEndPoint ) , initialWidth , endWidth ) ;
if ( UBDrawingController : : drawingController ( ) - > stylusTool ( ) ! = UBStylusTool : : Vector )
addPolygonItemToCurrentStroke ( polygonItem ) ;
{
UBGraphicsPolygonItem * polygonItem = lineToPolygonItem ( QLineF ( mPreviousPoint , pEndPoint ) , initialWidth , endWidth ) ;
addPolygonItemToCurrentStroke ( polygonItem ) ;
} else
{
UBGraphicsVectorItem * vectorItem = new UBGraphicsVectorItem ( QLineF ( mPreviousPoint , pEndPoint ) , initialWidth , endWidth ) ;
initVectorItem ( vectorItem ) ;
addVectorItemToCurrentStroke ( vectorItem ) ;
}
if ( ! bLineStyle ) {
if ( ! bLineStyle ) {
mPreviousPoint = pEndPoint ;
mPreviousPoint = pEndPoint ;
@ -998,6 +1021,19 @@ void UBGraphicsScene::addPolygonItemToCurrentStroke(UBGraphicsPolygonItem* polyg
}
}
void UBGraphicsScene : : addVectorItemToCurrentStroke ( UBGraphicsVectorItem * vectorItem )
{
vectorItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
vectorItem - > setFlag ( QGraphicsItem : : ItemIsSelectable , true ) ;
vectorItem - > SetDelegate ( ) ;
mpLastVector = vectorItem ;
mAddedItems . insert ( vectorItem ) ;
// Here we add the item to the scene
addItem ( vectorItem ) ;
}
void UBGraphicsScene : : eraseLineTo ( const QPointF & pEndPoint , const qreal & pWidth )
void UBGraphicsScene : : eraseLineTo ( const QPointF & pEndPoint , const qreal & pWidth )
{
{
const QLineF line ( mPreviousPoint , pEndPoint ) ;
const QLineF line ( mPreviousPoint , pEndPoint ) ;
@ -1017,13 +1053,15 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
typedef QList < QPolygonF > POLYGONSLIST ;
typedef QList < QPolygonF > POLYGONSLIST ;
QList < POLYGONSLIST > intersectedPolygons ;
QList < POLYGONSLIST > intersectedPolygons ;
QList < UBGraphicsVectorItem * > intersectedVectorItems ;
# pragma omp parallel for
# pragma omp parallel for
for ( int i = 0 ; i < collidItems . size ( ) ; i + + )
for ( int i = 0 ; i < collidItems . size ( ) ; i + + )
{
{
UBGraphicsPolygonItem * pi = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( collidItems [ i ] ) ;
UBGraphicsPolygonItem * pi = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( collidItems [ i ] ) ;
if ( pi = = NULL )
UBGraphicsVectorItem * vi = qgraphicsitem_cast < UBGraphicsVectorItem * > ( collidItems [ i ] ) ;
continue ;
if ( pi ! = NULL )
{
QPainterPath itemPainterPath ;
QPainterPath itemPainterPath ;
itemPainterPath . addPolygon ( pi - > sceneTransform ( ) . map ( pi - > polygon ( ) ) ) ;
itemPainterPath . addPolygon ( pi - > sceneTransform ( ) . map ( pi - > polygon ( ) ) ) ;
@ -1046,6 +1084,23 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
intersectedPolygons < < newPath . simplified ( ) . toFillPolygons ( pi - > sceneTransform ( ) . inverted ( ) ) ;
intersectedPolygons < < newPath . simplified ( ) . toFillPolygons ( pi - > sceneTransform ( ) . inverted ( ) ) ;
}
}
}
}
} else if ( vi ! = NULL )
{
QPainterPath itemPainterPath ;
QList < QPointF > linePoints = vi - > linePoints ( ) ;
for ( int i = 0 ; i < linePoints . count ( ) ; + + i )
{
itemPainterPath . addEllipse ( linePoints [ i ] , 1 , 1 ) ;
}
if ( eraserPath . contains ( itemPainterPath ) | | eraserPath . intersects ( itemPainterPath ) )
{
# pragma omp critical
{
// Compete remove item
intersectedVectorItems < < vi ;
}
}
}
}
}
for ( int i = 0 ; i < intersectedItems . size ( ) ; i + + )
for ( int i = 0 ; i < intersectedItems . size ( ) ; i + + )
@ -1093,7 +1148,21 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
intersectedPolygonItem - > setTransform ( t ) ;
intersectedPolygonItem - > setTransform ( t ) ;
}
}
if ( ! intersectedItems . empty ( ) )
for ( int i = 0 ; i < intersectedVectorItems . size ( ) ; i + + )
{
UBGraphicsVectorItem * intersectedVectorItem = intersectedVectorItems [ i ] ;
mRemovedItems < < intersectedVectorItem ;
QTransform t ;
bool bApplyTransform = false ;
removeItem ( intersectedVectorItem ) ;
if ( bApplyTransform )
{
intersectedVectorItem - > setTransform ( t ) ;
}
}
if ( ! intersectedItems . empty ( ) | | ! intersectedVectorItems . empty ( ) )
setModified ( true ) ;
setModified ( true ) ;
}
}
@ -1271,6 +1340,28 @@ void UBGraphicsScene::initPolygonItem(UBGraphicsPolygonItem* polygonItem)
polygonItem - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( UBItemLayerType : : Graphic ) ) ;
polygonItem - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( UBItemLayerType : : Graphic ) ) ;
}
}
void UBGraphicsScene : : initVectorItem ( UBGraphicsVectorItem * vectorItem )
{
QColor colorOnDarkBG ;
QColor colorOnLightBG ;
colorOnDarkBG = UBApplication : : boardController - > penColorOnDarkBackground ( ) ;
colorOnLightBG = UBApplication : : boardController - > penColorOnLightBackground ( ) ;
if ( mDarkBackground )
{
vectorItem - > setColor ( colorOnDarkBG ) ;
}
else
{
vectorItem - > setColor ( colorOnLightBG ) ;
}
vectorItem - > setColorOnDarkBackground ( colorOnDarkBG ) ;
vectorItem - > setColorOnLightBackground ( colorOnLightBG ) ;
vectorItem - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( UBItemLayerType : : Graphic ) ) ;
}
UBGraphicsPolygonItem * UBGraphicsScene : : arcToPolygonItem ( const QLineF & pStartRadius , qreal pSpanAngle , qreal pWidth )
UBGraphicsPolygonItem * UBGraphicsScene : : arcToPolygonItem ( const QLineF & pStartRadius , qreal pSpanAngle , qreal pWidth )
{
{
QPolygonF polygon = UBGeometryUtils : : arcToPolygon ( pStartRadius , pSpanAngle , pWidth ) ;
QPolygonF polygon = UBGeometryUtils : : arcToPolygon ( pStartRadius , pSpanAngle , pWidth ) ;
@ -1491,7 +1582,7 @@ void UBGraphicsScene::clearContent(clearCase pCase)
? qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item - > parentItem ( ) )
? qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item - > parentItem ( ) )
: 0 ;
: 0 ;
UBGraphicsItemDelegate * curDelegate = UBGraphicsItem : : Delegate ( item ) ;
UBGraphicsItemDelegate * curDelegate = UBGraphicsItem : : Delegate ( item ) ;
if ( ! curDelegate ) {
if ( ! curDelegate & & item - > type ( ) ! = UBGraphicsVectorItem : : Type ) {
continue ;
continue ;
}
}
@ -1499,6 +1590,12 @@ void UBGraphicsScene::clearContent(clearCase pCase)
bool isStrokesGroup = item - > type ( ) = = UBGraphicsStrokesGroup : : Type ;
bool isStrokesGroup = item - > type ( ) = = UBGraphicsStrokesGroup : : Type ;
bool shouldDelete = false ;
bool shouldDelete = false ;
if ( item - > type ( ) = = UBGraphicsVectorItem : : Type )
{
removedItems < < item ;
this - > removeItem ( item ) ;
} else
{
switch ( static_cast < int > ( pCase ) ) {
switch ( static_cast < int > ( pCase ) ) {
case clearAnnotations :
case clearAnnotations :
shouldDelete = isStrokesGroup ;
shouldDelete = isStrokesGroup ;
@ -1510,6 +1607,7 @@ void UBGraphicsScene::clearContent(clearCase pCase)
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) ;
shouldDelete = ! isGroup & & ! isBackgroundObject ( item ) ;
break ;
break ;
}
}
}
if ( shouldDelete ) {
if ( shouldDelete ) {
if ( itemGroup ) {
if ( itemGroup ) {