LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
findnotificationwk.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include "findnotification.h"
12#include <QWebPage>
13#include <QWebView>
14
15namespace LC::Util
16{
33 {
34 QWebView * const WebView_;
35 QString PreviousFindText_;
36 public:
46 FindNotificationWk (const ICoreProxy_ptr& proxy, QWebView *near)
47 : FindNotification { proxy, near }
48 , WebView_ { near }
49 {
50 connect (near,
51 &QWebView::loadFinished,
52 this,
53 [this]
54 {
55 if (PreviousFindText_.isEmpty ())
56 return;
57
58 ClearFindResults ();
59 FindNext ();
60 });
61 }
62
69 static QWebPage::FindFlags ToPageFlags (FindFlags findFlags)
70 {
71 QWebPage::FindFlags pageFlags;
72 auto check = [&pageFlags, findFlags] (FindFlag ourFlag, QWebPage::FindFlag pageFlag)
73 {
74 if (findFlags & ourFlag)
75 pageFlags |= pageFlag;
76 };
77 check (FindCaseSensitively, QWebPage::FindCaseSensitively);
78 check (FindBackwards, QWebPage::FindBackward);
79 check (FindWrapsAround, QWebPage::FindWrapsAroundDocument);
80 return pageFlags;
81 }
82 private:
83 void ClearFindResults ()
84 {
85 PreviousFindText_.clear ();
86 WebView_->page ()->findText ({}, QWebPage::HighlightAllOccurrences);
87 }
88 protected:
89 void HandleNext (const QString& text, FindFlags findFlags) override
90 {
91 const auto flags = ToPageFlags (findFlags);
92
93 if (PreviousFindText_ != text)
94 {
95 const auto nflags = flags | QWebPage::HighlightAllOccurrences;
96 WebView_->page ()->findText ({}, nflags);
97 WebView_->page ()->findText (text, nflags);
98 PreviousFindText_ = text;
99 }
100
101 const auto found = WebView_->page ()->findText (text, flags);
102 SetSuccessful (found);
103 }
104
105 void Reject () override
106 {
108 ClearFindResults ();
109 }
110 };
111}
void FindNext()
Search for the next occurrence of the search text.
FindNotification(const ICoreProxy_ptr &proxy, QWidget *near)
Creates the search widget in parent layout of near.
void SetSuccessful(bool successful)
Updates the widget to show whether the search has been successful.
void HandleNext(const QString &text, FindFlags findFlags) override
Called each time the user requests a search.
static QWebPage::FindFlags ToPageFlags(FindFlags findFlags)
Converts the given findFlags to WebKit find flags.
FindNotificationWk(const ICoreProxy_ptr &proxy, QWebView *near)
Constructs the find notification using the given proxy and near widget.
#define UTIL_GUI_API
Definition guiconfig.h:16
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition icoreproxy.h:181