diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp
index 2661f667..5e970806 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)
@@ -298,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;
@@ -308,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()) {
@@ -317,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();
@@ -329,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;
@@ -339,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));
@@ -359,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();
@@ -371,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;
@@ -556,173 +440,108 @@ 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;
+ qreal x = element.attribute(aX).toDouble();
+ qreal y = element.attribute(aY).toDouble();
+ qreal width = element.attribute(aWidth).toDouble();
+ qreal height = element.attribute(aHeight).toDouble();
-// // 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);
+ 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);
-// 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();
+ QSvgGenerator *generator = createSvgGenerator(width, height);
+ QPainter painter;
+ painter.begin(generator);
+ painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic));
-// //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 curY = 0.0;
+ qreal curX = 0.0;
+ qreal linespacing = QFontMetricsF(painter.font()).leading();
-// continue;
-// }
-// }
+// remember if text area has transform
+// QString transformString;
+ QTransform transform = fontTransform;
+ bool hasTransform = !fontTransform.isIdentity();
-// QSvgGenerator *generator = createSvgGenerator(width, height);
-// QPainter painter;
-// painter.begin(generator);
+ QRectF lastDrawnTextBoundingRect;
+ //parse text area tags
-// if (textRects.count() != 0)
-// {
-// QListIterator textRectsIter(textRects);
-// QListIterator textFontsIter(textFonts);
-// QListIterator textLinesIter(textLines);
-// QListIterator textAlignsIter(textAligns);
-// QListIterator textColorsIter(textColors);
+ //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);
-// 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();
-// painter.end();
+ //add resulting svg file to scene
+ UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName()));
+ repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform);
-// //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;
+}
-// delete generator;
+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) {
- return true;
+ 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;
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;
@@ -741,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, y, hasTransform, transform);
- delete generator;
+ delete generator;
return true;
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element)
@@ -800,7 +590,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,933 +606,520 @@ 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);
-// hashSceneItem(element, pixItem->);
+ repositionSvgItem(pixItem, width, height, x, y, hastransform, transform);
+// experimentalReposition(pixItem, width, height, x, y, hastransform, transform);
+ hashSceneItem(element, pixItem);
- return true;
+ return true;
}
-
-void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSectionAttr(const QDomElement &svgSection)
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &element)
{
- getViewBoxDimenstions(svgSection.attribute(aViewbox));
- mSize = QSize(svgSection.attribute(aWidth).toInt(),
- svgSection.attribute(aHeight).toInt());
-}
+ QString itemRefPath = element.attribute(aHref);
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGroup(QDomNode *group)
-{
- 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);
- }
+ 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;
}
- curGroupPtr = curGroupPtr.nextSiblingElement(tElement);
+ urlPath = QUrl::fromLocalFile(flashPath);
}
- 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);
-//}
-
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &parent)
-{
- QString tagName = parent.tagName();
- if (parent.namespaceURI() != svgNS) {
- qDebug() << "Incorrect namespace, error at content file, line number" << parent.lineNumber();
+ 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);
- if (tagName == tRect && !parseSvgRect(parent)) return false;
- else if (tagName == tEllipse && !parseSvgEllipse(parent)) return false;
- else if (tagName == tPolygon && !parseSvgPolygon(parent)) return false;
- else if (tagName == tPolyline && !parseSvgPolyline(parent)) return false;
- else if (tagName == tText && !parseSvgText(parent)) return false;
- else if (tagName == tTextarea && !parseSvgTextarea(parent)) return false;
- else if (tagName == tImage && !parseSvgImage(parent)) return false;
-
- return true;
-}
-
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPage(const QDomElement &parent)
-{
- createNewScene();
- QDomElement currentSvgElement = parent.firstChildElement();
- while (!currentSvgElement.isNull()) {
- if (!parseSvgElement(currentSvgElement))
- return false;
-
- currentSvgElement = currentSvgElement.nextSiblingElement();
- }
- persistCurrentScene();
- return true;
-}
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPageset(const QDomElement &parent)
-{
- QDomElement currentPage = parent.firstChildElement(tPage);
- while (!currentPage.isNull()) {
- if (!parseSvgPage(currentPage))
- return false;
- currentPage = currentPage.nextSiblingElement(tPage);
+ QTransform transform;
+ QString textTransform = element.attribute(aTransform);
+ bool hastransform = false;
+ if (!textTransform.isNull()) {
+ transform = transformFromString(textTransform);
+ hastransform = true;
}
+ repositionSvgItem(flashItem, width, height, x, y, true, transform);
+ hashSceneItem(element, flashItem);
+
return true;
}
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgAudio(const QDomElement &element)
{
- if (!hashElements()) return false; //hashing all elements having id attribute
-
- QDomElement svgSection = mDOMdoc.elementsByTagNameNS(svgNS, tSvg).at(0).toElement();
- parseSvgSectionAttr(svgSection);
+ qreal x = element.attribute(aX).toDouble();
+ qreal y = element.attribute(aY).toDouble();
+ qreal width = element.attribute(aWidth).toDouble();
+ qreal height = element.attribute(aHeight).toDouble();
- QDomElement currentSvg = svgSection.firstChildElement();
+ QString itemRefPath = element.attribute(aHref);
- if (currentSvg.tagName() != tPageset) {
- parseSvgPage(svgSection);
- } else if (currentSvg.tagName() == tPageset){
- parseSvgPageset(currentSvg);
+ 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);
+ }
-
-// 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());
+ 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::parseCurrentElementStart()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &element)
{
- 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;
+ QString itemRefPath = element.attribute(aHref);
+ if (itemRefPath.startsWith(tFlash + "/") && itemRefPath.endsWith(".swf")) {
+ if (parseSvgFlash(element)) return true;
+ else 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;
- }
- else
- if ( elName == tPage)
- {
- if (!parsePage())
- 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();
- PushState(PAGE);
- }
- else
- if ( elName == tPageset)
- {
- if (!parsePageSet())
+ 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;
-
- PushState(PAGESET);
+ }
+ urlPath = QUrl::fromLocalFile(videoPath);
}
- else
- if ( elName == tElement)
- {
- if (!parseIwbElementRef())
- return false;
+
+ 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;
}
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementCharacters()
+void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSectionAttr(const QDomElement &svgSection)
{
- return true;
+ getViewBoxDimenstions(svgSection.attribute(aViewbox));
+ mSize = QSize(svgSection.attribute(aWidth).toInt(),
+ svgSection.attribute(aHeight).toInt());
}
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementEnd()
+void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(const QDomElement &element, UBGraphicsItem *item)
{
- QStringRef elName = mReader.name();
- mIndent.remove(0,1);
- QString log = QString("%1%2>").arg(mIndent).arg(elName.toString());
- qDebug() << log;
+// adding element pointer to hash to refer if needed
+ QString key = element.attribute(aId);
+ if (!key.isNull()) {
+ persistedItems.insert(key, item);
- 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();
+ QHash::iterator iter;
+ iter = persistedItems.find(key);
+ UBGraphicsItem *itered = *iter;
+ if (key == "background")
+ itered->Delegate()->lock(true);
}
-
- return true;
}
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwb()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &parent)
{
- if (!stateStack.empty() || currentState != NONE)
- {
- qWarning() << "iwb content parse error, unexpected iwb tag at line" << mReader.lineNumber();
+ QString tagName = parent.tagName();
+ if (parent.namespaceURI() != svgNS) {
+ qDebug() << "Incorrect namespace, error at content file, line number" << parent.lineNumber();
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;
+ else if (tagName == tPolyline && !parseSvgPolyline(parent)) return false;
+ 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;
}
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPage(const QDomElement &parent)
{
- if (currentState != IWB)
- {
- qWarning() << "iwb content parse error, unexpected meta tag at line" << mReader.lineNumber();
- return false;
- }
+ createNewScene();
+ QDomElement currentSvgElement = parent.firstChildElement();
+ while (!currentSvgElement.isNull()) {
+ if (!parseSvgElement(currentSvgElement))
+ return false;
+ currentSvgElement = currentSvgElement.nextSiblingElement();
+ }
+ persistCurrentScene();
return true;
}
-
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPageset(const QDomElement &parent)
{
- if (currentState != IWB)
- {
- qWarning() << "iwb content parse error, unexpected svg tag at line" << mReader.lineNumber();
- return false;
+ QDomElement currentPage = parent.firstChildElement(tPage);
+ while (!currentPage.isNull()) {
+ if (!parseSvgPage(currentPage))
+ return false;
+ currentPage = currentPage.nextSiblingElement(tPage);
}
-
- getViewBoxDimenstions(mReader.attributes().value(aViewbox).toString());
- mSize = QSize(mReader.attributes().value(aWidth).toString().toInt(),
- mReader.attributes().value(aHeight).toString().toInt());
-
return true;
}
-void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(UBGraphicsSvgItem *item, qreal width, qreal height,
- 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
- 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();
-
- 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);
- }
-
- 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::repositionPixmapItem(UBGraphicsPixmapItem *item, qreal width, qreal height,
- qreal x, qreal y,
- bool useTransform, QTransform &transform)
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta(const QDomElement &element)
{
- //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();
-
- 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);
+ if (element.namespaceURI() != iwbNS) {
+ qDebug() << "incorrect meta namespace, incorrect document";
+ return false;
}
+ return true;
}
-
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseRect()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg(const QDomElement &svgSection)
{
- if (currentState != SVG && currentState != PAGE)
- {
- qWarning() << "iwb content parse error, unexpected rect tag at line" << mReader.lineNumber();
+ if (svgSection.namespaceURI() != svgNS) {
+ qDebug() << "incorrect svg namespace, incorrect document";
return false;
}
- //create new scene if it's not created yet (for one page document case)
- if (currentState == SVG && mCurrentScene == NULL)
- createNewScene();
+ parseSvgSectionAttr(svgSection);
+ QDomElement currentSvg = svgSection.firstChildElement();
- //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();
-
- //init svg generator with temp file
- QSvgGenerator *generator = createSvgGenerator(width + 10, height + 10);
-
- //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);
+ if (currentSvg.tagName() != tPageset) {
+ parseSvgPage(svgSection);
+ } else if (currentSvg.tagName() == tPageset){
+ parseSvgPageset(currentSvg);
}
- 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()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGroup(QDomElement &parent)
{
- if (currentState != SVG && currentState != PAGE)
- {
- qWarning() << "iwb content parse error, unexpected ellipse tag at line" << mReader.lineNumber();
+ if (parent.namespaceURI() != iwbNS) {
+ qDebug() << "incorrect iwb group namespace, incorrect document";
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()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::strToBool(QString str)
{
- if (currentState != SVG && currentState != PAGE)
- {
- qWarning() << "iwb content parse error, unexpected textarea tag at line" << mReader.lineNumber();
+ return str == "true";
+}
+
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElement(QDomElement &element)
+{
+ if (element.namespaceURI() != iwbNS) {
+ qDebug() << "incorrect iwb element namespace, incorrect document";
return false;
}
- //create new scene if it's not created yet (for one page document case)
- if (currentState == SVG && mCurrentScene == NULL)
- createNewScene();
+ 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;
- //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;
+ 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");
}
- 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;
+// UBGraphicsItem *referedItem = *(persistedItems.find(IDRef));
+// referedItem->Delegate()->lock(locked);
- //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()
+bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc()
{
- 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();
+ 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;
- 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(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();
-
- //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;
- }
+ currentTopElement = currentTopElement.nextSiblingElement();
}
-
- 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()
+void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(QGraphicsItem *item, qreal width, qreal height,
+ qreal x, qreal y,
+ bool useTransform, QTransform &transform)
{
- if (currentState != SVG && currentState != PAGE)
- {
- qWarning() << "iwb content parse error, unexpected polygon tag at line" << mReader.lineNumber();
- return false;
- }
+ //First using viebox coordinates, then translate them to scene coordinates
- //create new scene if it's not created yet (for one page document case)
- if (currentState == SVG && mCurrentScene == NULL)
- createNewScene();
+ QRectF itemBounds = item->boundingRect();
- QStringRef svgPoints = mReader.attributes().value("points");
- QPolygonF polygon;
+ qreal xScale = width / itemBounds.width();
+ qreal yScale = height / itemBounds.height();
- if (!svgPoints.isNull()) {
- QStringList ts = svgPoints.toString().split(QLatin1Char(' '),
- QString::SkipEmptyParts);
+ qreal fullScaleX = mVBTransFactor * xScale;
+ qreal fullScaleY = mVBTransFactor * yScale;
- 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;
- }
- }
+ 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);
+
+ 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));
}
+}
+void UBCFFSubsetAdaptor::UBCFFSubsetReader::experimentalReposition(QGraphicsItem *item, qreal width, qreal height,
+ qreal x, qreal y,
+ bool useTransform, QTransform &transform)
+{
+ Q_UNUSED(useTransform)
+ Q_UNUSED(transform)
- //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();
+ QRectF itemBounds = item->boundingRect();
- 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());
+ qreal xScale = width / itemBounds.width();
+ qreal yScale = height / itemBounds.height();
- QBrush brush;
- if (mReader.attributes().hasAttribute(aFill)) {
- brush.setColor(colorFromString(mReader.attributes().value(aFill).toString()));
- brush.setStyle(Qt::SolidPattern);
- }
+ qreal newX = (x - mViewBox.center().x()) * xScale * mVBTransFactor;
+ qreal newY = (y - mViewBox.center().y()) * yScale * mVBTransFactor;
- QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width());
- QPainter painter;
+// 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));
- painter.begin(generator); //drawing to svg tmp file
+ QPointF newPos(newX, newY);
- painter.translate(pen.widthF() / 2 - x1, pen.widthF() / 2 - y1);
- painter.setBrush(brush);
- painter.setPen(pen);
- painter.drawPolygon(polygon);
+ item->setTransform(QTransform(xScale * mVBTransFactor, 0, 0, yScale * mVBTransFactor, 0, 0));
+ item->setPos(newPos);
- painter.end();
+ item->setPos(newPos);
- //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;
+ qDebug();
- return true;
+
+
+ // 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::parsePolyline()
-{
- if (currentState != SVG && currentState != PAGE)
- {
- qWarning() << "iwb content parse error, unexpected polyline tag at line" << mReader.lineNumber();
- return false;
- }
+//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();
+// //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;
+// qreal x = mReader.attributes().value(aX).toString().toDouble();
+// qreal y = mReader.attributes().value(aY).toString().toDouble();
- if (!svgPoints.isNull()) {
- QStringList ts = svgPoints.toString().split(QLatin1Char(' '),
- QString::SkipEmptyParts);
+// qreal width = 0;
+// qreal height = 0;
- 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());
- }
+// QList textRects;
+// QList textFonts;
+// QList textLines;
+// QList textAligns;
+// QList textColors;
- //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();
+// qWarning() << QString().sprintf("Text coordinates : %f,%f. Text size %f,%f", x, y, width, 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());
+// qreal fontSize = 12.0;
+// QFont textFont;
+// QColor fontColor;
+// QString fontFamily = "Arial";
+// QString fontStretch = "normal";
- QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width());
- QPainter painter;
+// 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);
- painter.begin(generator); //drawing to svg tmp file
+// QFontMetricsF metrics = QFontMetricsF(textFont);
+// qreal curHeight = metrics.height();
- painter.translate(pen.widthF() / 2, pen.widthF() / 2);
- painter.setPen(pen);
- painter.drawPolyline(polygon);
+// qreal curY = 0.0;
+// qreal curX = 0.0;
- painter.end();
+// qreal linespacing = QFontMetrics(textFont).leading();
- //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;
+// //remember if text area has transform
+// QTransform transform;
+// bool hasTransform = getCurElementTransorm(transform);
- return true;
-}
+// QRectF lastDrawnTextBoundingRect;
-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;
-}
+// QStack fontStack;
+// QStack colorStack;
+// QStack alignStack;
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parsePageSet()
-{
- if (currentState != SVG)
- {
- qWarning() << "iwb content parse error, unexpected page tag at line" << mReader.lineNumber();
- return false;
- }
+// // 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);
- return true;
-}
+// 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();
-bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElementRef()
-{
- if (currentState != IWB)
- {
- qWarning() << "iwb content parse error, unexpected element tag at line" << mReader.lineNumber();
- return false;
- }
+// //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;
+// }
+// }
- return true;
-}
+// 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::createNewScene()
{
mCurrentScene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mProxy, mProxy->pageCount());
mCurrentSceneRect = mCurrentScene->normalizedSceneRect();
+ mVBTransFactor = qMin(mCurrentSceneRect.width() / mViewPort.width(),
+ mCurrentSceneRect.height() / mViewPort.height());
return true;
}
@@ -1786,17 +1163,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;
@@ -1836,8 +1202,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;
}
}
@@ -1850,8 +1219,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));
@@ -1879,64 +1248,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 dcddefdd..94d4c9a5 100644
--- a/src/adaptors/UBCFFSubsetAdaptor.h
+++ b/src/adaptors/UBCFFSubsetAdaptor.h
@@ -30,17 +30,9 @@ class UBGraphicsPixmapItem;
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
{
@@ -52,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;
@@ -79,6 +58,8 @@ private:
QRectF mCurrentSceneRect;
QString mIndent;
QRectF mViewBox;
+ QRectF mViewPort;
+ qreal mVBTransFactor;
QPointF mViewBoxCenter;
QSize mSize;
@@ -86,8 +67,8 @@ private:
// to kill
QDomDocument mDOMdoc;
QDomNode mCurrentDOMElement;
- QHash iwbExtProperties;
- QHash persistedItems;
+ QHash persistedItems;
+ QDir mTmpFlashDir;
bool hashElements();
void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup);
@@ -99,6 +80,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);
@@ -107,61 +90,44 @@ 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 void hashSceneItem(QDomNode *element, UBGraphicsItemDelegate *item);
+ 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 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,
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);
+ 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);
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/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.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 fcab9f8d..055a5de3 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);
@@ -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;
@@ -129,17 +131,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 +168,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..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();
- 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/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp
index 58c57a02..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
@@ -165,8 +164,6 @@ void UBGraphicsScene::selectionChangedProcessing()
nextItem->setZValue(2);
qDebug() << QString(" >>> %1 <<< ").arg(i) << QString(" >>> %1 <<< ").arg(zValue);
}
-
-
}
// MARK: -
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/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 5cd14d13..58f61867 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 = 0;
+ virtual void remove() = 0;
- virtual void remove() = 0;
};
#endif // UBITEM_H
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 +"');}");
-
}
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..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:
@@ -65,7 +66,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;