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