LeechCraft 0.6.70-17335-ge406ffdcaf
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
selectablebrowser.cpp
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#include "selectablebrowser.h"
10#include <QVBoxLayout>
11#include <util/sll/visitor.h>
12
13namespace LC::Util
14{
16 : QWidget (parent)
17 {
18 auto lay = new QVBoxLayout;
19 lay->setContentsMargins (0, 0, 0, 0);
20 setLayout (lay);
21 setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
22
23 PrepareInternal ();
24 }
25
27 {
28 std::unique_ptr<IWebWidget> external;
29 if (browser)
30 external = browser->CreateWidget ();
31
32 if (external)
33 {
34 external->SetNavBarVisible (NavBarVisible_);
35 external->SetEverythingElseVisible (EverythingElseVisible_);
36 layout ()->addWidget (external->GetQWidget ());
37 Browser_ = std::move (external);
38 }
39 else
40 PrepareInternal ();
41 }
42
43 void SelectableBrowser::SetHtml (const QString& html, const QUrl& base)
44 {
45 Util::Visit (Browser_,
46 [&] (IWebWidget_ptr& browser) { browser->SetHtml (html, base); },
47 [&] (QTextBrowser_ptr& browser) { browser->setHtml (html); });
48 }
49
51 {
52 NavBarVisible_ = visible;
53 Util::Visit (Browser_,
54 [&] (IWebWidget_ptr& browser) { browser->SetNavBarVisible (visible); },
55 [&] (QTextBrowser_ptr&) {});
56 }
57
59 {
60 EverythingElseVisible_ = visible;
61 Util::Visit (Browser_,
62 [&] (IWebWidget_ptr& browser) { browser->SetEverythingElseVisible (visible); },
63 [&] (QTextBrowser_ptr&) {});
64 }
65
66 void SelectableBrowser::PrepareInternal ()
67 {
68 auto browser = std::make_unique<QTextBrowser> ();
69 browser->setOpenExternalLinks (true);
70 browser->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding);
71 layout ()->addWidget (browser.get ());
72
73 Browser_ = std::move (browser);
74 }
75}
Base class for plugins that provide a web browser.
Definition iwebbrowser.h:84
virtual std::unique_ptr< IWebWidget > CreateWidget() const =0
Returns the IWebWidget for use in another modules of LeechCraft.
virtual void SetHtml(const QString &html, const QUrl &base={})=0
Sets the contents of the web widget to the specified html.
virtual void SetNavBarVisible(bool visible)=0
Sets whether the navigation bar of the widget (where the address bar and reload/back/forward/etc butt...
virtual void SetEverythingElseVisible(bool visible)=0
Shows or hides every other panel in the browser but navbar.
void SetHtml(const QString &html, const QUrl &base=QUrl())
Sets the HTML content to display.
void SetEverythingElseVisible(bool visible)
Sets whether other UI elements should be visible.
void SetNavBarVisible(bool visible)
Sets whether navigation bar should be visible.
SelectableBrowser(QWidget *parent=nullptr)
Constructs the browser with the given parent.
void Construct(IWebBrowser *browser)
Initialize the widget with the browser plugin.
auto Visit(const Either< Left, Right > &either, Args &&... args)
Definition either.h:204