LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
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 
15 namespace LC::Util
16 {
32  class UTIL_GUI_API FindNotificationWE : public FindNotification
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  {
92  ClearFindResults ();
93  }
94  };
95 }
LC::Util
Definition: icoreproxy.h:33
LC::Util::FindNotification::FindFlag
FindFlag
Definition: findnotification.h:68
findnotification.h
LC::Util::FindNotification::Reject
virtual void Reject()
Definition: findnotification.cpp:134
UTIL_GUI_API
#define UTIL_GUI_API
Definition: guiconfig.h:16
ICoreProxy_ptr
std::shared_ptr< ICoreProxy > ICoreProxy_ptr
Definition: icoreproxy.h:181