From e1b98c1e22400c7aad92c692e54df795addc21da Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 17 Jul 2019 11:23:06 +0200 Subject: [PATCH] GUI: snippets: add context menu to switch page/relevance sort --- src/qtgui/snippets_w.cpp | 35 +++++++++++++++++++++++++++++++++-- src/qtgui/snippets_w.h | 6 ++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/qtgui/snippets_w.cpp b/src/qtgui/snippets_w.cpp index be36446c..db1c5054 100644 --- a/src/qtgui/snippets_w.cpp +++ b/src/qtgui/snippets_w.cpp @@ -77,6 +77,7 @@ static PlainToRichQtSnippets g_hiliter; void SnippetsW::init() { + m_sortingByPage = prefs.snipwSortByPage; QPushButton *searchButton = new QPushButton(tr("Search")); searchButton->setAutoDefault(false); buttonBox->addButton(searchButton, QDialogButtonBox::ActionRole); @@ -102,6 +103,7 @@ void SnippetsW::init() connect(nextPB, SIGNAL(clicked()), this, SLOT(slotEditFindNext())); connect(prevPB, SIGNAL(clicked()), this, SLOT(slotEditFindPrevious())); + delete browserw; #if defined(USING_WEBKIT) browserw = new QWebView(this); @@ -119,6 +121,9 @@ void SnippetsW::init() } if (!prefs.snipCssFile.isEmpty()) ws->setUserStyleSheetUrl(QUrl::fromLocalFile(prefs.snipCssFile)); + browserw->setContextMenuPolicy(Qt::CustomContextMenu); + connect(browserw, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(createPopupMenu(const QPoint&))); #elif defined(USING_WEBENGINE) browserw = new QWebEngineView(this); verticalLayout->insertWidget(0, browserw); @@ -129,6 +134,9 @@ void SnippetsW::init() ws->setFontSize(QWEBSETTINGS::DefaultFontSize, prefs.reslistfontsize); } // Stylesheet TBD + browserw->setContextMenuPolicy(Qt::CustomContextMenu); + connect(browserw, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(createPopupMenu(const QPoint&))); #else browserw = new QTextBrowser(this); verticalLayout->insertWidget(0, browserw); @@ -147,9 +155,33 @@ void SnippetsW::init() #endif } +void SnippetsW::createPopupMenu(const QPoint& pos) +{ + QMenu *popup = new QMenu(this); + if (m_sortingByPage) { + popup->addAction(tr("Sort By Relevance"), this, + SLOT(reloadByRelevance())); + } else { + popup->addAction(tr("Sort By Page"), this, SLOT(reloadByPage())); + } + popup->popup(mapToGlobal(pos)); +} + +void SnippetsW::reloadByRelevance() +{ + m_sortingByPage = false; + onSetDoc(m_doc, m_source); +} +void SnippetsW::reloadByPage() +{ + m_sortingByPage = true; + onSetDoc(m_doc, m_source); +} + void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr source) { m_doc = doc; + m_source = source; if (!source) return; @@ -168,8 +200,7 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr source) setWindowTitle(title); vector vpabs; - source->getAbstract(m_doc, vpabs, - prefs.snipwMaxLength, prefs.snipwSortByPage); + source->getAbstract(m_doc, vpabs, prefs.snipwMaxLength, m_sortingByPage); HighlightData hdata; source->getTerms(hdata); diff --git a/src/qtgui/snippets_w.h b/src/qtgui/snippets_w.h index 21ebd775..ce421aac 100644 --- a/src/qtgui/snippets_w.h +++ b/src/qtgui/snippets_w.h @@ -44,18 +44,24 @@ public: public slots: virtual void onLinkClicked(const QUrl &); virtual void onSetDoc(Rcl::Doc doc, std::shared_ptr source); + virtual void createPopupMenu(const QPoint& pos); protected slots: virtual void slotEditFind(); virtual void slotEditFindNext(); virtual void slotEditFindPrevious(); virtual void slotSearchTextChanged(const QString&); + virtual void reloadByRelevance(); + virtual void reloadByPage(); + signals: void startNativeViewer(Rcl::Doc, int pagenum, QString term); private: void init(); + std::shared_ptr m_source; Rcl::Doc m_doc; + bool m_sortingByPage; }; #ifdef USING_WEBENGINE