From e87693c54ca97ed3a6ed25f9eaae8ab223fc18b1 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 29 Apr 2020 18:49:07 +0300 Subject: libwebengine Make src/webengine into a static library - Add some tests - Updated manpage - Remove WebProfileManager::id and WebProfileManager::instance - Add consumable semantics checks to WebProfileManager - Add WebProfileManager::walk Add ApplicationMenu class --- src/subwindow/subwindow.cpp | 21 ++++++++++++--------- src/subwindow/subwindow.h | 2 ++ src/subwindow/tabwidget.cpp | 11 ++++++----- src/subwindow/tabwidget.h | 4 +++- 4 files changed, 23 insertions(+), 15 deletions(-) (limited to 'src/subwindow') diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp index 8c2e3e7..588a070 100644 --- a/src/subwindow/subwindow.cpp +++ b/src/subwindow/subwindow.cpp @@ -81,10 +81,9 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags flags) SubWindow::SubWindow(const Session::SubWindow &data, QWidget *parent, Qt::WindowFlags flags) : SubWindow(parent, flags) { - const auto *profileManager = WebProfileManager::instance(); - Q_CHECK_PTR(profileManager); + WebProfileManager profileManager; - auto *profile = profileManager->profile(data.profile); + auto *profile = profileManager.profile(data.profile); if(profile != nullptr) { setProfile(profile); } @@ -96,15 +95,12 @@ SubWindow::SubWindow(const Session::SubWindow &data, QWidget *parent, Qt::Window Session::SubWindow SubWindow::serialize() const { - const auto *profileManager = WebProfileManager::instance(); - Q_CHECK_PTR(profileManager); - QVector tabs(tabCount()); for(int i = 0; i < tabCount(); ++i) { tabs[i] = view(i)->serialize(); } - return { profileManager->id(profile()), tabs }; + return { profile()->getId(), tabs }; } void SubWindow::setProfile(WebProfile *profile) @@ -131,13 +127,20 @@ SubWindow::TabData SubWindow::tabData(int index) const return tabWidget->tabBar()->tabData(index).value(); } +WebView *SubWindow::createView(QWebEnginePage::WebWindowType type) +{ + auto *view = new WebView(m_profile, std::bind(&SubWindow::createView, this, std::placeholders::_1), this); + tabWidget->addTab(view); + return view; +} + int SubWindow::addTab(const QUrl &url, WebProfile *profile) { Q_CHECK_PTR(m_profile); auto *_profile = (profile == nullptr) ? m_profile : profile; - auto *view = new WebView(_profile, this); + auto *view = new WebView(_profile, std::bind(&SubWindow::createView, this, std::placeholders::_1), this); if(url.isEmpty()) view->load(_profile->newtab()); else @@ -148,7 +151,7 @@ int SubWindow::addTab(const QUrl &url, WebProfile *profile) int SubWindow::addTab(const Session::WebView &data) { - auto *view = new WebView(data, this); + auto *view = new WebView(data, std::bind(&SubWindow::createView, this, std::placeholders::_1), this); return tabWidget->addTab(view); } diff --git a/src/subwindow/subwindow.h b/src/subwindow/subwindow.h index 02f50d0..88f3985 100644 --- a/src/subwindow/subwindow.h +++ b/src/subwindow/subwindow.h @@ -68,6 +68,8 @@ signals: void aboutToClose(); public slots: + WebView *createView(QWebEnginePage::WebWindowType type); + int addTab(const QUrl &url = QUrl(), WebProfile *profile = nullptr); int addTab(const Session::WebView &data); void closeTab(int index) diff --git a/src/subwindow/tabwidget.cpp b/src/subwindow/tabwidget.cpp index d09fffb..efa2b6a 100644 --- a/src/subwindow/tabwidget.cpp +++ b/src/subwindow/tabwidget.cpp @@ -17,17 +17,18 @@ #include #include "subwindow.h" -inline WebView *createViewFromInfo(TabWidget::TabInformation &tab, QWidget *parent) +inline WebView *createViewFromInfo(TabWidget::TabInformation &tab, SubWindow *parent) { - auto *view = new WebView(tab.profile, parent); + auto *view = new WebView(tab.profile, std::bind(&SubWindow::createView, parent, std::placeholders::_1), parent); QDataStream stream(&tab.historyBuffer, QIODevice::ReadOnly); stream >> *view->history(); view->history()->goToItem(view->history()->itemAt(tab.historyIndex)); return view; } -TabWidget::TabWidget(QWidget *parent) +TabWidget::TabWidget(SubWindow *parent) : QTabWidget(parent) + , m_parent(parent) { setStyleSheet("QTabBar::tab { width: 200px; }"); @@ -132,7 +133,7 @@ int TabWidget::restoreLastTab() { if(!m_closedTabs.isEmpty()) { TabInformation tab = m_closedTabs.takeLast(); - return addTab(createViewFromInfo(tab, this)); + return addTab(createViewFromInfo(tab, m_parent)); } return -1; } @@ -147,7 +148,7 @@ void TabWidget::restoreTabMenu(QMenu *menu) connect(openAction, &QAction::triggered, this, [this, i]() { TabInformation tab = m_closedTabs.takeAt(i); - addTab(createViewFromInfo(tab, this)); + addTab(createViewFromInfo(tab, m_parent)); }); } diff --git a/src/subwindow/tabwidget.h b/src/subwindow/tabwidget.h index d67d2de..de5e6fb 100644 --- a/src/subwindow/tabwidget.h +++ b/src/subwindow/tabwidget.h @@ -18,6 +18,7 @@ class QMenu; class WebView; class WebProfile; class QWebEnginePage; +class SubWindow; class TabWidget : public QTabWidget { Q_OBJECT @@ -31,7 +32,7 @@ public: QByteArray historyBuffer; }; - explicit TabWidget(QWidget *parent = nullptr); + explicit TabWidget(SubWindow *parent = nullptr); ~TabWidget() override; public slots: @@ -46,6 +47,7 @@ protected: void mousePressEvent(QMouseEvent *event) override; private: + SubWindow *m_parent; int current = -1; int previous = -1; QMenu *tabContextMenu; -- cgit v1.2.1