aboutsummaryrefslogtreecommitdiff
path: root/mainwindow.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-06-14 05:18:53 +0200
committerJavier <dev.git@javispedro.com>2015-06-14 05:18:53 +0200
commit2910de560ead3ff65db26292fc27e427a5cf9b5e (patch)
tree12f6c29b77244528176abeee0934bdc4c560f08d /mainwindow.cc
parent46cb4b079be113996214660020d6ef0c3d1f1e80 (diff)
downloadscribiu-2910de560ead3ff65db26292fc27e427a5cf9b5e.tar.gz
scribiu-2910de560ead3ff65db26292fc27e427a5cf9b5e.zip
add export feature and desktop file
Diffstat (limited to 'mainwindow.cc')
-rw-r--r--mainwindow.cc135
1 files changed, 135 insertions, 0 deletions
diff --git a/mainwindow.cc b/mainwindow.cc
index dd687a2..0fdf38d 100644
--- a/mainwindow.cc
+++ b/mainwindow.cc
@@ -1,4 +1,7 @@
#include <QtCore/QDebug>
+#include <QtGui/QFileDialog>
+#include <QtGui/QMessageBox>
+#include <QtSvg/QSvgGenerator>
#include "mainwindow.h"
#include "ui_mainwindow.h"
@@ -24,10 +27,15 @@ MainWindow::MainWindow(QWidget *parent) :
ui->paperReplayView->horizontalHeader()->setResizeMode(1, QHeaderView::Fixed);
ui->paperReplayView->setVisible(false);
Phonon::createPath(_media, _mediaOutput);
+ _media->setTickInterval(500);
ui->replaySlider->setMediaObject(_media);
ui->pauseButton->setVisible(false);
connect(_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(handleMediaStateChange(Phonon::State)));
+ connect(_media, SIGNAL(totalTimeChanged(qint64)),
+ this, SLOT(handleMediaTotalTimeChanged(qint64)));
+ connect(_media, SIGNAL(tick(qint64)),
+ this, SLOT(handleMediaTick(qint64)));
}
MainWindow::~MainWindow()
@@ -73,6 +81,46 @@ void MainWindow::openNotebook(const QString &pen, const QString &notebook)
}
}
+void MainWindow::exportCurrentPageAsPng(const QString &file)
+{
+ qDebug() << "Exporting current page" << ui->notebookView->curPage() << "to" << file;
+ QImage image = ui->notebookView->exportPage(ui->notebookView->curPage());
+ if (!image.save(file, "PNG")) {
+ QMessageBox::warning(this, tr("Export page"),
+ tr("Could not export current page to '%s'").arg(file));
+ }
+}
+
+void MainWindow::exportCurrentPageAsSvg(const QString &file)
+{
+ QSvgGenerator svg;
+ svg.setFileName(file);
+ svg.setSize(ui->notebookView->getCurPageSize());
+ svg.setViewBox(ui->notebookView->getCurPageTrim());
+ svg.setTitle(_curNotebookName + " p." + QString::number(ui->notebookView->curPage()));
+ svg.setDescription("Page " + QString::number(ui->notebookView->curPage()) + " of " + _curNotebookName + " from " + _curPenName);
+ qDebug() << "Exporting current page" << ui->notebookView->curPage() << "to" << file;
+ QPainter painter;
+ painter.begin(&svg);
+ ui->notebookView->renderPage(&painter, ui->notebookView->curPage());
+ painter.end();
+}
+
+void MainWindow::exportCurrentPaperReplayAsAac(const QString &file)
+{
+ QString src = _media->currentSource().fileName();
+ if (src.isEmpty()) {
+ QMessageBox::warning(this, tr("Export audio"),
+ tr("No audio file is selected"));
+ return;
+ }
+ qDebug() << "Exporting current audio" << src << "to" << file;
+ if (!QFile::copy(src, file)) {
+ QMessageBox::warning(this, tr("Export audio"),
+ tr("Could not export current audio to '%s'").arg(file));
+ }
+}
+
void MainWindow::handleNotebookSelected(const QModelIndex &index)
{
if (!index.isValid()) {
@@ -151,13 +199,100 @@ void MainWindow::handleMediaStateChange(Phonon::State state)
_media->seek(_pendingSeek);
_pendingSeek = 0;
}
+ ui->mediaPosLabel->setText(formatDuration(_media->currentTime()));
+ ui->mediaLenLabel->setText("/ " + formatDuration(_media->totalTime()));
break;
case Phonon::PausedState:
ui->playButton->setVisible(true);
ui->pauseButton->setVisible(false);
+ ui->mediaPosLabel->setText(formatDuration(_media->currentTime()));
+ ui->mediaLenLabel->setText("/ " + formatDuration(_media->totalTime()));
break;
default:
ui->playButton->setVisible(true);
ui->pauseButton->setVisible(false);
+ ui->mediaPosLabel->setText(QString());
+ ui->mediaLenLabel->setText(QString());
+ break;
+ }
+}
+
+void MainWindow::handleMediaTotalTimeChanged(qint64 time)
+{
+ ui->mediaLenLabel->setText("/ " + formatDuration(time));
+}
+
+void MainWindow::handleMediaTick(qint64 time)
+{
+ ui->mediaPosLabel->setText(formatDuration(time));
+}
+
+void MainWindow::handleExport()
+{
+ if (_curNotebookName == PAPER_REPLAY) {
+ QStringList filters;
+ filters << tr("Current audio as AAC (*.aac)");
+ QString filter;
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Export page"), QString(),
+ filters.join(";;"), &filter);
+ if (fileName.isEmpty()) return;
+ int filterIndex = filters.indexOf(filter);
+ switch (filterIndex) {
+ case 0:
+ if (!fileName.endsWith(".aac", Qt::CaseInsensitive)) {
+ fileName.append(".aac");
+ }
+ exportCurrentPaperReplayAsAac(fileName);
+ break;
+ }
+ } else if (!_curNotebookName.isEmpty()) {
+ QStringList filters;
+ filters << tr("Current page as PNG image (*.png)")
+ << tr("Current page as SVG image (*.svg)")
+ << tr("Current audio as AAC (*.aac)");
+ QString filter;
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Export page"), QString(),
+ filters.join(";;"), &filter);
+ if (fileName.isEmpty()) return;
+ int filterIndex = filters.indexOf(filter);
+ switch (filterIndex) {
+ case 0:
+ if (!fileName.endsWith(".png", Qt::CaseInsensitive)) {
+ fileName.append(".png");
+ }
+ exportCurrentPageAsPng(fileName);
+ break;
+ case 1:
+ if (!fileName.endsWith(".svg", Qt::CaseInsensitive)) {
+ fileName.append(".svg");
+ }
+ exportCurrentPageAsSvg(fileName);
+ break;
+ case 2:
+ if (!fileName.endsWith(".aac", Qt::CaseInsensitive)) {
+ fileName.append(".aac");
+ }
+ exportCurrentPaperReplayAsAac(fileName);
+ break;
+ }
+ } else {
+ QMessageBox::warning(this, tr("Export page"),
+ tr("Open a notebook or audio in order to export"));
+ }
+}
+
+QString MainWindow::formatDuration(qint64 time)
+{
+ int secs = time / 1000;
+ int mins = secs / 60;
+ secs %= 60;
+ int hours = mins / 60;
+ mins %= 60;
+
+ const QChar fill('0');
+ if (hours) {
+ return QString("%1:%2:%3").arg(hours).arg(mins, 2, 10, fill).arg(secs, 2, 10, fill);
+ } else {
+ return QString("%2:%3").arg(mins).arg(secs, 2, 10, fill);
}
}