LeechCraft 0.6.70-17609-g3dde4097dd
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#if QT_VERSION_MAJOR >= 6
15#include <QWebEngineFindTextResult>
16#endif
17
18namespace LC::Util
19{
36 {
37 QWebEngineView * const WebView_;
38 QString PreviousFindText_;
39 public:
49 FindNotificationWE (const ICoreProxy_ptr& proxy, QWebEngineView *near)
50 : FindNotification { proxy, near }
51 , WebView_ { near }
52 {
53 }
54
61 static QWebEnginePage::FindFlags ToPageFlags (FindFlags findFlags)
62 {
63 QWebEnginePage::FindFlags pageFlags;
64 auto check = [&pageFlags, findFlags] (FindFlag ourFlag, QWebEnginePage::FindFlag pageFlag)
65 {
66 if (findFlags & ourFlag)
67 pageFlags |= pageFlag;
68 };
69 check (FindCaseSensitively, QWebEnginePage::FindCaseSensitively);
70 check (FindBackwards, QWebEnginePage::FindBackward);
71 return pageFlags;
72 }
73 private:
74 void ClearFindResults ()
75 {
76 PreviousFindText_.clear ();
77 WebView_->page ()->findText ({});
78 }
79 protected:
80 void HandleNext (const QString& text, FindFlags findFlags) override
81 {
82 if (PreviousFindText_ != text)
83 {
84 ClearFindResults ();
85 PreviousFindText_ = text;
86 }
87
88#if QT_VERSION_MAJOR >= 6
89 WebView_->page ()->findText (text, ToPageFlags (findFlags),
90 [this] (const QWebEngineFindTextResult& found) { SetSuccessful (found.numberOfMatches ()); });
91#else
92 WebView_->page ()->findText (text, ToPageFlags (findFlags),
93 [this] (bool found) { SetSuccessful (found); });
94#endif
95 }
96
97 void Reject () override
98 {
100 ClearFindResults ();
101 }
102 };
103}
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:181