Generalize previews: Mainwindow: Do necessary renames

This commit is contained in:
Albert S. 2022-01-03 23:02:21 +01:00
والد 0cbd0dd9eb
کامیت 404ce22ce6
5فایلهای تغییر یافته به همراه79 افزوده شده و 80 حذف شده

مشاهده پرونده

@ -27,18 +27,27 @@ SOURCES += \
ipcserver.cpp \ ipcserver.cpp \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \
pdfworker.cpp \ clicklabel.cpp \
pdfpreview.cpp \ previewgenerator.cpp \
clicklabel.cpp previewgeneratormapfunctor.cpp \
previewgeneratorpdf.cpp \
previewresult.cpp \
previewresultpdf.cpp \
previewworker.cpp
HEADERS += \ HEADERS += \
ipc.h \ ipc.h \
ipcclient.h \ ipcclient.h \
ipcserver.h \ ipcserver.h \
mainwindow.h \ mainwindow.h \
pdfworker.h \ clicklabel.h \
pdfpreview.h \ previewgenerator.h \
clicklabel.h previewgeneratormapfunctor.h \
previewgeneratorpdf.h \
previewresult.h \
previewresultpdf.h \
previewworker.h \
renderconfig.h
FORMS += \ FORMS += \
mainwindow.ui mainwindow.ui

مشاهده پرونده

@ -6,7 +6,7 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "searchresult.h" #include "searchresult.h"
#include "pdfpreview.h" #include "previewresultpdf.h"
#include "../shared/common.h" #include "../shared/common.h"
#include "../submodules/exile.h/exile.h" #include "../submodules/exile.h/exile.h"
#include "ipcserver.h" #include "ipcserver.h"
@ -96,8 +96,8 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
qRegisterMetaType<QVector<SearchResult>>("QVector<SearchResult>"); qRegisterMetaType<QVector<SearchResult>>("QVector<SearchResult>");
qRegisterMetaType<QVector<PdfPreview>>("QVector<PdfPreview>"); qRegisterMetaType<QVector<PreviewResultPdf>>("QVector<PreviewResultPdf>");
qRegisterMetaType<PdfPreview>("PdfPreview"); qRegisterMetaType<PreviewResultPdf>("PreviewResultPdf");
IPCClient client{socketPath}; IPCClient client{socketPath};
MainWindow w{0, client}; MainWindow w{0, client};

مشاهده پرونده

