gui: mainwindow: Fix preview page number calculation

The paging now works on the actual pages to be rendered.
This commit is contained in:
Albert S. 2022-05-29 10:09:24 +02:00
parent 8d96f6e4ce
commit 82a4205c23

View File

@ -67,6 +67,9 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath) : QMainWindow(parent
QStringList indexPaths = settings.value("indexPaths").toStringList(); QStringList indexPaths = settings.value("indexPaths").toStringList();
ui->lstPaths->addItems(indexPaths); ui->lstPaths->addItems(indexPaths);
ui->spinPreviewPage->setValue(1);
ui->spinPreviewPage->setMinimum(1);
} }
void MainWindow::addPathToIndex() void MainWindow::addPathToIndex()
@ -385,10 +388,8 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
ui->treeResultsList->resizeColumnToContents(1); ui->treeResultsList->resizeColumnToContents(1);
previewDirty = !this->previewableSearchResults.empty(); previewDirty = !this->previewableSearchResults.empty();
int numpages = ceil(static_cast<double>(this->previewableSearchResults.size()) / previewsPerPage);
ui->spinPreviewPage->setMinimum(1);
ui->spinPreviewPage->setMaximum(numpages);
ui->spinPreviewPage->setValue(1); ui->spinPreviewPage->setValue(1);
if(previewTabActive() && previewDirty) if(previewTabActive() && previewDirty)
{ {
makePreviews(1); makePreviews(1);
@ -437,6 +438,11 @@ void MainWindow::makePreviews(int page)
} }
int end = previewsPerPage; int end = previewsPerPage;
int begin = page * previewsPerPage - previewsPerPage; int begin = page * previewsPerPage - previewsPerPage;
if(begin < 0)
{
// Should not happen actually
begin = 0;
}
RenderConfig renderConfig; RenderConfig renderConfig;
renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (scaleText.toInt() / 100.); renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (scaleText.toInt() / 100.);
@ -444,7 +450,7 @@ void MainWindow::makePreviews(int page)
renderConfig.wordsToHighlight = wordsToHighlight; renderConfig.wordsToHighlight = wordsToHighlight;
QVector<RenderTarget> targets; QVector<RenderTarget> targets;
for(SearchResult &sr : this->previewableSearchResults.mid(begin, end)) for(SearchResult &sr : this->previewableSearchResults)
{ {
RenderTarget renderTarget; RenderTarget renderTarget;
renderTarget.path = sr.fileData.absPath; renderTarget.path = sr.fileData.absPath;
@ -455,6 +461,10 @@ void MainWindow::makePreviews(int page)
targets.append(renderTarget); targets.append(renderTarget);
} }
} }
int numpages = ceil(static_cast<double>(targets.size()) / previewsPerPage);
ui->spinPreviewPage->setMaximum(numpages);
targets = targets.mid(begin, end);
ui->previewProcessBar->setMaximum(targets.count()); ui->previewProcessBar->setMaximum(targets.count());
ui->previewProcessBar->setMinimum(0); ui->previewProcessBar->setMinimum(0);
ui->previewProcessBar->setValue(0); ui->previewProcessBar->setValue(0);