paging for pdfpreviews

This commit is contained in:
Albert S. 2019-08-26 09:20:21 +02:00
parent fae104d094
commit 582abc333f
3 changed files with 227 additions and 189 deletions

View File

@ -21,9 +21,10 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSettings settings;
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(QSettings().value("dbpath").toString());
db.setDatabaseName(settings.value("dbpath").toString());
if(!db.open())
{
qDebug() << "failed to open database";
@ -35,8 +36,9 @@ MainWindow::MainWindow(QWidget *parent) :
ui->statusBar->addWidget(ui->lblSearchResults);
ui->statusBar->addWidget(ui->pdfProcessBar);
ui->pdfProcessBar->hide();
QSettings settings;
ui->comboScale->setCurrentText(settings.value("currentScale").toString());
pdfPreviewsPerPage = settings.value("pdfPreviewsPerPage", 20).toInt();
ui->spinPdfPreviewPage->setMinimum(1);
}
void MainWindow::connectSignals()
@ -63,13 +65,20 @@ void MainWindow::connectSignals()
connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this, &MainWindow::showSearchResultsContextMenu);
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::tabChanged);
connect(ui->comboScale, qOverload<const QString &>(&QComboBox::currentIndexChanged), this, &MainWindow::comboScaleChanged);
connect(ui->spinPdfPreviewPage, qOverload<int>(&QSpinBox::valueChanged), this, &MainWindow::spinPdfPreviewPageValueChanged);
}
void MainWindow::spinPdfPreviewPageValueChanged(int val)
{
makePdfPreview(val);
}
void MainWindow::comboScaleChanged(QString text)
{
QSettings scaleSetting;
scaleSetting.setValue("currentScale", ui->comboScale->currentText());
makePdfPreview();
makePdfPreview(ui->spinPdfPreviewPage->value());
}
bool MainWindow::pdfTabActive()
{
@ -102,7 +111,7 @@ void MainWindow::tabChanged()
{
if(pdfDirty)
{
makePdfPreview();
makePdfPreview(ui->spinPdfPreviewPage->value());
}
ui->pdfProcessBar->show();
}
@ -190,14 +199,19 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
ui->treeResultsList->resizeColumnToContents(0);
ui->treeResultsList->resizeColumnToContents(1);
pdfDirty = ! this->pdfSearchResults.empty();
int numpages = ceil(static_cast<double>(this->pdfSearchResults.size()) / pdfPreviewsPerPage);
ui->spinPdfPreviewPage->setMinimum(1);
ui->spinPdfPreviewPage->setMaximum(numpages);
ui->spinPdfPreviewPage->setValue(1);
if(pdfTabActive() && pdfDirty)
{
makePdfPreview();
makePdfPreview(1);
}
}
void MainWindow::makePdfPreview()
void MainWindow::makePdfPreview(int page)
{
this->pdfWorkerWatcher.cancel();
@ -233,7 +247,9 @@ void MainWindow::makePdfPreview()
}
}
PdfWorker worker;
this->pdfWorkerWatcher.setFuture(worker.generatePreviews(this->pdfSearchResults, wordsToHighlight, scaleText.toInt() / 100.));
int end = pdfPreviewsPerPage;
int begin = page * pdfPreviewsPerPage - pdfPreviewsPerPage;
this->pdfWorkerWatcher.setFuture(worker.generatePreviews(this->pdfSearchResults.mid(begin, end), wordsToHighlight, scaleText.toInt() / 100.));
ui->pdfProcessBar->setMaximum(this->pdfWorkerWatcher.progressMaximum());
ui->pdfProcessBar->setMinimum(this->pdfWorkerWatcher.progressMinimum());
@ -274,3 +290,4 @@ MainWindow::~MainWindow()
{
delete ui;
}

View File

@ -34,13 +34,14 @@ private:
void add(QString path, unsigned int page);
QVector<SearchResult> pdfSearchResults;
void connectSignals();
void makePdfPreview();
void makePdfPreview(int page);
bool pdfTabActive();
void keyPressEvent(QKeyEvent *event) override;
unsigned int processedPdfPreviews;
void handleSearchResults(const QVector<SearchResult> &results);
void handleSearchError(QString error);
QSSQuery currentQuery;
int pdfPreviewsPerPage;
private slots:
void lineEditReturnPressed();
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
@ -48,7 +49,7 @@ private slots:
void tabChanged();
void pdfPreviewReceived(PdfPreview preview);
void comboScaleChanged(QString text);
void spinPdfPreviewPageValueChanged(int val);
};
#endif // MAINWINDOW_H

View File

@ -148,6 +148,26 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblPdfPreviewPage">
<property name="text">
<string>Page:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinPdfPreviewPage">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::PlusMinus</enum>
</property>
<property name="accelerated">
<bool>false</bool>
</property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>