aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow/mainwindow.h
blob: c5d573e892fbb8618f0baccb9d1c7e0a823a0a94 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * This file is part of smolbote. It's copyrighted by the contributors recorded
 * in the version control history of the file, available from its original
 * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
 *
 * SPDX-License-Identifier: GPL-3.0
 */

#ifndef SMOLBOTE_MAINWINDOW_H
#define SMOLBOTE_MAINWINDOW_H

#include "session.hpp"
#include "subwindow/subwindow.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QMainWindow>
#include <QUrl>

class Browser;
class AddressBar;
class SearchForm;
class WebView;
class NavigationBar;
class WebProfile;
class MenuBar;
class MainWindow final : public QMainWindow
{
    friend class Browser;

    Q_OBJECT

public:
    enum ActionLocation {
        ToolsMenu
    };

    explicit MainWindow(const Session::MainWindow &mainwindow_data, QMenu *appMenu, QWidget *parent = nullptr);

    MainWindow(const MainWindow &) = delete;
    ~MainWindow() = default;

    [[nodiscard]] Session::MainWindow serialize() const
    {
        QVector<Session::SubWindow> subwindows(m_subwindows.size());
        for(int i = 0; i < m_subwindows.size(); ++i) {
            subwindows[i] = m_subwindows.at(i)->serialize();
        }
        return { subwindows };
    }

    void addDockWidget(Qt::DockWidgetArea area, QWidget *widget);
    void removeDockWidget(QWidget *widget);

    [[nodiscard]] const QVector<SubWindow *> subWindows() const
    {
        return m_subwindows;
    }
    [[nodiscard]] SubWindow *currentSubWindow() const
    {
        return qobject_cast<SubWindow *>(centralWidget());
    }
    [[nodiscard]] WebView *currentView() const
    {
        return currentSubWindow()->currentView();
    }

public slots:
    void createTab(const QUrl &url);
    void createTab(const Session::WebView &tab_data);
    SubWindow *createSubWindow(const Session::SubWindow &subwindow_data);
    void setCurrentSubWindow(SubWindow *subwindow);

private slots:
    void setView(WebView *view);

protected:
    void closeEvent(QCloseEvent *event) override;

private:
    QString defaultWindowTitle;
    MenuBar *m_menuBar = nullptr;
    QMenu *toolsMenu = nullptr;
    QMenu *pageLoadProfileMenu = nullptr;

    NavigationBar *navigationToolBar = nullptr;
    AddressBar *addressBar = nullptr;
    SearchForm *searchBox = nullptr;

    QVector<SubWindow *> m_subwindows;

    QMetaObject::Connection viewChangedConnection;
    QMetaObject::Connection statusBarConnection;
};

#endif // SMOLBOTE_MAINWINDOW_H