diff options
author | Javier <dev.git@javispedro.com> | 2015-06-14 01:35:25 +0200 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2015-06-14 01:35:25 +0200 |
commit | 59feffc5a253fec33b310f7a0105c8ef42b9019b (patch) | |
tree | 855c7c86b4413d813d2a6c40d167eb78ee3250d3 /mainwindow.cc | |
parent | 72a71a2003028fc97d74cebecebb1541d66ded86 (diff) | |
download | scribiu-59feffc5a253fec33b310f7a0105c8ef42b9019b.tar.gz scribiu-59feffc5a253fec33b310f7a0105c8ef42b9019b.zip |
paperreplay working
Diffstat (limited to 'mainwindow.cc')
-rw-r--r-- | mainwindow.cc | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/mainwindow.cc b/mainwindow.cc index c509d4e..e269c61 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -6,7 +6,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), _notebooks(new NotebookModel(this)), - _manager(new SmartpenManager(this)) + _manager(new SmartpenManager(this)), + _media(new Phonon::MediaObject(this)), + _mediaOutput(new Phonon::AudioOutput(this)) { ui->setupUi(this); ui->notebookTree->setModel(_notebooks); @@ -14,6 +16,11 @@ MainWindow::MainWindow(QWidget *parent) : ui->notebookTree->header()->setResizeMode(1, QHeaderView::Fixed); ui->notebookTree->header()->setResizeMode(2, QHeaderView::Fixed); ui->notebookTree->expandAll(); + Phonon::createPath(_media, _mediaOutput); + ui->replaySlider->setMediaObject(_media); + ui->pauseButton->setVisible(false); + connect(_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(handleMediaStateChange(Phonon::State))); } MainWindow::~MainWindow() @@ -65,3 +72,63 @@ void MainWindow::handleCurPageChanged() { ui->pageEdit->setText(QString::number(ui->notebookView->curPage() + 1)); } + +void MainWindow::handlePaperReplayRequested(const QString &file, qint64 time) +{ + QFileInfo finfo(file); + if (!finfo.exists()) { + qWarning() << "Cannot open paper replay media file:" << finfo.canonicalFilePath(); + } + + QString filePath = finfo.canonicalFilePath(); + + if (_media->currentSource().fileName() != filePath) { + _media->setCurrentSource(filePath); + } + + switch (_media->state()) { + case Phonon::PlayingState: + case Phonon::BufferingState: + case Phonon::PausedState: + _pendingSeek = 0; + _media->seek(time); + break; + default: + _pendingSeek = time; + break; + } + + _media->play(); +} + +void MainWindow::handlePaperReplayPlay() +{ + _media->play(); +} + +void MainWindow::handlePaperReplayPause() +{ + _media->pause(); +} + +void MainWindow::handleMediaStateChange(Phonon::State state) +{ + qDebug() << "Media state change:" << state; + switch (state) { + case Phonon::PlayingState: + ui->playButton->setVisible(false); + ui->pauseButton->setVisible(true); + if (_pendingSeek) { + _media->seek(_pendingSeek); + _pendingSeek = 0; + } + break; + case Phonon::PausedState: + ui->playButton->setVisible(true); + ui->pauseButton->setVisible(false); + break; + default: + ui->playButton->setVisible(true); + ui->pauseButton->setVisible(false); + } +} |