Generalize previews: Mainwindow: Do necessary renames
This commit is contained in:
parent
0cbd0dd9eb
commit
404ce22ce6
21
gui/gui.pro
21
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
|
||||
|
@ -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<SearchResult>>("QVector<SearchResult>");
|
||||
qRegisterMetaType<QVector<PdfPreview>>("QVector<PdfPreview>");
|
||||
qRegisterMetaType<PdfPreview>("PdfPreview");
|
||||
qRegisterMetaType<QVector<PreviewResultPdf>>("QVector<PreviewResultPdf>");
|
||||
qRegisterMetaType<PreviewResultPdf>("PreviewResultPdf");
|
||||
|
||||
IPCClient client{socketPath};
|
||||
MainWindow w{0, client};
|
||||
|
@ -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<PdfPreview>::resultReadyAt, this,
|
||||
[&](int index) { pdfPreviewReceived(pdfWorkerWatcher.resultAt(index)); });
|
||||
connect(&pdfWorkerWatcher, &QFutureWatcher<PdfPreview>::progressValueChanged, ui->pdfProcessBar,
|
||||
&QProgressBar::setValue);
|
||||
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::resultReadyAt, this,
|
||||
[&](int index) { previewReceived(previewWorkerWatcher.resultAt(index)); });
|
||||
connect(&previewWorkerWatcher, &QFutureWatcher<QSharedPointer<PreviewResult>>::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<int>(&QComboBox::currentIndexChanged), this, &MainWindow::comboScaleChanged);
|
||||
connect(ui->spinPdfPreviewPage, qOverload<int>(&QSpinBox::valueChanged), this,
|
||||
&MainWindow::spinPdfPreviewPageValueChanged);
|
||||
connect(ui->spinPreviewPage, qOverload<int>(&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<PreviewResult> 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<ClickLabel *>(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<SearchResult> &results)
|
||||
{
|
||||
this->pdfSearchResults.clear();
|
||||
this->previewableSearchResults.clear();
|
||||
ui->treeResultsList->clear();
|
||||
|
||||
bool hasDeleted = false;
|
||||
@ -201,7 +199,7 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &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<SearchResult> &results)
|
||||
}
|
||||
ui->treeResultsList->resizeColumnToContents(0);
|
||||
ui->treeResultsList->resizeColumnToContents(1);
|
||||
pdfDirty = !this->pdfSearchResults.empty();
|
||||
previewDirty = !this->previewableSearchResults.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)
|
||||
int numpages = ceil(static_cast<double>(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<SearchResult> &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)
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <QFutureWatcher>
|
||||
#include <QSqlDatabase>
|
||||
#include <QLocalSocket>
|
||||
#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<QVector<SearchResult>> searchWatcher;
|
||||
QFutureWatcher<PdfPreview> pdfWorkerWatcher;
|
||||
QFutureWatcher<QSharedPointer<PreviewResult>> previewWorkerWatcher;
|
||||
void add(QString path, unsigned int page);
|
||||
QVector<SearchResult> pdfSearchResults;
|
||||
QVector<SearchResult> 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<SearchResult> &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<PreviewResult> preview);
|
||||
void comboScaleChanged(int i);
|
||||
void spinPdfPreviewPageValueChanged(int val);
|
||||
void spinPreviewPageValueChanged(int val);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -60,9 +60,9 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="pdfPreviewTab">
|
||||
<widget class="QWidget" name="previewsTab">
|
||||
<attribute name="title">
|
||||
<string>PDF-Preview</string>
|
||||
<string>Previews</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
|
||||
<item>
|
||||
@ -81,8 +81,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1179</width>
|
||||
<height>370</height>
|
||||
<width>1185</width>
|
||||
<height>324</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
||||
@ -143,7 +143,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinPdfPreviewPage">
|
||||
<widget class="QSpinBox" name="spinPreviewPage">
|
||||
<property name="buttonSymbols">
|
||||
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||
</property>
|
||||
@ -182,7 +182,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="pdfProcessBar">
|
||||
<widget class="QProgressBar" name="previewProcessBar">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
@ -196,18 +196,10 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1221</width>
|
||||
<height>20</height>
|
||||
<height>35</height>
|
||||
</rect>
|
||||
</property>
|
||||
</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>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
|
Loading…
Reference in New Issue
Block a user