mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-27 11:40:07 +00:00
epub audio support
This commit is contained in:
parent
e9ccc4867b
commit
e95b1db23c
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <core/action.h>
|
||||
#include <core/movie.h>
|
||||
#include <core/sound.h>
|
||||
#include <core/annotations.h>
|
||||
|
||||
using namespace Epub;
|
||||
|
@ -197,9 +198,12 @@ 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;
|
||||
QVector<Okular::SoundAction *> soundActions;
|
||||
const QSize videoSize(320, 240);
|
||||
do{
|
||||
movieAnnots.clear();
|
||||
soundActions.clear();
|
||||
|
||||
if(epub_it_get_curr(it)) {
|
||||
const QString link = QString::fromUtf8(epub_it_get_curr_url(it));
|
||||
mTextDocument->setCurrentSubDocument(link);
|
||||
|
@ -257,11 +261,28 @@ QTextDocument* Converter::convert( const QString &fileName )
|
|||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//handle embedded audio
|
||||
QDomNodeList audioTags = dom.elementsByTagName("audio");
|
||||
if(!audioTags.isEmpty()) {
|
||||
for (int i = 0; i < audioTags.size(); ++i) {
|
||||
QString lnk = audioTags.at(i).toElement().attribute("src");
|
||||
|
||||
Okular::Sound *sound = new Okular::Sound(mTextDocument->loadResource(
|
||||
EpubDocument::AudioResource, QUrl(lnk)).toByteArray());
|
||||
|
||||
Okular::SoundAction *soundAction = new Okular::SoundAction(1.0,true,true,false,sound);
|
||||
soundActions.push_back(soundAction);
|
||||
|
||||
QDomDocument tempDoc;
|
||||
tempDoc.setContent(QString("<pre><audio></audio></pre>"));
|
||||
audioTags.at(i).parentNode().replaceChild(tempDoc.documentElement(),audioTags.at(i));
|
||||
}
|
||||
}
|
||||
htmlContent = dom.toString();
|
||||
}
|
||||
|
||||
|
@ -297,6 +318,19 @@ QTextDocument* Converter::convert( const QString &fileName )
|
|||
csr.movePosition(QTextCursor::NextWord);
|
||||
}
|
||||
|
||||
csr.movePosition(QTextCursor::Start);
|
||||
index = 0;
|
||||
const QString keyToSearch("<audio></audio>");
|
||||
while( !(csr = mTextDocument->find(keyToSearch, csr)).isNull() ) {
|
||||
const int posStart = csr.position() - keyToSearch.size();
|
||||
const QImage img(KStandardDirs::locate("data", "okular/pics/okular-epub-sound-icon.png"));
|
||||
csr.insertImage(img);
|
||||
const int posEnd = csr.position();
|
||||
qDebug() << posStart << posEnd;;
|
||||
emit addAction(soundActions[index++],posStart,posEnd);
|
||||
csr.movePosition(QTextCursor::NextWord);
|
||||
}
|
||||
|
||||
mSectionMap.insert(link, before);
|
||||
|
||||
_handle_anchors(before, link);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
install(FILES
|
||||
okular-epub-sound-icon.png
|
||||
okular-epub-movie.png
|
||||
DESTINATION ${DATA_INSTALL_DIR}/okular/pics)
|
||||
|
|
BIN
generators/epub/data/okular-epub-sound-icon.png
Normal file
BIN
generators/epub/data/okular-epub-sound-icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
|
@ -113,6 +113,11 @@ QVariant EpubDocument::loadResource(int type, const QUrl &name)
|
|||
resource.setValue(tmp->fileName());
|
||||
break;
|
||||
}
|
||||
case EpubDocument::AudioResource: {
|
||||
QByteArray ba(data,size);
|
||||
resource.setValue(ba);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
resource.setValue(QString::fromUtf8(data));
|
||||
break;
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Epub {
|
|||
void setCurrentSubDocument(const QString &doc);
|
||||
int maxContentHeight() const;
|
||||
int maxContentWidth() const;
|
||||
enum Multimedia { MovieResource = 4 };
|
||||
enum Multimedia { MovieResource = 4, AudioResource = 5 };
|
||||
|
||||
protected:
|
||||
virtual QVariant loadResource(int type, const QUrl &name);
|
||||
|
|
|
@ -77,6 +77,7 @@
|
|||
#include "core/misc.h"
|
||||
#include "core/generator.h"
|
||||
#include "core/movie.h"
|
||||
#include "core/audioplayer.h"
|
||||
#include "core/sourcereference.h"
|
||||
#include "core/tile.h"
|
||||
#include "settings.h"
|
||||
|
@ -2380,6 +2381,9 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
// creating the menu and its actions
|
||||
KMenu menu( this );
|
||||
QAction * actProcessLink = menu.addAction( i18n( "Follow This Link" ) );
|
||||
QAction * actStopSound = 0;
|
||||
if ( link->actionType() == Okular::Action::Sound )
|
||||
actStopSound = menu.addAction( i18n( "Stop Sound" ) );
|
||||
QAction * actCopyLinkLocation = 0;
|
||||
if ( dynamic_cast< const Okular::BrowseAction * >( link ) )
|
||||
actCopyLinkLocation = menu.addAction( KIcon( "edit-copy" ), i18n( "Copy Link Address" ) );
|
||||
|
@ -2398,6 +2402,10 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
if ( cb->supportsSelection() )
|
||||
cb->setText( browseLink->url(), QClipboard::Selection );
|
||||
}
|
||||
else if ( res == actStopSound )
|
||||
{
|
||||
Okular::AudioPlayer::instance()->stopPlaybacks();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue