1 // For license of this file, see <project-root-folder>/LICENSE.md.
2 
3 #ifndef WEBBROWSER_H
4 #define WEBBROWSER_H
5 
6 #include "gui/tabcontent.h"
7 
8 #include "core/message.h"
9 #include "network-web/webpage.h"
10 #include "services/abstract/rootitem.h"
11 
12 #include <QPointer>
13 #include <QToolBar>
14 
15 class QToolButton;
16 class QVBoxLayout;
17 class QHBoxLayout;
18 class QProgressBar;
19 class QMenu;
20 class QLabel;
21 class TabWidget;
22 class WebViewer;
23 class LocationLineEdit;
24 class DiscoverFeedsButton;
25 class SearchTextWidget;
26 
27 class WebBrowser : public TabContent {
28   Q_OBJECT
29 
30   public:
31     explicit WebBrowser(QWidget* parent = nullptr);
32     virtual ~WebBrowser();
33 
34     virtual WebBrowser* webBrowser() const;
35 
36     WebViewer* viewer() const;
37 
38     double verticalScrollBarPosition() const;
39     void setVerticalScrollBarPosition(double pos);
40 
41   public slots:
42     void reloadFontSettings();
43     void increaseZoom();
44     void decreaseZoom();
45     void resetZoom();
46 
47     void clear(bool also_hide);
48     void loadUrl(const QString& url);
49     void loadUrl(const QUrl& url);
50     void loadMessages(const QList<Message>& messages, RootItem* root);
51     void loadMessage(const Message& message, RootItem* root);
52     void setNavigationBarVisible(bool visible);
53 
54   protected:
55     virtual bool eventFilter(QObject* watched, QEvent* event);
56 
57   private slots:
58     void openCurrentSiteInSystemBrowser();
59     void updateUrl(const QUrl& url);
60     void onLoadingStarted();
61     void onLoadingProgress(int progress);
62     void onLoadingFinished(bool success);
63     void onTitleChanged(const QString& new_title);
64     void onIconChanged(const QIcon& icon);
65 
66   signals:
67     void closeRequested();
68     void iconChanged(int index, const QIcon& icon);
69     void titleChanged(int index, const QString& title);
70 
71   private:
72     void initializeLayout();
73     void createConnections();
74 
75     Message* findMessage(int id);
76 
77   private:
78     QVBoxLayout* m_layout;
79     QToolBar* m_toolBar;
80     WebViewer* m_webView;
81     SearchTextWidget* m_searchWidget;
82     LocationLineEdit* m_txtLocation;
83     DiscoverFeedsButton* m_btnDiscoverFeeds;
84     QProgressBar* m_loadingProgress;
85     QAction* m_actionBack;
86     QAction* m_actionForward;
87     QAction* m_actionReload;
88     QAction* m_actionStop;
89     QAction* m_actionOpenInSystemBrowser;
90     QList<Message> m_messages;
91     QPointer<RootItem> m_root;
92 };
93 
webBrowser()94 inline WebBrowser* WebBrowser::webBrowser() const {
95   return const_cast<WebBrowser*>(this);
96 }
97 
viewer()98 inline WebViewer* WebBrowser::viewer() const {
99   return m_webView;
100 }
101 
setNavigationBarVisible(bool visible)102 inline void WebBrowser::setNavigationBarVisible(bool visible) {
103   m_toolBar->setVisible(visible);
104 }
105 
106 #endif // WEBBROWSER_H
107