open specififed pdfviewer jumping to the page of the preveiw image

(cherry picked from commit 0bd429be1c9e16b96dd5e503265856107e55adaf)
This commit is contained in:
Albert S. 2018-08-31 20:08:23 +02:00
parent 53cf73cc8d
commit 703d426979
3 changed files with 28 additions and 6 deletions

View File

@ -7,6 +7,7 @@
#include <QClipboard> #include <QClipboard>
#include <QSettings> #include <QSettings>
#include <QDateTime> #include <QDateTime>
#include <QProcess>
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "clicklabel.h" #include "clicklabel.h"
@ -61,7 +62,27 @@ void MainWindow::pdfPreviewReceived(PdfPreview preview)
ClickLabel *label = new ClickLabel(); ClickLabel *label = new ClickLabel();
label->setPixmap(QPixmap::fromImage(preview.previewImage)); label->setPixmap(QPixmap::fromImage(preview.previewImage));
ui->scrollAreaWidgetContents->layout()->addWidget(label); ui->scrollAreaWidgetContents->layout()->addWidget(label);
connect(label, &ClickLabel::clicked, [=]() { QDesktopServices::openUrl(QUrl::fromLocalFile(preview.documentPath)); }); connect(label, &ClickLabel::clicked, [=]() {
QSettings settings;
QString command = settings.value("pdfviewer").toString();
qDebug() << command;
if(command != "" && command.contains("%p") && command.contains("%f"))
{
command = command.replace("%f", preview.documentPath);
command = command.replace("%p", QString::number(preview.page));
QStringList splitted = command.split(" ");
if(splitted.size() > 1)
{
QString cmd = splitted[0];
QStringList args = splitted.mid(1);
QProcess::startDetached(cmd, args);
}
}
else
{
QDesktopServices::openUrl(QUrl::fromLocalFile(preview.documentPath));
}
});
} }
void MainWindow::lineEditReturnPressed() void MainWindow::lineEditReturnPressed()

View File

@ -8,6 +8,7 @@ public:
PdfPreview(); PdfPreview();
QImage previewImage; QImage previewImage;
QString documentPath; QString documentPath;
unsigned int page;
}; };
#endif // PDFPREVIEW_H #endif // PDFPREVIEW_H

View File

@ -29,6 +29,10 @@ void PdfWorker::generatePreviews(QVector<SearchResult> paths, double scalefactor
this->generating = true; this->generating = true;
for(SearchResult &sr : paths) for(SearchResult &sr : paths)
{ {
if(this->cancelCurrent.load())
{
break;
}
Poppler::Document *doc = document(sr.path); Poppler::Document *doc = document(sr.path);
if(doc == nullptr) if(doc == nullptr)
{ {
@ -48,12 +52,8 @@ void PdfWorker::generatePreviews(QVector<SearchResult> paths, double scalefactor
PdfPreview preview; PdfPreview preview;
preview.previewImage = image; preview.previewImage = image;
preview.documentPath = sr.path; preview.documentPath = sr.path;
preview.page = sr.page;
emit previewReady(preview); emit previewReady(preview);
if(this->cancelCurrent.load())
{
break;
}
} }
isFreeMutex.lock(); isFreeMutex.lock();
isFree.wakeOne(); isFree.wakeOne();