Add search to snippets window + dont display snippets where no actual match is found
This commit is contained in:
parent
ec9bdfa882
commit
9b1a23385d
3 changed files with 167 additions and 33 deletions
|
@ -16,15 +16,90 @@
|
||||||
<property name="sizeGripEnabled">
|
<property name="sizeGripEnabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWebView" name="webView">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<property name="url">
|
<item>
|
||||||
<url>
|
<widget class="QWebView" name="webView">
|
||||||
<string>about:blank</string>
|
<property name="url">
|
||||||
</url>
|
<url>
|
||||||
</property>
|
<string>about:blank</string>
|
||||||
</widget>
|
</url>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QFrame" name="searchFM">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::StyledPanel</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="searchClosePB">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">X</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle">
|
||||||
|
<enum>Qt::ToolButtonTextOnly</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="searchLB">
|
||||||
|
<property name="text">
|
||||||
|
<string>Find:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="searchLE">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="nextPB">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Next</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="prevPB">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Prev</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
@ -63,5 +138,21 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>searchClosePB</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>searchFM</receiver>
|
||||||
|
<slot>hide()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>33</x>
|
||||||
|
<y>414</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>328</x>
|
||||||
|
<y>414</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -21,8 +21,13 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#include <QWebSettings>
|
||||||
|
#include <QWebFrame>
|
||||||
|
#include <QShortcut>
|
||||||
|
|
||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
#include "recoll.h"
|
#include "recoll.h"
|
||||||
#include "snippets_w.h"
|
#include "snippets_w.h"
|
||||||
|
@ -50,6 +55,25 @@ void SnippetsW::init()
|
||||||
if (m_source.isNull())
|
if (m_source.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
searchFM->hide();
|
||||||
|
webView->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal,
|
||||||
|
Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
|
|
||||||
|
new QShortcut(QKeySequence::Find, this, SLOT(slotEditFind()));
|
||||||
|
new QShortcut(QKeySequence(Qt::Key_Slash), this, SLOT(slotEditFind()));
|
||||||
|
new QShortcut(QKeySequence::FindNext, this, SLOT(slotEditFindNext()));
|
||||||
|
new QShortcut(QKeySequence::FindPrevious, this,
|
||||||
|
SLOT(slotEditFindPrevious()));
|
||||||
|
connect(searchLE, SIGNAL(textChanged(const QString&)),
|
||||||
|
this, SLOT(slotSearchTextChanged(const QString&)));
|
||||||
|
connect(nextPB, SIGNAL(clicked()), this, SLOT(slotEditFindNext()));
|
||||||
|
new QShortcut(QKeySequence(Qt::Key_F3), this, SLOT(slotEditFindNext()));
|
||||||
|
connect(prevPB, SIGNAL(clicked()), this, SLOT(slotEditFindPrevious()));
|
||||||
|
connect(webView, SIGNAL(linkClicked(const QUrl &)),
|
||||||
|
this, SLOT(linkWasClicked(const QUrl &)));
|
||||||
|
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
||||||
|
|
||||||
// Make title out of file name if none yet
|
// Make title out of file name if none yet
|
||||||
string titleOrFilename;
|
string titleOrFilename;
|
||||||
string utf8fn;
|
string utf8fn;
|
||||||
|
@ -58,7 +82,6 @@ void SnippetsW::init()
|
||||||
if (titleOrFilename.empty()) {
|
if (titleOrFilename.empty()) {
|
||||||
titleOrFilename = utf8fn;
|
titleOrFilename = utf8fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
setWindowTitle(QString::fromUtf8(titleOrFilename.c_str()));
|
setWindowTitle(QString::fromUtf8(titleOrFilename.c_str()));
|
||||||
|
|
||||||
vector<Rcl::Snippet> vpabs;
|
vector<Rcl::Snippet> vpabs;
|
||||||
|
@ -67,43 +90,60 @@ void SnippetsW::init()
|
||||||
HighlightData hdata;
|
HighlightData hdata;
|
||||||
m_source->getTerms(hdata);
|
m_source->getTerms(hdata);
|
||||||
|
|
||||||
QString html = QString::fromAscii(
|
ostringstream oss;
|
||||||
|
oss <<
|
||||||
"<html><head>"
|
"<html><head>"
|
||||||
"<meta http-equiv=\"content-type\" "
|
"<meta http-equiv=\"content-type\" "
|
||||||
"content=\"text/html; charset=utf-8\"></head>"
|
"content=\"text/html; charset=utf-8\"></head>"
|
||||||
"<body style='overflow-x: scroll; white-space: nowrap'>"
|
"<body style='overflow-x: scroll; white-space: nowrap'>"
|
||||||
"<table>"
|
"<table>"
|
||||||
);
|
;
|
||||||
|
|
||||||
g_hiliter.set_inputhtml(false);
|
g_hiliter.set_inputhtml(false);
|
||||||
|
|
||||||
for (vector<Rcl::Snippet>::const_iterator it = vpabs.begin();
|
for (vector<Rcl::Snippet>::const_iterator it = vpabs.begin();
|
||||||
it != vpabs.end(); it++) {
|
it != vpabs.end(); it++) {
|
||||||
html += "<tr><td>";
|
|
||||||
if (it->page > 0) {
|
|
||||||
char txt[100];
|
|
||||||
sprintf(txt, "P. %d", it->page);
|
|
||||||
char url[100];
|
|
||||||
sprintf(url, "P%dT%s", it->page, it->term.c_str());
|
|
||||||
html += "<a href=\"";
|
|
||||||
html += url;
|
|
||||||
html += "\">";
|
|
||||||
html += txt;
|
|
||||||
html += "</a>";
|
|
||||||
}
|
|
||||||
html += "</td><td>";
|
|
||||||
list<string> lr;
|
list<string> lr;
|
||||||
g_hiliter.plaintorich(it->snippet, lr, hdata);
|
if (!g_hiliter.plaintorich(it->snippet, lr, hdata)) {
|
||||||
html.append(QString::fromUtf8(lr.front().c_str()));
|
LOGDEB1(("No match for [%s]\n", it->snippet.c_str()));
|
||||||
html.append("</td></tr>\n");
|
continue;
|
||||||
|
}
|
||||||
|
oss << "<tr><td>";
|
||||||
|
if (it->page > 0) {
|
||||||
|
oss << "<a href=\"P" << it->page << "T" << it->term << "\">"
|
||||||
|
<< "P. " << it->page << "</a>";
|
||||||
|
}
|
||||||
|
oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << endl;
|
||||||
}
|
}
|
||||||
html.append("</body></html>");
|
oss << "</body></html>";
|
||||||
webView->setHtml(html);
|
|
||||||
connect(webView, SIGNAL(linkClicked(const QUrl &)),
|
QWebSettings *ws = webView->page()->settings();
|
||||||
this, SLOT(linkWasClicked(const QUrl &)));
|
if (prefs.reslistfontfamily != "") {
|
||||||
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
ws->setFontFamily(QWebSettings::StandardFont, prefs.reslistfontfamily);
|
||||||
|
ws->setFontSize(QWebSettings::DefaultFontSize, prefs.reslistfontsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
webView->setHtml(QString::fromUtf8(oss.str().c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SnippetsW::slotEditFind()
|
||||||
|
{
|
||||||
|
searchFM->show();
|
||||||
|
searchLE->selectAll();
|
||||||
|
searchLE->setFocus();
|
||||||
|
}
|
||||||
|
void SnippetsW::slotEditFindNext()
|
||||||
|
{
|
||||||
|
webView->findText(searchLE->text());
|
||||||
|
}
|
||||||
|
void SnippetsW::slotEditFindPrevious()
|
||||||
|
{
|
||||||
|
webView->findText(searchLE->text(), QWebPage::FindBackward);
|
||||||
|
}
|
||||||
|
void SnippetsW::slotSearchTextChanged(const QString& txt)
|
||||||
|
{
|
||||||
|
webView->findText(txt);
|
||||||
|
}
|
||||||
|
|
||||||
void SnippetsW::linkWasClicked(const QUrl &url)
|
void SnippetsW::linkWasClicked(const QUrl &url)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,7 +38,10 @@ public:
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void linkWasClicked(const QUrl &);
|
virtual void linkWasClicked(const QUrl &);
|
||||||
|
virtual void slotEditFind();
|
||||||
|
virtual void slotEditFindNext();
|
||||||
|
virtual void slotEditFindPrevious();
|
||||||
|
virtual void slotSearchTextChanged(const QString&);
|
||||||
signals:
|
signals:
|
||||||
void startNativeViewer(Rcl::Doc, int pagenum, QString term);
|
void startNativeViewer(Rcl::Doc, int pagenum, QString term);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue