paging for pdfpreviews
This commit is contained in:
parent
fae104d094
commit
582abc333f
@ -21,9 +21,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui(new Ui::MainWindow)
|
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";
|
||||||
@ -35,8 +36,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
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()
|
||||||
@ -63,13 +65,20 @@ void MainWindow::connectSignals()
|
|||||||
connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this, &MainWindow::showSearchResultsContextMenu);
|
connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this, &MainWindow::showSearchResultsContextMenu);
|
||||||
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, &MainWindow::comboScaleChanged);
|
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)
|
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()
|
||||||
{
|
{
|
||||||
@ -102,7 +111,7 @@ void MainWindow::tabChanged()
|
|||||||
{
|
{
|
||||||
if(pdfDirty)
|
if(pdfDirty)
|
||||||
{
|
{
|
||||||
makePdfPreview();
|
makePdfPreview(ui->spinPdfPreviewPage->value());
|
||||||
}
|
}
|
||||||
ui->pdfProcessBar->show();
|
ui->pdfProcessBar->show();
|
||||||
}
|
}
|
||||||
@ -190,14 +199,19 @@ 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();
|
||||||
@ -233,7 +247,9 @@ void MainWindow::makePdfPreview()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PdfWorker worker;
|
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->setMaximum(this->pdfWorkerWatcher.progressMaximum());
|
||||||
ui->pdfProcessBar->setMinimum(this->pdfWorkerWatcher.progressMinimum());
|
ui->pdfProcessBar->setMinimum(this->pdfWorkerWatcher.progressMinimum());
|
||||||
|
|
||||||
@ -274,3 +290,4 @@ MainWindow::~MainWindow()
|
|||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,13 +34,14 @@ private:
|
|||||||
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);
|
||||||
@ -48,7 +49,7 @@ private slots:
|
|||||||
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>
|
||||||
|
Loading…
Reference in New Issue
Block a user