paging for pdfpreviews
This commit is contained in:
parent
140128e405
commit
fa8e351859
@ -19,9 +19,10 @@
|
|||||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
db = QSqlDatabase::addDatabase("QSQLITE");
|
db = QSqlDatabase::addDatabase("QSQLITE");
|
||||||
db.setDatabaseName(QSettings().value("dbpath").toString());
|
db.setDatabaseName(settings.value("dbpath").toString());
|
||||||
if(!db.open())
|
if(!db.open())
|
||||||
{
|
{
|
||||||
qDebug() << "failed to open database";
|
qDebug() << "failed to open database";
|
||||||
@ -33,8 +34,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
ui->statusBar->addWidget(ui->lblSearchResults);
|
ui->statusBar->addWidget(ui->lblSearchResults);
|
||||||
ui->statusBar->addWidget(ui->pdfProcessBar);
|
ui->statusBar->addWidget(ui->pdfProcessBar);
|
||||||
ui->pdfProcessBar->hide();
|
ui->pdfProcessBar->hide();
|
||||||
QSettings settings;
|
|
||||||
ui->comboScale->setCurrentText(settings.value("currentScale").toString());
|
ui->comboScale->setCurrentText(settings.value("currentScale").toString());
|
||||||
|
pdfPreviewsPerPage = settings.value("pdfPreviewsPerPage", 20).toInt();
|
||||||
|
ui->spinPdfPreviewPage->setMinimum(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::connectSignals()
|
void MainWindow::connectSignals()
|
||||||
@ -64,13 +66,20 @@ void MainWindow::connectSignals()
|
|||||||
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::tabChanged);
|
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::tabChanged);
|
||||||
connect(ui->comboScale, qOverload<const QString &>(&QComboBox::currentIndexChanged), this,
|
connect(ui->comboScale, qOverload<const QString &>(&QComboBox::currentIndexChanged), this,
|
||||||
&MainWindow::comboScaleChanged);
|
&MainWindow::comboScaleChanged);
|
||||||
|
connect(ui->spinPdfPreviewPage, qOverload<int>(&QSpinBox::valueChanged), this,
|
||||||
|
&MainWindow::spinPdfPreviewPageValueChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::spinPdfPreviewPageValueChanged(int val)
|
||||||
|
{
|
||||||
|
makePdfPreview(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::comboScaleChanged(QString text)
|
void MainWindow::comboScaleChanged(QString text)
|
||||||
{
|
{
|
||||||
QSettings scaleSetting;
|
QSettings scaleSetting;
|
||||||
scaleSetting.setValue("currentScale", ui->comboScale->currentText());
|
scaleSetting.setValue("currentScale", ui->comboScale->currentText());
|
||||||
makePdfPreview();
|
makePdfPreview(ui->spinPdfPreviewPage->value());
|
||||||
}
|
}
|
||||||
bool MainWindow::pdfTabActive()
|
bool MainWindow::pdfTabActive()
|
||||||
{
|
{
|
||||||
@ -104,7 +113,7 @@ void MainWindow::tabChanged()
|
|||||||
{
|
{
|
||||||
if(pdfDirty)
|
if(pdfDirty)
|
||||||
{
|
{
|
||||||
makePdfPreview();
|
makePdfPreview(ui->spinPdfPreviewPage->value());
|
||||||
}
|
}
|
||||||
ui->pdfProcessBar->show();
|
ui->pdfProcessBar->show();
|
||||||
}
|
}
|
||||||
@ -195,13 +204,18 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
|||||||
ui->treeResultsList->resizeColumnToContents(0);
|
ui->treeResultsList->resizeColumnToContents(0);
|
||||||
ui->treeResultsList->resizeColumnToContents(1);
|
ui->treeResultsList->resizeColumnToContents(1);
|
||||||
pdfDirty = !this->pdfSearchResults.empty();
|
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)
|
if(pdfTabActive() && pdfDirty)
|
||||||
{
|
{
|
||||||
makePdfPreview();
|
makePdfPreview(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::makePdfPreview()
|
void MainWindow::makePdfPreview(int page)
|
||||||
{
|
{
|
||||||
|
|
||||||
this->pdfWorkerWatcher.cancel();
|
this->pdfWorkerWatcher.cancel();
|
||||||
@ -237,8 +251,10 @@ void MainWindow::makePdfPreview()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PdfWorker worker;
|
PdfWorker worker;
|
||||||
|
int end = pdfPreviewsPerPage;
|
||||||
|
int begin = page * pdfPreviewsPerPage - pdfPreviewsPerPage;
|
||||||
this->pdfWorkerWatcher.setFuture(
|
this->pdfWorkerWatcher.setFuture(
|
||||||
worker.generatePreviews(this->pdfSearchResults, wordsToHighlight, scaleText.toInt() / 100.));
|
worker.generatePreviews(this->pdfSearchResults.mid(begin, end), wordsToHighlight, scaleText.toInt() / 100.));
|
||||||
ui->pdfProcessBar->setMaximum(this->pdfWorkerWatcher.progressMaximum());
|
ui->pdfProcessBar->setMaximum(this->pdfWorkerWatcher.progressMaximum());
|
||||||
ui->pdfProcessBar->setMinimum(this->pdfWorkerWatcher.progressMinimum());
|
ui->pdfProcessBar->setMinimum(this->pdfWorkerWatcher.progressMinimum());
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,14 @@ class MainWindow : public QMainWindow
|
|||||||
void add(QString path, unsigned int page);
|
void add(QString path, unsigned int page);
|
||||||
QVector<SearchResult> pdfSearchResults;
|
QVector<SearchResult> pdfSearchResults;
|
||||||
void connectSignals();
|
void connectSignals();
|
||||||
void makePdfPreview();
|
void makePdfPreview(int page);
|
||||||
bool pdfTabActive();
|
bool pdfTabActive();
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
void keyPressEvent(QKeyEvent *event) override;
|
||||||
unsigned int processedPdfPreviews;
|
unsigned int processedPdfPreviews;
|
||||||
void handleSearchResults(const QVector<SearchResult> &results);
|
void handleSearchResults(const QVector<SearchResult> &results);
|
||||||
void handleSearchError(QString error);
|
void handleSearchError(QString error);
|
||||||
QSSQuery currentQuery;
|
QSSQuery currentQuery;
|
||||||
|
int pdfPreviewsPerPage;
|
||||||
private slots:
|
private slots:
|
||||||
void lineEditReturnPressed();
|
void lineEditReturnPressed();
|
||||||
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
||||||
@ -50,6 +51,7 @@ class MainWindow : public QMainWindow
|
|||||||
void tabChanged();
|
void tabChanged();
|
||||||
void pdfPreviewReceived(PdfPreview preview);
|
void pdfPreviewReceived(PdfPreview preview);
|
||||||
void comboScaleChanged(QString text);
|
void comboScaleChanged(QString text);
|
||||||
|
void spinPdfPreviewPageValueChanged(int val);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -148,6 +148,26 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Caricamento…
Fai riferimento in un nuovo problema
Block a user