paging for pdfpreviews
This commit is contained in:
父節點
140128e405
當前提交
fa8e351859
@ -19,9 +19,10 @@
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(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";
|
||||
@ -33,8 +34,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
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()
|
||||
@ -64,13 +66,20 @@ void MainWindow::connectSignals()
|
||||
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()
|
||||
{
|
||||
@ -104,7 +113,7 @@ void MainWindow::tabChanged()
|
||||
{
|
||||
if(pdfDirty)
|
||||
{
|
||||
makePdfPreview();
|
||||
makePdfPreview(ui->spinPdfPreviewPage->value());
|
||||
}
|
||||
ui->pdfProcessBar->show();
|
||||
}
|
||||
@ -195,13 +204,18 @@ 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();
|
||||
@ -237,8 +251,10 @@ void MainWindow::makePdfPreview()
|
||||
}
|
||||
}
|
||||
PdfWorker worker;
|
||||
int end = pdfPreviewsPerPage;
|
||||
int begin = page * pdfPreviewsPerPage - pdfPreviewsPerPage;
|
||||
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->setMinimum(this->pdfWorkerWatcher.progressMinimum());
|
||||
}
|
||||
|
@ -36,13 +36,14 @@ class MainWindow : public QMainWindow
|
||||
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);
|
||||
@ -50,6 +51,7 @@ class MainWindow : public QMainWindow
|
||||
void tabChanged();
|
||||
void pdfPreviewReceived(PdfPreview preview);
|
||||
void comboScaleChanged(QString text);
|
||||
void spinPdfPreviewPageValueChanged(int val);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -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>
|
||||
|
載入中…
新增問題並參考
Block a user