Compare commits
8 커밋
4ce14a7284
...
43a0f08579
작성자 | SHA1 | 날짜 | |
---|---|---|---|
43a0f08579 | |||
1aa5ae0ccc | |||
20d42a66a6 | |||
cba4df3eac | |||
fdbf3a7358 | |||
ac4d7dd0a5 | |||
ab064c3e3b | |||
a33c7f1859 |
@ -36,9 +36,11 @@ SOURCES += \
|
||||
clicklabel.cpp \
|
||||
previewgenerator.cpp \
|
||||
previewgeneratormapfunctor.cpp \
|
||||
previewgeneratorodt.cpp \
|
||||
previewgeneratorpdf.cpp \
|
||||
previewgeneratorplaintext.cpp \
|
||||
previewresult.cpp \
|
||||
previewresultodt.cpp \
|
||||
previewresultpdf.cpp \
|
||||
previewresultplaintext.cpp \
|
||||
renderconfig.cpp \
|
||||
@ -54,9 +56,11 @@ HEADERS += \
|
||||
clicklabel.h \
|
||||
previewgenerator.h \
|
||||
previewgeneratormapfunctor.h \
|
||||
previewgeneratorodt.h \
|
||||
previewgeneratorpdf.h \
|
||||
previewgeneratorplaintext.h \
|
||||
previewresult.h \
|
||||
previewresultodt.h \
|
||||
previewresultpdf.h \
|
||||
previewresultplaintext.h \
|
||||
renderconfig.h \
|
||||
@ -66,6 +70,7 @@ FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
INCLUDEPATH += /usr/include/poppler/qt5/
|
||||
INCLUDEPATH += /usr/include/quazip5
|
||||
|
||||
QT += widgets sql
|
||||
|
||||
|
@ -33,28 +33,6 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath)
|
||||
setWindowTitle(QCoreApplication::applicationName());
|
||||
this->ipcPreviewClient.moveToThread(&this->ipcClientThread);
|
||||
this->ipcPreviewClient.setSocketPath(socketPath);
|
||||
|
||||
connect(&ipcPreviewClient, &IPCPreviewClient::previewReceived, this, &MainWindow::previewReceived,
|
||||
Qt::QueuedConnection);
|
||||
connect(&ipcPreviewClient, &IPCPreviewClient::finished, this,
|
||||
[&]
|
||||
{
|
||||
this->ui->previewProcessBar->setValue(this->ui->previewProcessBar->maximum());
|
||||
this->ui->spinPreviewPage->setEnabled(true);
|
||||
this->ui->comboPreviewFiles->setEnabled(true);
|
||||
});
|
||||
connect(&ipcPreviewClient, &IPCPreviewClient::error, this,
|
||||
[this](QString msg)
|
||||
{
|
||||
qCritical() << msg << Qt::endl;
|
||||
QMessageBox::critical(this, "IPC error", msg);
|
||||
});
|
||||
|
||||
connect(this, &MainWindow::startIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::startGeneration,
|
||||
Qt::QueuedConnection);
|
||||
connect(this, &MainWindow::stopIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::stopGeneration,
|
||||
Qt::QueuedConnection);
|
||||
this->ipcClientThread.start();
|
||||
QSettings settings;
|
||||
|
||||
this->dbFactory = new DatabaseFactory(Common::databasePath());
|
||||
@ -91,6 +69,8 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath)
|
||||
auto policy = ui->btnOpenFailed->sizePolicy();
|
||||
policy.setRetainSizeWhenHidden(true);
|
||||
ui->btnOpenFailed->setSizePolicy(policy);
|
||||
|
||||
this->ipcClientThread.start();
|
||||
}
|
||||
|
||||
void MainWindow::addPathToIndex()
|
||||
@ -191,6 +171,9 @@ void MainWindow::connectSignals()
|
||||
connect(ui->menuAboutQtAction, &QAction::triggered, this,
|
||||
[this](bool checked) { QMessageBox::aboutQt(this, "About Qt"); });
|
||||
connect(ui->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync);
|
||||
connect(ui->menuOpenUserManualAction, &QAction::triggered, this,
|
||||
[this]() { QDesktopServices::openUrl(Common::userManualUrl()); });
|
||||
|
||||
connect(indexSyncer, &IndexSyncer::finished, this,
|
||||
[&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored)
|
||||
{
|
||||
@ -210,6 +193,26 @@ void MainWindow::connectSignals()
|
||||
connect(
|
||||
ui->comboPreviewFiles, qOverload<int>(&QComboBox::currentIndexChanged), this, [&]() { makePreviews(1); },
|
||||
Qt::QueuedConnection);
|
||||
connect(&ipcPreviewClient, &IPCPreviewClient::previewReceived, this, &MainWindow::previewReceived,
|
||||
Qt::QueuedConnection);
|
||||
connect(&ipcPreviewClient, &IPCPreviewClient::finished, this,
|
||||
[&]
|
||||
{
|
||||
this->ui->previewProcessBar->setValue(this->ui->previewProcessBar->maximum());
|
||||
this->ui->spinPreviewPage->setEnabled(true);
|
||||
this->ui->comboPreviewFiles->setEnabled(true);
|
||||
});
|
||||
connect(&ipcPreviewClient, &IPCPreviewClient::error, this,
|
||||
[this](QString msg)
|
||||
{
|
||||
qCritical() << msg << Qt::endl;
|
||||
QMessageBox::critical(this, "IPC error", msg);
|
||||
});
|
||||
|
||||
connect(this, &MainWindow::startIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::startGeneration,
|
||||
Qt::QueuedConnection);
|
||||
connect(this, &MainWindow::stopIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::stopGeneration,
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void MainWindow::exportFailedPaths()
|
||||
@ -436,19 +439,46 @@ void MainWindow::previewReceived(QSharedPointer<PreviewResult> preview, unsigned
|
||||
QString docPath = preview->getDocumentPath();
|
||||
auto previewPage = preview->getPage();
|
||||
|
||||
ClickLabel *headerLabel = new ClickLabel();
|
||||
headerLabel->setText(QString("Path: ") + preview->getDocumentPath());
|
||||
|
||||
ClickLabel *label = dynamic_cast<ClickLabel *>(preview->createPreviewWidget());
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(label);
|
||||
connect(label, &ClickLabel::leftClick, [this, docPath, previewPage]() { openDocument(docPath, previewPage); });
|
||||
connect(label, &ClickLabel::rightClick,
|
||||
[this, docPath, previewPage]()
|
||||
{
|
||||
QFileInfo fileInfo{docPath};
|
||||
QMenu menu("labeRightClick", this);
|
||||
createSearchResutlMenu(menu, fileInfo);
|
||||
menu.addAction("Copy page number", [previewPage]
|
||||
{ QGuiApplication::clipboard()->setText(QString::number(previewPage)); });
|
||||
menu.exec(QCursor::pos());
|
||||
});
|
||||
|
||||
QVBoxLayout *previewLayout = new QVBoxLayout();
|
||||
|
||||
QFont font = label->font();
|
||||
font.setPointSize(QApplication::font().pointSize() * currentSelectedScale() / 100);
|
||||
label->setFont(font);
|
||||
headerLabel->setFont(font);
|
||||
|
||||
auto leftClickHandler = [this, docPath, previewPage]() { openDocument(docPath, previewPage); };
|
||||
auto rightClickhandler = [this, docPath, previewPage]()
|
||||
{
|
||||
QFileInfo fileInfo{docPath};
|
||||
QMenu menu("labeRightClick", this);
|
||||
createSearchResutlMenu(menu, fileInfo);
|
||||
menu.addAction("Copy page number",
|
||||
[previewPage] { QGuiApplication::clipboard()->setText(QString::number(previewPage)); });
|
||||
menu.exec(QCursor::pos());
|
||||
};
|
||||
|
||||
connect(label, &ClickLabel::leftClick, leftClickHandler);
|
||||
connect(label, &ClickLabel::rightClick, rightClickhandler);
|
||||
|
||||
connect(headerLabel, &ClickLabel::rightClick, rightClickhandler);
|
||||
|
||||
previewLayout->addWidget(label);
|
||||
|
||||
previewLayout->addWidget(headerLabel);
|
||||
|
||||
previewLayout->setMargin(0);
|
||||
previewLayout->insertStretch(0, 1);
|
||||
previewLayout->insertStretch(-1, 1);
|
||||
QWidget *previewWidget = new QWidget();
|
||||
|
||||
previewWidget->setLayout(previewLayout);
|
||||
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(previewWidget);
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,6 +597,13 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results)
|
||||
ui->lblSearchResults->setText(statusText);
|
||||
}
|
||||
|
||||
int MainWindow::currentSelectedScale()
|
||||
{
|
||||
QString scaleText = ui->comboScale->currentText();
|
||||
scaleText.chop(1);
|
||||
return scaleText.toInt();
|
||||
}
|
||||
|
||||
void MainWindow::makePreviews(int page)
|
||||
{
|
||||
if(this->previewableSearchResults.empty())
|
||||
@ -578,8 +615,6 @@ void MainWindow::makePreviews(int page)
|
||||
ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout());
|
||||
ui->previewProcessBar->setMaximum(this->previewableSearchResults.size());
|
||||
processedPdfPreviews = 0;
|
||||
QString scaleText = ui->comboScale->currentText();
|
||||
scaleText.chop(1);
|
||||
|
||||
QVector<QString> wordsToHighlight;
|
||||
QRegularExpression extractor(R"#("([^"]*)"|((\p{L}|\p{N})+))#");
|
||||
@ -608,9 +643,10 @@ void MainWindow::makePreviews(int page)
|
||||
begin = 0;
|
||||
}
|
||||
|
||||
int currentScale = currentSelectedScale();
|
||||
RenderConfig renderConfig;
|
||||
renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (scaleText.toInt() / 100.);
|
||||
renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (scaleText.toInt() / 100.);
|
||||
renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (currentScale / 100.);
|
||||
renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.);
|
||||
renderConfig.wordsToHighlight = wordsToHighlight;
|
||||
|
||||
QVector<RenderTarget> targets;
|
||||
|
@ -62,6 +62,7 @@ class MainWindow : public QMainWindow
|
||||
void openFile(QString path);
|
||||
unsigned int currentPreviewGeneration = 1;
|
||||
void initSettingsTabs();
|
||||
int currentSelectedScale();
|
||||
private slots:
|
||||
void lineEditReturnPressed();
|
||||
void treeSearchItemActivated(QTreeWidgetItem *item, int i);
|
||||
|
@ -626,6 +626,7 @@
|
||||
<string>looqs</string>
|
||||
</property>
|
||||
<addaction name="menuSyncIndexAction"/>
|
||||
<addaction name="menuOpenUserManualAction"/>
|
||||
<addaction name="menuAboutAction"/>
|
||||
<addaction name="menuAboutQtAction"/>
|
||||
<addaction name="separator"/>
|
||||
@ -647,6 +648,11 @@
|
||||
<string>Sync index (remove deleted, update existing files)</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="menuOpenUserManualAction">
|
||||
<property name="text">
|
||||
<string>Open user manual</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
@ -2,13 +2,15 @@
|
||||
#include "previewgenerator.h"
|
||||
#include "previewgeneratorpdf.h"
|
||||
#include "previewgeneratorplaintext.h"
|
||||
#include "previewgeneratorodt.h"
|
||||
|
||||
static PreviewGenerator *plainTextGenerator = new PreviewGeneratorPlainText();
|
||||
|
||||
static QMap<QString, PreviewGenerator *> generators{
|
||||
{"pdf", new PreviewGeneratorPdf()}, {"txt", plainTextGenerator}, {"md", plainTextGenerator},
|
||||
{"py", plainTextGenerator}, {"java", plainTextGenerator}, {"js", plainTextGenerator},
|
||||
{"cpp", plainTextGenerator}, {"c", plainTextGenerator}, {"sql", plainTextGenerator}};
|
||||
{"cpp", plainTextGenerator}, {"c", plainTextGenerator}, {"sql", plainTextGenerator},
|
||||
{"odt", new PreviewGeneratorOdt()}};
|
||||
|
||||
PreviewGenerator *PreviewGenerator::get(QFileInfo &info)
|
||||
{
|
||||
|
32
gui/previewgeneratorodt.cpp
Normal file
32
gui/previewgeneratorodt.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <quazip.h>
|
||||
#include <quazipfile.h>
|
||||
#include "previewgeneratorplaintext.h"
|
||||
#include "previewgeneratorodt.h"
|
||||
#include "previewresultodt.h"
|
||||
#include "../shared/tagstripperprocessor.h"
|
||||
|
||||
QSharedPointer<PreviewResult> PreviewGeneratorOdt::generate(RenderConfig config, QString documentPath,
|
||||
unsigned int page)
|
||||
{
|
||||
PreviewResultOdt *result = new PreviewResultOdt(documentPath, page);
|
||||
|
||||
QFileInfo info{documentPath};
|
||||
|
||||
QuaZipFile zipFile(documentPath);
|
||||
zipFile.setFileName("content.xml");
|
||||
if(!zipFile.open(QIODevice::ReadOnly))
|
||||
{
|
||||
return QSharedPointer<PreviewResult>(result);
|
||||
}
|
||||
QByteArray entireContent = zipFile.readAll();
|
||||
if(entireContent.isEmpty())
|
||||
{
|
||||
throw LooqsGeneralException("Error while reading content.xml of " + documentPath);
|
||||
}
|
||||
TagStripperProcessor tsp;
|
||||
QString content = tsp.process(entireContent).first().content;
|
||||
|
||||
PreviewGeneratorPlainText plainTextGenerator;
|
||||
result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName()));
|
||||
return QSharedPointer<PreviewResult>(result);
|
||||
}
|
12
gui/previewgeneratorodt.h
Normal file
12
gui/previewgeneratorodt.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef PREVIEWGENERATORODT_H
|
||||
#define PREVIEWGENERATORODT_H
|
||||
|
||||
#include "previewgenerator.h"
|
||||
class PreviewGeneratorOdt : public PreviewGenerator
|
||||
{
|
||||
public:
|
||||
using PreviewGenerator::PreviewGenerator;
|
||||
|
||||
QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page);
|
||||
};
|
||||
#endif // PREVIEWGENERATORODT_H
|
@ -3,24 +3,15 @@
|
||||
#include "previewgeneratorplaintext.h"
|
||||
#include "previewresultplaintext.h"
|
||||
|
||||
QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig config, QString documentPath,
|
||||
unsigned int page)
|
||||
QString PreviewGeneratorPlainText::generatePreviewText(QString content, RenderConfig config, QString fileName)
|
||||
{
|
||||
PreviewResultPlainText *result = new PreviewResultPlainText(documentPath, page);
|
||||
QFile file(documentPath);
|
||||
if(!file.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
return QSharedPointer<PreviewResultPlainText>(result);
|
||||
}
|
||||
QTextStream in(&file);
|
||||
|
||||
QString resulText = "";
|
||||
QString content = in.readAll();
|
||||
|
||||
QMap<int, QString> snippet;
|
||||
|
||||
int coveredRange = 0;
|
||||
int coveredRange = -1;
|
||||
int lastWordPos = -1;
|
||||
|
||||
int lastWordPos = 0;
|
||||
QHash<QString, int> countmap;
|
||||
|
||||
const unsigned int maxSnippets = 7;
|
||||
@ -71,9 +62,7 @@ QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig c
|
||||
resulText.replace(word, "<span style=\"background-color: yellow;\">" + word + "</span>", Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
QFileInfo info{documentPath};
|
||||
|
||||
QString header = "<b>" + info.fileName() + "</b> ";
|
||||
QString header = "<b>" + fileName + "</b> ";
|
||||
for(QString &word : config.wordsToHighlight)
|
||||
{
|
||||
header += word + ": " + QString::number(countmap[word]) + " ";
|
||||
@ -85,6 +74,22 @@ QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig c
|
||||
|
||||
header += "<hr>";
|
||||
|
||||
result->setText(header + resulText.replace("\n", "<br>").mid(0, 1000));
|
||||
return header + resulText.replace("\n", "<br>").mid(0, 1000);
|
||||
}
|
||||
|
||||
QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig config, QString documentPath,
|
||||
unsigned int page)
|
||||
{
|
||||
PreviewResultPlainText *result = new PreviewResultPlainText(documentPath, page);
|
||||
QFile file(documentPath);
|
||||
if(!file.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
return QSharedPointer<PreviewResultPlainText>(result);
|
||||
}
|
||||
QTextStream in(&file);
|
||||
|
||||
QString content = in.readAll();
|
||||
QFileInfo info{documentPath};
|
||||
result->setText(generatePreviewText(content, config, info.fileName()));
|
||||
return QSharedPointer<PreviewResultPlainText>(result);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ class PreviewGeneratorPlainText : public PreviewGenerator
|
||||
{
|
||||
public:
|
||||
using PreviewGenerator::PreviewGenerator;
|
||||
QString generatePreviewText(QString content, RenderConfig config, QString fileName);
|
||||
QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page);
|
||||
};
|
||||
|
||||
|
1
gui/previewresultodt.cpp
Normal file
1
gui/previewresultodt.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "previewresultodt.h"
|
10
gui/previewresultodt.h
Normal file
10
gui/previewresultodt.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef PREVIEWRESULTODT_H
|
||||
#define PREVIEWRESULTODT_H
|
||||
#include "previewresultplaintext.h"
|
||||
|
||||
class PreviewResultOdt : public PreviewResultPlainText
|
||||
{
|
||||
using PreviewResultPlainText::PreviewResultPlainText;
|
||||
};
|
||||
|
||||
#endif // PREVIEWRESULTODT_H
|
@ -234,3 +234,8 @@ QString Common::versionText()
|
||||
QString tag = GIT_TAG;
|
||||
return tag + " (" + commitid + ") built " + __DATE__ + " " + __TIME__;
|
||||
}
|
||||
|
||||
QString Common::userManualUrl()
|
||||
{
|
||||
return QString("https://github.com/quitesimpleorg/looqs/blob/%1/USAGE.md").arg(QString(GIT_COMMIT_ID));
|
||||
}
|
||||
|
@ -25,5 +25,6 @@ bool isTextFile(QFileInfo fileInfo);
|
||||
bool isMountPath(QString path);
|
||||
bool noSandboxModeRequested();
|
||||
QString versionText();
|
||||
QString userManualUrl();
|
||||
} // namespace Common
|
||||
#endif
|
||||
|
불러오는 중...
Reference in New Issue
Block a user