LeechCraft 0.6.70-16373-g319c272718
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
15namespace LC::Util
16{
33 {
34 QWebEngineView * const WebView_;
35 QString PreviousFindText_;
36 public:
46 FindNotificationWE (const ICoreProxy_ptr& proxy, QWebEngineView *near)
47 : FindNotification { proxy, near }
48 , WebView_ { near }
49 {
50 }
51
58 static QWebEnginePage::FindFlags ToPageFlags (FindFlags findFlags)
59 {
60 QWebEnginePage::FindFlags pageFlags;
61 auto check = [&pageFlags, findFlags] (FindFlag ourFlag, QWebEnginePage::FindFlag pageFlag)
62 {
63 if (findFlags & ourFlag)
64 pageFlags |= pageFlag;
65 };
66 check (FindCaseSensitively, QWebEnginePage::FindCaseSensitively);
67 check (FindBackwards, QWebEnginePage::FindBackward);
68 return pageFlags;
69 }
70 private:
71 void ClearFindResults ()
72 {
73 PreviousFindText_.clear ();
74 WebView_->page ()->findText ({});
75 }
76 protected:
77 void HandleNext (const QString& text, FindFlags findFlags) override
78 {
79 if (PreviousFindText_ != text)
80 {
81 ClearFindResults ();
82 PreviousFindText_ = text;
83 }
84
85 WebView_->page ()->findText (text, ToPageFlags (findFlags),
86 [this] (bool found) { SetSuccessful (found); });
87 }
88
89 void Reject () override
90 {
91 FindNotification::Reject ();
92 ClearFindResults ();
93 }
94 };
95}
A horizontal bar with typical widgets for text search.
A helper class to aid connecting FindNotification with QtWebEngine.
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:181