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/UBGraphicsTextItemDelegate.h"
#include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsGroupContainerItem.h"
#include "frameworks/UBFileSystemUtils.h"
@ -128,8 +129,9 @@ bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentP
return result;
}
UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content):
mProxy(proxy)
UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content)
: mProxy(proxy)
, mGSectionContainer(NULL)
{
int errorLine, errorColumn;
QString errorStr;
@ -168,6 +170,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse()
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &element)
{
mGSectionContainer = new UBGraphicsGroupContainerItem();
QDomElement currentSvgElement = element.firstChildElement();
while (!currentSvgElement.isNull()) {
if (!parseSvgElement(currentSvgElement))
@ -176,6 +180,16 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseGSection(const QDomElement &ele
currentSvgElement = currentSvgElement.nextSiblingElement();
}
if (mGSectionContainer->childItems().count())
{
mCurrentScene->addGroup(mGSectionContainer);
}
else
{
delete mGSectionContainer;
mGSectionContainer = NULL;
}
return true;
}
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);
hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator;
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);
hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator;
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);
hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator;
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);
hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator;
return true;
@ -593,6 +627,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgText(const QDomElement &elem
repositionSvgItem(svgItem, width, height, x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
delete generator;
return true;
}
@ -712,6 +751,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement &
repositionSvgItem(svgItem, width, height, x + transform.m31(), y + transform.m32(), transform);
hashSceneItem(element, svgItem);
if (mGSectionContainer)
{
addItemToGSection(svgItem);
}
return true;
}
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);
hashSceneItem(element, pixItem);
if (mGSectionContainer)
{
addItemToGSection(pixItem);
}
return true;
}
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);
hashSceneItem(element, flashItem);
if (mGSectionContainer)
{
addItemToGSection(flashItem);
}
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);
hashSceneItem(element, audioItem);
if (mGSectionContainer)
{
addItemToGSection(audioItem);
}
return true;
}
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);
hashSceneItem(element, videoItem);
if (mGSectionContainer)
{
addItemToGSection(videoItem);
}
return true;
}
@ -877,6 +941,11 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSectionAttr(const QDomElemen
svgSection.attribute(aHeight).toInt());
}
void UBCFFSubsetAdaptor::UBCFFSubsetReader::addItemToGSection(QGraphicsItem *item)
{
mGSectionContainer->addToGroup(item);
}
void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(const QDomElement &element, UBGraphicsItem *item)
{
// adding element pointer to hash to refer if needed

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

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

Loading…
Cancel
Save