@ -36,11 +36,11 @@ MainWindow::MainWindow(QWidget *parent, IPCClient &client) : QMainWindow(parent)
ui->treeResultsList->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); ui->treeResultsList->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
ui->tabWidget->setCurrentIndex(0); ui->tabWidget->setCurrentIndex(0);
ui->statusBar->addWidget(ui->lblSearchResults); ui->statusBar->addWidget(ui->lblSearchResults);
ui->statusBar->addWidget(ui->pdfProcessBar); ui->statusBar->addWidget(ui->previewProcessBar);
ui->pdfProcessBar->hide(); ui->previewProcessBar->hide();
ui->comboScale->setCurrentText(settings.value("currentScale").toString()); ui->comboScale->setCurrentText(settings.value("currentScale").toString());
pdfPreviewsPerPage = settings.value("pdfPreviewsPerPage", 20).toInt(); previewsPerPage = settings.value("previewsPerPage", 20).toInt();
ui->spinPdfPreviewPage->setMinimum(1); ui->spinPreviewPage->setMinimum(1);
} }
void MainWindow::connectSignals() void MainWindow::connectSignals()
@ -60,32 +60,31 @@ void MainWindow::connectSignals()
handleSearchError(e.message); handleSearchError(e.message);
} }
}); });
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::resultReadyAt, this,
connect(&pdfWorkerWatcher, &QFutureWatcher<PdfPreview>::resultReadyAt, this, [&](int index) { previewReceived(previewWorkerWatcher.resultAt(index)); });
[&](int index) { pdfPreviewReceived(pdfWorkerWatcher.resultAt(index)); }); connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::progressValueChanged,
connect(&pdfWorkerWatcher, &QFutureWatcher<PdfPreview>::progressValueChanged, ui->pdfProcessBar, ui->previewProcessBar, &QProgressBar::setValue);
&QProgressBar::setValue);
connect(ui->treeResultsList, &QTreeWidget::itemActivated, this, &MainWindow::treeSearchItemActivated); connect(ui->treeResultsList, &QTreeWidget::itemActivated, this, &MainWindow::treeSearchItemActivated);
connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this, connect(ui->treeResultsList, &QTreeWidget::customContextMenuRequested, this,
&MainWindow::showSearchResultsContextMenu); &MainWindow::showSearchResultsContextMenu);
connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::tabChanged); connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::tabChanged);
connect(ui->comboScale, qOverload<int>(&QComboBox::currentIndexChanged), this, &MainWindow::comboScaleChanged); connect(ui->comboScale, qOverload<int>(&QComboBox::currentIndexChanged), this, &MainWindow::comboScaleChanged);
connect(ui->spinPdfPreviewPage, qOverload<int>(&QSpinBox::valueChanged), this, connect(ui->spinPreviewPage, qOverload<int>(&QSpinBox::valueChanged), this,
&MainWindow::spinPdfPreviewPageValueChanged); &MainWindow::spinPreviewPageValueChanged);
} }
void MainWindow::spinPdfPreviewPageValueChanged(int val) void MainWindow::spinPreviewPageValueChanged(int val)
{ {
makePdfPreview(val); makePreviews(val);
} }
void MainWindow::comboScaleChanged(int i) void MainWindow::comboScaleChanged(int i)
{ {
QSettings scaleSetting; QSettings scaleSetting;
scaleSetting.setValue("currentScale", ui->comboScale->currentText()); 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; return ui->tabWidget->currentIndex() == 1;
} }
@ -113,29 +112,28 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
void MainWindow::tabChanged() 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 else
{ {
ui->pdfProcessBar->hide(); ui->previewProcessBar->hide();
} }
} }
void MainWindow::pdfPreviewReceived(PdfPreview preview) void MainWindow::previewReceived(QSharedPointer<PreviewResult> preview)
{ {
if(preview.hasPreviewImage()) if(preview->hasPreview())
{ {
ClickLabel *label = new ClickLabel(); QString docPath = preview->getDocumentPath();
QString docPath = preview.documentPath; auto previewPage = preview->getPage();
auto previewPage = preview.page;
label->setPixmap(QPixmap::fromImage(preview.previewImage)); ClickLabel *label = dynamic_cast<ClickLabel *>(preview->createPreviewWidget());
label->setToolTip(preview.documentPath);
ui->scrollAreaWidgetContents->layout()->addWidget(label); ui->scrollAreaWidgetContents->layout()->addWidget(label);
connect(label, &ClickLabel::leftClick, [this, docPath, previewPage]() { ipcDocOpen(docPath, previewPage); }); connect(label, &ClickLabel::leftClick, [this, docPath, previewPage]() { ipcDocOpen(docPath, previewPage); });
connect(label, &ClickLabel::rightClick, connect(label, &ClickLabel::rightClick,
@ -179,7 +177,7 @@ void MainWindow::lineEditReturnPressed()
void MainWindow::handleSearchResults(const QVector<SearchResult> &results) void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
{ {
this->pdfSearchResults.clear(); this->previewableSearchResults.clear();
ui->treeResultsList->clear(); ui->treeResultsList->clear();
bool hasDeleted = false; bool hasDeleted = false;
@ -201,7 +199,7 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
{ {
if(result.fileData.absPath.endsWith(".pdf")) if(result.fileData.absPath.endsWith(".pdf"))
{ {
this->pdfSearchResults.append(result); this->previewableSearchResults.append(result);
} }
} }
else else
@ -211,15 +209,15 @@ 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(); previewDirty = !this->previewableSearchResults.empty();
int numpages = ceil(static_cast<double>(this->pdfSearchResults.size()) / pdfPreviewsPerPage); int numpages = ceil(static_cast<double>(this->previewableSearchResults.size()) / previewsPerPage);
ui->spinPdfPreviewPage->setMinimum(1); ui->spinPreviewPage->setMinimum(1);
ui->spinPdfPreviewPage->setMaximum(numpages); ui->spinPreviewPage->setMaximum(numpages);
ui->spinPdfPreviewPage->setValue(1); ui->spinPreviewPage->setValue(1);
if(pdfTabActive() && pdfDirty) if(previewTabActive() && previewDirty)
{ {
makePdfPreview(1); makePreviews(1);
} }
QString statusText = "Results: " + QString::number(results.size()) + " files"; QString statusText = "Results: " + QString::number(results.size()) + " files";
@ -230,18 +228,18 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
ui->lblSearchResults->setText(statusText); ui->lblSearchResults->setText(statusText);
} }
void MainWindow::makePdfPreview(int page) void MainWindow::makePreviews(int page)
{ {
this->pdfWorkerWatcher.cancel(); this->previewWorkerWatcher.cancel();
this->pdfWorkerWatcher.waitForFinished(); this->previewWorkerWatcher.waitForFinished();
QCoreApplication::processEvents(); // Maybe not necessary anymore, depends on whether it's possible that a slot is QCoreApplication::processEvents(); // Maybe not necessary anymore, depends on whether it's possible that a slot is
// still to be fired. // still to be fired.
qDeleteAll(ui->scrollAreaWidgetContents->children()); qDeleteAll(ui->scrollAreaWidgetContents->children());
ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout()); ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
ui->pdfProcessBar->setMaximum(this->pdfSearchResults.size()); ui->previewProcessBar->setMaximum(this->previewableSearchResults.size());
processedPdfPreviews = 0; processedPdfPreviews = 0;
QString scaleText = ui->comboScale->currentText(); QString scaleText = ui->comboScale->currentText();
scaleText.chop(1); scaleText.chop(1);
@ -265,13 +263,13 @@ void MainWindow::makePdfPreview(int page)
} }
} }
} }
PdfWorker worker; PreviewWorker worker;
int end = pdfPreviewsPerPage; int end = previewsPerPage;
int begin = page * pdfPreviewsPerPage - pdfPreviewsPerPage; int begin = page * previewsPerPage - previewsPerPage;
this->pdfWorkerWatcher.setFuture( this->previewWorkerWatcher.setFuture(worker.generatePreviews(this->previewableSearchResults.mid(begin, end),
worker.generatePreviews(this->pdfSearchResults.mid(begin, end), wordsToHighlight, scaleText.toInt() / 100.)); wordsToHighlight, scaleText.toInt() / 100.));
ui->pdfProcessBar->setMaximum(this->pdfWorkerWatcher.progressMaximum()); ui->previewProcessBar->setMaximum(this->previewWorkerWatcher.progressMaximum());
ui->pdfProcessBar->setMinimum(this->pdfWorkerWatcher.progressMinimum()); ui->previewProcessBar->setMinimum(this->previewWorkerWatcher.progressMinimum());
} }
void MainWindow::handleSearchError(QString error) void MainWindow::handleSearchError(QString error)

