Commit 37afb699 authored by Ivan Ilin's avatar Ivan Ilin

Merge branch 'CFFBranch'

parents 0898bc53 61d46015
...@@ -12,12 +12,10 @@ ...@@ -12,12 +12,10 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QRegExp> #include <QRegExp>
#include <QSvgGenerator> #include <QSvgGenerator>
#include <QSvgRenderer> #include <QSvgRenderer>
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
...@@ -26,6 +24,12 @@ ...@@ -26,6 +24,12 @@
#include "domain/UBGraphicsTextItem.h" #include "domain/UBGraphicsTextItem.h"
#include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsPixmapItem.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 "UBCFFSubsetAdaptor.h"
#include "UBMetadataDcSubsetAdaptor.h" #include "UBMetadataDcSubsetAdaptor.h"
...@@ -35,7 +39,7 @@ ...@@ -35,7 +39,7 @@
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "QFile" #include "QFile"
#include "QDomDocument" #include <QDomDocument>
//enum of xmlparse status //enum of xmlparse status
...@@ -57,6 +61,10 @@ static QString tTextarea = "textarea"; ...@@ -57,6 +61,10 @@ static QString tTextarea = "textarea";
static QString tTspan = "tspan"; static QString tTspan = "tspan";
static QString tBreak = "tbreak"; static QString tBreak = "tbreak";
static QString tImage = "image"; static QString tImage = "image";
static QString tFlash = "flash";
static QString tAudio = "audio";
static QString tVideo = "video";
//attribute names definition //attribute names definition
static QString aFill = "fill"; static QString aFill = "fill";
...@@ -85,6 +93,8 @@ static QString iwbNS = "http://www.becta.org.uk/iwb"; ...@@ -85,6 +93,8 @@ static QString iwbNS = "http://www.becta.org.uk/iwb";
static QString aId = "id"; static QString aId = "id";
static QString aRef = "ref"; static QString aRef = "ref";
static QString aHref = "href"; static QString aHref = "href";
static QString aBackground = "background";
static QString aLocked = "locked";
//attributes part names //attributes part names
static QString apRotate = "rotate"; static QString apRotate = "rotate";
...@@ -92,115 +102,7 @@ static QString apTranslate = "translate"; ...@@ -92,115 +102,7 @@ static QString apTranslate = "translate";
UBCFFSubsetAdaptor::UBCFFSubsetAdaptor() UBCFFSubsetAdaptor::UBCFFSubsetAdaptor()
{ {}
}
void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSiblingIwbElements(QDomElement *parent, QDomElement *topGroup) {
QDomElement curExt = parent->firstChildElement(tElement);
while (!curExt.isNull()) {
if (curExt.namespaceURI() != iwbNS)
continue;
QHash<QString, IwbExt>::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) bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentProxy* pDocument)
{ {
...@@ -224,7 +126,7 @@ bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentP ...@@ -224,7 +126,7 @@ bool UBCFFSubsetAdaptor::ConvertCFFFileToUbz(QString &cffSourceFile, UBDocumentP
} }
UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content): UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content):
mReader(content), mProxy(proxy), currentState(NONE) mProxy(proxy)
{ {
int errorLine, errorColumn; int errorLine, errorColumn;
QString errorStr; QString errorStr;
...@@ -235,11 +137,6 @@ UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy, ...@@ -235,11 +137,6 @@ UBCFFSubsetAdaptor::UBCFFSubsetReader::UBCFFSubsetReader(UBDocumentProxy *proxy,
qDebug() << "well parsed to DOM"; qDebug() << "well parsed to DOM";
pwdContent = QFileInfo(content->fileName()).dir().absolutePath(); 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; qDebug() << "tmp path is" << pwdContent;
} }
...@@ -248,9 +145,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse() ...@@ -248,9 +145,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse()
UBMetadataDcSubsetAdaptor::persist(mProxy); UBMetadataDcSubsetAdaptor::persist(mProxy);
mIndent = ""; mIndent = "";
if (!getTempFileName()) if (!getTempFileName() || !createTempFlashPath())
return false; return false;
if (mDOMdoc.isNull()) if (mDOMdoc.isNull())
return false; return false;
...@@ -261,24 +159,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse() ...@@ -261,24 +159,10 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parse()
if (QFile::exists(mTempFilePath)) if (QFile::exists(mTempFilePath))
QFile::remove(mTempFilePath); QFile::remove(mTempFilePath);
return result; // if (mTmpFlashDir.exists())
} // UBFileSystemUtils::deleteDir(mTmpFlashDir.path());
int UBCFFSubsetAdaptor::UBCFFSubsetReader::PopState()
{
if (stateStack.count() == 0)
currentState = NONE;
else
currentState = stateStack.pop();
return currentState;
}
void UBCFFSubsetAdaptor::UBCFFSubsetReader::PushState(int state) return result;
{
if (currentState != NONE)
stateStack.push(currentState);
currentState = state;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &element)
...@@ -298,7 +182,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem ...@@ -298,7 +182,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem
int strokeWidth = !textStrokeWidth.isNull() ? textStrokeWidth.toInt() : 0; int strokeWidth = !textStrokeWidth.isNull() ? textStrokeWidth.toInt() : 0;
//init svg generator with temp file //init svg generator with temp file
QSvgGenerator *generator = createSvgGenerator(width + 10, height + 10); QSvgGenerator *generator = createSvgGenerator(width, height);
//init painter to paint to svg //init painter to paint to svg
QPainter painter; QPainter painter;
...@@ -308,7 +192,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem ...@@ -308,7 +192,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem
//fill rect //fill rect
if (fillColor.isValid()) { if (fillColor.isValid()) {
painter.setBrush(QBrush(fillColor)); painter.setBrush(QBrush(fillColor));
painter.fillRect(5, 5, width, height, fillColor); painter.fillRect(0, 0, width, height, fillColor);
} }
QPen pen; QPen pen;
if (strokeColor.isValid()) { if (strokeColor.isValid()) {
...@@ -317,7 +201,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem ...@@ -317,7 +201,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem
if (strokeWidth) if (strokeWidth)
pen.setWidth(strokeWidth); pen.setWidth(strokeWidth);
painter.setPen(pen); painter.setPen(pen);
painter.drawRect(5, 5, width, height); painter.drawRect(0, 0, width, height);
painter.end(); painter.end();
...@@ -329,7 +213,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem ...@@ -329,7 +213,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgRect(const QDomElement &elem
transform = transformFromString(textTransform); transform = transformFromString(textTransform);
hastransform = true; hastransform = true;
} }
repositionSvgItem(svgItem, width + 10, height + 10, x1 - 5, y1 - 5, hastransform, transform); repositionSvgItem(svgItem, width, height, x1, y1, hastransform, transform);
delete generator; delete generator;
return true; return true;
...@@ -339,7 +223,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e ...@@ -339,7 +223,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e
//ellipse horisontal and vertical radius //ellipse horisontal and vertical radius
qreal rx = element.attribute(aRx).toDouble(); qreal rx = element.attribute(aRx).toDouble();
qreal ry = element.attribute(aRy).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 //fill and stroke color
QColor fillColor = colorFromString(element.attribute(aFill)); QColor fillColor = colorFromString(element.attribute(aFill));
...@@ -359,7 +243,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e ...@@ -359,7 +243,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e
painter.setPen(pen); painter.setPen(pen);
painter.setBrush(QBrush(fillColor)); painter.setBrush(QBrush(fillColor));
painter.drawEllipse(5, 5, rx * 2, ry * 2); painter.drawEllipse(0, 0, rx * 2, ry * 2);
painter.end(); painter.end();
...@@ -371,7 +255,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e ...@@ -371,7 +255,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgEllipse(const QDomElement &e
transform = transformFromString(textTransform); transform = transformFromString(textTransform);
hastransform = true; 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; delete generator;
return true; return true;
...@@ -556,173 +440,108 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTextAttributes(const QDomElemen ...@@ -556,173 +440,108 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTextAttributes(const QDomElemen
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgText(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgText(const QDomElement &element)
{ {
// qreal x = element.attribute(aX).toDouble(); qreal x = element.attribute(aX).toDouble();
// qreal y = element.attribute(aY).toDouble();; qreal y = element.attribute(aY).toDouble();
qreal width = element.attribute(aWidth).toDouble();
// qreal width = 0; qreal height = element.attribute(aHeight).toDouble();
// qreal height = 0;
// QList<QRectF> textRects;
// QList<QFont> textFonts;
// QList<QString> textLines;
// QList<int> textAligns;
// QList<QColor> 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<QFont> fontStack;
// QStack<QColor> colorStack;
// QStack<int> alignStack;
// // first extimate desired text area size qreal fontSize = 12;
// // to do that, parse text area tags QColor fontColor(qApp->palette().foreground().color());
// while(true) QString fontFamily = "Arial";
// { QString fontStretch = "normal";
// mReader.readNext(); bool italic = false;
// QStringRef elementName = mReader.name(); int fontWeight = QFont::Normal;
// if (mReader.isEndDocument()) int textAlign = Qt::AlignLeft;
// break; QTransform fontTransform;
// if (mReader.isEndElement()) parseTextAttributes(element, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform);
// {
// 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); QSvgGenerator *generator = createSvgGenerator(width, height);
// textFont = QFont(fontFamily, fontSize, fontWeight, italic); QPainter painter;
// metrics = QFontMetricsF(textFont); painter.begin(generator);
// curHeight = metrics.height(); painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic));
// linespacing = QFontMetricsF(textFont).leading();
// continue;
// }
// if (mReader.isCharacters() || mReader.isCDATA())
// {
// QString text = mReader.text().toString();
// //skip empty text qreal curY = 0.0;
// if (text.trimmed().length() == 0) qreal curX = 0.0;
// continue; qreal linespacing = QFontMetricsF(painter.font()).leading();
// //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; // remember if text area has transform
// } // QString transformString;
// } QTransform transform = fontTransform;
bool hasTransform = !fontTransform.isIdentity();
// QSvgGenerator *generator = createSvgGenerator(width, height); QRectF lastDrawnTextBoundingRect;
// QPainter painter; //parse text area tags
// painter.begin(generator);
// if (textRects.count() != 0) //recursive call any tspan in text svg element
// { parseTSpan(element, painter
// QListIterator<QRectF> textRectsIter(textRects); , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect
// QListIterator<QFont> textFontsIter(textFonts); , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform);
// QListIterator<QString> textLinesIter(textLines);
// QListIterator<int> textAlignsIter(textAligns);
// QListIterator<QColor> textColorsIter(textColors);
// while (textRectsIter.hasNext()) painter.end();
// {
// 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);
// //add resulting svg file to scene delete generator;
// UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); return true;
// repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); }
// 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) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement &element)
{ {
//TODO textarea node
qreal x = element.attribute(aX).toDouble(); qreal x = element.attribute(aX).toDouble();
qreal y = element.attribute(aY).toDouble(); qreal y = element.attribute(aY).toDouble();
qreal width = element.attribute(aWidth).toDouble(); qreal width = element.attribute(aWidth).toDouble();
qreal height = element.attribute(aHeight).toDouble(); qreal height = element.attribute(aHeight).toDouble();
qreal fontSize = 12; qreal fontSize = 12;
QColor fontColor; QColor fontColor(qApp->palette().foreground().color());
QString fontFamily = "Arial"; QString fontFamily = "Arial";
QString fontStretch = "normal"; QString fontStretch = "normal";
bool italic = false; bool italic = false;
int fontWeight = QFont::Normal; int fontWeight = QFont::Normal;
int textAlign = Qt::AlignLeft; int textAlign = Qt::AlignLeft;
QTransform fontTransform; 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); QSvgGenerator *generator = createSvgGenerator(width, height);
QPainter painter; QPainter painter;
...@@ -741,47 +560,18 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement & ...@@ -741,47 +560,18 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement &
QRectF lastDrawnTextBoundingRect; QRectF lastDrawnTextBoundingRect;
//parse text area tags //parse text area tags
QDomElement curTextElement = element.firstChildElement(); //recursive call any tspan in text svg element
while (!curTextElement.isNull()) { parseTSpan(element, painter
QString tagName = curTextElement.tagName(); , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect
if (tagName == tTspan) { , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform);
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();
}
painter.end(); painter.end();
//add resulting svg file to scene //add resulting svg file to scene
UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName()));
repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform);
delete generator;
delete generator;
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element)
...@@ -800,7 +590,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele ...@@ -800,7 +590,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele
qDebug() << "can't load file" << pwdContent + "/" + itemRefPath << "maybe file corrupted"; qDebug() << "can't load file" << pwdContent + "/" + itemRefPath << "maybe file corrupted";
return false; return false;
} else { } else {
qDebug() << "size of file" << itemRefPath << QFileInfo(itemRefPath).size(); // qDebug() << "size of file" << itemRefPath << QFileInfo(itemRefPath).size();
} }
pix.load(imagePath); pix.load(imagePath);
if (pix.isNull()) { if (pix.isNull()) {
...@@ -816,49 +606,144 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele ...@@ -816,49 +606,144 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &ele
transform = transformFromString(textTransform); transform = transformFromString(textTransform);
hastransform = true; hastransform = true;
} }
// repositionSvgItem(svgItem, rx * 2 + 10, ry * 2 + 10, cx - rx - 5, cy - ry -5, hastransform, transform); repositionSvgItem(pixItem, width, height, x, y, hastransform, transform);
repositionPixmapItem(pixItem, width, height, x, y, hastransform, transform); // experimentalReposition(pixItem, width, height, x, y, hastransform, transform);
// hashSceneItem(element, pixItem->); hashSceneItem(element, pixItem);
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgFlash(const QDomElement &element)
void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgSectionAttr(const QDomElement &svgSection)
{ {
getViewBoxDimenstions(svgSection.attribute(aViewbox)); QString itemRefPath = element.attribute(aHref);
mSize = QSize(svgSection.attribute(aWidth).toInt(),
svgSection.attribute(aHeight).toInt());
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGroup(QDomNode *group) qreal x = element.attribute(aX).toDouble();
{ qreal y = element.attribute(aY).toDouble();
QDomElement curGroupPtr = group->firstChildElement(); qreal width = element.attribute(aWidth).toDouble();
qreal height = element.attribute(aHeight).toDouble();
while (!curGroupPtr.isNull()) {
if (curGroupPtr.namespaceURI() != iwbNS) QUrl urlPath;
continue; QString flashPath;
if (curGroupPtr.hasChildNodes() && curGroupPtr.toElement().tagName() == tGroup) { if (!itemRefPath.isNull()) {
parseIwbGroup(&curGroupPtr); flashPath = pwdContent + "/" + itemRefPath;
} else if (curGroupPtr.toElement().tagName() == tElement) { if (!QFile::exists(flashPath)) {
QHash<QString, IwbExt>::iterator iSvgElementExt = iwbExtProperties.find(curGroupPtr.attribute(aRef)); qDebug() << "can't load file" << pwdContent + "/" + itemRefPath << "maybe file corrupted";
if (iSvgElementExt != iwbExtProperties.end()) { return false;
IwbExt &svgElementExt = *iSvgElementExt; }
QDomNode &svgElement = svgElementExt.element; urlPath = QUrl::fromLocalFile(flashPath);
svgElement.parentNode().removeChild(svgElement); }
} QDir tmpFlashDir(mTmpFlashDir);
if (!tmpFlashDir.exists()) {
qDebug() << "Can't create temporary directory to put flash";
return false;
} }
curGroupPtr = curGroupPtr.nextSiblingElement(tElement);
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, y, true, transform);
hashSceneItem(element, flashItem);
return true; return true;
} }
//void UBCFFSubsetAdaptor::UBCFFSubsetReader::hashSceneItem(QDomNode &element, UBGraphicsItemDelegate *item) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgAudio(const QDomElement &element)
//{ {
//// adding element pointer to hash to refer if needed qreal x = element.attribute(aX).toDouble();
// QString key = element.attribute(aId); qreal y = element.attribute(aY).toDouble();
// if (!key.isNull()) qreal width = element.attribute(aWidth).toDouble();
// persistedItems.insert(key, item); 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)
{
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;
}
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()) {
persistedItems.insert(key, item);
QHash<QString, UBGraphicsItem*>::iterator iter;
iter = persistedItems.find(key);
UBGraphicsItem *itered = *iter;
if (key == "background")
itered->Delegate()->lock(true);
}
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &parent) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &parent)
{ {
...@@ -868,7 +753,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &p ...@@ -868,7 +753,6 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &p
return false; return false;
} }
if (tagName == tRect && !parseSvgRect(parent)) return false; if (tagName == tRect && !parseSvgRect(parent)) return false;
else if (tagName == tEllipse && !parseSvgEllipse(parent)) return false; else if (tagName == tEllipse && !parseSvgEllipse(parent)) return false;
else if (tagName == tPolygon && !parseSvgPolygon(parent)) return false; else if (tagName == tPolygon && !parseSvgPolygon(parent)) return false;
...@@ -876,6 +760,9 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &p ...@@ -876,6 +760,9 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgElement(const QDomElement &p
else if (tagName == tText && !parseSvgText(parent)) return false; else if (tagName == tText && !parseSvgText(parent)) return false;
else if (tagName == tTextarea && !parseSvgTextarea(parent)) return false; else if (tagName == tTextarea && !parseSvgTextarea(parent)) return false;
else if (tagName == tImage && !parseSvgImage(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; return true;
} }
...@@ -904,13 +791,23 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPageset(const QDomElement &p ...@@ -904,13 +791,23 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgPageset(const QDomElement &p
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta(const QDomElement &element)
{ {
if (!hashElements()) return false; //hashing all elements having id attribute if (element.namespaceURI() != iwbNS) {
qDebug() << "incorrect meta namespace, incorrect document";
return false;
}
QDomElement svgSection = mDOMdoc.elementsByTagNameNS(svgNS, tSvg).at(0).toElement(); return true;
parseSvgSectionAttr(svgSection); }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg(const QDomElement &svgSection)
{
if (svgSection.namespaceURI() != svgNS) {
qDebug() << "incorrect svg namespace, incorrect document";
return false;
}
parseSvgSectionAttr(svgSection);
QDomElement currentSvg = svgSection.firstChildElement(); QDomElement currentSvg = svgSection.firstChildElement();
if (currentSvg.tagName() != tPageset) { if (currentSvg.tagName() != tPageset) {
...@@ -919,830 +816,310 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc() ...@@ -919,830 +816,310 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc()
parseSvgPageset(currentSvg); 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; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementStart() bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbGroup(QDomElement &parent)
{ {
QStringRef elName = mReader.name(); if (parent.namespaceURI() != iwbNS) {
// QString log = QString("%1<%2>").arg(mIndent).arg(elName.toString()); qDebug() << "incorrect iwb group namespace, incorrect document";
// 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;
}
else
if ( elName == tPage)
{
if (!parsePage())
return false;
PushState(PAGE);
}
else
if ( elName == tPageset)
{
if (!parsePageSet())
return false;
PushState(PAGESET);
}
else
if ( elName == tElement)
{
if (!parseIwbElementRef())
return false; return false;
} }
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementCharacters() bool UBCFFSubsetAdaptor::UBCFFSubsetReader::strToBool(QString str)
{ {
return true; return str == "true";
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseCurrentElementEnd() bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbElement(QDomElement &element)
{ {
QStringRef elName = mReader.name(); if (element.namespaceURI() != iwbNS) {
mIndent.remove(0,1); qDebug() << "incorrect iwb element namespace, incorrect document";
QString log = QString("%1</%2>").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;
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwb()
{
if (!stateStack.empty() || currentState != NONE)
{
qWarning() << "iwb content parse error, unexpected iwb tag at line" << mReader.lineNumber();
return false; 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;
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseIwbMeta() QHash<QString, UBGraphicsItem*>::iterator iReferedItem;
{ iReferedItem = persistedItems.find(IDRef);
if (currentState != IWB) if (iReferedItem != persistedItems.end() && IDRef == "background") {
{ UBGraphicsItem *referedItem = *iReferedItem;
qWarning() << "iwb content parse error, unexpected meta tag at line" << mReader.lineNumber(); // UBGraphicsPixmapItem *item = dynamic_cast<UBGraphicsPixmapItem*>(referedItem);
return false; referedItem->Delegate()->lock(false);
referedItem->Delegate()->printMessage("called from extended");
} }
return true; // UBGraphicsItem *referedItem = *(persistedItems.find(IDRef));
} // referedItem->Delegate()->lock(locked);
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvg()
{
if (currentState != IWB)
{
qWarning() << "iwb content parse error, unexpected svg tag at line" << mReader.lineNumber();
return false;
} }
getViewBoxDimenstions(mReader.attributes().value(aViewbox).toString());
mSize = QSize(mReader.attributes().value(aWidth).toString().toInt(),
mReader.attributes().value(aHeight).toString().toInt());
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseDoc()
void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(UBGraphicsSvgItem *item, qreal width, qreal height,
qreal x, qreal y,
bool useTransform, QTransform &transform)
{ {
QTransform curTrans = item->transform(); QDomElement currentTopElement = mDOMdoc.documentElement().firstChildElement();
// 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()); while (!currentTopElement.isNull()) {
//check if rect is rotated QString tagName = currentTopElement.tagName();
//rotate svg item itself if (tagName == tMeta && !parseIwbMeta(currentTopElement)) return false;
QRectF itemBounds = item->boundingRect(); else if (tagName == tSvg && !parseSvg(currentTopElement)) return false;
//first, svg is mapped to svg item bound else if (tagName == tGroup && !parseIwbGroup(currentTopElement)) return false;
//second, svg item is mapped to scene else if (tagName == tElement && !parseIwbElement(currentTopElement)) return false;
//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) currentTopElement = currentTopElement.nextSiblingElement();
{
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);
} }
return true;
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,
void UBCFFSubsetAdaptor::UBCFFSubsetReader::repositionSvgItem(QGraphicsItem *item, qreal width, qreal height,
qreal x, qreal y, qreal x, qreal y,
bool useTransform, QTransform &transform) bool useTransform, QTransform &transform)
{ {
//if element is to transform //First using viebox coordinates, then translate them to scene coordinates
// 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); QRectF itemBounds = item->boundingRect();
qreal xScale = width / itemBounds.width();
qreal yScale = height / itemBounds.height();
QTransform curTrans = item->transform(); qreal fullScaleX = mVBTransFactor * xScale;
// 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()); qreal fullScaleY = mVBTransFactor * yScale;
//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) if (useTransform) { //if rotation or translation specified
{
QPointF oldVector((x - transform.dx()), (y - transform.dy())); QPointF oldVector((x - transform.dx()), (y - transform.dy()));
QTransform rTransform(transform.m11(), transform.m12(), transform.m21(), transform.m22(), 0, 0); QTransform rTransform(transform.m11(), transform.m12(), transform.m21(), transform.m22(), 0, 0);
QPointF newVector = rTransform.map(oldVector); 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);
}
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseRect()
{
if (currentState != SVG && currentState != PAGE)
{
qWarning() << "iwb content parse error, unexpected rect 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();
//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);
}
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 item->setTransform(rTransform.scale(fullScaleX, fullScaleY));
lastDrawnTextBoundingRect = painter.boundingRect(QRectF(curX, curY, width, height - curY), textAlign|Qt::TextWordWrap, text); item->setPos((x - mViewBoxCenter.x() + (newVector - oldVector).x()) * mVBTransFactor,
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()); (y - mViewBoxCenter.y() + (newVector - oldVector).y()) * mVBTransFactor);
qWarning() << "Text " << text << log; } else { //item is't rotated or translated
painter.drawText(curX, curY, width, lastDrawnTextBoundingRect.height(), textAlign|Qt::TextWordWrap, text); item->setTransform(QTransform(fullScaleX, 0, 0, fullScaleY, 0, 0));
curX += lastDrawnTextBoundingRect.x() + lastDrawnTextBoundingRect.width(); itemBounds = item->boundingRect();
item->setPos((int)((x - mViewBoxCenter.x()) * mVBTransFactor),
continue; (int)((y - mViewBoxCenter.y()) * mVBTransFactor));
}
} }
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;
} }
void UBCFFSubsetAdaptor::UBCFFSubsetReader::experimentalReposition(QGraphicsItem *item, qreal width, qreal height,
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseText() qreal x, qreal y,
{ bool useTransform, QTransform &transform)
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<QRectF> textRects;
QList<QFont> textFonts;
QList<QString> textLines;
QList<int> textAligns;
QList<QColor> 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<QFont> fontStack;
QStack<QColor> colorStack;
QStack<int> 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;
}
}
QSvgGenerator *generator = createSvgGenerator(width, height);
QPainter painter;
painter.begin(generator);
if (textRects.count() != 0)
{
QListIterator<QRectF> textRectsIter(textRects);
QListIterator<QFont> textFontsIter(textFonts);
QListIterator<QString> textLinesIter(textLines);
QListIterator<int> textAlignsIter(textAligns);
QListIterator<QColor> 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) Q_UNUSED(useTransform)
{ Q_UNUSED(transform)
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()) { QRectF itemBounds = item->boundingRect();
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 xScale = width / itemBounds.width();
qreal x1 = polygon.boundingRect().topLeft().x(); qreal yScale = height / itemBounds.height();
qreal y1 = polygon.boundingRect().topLeft().y();
//bounding rect dimensions
qreal width = polygon.boundingRect().width();
qreal height = polygon.boundingRect().height();
QPen pen; qreal newX = (x - mViewBox.center().x()) * xScale * mVBTransFactor;
if (mReader.attributes().hasAttribute(aStroke)) qreal newY = (y - mViewBox.center().y()) * yScale * mVBTransFactor;
pen.setColor(colorFromString(mReader.attributes().value(aStroke).toString()));
if (mReader.attributes().hasAttribute(aStrokewidth))
pen.setWidth(mReader.attributes().value(aStrokewidth).toString().toInt());
QBrush brush; // qDebug() << item->transform();
if (mReader.attributes().hasAttribute(aFill)) { // QTransform transform1(1, 0, 0, 1, mCurrentSceneRect.center().x(), mCurrentSceneRect.center().y());
brush.setColor(colorFromString(mReader.attributes().value(aFill).toString())); // QPointF newPos = QTransform(xScale * mVBTransFactor, 0, 0, yScale * mVBTransFactor,
brush.setStyle(Qt::SolidPattern); // mCurrentSceneRect.center().x(), mCurrentSceneRect.center().y()).map(QPointF(x, y));
}
QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width()); QPointF newPos(newX, newY);
QPainter painter;
painter.begin(generator); //drawing to svg tmp file item->setTransform(QTransform(xScale * mVBTransFactor, 0, 0, yScale * mVBTransFactor, 0, 0));
item->setPos(newPos);
painter.translate(pen.widthF() / 2 - x1, pen.widthF() / 2 - y1); item->setPos(newPos);
painter.setBrush(brush);
painter.setPen(pen);
painter.drawPolygon(polygon);
painter.end(); qDebug();
//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;
// 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() //bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseText()
{ //{
if (currentState != SVG && currentState != PAGE) // if (currentState != SVG && currentState != PAGE)
{ // {
qWarning() << "iwb content parse error, unexpected polyline tag at line" << mReader.lineNumber(); // qWarning() << "iwb content parse error, unexpected textarea tag at line" << mReader.lineNumber();
return false; // return false;
} // }
//create new scene if it's not created yet (for one page document case) // //create new scene if it's not created yet (for one page document case)
if (currentState == SVG && mCurrentScene == NULL) // if (currentState == SVG && mCurrentScene == NULL)
createNewScene(); // createNewScene();
QStringRef svgPoints = mReader.attributes().value("points"); // qreal x = mReader.attributes().value(aX).toString().toDouble();
QPolygonF polygon; // qreal y = mReader.attributes().value(aY).toString().toDouble();
if (!svgPoints.isNull()) { // qreal width = 0;
QStringList ts = svgPoints.toString().split(QLatin1Char(' '), // qreal height = 0;
QString::SkipEmptyParts);
foreach(const QString sPoint, ts) { // QList<QRectF> textRects;
QStringList sCoord = sPoint.split(QLatin1Char(','), QString::SkipEmptyParts); // QList<QFont> textFonts;
if (sCoord.size() == 2) { // QList<QString> textLines;
QPointF point; // QList<int> textAligns;
point.setX(sCoord.at(0).toFloat()); // QList<QColor> textColors;
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 // qWarning() << QString().sprintf("Text coordinates : %f,%f. Text size %f,%f", x, y, width, height);
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; // qreal fontSize = 12.0;
if (mReader.attributes().hasAttribute(aStroke)) // QFont textFont;
pen.setColor(colorFromString(mReader.attributes().value(aStroke).toString())); // QColor fontColor;
if (mReader.attributes().hasAttribute(aStrokewidth)) // QString fontFamily = "Arial";
pen.setWidth(mReader.attributes().value(aStrokewidth).toString().toInt()); // QString fontStretch = "normal";
QSvgGenerator *generator = createSvgGenerator(width + pen.width(), height + pen.width()); // bool italic = false;
QPainter painter; // 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); // qreal curY = 0.0;
painter.setPen(pen); // qreal curX = 0.0;
painter.drawPolyline(polygon);
painter.end(); // qreal linespacing = QFontMetrics(textFont).leading();
//add resulting svg file to scene // //remember if text area has transform
UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); // QTransform transform;
QTransform transform; // bool hasTransform = getCurElementTransorm(transform);
bool hastransform = getCurElementTransorm(transform);
repositionSvgItem(svgItem, width + 10, height + 10, x1 - 5, y1 - 5, hastransform, transform);
delete generator;
return true; // QRectF lastDrawnTextBoundingRect;
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parsePage() // QStack<QFont> fontStack;
{ // QStack<QColor> colorStack;
if (currentState != PAGESET && currentState != SVG) // QStack<int> alignStack;
{
qWarning() << "iwb content parse error, unexpected page tag at line" << mReader.lineNumber();
return false;
}
createNewScene();
qWarning() << "Added page number" << mProxy->pageCount();
return true;
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parsePageSet() // // first extimate desired text area size
{ // // to do that, parse text area tags
if (currentState != SVG) // while(true)
{ // {
qWarning() << "iwb content parse error, unexpected page tag at line" << mReader.lineNumber(); // mReader.readNext();
return false; // 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() // //skip empty text
{ // if (text.trimmed().length() == 0)
if (currentState != IWB) // continue;
{ // //get bounding rect to obtain desired text height
qWarning() << "iwb content parse error, unexpected element tag at line" << mReader.lineNumber(); // lastDrawnTextBoundingRect = metrics.boundingRect(QRectF(), textAlign, text);
return false; // 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;
return true; // continue;
} // }
// }
// QSvgGenerator *generator = createSvgGenerator(width, height);
// QPainter painter;
// painter.begin(generator);
// if (textRects.count() != 0)
// {
// QListIterator<QRectF> textRectsIter(textRects);
// QListIterator<QFont> textFontsIter(textFonts);
// QListIterator<QString> textLinesIter(textLines);
// QListIterator<int> textAlignsIter(textAligns);
// QListIterator<QColor> 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() bool UBCFFSubsetAdaptor::UBCFFSubsetReader::createNewScene()
{ {
mCurrentScene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mProxy, mProxy->pageCount()); mCurrentScene = UBPersistenceManager::persistenceManager()->createDocumentSceneAt(mProxy, mProxy->pageCount());
mCurrentSceneRect = mCurrentScene->normalizedSceneRect(); mCurrentSceneRect = mCurrentScene->normalizedSceneRect();
mVBTransFactor = qMin(mCurrentSceneRect.width() / mViewPort.width(),
mCurrentSceneRect.height() / mViewPort.height());
return true; return true;
} }
...@@ -1786,17 +1163,6 @@ QColor UBCFFSubsetAdaptor::UBCFFSubsetReader::colorFromString(const QString& clr ...@@ -1786,17 +1163,6 @@ QColor UBCFFSubsetAdaptor::UBCFFSubsetReader::colorFromString(const QString& clr
return QColor(clrString); 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) QTransform UBCFFSubsetAdaptor::UBCFFSubsetReader::transformFromString(const QString trString)
{ {
qreal dx = 0.0; qreal dx = 0.0;
...@@ -1836,8 +1202,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getViewBoxDimenstions(const QString& ...@@ -1836,8 +1202,11 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getViewBoxDimenstions(const QString&
if (capturesCount == 5 && regexp.capturedTexts().at(0).length() == viewBox.length()) if (capturesCount == 5 && regexp.capturedTexts().at(0).length() == viewBox.length())
{ {
mViewBox = QRectF(0, 0, regexp.capturedTexts().at(3).toDouble(), regexp.capturedTexts().at(4).toDouble()); 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.setX(mViewBox.width() / 2);
mViewBoxCenter.setY(mViewBox.height() / 2); mViewBoxCenter.setY(mViewBox.height() / 2);
return true; return true;
} }
} }
...@@ -1850,8 +1219,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getViewBoxDimenstions(const QString& ...@@ -1850,8 +1219,8 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getViewBoxDimenstions(const QString&
QSvgGenerator* UBCFFSubsetAdaptor::UBCFFSubsetReader::createSvgGenerator(qreal width, qreal height) QSvgGenerator* UBCFFSubsetAdaptor::UBCFFSubsetReader::createSvgGenerator(qreal width, qreal height)
{ {
QSvgGenerator* generator = new QSvgGenerator(); QSvgGenerator* generator = new QSvgGenerator();
qWarning() << QString("Making generator with file %1, size (%2, %3) and viewbox (%4 %5 %6 %7)").arg(mTempFilePath) // 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); // .arg(width).arg(height).arg(0.0).arg(0.0).arg(width).arg(width);
generator->setResolution(QApplication::desktop()->physicalDpiY()); generator->setResolution(QApplication::desktop()->physicalDpiY());
generator->setFileName(mTempFilePath); generator->setFileName(mTempFilePath);
generator->setSize(QSize(width, height)); generator->setSize(QSize(width, height));
...@@ -1879,64 +1248,29 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getTempFileName() ...@@ -1879,64 +1248,29 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::getTempFileName()
return false; return false;
} }
} }
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::createTempFlashPath()
void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTextAttributes(qreal &fontSize, QColor &fontColor,
QString &fontFamily, QString &fontStretch, bool &italic,
int &fontWeight, int &textAlign, QTransform &fontTransform)
{ {
if (mReader.attributes().hasAttribute(aFontSize)) int tmpNumber = 0;
{ QDir systemTmp = QDir::temp();
//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)) while (true) {
{ QString dirName = QString("SankTmpFlash%1.%2")
QStringRef fontStyle = mReader.attributes().value(aFontstyle); .arg(QDateTime::currentDateTime().toString("dd_MM_yyyy_HH-mm"))
italic = fontStyle == "italic"; .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) {
if (mReader.attributes().hasAttribute(aFontweight)) qWarning() << "Import failed. Failed to create temporary file for svg objects";
{ return false;
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;
} }
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;
} }
if (mReader.attributes().hasAttribute(aTransform)) return true;
fontTransform = transformFromString(mReader.attributes().value(aTransform).toString());
} }
...@@ -30,17 +30,9 @@ class UBGraphicsPixmapItem; ...@@ -30,17 +30,9 @@ class UBGraphicsPixmapItem;
class UBGraphicsItemDelegate; class UBGraphicsItemDelegate;
class QTransform; class QTransform;
class QPainter; class QPainter;
class UBGraphicsItem;
class QGraphicsItem;
struct IwbExt {
IwbExt() {;}
IwbExt(QDomNode element) : element(element), extAttr(*(new QVector<QDomNode>())) {;}
QDomNode group;
QDomNode element;
QVector<QDomNode> extAttr;
QHash<QString, QString> textAttributes;
operator bool() const {return !group.isNull() || !element.isNull();}
};
class UBCFFSubsetAdaptor class UBCFFSubsetAdaptor
{ {
...@@ -52,22 +44,9 @@ public: ...@@ -52,22 +44,9 @@ public:
private: private:
class UBCFFSubsetReader class UBCFFSubsetReader
{ {
//xml parse states definition
enum
{
NONE,
IWB,
SVG,
PAGESET,
PAGE,
TEXTAREA,
TSPAN
};
public: public:
UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content); UBCFFSubsetReader(UBDocumentProxy *proxy, QFile *content);
QXmlStreamReader mReader;
UBDocumentProxy *mProxy; UBDocumentProxy *mProxy;
QString pwdContent; QString pwdContent;
...@@ -79,6 +58,8 @@ private: ...@@ -79,6 +58,8 @@ private:
QRectF mCurrentSceneRect; QRectF mCurrentSceneRect;
QString mIndent; QString mIndent;
QRectF mViewBox; QRectF mViewBox;
QRectF mViewPort;
qreal mVBTransFactor;
QPointF mViewBoxCenter; QPointF mViewBoxCenter;
QSize mSize; QSize mSize;
...@@ -86,8 +67,8 @@ private: ...@@ -86,8 +67,8 @@ private:
// to kill // to kill
QDomDocument mDOMdoc; QDomDocument mDOMdoc;
QDomNode mCurrentDOMElement; QDomNode mCurrentDOMElement;
QHash<QString, IwbExt> iwbExtProperties; QHash<QString, UBGraphicsItem*> persistedItems;
QHash<QString, UBGraphicsItemDelegate*> persistedItems; QDir mTmpFlashDir;
bool hashElements(); bool hashElements();
void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup); void addExtentionsToHash(QDomElement *parent, QDomElement *topGroup);
...@@ -99,6 +80,8 @@ private: ...@@ -99,6 +80,8 @@ private:
bool parseSvgPage(const QDomElement &parent); bool parseSvgPage(const QDomElement &parent);
bool parseSvgPageset(const QDomElement &parent); bool parseSvgPageset(const QDomElement &parent);
bool parseSvgElement(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 parseSvgRect(const QDomElement &element);
inline bool parseSvgEllipse(const QDomElement &element); inline bool parseSvgEllipse(const QDomElement &element);
...@@ -107,61 +90,44 @@ private: ...@@ -107,61 +90,44 @@ private:
inline bool parseSvgText(const QDomElement &element); inline bool parseSvgText(const QDomElement &element);
inline bool parseSvgTextarea(const QDomElement &element); inline bool parseSvgTextarea(const QDomElement &element);
inline bool parseSvgImage(const QDomElement &element); inline bool parseSvgImage(const QDomElement &element);
// inline bool parseSvgTSpan(const QDomElement) inline bool parseSvgFlash(const QDomElement &element);
bool parseIwbGroup(QDomNode *element); inline bool parseSvgAudio(const QDomElement &element);
inline void hashSceneItem(QDomNode *element, UBGraphicsItemDelegate *item); 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 // to kill
void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor, void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor,
QString &fontFamily, QString &fontStretch, bool &italic, QString &fontFamily, QString &fontStretch, bool &italic,
int &fontWeight, int &textAlign, QTransform &fontTransform); int &fontWeight, int &textAlign, QTransform &fontTransform);
//methods to store current xml parse state
int PopState();
void PushState(int state);
//elements parsing methods //elements parsing methods
bool parseDoc(); 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 createNewScene();
bool persistCurrentScene(); bool persistCurrentScene();
// helper methods
QStack<int> stateStack; // bool getCurElementTransorm(QTransform &transform);
void repositionSvgItem(QGraphicsItem *item, qreal width, qreal height,
int currentState; qreal x, qreal y,
bool useTransform, QTransform &transform);
//helper methods void experimentalReposition(QGraphicsItem *item, qreal width, qreal height,
bool getCurElementTransorm(QTransform &transform); qreal x, qreal y,
void repositionSvgItem(UBGraphicsSvgItem *item, qreal width, qreal height, qreal x, qreal y, bool useTransform, QTransform &transform); bool useTransform, QTransform &transform);
void repositionPixmapItem(UBGraphicsPixmapItem *item, qreal width, qreal height, qreal x, qreal y
, bool useTransform, QTransform &transform);
QColor colorFromString(const QString& clrString); QColor colorFromString(const QString& clrString);
QTransform transformFromString(const QString trString); QTransform transformFromString(const QString trString);
bool getViewBoxDimenstions(const QString& viewBox); bool getViewBoxDimenstions(const QString& viewBox);
QSvgGenerator* createSvgGenerator(qreal width, qreal height); QSvgGenerator* createSvgGenerator(qreal width, qreal height);
bool getTempFileName(); bool getTempFileName();
void parseTextAttributes(qreal &fontSize, QColor &fontColor, inline bool strToBool(QString);
QString &fontFamily, QString &fontStretch, bool &italic, bool createTempFlashPath();
int &fontWeight, int &textAlign, QTransform &fontTransform);
}; };
}; };
......
...@@ -37,6 +37,7 @@ public: ...@@ -37,6 +37,7 @@ public:
} }
virtual UBItem* deepCopy () const; virtual UBItem* deepCopy () const;
virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;}
private slots: private slots:
......
...@@ -319,10 +319,12 @@ void UBGraphicsItemDelegate::lock(bool locked) ...@@ -319,10 +319,12 @@ void UBGraphicsItemDelegate::lock(bool locked)
if (locked) if (locked)
{ {
mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(true)); mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(true));
qDebug() << "item's data is called for locked" << mDelegated->data(UBGraphicsItemData::ItemLocked);
} }
else else
{ {
mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(false)); mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(false));
qDebug() << "item's data is called for unlocked" << mDelegated->data(UBGraphicsItemData::ItemLocked);
} }
mDelegated->update(); mDelegated->update();
......
...@@ -30,7 +30,7 @@ class UBGraphicsWidgetItem; ...@@ -30,7 +30,7 @@ class UBGraphicsWidgetItem;
class DelegateButton: public QGraphicsSvgItem class DelegateButton: public QGraphicsSvgItem
{ {
Q_OBJECT; Q_OBJECT
public: public:
DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0) DelegateButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0)
...@@ -90,7 +90,7 @@ class DelegateButton: public QGraphicsSvgItem ...@@ -90,7 +90,7 @@ class DelegateButton: public QGraphicsSvgItem
class UBGraphicsItemDelegate : public QObject class UBGraphicsItemDelegate : public QObject
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent = 0, bool respectRatio = true, bool canRotate = false); UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent = 0, bool respectRatio = true, bool canRotate = false);
...@@ -107,6 +107,8 @@ class UBGraphicsItemDelegate : public QObject ...@@ -107,6 +107,8 @@ class UBGraphicsItemDelegate : public QObject
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change,
const QVariant &value); const QVariant &value);
void printMessage(const QString &mess) {qDebug() << mess;}
QGraphicsItem* delegated() QGraphicsItem* delegated()
{ {
return mDelegated; return mDelegated;
...@@ -129,17 +131,19 @@ class UBGraphicsItemDelegate : public QObject ...@@ -129,17 +131,19 @@ class UBGraphicsItemDelegate : public QObject
void setMimeData(QMimeData* mimeData); void setMimeData(QMimeData* mimeData);
signals: signals:
void showOnDisplayChanged(bool shown); void showOnDisplayChanged(bool shown);
void lockChanged(bool locked); void lockChanged(bool locked);
public slots: public slots:
virtual void remove(bool canUndo = true); virtual void remove(bool canUndo = true);
void showMenu(); void showMenu();
virtual void showHide(bool show);
virtual void lock(bool lock);
virtual void duplicate();
protected: protected:
virtual void buildButtons() {}; virtual void buildButtons() {;}
virtual void decorateMenu(QMenu *menu); virtual void decorateMenu(QMenu *menu);
virtual void updateMenuActionState(); virtual void updateMenuActionState();
...@@ -164,9 +168,7 @@ class UBGraphicsItemDelegate : public QObject ...@@ -164,9 +168,7 @@ class UBGraphicsItemDelegate : public QObject
protected slots: protected slots:
virtual void gotoContentSource(bool checked); virtual void gotoContentSource(bool checked);
virtual void showHide(bool show);
virtual void lock(bool lock);
virtual void duplicate();
private: private:
......
...@@ -48,6 +48,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic ...@@ -48,6 +48,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic
virtual void remove(); virtual void remove();
virtual UBGraphicsPixmapItem* toPixmapItem() const; virtual UBGraphicsPixmapItem* toPixmapItem() const;
virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;}
protected: protected:
...@@ -57,7 +58,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic ...@@ -57,7 +58,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
UBGraphicsItemDelegate* mDelegate; // UBGraphicsItemDelegate* mDelegate;
}; };
#endif /* UBGRAPHICSPDFITEM_H_ */ #endif /* UBGRAPHICSPDFITEM_H_ */
...@@ -45,11 +45,13 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public ...@@ -45,11 +45,13 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public
virtual void remove(); virtual void remove();
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity); Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
void setOpacity(qreal op); void setOpacity(qreal op);
qreal opacity() const; qreal opacity() const;
virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;}
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
...@@ -60,7 +62,8 @@ protected: ...@@ -60,7 +62,8 @@ protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
UBGraphicsItemDelegate* mDelegate;
// UBGraphicsItemDelegate* mDelegate;
}; };
......
...@@ -41,7 +41,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public ...@@ -41,7 +41,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public
virtual void remove(); virtual void remove();
UBGraphicsItemDelegate* delegate (){ return mDelegate;} virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;}
protected: protected:
...@@ -53,7 +53,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public ...@@ -53,7 +53,7 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
UBGraphicsItemDelegate* mDelegate; // UBGraphicsItemDelegate* mDelegate;
}; };
#endif /* UBGRAPHICSPROXYWIDGET_H_ */ #endif /* UBGRAPHICSPROXYWIDGET_H_ */
...@@ -139,7 +139,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent) ...@@ -139,7 +139,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing())); connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChangedProcessing()));
} }
UBGraphicsScene::~UBGraphicsScene() UBGraphicsScene::~UBGraphicsScene()
{ {
// NOOP // NOOP
...@@ -165,8 +164,6 @@ void UBGraphicsScene::selectionChangedProcessing() ...@@ -165,8 +164,6 @@ void UBGraphicsScene::selectionChangedProcessing()
nextItem->setZValue(2); nextItem->setZValue(2);
qDebug() << QString(" >>> %1 <<< ").arg(i) << QString(" >>> %1 <<< ").arg(zValue); qDebug() << QString(" >>> %1 <<< ").arg(i) << QString(" >>> %1 <<< ").arg(zValue);
} }
} }
// MARK: - // MARK: -
......
...@@ -59,6 +59,7 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi ...@@ -59,6 +59,7 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi
virtual void remove(); virtual void remove();
virtual UBGraphicsPixmapItem* toPixmapItem() const; virtual UBGraphicsPixmapItem* toPixmapItem() const;
virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;}
protected: protected:
...@@ -70,7 +71,7 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi ...@@ -70,7 +71,7 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
UBGraphicsItemDelegate* mDelegate; // UBGraphicsItemDelegate* mDelegate;
QByteArray mFileData; QByteArray mFileData;
}; };
......
...@@ -30,7 +30,6 @@ QColor UBGraphicsTextItem::lastUsedTextColor; ...@@ -30,7 +30,6 @@ QColor UBGraphicsTextItem::lastUsedTextColor;
UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
: QGraphicsTextItem(parent) : QGraphicsTextItem(parent)
, mDelegate(0)
, mMultiClickState(0) , mMultiClickState(0)
, mLastMousePressTime(QTime::currentTime()) , mLastMousePressTime(QTime::currentTime())
{ {
......
...@@ -78,6 +78,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes ...@@ -78,6 +78,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes
{ {
mColorOnLightBackground = pColorOnLightBackground; mColorOnLightBackground = pColorOnLightBackground;
} }
virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;}
signals: signals:
void textUndoCommandAdded(UBGraphicsTextItem *textItem); void textUndoCommandAdded(UBGraphicsTextItem *textItem);
...@@ -96,7 +97,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes ...@@ -96,7 +97,7 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
private: private:
UBGraphicsItemDelegate *mDelegate; // UBGraphicsItemDelegate *mDelegate;
qreal mTextHeight; qreal mTextHeight;
int mMultiClickState; int mMultiClickState;
......
...@@ -40,6 +40,7 @@ public: ...@@ -40,6 +40,7 @@ public:
{ {
return mVideoWidget; return mVideoWidget;
} }
virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;}
public slots: public slots:
......
...@@ -29,10 +29,12 @@ class UBGraphicsScene; ...@@ -29,10 +29,12 @@ class UBGraphicsScene;
class UBAbstractWidget; class UBAbstractWidget;
class UBW3CWidgetAPI; class UBW3CWidgetAPI;
class UBW3CWidgetWebStorageAPI; class UBW3CWidgetWebStorageAPI;
class UBGraphiscItem;
class UBGraphiscItemDelegate;
class UBGraphicsWidgetItem : public UBGraphicsProxyWidget class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsWidgetItem(QGraphicsItem *parent = 0, int widgetType = 0); UBGraphicsWidgetItem(QGraphicsItem *parent = 0, int widgetType = 0);
...@@ -60,11 +62,13 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget ...@@ -60,11 +62,13 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
QMap<QString, QString> datastoreEntries() const; QMap<QString, QString> datastoreEntries() const;
void removeDatastoreEntry(const QString& key); void removeDatastoreEntry(const QString& key);
void removeAllDatastoreEntries(); void removeAllDatastoreEntries();
virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;}
virtual void remove(); virtual void remove();
void removeScript(); void removeScript();
protected: protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
...@@ -89,7 +93,7 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget ...@@ -89,7 +93,7 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget
class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0); UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0);
...@@ -109,7 +113,7 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem ...@@ -109,7 +113,7 @@ class UBGraphicsAppleWidgetItem : public UBGraphicsWidgetItem
class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0, int widgetType = UBGraphicsItemType::W3CWidgetItemType); UBGraphicsW3CWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent = 0, int widgetType = UBGraphicsItemType::W3CWidgetItemType);
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
class UBGraphicsWidgetItemDelegate : public UBGraphicsItemDelegate class UBGraphicsWidgetItemDelegate : public UBGraphicsItemDelegate
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsWidgetItemDelegate(UBGraphicsWidgetItem* pDelegated, int widgetType = 0); UBGraphicsWidgetItemDelegate(UBGraphicsWidgetItem* pDelegated, int widgetType = 0);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define UBITEM_H #define UBITEM_H
#include <QtGui> #include <QtGui>
#include "domain/UBGraphicsItemDelegate.h"
class UBGraphicsScene; class UBGraphicsScene;
...@@ -84,21 +85,23 @@ class UBItem ...@@ -84,21 +85,23 @@ class UBItem
class UBGraphicsItem class UBGraphicsItem
{ {
protected: protected:
UBGraphicsItem() UBGraphicsItem() : mDelegate(0)
{ {
// NOOP // NOOP
} }
UBGraphicsItemDelegate* mDelegate;
virtual ~UBGraphicsItem() virtual ~UBGraphicsItem()
{ {
// NOOP // NOOP
} }
public: public:
virtual UBGraphicsItemDelegate *Delegate() const = 0;
virtual void remove() = 0; virtual void remove() = 0;
}; };
#endif // UBITEM_H #endif // UBITEM_H
...@@ -228,7 +228,6 @@ void UBW3CWidget::javaScriptWindowObjectCleared() ...@@ -228,7 +228,6 @@ void UBW3CWidget::javaScriptWindowObjectCleared()
void UBW3CWidget::votingSystemError(const QString& error) void UBW3CWidget::votingSystemError(const QString& error)
{ {
page()->mainFrame()->evaluateJavaScript("if(voting.onerror) { voting.onerror('" + error +"');}"); page()->mainFrame()->evaluateJavaScript("if(voting.onerror) { voting.onerror('" + error +"');}");
} }
......
...@@ -36,7 +36,6 @@ const QColor UBGraphicsCurtainItem::sDarkBackgroundOpaqueControlColor = QColor(6 ...@@ -36,7 +36,6 @@ const QColor UBGraphicsCurtainItem::sDarkBackgroundOpaqueControlColor = QColor(6
UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent) UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent)
: QGraphicsRectItem(parent) : QGraphicsRectItem(parent)
, mDelegate(0)
{ {
mDelegate = new UBGraphicsCurtainItemDelegate(this, 0); mDelegate = new UBGraphicsCurtainItemDelegate(this, 0);
mDelegate->init(); mDelegate->init();
......
...@@ -28,7 +28,7 @@ class UBGraphicsItemDelegate; ...@@ -28,7 +28,7 @@ class UBGraphicsItemDelegate;
class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public UBItem, public UBGraphicsItem class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public UBItem, public UBGraphicsItem
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsCurtainItem(QGraphicsItem* parent = 0); UBGraphicsCurtainItem(QGraphicsItem* parent = 0);
...@@ -47,6 +47,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U ...@@ -47,6 +47,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U
//TODO UB 4.x not nice ... //TODO UB 4.x not nice ...
void triggerRemovedSignal(); void triggerRemovedSignal();
virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;}
signals: signals:
...@@ -65,7 +66,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U ...@@ -65,7 +66,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U
QColor drawColor() const; QColor drawColor() const;
QColor opaqueControlColor() const; QColor opaqueControlColor() const;
UBGraphicsItemDelegate* mDelegate; // UBGraphicsItemDelegate* mDelegate;
static const QColor sDrawColor; static const QColor sDrawColor;
static const QColor sDarkBackgroundDrawColor; static const QColor sDarkBackgroundDrawColor;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment