/* * 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_SUBWINDOW_H #define SMOLBOTE_SUBWINDOW_H #include "smolbote/session.hpp" #include "tabwidget.h" #include "webengine/webview.h" #include #include #include class WebProfile; class SubWindow : public QWidget { Q_OBJECT public: struct TabData { bool closeLocked = false; bool refreshLocked = false; }; explicit SubWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); explicit SubWindow(const Session::SubWindow &tab_data, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~SubWindow() = default; [[nodiscard]] Session::SubWindow serialize() const; [[nodiscard]] int currentTabIndex() const { return tabWidget->currentIndex(); } [[nodiscard]] WebView *currentView() { return qobject_cast(tabWidget->currentWidget()); } [[nodiscard]] WebView *view(int index) const { return qobject_cast(tabWidget->widget(index)); } [[nodiscard]] int tabCount() const { return tabWidget->count(); } void setProfile(WebProfile *profile); [[nodiscard]] WebProfile *profile() const { return m_profile; } void setTabData(TabData &tab_data, int index); [[nodiscard]] TabData tabData(int index) const; signals: void currentViewChanged(WebView *view); void showStatusMessage(const QString &message, int timeout = 0); void visibilityChanged(bool isVisible); void aboutToClose(); public slots: WebView *createView(QWebEnginePage::WebWindowType type); int addTab(const QUrl &url = QUrl(), WebProfile *profile = nullptr); int addTab(const Session::WebView &tab_data); void closeTab(int index) { tabWidget->removeTab(index); } void setCurrentTab(int index) { if(index >= 0) tabWidget->setCurrentIndex(index); } void moveTab(int from, int to); int restoreLastTab() { return tabWidget->restoreLastTab(); } void restoreTabMenu(QMenu *menu) { tabWidget->restoreTabMenu(menu); } protected: void closeEvent(QCloseEvent *event); void hideEvent(QHideEvent *event); void showEvent(QShowEvent *event); private: WebProfile *m_profile; TabWidget *tabWidget; QMetaObject::Connection titleConnection; QMetaObject::Connection linkHoveredConnection; }; Q_DECLARE_METATYPE(SubWindow::TabData) #endif // SMOLBOTE_SUBWINDOW_H