From 9aa3027c51988442f8d29bfd92fa4187ad7acbff Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Mon, 31 Oct 2011 17:12:38 +0200 Subject: [PATCH 1/5] implemented delegate() function for graphics objects --- src/adaptors/UBCFFSubsetAdaptor.cpp | 19 +++++++++---------- src/adaptors/UBCFFSubsetAdaptor.h | 5 +++-- src/domain/UBGraphicsAudioItem.h | 1 + src/domain/UBGraphicsItemDelegate.h | 16 ++++++++-------- src/domain/UBGraphicsPDFItem.h | 3 ++- src/domain/UBGraphicsPixmapItem.h | 7 +++++-- src/domain/UBGraphicsProxyWidget.h | 4 ++-- src/domain/UBGraphicsSvgItem.h | 3 ++- src/domain/UBGraphicsTextItem.cpp | 1 - src/domain/UBGraphicsTextItem.h | 3 ++- src/domain/UBGraphicsVideoItem.h | 1 + src/domain/UBItem.h | 25 ++++++++++++++----------- src/tools/UBGraphicsCurtainItem.cpp | 1 - src/tools/UBGraphicsCurtainItem.h | 2 +- 14 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 2661f667..82dda974 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -818,8 +818,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele } // repositionSvgItem(svgItem, rx * 2 + 10, ry * 2 + 10, cx - rx - 5, cy - ry -5, hastransform, transform); repositionPixmapItem(pixItem, width, height, x, y, hastransform, transform); -// hashSceneItem(element, pixItem->); - + hashSceneItem(element, pixItem); + pixItem->Delegate()->lock(true); return true; } @@ -852,13 +852,13 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGroup(QDomNode *group) return true; } -//void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(QDomNode &element, UBGraphicsItemDelegate *item) -//{ -//// adding element pointer to hash to refer if needed -// QString key = element.attribute(aId); -// if (!key.isNull()) -// persistedItems.insert(key, item); -//} +void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(const QDomElement &element, UBGraphicsItem *item) +{ +// adding element pointer to hash to refer if needed + QString key = element.attribute(aId); + if (!key.isNull()) + persistedItems.insert(key, item); +} bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &parent) { @@ -868,7 +868,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &p return false; } - if (tagName == tRect && !parseSvgRect(parent)) return false; else if (tagName == tEllipse && !parseSvgEllipse(parent)) return false; else if (tagName == tPolygon && !parseSvgPolygon(parent)) return false; diff --git a/src/adaptors/UBCFFSubsetAdaptor.h b/src/adaptors/UBCFFSubsetAdaptor.h index dcddefdd..5bb69413 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.h +++ b/src/adaptors/UBCFFSubsetAdaptor.h @@ -30,6 +30,7 @@ class UBGraphicsPixmapItem; class UBGraphicsItemDelegate; class QTransform; class QPainter; +class UBGraphicsItem; struct IwbExt { IwbExt() {;} @@ -87,7 +88,7 @@ private: QDomDocument mDOMdoc; QDomNode mCurrentDOMElement; QHash iwbExtProperties; - QHash persistedItems; + QHash persistedItems; bool hashElements(); void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup); @@ -109,7 +110,7 @@ private: inline bool parseSvgImage(const QDomElement &element); // inline bool parseSvgTSpan(const QDomElement) bool parseIwbGroup(QDomNode *element); - inline void hashSceneItem(QDomNode *element, UBGraphicsItemDelegate *item); + inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item); // to kill void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor, diff --git a/src/domain/UBGraphicsAudioItem.h b/src/domain/UBGraphicsAudioItem.h index a9f06bbb..337ba99d 100644 --- a/src/domain/UBGraphicsAudioItem.h +++ b/src/domain/UBGraphicsAudioItem.h @@ -37,6 +37,7 @@ public: } virtual UBItem* deepCopy () const; + virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} private slots: diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index fcab9f8d..eefa8b1e 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -30,7 +30,7 @@ class UBGraphicsWidgetItem; class DelegateButton: public QGraphicsSvgItem { - Q_OBJECT; + Q_OBJECT public: DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0) @@ -90,7 +90,7 @@ class DelegateButton: public QGraphicsSvgItem class UBGraphicsItemDelegate : public QObject { - Q_OBJECT; + Q_OBJECT public: UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent = 0, bool respectRatio = true, bool canRotate = false); @@ -129,17 +129,19 @@ class UBGraphicsItemDelegate : public QObject void setMimeData(QMimeData* mimeData); signals: - void showOnDisplayChanged(bool shown); void lockChanged(bool locked); public slots: - virtual void remove(bool canUndo = true); void showMenu(); + virtual void showHide(bool show); + virtual void lock(bool lock); + virtual void duplicate(); + protected: - virtual void buildButtons() {}; + virtual void buildButtons() {;} virtual void decorateMenu(QMenu *menu); virtual void updateMenuActionState(); @@ -164,9 +166,7 @@ class UBGraphicsItemDelegate : public QObject protected slots: virtual void gotoContentSource(bool checked); - virtual void showHide(bool show); - virtual void lock(bool lock); - virtual void duplicate(); + private: diff --git a/src/domain/UBGraphicsPDFItem.h b/src/domain/UBGraphicsPDFItem.h index b0c837e1..426361cf 100644 --- a/src/domain/UBGraphicsPDFItem.h +++ b/src/domain/UBGraphicsPDFItem.h @@ -48,6 +48,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual void remove(); virtual UBGraphicsPixmapItem* toPixmapItem() const; + virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} protected: @@ -57,7 +58,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - UBGraphicsItemDelegate* mDelegate; +// UBGraphicsItemDelegate* mDelegate; }; #endif /* UBGRAPHICSPDFITEM_H_ */ diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 32c04f67..053ce0e5 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -45,11 +45,13 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public virtual void remove(); - Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity); + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) void setOpacity(qreal op); qreal opacity() const; + virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -60,7 +62,8 @@ protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - UBGraphicsItemDelegate* mDelegate; + +// UBGraphicsItemDelegate* mDelegate; }; diff --git a/src/domain/UBGraphicsProxyWidget.h b/src/domain/UBGraphicsProxyWidget.h index adf0737f..14739946 100644 --- a/src/domain/UBGraphicsProxyWidget.h +++ b/src/domain/UBGraphicsProxyWidget.h @@ -41,7 +41,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public virtual void remove(); - UBGraphicsItemDelegate* delegate (){ return mDelegate;} + virtual UBGraphicsItemDelegate* delegate() const { return mDelegate;} protected: @@ -53,7 +53,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - UBGraphicsItemDelegate* mDelegate; +// UBGraphicsItemDelegate* mDelegate; }; #endif /* UBGRAPHICSPROXYWIDGET_H_ */ diff --git a/src/domain/UBGraphicsSvgItem.h b/src/domain/UBGraphicsSvgItem.h index 6b64a901..eb238cf4 100644 --- a/src/domain/UBGraphicsSvgItem.h +++ b/src/domain/UBGraphicsSvgItem.h @@ -59,6 +59,7 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi virtual void remove(); virtual UBGraphicsPixmapItem* toPixmapItem() const; + virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} protected: @@ -70,7 +71,7 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - UBGraphicsItemDelegate* mDelegate; +// UBGraphicsItemDelegate* mDelegate; QByteArray mFileData; }; diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 7aa1da1c..b2a5536f 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -30,7 +30,6 @@ QColor UBGraphicsTextItem::lastUsedTextColor; UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) : QGraphicsTextItem(parent) - , mDelegate(0) , mMultiClickState(0) , mLastMousePressTime(QTime::currentTime()) { diff --git a/src/domain/UBGraphicsTextItem.h b/src/domain/UBGraphicsTextItem.h index 2480bece..b9f08f5d 100644 --- a/src/domain/UBGraphicsTextItem.h +++ b/src/domain/UBGraphicsTextItem.h @@ -78,6 +78,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes { mColorOnLightBackground = pColorOnLightBackground; } + virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} signals: void textUndoCommandAdded(UBGraphicsTextItem *textItem); @@ -96,7 +97,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); private: - UBGraphicsItemDelegate *mDelegate; +// UBGraphicsItemDelegate *mDelegate; qreal mTextHeight; int mMultiClickState; diff --git a/src/domain/UBGraphicsVideoItem.h b/src/domain/UBGraphicsVideoItem.h index 73c30a90..52e8b0aa 100644 --- a/src/domain/UBGraphicsVideoItem.h +++ b/src/domain/UBGraphicsVideoItem.h @@ -40,6 +40,7 @@ public: { return mVideoWidget; } + virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} public slots: diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 5cd14d13..8fcbb6c8 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -16,6 +16,7 @@ #define UBITEM_H #include +#include "domain/UBGraphicsItemDelegate.h" class UBGraphicsScene; @@ -84,21 +85,23 @@ class UBItem class UBGraphicsItem { - protected: +protected: - UBGraphicsItem() - { - // NOOP - } + UBGraphicsItem() : mDelegate(0) + { + // NOOP + } + UBGraphicsItemDelegate* mDelegate; - virtual ~UBGraphicsItem() - { - // NOOP - } + virtual ~UBGraphicsItem() + { + // NOOP + } - public: +public: + virtual UBGraphicsItemDelegate *Delegate() const {return 0;} + virtual void remove() = 0; - virtual void remove() = 0; }; #endif // UBITEM_H diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index 968a8c32..118b92f2 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -36,7 +36,6 @@ const QColor UBGraphicsCurtainItem::sDarkBackgroundOpaqueControlColor = QColor(6 UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent) : QGraphicsRectItem(parent) - , mDelegate(0) { mDelegate = new UBGraphicsCurtainItemDelegate(this, 0); mDelegate->init(); diff --git a/src/tools/UBGraphicsCurtainItem.h b/src/tools/UBGraphicsCurtainItem.h index f5b90bf6..446c7fa8 100644 --- a/src/tools/UBGraphicsCurtainItem.h +++ b/src/tools/UBGraphicsCurtainItem.h @@ -65,7 +65,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U QColor drawColor() const; QColor opaqueControlColor() const; - UBGraphicsItemDelegate* mDelegate; +// UBGraphicsItemDelegate* mDelegate; static const QColor sDrawColor; static const QColor sDarkBackgroundDrawColor; From fc593b1ecea98df3add99aa4f903ebb111e2f79b Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Tue, 1 Nov 2011 10:48:58 +0200 Subject: [PATCH 2/5] Have pure virtual function on UBGraphicsItems --- src/adaptors/UBCFFSubsetAdaptor.cpp | 3 --- src/domain/UBGraphicsProxyWidget.h | 2 +- src/domain/UBGraphicsWidgetItem.h | 10 +++++++--- src/domain/UBGraphicsWidgetItemDelegate.h | 2 +- src/domain/UBItem.h | 2 +- src/tools/UBGraphicsCurtainItem.h | 3 ++- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 82dda974..d0c531d0 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -917,8 +917,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() } else if (currentSvg.tagName() == tPageset){ parseSvgPageset(currentSvg); } - - // while (!mReader.atEnd()) // { // mReader.readNext(); @@ -942,7 +940,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() // } // if (!mReader.error() == QXmlStreamReader::NoError) // UBApplication::showMessage(mReader.errorString()); - return true; } diff --git a/src/domain/UBGraphicsProxyWidget.h b/src/domain/UBGraphicsProxyWidget.h index 14739946..3b7fea29 100644 --- a/src/domain/UBGraphicsProxyWidget.h +++ b/src/domain/UBGraphicsProxyWidget.h @@ -41,7 +41,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public virtual void remove(); - virtual UBGraphicsItemDelegate* delegate() const { return mDelegate;} + virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} protected: diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 465ae4c8..37386df6 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -29,10 +29,12 @@ class UBGraphicsScene; class UBAbstractWidget; class UBW3CWidgetAPI; class UBW3CWidgetWebStorageAPI; +class UBGraphiscItem; +class UBGraphiscItemDelegate; class UBGraphicsWidgetItem : public UBGraphicsProxyWidget { - Q_OBJECT; + Q_OBJECT public: UBGraphicsWidgetItem(QGraphicsItem *parent = 0, int widgetType = 0); @@ -60,11 +62,13 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget QMap datastoreEntries() const; void removeDatastoreEntry(const QString& key); void removeAllDatastoreEntries(); + virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} virtual void remove(); void removeScript(); + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -89,7 +93,7 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem { - Q_OBJECT; + Q_OBJECT public: UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0); @@ -109,7 +113,7 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem { - Q_OBJECT; + Q_OBJECT public: UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0, int widgetType = UBGraphicsItemType::W3CWidgetItemType); diff --git a/src/domain/UBGraphicsWidgetItemDelegate.h b/src/domain/UBGraphicsWidgetItemDelegate.h index 75d7ccdb..0e379137 100644 --- a/src/domain/UBGraphicsWidgetItemDelegate.h +++ b/src/domain/UBGraphicsWidgetItemDelegate.h @@ -24,7 +24,7 @@ class UBGraphicsWidgetItemDelegate : public UBGraphicsItemDelegate { - Q_OBJECT; + Q_OBJECT public: UBGraphicsWidgetItemDelegate(UBGraphicsWidgetItem* pDelegated, int widgetType = 0); diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 8fcbb6c8..58f61867 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -99,7 +99,7 @@ protected: } public: - virtual UBGraphicsItemDelegate *Delegate() const {return 0;} + virtual UBGraphicsItemDelegate *Delegate() const = 0; virtual void remove() = 0; }; diff --git a/src/tools/UBGraphicsCurtainItem.h b/src/tools/UBGraphicsCurtainItem.h index 446c7fa8..3b8fd57b 100644 --- a/src/tools/UBGraphicsCurtainItem.h +++ b/src/tools/UBGraphicsCurtainItem.h @@ -28,7 +28,7 @@ class UBGraphicsItemDelegate; class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public UBItem, public UBGraphicsItem { - Q_OBJECT; + Q_OBJECT public: UBGraphicsCurtainItem(QGraphicsItem* parent = 0); @@ -47,6 +47,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U //TODO UB 4.x not nice ... void triggerRemovedSignal(); + virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} signals: From deae689f9ac9f263b5f5d8991db7fc357f9d15b6 Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Thu, 3 Nov 2011 14:50:46 +0200 Subject: [PATCH 3/5] new changes --- src/adaptors/UBCFFSubsetAdaptor.cpp | 1301 +++++++------------------ src/adaptors/UBCFFSubsetAdaptor.h | 77 +- src/domain/UBGraphicsItemDelegate.cpp | 2 + src/domain/UBGraphicsItemDelegate.h | 2 + src/domain/UBGraphicsScene.cpp | 2 - src/domain/UBW3CWidget.cpp | 1 - 6 files changed, 351 insertions(+), 1034 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index d0c531d0..40a20ba1 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -12,12 +12,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include #include #include - #include "core/UBPersistenceManager.h" #include "document/UBDocumentProxy.h" #include "domain/UBItem.h" @@ -26,6 +24,12 @@ #include "domain/UBGraphicsTextItem.h" #include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsPixmapItem.h" +#include "domain/UBGraphicsVideoItem.h" +#include "domain/UBGraphicsAudioItem.h" +#include "domain/UBGraphicsWidgetItem.h" +#include "domain/UBW3CWidget.h" + +#include "frameworks/UBFileSystemUtils.h" #include "UBCFFSubsetAdaptor.h" #include "UBMetadataDcSubsetAdaptor.h" @@ -35,7 +39,7 @@ #include "core/UBApplication.h" #include "QFile" -#include "QDomDocument" +#include //enum of xmlparse status @@ -57,6 +61,10 @@ static QString tTextarea = "textarea"; static QString tTspan = "tspan"; static QString tBreak = "tbreak"; static QString tImage = "image"; +static QString tFlash = "flash"; +static QString tAudio = "audio"; +static QString tVideo = "video"; + //attribute names definition static QString aFill = "fill"; @@ -85,6 +93,8 @@ static QString iwbNS = "http://www.becta.org.uk/iwb"; static QString aId = "id"; static QString aRef = "ref"; static QString aHref = "href"; +static QString aBackground = "background"; +static QString aLocked = "locked"; //attributes part names static QString apRotate = "rotate"; @@ -92,115 +102,7 @@ static QString apTranslate = "translate"; UBCFFSubsetAdaptor::UBCFFSubsetAdaptor() -{ - -} - -void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSiblingIwbElements(QDomElement *parent, QDomElement *topGroup) { - - QDomElement curExt = parent->firstChildElement(tElement); - while (!curExt.isNull()) { - if (curExt.namespaceURI() != iwbNS) - continue; - QHash::iterator iSvgElement = iwbExtProperties.find(curExt.attribute(aRef)); - if (iSvgElement != iwbExtProperties.end()) { - IwbExt &svgElement = *iSvgElement; - svgElement.extAttr.push_back(curExt); - if (topGroup) - svgElement.group = *topGroup; - } - curExt = curExt.nextSiblingElement(tElement); - } -} - -void UBCFFSubsetAdaptor::UBCFFSubsetReader::addExtentionsToHash(QDomElement *parent, QDomElement *topGroup) -{ - //add top level elements - if(*parent == mDOMdoc.documentElement()) { - hashSiblingIwbElements(parent); - } else - hashSiblingIwbElements(parent, topGroup); - - //add iwb groups if needed - QDomElement curGroup = parent->firstChildElement(tGroup); - while (!curGroup.isNull()) { - if (curGroup.namespaceURI() != iwbNS) - continue; - if(*parent == mDOMdoc.documentElement()) { - topGroup = &curGroup; - } - if (curGroup.hasChildNodes()) { - addExtentionsToHash(&curGroup, topGroup); - } - curGroup = curGroup.nextSiblingElement(tGroup); - } -} - -void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSvg(QDomNode *parent, QString prefix) -{ - QDomNode n = parent->firstChild(); - while (!n.isNull()) { - QDomElement e = n.toElement(); - QString id = e.attribute(aId); - if(!id.isNull()) { - iwbExtProperties.insert(id, IwbExt(e)); - qDebug() << prefix + e.prefix() + ":" + e.tagName(); - } - if (n.hasChildNodes()) { - hashSvg(&n, QString("| %1").arg(prefix)); - } - n = n.nextSibling(); - } -} - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::hashElements() -{ - bool result = true; - - QDomElement svgSection = mDOMdoc.elementsByTagNameNS(svgNS, tSvg).at(0).toElement(); - if (svgSection.isNull()) { - qDebug("\"svg:svg\" section not found maybe invalid document"); - result = false; - } - hashSvg(&svgSection); - - QDomElement parElement = mDOMdoc.documentElement(); - if (parElement.isNull()) { - qDebug("invalid pass paramentr maybe invalid document"); - result = false; - } - - // Adding iwb extentions to hash table crossing elements and groups using recursive descent - addExtentionsToHash(&parElement, 0); - -// int i = 0; -// foreach (IwbExt cur, iwbExtProperties) { -// QString elem = cur.element.toElement().attribute(aId); -// QString tagName = cur.element.toElement().tagName(); -// QString gr = !cur.group.isNull() -// ? i++, " is group\n-------------\n" + QString::number(i) -// + cur.group.toElement().tagName() -// + (cur.group.toElement().hasChildNodes() ? "true" : "false") -// : ""; -//// QString attr = !cur.extAttr.isEmpty() ? cur.extAttr.first().toElement().attribute(aRef) : ""; -//// if (cur.group) { -//// *(cur.group); -//// } -// qDebug() << "element" + elem + "tag" + tagName + gr; -// if (!gr.isNull()) { - -// mDOMdoc.documentElement().removeChild(cur.group); -// } -// } -// QDomNode n = mDOMdoc.documentElement().firstChild(); -// while (!n.isNull()) { -// qDebug() << "new dom tags"<< n.toElement().tagName(); -// n = n.nextSibling(); -// } - - - return result; -} +{} bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument) { @@ -224,7 +126,7 @@ bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentP } UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content): - mReader(content), mProxy(proxy), currentState(NONE) + mProxy(proxy) { int errorLine, errorColumn; QString errorStr; @@ -235,11 +137,6 @@ UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, qDebug() << "well parsed to DOM"; pwdContent = QFileInfo(content->fileName()).dir().absolutePath(); } -// QFile tfile("/home/ilia/Documents/tmp/2/out.xml"); -// tfile.open(QIODevice::ReadWr ite | QIODevice::Text); -// QTextStream out(&tfile); -// out << content; -// tfile.close(); qDebug() << "tmp path is" << pwdContent; } @@ -248,9 +145,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse() UBMetadataDcSubsetAdaptor::persist(mProxy); mIndent = ""; - if (!getTempFileName()) + if (!getTempFileName() || !createTempFlashPath()) return false; + if (mDOMdoc.isNull()) return false; @@ -261,24 +159,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse() if (QFile::exists(mTempFilePath)) QFile::remove(mTempFilePath); - return result; -} - -int UBCFFSubsetAdaptor::UBCFFSubsetReader::PopState() -{ - if (stateStack.count() == 0) - currentState = NONE; - else - currentState = stateStack.pop(); - - return currentState; -} +// if (mTmpFlashDir.exists()) +// UBFileSystemUtils::deleteDir(mTmpFlashDir.path()); -void UBCFFSubsetAdaptor::UBCFFSubsetReader::PushState(int state) -{ - if (currentState != NONE) - stateStack.push(currentState); - currentState = state; + return result; } bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &element) @@ -722,7 +606,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement & int fontWeight = QFont::Normal; int textAlign = Qt::AlignLeft; QTransform fontTransform; - parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); + parseTextAttributes(element, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); QSvgGenerator *generator = createSvgGenerator(width, height); QPainter painter; @@ -800,7 +684,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele qDebug() << "can't load file" << pwdContent + "/" + itemRefPath << "maybe file corrupted"; return false; } else { - qDebug() << "size of file" << itemRefPath << QFileInfo(itemRefPath).size(); +// qDebug() << "size of file" << itemRefPath << QFileInfo(itemRefPath).size(); } pix.load(imagePath); if (pix.isNull()) { @@ -816,48 +700,114 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele transform = transformFromString(textTransform); hastransform = true; } -// repositionSvgItem(svgItem, rx * 2 + 10, ry * 2 + 10, cx - rx - 5, cy - ry -5, hastransform, transform); - repositionPixmapItem(pixItem, width, height, x, y, hastransform, transform); + repositionSvgItem(pixItem, width, height, x - 5, y - 5, hastransform, transform); hashSceneItem(element, pixItem); - pixItem->Delegate()->lock(true); + + return true; +} +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &element) +{ + QString itemRefPath = element.attribute(aHref); + + qreal x = element.attribute(aX).toDouble(); + qreal y = element.attribute(aY).toDouble(); + qreal width = element.attribute(aWidth).toDouble(); + qreal height = element.attribute(aHeight).toDouble(); + + QUrl urlPath; + QString flashPath; + if (!itemRefPath.isNull()) { + flashPath = pwdContent + "/" + itemRefPath; + if (!QFile::exists(flashPath)) { + qDebug() << "can't load file" << pwdContent + "/" + itemRefPath << "maybe file corrupted"; + return false; + } + urlPath = QUrl::fromLocalFile(flashPath); + } + QDir tmpFlashDir(mTmpFlashDir); + if (!tmpFlashDir.exists()) { + qDebug() << "Can't create temporary directory to put flash"; + return false; + } + + QString flashUrl = UBW3CWidget::createNPAPIWrapperInDir(flashPath, tmpFlashDir, "application/x-shockwave-flash"); + UBGraphicsWidgetItem *flashItem = mCurrentScene->addW3CWidget(QUrl::fromLocalFile(flashUrl)); + flashItem->setSourceUrl(urlPath); + + QTransform transform; + QString textTransform = element.attribute(aTransform); + bool hastransform = false; + if (!textTransform.isNull()) { + transform = transformFromString(textTransform); + hastransform = true; + } + repositionSvgItem(flashItem, width, height, x - 5, y - 5, true, transform); + hashSceneItem(element, flashItem); + return true; } -void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSectionAttr(const QDomElement &svgSection) +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgAudio(const QDomElement &element) { - getViewBoxDimenstions(svgSection.attribute(aViewbox)); - mSize = QSize(svgSection.attribute(aWidth).toInt(), - svgSection.attribute(aHeight).toInt()); + return true; } - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGroup(QDomNode *group) +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &element) { - QDomElement curGroupPtr = group->firstChildElement(); - - while (!curGroupPtr.isNull()) { - if (curGroupPtr.namespaceURI() != iwbNS) - continue; - if (curGroupPtr.hasChildNodes() && curGroupPtr.toElement().tagName() == tGroup) { - parseIwbGroup(&curGroupPtr); - } else if (curGroupPtr.toElement().tagName() == tElement) { - QHash::iterator iSvgElementExt = iwbExtProperties.find(curGroupPtr.attribute(aRef)); - if (iSvgElementExt != iwbExtProperties.end()) { - IwbExt &svgElementExt = *iSvgElementExt; - QDomNode &svgElement = svgElementExt.element; - svgElement.parentNode().removeChild(svgElement); - } + QString itemRefPath = element.attribute(aHref); + if (itemRefPath.startsWith(tFlash + "/") && itemRefPath.endsWith(".swf")) { + if (parseSvgFlash(element)) return true; + else return false; + } + + qreal x = element.attribute(aX).toDouble(); + qreal y = element.attribute(aY).toDouble(); + qreal width = element.attribute(aWidth).toDouble(); + qreal height = element.attribute(aHeight).toDouble(); + + QUrl urlPath; + if (!itemRefPath.isNull()) { + QString videoPath = pwdContent + "/" + itemRefPath; + if (!QFile::exists(videoPath)) { + qDebug() << "can't load file" << pwdContent + "/" + itemRefPath << "maybe file corrupted"; + return false; } - curGroupPtr = curGroupPtr.nextSiblingElement(tElement); + urlPath = QUrl::fromLocalFile(videoPath); + } + + UBGraphicsVideoItem *videoItem = mCurrentScene->addVideo(urlPath, false); + QTransform transform; + QString textTransform = element.attribute(aTransform); + bool hastransform = false; + if (!textTransform.isNull()) { + transform = transformFromString(textTransform); + hastransform = true; } + repositionSvgItem(videoItem, width, height, x - 5, y - 5, hastransform, transform); + hashSceneItem(element, videoItem); + return true; } +void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSectionAttr(const QDomElement &svgSection) +{ + getViewBoxDimenstions(svgSection.attribute(aViewbox)); + mSize = QSize(svgSection.attribute(aWidth).toInt(), + svgSection.attribute(aHeight).toInt()); +} + void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(const QDomElement &element, UBGraphicsItem *item) { // adding element pointer to hash to refer if needed QString key = element.attribute(aId); - if (!key.isNull()) + if (!key.isNull()) { persistedItems.insert(key, item); + + QHash::iterator iter; + iter = persistedItems.find(key); + UBGraphicsItem *itered = *iter; + if (key == "background") + itered->Delegate()->lock(true); + } } bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &parent) @@ -875,6 +825,9 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &p else if (tagName == tText && !parseSvgText(parent)) return false; else if (tagName == tTextarea && !parseSvgTextarea(parent)) return false; else if (tagName == tImage && !parseSvgImage(parent)) return false; + else if (tagName == tFlash && !parseSvgFlash(parent)) return false; + else if (tagName == tAudio && !parseSvgAudio(parent)) return false; + else if (tagName == tVideo && !parseSvgVideo(parent)) return false; return true; } @@ -903,212 +856,97 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPageset(const QDomElement &p return true; } -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta(const QDomElement &element) { - if (!hashElements()) return false; //hashing all elements having id attribute - - QDomElement svgSection = mDOMdoc.elementsByTagNameNS(svgNS, tSvg).at(0).toElement(); - parseSvgSectionAttr(svgSection); - - QDomElement currentSvg = svgSection.firstChildElement(); + if (element.namespaceURI() != iwbNS) { + qDebug() << "incorrect meta namespace, incorrect document"; + return false; + } - if (currentSvg.tagName() != tPageset) { - parseSvgPage(svgSection); - } else if (currentSvg.tagName() == tPageset){ - parseSvgPageset(currentSvg); - } -// while (!mReader.atEnd()) -// { -// mReader.readNext(); -// if (mReader.isStartElement()) -// { -// if (!parseCurrentElementStart()) -// return false; -// } -// else -// if (mReader.isCharacters()) -// { -// if (!parseCurrentElementCharacters()) -// return false; -// } -// else -// if (mReader.isEndElement()) -// { -// if (!parseCurrentElementEnd()) -// return false; -// } -// } -// if (!mReader.error() == QXmlStreamReader::NoError) -// UBApplication::showMessage(mReader.errorString()); return true; } - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementStart() +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg(const QDomElement &svgSection) { - QStringRef elName = mReader.name(); -// QString log = QString("%1<%2>").arg(mIndent).arg(elName.toString()); -// qDebug() << log; - mIndent += " "; - if ( elName == tIwb) - { - if (!parseIwb()) - return false; - - PushState(IWB); - } - else - if ( elName == tMeta) - { - if (!parseIwbMeta()) - return false; - } - else - if ( elName == tSvg) - { - if (!parseSvg()) - return false; - - PushState(SVG); - } - else - if ( elName == tRect) - { - if (!parseRect()) - return false; - } - else - if ( elName == tEllipse) - { - if (!parseEllipse()) - return false; - } - else - if ( elName == tText) - { - if (!parseText()) - return false; - } - else - if ( elName == tTextarea) - { - if (!parseTextArea()) - return false; - } - else - if ( elName == tPolygon) - { - if (!parsePolygon()) - return false; - } - else - if ( elName == tPolyline) - { - if (!parsePolyline()) - return false; + if (svgSection.namespaceURI() != svgNS) { + qDebug() << "incorrect svg namespace, incorrect document"; + return false; } - else - if ( elName == tPage) - { - if (!parsePage()) - return false; - PushState(PAGE); - } - else - if ( elName == tPageset) - { - if (!parsePageSet()) - return false; + parseSvgSectionAttr(svgSection); + QDomElement currentSvg = svgSection.firstChildElement(); - PushState(PAGESET); - } - else - if ( elName == tElement) - { - if (!parseIwbElementRef()) - return false; + if (currentSvg.tagName() != tPageset) { + parseSvgPage(svgSection); + } else if (currentSvg.tagName() == tPageset){ + parseSvgPageset(currentSvg); } return true; } -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementCharacters() +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGroup(QDomElement &parent) { + if (parent.namespaceURI() != iwbNS) { + qDebug() << "incorrect iwb group namespace, incorrect document"; + return false; + } + return true; } -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementEnd() +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::strToBool(QString str) { - QStringRef elName = mReader.name(); - mIndent.remove(0,1); - QString log = QString("%1").arg(mIndent).arg(elName.toString()); - qDebug() << log; - - if ( elName == tIwb) - PopState(); - else - if ( elName == tMeta) - { - } - else - if ( elName == tSvg) - { - persistCurrentScene(); - PopState(); - } - else - if ( elName == tPage) - { - persistCurrentScene(); - PopState(); - } - else - if ( elName == tPageset) - { - PopState(); - } - - return true; + return str == "true"; } -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwb() +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElement(QDomElement &element) { - if (!stateStack.empty() || currentState != NONE) - { - qWarning() << "iwb content parse error, unexpected iwb tag at line" << mReader.lineNumber(); + if (element.namespaceURI() != iwbNS) { + qDebug() << "incorrect iwb element namespace, incorrect document"; return false; } - return true; -} + bool locked = false, isBackground = false; + QString IDRef = element.attribute(aRef); + if (!IDRef.isNull()) { + isBackground = element.hasAttribute(aBackground) ? strToBool(element.attribute(aBackground)) : false; + locked = element.hasAttribute(aBackground) ? strToBool(element.attribute(aBackground)) : false; + + QHash::iterator iReferedItem; + iReferedItem = persistedItems.find(IDRef); + if (iReferedItem != persistedItems.end() && IDRef == "background") { + UBGraphicsItem *referedItem = *iReferedItem; +// UBGraphicsPixmapItem *item = dynamic_cast(referedItem); + referedItem->Delegate()->lock(false); + referedItem->Delegate()->printMessage("called from extended"); + } + +// UBGraphicsItem *referedItem = *(persistedItems.find(IDRef)); +// referedItem->Delegate()->lock(locked); -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta() -{ - if (currentState != IWB) - { - qWarning() << "iwb content parse error, unexpected meta tag at line" << mReader.lineNumber(); - return false; } + + return true; } - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg() +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() { - if (currentState != IWB) - { - qWarning() << "iwb content parse error, unexpected svg tag at line" << mReader.lineNumber(); - return false; - } + QDomElement currentTopElement = mDOMdoc.documentElement().firstChildElement(); + while (!currentTopElement.isNull()) { + QString tagName = currentTopElement.tagName(); + if (tagName == tMeta && !parseIwbMeta(currentTopElement)) return false; + else if (tagName == tSvg && !parseSvg(currentTopElement)) return false; + else if (tagName == tGroup && !parseIwbGroup(currentTopElement)) return false; + else if (tagName == tElement && !parseIwbElement(currentTopElement)) return false; - getViewBoxDimenstions(mReader.attributes().value(aViewbox).toString()); - mSize = QSize(mReader.attributes().value(aWidth).toString().toInt(), - mReader.attributes().value(aHeight).toString().toInt()); + currentTopElement = currentTopElement.nextSiblingElement(); + } return true; } -void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(UBGraphicsSvgItem *item, qreal width, qreal height, +void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(QGraphicsItem *item, qreal width, qreal height, qreal x, qreal y, bool useTransform, QTransform &transform) { @@ -1141,599 +979,168 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(UBGraphicsSvgItem // qWarning() << QString("Item new transform = %3 0 0 %4 %1 %2, position %5, %6").arg(newTrans.dx()).arg(newTrans.dy()).arg(newTrans.m11()).arg(newTrans.m22()).arg(item->x()).arg(item->y()); } -void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionPixmapItem(UBGraphicsPixmapItem *item, qreal width, qreal height, - qreal x, qreal y, - bool useTransform, QTransform &transform) -{ - //if element is to transform -// if (!transform.isIdentity()) { -// QTransform curTransform = item->transform(); -// qreal hScale = item->boundingRect().width() / width * curTransform.m11(); -// qreal vScale = item->boundingRect().height() / height * curTransform.m22(); -// curTransform = curTransform.translate(x - mViewBoxCenter.x(), y - mViewBoxCenter.y()).scale(hScale, vScale); -// curTransform = curTransform * transform; -// item->setTransform(curTransform); - - - QTransform curTrans = item->transform(); -// qWarning() << QString().sprintf("Item current transform = %f 0 0 %f %f %f, position %f, %f", curTrans.m11(), curTrans.m22(), curTrans.dx(), curTrans.dy(), item->x(), item->y()); - //check if rect is rotated - //rotate svg item itself - QRectF itemBounds = item->boundingRect(); - //first, svg is mapped to svg item bound - //second, svg item is mapped to scene - //so, get svg to svg item scale and multiple by scene scale - qreal hScale = itemBounds.width() / width * curTrans.m11(); - qreal vScale = itemBounds.height() / height * curTrans.m22(); +//bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseText() +//{ +// if (currentState != SVG && currentState != PAGE) +// { +// qWarning() << "iwb content parse error, unexpected textarea tag at line" << mReader.lineNumber(); +// return false; +// } - if (useTransform) - { - QPointF oldVector((x - transform.dx()), (y - transform.dy())); - QTransform rTransform(transform.m11(), transform.m12(), transform.m21(), transform.m22(), 0, 0); - QPointF newVector = rTransform.map(oldVector); - rTransform.scale(curTrans.m11(), curTrans.m22()); - item->setTransform(QTransform(rTransform.m11(), rTransform.m12(), rTransform.m21(), rTransform.m22(), 0, 0)); - item->setPos((x - mViewBoxCenter.x() + (newVector - oldVector).x()) * hScale, (y - mViewBoxCenter.y() + (newVector - oldVector).y()) * vScale ); - } - else - { - item->setPos((x - mViewBoxCenter.x()) * hScale, (y - mViewBoxCenter.y()) * vScale); - } +// //create new scene if it's not created yet (for one page document case) +// if (currentState == SVG && mCurrentScene == NULL) +// createNewScene(); -} +// qreal x = mReader.attributes().value(aX).toString().toDouble(); +// qreal y = mReader.attributes().value(aY).toString().toDouble(); -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseRect() -{ - if (currentState != SVG && currentState != PAGE) - { - qWarning() << "iwb content parse error, unexpected rect tag at line" << mReader.lineNumber(); - return false; - } +// qreal width = 0; +// qreal height = 0; - //create new scene if it's not created yet (for one page document case) - if (currentState == SVG && mCurrentScene == NULL) - createNewScene(); +// QList textRects; +// QList textFonts; +// QList textLines; +// QList textAligns; +// QList textColors; - //rect lef top corner coordinates - qreal x1 = mReader.attributes().value(aX).toString().toDouble(); - qreal y1 = mReader.attributes().value(aY).toString().toDouble(); - //rect dimensions - qreal width = mReader.attributes().value(aWidth).toString().toDouble(); - qreal height = mReader.attributes().value(aHeight).toString().toDouble(); +// qWarning() << QString().sprintf("Text coordinates : %f,%f. Text size %f,%f", x, y, width, height); - //init svg generator with temp file - QSvgGenerator *generator = createSvgGenerator(width + 10, height + 10); +// qreal fontSize = 12.0; +// QFont textFont; +// QColor fontColor; +// QString fontFamily = "Arial"; +// QString fontStretch = "normal"; - //init painter to paint to svg - QPainter painter; - painter.begin(generator); - - //fill rect - if (mReader.attributes().hasAttribute(aFill)) - { - QColor fillColor = colorFromString(mReader.attributes().value(aFill).toString()); - painter.setBrush(QBrush(fillColor)); - painter.fillRect(5, 5, width, height, fillColor); - } - - bool hasStrokeColor = mReader.attributes().hasAttribute(aStroke); - bool hasStrokeWidth = mReader.attributes().hasAttribute(aStrokewidth); - if (hasStrokeColor || hasStrokeWidth) - { - QPen pen; - if (hasStrokeColor) - pen.setColor(colorFromString(mReader.attributes().value(aStroke).toString())); - if (hasStrokeWidth) - pen.setWidth(mReader.attributes().value(aStrokewidth).toString().toInt()); - - painter.setPen(pen); - painter.drawRect(5, 5, width, height); - } - - painter.end(); - - //add resulting svg file to scene - UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - QTransform transform; - bool hastransform = getCurElementTransorm(transform); - repositionSvgItem(svgItem, width + 10, height + 10, x1 - 5, y1 - 5, hastransform, transform); - delete generator; - - return true; -} - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseEllipse() -{ - if (currentState != SVG && currentState != PAGE) - { - qWarning() << "iwb content parse error, unexpected ellipse tag at line" << mReader.lineNumber(); - return false; - } - - //create new scene if it's not created yet (for one page document case) - if (currentState == SVG && mCurrentScene == NULL) - createNewScene(); - - //ellipse horisontal and vertical radius - qreal rx = mReader.attributes().value(aRx).toString().toDouble(); - qreal ry = mReader.attributes().value(aRy).toString().toDouble(); - QSvgGenerator *generator = createSvgGenerator(rx * 2 + 10, ry * 2 + 10); - - //fill and stroke color - QColor fillColor = colorFromString(mReader.attributes().value(aFill).toString()); - QColor strokeColor = colorFromString(mReader.attributes().value(aStroke).toString()); - int strokeWidth = mReader.attributes().value(aStrokewidth).toString().toInt(); - - //ellipse center coordinates - qreal cx = mReader.attributes().value(aCx).toString().toDouble(); - qreal cy = mReader.attributes().value(aCy).toString().toDouble(); - - //init painter to paint to svg - QPainter painter; - painter.begin(generator); - - QPen pen(strokeColor); - pen.setWidth(strokeWidth); - painter.setPen(pen); - painter.setBrush(QBrush(fillColor)); - - painter.drawEllipse(5, 5, rx * 2, ry * 2); - - painter.end(); - - - //add resulting svg file to scene - UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - - QTransform transform; - bool hasTransform = getCurElementTransorm(transform); - - repositionSvgItem(svgItem, rx * 2 + 10, ry * 2 + 10, cx - rx - 5, cy - ry -5, hasTransform, transform); - - delete generator; - - return true; - } - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTextArea() -{ - if (currentState != SVG && currentState != PAGE) - { - qWarning() << "iwb content parse error, unexpected textarea tag at line" << mReader.lineNumber(); - return false; - } - - //create new scene if it's not created yet (for one page document case) - if (currentState == SVG && mCurrentScene == NULL) - createNewScene(); - - //TODO textarea node - qreal x = mReader.attributes().value(aX).toString().toDouble(); - qreal y = mReader.attributes().value(aY).toString().toDouble(); - qreal width = mReader.attributes().value(aWidth).toString().toDouble(); - qreal height = mReader.attributes().value(aHeight).toString().toDouble(); - - qWarning() << QString().sprintf("Text coordinates : %f,%f. Text size %f,%f", x, y, width, height); - - qreal fontSize = 12.0; - QColor fontColor; - QString fontFamily = "Arial"; - QString fontStretch = "normal"; - bool italic = false; - int fontWeight = QFont::Normal; - int textAlign = Qt::AlignLeft; - QTransform fontTransform; - parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); - - QSvgGenerator *generator = createSvgGenerator(width, height); - QPainter painter; - painter.begin(generator); - painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); - - qreal curY = 0.0; - qreal curX = 0.0; - qreal linespacing = QFontMetricsF(painter.font()).leading(); - - //remember if text area has transform - QString transformString; - QTransform transform; - bool hasTransform = getCurElementTransorm(transform); - - QRectF lastDrawnTextBoundingRect; - //parse text area tags - while(true) - { - mReader.readNext(); - QStringRef elementName = mReader.name(); - if (mReader.isEndDocument()) - break; - if (mReader.isEndElement() && elementName == tBreak) - { - //when tbreak appers, move down by the drawn rect height - //TODO: line spacing is not calculated yet, additional code is required - curY += lastDrawnTextBoundingRect.height() + linespacing; - curX = 0.0; - lastDrawnTextBoundingRect = QRectF(0,0,0,0); - continue; - } - if (mReader.isEndElement() && elementName == tTextarea) - break; - if (mReader.isStartElement() && elementName == tTspan) - { - parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); - painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); - painter.setPen(fontColor); - linespacing = QFontMetricsF(painter.font()).leading(); - continue; - } - if (mReader.isCharacters() || mReader.isCDATA()) - { - QString text = mReader.text().toString().trimmed(); - - //skip empty text - if (text.length() == 0) - continue; - - //get bounding rect to obtain desired text height - lastDrawnTextBoundingRect = painter.boundingRect(QRectF(curX, curY, width, height - curY), textAlign|Qt::TextWordWrap, text); - QString log = QString().sprintf(" at rect %f, %f, %f, %f. Bounding rect is %f, %f, %f, %f", 0.0, curY, width, height - curY, lastDrawnTextBoundingRect.x(), lastDrawnTextBoundingRect.y(), lastDrawnTextBoundingRect.width(), lastDrawnTextBoundingRect.height()); - qWarning() << "Text " << text << log; - painter.drawText(curX, curY, width, lastDrawnTextBoundingRect.height(), textAlign|Qt::TextWordWrap, text); - curX += lastDrawnTextBoundingRect.x() + lastDrawnTextBoundingRect.width(); - - continue; - } - } - - painter.end(); - - //add resulting svg file to scene - UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - - repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); - delete generator; - - return true; -} - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseText() -{ - if (currentState != SVG && currentState != PAGE) - { - qWarning() << "iwb content parse error, unexpected textarea tag at line" << mReader.lineNumber(); - return false; - } - - //create new scene if it's not created yet (for one page document case) - if (currentState == SVG && mCurrentScene == NULL) - createNewScene(); - - qreal x = mReader.attributes().value(aX).toString().toDouble(); - qreal y = mReader.attributes().value(aY).toString().toDouble(); - - qreal width = 0; - qreal height = 0; - - QList textRects; - QList textFonts; - QList textLines; - QList textAligns; - QList textColors; - - qWarning() << QString().sprintf("Text coordinates : %f,%f. Text size %f,%f", x, y, width, height); +// bool italic = false; +// int fontWeight = QFont::Normal; +// int textAlign = Qt::AlignLeft; +// QTransform fontTransform; +// parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); +// textFont = QFont(fontFamily, fontSize, fontWeight, italic); - qreal fontSize = 12.0; - QFont textFont; - QColor fontColor; - QString fontFamily = "Arial"; - QString fontStretch = "normal"; +// QFontMetricsF metrics = QFontMetricsF(textFont); +// qreal curHeight = metrics.height(); - bool italic = false; - int fontWeight = QFont::Normal; - int textAlign = Qt::AlignLeft; - QTransform fontTransform; - parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); - textFont = QFont(fontFamily, fontSize, fontWeight, italic); +// qreal curY = 0.0; +// qreal curX = 0.0; - QFontMetricsF metrics = QFontMetricsF(textFont); - qreal curHeight = metrics.height(); +// qreal linespacing = QFontMetrics(textFont).leading(); - qreal curY = 0.0; - qreal curX = 0.0; +// //remember if text area has transform +// QTransform transform; +// bool hasTransform = getCurElementTransorm(transform); - qreal linespacing = QFontMetrics(textFont).leading(); +// QRectF lastDrawnTextBoundingRect; - //remember if text area has transform - QTransform transform; - bool hasTransform = getCurElementTransorm(transform); +// QStack fontStack; +// QStack colorStack; +// QStack alignStack; - QRectF lastDrawnTextBoundingRect; +// // first extimate desired text area size +// // to do that, parse text area tags +// while(true) +// { +// mReader.readNext(); +// QStringRef elementName = mReader.name(); +// if (mReader.isEndDocument()) +// break; +// if (mReader.isEndElement()) +// { +// if (elementName == tBreak) +// { +// //when tbreak appers, move down by the drawn rect height +// //TODO: line spacing is not calculated yet, probably additional code is required +// curY += lastDrawnTextBoundingRect.height() + linespacing; +// curX = 0.0; +// height += lastDrawnTextBoundingRect.height(); +// lastDrawnTextBoundingRect = QRectF(0,0,0,0); +// continue; +// } +// if (elementName == tTspan) +// { +// textFont = fontStack.pop(); +// fontColor = colorStack.pop(); +// textAlign = alignStack.pop(); +// continue; +// } +// } +// if (mReader.isEndElement() && elementName == tText) +// break; +// if (mReader.isStartElement() && elementName == tTspan) +// { +// fontStack.push(textFont); +// colorStack.push(fontColor); +// alignStack.push(textAlign); - QStack fontStack; - QStack colorStack; - QStack alignStack; +// parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); +// textFont = QFont(fontFamily, fontSize, fontWeight, italic); +// metrics = QFontMetricsF(textFont); +// curHeight = metrics.height(); +// linespacing = QFontMetricsF(textFont).leading(); +// continue; +// } +// if (mReader.isCharacters() || mReader.isCDATA()) +// { +// QString text = mReader.text().toString(); - // first extimate desired text area size - // to do that, parse text area tags - while(true) - { - mReader.readNext(); - QStringRef elementName = mReader.name(); - if (mReader.isEndDocument()) - break; - if (mReader.isEndElement()) - { - if (elementName == tBreak) - { - //when tbreak appers, move down by the drawn rect height - //TODO: line spacing is not calculated yet, probably additional code is required - curY += lastDrawnTextBoundingRect.height() + linespacing; - curX = 0.0; - height += lastDrawnTextBoundingRect.height(); - lastDrawnTextBoundingRect = QRectF(0,0,0,0); - continue; - } - if (elementName == tTspan) - { - textFont = fontStack.pop(); - fontColor = colorStack.pop(); - textAlign = alignStack.pop(); - continue; - } - } - if (mReader.isEndElement() && elementName == tText) - break; - if (mReader.isStartElement() && elementName == tTspan) - { - fontStack.push(textFont); - colorStack.push(fontColor); - alignStack.push(textAlign); - - parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); - textFont = QFont(fontFamily, fontSize, fontWeight, italic); - metrics = QFontMetricsF(textFont); - curHeight = metrics.height(); - linespacing = QFontMetricsF(textFont).leading(); - continue; - } - if (mReader.isCharacters() || mReader.isCDATA()) - { - QString text = mReader.text().toString(); - - //skip empty text - if (text.trimmed().length() == 0) - continue; - //get bounding rect to obtain desired text height - lastDrawnTextBoundingRect = metrics.boundingRect(QRectF(), textAlign, text); - QString log = QString().sprintf(" at rect %f, %f, %f, %f. Bounding rect is %f, %f, %f, %f", 0.0, curY, width, height - curY, lastDrawnTextBoundingRect.x(), lastDrawnTextBoundingRect.y(), lastDrawnTextBoundingRect.width(), lastDrawnTextBoundingRect.height()); - qWarning() << "Text " << text << log; - textFonts.append(textFont); - textRects.append(QRectF(curX, curY, lastDrawnTextBoundingRect.width(), lastDrawnTextBoundingRect.height())); - textLines.append(text); - textAligns.append(textAlign); - textColors.append(fontColor); - curX += lastDrawnTextBoundingRect.width(); - if (width < curX) - width = curX; - if (height == 0) - height = curHeight; +// //skip empty text +// if (text.trimmed().length() == 0) +// continue; +// //get bounding rect to obtain desired text height +// lastDrawnTextBoundingRect = metrics.boundingRect(QRectF(), textAlign, text); +// QString log = QString().sprintf(" at rect %f, %f, %f, %f. Bounding rect is %f, %f, %f, %f", 0.0, curY, width, height - curY, lastDrawnTextBoundingRect.x(), lastDrawnTextBoundingRect.y(), lastDrawnTextBoundingRect.width(), lastDrawnTextBoundingRect.height()); +// qWarning() << "Text " << text << log; +// textFonts.append(textFont); +// textRects.append(QRectF(curX, curY, lastDrawnTextBoundingRect.width(), lastDrawnTextBoundingRect.height())); +// textLines.append(text); +// textAligns.append(textAlign); +// textColors.append(fontColor); +// curX += lastDrawnTextBoundingRect.width(); +// if (width < curX) +// width = curX; +// if (height == 0) +// height = curHeight; - continue; - } - } - - QSvgGenerator *generator = createSvgGenerator(width, height); - QPainter painter; - painter.begin(generator); - - if (textRects.count() != 0) - { - QListIterator textRectsIter(textRects); - QListIterator textFontsIter(textFonts); - QListIterator textLinesIter(textLines); - QListIterator textAlignsIter(textAligns); - QListIterator textColorsIter(textColors); - - while (textRectsIter.hasNext()) - { - QRectF rt = textRectsIter.next(); - QFont font = textFontsIter.next(); - QString line = textLinesIter.next(); - int align = textAlignsIter.next(); - QColor color = textColorsIter.next(); - painter.setFont(font); - painter.setPen(color); - painter.drawText(rt.x(), rt.y(), rt.width(), rt.height(), align, line); - } - } - - painter.end(); - - //add resulting svg file to scene - UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); - - delete generator; - - return true; -} - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parsePolygon() -{ - if (currentState != SVG && currentState != PAGE) - { - qWarning() << "iwb content parse error, unexpected polygon tag at line" << mReader.lineNumber(); - return false; - } - - //create new scene if it's not created yet (for one page document case) - if (currentState == SVG && mCurrentScene == NULL) - createNewScene(); - - QStringRef svgPoints = mReader.attributes().value("points"); - QPolygonF polygon; - - if (!svgPoints.isNull()) { - QStringList ts = svgPoints.toString().split(QLatin1Char(' '), - QString::SkipEmptyParts); - - foreach(const QString sPoint, ts) { - QStringList sCoord = sPoint.split(QLatin1Char(','), QString::SkipEmptyParts); - if (sCoord.size() == 2) { - QPointF point; - point.setX(sCoord.at(0).toFloat()); - point.setY(sCoord.at(1).toFloat()); - polygon << point; - } - else { - qWarning() << "cannot make sense of a 'point' value" << sCoord; - } - } - } - - //bounding rect lef top corner coordinates - qreal x1 = polygon.boundingRect().topLeft().x(); - qreal y1 = polygon.boundingRect().topLeft().y(); - //bounding rect dimensions - qreal width = polygon.boundingRect().width(); - qreal height = polygon.boundingRect().height(); - - QPen pen; - if (mReader.attributes().hasAttribute(aStroke)) - pen.setColor(colorFromString(mReader.attributes().value(aStroke).toString())); - if (mReader.attributes().hasAttribute(aStrokewidth)) - pen.setWidth(mReader.attributes().value(aStrokewidth).toString().toInt()); - - QBrush brush; - if (mReader.attributes().hasAttribute(aFill)) { - brush.setColor(colorFromString(mReader.attributes().value(aFill).toString())); - brush.setStyle(Qt::SolidPattern); - } - - QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width()); - QPainter painter; - - painter.begin(generator); //drawing to svg tmp file - - painter.translate(pen.widthF() / 2 - x1, pen.widthF() / 2 - y1); - painter.setBrush(brush); - painter.setPen(pen); - painter.drawPolygon(polygon); - - painter.end(); - - //add resulting svg file to scene - UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - QTransform transform; - bool hastransform = getCurElementTransorm(transform); - repositionSvgItem(svgItem, width + 10, height + 10, x1 - 5, y1 - 5, hastransform, transform); - delete generator; - - return true; -} - -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parsePolyline() -{ - if (currentState != SVG && currentState != PAGE) - { - qWarning() << "iwb content parse error, unexpected polyline tag at line" << mReader.lineNumber(); - return false; - } - - //create new scene if it's not created yet (for one page document case) - if (currentState == SVG && mCurrentScene == NULL) - createNewScene(); - - QStringRef svgPoints = mReader.attributes().value("points"); - QPolygonF polygon; - - if (!svgPoints.isNull()) { - QStringList ts = svgPoints.toString().split(QLatin1Char(' '), - QString::SkipEmptyParts); - - foreach(const QString sPoint, ts) { - QStringList sCoord = sPoint.split(QLatin1Char(','), QString::SkipEmptyParts); - if (sCoord.size() == 2) { - QPointF point; - point.setX(sCoord.at(0).toFloat()); - point.setY(sCoord.at(1).toFloat()); - polygon << point; - } - else { - qWarning() << "cannot make sense of a 'point' value" << sCoord; - } - } - polygon.translate(-polygon.boundingRect().topLeft()); - } - - //bounding rect lef top corner coordinates - qreal x1 = polygon.boundingRect().topLeft().x(); - qreal y1 = polygon.boundingRect().topLeft().y(); - //bounding rect dimensions - qreal width = polygon.boundingRect().width(); - qreal height = polygon.boundingRect().height(); - - QPen pen; - if (mReader.attributes().hasAttribute(aStroke)) - pen.setColor(colorFromString(mReader.attributes().value(aStroke).toString())); - if (mReader.attributes().hasAttribute(aStrokewidth)) - pen.setWidth(mReader.attributes().value(aStrokewidth).toString().toInt()); - - QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width()); - QPainter painter; - - painter.begin(generator); //drawing to svg tmp file - - painter.translate(pen.widthF() / 2, pen.widthF() / 2); - painter.setPen(pen); - painter.drawPolyline(polygon); - - painter.end(); +// continue; +// } +// } - //add resulting svg file to scene - UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - QTransform transform; - bool hastransform = getCurElementTransorm(transform); - repositionSvgItem(svgItem, width + 10, height + 10, x1 - 5, y1 - 5, hastransform, transform); - delete generator; +// QSvgGenerator *generator = createSvgGenerator(width, height); +// QPainter painter; +// painter.begin(generator); - return true; -} +// if (textRects.count() != 0) +// { +// QListIterator textRectsIter(textRects); +// QListIterator textFontsIter(textFonts); +// QListIterator textLinesIter(textLines); +// QListIterator textAlignsIter(textAligns); +// QListIterator textColorsIter(textColors); -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parsePage() -{ - if (currentState != PAGESET && currentState != SVG) - { - qWarning() << "iwb content parse error, unexpected page tag at line" << mReader.lineNumber(); - return false; - } - createNewScene(); - qWarning() << "Added page number" << mProxy->pageCount(); - return true; -} +// while (textRectsIter.hasNext()) +// { +// QRectF rt = textRectsIter.next(); +// QFont font = textFontsIter.next(); +// QString line = textLinesIter.next(); +// int align = textAlignsIter.next(); +// QColor color = textColorsIter.next(); +// painter.setFont(font); +// painter.setPen(color); +// painter.drawText(rt.x(), rt.y(), rt.width(), rt.height(), align, line); +// } +// } -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parsePageSet() -{ - if (currentState != SVG) - { - qWarning() << "iwb content parse error, unexpected page tag at line" << mReader.lineNumber(); - return false; - } +// painter.end(); - return true; -} +// //add resulting svg file to scene +// UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); +// repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElementRef() -{ - if (currentState != IWB) - { - qWarning() << "iwb content parse error, unexpected element tag at line" << mReader.lineNumber(); - return false; - } +// delete generator; - return true; -} +// return true; +//} bool UBCFFSubsetAdaptor::UBCFFSubsetReader::createNewScene() { @@ -1782,17 +1189,6 @@ QColor UBCFFSubsetAdaptor::UBCFFSubsetReader::colorFromString(const QString& clr return QColor(clrString); } -bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getCurElementTransorm(QTransform &transform) -{ - if (mReader.attributes().hasAttribute(aTransform)) - { - transform = transformFromString(mReader.attributes().value(aTransform).toString()); - return true; - } - else - return false; -} - QTransform UBCFFSubsetAdaptor::UBCFFSubsetReader::transformFromString(const QString trString) { qreal dx = 0.0; @@ -1846,8 +1242,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getViewBoxDimenstions(const QString& QSvgGenerator* UBCFFSubsetAdaptor::UBCFFSubsetReader::createSvgGenerator(qreal width, qreal height) { QSvgGenerator* generator = new QSvgGenerator(); - qWarning() << QString("Making generator with file %1, size (%2, %3) and viewbox (%4 %5 %6 %7)").arg(mTempFilePath) - .arg(width).arg(height).arg(0.0).arg(0.0).arg(width).arg(width); +// qWarning() << QString("Making generator with file %1, size (%2, %3) and viewbox (%4 %5 %6 %7)").arg(mTempFilePath) +// .arg(width).arg(height).arg(0.0).arg(0.0).arg(width).arg(width); generator->setResolution(QApplication::desktop()->physicalDpiY()); generator->setFileName(mTempFilePath); generator->setSize(QSize(width, height)); @@ -1875,64 +1271,29 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getTempFileName() return false; } } - } - -void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTextAttributes(qreal &fontSize, QColor &fontColor, - QString &fontFamily, QString &fontStretch, bool &italic, - int &fontWeight, int &textAlign, QTransform &fontTransform) +bool UBCFFSubsetAdaptor::UBCFFSubsetReader::createTempFlashPath() { - if (mReader.attributes().hasAttribute(aFontSize)) - { - //consider inch has 72 liens - //since svg font size is given in pixels, divide it by pixels per line - fontSize = mReader.attributes().value(aFontSize).toString().toDouble() * 72 / QApplication::desktop()->physicalDpiY(); - } - - if (mReader.attributes().hasAttribute(aFill)) - fontColor = colorFromString(mReader.attributes().value(aFill).toString()); - - if (mReader.attributes().hasAttribute(aFontfamily)) - fontFamily = mReader.attributes().value(aFontfamily).toString(); - - if (mReader.attributes().hasAttribute(aFontstretch)) - fontStretch = mReader.attributes().value(aFontstretch).toString(); - - if (mReader.attributes().hasAttribute(aFontstyle)) - { - QStringRef fontStyle = mReader.attributes().value(aFontstyle); - italic = fontStyle == "italic"; - } - - if (mReader.attributes().hasAttribute(aFontweight)) - { - QStringRef weight = mReader.attributes().value(aFontweight); - if (weight == "normal") - fontWeight = QFont::Normal; - else if (weight == "light") - fontWeight = QFont::Light; - else if (weight == "demibold") - fontWeight = QFont::DemiBold; - else if (weight == "bold") - fontWeight = QFont::Bold; - if (weight == "black") - fontWeight = QFont::Black; - } + int tmpNumber = 0; + QDir systemTmp = QDir::temp(); - if (mReader.attributes().hasAttribute(aTextalign)) - { - QString align = mReader.attributes().value(aTextalign).toString(); - if (align == "middle" || align == "center") - textAlign = Qt::AlignHCenter; - else - if (align == "start") - textAlign = Qt::AlignLeft; - else - if (align == "end") - textAlign = Qt::AlignRight; + while (true) { + QString dirName = QString("SankTmpFlash%1.%2") + .arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm")) + .arg(tmpNumber++); + if (!systemTmp.exists(dirName)) { + if (systemTmp.mkdir(dirName)) { + mTmpFlashDir = QDir(systemTmp.absolutePath() + "/" + dirName); + return true; + } else { + qDebug() << "Can't create temporary dir maybe due to permissions"; + return false; + } + } else if (tmpNumber == 1000) { + qWarning() << "Import failed. Failed to create temporary file for svg objects"; + return false; + } } - if (mReader.attributes().hasAttribute(aTransform)) - fontTransform = transformFromString(mReader.attributes().value(aTransform).toString()); + return true; } - diff --git a/src/adaptors/UBCFFSubsetAdaptor.h b/src/adaptors/UBCFFSubsetAdaptor.h index 5bb69413..106a0ec6 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.h +++ b/src/adaptors/UBCFFSubsetAdaptor.h @@ -31,17 +31,8 @@ class UBGraphicsItemDelegate; class QTransform; class QPainter; class UBGraphicsItem; +class QGraphicsItem; -struct IwbExt { - IwbExt() {;} - IwbExt(QDomNode element) : element(element), extAttr(*(new QVector())) {;} - - QDomNode group; - QDomNode element; - QVector extAttr; - QHash textAttributes; - operator bool() const {return !group.isNull() || !element.isNull();} -}; class UBCFFSubsetAdaptor { @@ -53,22 +44,9 @@ public: private: class UBCFFSubsetReader { - //xml parse states definition - enum - { - NONE, - IWB, - SVG, - PAGESET, - PAGE, - TEXTAREA, - TSPAN - }; - public: UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content); - QXmlStreamReader mReader; UBDocumentProxy *mProxy; QString pwdContent; @@ -87,8 +65,8 @@ private: // to kill QDomDocument mDOMdoc; QDomNode mCurrentDOMElement; - QHash iwbExtProperties; QHash persistedItems; + QDir mTmpFlashDir; bool hashElements(); void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup); @@ -100,6 +78,8 @@ private: bool parseSvgPage(const QDomElement &parent); bool parseSvgPageset(const QDomElement &parent); bool parseSvgElement(const QDomElement &parent); + bool parseIwbMeta(const QDomElement &element); + bool parseSvg(const QDomElement &svgSection); inline bool parseSvgRect(const QDomElement &element); inline bool parseSvgEllipse(const QDomElement &element); @@ -108,8 +88,11 @@ private: inline bool parseSvgText(const QDomElement &element); inline bool parseSvgTextarea(const QDomElement &element); inline bool parseSvgImage(const QDomElement &element); -// inline bool parseSvgTSpan(const QDomElement) - bool parseIwbGroup(QDomNode *element); + inline bool parseSvgFlash(const QDomElement &element); + inline bool parseSvgAudio(const QDomElement &element); + inline bool parseSvgVideo(const QDomElement &element); + inline bool parseIwbGroup(QDomElement &parent); + inline bool parseIwbElement(QDomElement &element); inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item); // to kill @@ -117,52 +100,24 @@ private: QString &fontFamily, QString &fontStretch, bool &italic, int &fontWeight, int &textAlign, QTransform &fontTransform); - - //methods to store current xml parse state - int PopState(); - void PushState(int state); - //elements parsing methods bool parseDoc(); - bool parseCurrentElementStart(); - bool parseCurrentElementCharacters(); - bool parseCurrentElementEnd(); - - bool parseIwb(); - bool parseIwbMeta(); - bool parseSvg(); - bool parseRect(); - bool parseEllipse(); - bool parseTextArea(); - bool parseText(); - bool parsePolygon(); - bool parsePolyline(); - bool parsePage(); - bool parsePageSet(); - bool parseIwbElementRef(); - bool createNewScene(); bool persistCurrentScene(); - - QStack stateStack; - - int currentState; - - //helper methods - bool getCurElementTransorm(QTransform &transform); - void repositionSvgItem(UBGraphicsSvgItem *item, qreal width, qreal height, qreal x, qreal y, bool useTransform, QTransform &transform); - void repositionPixmapItem(UBGraphicsPixmapItem *item, qreal width, qreal height, qreal x, qreal y - , bool useTransform, QTransform &transform); +// helper methods +// bool getCurElementTransorm(QTransform &transform); + void repositionSvgItem(QGraphicsItem *item, qreal width, qreal height, + qreal x, qreal y, + bool useTransform, QTransform &transform); QColor colorFromString(const QString& clrString); QTransform transformFromString(const QString trString); bool getViewBoxDimenstions(const QString& viewBox); QSvgGenerator* createSvgGenerator(qreal width, qreal height); bool getTempFileName(); - void parseTextAttributes(qreal &fontSize, QColor &fontColor, - QString &fontFamily, QString &fontStretch, bool &italic, - int &fontWeight, int &textAlign, QTransform &fontTransform); + inline bool strToBool(QString); + bool createTempFlashPath(); }; }; diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index ea5d792c..1468ff8c 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -319,10 +319,12 @@ void UBGraphicsItemDelegate::lock(bool locked) if (locked) { mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(true)); + qDebug() << "item's data is called for locked" << mDelegated->data(UBGraphicsItemData::ItemLocked); } else { mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(false)); + qDebug() << "item's data is called for unlocked" << mDelegated->data(UBGraphicsItemData::ItemLocked); } mDelegated->update(); diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index eefa8b1e..055a5de3 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -107,6 +107,8 @@ class UBGraphicsItemDelegate : public QObject virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); + void printMessage(const QString &mess) {qDebug() << mess;} + QGraphicsItem* delegated() { return mDelegated; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 58c57a02..4f616a4b 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -165,8 +165,6 @@ void UBGraphicsScene::selectionChangedProcessing() nextItem->setZValue(2); qDebug() << QString(" >>> %1 <<< ").arg(i) << QString(" >>> %1 <<< ").arg(zValue); } - - } // MARK: - diff --git a/src/domain/UBW3CWidget.cpp b/src/domain/UBW3CWidget.cpp index e4ca197c..6d7a0fe8 100644 --- a/src/domain/UBW3CWidget.cpp +++ b/src/domain/UBW3CWidget.cpp @@ -228,7 +228,6 @@ void UBW3CWidget::javaScriptWindowObjectCleared() void UBW3CWidget::votingSystemError(const QString& error) { page()->mainFrame()->evaluateJavaScript("if(voting.onerror) { voting.onerror('" + error +"');}"); - } From b484a095c83179674407614b09de6354962e46da Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Tue, 8 Nov 2011 15:40:49 +0200 Subject: [PATCH 4/5] viewbox dimentions created for svg and images --- src/adaptors/UBCFFSubsetAdaptor.cpp | 83 +++++++++++++++++++++++++---- src/adaptors/UBCFFSubsetAdaptor.h | 5 ++ 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 40a20ba1..2c1e6fb8 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -182,7 +182,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem int strokeWidth = !textStrokeWidth.isNull() ? textStrokeWidth.toInt() : 0; //init svg generator with temp file - QSvgGenerator *generator = createSvgGenerator(width + 10, height + 10); + QSvgGenerator *generator = createSvgGenerator(width, height); //init painter to paint to svg QPainter painter; @@ -192,7 +192,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem //fill rect if (fillColor.isValid()) { painter.setBrush(QBrush(fillColor)); - painter.fillRect(5, 5, width, height, fillColor); + painter.fillRect(0, 0, width, height, fillColor); } QPen pen; if (strokeColor.isValid()) { @@ -201,7 +201,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem if (strokeWidth) pen.setWidth(strokeWidth); painter.setPen(pen); - painter.drawRect(5, 5, width, height); + painter.drawRect(0, 0, width, height); painter.end(); @@ -213,7 +213,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem transform = transformFromString(textTransform); hastransform = true; } - repositionSvgItem(svgItem, width + 10, height + 10, x1 - 5, y1 - 5, hastransform, transform); + repositionSvgItem(svgItem, width, height, x1, y1, hastransform, transform); delete generator; return true; @@ -663,7 +663,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement & //add resulting svg file to scene UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); + repositionSvgItem(svgItem, width, height, x + 5, y + 5, hasTransform, transform); delete generator; return true; @@ -700,7 +700,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele transform = transformFromString(textTransform); hastransform = true; } - repositionSvgItem(pixItem, width, height, x - 5, y - 5, hastransform, transform); + repositionSvgItem(pixItem, width, height, x, y, hastransform, transform); +// experimentalReposition(pixItem, width, height, x, y, hastransform, transform); hashSceneItem(element, pixItem); return true; @@ -741,7 +742,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &ele transform = transformFromString(textTransform); hastransform = true; } - repositionSvgItem(flashItem, width, height, x - 5, y - 5, true, transform); + repositionSvgItem(flashItem, width, height, x, y, true, transform); hashSceneItem(element, flashItem); return true; @@ -961,23 +962,80 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(QGraphicsItem *ite qreal hScale = itemBounds.width() / width * curTrans.m11(); qreal vScale = itemBounds.height() / height * curTrans.m22(); + qreal xScale = width / itemBounds.width(); + qreal yScale = height / itemBounds.height(); + if (useTransform) { QPointF oldVector((x - transform.dx()), (y - transform.dy())); QTransform rTransform(transform.m11(), transform.m12(), transform.m21(), transform.m22(), 0, 0); QPointF newVector = rTransform.map(oldVector); rTransform.scale(curTrans.m11(), curTrans.m22()); - item->setTransform(QTransform(rTransform.m11(), rTransform.m12(), rTransform.m21(), rTransform.m22(), 0, 0)); - item->setPos((x - mViewBoxCenter.x() + (newVector - oldVector).x()) * hScale, (y - mViewBoxCenter.y() + (newVector - oldVector).y()) * vScale ); + item->setTransform(QTransform(rTransform.m11() * mVBTransFactor, + rTransform.m12() * mVBTransFactor, + rTransform.m21(), rTransform.m22(), 0, 0)); + item->setPos((x - mViewBoxCenter.x() + (newVector - oldVector).x()) * xScale * mVBTransFactor, + (y - mViewBoxCenter.y() + (newVector - oldVector).y()) * yScale * mVBTransFactor); } else { - item->setPos((x - mViewBoxCenter.x()) * hScale, (y - mViewBoxCenter.y()) * vScale); + qreal fullScaleX = mVBTransFactor * xScale; + qreal fullScaleY = mVBTransFactor * yScale; + item->setTransform(QTransform(fullScaleX, 0, 0, fullScaleY, 0, 0)); + itemBounds = item->boundingRect(); + item->setPos((int)((x - mViewBoxCenter.x()) * mVBTransFactor), + (int)((y - mViewBoxCenter.y()) * mVBTransFactor)); + QPointF newPos = item->pos(); + qDebug(); } QTransform newTrans = item->transform(); // qWarning() << QString("Item new transform = %3 0 0 %4 %1 %2, position %5, %6").arg(newTrans.dx()).arg(newTrans.dy()).arg(newTrans.m11()).arg(newTrans.m22()).arg(item->x()).arg(item->y()); +} +void UBCFFSubsetAdaptor::UBCFFSubsetReader::experimentalReposition(QGraphicsItem *item, qreal width, qreal height, + qreal x, qreal y, + bool useTransform, QTransform &transform) +{ + Q_UNUSED(useTransform) + Q_UNUSED(transform) + + QRectF itemBounds = item->boundingRect(); + + qreal xScale = width / itemBounds.width(); + qreal yScale = height / itemBounds.height(); + + qreal newX = (x - mViewBox.center().x()) * xScale * mVBTransFactor; + qreal newY = (y - mViewBox.center().y()) * yScale * mVBTransFactor; + +// qDebug() << item->transform(); +// QTransform transform1(1, 0, 0, 1, mCurrentSceneRect.center().x(), mCurrentSceneRect.center().y()); +// QPointF newPos = QTransform(xScale * mVBTransFactor, 0, 0, yScale * mVBTransFactor, +// mCurrentSceneRect.center().x(), mCurrentSceneRect.center().y()).map(QPointF(x, y)); + + QPointF newPos(newX, newY); + + item->setTransform(QTransform(xScale * mVBTransFactor, 0, 0, yScale * mVBTransFactor, 0, 0)); + item->setPos(newPos); + + item->setPos(newPos); + + qDebug(); + + + + // QTransform transform; + +// QTransform newTransform(mVBTransFactor, 0, 0, +// mVBTransFactor, mViewPort.center().x(), mViewPort.center().y()); +// QRectF newItemRect = newTransform.mapRect(itemRect); +// item->setPos(newItemRect.topLeft()); +// item->setBou + + +// QTransform translateTransform(width * mVBTransFactor, 0, 0, height * mVBTransFactor, +// mViewPort.center().x(), mViewPort.center().y()); +// item->setTransform(translateTransform); } //bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseText() @@ -1146,6 +1204,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::createNewScene() { mCurrentScene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mProxy, mProxy->pageCount()); mCurrentSceneRect = mCurrentScene->normalizedSceneRect(); + mVBTransFactor = qMin(mCurrentSceneRect.width() / mViewPort.width(), + mCurrentSceneRect.height() / mViewPort.height()); return true; } @@ -1228,8 +1288,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getViewBoxDimenstions(const QString& if (capturesCount == 5 && regexp.capturedTexts().at(0).length() == viewBox.length()) { mViewBox = QRectF(0, 0, regexp.capturedTexts().at(3).toDouble(), regexp.capturedTexts().at(4).toDouble()); + mViewPort = mViewBox; + mViewPort.translate(- mViewPort.center()); mViewBoxCenter.setX(mViewBox.width() / 2); mViewBoxCenter.setY(mViewBox.height() / 2); + return true; } } diff --git a/src/adaptors/UBCFFSubsetAdaptor.h b/src/adaptors/UBCFFSubsetAdaptor.h index 106a0ec6..45ba431b 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.h +++ b/src/adaptors/UBCFFSubsetAdaptor.h @@ -58,6 +58,8 @@ private: QRectF mCurrentSceneRect; QString mIndent; QRectF mViewBox; + QRectF mViewPort; + qreal mVBTransFactor; QPointF mViewBoxCenter; QSize mSize; @@ -111,6 +113,9 @@ private: void repositionSvgItem(QGraphicsItem *item, qreal width, qreal height, qreal x, qreal y, bool useTransform, QTransform &transform); + void experimentalReposition(QGraphicsItem *item, qreal width, qreal height, + qreal x, qreal y, + bool useTransform, QTransform &transform); QColor colorFromString(const QString& clrString); QTransform transformFromString(const QString trString); bool getViewBoxDimenstions(const QString& viewBox); From 61d46015e390c3bad97ff650b82a3d6021e39e48 Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Wed, 9 Nov 2011 19:29:53 +0200 Subject: [PATCH 5/5] cff partial support --- src/adaptors/UBCFFSubsetAdaptor.cpp | 334 +++++++++++----------------- src/adaptors/UBCFFSubsetAdaptor.h | 5 + src/domain/UBGraphicsScene.cpp | 1 - 3 files changed, 129 insertions(+), 211 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 2c1e6fb8..5e970806 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -223,7 +223,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e //ellipse horisontal and vertical radius qreal rx = element.attribute(aRx).toDouble(); qreal ry = element.attribute(aRy).toDouble(); - QSvgGenerator *generator = createSvgGenerator(rx * 2 + 10, ry * 2 + 10); + QSvgGenerator *generator = createSvgGenerator(rx * 2, ry * 2); //fill and stroke color QColor fillColor = colorFromString(element.attribute(aFill)); @@ -243,7 +243,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e painter.setPen(pen); painter.setBrush(QBrush(fillColor)); - painter.drawEllipse(5, 5, rx * 2, ry * 2); + painter.drawEllipse(0, 0, rx * 2, ry * 2); painter.end(); @@ -255,7 +255,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e transform = transformFromString(textTransform); hastransform = true; } - repositionSvgItem(svgItem, rx * 2 + 10, ry * 2 + 10, cx - rx - 5, cy - ry -5, hastransform, transform); + repositionSvgItem(svgItem, rx * 2, ry * 2, cx - rx , cy - ry, hastransform, transform); delete generator; return true; @@ -440,166 +440,101 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTextAttributes(const QDomElemen bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgText(const QDomElement &element) { -// qreal x = element.attribute(aX).toDouble(); -// qreal y = element.attribute(aY).toDouble();; - -// qreal width = 0; -// qreal height = 0; - -// QList textRects; -// QList textFonts; -// QList textLines; -// QList textAligns; -// QList textColors; - -// qWarning() << QString().sprintf("Text coordinates : %f,%f. Text size %f,%f", x, y, width, height); - -// qreal fontSize = 12.0; -// QFont textFont; -// QColor fontColor; -// QString fontFamily = "Arial"; -// QString fontStretch = "normal"; - -// bool italic = false; -// int fontWeight = QFont::Normal; -// int textAlign = Qt::AlignLeft; -// QTransform fontTransform; -// parseTextAttributes(element, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); -// textFont = QFont(fontFamily, fontSize, fontWeight, italic); - -// QFontMetricsF metrics = QFontMetricsF(textFont); -// qreal curHeight = metrics.height(); - -// qreal curY = 0.0; -// qreal curX = 0.0; - -// qreal linespacing = QFontMetrics(textFont).leading(); - -// //remember if text area has transform -// QTransform transform; -//// bool hasTransform = getCurElementTransorm(transform); - -// QRectF lastDrawnTextBoundingRect; - -// QStack fontStack; -// QStack colorStack; -// QStack alignStack; - -// // first extimate desired text area size -// // to do that, parse text area tags -// while(true) -// { -// mReader.readNext(); -// QStringRef elementName = mReader.name(); -// if (mReader.isEndDocument()) -// break; -// if (mReader.isEndElement()) -// { -// if (elementName == tBreak) -// { -// //when tbreak appers, move down by the drawn rect height -// //TODO: line spacing is not calculated yet, probably additional code is required -// curY += lastDrawnTextBoundingRect.height() + linespacing; -// curX = 0.0; -// height += lastDrawnTextBoundingRect.height(); -// lastDrawnTextBoundingRect = QRectF(0,0,0,0); -// continue; -// } -// if (elementName == tTspan) -// { -// textFont = fontStack.pop(); -// fontColor = colorStack.pop(); -// textAlign = alignStack.pop(); -// continue; -// } -// } -// if (mReader.isEndElement() && elementName == tText) -// break; -// if (mReader.isStartElement() && elementName == tTspan) -// { -// fontStack.push(textFont); -// colorStack.push(fontColor); -// alignStack.push(textAlign); - -// parseTextAttributes(fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); -// textFont = QFont(fontFamily, fontSize, fontWeight, italic); -// metrics = QFontMetricsF(textFont); -// curHeight = metrics.height(); -// linespacing = QFontMetricsF(textFont).leading(); -// continue; -// } -// if (mReader.isCharacters() || mReader.isCDATA()) -// { -// QString text = mReader.text().toString(); + qreal x = element.attribute(aX).toDouble(); + qreal y = element.attribute(aY).toDouble(); + qreal width = element.attribute(aWidth).toDouble(); + qreal height = element.attribute(aHeight).toDouble(); -// //skip empty text -// if (text.trimmed().length() == 0) -// continue; -// //get bounding rect to obtain desired text height -// lastDrawnTextBoundingRect = metrics.boundingRect(QRectF(), textAlign, text); -// QString log = QString().sprintf(" at rect %f, %f, %f, %f. Bounding rect is %f, %f, %f, %f", 0.0, curY, width, height - curY, lastDrawnTextBoundingRect.x(), lastDrawnTextBoundingRect.y(), lastDrawnTextBoundingRect.width(), lastDrawnTextBoundingRect.height()); -// qWarning() << "Text " << text << log; -// textFonts.append(textFont); -// textRects.append(QRectF(curX, curY, lastDrawnTextBoundingRect.width(), lastDrawnTextBoundingRect.height())); -// textLines.append(text); -// textAligns.append(textAlign); -// textColors.append(fontColor); -// curX += lastDrawnTextBoundingRect.width(); -// if (width < curX) -// width = curX; -// if (height == 0) -// height = curHeight; + qreal fontSize = 12; + QColor fontColor(qApp->palette().foreground().color()); + QString fontFamily = "Arial"; + QString fontStretch = "normal"; + bool italic = false; + int fontWeight = QFont::Normal; + int textAlign = Qt::AlignLeft; + QTransform fontTransform; + parseTextAttributes(element, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); -// continue; -// } -// } + QSvgGenerator *generator = createSvgGenerator(width, height); + QPainter painter; + painter.begin(generator); + painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); -// QSvgGenerator *generator = createSvgGenerator(width, height); -// QPainter painter; -// painter.begin(generator); + qreal curY = 0.0; + qreal curX = 0.0; + qreal linespacing = QFontMetricsF(painter.font()).leading(); -// if (textRects.count() != 0) -// { -// QListIterator textRectsIter(textRects); -// QListIterator textFontsIter(textFonts); -// QListIterator textLinesIter(textLines); -// QListIterator textAlignsIter(textAligns); -// QListIterator textColorsIter(textColors); +// remember if text area has transform +// QString transformString; + QTransform transform = fontTransform; + bool hasTransform = !fontTransform.isIdentity(); -// while (textRectsIter.hasNext()) -// { -// QRectF rt = textRectsIter.next(); -// QFont font = textFontsIter.next(); -// QString line = textLinesIter.next(); -// int align = textAlignsIter.next(); -// QColor color = textColorsIter.next(); -// painter.setFont(font); -// painter.setPen(color); -// painter.drawText(rt.x(), rt.y(), rt.width(), rt.height(), align, line); -// } -// } + QRectF lastDrawnTextBoundingRect; + //parse text area tags -// painter.end(); + //recursive call any tspan in text svg element + parseTSpan(element, painter + , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect + , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); -// //add resulting svg file to scene -// UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); -// repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); + painter.end(); -// delete generator; + //add resulting svg file to scene + UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); + repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); + delete generator; return true; +} + +void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTSpan(const QDomElement &parent, QPainter &painter + , qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect + , qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic + , int &fontWeight, int &textAlign, QTransform &fontTransform) +{ + QDomNode curNode = parent.firstChild(); + while (!curNode.isNull()) { + if (curNode.toElement().tagName() == tTspan) { + QDomElement curTSpan = curNode.toElement(); + parseTextAttributes(curTSpan, fontSize, fontColor, fontFamily, fontStretch, italic + , fontWeight, textAlign, fontTransform); + painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); + painter.setPen(fontColor); + linespacing = QFontMetricsF(painter.font()).leading(); + parseTSpan(curTSpan, painter + , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect + , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); + } else if (curNode.nodeType() == QDomNode::CharacterDataNode + || curNode.nodeType() == QDomNode::CDATASectionNode + || curNode.nodeType() == QDomNode::TextNode) { + + QDomCharacterData textData = curNode.toCharacterData(); + QString text = textData.data().trimmed(); + //get bounding rect to obtain desired text height + lastDrawnTextBoundingRect = painter.boundingRect(QRectF(curX, curY, width, height - curY), textAlign|Qt::TextWordWrap, text); + painter.drawText(curX, curY, width, lastDrawnTextBoundingRect.height(), textAlign|Qt::TextWordWrap, text); + curX += lastDrawnTextBoundingRect.x() + lastDrawnTextBoundingRect.width(); + } else if (curNode.nodeType() == QDomNode::ElementNode + && curNode.toElement().tagName() == tBreak) { + + curY += lastDrawnTextBoundingRect.height() + linespacing; + curX = 0.0; + lastDrawnTextBoundingRect = QRectF(0,0,0,0); + } + curNode = curNode.nextSibling(); + } } + bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement &element) { - //TODO textarea node qreal x = element.attribute(aX).toDouble(); qreal y = element.attribute(aY).toDouble(); qreal width = element.attribute(aWidth).toDouble(); qreal height = element.attribute(aHeight).toDouble(); qreal fontSize = 12; - QColor fontColor; + QColor fontColor(qApp->palette().foreground().color()); QString fontFamily = "Arial"; QString fontStretch = "normal"; bool italic = false; @@ -625,47 +560,18 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement & QRectF lastDrawnTextBoundingRect; //parse text area tags - QDomElement curTextElement = element.firstChildElement(); - while (!curTextElement.isNull()) { - QString tagName = curTextElement.tagName(); - if (tagName == tTspan) { - parseTextAttributes(curTextElement, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); - painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); - painter.setPen(fontColor); - linespacing = QFontMetricsF(painter.font()).leading(); - - QDomNode tspanNode = curTextElement.firstChild(); - while (!tspanNode.isNull()) { - if (tspanNode.nodeType() == QDomNode::CharacterDataNode - || tspanNode.nodeType() == QDomNode::CDATASectionNode) { - QDomCharacterData textData = tspanNode.toCharacterData(); - QString text = textData.data().trimmed(); - //get bounding rect to obtain desired text height - lastDrawnTextBoundingRect = painter.boundingRect(QRectF(curX, curY, width, height - curY), textAlign|Qt::TextWordWrap, text); - painter.drawText(curX, curY, width, lastDrawnTextBoundingRect.height(), textAlign|Qt::TextWordWrap, text); - curX += lastDrawnTextBoundingRect.x() + lastDrawnTextBoundingRect.width(); - } else if (tspanNode.nodeType() == QDomNode::ElementNode) { - //when tbreak appers, move down by the drawn rect height - //TODO: line spacing is not calculated yet, additional code is required - curY += lastDrawnTextBoundingRect.height() + linespacing; - curX = 0.0; - lastDrawnTextBoundingRect = QRectF(0,0,0,0); - } - tspanNode = tspanNode.nextSibling(); - } - } else if (tagName == tBreak) { - - } - curTextElement = curTextElement.nextSiblingElement(); - } + //recursive call any tspan in text svg element + parseTSpan(element, painter + , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect + , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); painter.end(); //add resulting svg file to scene UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); - repositionSvgItem(svgItem, width, height, x + 5, y + 5, hasTransform, transform); - delete generator; + repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); + delete generator; return true; } bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element) @@ -750,6 +656,34 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &ele bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgAudio(const QDomElement &element) { + qreal x = element.attribute(aX).toDouble(); + qreal y = element.attribute(aY).toDouble(); + qreal width = element.attribute(aWidth).toDouble(); + qreal height = element.attribute(aHeight).toDouble(); + + QString itemRefPath = element.attribute(aHref); + + QUrl urlPath; + if (!itemRefPath.isNull()) { + QString videoPath = pwdContent + "/" + itemRefPath; + if (!QFile::exists(videoPath)) { + qDebug() << "can't load file" << pwdContent + "/" + itemRefPath << "maybe file corrupted"; + return false; + } + urlPath = QUrl::fromLocalFile(videoPath); + } + + UBGraphicsAudioItem *audioItem = mCurrentScene->addAudio(urlPath, false); + QTransform transform; + QString textTransform = element.attribute(aTransform); + bool hastransform = false; + if (!textTransform.isNull()) { + transform = transformFromString(textTransform); + hastransform = true; + } + repositionSvgItem(audioItem, width, height, x, y, hastransform, transform); + hashSceneItem(element, audioItem); + return true; } bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &element) @@ -927,8 +861,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElement(QDomElement &element } - - return true; } bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() @@ -943,7 +875,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() currentTopElement = currentTopElement.nextSiblingElement(); } - return true; } @@ -951,47 +882,30 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(QGraphicsItem *ite qreal x, qreal y, bool useTransform, QTransform &transform) { - QTransform curTrans = item->transform(); -// qWarning() << QString().sprintf("Item current transform = %f 0 0 %f %f %f, position %f, %f", curTrans.m11(), curTrans.m22(), curTrans.dx(), curTrans.dy(), item->x(), item->y()); - //check if rect is rotated - //rotate svg item itself + //First using viebox coordinates, then translate them to scene coordinates + QRectF itemBounds = item->boundingRect(); - //first, svg is mapped to svg item bound - //second, svg item is mapped to scene - //so, get svg to svg item scale and multiple by scene scale - qreal hScale = itemBounds.width() / width * curTrans.m11(); - qreal vScale = itemBounds.height() / height * curTrans.m22(); - + qreal xScale = width / itemBounds.width(); qreal yScale = height / itemBounds.height(); - if (useTransform) - { + qreal fullScaleX = mVBTransFactor * xScale; + qreal fullScaleY = mVBTransFactor * yScale; + + if (useTransform) { //if rotation or translation specified QPointF oldVector((x - transform.dx()), (y - transform.dy())); QTransform rTransform(transform.m11(), transform.m12(), transform.m21(), transform.m22(), 0, 0); QPointF newVector = rTransform.map(oldVector); - rTransform.scale(curTrans.m11(), curTrans.m22()); - item->setTransform(QTransform(rTransform.m11() * mVBTransFactor, - rTransform.m12() * mVBTransFactor, - rTransform.m21(), rTransform.m22(), 0, 0)); - item->setPos((x - mViewBoxCenter.x() + (newVector - oldVector).x()) * xScale * mVBTransFactor, - (y - mViewBoxCenter.y() + (newVector - oldVector).y()) * yScale * mVBTransFactor); - } - else - { - qreal fullScaleX = mVBTransFactor * xScale; - qreal fullScaleY = mVBTransFactor * yScale; + + item->setTransform(rTransform.scale(fullScaleX, fullScaleY)); + item->setPos((x - mViewBoxCenter.x() + (newVector - oldVector).x()) * mVBTransFactor, + (y - mViewBoxCenter.y() + (newVector - oldVector).y()) * mVBTransFactor); + } else { //item is't rotated or translated item->setTransform(QTransform(fullScaleX, 0, 0, fullScaleY, 0, 0)); itemBounds = item->boundingRect(); item->setPos((int)((x - mViewBoxCenter.x()) * mVBTransFactor), (int)((y - mViewBoxCenter.y()) * mVBTransFactor)); - QPointF newPos = item->pos(); - qDebug(); } - - QTransform newTrans = item->transform(); -// qWarning() << QString("Item new transform = %3 0 0 %4 %1 %2, position %5, %6").arg(newTrans.dx()).arg(newTrans.dy()).arg(newTrans.m11()).arg(newTrans.m22()).arg(item->x()).arg(item->y()); - } void UBCFFSubsetAdaptor::UBCFFSubsetReader::experimentalReposition(QGraphicsItem *item, qreal width, qreal height, qreal x, qreal y, diff --git a/src/adaptors/UBCFFSubsetAdaptor.h b/src/adaptors/UBCFFSubsetAdaptor.h index 45ba431b..94d4c9a5 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.h +++ b/src/adaptors/UBCFFSubsetAdaptor.h @@ -95,8 +95,13 @@ private: inline bool parseSvgVideo(const QDomElement &element); inline bool parseIwbGroup(QDomElement &parent); inline bool parseIwbElement(QDomElement &element); + inline void parseTSpan(const QDomElement &parent, QPainter &painter + , qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect + , qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic + , int &fontWeight, int &textAlign, QTransform &fontTransform); inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item); + // to kill void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic, diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 4f616a4b..b46796f7 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -139,7 +139,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); } - UBGraphicsScene::~UBGraphicsScene() { // NOOP