|
|
|
|
@ -17,7 +17,11 @@ |
|
|
|
|
|
|
|
|
|
#include <kdebug.h> |
|
|
|
|
#include <klocale.h> |
|
|
|
|
#include <KStandardDirs> |
|
|
|
|
|
|
|
|
|
#include <core/action.h> |
|
|
|
|
#include <core/movie.h> |
|
|
|
|
#include <core/annotations.h> |
|
|
|
|
|
|
|
|
|
using namespace Epub; |
|
|
|
|
|
|
|
|
|
@ -135,6 +139,28 @@ void Converter::_insert_local_links(const QString &key, const QPair<int, int> &v |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static QPoint calculateXYPosition( QTextDocument *document, int startPosition ) |
|
|
|
|
{ |
|
|
|
|
const QTextBlock startBlock = document->findBlock( startPosition ); |
|
|
|
|
const QRectF startBoundingRect = document->documentLayout()->blockBoundingRect( startBlock ); |
|
|
|
|
|
|
|
|
|
QTextLayout *startLayout = startBlock.layout(); |
|
|
|
|
if (!startLayout) { |
|
|
|
|
kWarning() << "Start layout not found" << startLayout; |
|
|
|
|
return QPoint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int startPos = startPosition - startBlock.position(); |
|
|
|
|
const QTextLine startLine = startLayout->lineForTextPosition( startPos ); |
|
|
|
|
|
|
|
|
|
double x = startBoundingRect.x() ; |
|
|
|
|
double y = startBoundingRect.y() + startLine.y(); |
|
|
|
|
|
|
|
|
|
y = (int)y % 800; |
|
|
|
|
|
|
|
|
|
return QPoint(x,y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QTextDocument* Converter::convert( const QString &fileName ) |
|
|
|
|
{ |
|
|
|
|
EpubDocument *newDocument = new EpubDocument(fileName); |
|
|
|
|
@ -170,7 +196,10 @@ QTextDocument* Converter::convert( const QString &fileName ) |
|
|
|
|
|
|
|
|
|
// if the background color of the document is non-white it will be handled by QTextDocument::setHtml()
|
|
|
|
|
bool firstPage = true; |
|
|
|
|
QVector<Okular::MovieAnnotation *> movieAnnots; |
|
|
|
|
const QSize videoSize(320, 240); |
|
|
|
|
do{ |
|
|
|
|
movieAnnots.clear(); |
|
|
|
|
if(epub_it_get_curr(it)) { |
|
|
|
|
const QString link = QString::fromUtf8(epub_it_get_curr_url(it)); |
|
|
|
|
mTextDocument->setCurrentSubDocument(link); |
|
|
|
|
@ -208,8 +237,32 @@ QTextDocument* Converter::convert( const QString &fileName ) |
|
|
|
|
svgs.at(i).parentNode().replaceChild(nd,svgs.at(i)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
htmlContent = dom.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// handle embedded videos
|
|
|
|
|
QDomNodeList videoTags = dom.elementsByTagName("video"); |
|
|
|
|
if(!videoTags.isEmpty()) { |
|
|
|
|
for (int i = 0; i < videoTags.size(); ++i) { |
|
|
|
|
QDomNodeList sourceTags = videoTags.at(i).toElement().elementsByTagName("source"); |
|
|
|
|
if(!sourceTags.isEmpty()) { |
|
|
|
|
QString lnk = sourceTags.at(0).toElement().attribute("src"); |
|
|
|
|
|
|
|
|
|
Okular::Movie *movie = new Okular::Movie(mTextDocument->loadResource(EpubDocument::MovieResource,QUrl(lnk)).toString()); |
|
|
|
|
movie->setSize(videoSize); |
|
|
|
|
movie->setShowControls(true); |
|
|
|
|
|
|
|
|
|
Okular::MovieAnnotation *annot = new Okular::MovieAnnotation; |
|
|
|
|
annot->setMovie(movie); |
|
|
|
|
|
|
|
|
|
movieAnnots.push_back(annot); |
|
|
|
|
QDomDocument tempDoc; |
|
|
|
|
tempDoc.setContent(QString("<pre><video></video></pre>")); |
|
|
|
|
qDebug() << "replacing"; |
|
|
|
|
videoTags.at(i).parentNode().replaceChild(tempDoc.documentElement(),videoTags.at(i)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
htmlContent = dom.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QTextBlock before; |
|
|
|
|
@ -228,6 +281,22 @@ QTextDocument* Converter::convert( const QString &fileName ) |
|
|
|
|
_cursor->insertHtml(htmlContent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QTextCursor csr(mTextDocument); // a temporary cursor
|
|
|
|
|
csr.movePosition(QTextCursor::Start); |
|
|
|
|
int index = 0; |
|
|
|
|
while( !(csr = mTextDocument->find("<video></video>",csr)).isNull() ) { |
|
|
|
|
const int posStart = csr.position(); |
|
|
|
|
const QPoint startPoint = calculateXYPosition(mTextDocument, posStart); |
|
|
|
|
QImage img(KStandardDirs::locate("data", "okular/pics/okular-epub-movie.png")); |
|
|
|
|
img = img.scaled(videoSize); |
|
|
|
|
csr.insertImage(img); |
|
|
|
|
const int posEnd = csr.position(); |
|
|
|
|
const QRect videoRect(startPoint,videoSize); |
|
|
|
|
movieAnnots[index]->setBoundingRectangle(Okular::NormalizedRect(videoRect,mTextDocument->pageSize().width(), mTextDocument->pageSize().height())); |
|
|
|
|
emit addAnnotation(movieAnnots[index++],posStart,posEnd); |
|
|
|
|
csr.movePosition(QTextCursor::NextWord); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mSectionMap.insert(link, before); |
|
|
|
|
|
|
|
|
|
_handle_anchors(before, link); |
|
|
|
|
|