Commit ab5d03ce authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

continue to implement search

parent 1c72b524
......@@ -7,11 +7,13 @@
#include "findutils.h"
#include "textfindreplacewidget.h"
#include <QDebug>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QRegularExpression>
#include <QTextCursor>
#include <QTextDocument>
#include <QTextEdit>
using namespace KPIMTextEdit;
......@@ -37,7 +39,7 @@ int FindUtils::replaceAll(QTextDocument *document, const TextFindWidget *findWid
c.endEditBlock();
return count;
}
#include <QDebug>
bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
{
const QString text = FindUtils::normalize(view->document()->toPlainText());
......@@ -63,6 +65,31 @@ bool FindUtils::find(QPlainTextEdit *view, const TextFindWidget *findWidget)
return false;
}
bool FindUtils::find(QTextEdit *view, const TextFindWidget *findWidget)
{
const QString text = FindUtils::normalize(view->document()->toPlainText());
QTextDocument doc(text);
QTextCursor c(&doc);
QTextCursor docCusor(view->textCursor());
c.setPosition(docCusor.position());
qDebug() << " docCusor.position() " << docCusor.position();
QTextDocument::FindFlags flags = findWidget->searchOptions() & ~QTextDocument::FindBackward;
if (findWidget->isRegularExpression()) {
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
} else {
c = doc.find(FindUtils::normalize(findWidget->searchText()), c, flags);
}
if (!c.isNull()) {
qDebug() << " c.selectionStart() " << c.selectionStart() << "c.selectionEnd() " << c.selectionEnd();
docCusor.setPosition(c.selectionStart());
docCusor.setPosition(c.selectionEnd(), QTextCursor::KeepAnchor);
view->setTextCursor(docCusor);
view->ensureCursorVisible();
return true;
}
return false;
}
// code from kitinerary/src/lib/stringutil.cpp
QChar FindUtils::normalize(QChar c)
{
......
......@@ -11,6 +11,7 @@
#include <qglobal.h>
class QTextDocument;
class QPlainTextEdit;
class QTextEdit;
namespace KPIMTextEdit
{
class TextFindWidget;
......@@ -29,6 +30,7 @@ Q_REQUIRED_RESULT int replaceAll(QTextDocument *document, const TextFindWidget *
Q_REQUIRED_RESULT QString normalize(QStringView str);
Q_REQUIRED_RESULT QChar normalize(QChar c);
Q_REQUIRED_RESULT bool find(QPlainTextEdit *view, const TextFindWidget *findWidget);
Q_REQUIRED_RESULT bool find(QTextEdit *view, const TextFindWidget *findWidget);
}
} // namespace KPIMTextEdit
......@@ -54,10 +54,7 @@ bool PlainTextEditFindBar::documentIsEmpty() const
bool PlainTextEditFindBar::searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions)
{
#ifdef SEARCH_DIACRITIC_WORD
// bool found = d->mView->find(text, searchOptions);
// if (!found) {
bool found = FindUtils::find(d->mView, mFindWidget);
//}
const bool found = FindUtils::find(d->mView, mFindWidget);
#else
const bool found = d->mView->find(text, searchOptions);
#endif
......
......@@ -15,6 +15,7 @@
#include <QTextEdit>
using namespace KPIMTextEdit;
#define SEARCH_DIACRITIC_WORD 1
class Q_DECL_HIDDEN KPIMTextEdit::RichTextEditFindBarPrivate
{
public:
......@@ -52,7 +53,11 @@ bool RichTextEditFindBar::documentIsEmpty() const
bool RichTextEditFindBar::searchInDocument(const QString &text, QTextDocument::FindFlags searchOptions)
{
#ifdef SEARCH_DIACRITIC_WORD
const bool found = FindUtils::find(d->mView, mFindWidget);
#else
const bool found = d->mView->find(text, searchOptions);
#endif
mFindWidget->setFoundMatch(found);
return found;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment