aboutsummaryrefslogtreecommitdiff
path: root/src/widgets/WebViewStack.hpp
blob: c975d16398a2af6bbf1a890c8ff1829687a07f25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once

#include <QStackedLayout>
#include <QWebEngineProfile>
#include <cstdint>
#include <vector>

#include "Configuration.hpp"
#include "widgets/WebView.hpp"

using WebViewId = qsizetype;

enum OpenType : uint8_t {
  OpenUrl,
  OpenUrlInTab,
  OpenUrlInBgTab,
  OpenUrlInWindow
};

struct Tab {
  QString url;
  QString title;
};

class WebViewStack : public QWidget {
  Q_OBJECT

public:
  WebViewStack(const Configuration *configuration,
               QWebEngineProfile *profile = new QWebEngineProfile,
               QWidget *parent = nullptr);

  void open_url(const QUrl &url, OpenType open_type = OpenType::OpenUrl);

  std::vector<QUrl> urls();
  QList<Tab> get_webview_list();
  uint32_t current_webview_index();
  uint32_t count();
  QUrl current_url();

  void focus_webview(WebViewId index);
  void next();
  void previous();

  void close(WebViewId index);
  void close_current();

  void webview_history_back(WebViewId webview_id, qsizetype history_index);
  void webview_history_forward(WebViewId webview_id, qsizetype history_index);

private slots:
  void on_new_webview_request(const QWebEngineNewWindowRequest &request);

protected:
  void set_current_url(const QUrl &url);
  WebView *create_new_webview(const QUrl &url, bool focus = false);

private:
  const Configuration *configuration;
  QWebEngineProfile *profile;
  QStackedLayout *layout;
  QList<WebView *> webview_list;
};