Improved import from cff - elements from <g> section adds to a group.

Undo stack disabled ad scene loading because it is not needed there.
preferencesAboutTextFull
Aleksei Kanash 12 years ago
parent da8c496f3e
commit a0eb1fa8c5
  1. 73
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 4
      src/adaptors/UBCFFSubsetAdaptor.h
  3. 2
      src/adaptors/UBSvgSubsetAdaptor.cpp

@ -32,6 +32,7 @@
#include "domain/UBGraphicsTextItem.h" #include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsTextItemDelegate.h" #include "domain/UBGraphicsTextItemDelegate.h"
#include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsGroupContainerItem.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
@ -128,8 +129,9 @@ bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentP
return result; return result;
} }
UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content): UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content)
mProxy(proxy) : mProxy(proxy)
, mGSectionContainer(NULL)
{ {
int errorLine, errorColumn; int errorLine, errorColumn;
QString errorStr; QString errorStr;
@ -168,6 +170,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse()
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &element)
{ {
mGSectionContainer = new UBGraphicsGroupContainerItem();
QDomElement currentSvgElement = element.firstChildElement(); QDomElement currentSvgElement = element.firstChildElement();
while (!currentSvgElement.isNull()) { while (!currentSvgElement.isNull()) {
if (!parseSvgElement(currentSvgElement)) if (!parseSvgElement(currentSvgElement))
@ -176,6 +180,16 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &ele
currentSvgElement = currentSvgElement.nextSiblingElement(); currentSvgElement = currentSvgElement.nextSiblingElement();
} }
if (mGSectionContainer->childItems().count())
{
mCurrentScene->addGroup(mGSectionContainer);
}
else
{
delete mGSectionContainer;
mGSectionContainer = NULL;
}
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSwitchSection(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSwitchSection(const QDomElement &element)
@ -247,6 +261,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem
repositionSvgItem(svgItem, width, height, x1, y1, transform); repositionSvgItem(svgItem, width, height, x1, y1, transform);
hashSceneItem(element, svgItem); hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator; delete generator;
return true; return true;
@ -293,6 +312,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e
repositionSvgItem(svgItem, rx * 2, ry * 2, cx - 2*rx, cy+ry, transform); repositionSvgItem(svgItem, rx * 2, ry * 2, cx - 2*rx, cy+ry, transform);
hashSceneItem(element, svgItem); hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator; delete generator;
return true; return true;
@ -375,6 +399,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolygon(const QDomElement &e
repositionSvgItem(svgItem, width +strokeWidth, height + strokeWidth, x1 - strokeWidth/2 + transform.m31(), y1 + strokeWidth/2 + transform.m32(), transform); repositionSvgItem(svgItem, width +strokeWidth, height + strokeWidth, x1 - strokeWidth/2 + transform.m31(), y1 + strokeWidth/2 + transform.m32(), transform);
hashSceneItem(element, svgItem); hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator; delete generator;
return true; return true;
@ -454,6 +483,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPolyline(const QDomElement &
repositionSvgItem(svgItem, width +strokeWidth, height + strokeWidth, x1 + transform.m31() - strokeWidth/2, y1 + transform.m32() + strokeWidth/2, transform); repositionSvgItem(svgItem, width +strokeWidth, height + strokeWidth, x1 + transform.m31() - strokeWidth/2, y1 + transform.m32() + strokeWidth/2, transform);
hashSceneItem(element, svgItem); hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator; delete generator;
return true; return true;
@ -593,6 +627,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgText(const QDomElement &elem
repositionSvgItem(svgItem, width, height, x + transform.m31(), y + transform.m32(), transform); repositionSvgItem(svgItem, width, height, x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, svgItem); hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator; delete generator;
return true; return true;
} }
@ -712,6 +751,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement &
repositionSvgItem(svgItem, width, height, x + transform.m31(), y + transform.m32(), transform); repositionSvgItem(svgItem, width, height, x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, svgItem); hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element)
@ -749,6 +793,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele
repositionSvgItem(pixItem, width, height, x + transform.m31(), y + transform.m32(), transform); repositionSvgItem(pixItem, width, height, x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, pixItem); hashSceneItem(element, pixItem);
if (mGSectionContainer)
{
addItemToGSection(pixItem);
}
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &element)
@ -791,6 +840,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &ele
repositionSvgItem(flashItem, width, height, x + transform.m31(), y + transform.m32(), transform); repositionSvgItem(flashItem, width, height, x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, flashItem); hashSceneItem(element, flashItem);
if (mGSectionContainer)
{
addItemToGSection(flashItem);
}
return true; return true;
} }
@ -829,6 +883,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgAudio(const QDomElement &ele
repositionSvgItem(audioItem, audioItem->boundingRect().width(), audioItem->boundingRect().height(), x + transform.m31(), y + transform.m32(), transform); repositionSvgItem(audioItem, audioItem->boundingRect().width(), audioItem->boundingRect().height(), x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, audioItem); hashSceneItem(element, audioItem);
if (mGSectionContainer)
{
addItemToGSection(audioItem);
}
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &element)
@ -867,6 +926,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &ele
repositionSvgItem(videoItem, videoItem->boundingRect().width(), videoItem->boundingRect().height(), x + transform.m31(), y + transform.m32(), transform); repositionSvgItem(videoItem, videoItem->boundingRect().width(), videoItem->boundingRect().height(), x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, videoItem); hashSceneItem(element, videoItem);
if (mGSectionContainer)
{
addItemToGSection(videoItem);
}
return true; return true;
} }
@ -877,6 +941,11 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSectionAttr(const QDomElemen
svgSection.attribute(aHeight).toInt()); svgSection.attribute(aHeight).toInt());
} }
void UBCFFSubsetAdaptor::UBCFFSubsetReader::addItemToGSection(QGraphicsItem *item)
{
mGSectionContainer->addToGroup(item);
}
void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(const QDomElement &element, UBGraphicsItem *item) void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(const QDomElement &element, UBGraphicsItem *item)
{ {
// adding element pointer to hash to refer if needed // adding element pointer to hash to refer if needed

@ -35,6 +35,7 @@ class QGraphicsItem;
class QTextBlockFormat; class QTextBlockFormat;
class QTextCharFormat; class QTextCharFormat;
class QTextCursor; class QTextCursor;
class UBGraphicsStrokesGroup;
class UBCFFSubsetAdaptor class UBCFFSubsetAdaptor
@ -66,6 +67,8 @@ private:
QPointF mViewBoxCenter; QPointF mViewBoxCenter;
QSize mSize; QSize mSize;
QPointF mShiftVector; QPointF mShiftVector;
bool mSvgGSectionIsOpened;
UBGraphicsGroupContainerItem *mGSectionContainer;
private: private:
QDomDocument mDOMdoc; QDomDocument mDOMdoc;
@ -73,6 +76,7 @@ private:
QHash<QString, UBGraphicsItem*> persistedItems; QHash<QString, UBGraphicsItem*> persistedItems;
QDir mTmpFlashDir; QDir mTmpFlashDir;
void addItemToGSection(QGraphicsItem *item);
bool hashElements(); bool hashElements();
void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup); void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup);

@ -396,6 +396,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
if (!mScene) if (!mScene)
{ {
mScene = new UBGraphicsScene(mProxy); mScene = new UBGraphicsScene(mProxy);
mScene->setURStackEnable(false);
} }
// introduced in UB 4.2 // introduced in UB 4.2
@ -1013,6 +1014,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
delete annotationGroup; delete annotationGroup;
} }
mScene->setURStackEnable(true);
return mScene; return mScene;
} }

Loading…
Cancel
Save