مشاهده پرونده

@ -9,7 +9,7 @@
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QSqlDatabase> #include <QSqlDatabase>
#include <QLocalSocket> #include <QLocalSocket>
#include "pdfworker.h" #include "previewworker.h"
#include "../shared/looqsquery.h" #include "../shared/looqsquery.h"
#include "ipcclient.h" #include "ipcclient.h"
namespace Ui namespace Ui
@ -32,21 +32,21 @@ class MainWindow : public QMainWindow
Ui::MainWindow *ui; Ui::MainWindow *ui;
IPCClient *ipcClient; IPCClient *ipcClient;
QFileIconProvider iconProvider; QFileIconProvider iconProvider;
bool pdfDirty; bool previewDirty;
QSqlDatabase db; QSqlDatabase db;
QFutureWatcher<QVector<SearchResult>> searchWatcher; QFutureWatcher<QVector<SearchResult>> searchWatcher;
QFutureWatcher<PdfPreview> pdfWorkerWatcher; QFutureWatcher<QSharedPointer<PreviewResult>> previewWorkerWatcher;
void add(QString path, unsigned int page); void add(QString path, unsigned int page);
QVector<SearchResult> pdfSearchResults; QVector<SearchResult> previewableSearchResults;
void connectSignals(); void connectSignals();
void makePdfPreview(int page); void makePreviews(int page);
bool pdfTabActive(); bool previewTabActive();
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);
LooqsQuery contentSearchQuery; LooqsQuery contentSearchQuery;
int pdfPreviewsPerPage; int previewsPerPage;
void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo); void createSearchResutlMenu(QMenu &menu, const QFileInfo &fileInfo);
void ipcDocOpen(QString path, int num); void ipcDocOpen(QString path, int num);
void ipcFileOpen(QString path); void ipcFileOpen(QString path);
@ -56,9 +56,9 @@ class MainWindow : public QMainWindow
void treeSearchItemActivated(QTreeWidgetItem *item, int i); void treeSearchItemActivated(QTreeWidgetItem *item, int i);
void showSearchResultsContextMenu(const QPoint &point); void showSearchResultsContextMenu(const QPoint &point);
void tabChanged(); void tabChanged();
void pdfPreviewReceived(PdfPreview preview); void previewReceived(QSharedPointer<PreviewResult> preview);
void comboScaleChanged(int i); void comboScaleChanged(int i);
void spinPdfPreviewPageValueChanged(int val); void spinPreviewPageValueChanged(int val);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

مشاهده پرونده

@ -60,9 +60,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="pdfPreviewTab"> <widget class="QWidget" name="previewsTab">
<attribute name="title"> <attribute name="title">
<string>PDF-Preview</string> <string>Previews</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0"> <layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
<item> <item>
@ -81,8 +81,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1179</width> <width>1185</width>
<height>370</height> <height>324</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"/> <layout class="QHBoxLayout" name="horizontalLayout"/>
@ -143,7 +143,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="spinPdfPreviewPage"> <widget class="QSpinBox" name="spinPreviewPage">
<property name="buttonSymbols"> <property name="buttonSymbols">
<enum>QAbstractSpinBox::PlusMinus</enum> <enum>QAbstractSpinBox::PlusMinus</enum>
</property> </property>
@ -182,7 +182,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QProgressBar" name="pdfProcessBar"> <widget class="QProgressBar" name="previewProcessBar">
<property name="value"> <property name="value">
<number>24</number> <number>24</number>
</property> </property>
@ -196,18 +196,10 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1221</width> <width>1221</width>
<height>20</height> <height>35</height>
</rect> </rect>
</property> </property>
</widget> </widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>