1 /* ============================================================
2 * Falkon - Qt web browser
3 * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 * ============================================================ */
18 #ifndef NAVIGATIONBAR_H
19 #define NAVIGATIONBAR_H
20 
21 #include <QWidget>
22 
23 #include "qzcommon.h"
24 
25 class QUrl;
26 class QHBoxLayout;
27 class QSplitter;
28 class QWebEngineHistoryItem;
29 
30 class ToolButton;
31 class WebSearchBar;
32 class BrowserWindow;
33 class ReloadStopButton;
34 class Menu;
35 class AbstractButtonInterface;
36 class TabbedWebView;
37 
38 class FALKON_EXPORT NavigationBar : public QWidget
39 {
40     Q_OBJECT
41     Q_PROPERTY(int layoutMargin READ layoutMargin WRITE setLayoutMargin)
42     Q_PROPERTY(int layoutSpacing READ layoutSpacing WRITE setLayoutSpacing)
43 
44 public:
45     explicit NavigationBar(BrowserWindow* window);
46     ~NavigationBar();
47 
48     void setSplitterSizes(int locationBar, int websearchBar);
49 
50     void setCurrentView(TabbedWebView *view);
51 
52     void showReloadButton();
53     void showStopButton();
54 
55     void enterFullScreen();
56     void leaveFullScreen();
57 
webSearchBar()58     WebSearchBar* webSearchBar() { return m_searchLine; }
splitter()59     QSplitter* splitter() { return m_navigationSplitter; }
60 
61     void setSuperMenuVisible(bool visible);
62 
63     int layoutMargin() const;
64     void setLayoutMargin(int margin);
65 
66     int layoutSpacing() const;
67     void setLayoutSpacing(int spacing);
68 
69     void addWidget(QWidget *widget, const QString &id, const QString &name);
70     void removeWidget(const QString &id);
71 
72     void addToolButton(AbstractButtonInterface *button);
73     void removeToolButton(AbstractButtonInterface *button);
74 
75 public Q_SLOTS:
76     void stop();
77     void reload();
78     void goBack();
79     void goBackInNewTab();
80     void goForward();
81     void goForwardInNewTab();
82 
83 private Q_SLOTS:
84     void aboutToShowHistoryNextMenu();
85     void aboutToShowHistoryBackMenu();
86     void aboutToShowToolsMenu();
87 
88     void loadHistoryIndex();
89     void loadHistoryIndexInNewTab(int index = -1);
90 
91     void clearHistory();
92     void contextMenuRequested(const QPoint &pos);
93     void openConfigurationDialog();
94     void toolActionActivated();
95 
96 private:
97     void loadSettings();
98     void reloadLayout();
99     void loadHistoryItem(const QWebEngineHistoryItem &item);
100     void loadHistoryItemInNewTab(const QWebEngineHistoryItem &item);
101 
102     BrowserWindow* m_window;
103     QHBoxLayout* m_layout;
104     QSplitter* m_navigationSplitter;
105     WebSearchBar* m_searchLine;
106 
107     Menu* m_menuBack;
108     Menu* m_menuForward;
109     ToolButton* m_buttonBack;
110     ToolButton* m_buttonForward;
111     ReloadStopButton* m_reloadStop;
112     Menu *m_menuTools;
113     ToolButton* m_supMenu;
114     ToolButton *m_exitFullscreen;
115     QMetaObject::Connection m_backConnection;
116     QMetaObject::Connection m_forwardConnection;
117 
118     struct WidgetData {
119         QString id;
120         QString name;
121         QWidget *widget = nullptr;
122         AbstractButtonInterface *button = nullptr;
123     };
124 
125     QStringList m_layoutIds;
126     QHash<QString, WidgetData> m_widgets;
127 
128     friend class NavigationBarConfigDialog;
129 };
130 
131 #endif // NAVIGATIONBAR_H
132