mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Advanced search - finishing, fixing bugs
This commit is contained in:
@@ -40,6 +40,7 @@ PDFAdvancedFindWidget::PDFAdvancedFindWidget(pdf::PDFDrawWidgetProxy* proxy, QWi
|
||||
connect(ui->regularExpressionsCheckbox, &QCheckBox::clicked, this, &PDFAdvancedFindWidget::updateUI);
|
||||
connect(m_proxy, &pdf::PDFDrawWidgetProxy::textLayoutChanged, this, &PDFAdvancedFindWidget::performSearch);
|
||||
connect(ui->resultsTableWidget, &QTableWidget::cellDoubleClicked, this, &PDFAdvancedFindWidget::onResultItemDoubleClicked);
|
||||
connect(ui->resultsTableWidget, &QTableWidget::itemSelectionChanged, this, &PDFAdvancedFindWidget::onSelectionChanged);
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -105,6 +106,19 @@ void PDFAdvancedFindWidget::on_searchButton_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::on_clearButton_clicked()
|
||||
{
|
||||
m_parameters = SearchParameters();
|
||||
m_findResults.clear();
|
||||
updateResultsUI();
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::onSelectionChanged()
|
||||
{
|
||||
m_textSelection.dirty();
|
||||
m_proxy->repaintNeeded();
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::onResultItemDoubleClicked(int row, int column)
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
@@ -144,6 +158,19 @@ void PDFAdvancedFindWidget::updateResultsUI()
|
||||
}
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::drawPage(QPainter* painter,
|
||||
pdf::PDFInteger pageIndex,
|
||||
const pdf::PDFPrecompiledPage* compiledPage,
|
||||
pdf::PDFTextLayoutGetter& layoutGetter,
|
||||
const QMatrix& pagePointToDevicePointMatrix) const
|
||||
{
|
||||
Q_UNUSED(compiledPage);
|
||||
|
||||
const pdf::PDFTextSelection& textSelection = getTextSelection();
|
||||
pdf::PDFTextSelectionPainter textSelectionPainter(&textSelection);
|
||||
textSelectionPainter.draw(painter, pageIndex, layoutGetter, pagePointToDevicePointMatrix);
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::performSearch()
|
||||
{
|
||||
if (m_parameters.isSearchFinished)
|
||||
@@ -215,7 +242,47 @@ void PDFAdvancedFindWidget::performSearch()
|
||||
m_findResults = textLayoutStorage->find(regularExpression, flowFlags);
|
||||
}
|
||||
|
||||
m_textSelection.dirty();
|
||||
m_proxy->repaintNeeded();
|
||||
|
||||
updateResultsUI();
|
||||
}
|
||||
|
||||
pdf::PDFTextSelection PDFAdvancedFindWidget::getTextSelectionImpl() const
|
||||
{
|
||||
pdf::PDFTextSelection result;
|
||||
|
||||
std::vector<size_t> selectedRowIndices;
|
||||
QModelIndexList selectedRows = ui->resultsTableWidget->selectionModel()->selectedRows();
|
||||
std::transform(selectedRows.cbegin(), selectedRows.cend(), std::back_inserter(selectedRowIndices), [] (const QModelIndex& index) { return index.row(); });
|
||||
std::sort(selectedRowIndices.begin(), selectedRowIndices.end());
|
||||
|
||||
for (size_t i = 0; i < m_findResults.size(); ++i)
|
||||
{
|
||||
const pdf::PDFFindResult& findResult = m_findResults[i];
|
||||
|
||||
QColor color(Qt::blue);
|
||||
if (std::binary_search(selectedRowIndices.cbegin(), selectedRowIndices.cend(), i))
|
||||
{
|
||||
color = QColor(Qt::yellow);
|
||||
}
|
||||
|
||||
result.addItems(findResult.textSelectionItems, color);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::showEvent(QShowEvent* event)
|
||||
{
|
||||
BaseClass::showEvent(event);
|
||||
m_proxy->registerDrawInterface(this);
|
||||
}
|
||||
|
||||
void PDFAdvancedFindWidget::hideEvent(QHideEvent* event)
|
||||
{
|
||||
m_proxy->unregisterDrawInterface(this);
|
||||
BaseClass::hideEvent(event);
|
||||
}
|
||||
|
||||
} // namespace pdfviewer
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#define PDFADVANCEDFINDWIDGET_H
|
||||
|
||||
#include "pdfglobal.h"
|
||||
#include "pdfdrawspacecontroller.h"
|
||||
#include "pdftextlayout.h"
|
||||
|
||||
#include <QWidget>
|
||||
@@ -37,25 +38,44 @@ class PDFDrawWidgetProxy;
|
||||
namespace pdfviewer
|
||||
{
|
||||
|
||||
class PDFAdvancedFindWidget : public QWidget
|
||||
class PDFAdvancedFindWidget : public QWidget, public pdf::IDocumentDrawInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
using BaseClass = QWidget;
|
||||
|
||||
public:
|
||||
explicit PDFAdvancedFindWidget(pdf::PDFDrawWidgetProxy* proxy, QWidget* parent = nullptr);
|
||||
virtual ~PDFAdvancedFindWidget() override;
|
||||
|
||||
virtual void drawPage(QPainter* painter,
|
||||
pdf::PDFInteger pageIndex,
|
||||
const pdf::PDFPrecompiledPage* compiledPage,
|
||||
pdf::PDFTextLayoutGetter& layoutGetter,
|
||||
const QMatrix& pagePointToDevicePointMatrix) const override;
|
||||
|
||||
void setDocument(const pdf::PDFDocument* document);
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent* event) override;
|
||||
virtual void hideEvent(QHideEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void on_searchButton_clicked();
|
||||
void onSelectionChanged();
|
||||
void onResultItemDoubleClicked(int row, int column);
|
||||
|
||||
void on_clearButton_clicked();
|
||||
|
||||
private:
|
||||
void updateUI();
|
||||
void updateResultsUI();
|
||||
void performSearch();
|
||||
|
||||
pdf::PDFTextSelection getTextSelection() const { return m_textSelection.get(this, &PDFAdvancedFindWidget::getTextSelectionImpl); }
|
||||
pdf::PDFTextSelection getTextSelectionImpl() const;
|
||||
|
||||
struct SearchParameters
|
||||
{
|
||||
QString phrase;
|
||||
@@ -74,6 +94,7 @@ private:
|
||||
const pdf::PDFDocument* m_document;
|
||||
SearchParameters m_parameters;
|
||||
pdf::PDFFindResults m_findResults;
|
||||
mutable pdf::PDFCachedItem<pdf::PDFTextSelection> m_textSelection;
|
||||
};
|
||||
|
||||
} // namespace pdfviewer
|
||||
|
@@ -29,38 +29,21 @@
|
||||
<property name="title">
|
||||
<string>Search Settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="searchSettingsGroupBoxLayout" columnstretch="0,1,0">
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="searchPhraseEdit"/>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QCheckBox" name="regularExpressionsCheckbox">
|
||||
<layout class="QGridLayout" name="searchSettingsGroupBoxLayout" columnstretch="0,1,0,0">
|
||||
<item row="5" column="3">
|
||||
<widget class="QPushButton" name="searchButton">
|
||||
<property name="text">
|
||||
<string>Use regular expressions</string>
|
||||
<string>Search</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="QCheckBox" name="wholeWordsOnlyCheckBox">
|
||||
<property name="text">
|
||||
<string>Whole words only</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="searchLabel">
|
||||
<property name="text">
|
||||
<string>Search for:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2">
|
||||
<widget class="QCheckBox" name="caseSensitiveCheckBox">
|
||||
<property name="text">
|
||||
<string>Case sensitive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="removeSoftHyphenCheckBox">
|
||||
<property name="text">
|
||||
@@ -68,10 +51,34 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QPushButton" name="searchButton">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="searchLabel">
|
||||
<property name="text">
|
||||
<string>Search</string>
|
||||
<string>Search for:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="3">
|
||||
<widget class="QCheckBox" name="caseSensitiveCheckBox">
|
||||
<property name="text">
|
||||
<string>Case sensitive</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="searchPhraseEdit"/>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="3">
|
||||
<widget class="QCheckBox" name="regularExpressionsCheckbox">
|
||||
<property name="text">
|
||||
<string>Use regular expressions</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QPushButton" name="clearButton">
|
||||
<property name="text">
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Reference in New Issue
Block a user