LeechCraft 0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
findnotificationwe.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 <QWebEnginePage>
13#include <QWebEngineView>
14#include <QWebEngineFindTextResult>
15
16namespace LC::Util
17{
34 {
35 QWebEngineView * const WebView_;
36 QString PreviousFindText_;
37 public:
47 FindNotificationWE (const ICoreProxy_ptr& proxy, QWebEngineView *near)
48 : FindNotification { proxy, near }
49 , WebView_ { near }
50 {
51 }
52
59 static QWebEnginePage::FindFlags ToPageFlags (FindFlags findFlags)
60 {
61 QWebEnginePage::FindFlags pageFlags;
62 auto check = [&pageFlags, findFlags] (FindFlag ourFlag, QWebEnginePage::FindFlag pageFlag)
63 {
64 if (findFlags & ourFlag)
65 pageFlags |= pageFlag;
66 };
67 check (FindCaseSensitively, QWebEnginePage::FindCaseSensitively);
68 check (FindBackwards, QWebEnginePage::FindBackward);
69 return pageFlags;
70 }
71 private:
72 void ClearFindResults ()
73 {
74 PreviousFindText_.clear ();
75 WebView_->page ()->findText ({});
76 }
77 protected:
78 void HandleNext (const QString& text, FindFlags findFlags) override
79 {
80 if (PreviousFindText_ != text)
81 {
82 ClearFindResults ();
83 PreviousFindText_ = text;
84 }
85
86 WebView_->page ()->findText (text, ToPageFlags (findFlags),
87 [this] (const QWebEngineFindTextResult& found) { SetSuccessful (found.numberOfMatches ()); });
88 }
89
90 void Reject () override
91 {
93 ClearFindResults ();
94 }
95 };
96}
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 QWebEnginePage::FindFlags ToPageFlags(FindFlags findFlags)
Converts the given findFlags to WebKit find flags.
FindNotificationWE(const ICoreProxy_ptr &proxy, QWebEngineView *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:177