@ -1,5 +1,5 @@
/*
/*
* Copyright ( C ) 2012 Webdoc SA
* Copyright ( C ) 2010 - 2013 Groupement d ' Intérêt Public pour l ' Education Numérique en Afrique ( GIP ENA )
*
*
* This file is part of Open - Sankoré .
* This file is part of Open - Sankoré .
*
*
@ -399,10 +399,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mXmlReader . readNext ( ) ;
mXmlReader . readNext ( ) ;
if ( mXmlReader . isStartElement ( ) )
if ( mXmlReader . isStartElement ( ) )
{
{
qreal zFromSvg = getZValueFromSvg ( ) ;
QUuid uuidFromSvg = getUuidFromSvg ( ) ;
if ( mXmlReader . name ( ) = = " svg " )
if ( mXmlReader . name ( ) = = " svg " )
{
{
if ( ! mScene )
if ( ! mScene )
@ -443,9 +439,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
QStringRef svgSceneUuid = mXmlReader . attributes ( ) . value ( mNamespaceUri , " uuid " ) ;
QStringRef svgSceneUuid = mXmlReader . attributes ( ) . value ( mNamespaceUri , " uuid " ) ;
if ( ! svgSceneUuid . isNull ( ) )
if ( ! svgSceneUuid . isNull ( ) )
{
mScene - > setUuid ( QUuid ( svgSceneUuid . toString ( ) ) ) ;
mScene - > setUuid ( QUuid ( svgSceneUuid . toString ( ) ) ) ;
}
// introduced in UB 4.0
// introduced in UB 4.0
@ -475,9 +469,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
QStringRef pageDpi = mXmlReader . attributes ( ) . value ( " pageDpi " ) ;
QStringRef pageDpi = mXmlReader . attributes ( ) . value ( " pageDpi " ) ;
if ( ! pageDpi . isNull ( ) )
if ( ! pageDpi . isNull ( ) )
{
UBSettings : : settings ( ) - > pageDpi - > set ( pageDpi . toString ( ) ) ;
UBSettings : : settings ( ) - > pageDpi - > set ( pageDpi . toString ( ) ) ;
}
bool darkBackground = false ;
bool darkBackground = false ;
bool crossedBackground = false ;
bool crossedBackground = false ;
@ -560,9 +552,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
if ( polygonItem )
if ( polygonItem )
{
{
polygonItem - > setUuid ( uuidFromSvg ) ;
polygonItem - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( UBItemLayerType : : Graphic ) ) ;
polygonItem - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( UBItemLayerType : : Graphic ) ) ;
UBGraphicsStrokesGroup * group ;
UBGraphicsStrokesGroup * group ;
@ -570,24 +559,26 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
group = new UBGraphicsStrokesGroup ( ) ;
group = new UBGraphicsStrokesGroup ( ) ;
mStrokesList . insert ( parentId , group ) ;
mStrokesList . insert ( parentId , group ) ;
currentStroke = new UBGraphicsStroke ( ) ;
currentStroke = new UBGraphicsStroke ( ) ;
group - > setTransform ( polygonItem - > transform ( ) ) ;
UBGraphicsItem : : assignZValue ( group , polygonItem - > zValue ( ) ) ;
}
}
else
else
group = mStrokesList . value ( parentId ) ;
group = mStrokesList . value ( parentId ) ;
if ( polygonItem - > transform ( ) . isIdentity ( ) )
polygonItem - > setTransform ( group - > transform ( ) ) ;
polygonItem - > setTransform ( group - > transform ( ) ) ;
group - > addToGroup ( polygonItem ) ;
group - > addToGroup ( polygonItem ) ;
polygonItem - > setStrokesGroup ( group ) ;
polygonItem - > setStrokesGroup ( group ) ;
polygonItem - > setStroke ( currentStroke ) ;
polygonItem - > setStroke ( currentStroke ) ;
polygonItem - > show ( ) ;
polygonItem - > show ( ) ;
group - > addToGroup ( polygonItem ) ;
group - > addToGroup ( polygonItem ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " polyline " )
else if ( mXmlReader . name ( ) = = " polyline " )
{
{
QList < UBGraphicsPolygonItem * > polygonItems
QList < UBGraphicsPolygonItem * > polygonItems = polygonItemsFromPolylineSvg ( mScene - > isDarkBackground ( ) ? Qt : : white : Qt : : black ) ;
= polygonItemsFromPolylineSvg ( mScene - > isDarkBackground ( ) ? Qt : : white : Qt : : black ) ;
QString parentId = QUuid : : createUuid ( ) . toString ( ) ;
QString parentId = QUuid : : createUuid ( ) . toString ( ) ;
@ -600,11 +591,15 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
group = new UBGraphicsStrokesGroup ( ) ;
group = new UBGraphicsStrokesGroup ( ) ;
mStrokesList . insert ( parentId , group ) ;
mStrokesList . insert ( parentId , group ) ;
currentStroke = new UBGraphicsStroke ( ) ;
currentStroke = new UBGraphicsStroke ( ) ;
group - > setTransform ( polygonItem - > transform ( ) ) ;
UBGraphicsItem : : assignZValue ( group , polygonItem - > zValue ( ) ) ;
}
}
else
else
group = mStrokesList . value ( parentId ) ;
group = mStrokesList . value ( parentId ) ;
if ( polygonItem - > transform ( ) . isIdentity ( ) )
polygonItem - > setTransform ( group - > transform ( ) ) ;
polygonItem - > setTransform ( group - > transform ( ) ) ;
group - > addToGroup ( polygonItem ) ;
group - > addToGroup ( polygonItem ) ;
polygonItem - > setStrokesGroup ( group ) ;
polygonItem - > setStrokesGroup ( group ) ;
polygonItem - > setStroke ( currentStroke ) ;
polygonItem - > setStroke ( currentStroke ) ;
@ -612,6 +607,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
polygonItem - > show ( ) ;
polygonItem - > show ( ) ;
group - > addToGroup ( polygonItem ) ;
group - > addToGroup ( polygonItem ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " image " )
else if ( mXmlReader . name ( ) = = " image " )
{
{
@ -636,12 +632,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( pixmapItem ) ;
mScene - > addItem ( pixmapItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( pixmapItem , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
pixmapItem - > setUuid ( uuidFromSvg ) ;
if ( isBackground )
if ( isBackground )
mScene - > setAsBackgroundObject ( pixmapItem ) ;
mScene - > setAsBackgroundObject ( pixmapItem ) ;
@ -651,7 +641,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if ( href . contains ( " svg " ) )
else if ( href . contains ( " svg " ) )
{
{
UBGraphicsSvgItem * svgItem = svgItemFromSvg ( ) ;
UBGraphicsSvgItem * svgItem = svgItemFromSvg ( ) ;
if ( svgItem )
if ( svgItem )
{
{
svgItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
svgItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
@ -659,9 +648,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( svgItem ) ;
mScene - > addItem ( svgItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( svgItem , zFromSvg ) ;
if ( isBackground )
if ( isBackground )
mScene - > setAsBackgroundObject ( svgItem ) ;
mScene - > setAsBackgroundObject ( svgItem ) ;
@ -677,7 +663,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if ( mXmlReader . name ( ) = = " audio " )
else if ( mXmlReader . name ( ) = = " audio " )
{
{
UBGraphicsMediaItem * audioItem = audioItemFromSvg ( ) ;
UBGraphicsMediaItem * audioItem = audioItemFromSvg ( ) ;
if ( audioItem )
if ( audioItem )
{
{
audioItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
audioItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
@ -685,12 +670,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( audioItem ) ;
mScene - > addItem ( audioItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( audioItem , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
audioItem - > setUuid ( uuidFromSvg ) ;
audioItem - > show ( ) ;
audioItem - > show ( ) ;
//force start to load the video and display the first frame
//force start to load the video and display the first frame
@ -701,20 +680,14 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if ( mXmlReader . name ( ) = = " video " )
else if ( mXmlReader . name ( ) = = " video " )
{
{
UBGraphicsMediaItem * videoItem = videoItemFromSvg ( ) ;
UBGraphicsMediaItem * videoItem = videoItemFromSvg ( ) ;
if ( videoItem )
if ( videoItem )
{
{
videoItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
videoItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
videoItem - > setFlag ( QGraphicsItem : : ItemIsSelectable , true ) ;
videoItem - > setFlag ( QGraphicsItem : : ItemIsSelectable , true ) ;
mScene - > addItem ( videoItem ) ;
mScene - > addItem ( videoItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( videoItem , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
videoItem - > setUuid ( uuidFromSvg ) ;
videoItem - > show ( ) ;
videoItem - > show ( ) ;
//force start to load the video and display the first frame
//force start to load the video and display the first frame
@ -725,7 +698,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if ( mXmlReader . name ( ) = = " text " ) //This is for backward compatibility with proto text field prior to version 4.3
else if ( mXmlReader . name ( ) = = " text " ) //This is for backward compatibility with proto text field prior to version 4.3
{
{
UBGraphicsTextItem * textItem = textItemFromSvg ( ) ;
UBGraphicsTextItem * textItem = textItemFromSvg ( ) ;
if ( textItem )
if ( textItem )
{
{
textItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
textItem - > setFlag ( QGraphicsItem : : ItemIsMovable , true ) ;
@ -733,85 +705,54 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( textItem ) ;
mScene - > addItem ( textItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( textItem , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
textItem - > setUuid ( uuidFromSvg ) ;
textItem - > show ( ) ;
textItem - > show ( ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " curtain " )
else if ( mXmlReader . name ( ) = = " curtain " )
{
{
UBGraphicsCurtainItem * mask = curtainItemFromSvg ( ) ;
UBGraphicsCurtainItem * mask = curtainItemFromSvg ( ) ;
if ( mask )
if ( mask )
{
{
mScene - > addItem ( mask ) ;
mScene - > addItem ( mask ) ;
mScene - > registerTool ( mask ) ;
mScene - > registerTool ( mask ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( mask , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
mask - > setUuid ( uuidFromSvg ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " ruler " )
else if ( mXmlReader . name ( ) = = " ruler " )
{
{
QString ubZValue = mXmlReader . attributes ( ) . value ( mNamespaceUri , " z-value " ) . toString ( ) ;
UBGraphicsRuler * ruler = rulerFromSvg ( ) ;
UBGraphicsRuler * ruler = rulerFromSvg ( ) ;
ubZValue = mXmlReader . attributes ( ) . value ( mNamespaceUri , " z-value " ) . toString ( ) ;
if ( ruler )
if ( ruler )
{
{
mScene - > addItem ( ruler ) ;
mScene - > addItem ( ruler ) ;
mScene - > registerTool ( ruler ) ;
mScene - > registerTool ( ruler ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( ruler , zFromSvg ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " compass " )
else if ( mXmlReader . name ( ) = = " compass " )
{
{
UBGraphicsCompass * compass = compassFromSvg ( ) ;
UBGraphicsCompass * compass = compassFromSvg ( ) ;
if ( compass )
if ( compass )
{
{
mScene - > addItem ( compass ) ;
mScene - > addItem ( compass ) ;
mScene - > registerTool ( compass ) ;
mScene - > registerTool ( compass ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( compass , zFromSvg ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " protractor " )
else if ( mXmlReader . name ( ) = = " protractor " )
{
{
UBGraphicsProtractor * protractor = protractorFromSvg ( ) ;
UBGraphicsProtractor * protractor = protractorFromSvg ( ) ;
if ( protractor )
if ( protractor )
{
{
mScene - > addItem ( protractor ) ;
mScene - > addItem ( protractor ) ;
mScene - > registerTool ( protractor ) ;
mScene - > registerTool ( protractor ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( protractor , zFromSvg ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " triangle " )
else if ( mXmlReader . name ( ) = = " triangle " )
{
{
UBGraphicsTriangle * triangle = triangleFromSvg ( ) ;
UBGraphicsTriangle * triangle = triangleFromSvg ( ) ;
if ( triangle )
if ( triangle )
{
{
mScene - > addItem ( triangle ) ;
mScene - > addItem ( triangle ) ;
mScene - > registerTool ( triangle ) ;
mScene - > registerTool ( triangle ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( triangle , zFromSvg ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " cache " )
else if ( mXmlReader . name ( ) = = " cache " )
@ -822,9 +763,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( cache ) ;
mScene - > addItem ( cache ) ;
mScene - > registerTool ( cache ) ;
mScene - > registerTool ( cache ) ;
UBApplication : : boardController - > notifyCache ( true ) ;
UBApplication : : boardController - > notifyCache ( true ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( cache , zFromSvg ) ;
}
}
}
}
else if ( mXmlReader . name ( ) = = " foreignObject " )
else if ( mXmlReader . name ( ) = = " foreignObject " )
@ -851,9 +789,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( pdfItem ) ;
mScene - > addItem ( pdfItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( pdfItem , zFromSvg ) ;
if ( isBackground )
if ( isBackground )
mScene - > setAsBackgroundObject ( pdfItem ) ;
mScene - > setAsBackgroundObject ( pdfItem ) ;
@ -873,12 +808,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( appleWidgetItem ) ;
mScene - > addItem ( appleWidgetItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( appleWidgetItem , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
appleWidgetItem - > setUuid ( uuidFromSvg ) ;
appleWidgetItem - > show ( ) ;
appleWidgetItem - > show ( ) ;
currentWidget = appleWidgetItem ;
currentWidget = appleWidgetItem ;
@ -887,7 +816,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if ( src . contains ( " .wgt " ) )
else if ( src . contains ( " .wgt " ) )
{
{
UBGraphicsW3CWidgetItem * w3cWidgetItem = graphicsW3CWidgetFromSvg ( ) ;
UBGraphicsW3CWidgetItem * w3cWidgetItem = graphicsW3CWidgetFromSvg ( ) ;
if ( w3cWidgetItem )
if ( w3cWidgetItem )
{
{
w3cWidgetItem - > setFlag ( QGraphicsItem : : ItemIsSelectable , true ) ;
w3cWidgetItem - > setFlag ( QGraphicsItem : : ItemIsSelectable , true ) ;
@ -896,12 +824,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( w3cWidgetItem ) ;
mScene - > addItem ( w3cWidgetItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( w3cWidgetItem , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
w3cWidgetItem - > setUuid ( uuidFromSvg ) ;
w3cWidgetItem - > show ( ) ;
w3cWidgetItem - > show ( ) ;
currentWidget = w3cWidgetItem ;
currentWidget = w3cWidgetItem ;
@ -910,7 +832,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
else if ( type = = " text " )
else if ( type = = " text " )
{
{
UBGraphicsTextItem * textItem = textItemFromSvg ( ) ;
UBGraphicsTextItem * textItem = textItemFromSvg ( ) ;
UBGraphicsTextItemDelegate * textDelegate = 0 ;
UBGraphicsTextItemDelegate * textDelegate = 0 ;
if ( textItem )
if ( textItem )
@ -931,12 +852,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( textItem ) ;
mScene - > addItem ( textItem ) ;
if ( zFromSvg ! = UBZLayerController : : errorNum ( ) )
UBGraphicsItem : : assignZValue ( textItem , zFromSvg ) ;
if ( ! uuidFromSvg . isNull ( ) )
textItem - > setUuid ( uuidFromSvg ) ;
textItem - > show ( ) ;
textItem - > show ( ) ;
}
}
}
}
@ -991,9 +906,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
mScene - > addItem ( iterator . value ( ) ) ;
mScene - > addItem ( iterator . value ( ) ) ;
}
}
if ( mScene ) {
if ( mScene )
mScene - > setModified ( false ) ;
mScene - > setModified ( false ) ;
}
mScene - > enableUndoRedoStack ( ) ;
mScene - > enableUndoRedoStack ( ) ;
qDebug ( ) < < " loadScene() : created scene and read file " ;
qDebug ( ) < < " loadScene() : created scene and read file " ;
@ -1213,24 +1127,25 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
foreach ( QGraphicsItem * item , strokesGroupItem - > childItems ( ) ) {
foreach ( QGraphicsItem * item , strokesGroupItem - > childItems ( ) ) {
UBGraphicsPolygonItem * poly = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
UBGraphicsPolygonItem * poly = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
if ( ! poly ) {
if ( ! poly )
continue ;
continue ;
} else if ( ! resultPoly ) {
if ( ! resultPoly ) {
resultPoly = poly ;
resultPoly = poly ;
continue ;
continue ;
}
}
QPolygonF newPolygon = poly - > sceneTransform ( ) . map ( poly - > polygon ( ) ) ;
QPainterPath strokePainterPath ;
strokePainterPath . addPolygon ( resultPoly - > sceneTransform ( ) . map ( resultPoly - > polygon ( ) ) ) ;
QPolygonF oldPolygons = strokePainterPath . simplified ( ) . toFillPolygon ( resultPoly - > sceneTransform ( ) . inverted ( ) ) ;
newPolygon = oldPolygons . united ( newPolygon ) ;
resultPoly - > setPolygon ( newPolygon ) ;
//
QPolygonF unitedPolygon = resultPoly - > polygon ( ) . united ( poly - > polygon ( ) ) ;
resultPoly - > setPolygon ( unitedPolygon ) ;
items . removeOne ( poly ) ;
items . removeOne ( poly ) ;
}
}
if ( resultPoly ) {
if ( resultPoly ) {
polygonItemToSvgPolygon ( resultPoly , true ) ;
resultPoly - > setZValue ( strokesGroupItem - > zValue ( ) ) ;
//Claudio: the painter path simplification remove all the polygons overlap
QPainterPath painterPath ;
painterPath . addPolygon ( resultPoly - > polygon ( ) ) ;
painterPath = painterPath . simplified ( ) ;
resultPoly - > setPolygon ( painterPath . toFillPolygon ( ) ) ;
polygonItemToSvgPolygon ( resultPoly , false ) ;
items . removeOne ( resultPoly ) ;
items . removeOne ( resultPoly ) ;
}
}
}
}
@ -1239,9 +1154,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
UBGraphicsPolygonItem * polygonItem = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
UBGraphicsPolygonItem * polygonItem = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
if ( polygonItem & & polygonItem - > isVisible ( ) )
if ( polygonItem & & polygonItem - > isVisible ( ) )
{
{
UBGraphicsStroke * currentStroke = polygonItem - > stroke ( ) ;
UBGraphicsStroke * currentStroke = polygonItem - > stroke ( ) ;
if ( openStroke & & ( currentStroke ! = openStroke ) )
if ( openStroke & & ( currentStroke ! = openStroke ) )
{
{
mXmlWriter . writeEndElement ( ) ; //g
mXmlWriter . writeEndElement ( ) ; //g
@ -1514,7 +1427,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistGroupToDom(QGraphicsItem *gro
foreach ( QGraphicsItem * item , groupItem - > childItems ( ) ) {
foreach ( QGraphicsItem * item , groupItem - > childItems ( ) ) {
QUuid tmpUuid = UBGraphicsScene : : getPersonalUuid ( item ) ;
QUuid tmpUuid = UBGraphicsScene : : getPersonalUuid ( item ) ;
if ( ! tmpUuid . isNull ( ) ) {
if ( ! tmpUuid . isNull ( ) ) {
if ( item - > type ( ) = = UBGraphicsGroupContainerItem : : Type & & item - > childItems ( ) . count ( ) ) {
if ( item - > type ( ) = = UBGraphicsGroupContainerItem : : Type & & item - > childItems ( ) . count ( ) )
persistGroupToDom ( item , curParent , groupDomDocument ) ;
persistGroupToDom ( item , curParent , groupDomDocument ) ;
}
}
else {
else {
@ -1525,7 +1438,6 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistGroupToDom(QGraphicsItem *gro
}
}
}
}
}
}
}
}
}
void UBSvgSubsetAdaptor : : UBSvgSubsetWriter : : polygonItemToSvgLine ( UBGraphicsPolygonItem * polygonItem , bool groupHoldsInfo )
void UBSvgSubsetAdaptor : : UBSvgSubsetWriter : : polygonItemToSvgLine ( UBGraphicsPolygonItem * polygonItem , bool groupHoldsInfo )
@ -1694,26 +1606,15 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromPol
{
{
UBGraphicsPolygonItem * polygonItem = new UBGraphicsPolygonItem ( ) ;
UBGraphicsPolygonItem * polygonItem = new UBGraphicsPolygonItem ( ) ;
graphicsItemFromSvg ( polygonItem ) ;
QStringRef svgPoints = mXmlReader . attributes ( ) . value ( " points " ) ;
QStringRef svgPoints = mXmlReader . attributes ( ) . value ( " points " ) ;
QPolygonF polygon ;
QPolygonF polygon ;
if ( ! svgPoints . isNull ( ) )
if ( ! svgPoints . isNull ( ) )
{
{
// int lenght = strlen(svgPoints.toUtf8().constData()) + 1;
QStringList ts = svgPoints . toString ( ) . split ( QLatin1Char ( ' ' ) , QString : : SkipEmptyParts ) ;
// char pippo[lenght];
// memcpy(pippo,svgPoints.toUtf8().constData(),lenght);
// char* localPosition = (char*) &pippo[0];
// do{
// float x = atof(localPosition);
// localPosition = strchr(localPosition,',') + 1;
// float y = atof(localPosition);
// localPosition = strchrnul(localPosition,' ');
// polygon << QPointF(x,y);
// }while(localPosition - pippo > lenght - 5);
QStringList ts = svgPoints . toString ( ) . split ( QLatin1Char ( ' ' ) ,
QString : : SkipEmptyParts ) ;
foreach ( const QString sPoint , ts )
foreach ( const QString sPoint , ts )
{
{
@ -1748,26 +1649,13 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromPol
polygonItem - > setPolygon ( polygon ) ;
polygonItem - > setPolygon ( polygon ) ;
QStringRef svgTransform = mXmlReader . attributes ( ) . value ( " transform " ) ;
QMatrix itemMatrix ;
if ( ! svgTransform . isNull ( ) )
{
itemMatrix = fromSvgTransform ( svgTransform . toString ( ) ) ;
polygonItem - > setMatrix ( itemMatrix ) ;
}
QStringRef svgFill = mXmlReader . attributes ( ) . value ( " fill " ) ;
QStringRef svgFill = mXmlReader . attributes ( ) . value ( " fill " ) ;
QColor brushColor = pDefaultColor ;
QColor brushColor = pDefaultColor ;
if ( ! svgFill . isNull ( ) )
if ( ! svgFill . isNull ( ) )
{
brushColor . setNamedColor ( svgFill . toString ( ) ) ;
brushColor . setNamedColor ( svgFill . toString ( ) ) ;
}
QStringRef svgFillOpacity = mXmlReader . attributes ( ) . value ( " fill-opacity " ) ;
QStringRef svgFillOpacity = mXmlReader . attributes ( ) . value ( " fill-opacity " ) ;
qreal opacity = 1.0 ;
qreal opacity = 1.0 ;
@ -1779,17 +1667,6 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromPol
polygonItem - > setColor ( brushColor ) ;
polygonItem - > setColor ( brushColor ) ;
QStringRef ubZValue = mXmlReader . attributes ( ) . value ( mNamespaceUri , " z-value " ) ;
if ( ! ubZValue . isNull ( ) )
{
UBGraphicsItem : : assignZValue ( polygonItem , ubZValue . toString ( ) . toFloat ( ) ) ;
}
else
{
UBGraphicsItem : : assignZValue ( polygonItem , mGroupZIndex ) ;
}
QStringRef ubFillOnDarkBackground = mXmlReader . attributes ( ) . value ( mNamespaceUri , " fill-on-dark-background " ) ;
QStringRef ubFillOnDarkBackground = mXmlReader . attributes ( ) . value ( mNamespaceUri , " fill-on-dark-background " ) ;
if ( ! ubFillOnDarkBackground . isNull ( ) )
if ( ! ubFillOnDarkBackground . isNull ( ) )
@ -1864,6 +1741,7 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromLin
}
}
UBGraphicsPolygonItem * polygonItem = new UBGraphicsPolygonItem ( line , lineWidth ) ;
UBGraphicsPolygonItem * polygonItem = new UBGraphicsPolygonItem ( line , lineWidth ) ;
graphicsItemFromSvg ( polygonItem ) ;
QStringRef svgStroke = mXmlReader . attributes ( ) . value ( " stroke " ) ;
QStringRef svgStroke = mXmlReader . attributes ( ) . value ( " stroke " ) ;
@ -1886,18 +1764,6 @@ UBGraphicsPolygonItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::polygonItemFromLin
polygonItem - > setColor ( brushColor ) ;
polygonItem - > setColor ( brushColor ) ;
QStringRef ubZValue = mXmlReader . attributes ( ) . value ( mNamespaceUri , " z-value " ) ;
if ( ! ubZValue . isNull ( ) )
{
UBGraphicsItem : : assignZValue ( polygonItem , ubZValue . toString ( ) . toFloat ( ) ) ;
}
else
{
UBGraphicsItem : : assignZValue ( polygonItem , mGroupZIndex ) ;
}
QStringRef ubFillOnDarkBackground = mXmlReader . attributes ( ) . value ( mNamespaceUri , " fill-on-dark-background " ) ;
QStringRef ubFillOnDarkBackground = mXmlReader . attributes ( ) . value ( mNamespaceUri , " fill-on-dark-background " ) ;
if ( ! ubFillOnDarkBackground . isNull ( ) )
if ( ! ubFillOnDarkBackground . isNull ( ) )
@ -2288,24 +2154,21 @@ UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg()
//Claudio this is necessary to fix the absolute path added on Sankore 3.1 1.00.00
//Claudio this is necessary to fix the absolute path added on Sankore 3.1 1.00.00
//The absoult path doesn't work when you want to share Sankore documents.
//The absoult path doesn't work when you want to share Sankore documents.
if ( ! h ref. startsWith ( " audios/ " ) ) {
if ( ! audioH ref. startsWith ( " audios/ " ) ) {
int indexOfAudioDirectory = href . lastIndexOf ( " audios " ) ;
int indexOfAudioDirectory = href . lastIndexOf ( " audios " ) ;
href = mDocumentPath + " / " + href . right ( href . length ( ) - indexOfAudioDirectory ) ;
href = mDocumentPath + " / " + href . right ( href . length ( ) - indexOfAudioDirectory ) ;
}
}
UBGraphicsMediaItem * audioItem = new UBGraphicsMediaItem ( QUrl : : fromLocalFile ( href ) ) ;
UBGraphicsMediaItem * audioItem = new UBGraphicsMediaItem ( QUrl : : fromLocalFile ( href ) ) ;
if ( audioItem ) {
if ( audioItem )
audioItem - > connect ( UBApplication : : boardController , SIGNAL ( activeSceneChanged ( ) ) , audioItem , SLOT ( activeSceneChanged ( ) ) ) ;
audioItem - > connect ( UBApplication : : boardController , SIGNAL ( activeSceneChanged ( ) ) , audioItem , SLOT ( activeSceneChanged ( ) ) ) ;
}
graphicsItemFromSvg ( audioItem ) ;
graphicsItemFromSvg ( audioItem ) ;
QStringRef ubPos = mXmlReader . attributes ( ) . value ( mNamespaceUri , " position " ) ;
QStringRef ubPos = mXmlReader . attributes ( ) . value ( mNamespaceUri , " position " ) ;
qint64 p = 0 ;
qint64 p = 0 ;
if ( ! ubPos . isNull ( ) )
if ( ! ubPos . isNull ( ) )
{
p = ubPos . toString ( ) . toLongLong ( ) ;
p = ubPos . toString ( ) . toLongLong ( ) ;
}
audioItem - > setInitialPos ( p ) ;
audioItem - > setInitialPos ( p ) ;
return audioItem ;
return audioItem ;
@ -2326,7 +2189,7 @@ UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::videoItemFromSvg()
//Claudio this is necessary to fix the absolute path added on Sankore 3.1 1.00.00
//Claudio this is necessary to fix the absolute path added on Sankore 3.1 1.00.00
//The absoult path doesn't work when you want to share Sankore documents.
//The absoult path doesn't work when you want to share Sankore documents.
if ( ! h ref. startsWith ( " videos/ " ) ) {
if ( ! videoH ref. startsWith ( " videos/ " ) ) {
int indexOfAudioDirectory = href . lastIndexOf ( " videos " ) ;
int indexOfAudioDirectory = href . lastIndexOf ( " videos " ) ;
href = mDocumentPath + " / " + href . right ( href . length ( ) - indexOfAudioDirectory ) ;
href = mDocumentPath + " / " + href . right ( href . length ( ) - indexOfAudioDirectory ) ;
}
}
@ -2380,9 +2243,9 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g
{
{
if ( ! svgX . isNull ( ) & & ! svgY . isNull ( ) )
if ( ! svgX . isNull ( ) & & ! svgY . isNull ( ) )
{
{
# ifdef Q_WS_WIN
# ifdef Q_WS_WIN
gItem - > setPos ( svgX . toString ( ) . toFloat ( ) , svgY . toString ( ) . toFloat ( ) ) ;
gItem - > setPos ( svgX . toString ( ) . toFloat ( ) , svgY . toString ( ) . toFloat ( ) ) ;
# endif
# endif
}
}
}
}
@ -2402,9 +2265,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g
QStringRef ubZValue = mXmlReader . attributes ( ) . value ( mNamespaceUri , " z-value " ) ;
QStringRef ubZValue = mXmlReader . attributes ( ) . value ( mNamespaceUri , " z-value " ) ;
if ( ! ubZValue . isNull ( ) )
if ( ! ubZValue . isNull ( ) )
{
UBGraphicsItem : : assignZValue ( gItem , ubZValue . toString ( ) . toFloat ( ) ) ;
UBGraphicsItem : : assignZValue ( gItem , ubZValue . toString ( ) . toFloat ( ) ) ;
}
UBItem * ubItem = dynamic_cast < UBItem * > ( gItem ) ;
UBItem * ubItem = dynamic_cast < UBItem * > ( gItem ) ;
@ -2413,17 +2274,15 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g
QStringRef ubUuid = mXmlReader . attributes ( ) . value ( mNamespaceUri , " uuid " ) ;
QStringRef ubUuid = mXmlReader . attributes ( ) . value ( mNamespaceUri , " uuid " ) ;
if ( ! ubUuid . isNull ( ) )
if ( ! ubUuid . isNull ( ) )
{
ubItem - > setUuid ( QUuid ( ubUuid . toString ( ) ) ) ;
ubItem - > setUuid ( QUuid ( ubUuid . toString ( ) ) ) ;
}
else
ubItem - > setUuid ( QUuid : : createUuid ( ) ) ;
QStringRef ubSource = mXmlReader . attributes ( ) . value ( mNamespaceUri , " source " ) ;
QStringRef ubSource = mXmlReader . attributes ( ) . value ( mNamespaceUri , " source " ) ;
if ( ! ubSource . isNull ( ) )
if ( ! ubSource . isNull ( ) )
{
ubItem - > setSourceUrl ( QUrl ( ubSource . toString ( ) ) ) ;
ubItem - > setSourceUrl ( QUrl ( ubSource . toString ( ) ) ) ;
}
}
}
QStringRef ubLocked = mXmlReader . attributes ( ) . value ( mNamespaceUri , " locked " ) ;
QStringRef ubLocked = mXmlReader . attributes ( ) . value ( mNamespaceUri , " locked " ) ;
@ -2449,35 +2308,10 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::graphicsItemFromSvg(QGraphicsItem* g
int layerAsInt = ubLayer . toString ( ) . toInt ( & ok ) ;
int layerAsInt = ubLayer . toString ( ) . toInt ( & ok ) ;
if ( ok )
if ( ok )
{
gItem - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( layerAsInt ) ) ;
gItem - > setData ( UBGraphicsItemData : : ItemLayerType , QVariant ( layerAsInt ) ) ;
}
}
}
}
qreal UBSvgSubsetAdaptor : : UBSvgSubsetReader : : getZValueFromSvg ( )
{
qreal result = UBZLayerController : : errorNum ( ) ;
QStringRef ubZValue = mXmlReader . attributes ( ) . value ( mNamespaceUri , " z-value " ) ;
if ( ! ubZValue . isNull ( ) ) {
result = ubZValue . toString ( ) . toFloat ( ) ;
}
return result ;
}
QUuid UBSvgSubsetAdaptor : : UBSvgSubsetReader : : getUuidFromSvg ( )
{
QString strUuid = mXmlReader . attributes ( ) . value ( mNamespaceUri , " uuid " ) . toString ( ) ;
QUuid uuid = QUuid ( strUuid ) ;
if ( ! uuid . isNull ( ) )
return uuid ;
return QUuid : : createUuid ( ) ;
}
}
void UBSvgSubsetAdaptor : : UBSvgSubsetWriter : : graphicsItemToSvg ( QGraphicsItem * item )
void UBSvgSubsetAdaptor : : UBSvgSubsetWriter : : graphicsItemToSvg ( QGraphicsItem * item )
{
{
mXmlWriter . writeAttribute ( " x " , " 0 " ) ;
mXmlWriter . writeAttribute ( " x " , " 0 " ) ;
@ -2769,6 +2603,7 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
if ( mXmlReader . hasError ( ) )
if ( mXmlReader . hasError ( ) )
{
{
delete textItem ;
delete textItem ;
textItem = 0 ;
return 0 ;
return 0 ;
}
}
@ -3299,9 +3134,3 @@ void UBSvgSubsetAdaptor::convertSvgImagesToImages(UBDocumentProxy* proxy)
}
}
}
}
}
}