preliminary implementation for the snippets "open to page" popup window
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <qvariant.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
|
||||
@@ -301,6 +301,7 @@ void RclMain::init()
|
||||
connect(restable, SIGNAL(docSaveToFileClicked(Rcl::Doc)),
|
||||
this, SLOT(saveDocToFile(Rcl::Doc)));
|
||||
|
||||
reslist->setRclMain(this);
|
||||
connect(this, SIGNAL(docSourceChanged(RefCntr<DocSequence>)),
|
||||
reslist, SLOT(setDocSource(RefCntr<DocSequence>)));
|
||||
connect(firstPageAction, SIGNAL(activated()),
|
||||
@@ -1501,8 +1502,9 @@ static bool lookForHtmlBrowser(string &exefile)
|
||||
return false;
|
||||
}
|
||||
|
||||
void RclMain::startNativeViewer(Rcl::Doc doc)
|
||||
void RclMain::startNativeViewer(Rcl::Doc doc, int pagenum)
|
||||
{
|
||||
LOGDEB(("RclMain::startNativeViewer: page %d\n", pagenum));
|
||||
// Look for appropriate viewer
|
||||
string cmdplusattr;
|
||||
if (prefs.useDesktopOpen) {
|
||||
@@ -1520,11 +1522,13 @@ void RclMain::startNativeViewer(Rcl::Doc doc)
|
||||
return;
|
||||
}
|
||||
|
||||
int pagenum = 1;
|
||||
if (m_source.isNotNull())
|
||||
pagenum = m_source->getFirstMatchPage(doc);
|
||||
if (pagenum == -1)
|
||||
if (pagenum == -1) {
|
||||
pagenum = 1;
|
||||
if (m_source.isNotNull())
|
||||
pagenum = m_source->getFirstMatchPage(doc);
|
||||
if (pagenum == -1)
|
||||
pagenum = 1;
|
||||
}
|
||||
char cpagenum[20];
|
||||
sprintf(cpagenum, "%d", pagenum);
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ public slots:
|
||||
virtual void docExpand(Rcl::Doc);
|
||||
virtual void startPreview(int docnum, Rcl::Doc doc, int keymods);
|
||||
virtual void startPreview(Rcl::Doc);
|
||||
virtual void startNativeViewer(Rcl::Doc);
|
||||
virtual void startNativeViewer(Rcl::Doc, int pagenum = -1);
|
||||
virtual void saveDocToFile(Rcl::Doc);
|
||||
virtual void previewNextInTab(Preview *, int sid, int docnum);
|
||||
virtual void previewPrevInTab(Preview *, int sid, int docnum);
|
||||
|
||||
@@ -25,6 +25,7 @@ HEADERS += \
|
||||
restable.h \
|
||||
rtitool.h \
|
||||
searchclause_w.h \
|
||||
snippets_w.h \
|
||||
spell_w.h \
|
||||
ssearch_w.h \
|
||||
uiprefs_w.h \
|
||||
@@ -46,6 +47,7 @@ SOURCES += \
|
||||
restable.cpp \
|
||||
rtitool.cpp \
|
||||
searchclause_w.cpp \
|
||||
snippets_w.cpp \
|
||||
spell_w.cpp \
|
||||
ssearch_w.cpp \
|
||||
uiprefs_w.cpp \
|
||||
@@ -64,6 +66,7 @@ FORMS = \
|
||||
restable.ui \
|
||||
rtitool.ui \
|
||||
spell.ui \
|
||||
snippets.ui \
|
||||
ssearchb.ui \
|
||||
uiprefs.ui \
|
||||
viewaction.ui \
|
||||
|
||||
+18
-1
@@ -50,6 +50,7 @@
|
||||
#include "refcntr.h"
|
||||
#include "internfile.h"
|
||||
#include "indexer.h"
|
||||
#include "snippets_w.h"
|
||||
|
||||
#include "reslist.h"
|
||||
#include "moc_reslist.cpp"
|
||||
@@ -272,7 +273,7 @@ static PlainToRichQtReslist g_hiliter;
|
||||
/////////////////////////////////////
|
||||
|
||||
ResList::ResList(QWidget* parent, const char* name)
|
||||
: RESLIST_PARENTCLASS(parent)
|
||||
: RESLIST_PARENTCLASS(parent), m_parent(0)
|
||||
{
|
||||
if (!name)
|
||||
setObjectName("resList");
|
||||
@@ -892,6 +893,8 @@ void ResList::createPopupMenu(const QPoint& pos)
|
||||
this, SLOT(menuPreviewParent()));
|
||||
popup->addAction(tr("&Open Parent document/folder"),
|
||||
this, SLOT(menuOpenParent()));
|
||||
popup->addAction(tr("Open &Snippets window"),
|
||||
this, SLOT(menuOpenSnippets()));
|
||||
popup->popup(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
@@ -943,6 +946,20 @@ void ResList::menuOpenParent()
|
||||
}
|
||||
}
|
||||
|
||||
void ResList::menuOpenSnippets()
|
||||
{
|
||||
Rcl::Doc doc;
|
||||
if (!getDoc(m_popDoc, doc) || m_source.isNull())
|
||||
return;
|
||||
SnippetsW *sp = new SnippetsW(doc, m_source);
|
||||
if (m_parent) {
|
||||
connect(sp, SIGNAL(startNativeViewer(Rcl::Doc, int)),
|
||||
m_parent, SLOT(startNativeViewer(Rcl::Doc, int)));
|
||||
}
|
||||
|
||||
sp->show();
|
||||
}
|
||||
|
||||
void ResList::menuEdit()
|
||||
{
|
||||
Rcl::Doc doc;
|
||||
|
||||
+7
-1
@@ -41,6 +41,7 @@ using std::pair;
|
||||
#include "rcldoc.h"
|
||||
#include "reslistpager.h"
|
||||
|
||||
class RclMain;
|
||||
class QtGuiResListPager;
|
||||
|
||||
/**
|
||||
@@ -66,7 +67,10 @@ class ResList : public RESLIST_PARENTCLASS
|
||||
int listId() const {return m_listId;}
|
||||
int pageFirstDocNum();
|
||||
void setFont();
|
||||
|
||||
void setRclMain(RclMain *m)
|
||||
{
|
||||
m_parent = m;
|
||||
}
|
||||
public slots:
|
||||
virtual void setDocSource(RefCntr<DocSequence> nsource);
|
||||
virtual void resetList(); // Erase current list
|
||||
@@ -84,6 +88,7 @@ class ResList : public RESLIST_PARENTCLASS
|
||||
virtual void menuExpand();
|
||||
virtual void menuPreviewParent();
|
||||
virtual void menuOpenParent();
|
||||
virtual void menuOpenSnippets();
|
||||
virtual void previewExposed(int);
|
||||
virtual void append(const QString &text);
|
||||
virtual void readDocSource();
|
||||
@@ -132,6 +137,7 @@ class ResList : public RESLIST_PARENTCLASS
|
||||
// so we store the page and display it when done.
|
||||
QString m_text;
|
||||
#endif
|
||||
RclMain *m_parent;
|
||||
|
||||
virtual void displayPage(); // Display current page
|
||||
static int newListId();
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Snippets</class>
|
||||
<widget class="QDialog" name="Snippets">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>516</width>
|
||||
<height>395</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Snippets</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWebView" name="webView">
|
||||
<property name="url">
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
</url>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>QtWebKit/QWebView</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>clicked(QAbstractButton*)</signal>
|
||||
<receiver>Snippets</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>257</x>
|
||||
<y>369</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>257</x>
|
||||
<y>197</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -0,0 +1,109 @@
|
||||
/* Copyright (C) 2012 J.F.Dockes
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include "autoconfig.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "recoll.h"
|
||||
#include "snippets_w.h"
|
||||
#include "guiutils.h"
|
||||
#include "rcldb.h"
|
||||
#include "rclhelp.h"
|
||||
#include "plaintorich.h"
|
||||
|
||||
class PlainToRichQtSnippets : public PlainToRich {
|
||||
public:
|
||||
virtual string startMatch(unsigned int)
|
||||
{
|
||||
return string("<span class='rclmatch' style='color: ")
|
||||
+ string((const char *)prefs.qtermcolor.toAscii()) + string("'>");
|
||||
}
|
||||
virtual string endMatch()
|
||||
{
|
||||
return string("</span>");
|
||||
}
|
||||
};
|
||||
static PlainToRichQtSnippets g_hiliter;
|
||||
|
||||
void SnippetsW::init()
|
||||
{
|
||||
if (m_source.isNull())
|
||||
return;
|
||||
|
||||
vector<pair<int, string> > vpabs;
|
||||
m_source->getAbstract(m_doc, vpabs);
|
||||
|
||||
HighlightData hdata;
|
||||
m_source->getTerms(hdata);
|
||||
|
||||
QString html = QString::fromAscii(
|
||||
"<html><head>"
|
||||
"<meta http-equiv=\"content-type\" "
|
||||
"content=\"text/html; charset=utf-8\"></head>"
|
||||
"<body style='overflow-x: scroll; white-space: nowrap'>");
|
||||
|
||||
g_hiliter.set_inputhtml(false);
|
||||
|
||||
for (vector<pair<int, string> >::const_iterator it = vpabs.begin();
|
||||
it != vpabs.end(); it++) {
|
||||
if (it->first > 0) {
|
||||
char buf[100];
|
||||
sprintf(buf, "P. %d", it->first);
|
||||
html += "<a href=\"";
|
||||
html += buf;
|
||||
html += "\">";
|
||||
html += buf;
|
||||
html += "</a> ";
|
||||
}
|
||||
list<string> lr;
|
||||
g_hiliter.plaintorich(it->second, lr, hdata);
|
||||
html.append(QString::fromUtf8(lr.front().c_str()));
|
||||
html.append("<br>\n");
|
||||
}
|
||||
html.append("</body></html>");
|
||||
webView->setHtml(html);
|
||||
connect(webView, SIGNAL(linkClicked(const QUrl &)),
|
||||
this, SLOT(linkWasClicked(const QUrl &)));
|
||||
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
|
||||
}
|
||||
|
||||
|
||||
void SnippetsW::linkWasClicked(const QUrl &url)
|
||||
{
|
||||
string ascurl = (const char *)url.toString().toAscii();;
|
||||
LOGDEB(("Snippets::linkWasClicked: [%s]\n", ascurl.c_str()));
|
||||
|
||||
if (ascurl.size() > 3) {
|
||||
int what = ascurl[0];
|
||||
switch (what) {
|
||||
case 'P':
|
||||
{
|
||||
int page = atoi(ascurl.c_str()+2);
|
||||
emit startNativeViewer(m_doc, page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGERR(("Snippets::linkWasClicked: bad link [%s]\n", ascurl.c_str()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* Copyright (C) 2012 J.F.Dockes
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef _SNIPPETS_W_H_INCLUDED_
|
||||
#define _SNIPPETS_W_H_INCLUDED_
|
||||
|
||||
#include "rcldoc.h"
|
||||
#include "refcntr.h"
|
||||
#include "docseq.h"
|
||||
#include "rclmain_w.h"
|
||||
|
||||
#include "ui_snippets.h"
|
||||
|
||||
class SnippetsW : public QWidget, public Ui::Snippets
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SnippetsW(Rcl::Doc doc, RefCntr<DocSequence> source, QWidget* parent = 0)
|
||||
: QWidget(parent), m_doc(doc), m_source(source)
|
||||
{
|
||||
setupUi((QDialog*)this);
|
||||
init();
|
||||
}
|
||||
|
||||
protected slots:
|
||||
virtual void linkWasClicked(const QUrl &);
|
||||
|
||||
signals:
|
||||
void startNativeViewer(Rcl::Doc, int pagenum);
|
||||
|
||||
private:
|
||||
void init();
|
||||
Rcl::Doc m_doc;
|
||||
RefCntr<DocSequence> m_source;
|
||||
};
|
||||
|
||||
#endif /* _SNIPPETS_W_H_INCLUDED_ */
|
||||
Reference in New Issue
Block a user