/* * 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_TABWIDGET_H #define SMOLBOTE_TABWIDGET_H #include #include #include template concept c_WebView = requires(T *a) { a->title(); a->titleChanged(QString()); a->iconChanged(QIcon()); }; class QAction; class QMenu; class WebView; class WebProfile; class QWebEnginePage; class SubWindow; class TabWidget : public QTabWidget { Q_OBJECT public: explicit TabWidget(SubWindow *parent = nullptr); ~TabWidget() override; template int addTab(T *view) { if(view == nullptr) { return -1; } const int idx = QTabWidget::addTab(view, view->title()); connect(view, &T::titleChanged, [this, view](const QString &title) { const int current_idx = indexOf(view); if(current_idx != -1) { setTabText(current_idx, title); } }); connect(view, &T::iconChanged, [this, view](const QIcon &icon) { const int current_idx = indexOf(view); if(current_idx != -1) { setTabIcon(current_idx, icon); } }); //tabBar()->setTabData(idx, QVariant::fromValue(SubWindow::TabData{})); return idx; } public slots: void removeTab(int index); int restoreLastTab(); void restoreTabMenu(QMenu *menu); protected: void contextMenuEvent(QContextMenuEvent *event) override; void mousePressEvent(QMouseEvent *event) override; private: struct TabInformation { WebProfile *profile; QString title; int historyIndex; QByteArray historyBuffer; }; [[nodiscard]] WebView *createViewFromInfo(TabInformation &tab, SubWindow *parent); SubWindow *m_parent; int current = -1; int previous = -1; QMenu *tabContextMenu; QQueue m_closedTabs; }; #endif // SMOLBOTE_TABWIDGET_H