@ -256,6 +256,29 @@ UBGraphicsScene* UBSvgSubsetAdaptor::loadScene(UBDocumentProxy* proxy, const int
}
}
QByteArray UBSvgSubsetAdaptor : : loadSceneAsText ( UBDocumentProxy * proxy , const int pageIndex )
{
QString fileName = proxy - > persistencePath ( ) + UBFileSystemUtils : : digitFileFormat ( " /page%1.svg " , pageIndex ) ;
qDebug ( ) < < fileName ;
QFile file ( fileName ) ;
if ( file . exists ( ) )
{
if ( ! file . open ( QIODevice : : ReadOnly ) )
{
qWarning ( ) < < " Cannot open file " < < fileName < < " for reading ... " ;
return " " ;
}
return file . readAll ( ) ;
file . close ( ) ;
}
return " " ;
}
QUuid UBSvgSubsetAdaptor : : sceneUuid ( UBDocumentProxy * proxy , const int pageIndex )
QUuid UBSvgSubsetAdaptor : : sceneUuid ( UBDocumentProxy * proxy , const int pageIndex )
{
{
QString fileName = proxy - > persistencePath ( ) + UBFileSystemUtils : : digitFileFormat ( " /page%1.svg " , pageIndex ) ;
QString fileName = proxy - > persistencePath ( ) + UBFileSystemUtils : : digitFileFormat ( " /page%1.svg " , pageIndex ) ;
@ -1019,307 +1042,299 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement()
bool UBSvgSubsetAdaptor : : UBSvgSubsetWriter : : persistScene ( int pageIndex )
bool UBSvgSubsetAdaptor : : UBSvgSubsetWriter : : persistScene ( int pageIndex )
{
{
Q_UNUSED ( pageIndex ) ;
Q_UNUSED ( pageIndex ) ;
if ( mScene - > isModified ( ) )
{
//Creating dom structure to store information
//Creating dom structure to store information
QDomDocument groupDomDocument ;
QDomDocument groupDomDocument ;
QDomElement groupRoot = groupDomDocument . createElement ( tGroups ) ;
QDomElement groupRoot = groupDomDocument . createElement ( tGroups ) ;
groupDomDocument . appendChild ( groupRoot ) ;
groupDomDocument . appendChild ( groupRoot ) ;
QBuffer buffer ;
QBuffer buffer ;
buffer . open ( QBuffer : : WriteOnly ) ;
buffer . open ( QBuffer : : WriteOnly ) ;
mXmlWriter . setDevice ( & buffer ) ;
mXmlWriter . setDevice ( & buffer ) ;
mXmlWriter . setAutoFormatting ( true ) ;
mXmlWriter . setAutoFormatting ( true ) ;
mXmlWriter . writeStartDocument ( ) ;
mXmlWriter . writeStartDocument ( ) ;
mXmlWriter . writeDefaultNamespace ( nsSvg ) ;
mXmlWriter . writeDefaultNamespace ( nsSvg ) ;
mXmlWriter . writeNamespace ( nsXLink , " xlink " ) ;
mXmlWriter . writeNamespace ( nsXLink , " xlink " ) ;
mXmlWriter . writeNamespace ( UBSettings : : uniboardDocumentNamespaceUri , " ub " ) ;
mXmlWriter . writeNamespace ( UBSettings : : uniboardDocumentNamespaceUri , " ub " ) ;
mXmlWriter . writeNamespace ( nsXHtml , " xhtml " ) ;
mXmlWriter . writeNamespace ( nsXHtml , " xhtml " ) ;
writeSvgElement ( ) ;
writeSvgElement ( ) ;
// Get the items from the scene
// Get the items from the scene
QList < QGraphicsItem * > items = mScene - > items ( ) ;
QList < QGraphicsItem * > items = mScene - > items ( ) ;
int strokes = 0 ; int polygons = 0 ;
int strokes = 0 ; int polygons = 0 ;
foreach ( QGraphicsItem * item , items ) {
foreach ( QGraphicsItem * item , items ) {
if ( item - > type ( ) = = UBGraphicsPolygonItem : : Type ) {
if ( item - > type ( ) = = UBGraphicsPolygonItem : : Type ) {
polygons + + ;
polygons + + ;
} else if ( item - > type ( ) = = UBGraphicsStrokesGroup : : Type ) {
} else if ( item - > type ( ) = = UBGraphicsStrokesGroup : : Type ) {
strokes + + ;
strokes + + ;
}
}
}
qDebug ( ) < < " ---Strokes count " < < strokes < < " Polygons count " < < polygons ;
}
qDebug ( ) < < " ---Strokes count " < < strokes < < " Polygons count " < < polygons ;
qSort ( items . begin ( ) , items . end ( ) , itemZIndexComp ) ;
qSort ( items . begin ( ) , items . end ( ) , itemZIndexComp ) ;
UBGraphicsStroke * openStroke = 0 ;
UBGraphicsStroke * openStroke = 0 ;
bool groupHoldsInfo = false ;
bool groupHoldsInfo = false ;
while ( ! items . empty ( ) )
while ( ! items . empty ( ) )
{
{
QGraphicsItem * item = items . takeFirst ( ) ;
QGraphicsItem * item = items . takeFirst ( ) ;
// Is the item a strokes group?
// Is the item a strokes group?
UBGraphicsStrokesGroup * strokesGroupItem = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ;
UBGraphicsStrokesGroup * strokesGroupItem = qgraphicsitem_cast < UBGraphicsStrokesGroup * > ( item ) ;
if ( strokesGroupItem & & strokesGroupItem - > isVisible ( ) ) {
if ( strokesGroupItem & & strokesGroupItem - > isVisible ( ) ) {
// Add the polygons
// Add the polygons
foreach ( QGraphicsItem * item , strokesGroupItem - > childItems ( ) ) {
foreach ( QGraphicsItem * item , strokesGroupItem - > childItems ( ) ) {
UBGraphicsPolygonItem * poly = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
UBGraphicsPolygonItem * poly = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
if ( NULL ! = poly ) {
if ( NULL ! = poly ) {
polygonItemToSvgPolygon ( poly , true ) ;
polygonItemToSvgPolygon ( poly , true ) ;
items . removeOne ( poly ) ;
items . removeOne ( poly ) ;
}
}
}
}
}
}
// Is the item a polygon?
// Is the item a polygon?
UBGraphicsPolygonItem * polygonItem = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
UBGraphicsPolygonItem * polygonItem = qgraphicsitem_cast < UBGraphicsPolygonItem * > ( item ) ;
if ( polygonItem & & polygonItem - > isVisible ( ) )
if ( polygonItem & & polygonItem - > isVisible ( ) )
{
UBGraphicsStroke * currentStroke = polygonItem - > stroke ( ) ;
if ( openStroke & & ( currentStroke ! = openStroke ) )
{
{
UBGraphicsStroke * currentStroke = polygonItem - > stroke ( ) ;
mXmlWriter . writeEndElement ( ) ; //g
if ( openStroke & & ( currentStroke ! = openStroke ) )
openStroke = 0 ;
{
groupHoldsInfo = false ;
mXmlWriter . writeEndElement ( ) ; //g
}
openStroke = 0 ;
groupHoldsInfo = false ;
}
bool firstPolygonInStroke = currentStroke & & ! openStroke ;
bool firstPolygonInStroke = currentStroke & & ! openStroke ;
if ( firstPolygonInStroke )
if ( firstPolygonInStroke )
{
{
mXmlWriter . writeStartElement ( " g " ) ;
mXmlWriter . writeStartElement ( " g " ) ;
openStroke = currentStroke ;
openStroke = currentStroke ;
QMatrix matrix = item - > sceneMatrix ( ) ;
QMatrix matrix = item - > sceneMatrix ( ) ;
if ( ! matrix . isIdentity ( ) )
if ( ! matrix . isIdentity ( ) )
mXmlWriter . writeAttribute ( " transform " , toSvgTransform ( matrix ) ) ;
mXmlWriter . writeAttribute ( " transform " , toSvgTransform ( matrix ) ) ;
UBGraphicsStroke * stroke = dynamic_cast < UBGraphicsStroke * > ( currentStroke ) ;
UBGraphicsStroke * stroke = dynamic_cast < UBGraphicsStroke * > ( currentStroke ) ;
if ( stroke )
if ( stroke )
{
{
QColor colorOnDarkBackground = polygonItem - > colorOnDarkBackground ( ) ;
QColor colorOnDarkBackground = polygonItem - > colorOnDarkBackground ( ) ;
QColor colorOnLightBackground = polygonItem - > colorOnLightBackground ( ) ;
QColor colorOnLightBackground = polygonItem - > colorOnLightBackground ( ) ;
if ( colorOnDarkBackground . isValid ( ) & & colorOnLightBackground . isValid ( ) )
if ( colorOnDarkBackground . isValid ( ) & & colorOnLightBackground . isValid ( ) )
{
{
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri , " z-value "
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri , " z-value "
, QString ( " %1 " ) . arg ( polygonItem - > zValue ( ) ) ) ;
, QString ( " %1 " ) . arg ( polygonItem - > zValue ( ) ) ) ;
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri
, " fill-on-dark-background " , colorOnDarkBackground . name ( ) ) ;
, " fill-on-dark-background " , colorOnDarkBackground . name ( ) ) ;
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri
, " fill-on-light-background " , colorOnLightBackground . name ( ) ) ;
, " fill-on-light-background " , colorOnLightBackground . name ( ) ) ;
groupHoldsInfo = true ;
groupHoldsInfo = true ;
}
}
}
}
if ( stroke & & ! stroke - > hasPressure ( ) )
if ( stroke & & ! stroke - > hasPressure ( ) )
{
{
strokeToSvgPolyline ( stroke , groupHoldsInfo ) ;
strokeToSvgPolyline ( stroke , groupHoldsInfo ) ;
//we can dequeue all polygons belonging to that stroke
//we can dequeue all polygons belonging to that stroke
foreach ( UBGraphicsPolygonItem * gi , stroke - > polygons ( ) )
foreach ( UBGraphicsPolygonItem * gi , stroke - > polygons ( ) )
{
{
items . removeOne ( gi ) ;
items . removeOne ( gi ) ;
}
continue ;
}
}
continue ;
}
}
if ( polygonItem - > isNominalLine ( ) )
polygonItemToSvgLine ( polygonItem , groupHoldsInfo ) ;
else
polygonItemToSvgPolygon ( polygonItem , groupHoldsInfo ) ;
continue ;
}
}
if ( openStroke )
if ( polygonItem - > isNominalLine ( ) )
{
polygonItemToSvgLine ( polygonItem , groupHoldsInfo ) ;
mXmlWriter . writeEndElement ( ) ; //g
else
groupHoldsInfo = false ;
polygonItemToSvgPolygon ( polygonItem , groupHoldsInfo ) ;
openStroke = 0 ;
}
// Is the item a picture?
continue ;
UBGraphicsPixmapItem * pixmapItem = qgraphicsitem_cast < UBGraphicsPixmapItem * > ( item ) ;
}
if ( pixmapItem & & pixmapItem - > isVisible ( ) )
{
pixmapItemToLinkedImage ( pixmapItem ) ;
continue ;
}
// Is the item a shape?
if ( openStroke )
UBGraphicsSvgItem * svgItem = qgraphicsitem_cast < UBGraphicsSvgItem * > ( item ) ;
{
if ( svgItem & & svgItem - > isVisible ( ) )
mXmlWriter . writeEndElement ( ) ; //g
{
groupHoldsInfo = false ;
svgItemToLinkedSvg ( svgItem ) ;
openStroke = 0 ;
continue ;
}
}
// Is the item a picture?
UBGraphicsPixmapItem * pixmapItem = qgraphicsitem_cast < UBGraphicsPixmapItem * > ( item ) ;
if ( pixmapItem & & pixmapItem - > isVisible ( ) )
{
pixmapItemToLinkedImage ( pixmapItem ) ;
continue ;
}
UBGraphicsMediaItem * mediaItem = qgraphicsitem_cast < UBGraphicsMediaItem * > ( item ) ;
// Is the item a shape?
UBGraphicsSvgItem * svgItem = qgraphicsitem_cast < UBGraphicsSvgItem * > ( item ) ;
if ( svgItem & & svgItem - > isVisible ( ) )
{
svgItemToLinkedSvg ( svgItem ) ;
continue ;
}
if ( mediaItem & & mediaItem - > isVisible ( ) )
UBGraphicsMediaItem * mediaItem = qgraphicsitem_cast < UBGraphicsMediaItem * > ( item ) ;
{
if ( UBGraphicsMediaItem : : mediaType_Video = = mediaItem - > getMediaType ( ) )
videoItemToLinkedVideo ( mediaItem ) ;
else
audioItemToLinkedAudio ( mediaItem ) ;
continue ;
}
// Is the item an app?
if ( mediaItem & & mediaItem - > isVisible ( ) )
UBGraphicsAppleWidgetItem * appleWidgetItem = qgraphicsitem_cast < UBGraphicsAppleWidgetItem * > ( item ) ;
{
if ( appleWidgetItem & & appleWidgetItem - > isVisible ( ) )
if ( UBGraphicsMediaItem : : mediaType_Video = = mediaItem - > getMediaType ( ) )
{
videoItemToLinkedVideo ( mediaItem ) ;
graphicsAppleWidgetToSvg ( appleWidgetItem ) ;
else
continue ;
audioItemToLinkedAudio ( mediaItem ) ;
}
continue ;
}
// Is the item a W3C ?
// Is the item an app ?
UBGraphicsW3CWidgetItem * w3c WidgetItem = qgraphicsitem_cast < UBGraphicsW3C WidgetItem * > ( item ) ;
UBGraphicsAppleWidgetItem * apple WidgetItem = qgraphicsitem_cast < UBGraphicsApple WidgetItem * > ( item ) ;
if ( w3cWidgetItem & & w3c WidgetItem- > isVisible ( ) )
if ( appleWidgetItem & & apple WidgetItem- > isVisible ( ) )
{
{
graphicsW3CWidgetToSvg ( w3c WidgetItem ) ;
graphicsAppleWidgetToSvg ( apple WidgetItem) ;
continue ;
continue ;
}
}
// Is the item a PDF ?
// Is the item a W3C ?
UBGraphicsPDFItem * pdf Item = qgraphicsitem_cast < UBGraphicsPDF Item * > ( item ) ;
UBGraphicsW3CWidgetItem * w3cWidget Item = qgraphicsitem_cast < UBGraphicsW3CWidget Item * > ( item ) ;
if ( pdfItem & & pdf Item- > isVisible ( ) )
if ( w3cWidgetItem & & w3cWidget Item- > isVisible ( ) )
{
{
pdfItemToLinkedPDF ( pdf Item ) ;
graphicsW3CWidgetToSvg ( w3cWidget Item) ;
continue ;
continue ;
}
}
// Is the item a text ?
// Is the item a PDF ?
UBGraphicsTextItem * text Item = qgraphicsitem_cast < UBGraphicsText Item * > ( item ) ;
UBGraphicsPDFItem * pdf Item = qgraphicsitem_cast < UBGraphicsPDF Item * > ( item ) ;
if ( textItem & & text Item- > isVisible ( ) )
if ( pdfItem & & pdf Item- > isVisible ( ) )
{
{
textItemToSvg ( text Item ) ;
pdfItemToLinkedPDF ( pdf Item) ;
continue ;
continue ;
}
}
// Is the item a curtain ?
// Is the item a text ?
UBGraphicsCurtainItem * curtain Item = qgraphicsitem_cast < UBGraphicsCurtain Item * > ( item ) ;
UBGraphicsTextItem * text Item = qgraphicsitem_cast < UBGraphicsText Item * > ( item ) ;
if ( curtainItem & & curtain Item- > isVisible ( ) )
if ( textItem & & text Item- > isVisible ( ) )
{
{
curtainItemToSvg ( curtain Item ) ;
textItemToSvg ( text Item) ;
continue ;
continue ;
}
}
// Is the item a ruler ?
// Is the item a curtain ?
UBGraphicsRuler * ruler = qgraphicsitem_cast < UBGraphicsRuler * > ( item ) ;
UBGraphicsCurtainItem * curtainItem = qgraphicsitem_cast < UBGraphicsCurtainItem * > ( item ) ;
if ( ruler & & ruler - > isVisible ( ) )
if ( curtainItem & & curtainItem - > isVisible ( ) )
{
{
rulerToSvg ( ruler ) ;
curtainItemToSvg ( curtainItem ) ;
continue ;
continue ;
}
}
// Is the item a cache ?
// Is the item a ruler ?
UBGraphicsCache * cache = qgraphicsitem_cast < UBGraphicsCache * > ( item ) ;
UBGraphicsRuler * ruler = qgraphicsitem_cast < UBGraphicsRuler * > ( item ) ;
if ( cache & & cache - > isVisible ( ) )
if ( ruler & & ruler - > isVisible ( ) )
{
{
cacheToSvg ( cache ) ;
rulerToSvg ( ruler ) ;
continue ;
continue ;
}
}
// Is the item a compass
// Is the item a cache?
UBGraphicsCompass * compass = qgraphicsitem_cast < UBGraphicsCompass * > ( item ) ;
UBGraphicsCache * cache = qgraphicsitem_cast < UBGraphicsCache * > ( item ) ;
if ( compass & & compass - > isVisible ( ) )
if ( cache & & cache - > isVisible ( ) )
{
{
compassToSvg ( compass ) ;
cacheToSvg ( cache ) ;
continue ;
continue ;
}
}
// Is the item a protractor?
// Is the item a compass
UBGraphicsProtractor * protractor = qgraphicsitem_cast < UBGraphicsProtractor * > ( item ) ;
UBGraphicsCompass * compass = qgraphicsitem_cast < UBGraphicsCompass * > ( item ) ;
if ( protractor & & protractor - > isVisible ( ) )
if ( compass & & compass - > isVisible ( ) )
{
{
protractorToSvg ( protractor ) ;
compassToSvg ( compass ) ;
continue ;
continue ;
}
}
// Is the item a triangle ?
// Is the item a protractor ?
UBGraphicsTriangle * triangle = qgraphicsitem_cast < UBGraphicsTriangle * > ( item ) ;
UBGraphicsProtractor * protractor = qgraphicsitem_cast < UBGraphicsProtractor * > ( item ) ;
if ( triangle & & triangle - > isVisible ( ) )
if ( protractor & & protractor - > isVisible ( ) )
{
{
triangleToSvg ( triangle ) ;
protractorToSvg ( protractor ) ;
continue ;
continue ;
}
}
// Is the item a group?
// Is the item a triangle?
UBGraphicsGroupContainerItem * groupItem = qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item ) ;
UBGraphicsTriangle * triangle = qgraphicsitem_cast < UBGraphicsTriangle * > ( item ) ;
if ( groupItem & & groupItem - > isVisible ( ) )
if ( triangle & & triangle - > isVisible ( ) )
{
{
persistGroupToDom ( groupItem , & groupRoot , & groupDomDocument ) ;
triangleToSvg ( triangle ) ;
continue ;
continue ;
}
}
}
if ( openStroke )
// Is the item a group?
UBGraphicsGroupContainerItem * groupItem = qgraphicsitem_cast < UBGraphicsGroupContainerItem * > ( item ) ;
if ( groupItem & & groupItem - > isVisible ( ) )
{
{
mXmlWriter . writeEndElement ( ) ;
persistGroupToDom ( groupItem , & groupRoot , & groupDomDocument ) ;
groupHoldsInfo = false ;
continue ;
openStroke = 0 ;
}
}
}
//writing group data
if ( openStroke )
if ( groupRoot . hasChildNodes ( ) ) {
{
mXmlWriter . writeStartElement ( tGroups ) ;
mXmlWriter . writeEndElement ( ) ;
QDomElement curElement = groupRoot . firstChildElement ( ) ;
groupHoldsInfo = false ;
while ( ! curElement . isNull ( ) ) {
openStroke = 0 ;
if ( curElement . hasAttribute ( aId ) ) {
}
mXmlWriter . writeStartElement ( curElement . tagName ( ) ) ;
mXmlWriter . writeAttribute ( aId , curElement . attribute ( aId ) ) ;
//writing group data
if ( curElement . hasAttribute ( " locked " ) ) {
if ( groupRoot . hasChildNodes ( ) ) {
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri , " locked " , curElement . attribute ( " locked " ) ) ;
mXmlWriter . writeStartElement ( tGroups ) ;
}
QDomElement curElement = groupRoot . firstChildElement ( ) ;
QDomElement curSubElement = curElement . firstChildElement ( ) ;
while ( ! curElement . isNull ( ) ) {
while ( ! curSubElement . isNull ( ) ) {
if ( curElement . hasAttribute ( aId ) ) {
if ( curSubElement . hasAttribute ( aId ) ) {
mXmlWriter . writeStartElement ( curElement . tagName ( ) ) ;
mXmlWriter . writeStartElement ( curSubElement . tagName ( ) ) ;
mXmlWriter . writeAttribute ( aId , curElement . attribute ( aId ) ) ;
mXmlWriter . writeAttribute ( aId , curSubElement . attribute ( aId ) ) ;
if ( curElement . hasAttribute ( " locked " ) ) {
mXmlWriter . writeEndElement ( ) ;
mXmlWriter . writeAttribute ( UBSettings : : uniboardDocumentNamespaceUri , " locked " , curElement . attribute ( " locked " ) ) ;
curSubElement = curSubElement . nextSiblingElement ( ) ;
}
}
QDomElement curSubElement = curElement . firstChildElement ( ) ;
while ( ! curSubElement . isNull ( ) ) {
if ( curSubElement . hasAttribute ( aId ) ) {
mXmlWriter . writeStartElement ( curSubElement . tagName ( ) ) ;
mXmlWriter . writeAttribute ( aId , curSubElement . attribute ( aId ) ) ;
mXmlWriter . writeEndElement ( ) ;
curSubElement = curSubElement . nextSiblingElement ( ) ;
}
}
mXmlWriter . writeEndElement ( ) ;
}
}
curElement = curElement . nextSiblingElement ( ) ;
mXmlWriter . writeEnd Element( ) ;
}
}
mXmlWriter . writeEndElement ( ) ;
curElement = curElement . nextSibling Element( ) ;
}
}
mXmlWriter . writeEndElement ( ) ;
}
mXmlWriter . writeEndDocument ( ) ;
mXmlWriter . writeEndDocument ( ) ;
QString fileName = mDocumentPath + UBFileSystemUtils : : digitFileFormat ( " /page%1.svg " , mPageIndex ) ;
QString fileName = mDocumentPath + UBFileSystemUtils : : digitFileFormat ( " /page%1.svg " , mPageIndex ) ;
QFile file ( fileName ) ;
QFile file ( fileName ) ;
if ( ! file . open ( QIODevice : : WriteOnly | QIODevice : : Truncate ) )
{
qCritical ( ) < < " cannot open " < < fileName < < " for writing ... " ;
return false ;
}
file . write ( buffer . data ( ) ) ;
file . flush ( ) ;
file . close ( ) ;
}
if ( ! file . open ( QIODevice : : WriteOnly | QIODevice : : Truncate ) )
else
{
{
qDebug ( ) < < " ignoring unmodified page " < < UBApplication : : boardController - > pageFromSceneIndex ( mPageIndex ) ;
qCritical ( ) < < " cannot open " < < fileName < < " for writing ... " ;
return false ;
}
}
file . write ( buffer . data ( ) ) ;
file . flush ( ) ;
file . close ( ) ;
return true ;
return true ;
}
}