From 404ce22ce6175e89c26daf4c01509e08624fe1bb Mon Sep 17 00:00:00 2001 From: Albert S Date: Mon, 3 Jan 2022 23:02:21 +0100 Subject: [PATCH] Generalize previews: Mainwindow: Do necessary renames --- gui/gui.pro | 21 ++++++++--- gui/main.cpp | 6 +-- gui/mainwindow.cpp | 92 +++++++++++++++++++++++----------------------- gui/mainwindow.h | 18 ++++----- gui/mainwindow.ui | 22 ++++------- 5 files changed, 79 insertions(+), 80 deletions(-) diff --git a/gui/gui.pro b/gui/gui.pro index e97e05c..171d68c 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -27,18 +27,27 @@ SOURCES += \ ipcserver.cpp \ main.cpp \ mainwindow.cpp \ - pdfworker.cpp \ - pdfpreview.cpp \ - clicklabel.cpp + clicklabel.cpp \ + previewgenerator.cpp \ + previewgeneratormapfunctor.cpp \ + previewgeneratorpdf.cpp \ + previewresult.cpp \ + previewresultpdf.cpp \ + previewworker.cpp HEADERS += \ ipc.h \ ipcclient.h \ ipcserver.h \ mainwindow.h \ - pdfworker.h \ - pdfpreview.h \ - clicklabel.h + clicklabel.h \ + previewgenerator.h \ + previewgeneratormapfunctor.h \ + previewgeneratorpdf.h \ + previewresult.h \ + previewresultpdf.h \ + previewworker.h \ + renderconfig.h FORMS += \ mainwindow.ui diff --git a/gui/main.cpp b/gui/main.cpp index 9449d18..d9b4915 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -6,7 +6,7 @@ #include "mainwindow.h" #include "searchresult.h" -#include "pdfpreview.h" +#include "previewresultpdf.h" #include "../shared/common.h" #include "../submodules/exile.h/exile.h" #include "ipcserver.h" @@ -96,8 +96,8 @@ int main(int argc, char *argv[]) return 1; } qRegisterMetaType>("QVector"); - qRegisterMetaType>("QVector"); - qRegisterMetaType("PdfPreview"); + qRegisterMetaType>("QVector"); + qRegisterMetaType("PreviewResultPdf"); IPCClient client{socketPath}; MainWindow w{0, client}; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index c55cbd4..6ddbdad 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -36,11 +36,11 @@ MainWindow::MainWindow(QWidget *parent, IPCClient &client) : QMainWindow(parent) ui->treeResultsList->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); ui->tabWidget->setCurrentIndex(0); ui->statusBar->addWidget(ui->lblSearchResults); - ui->statusBar->addWidget(ui->pdfProcessBar); - ui->pdfProcessBar->hide(); + ui->statusBar->addWidget(ui->previewProcessBar); + ui->previewProcessBar->hide(); ui->comboScale->setCurrentText(settings.value("currentScale").toString()); - pdfPreviewsPerPage = settings.value("pdfPreviewsPerPage", 20).toInt(); - ui->spinPdfPreviewPage->setMinimum(1); + previewsPerPage = settings.value("previewsPerPage", 20).toInt(); + ui->spinPreviewPage->setMinimum(1); } void MainWindow::connectSignals() @@ -60,32 +60,31 @@ void MainWindow::connectSignals() handleSearchError(e.message); } }); - - connect(&pdfWorkerWatcher, &QFutureWatcher::resultReadyAt, this, - [&](int index) { pdfPreviewReceived(pdfWorkerWatcher.resultAt(index)); }); - connect(&pdfWorkerWatcher, &QFutureWatcher::progressValueChanged, ui->pdfProcessBar, - &QProgressBar::setValue); + connect(&previewWorkerWatcher, &QFutureWatcher>::resultReadyAt, this, + [&](int index) { previewReceived(previewWorkerWatcher.resultAt(index)); }); + connect(&previewWorkerWatcher, &QFutureWatcher>::progressValueChanged, + ui->previewProcessBar, &QProgressBar::setValue); connect(ui->treeResultsList, &QTreeWidget::itemActivated, this, &MainWindow::treeSearchItemActivated); connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this, &MainWindow::showSearchResultsContextMenu); connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::tabChanged); connect(ui->comboScale, qOverload(&QComboBox::currentIndexChanged), this, &MainWindow::comboScaleChanged); - connect(ui->spinPdfPreviewPage, qOverload(&QSpinBox::valueChanged), this, - &MainWindow::spinPdfPreviewPageValueChanged); + connect(ui->spinPreviewPage, qOverload(&QSpinBox::valueChanged), this, + &MainWindow::spinPreviewPageValueChanged); } -void MainWindow::spinPdfPreviewPageValueChanged(int val) +void MainWindow::spinPreviewPageValueChanged(int val) { - makePdfPreview(val); + makePreviews(val); } void MainWindow::comboScaleChanged(int i) { QSettings scaleSetting; scaleSetting.setValue("currentScale", ui->comboScale->currentText()); - makePdfPreview(ui->spinPdfPreviewPage->value()); + makePreviews(ui->spinPreviewPage->value()); } -bool MainWindow::pdfTabActive() +bool MainWindow::previewTabActive() { return ui->tabWidget->currentIndex() == 1; } @@ -113,29 +112,28 @@ void MainWindow::keyPressEvent(QKeyEvent *event) void MainWindow::tabChanged() { - if(pdfTabActive()) + if(previewTabActive()) { - if(pdfDirty) + if(previewDirty) { - makePdfPreview(ui->spinPdfPreviewPage->value()); + makePreviews(ui->spinPreviewPage->value()); } - ui->pdfProcessBar->show(); + ui->previewProcessBar->show(); } else { - ui->pdfProcessBar->hide(); + ui->previewProcessBar->hide(); } } -void MainWindow::pdfPreviewReceived(PdfPreview preview) +void MainWindow::previewReceived(QSharedPointer preview) { - if(preview.hasPreviewImage()) + if(preview->hasPreview()) { - ClickLabel *label = new ClickLabel(); - QString docPath = preview.documentPath; - auto previewPage = preview.page; - label->setPixmap(QPixmap::fromImage(preview.previewImage)); - label->setToolTip(preview.documentPath); + QString docPath = preview->getDocumentPath(); + auto previewPage = preview->getPage(); + + ClickLabel *label = dynamic_cast(preview->createPreviewWidget()); ui->scrollAreaWidgetContents->layout()->addWidget(label); connect(label, &ClickLabel::leftClick, [this, docPath, previewPage]() { ipcDocOpen(docPath, previewPage); }); connect(label, &ClickLabel::rightClick, @@ -179,7 +177,7 @@ void MainWindow::lineEditReturnPressed() void MainWindow::handleSearchResults(const QVector &results) { - this->pdfSearchResults.clear(); + this->previewableSearchResults.clear(); ui->treeResultsList->clear(); bool hasDeleted = false; @@ -201,7 +199,7 @@ void MainWindow::handleSearchResults(const QVector &results) { if(result.fileData.absPath.endsWith(".pdf")) { - this->pdfSearchResults.append(result); + this->previewableSearchResults.append(result); } } else @@ -211,15 +209,15 @@ void MainWindow::handleSearchResults(const QVector &results) } ui->treeResultsList->resizeColumnToContents(0); ui->treeResultsList->resizeColumnToContents(1); - pdfDirty = !this->pdfSearchResults.empty(); + previewDirty = !this->previewableSearchResults.empty(); - int numpages = ceil(static_cast(this->pdfSearchResults.size()) / pdfPreviewsPerPage); - ui->spinPdfPreviewPage->setMinimum(1); - ui->spinPdfPreviewPage->setMaximum(numpages); - ui->spinPdfPreviewPage->setValue(1); - if(pdfTabActive() && pdfDirty) + int numpages = ceil(static_cast(this->previewableSearchResults.size()) / previewsPerPage); + ui->spinPreviewPage->setMinimum(1); + ui->spinPreviewPage->setMaximum(numpages); + ui->spinPreviewPage->setValue(1); + if(previewTabActive() && previewDirty) { - makePdfPreview(1); + makePreviews(1); } QString statusText = "Results: " + QString::number(results.size()) + " files"; @@ -230,18 +228,18 @@ void MainWindow::handleSearchResults(const QVector &results) ui->lblSearchResults->setText(statusText); } -void MainWindow::makePdfPreview(int page) +void MainWindow::makePreviews(int page) { - this->pdfWorkerWatcher.cancel(); - this->pdfWorkerWatcher.waitForFinished(); + this->previewWorkerWatcher.cancel(); + this->previewWorkerWatcher.waitForFinished(); QCoreApplication::processEvents(); // Maybe not necessary anymore, depends on whether it's possible that a slot is // still to be fired. qDeleteAll(ui->scrollAreaWidgetContents->children()); ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout()); - ui->pdfProcessBar->setMaximum(this->pdfSearchResults.size()); + ui->previewProcessBar->setMaximum(this->previewableSearchResults.size()); processedPdfPreviews = 0; QString scaleText = ui->comboScale->currentText(); scaleText.chop(1); @@ -265,13 +263,13 @@ void MainWindow::makePdfPreview(int page) } } } - PdfWorker worker; - 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->setMinimum(this->pdfWorkerWatcher.progressMinimum()); + PreviewWorker worker; + int end = previewsPerPage; + int begin = page * previewsPerPage - previewsPerPage; + this->previewWorkerWatcher.setFuture(worker.generatePreviews(this->previewableSearchResults.mid(begin, end), + wordsToHighlight, scaleText.toInt() / 100.)); + ui->previewProcessBar->setMaximum(this->previewWorkerWatcher.progressMaximum()); + ui->previewProcessBar->setMinimum(this->previewWorkerWatcher.progressMinimum()); } void MainWindow::handleSearchError(QString error) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 053274d..d6ce9a4 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -9,7 +9,7 @@ #include #include #include -#include "pdfworker.h" +#include "previewworker.h" #include "../shared/looqsquery.h" #include "ipcclient.h" namespace Ui @@ -32,21 +32,21 @@ class MainWindow : public QMainWindow Ui::MainWindow *ui; IPCClient *ipcClient; QFileIconProvider iconProvider; - bool pdfDirty; + bool previewDirty; QSqlDatabase db; QFutureWatcher> searchWatcher; - QFutureWatcher pdfWorkerWatcher; + QFutureWatcher> previewWorkerWatcher; void add(QString path, unsigned int page); - QVector pdfSearchResults; + QVector previewableSearchResults; void connectSignals(); - void makePdfPreview(int page); - bool pdfTabActive(); + void makePreviews(int page); + bool previewTabActive(); void keyPressEvent(QKeyEvent *event) override; unsigned int processedPdfPreviews; void handleSearchResults(const QVector &results); void handleSearchError(QString error); LooqsQuery contentSearchQuery; - int pdfPreviewsPerPage; + int previewsPerPage; void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo); void ipcDocOpen(QString path, int num); void ipcFileOpen(QString path); @@ -56,9 +56,9 @@ class MainWindow : public QMainWindow void treeSearchItemActivated(QTreeWidgetItem *item, int i); void showSearchResultsContextMenu(const QPoint &point); void tabChanged(); - void pdfPreviewReceived(PdfPreview preview); + void previewReceived(QSharedPointer preview); void comboScaleChanged(int i); - void spinPdfPreviewPageValueChanged(int val); + void spinPreviewPageValueChanged(int val); }; #endif // MAINWINDOW_H diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index eca9712..ca9cee6 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -60,9 +60,9 @@ - + - PDF-Preview + Previews @@ -81,8 +81,8 @@ 0 0 - 1179 - 370 + 1185 + 324 @@ -143,7 +143,7 @@ - + QAbstractSpinBox::PlusMinus @@ -182,7 +182,7 @@ - + 24 @@ -196,18 +196,10 @@ 0 0 1221 - 20 + 35 - - - TopToolBarArea - - - false - -