diff options
Diffstat (limited to 'src/subwindow/tabwidget.cpp')
-rw-r--r-- | src/subwindow/tabwidget.cpp | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/src/subwindow/tabwidget.cpp b/src/subwindow/tabwidget.cpp index 69f3b8a..1e1d939 100644 --- a/src/subwindow/tabwidget.cpp +++ b/src/subwindow/tabwidget.cpp @@ -8,29 +8,22 @@ #include "tabwidget.h" #include "browser.h" -#include "webengine/webview.h" +#include "subwindow.h" +#include "webprofile.h" +#include "webview.h" #include <QAction> #include <QContextMenuEvent> #include <QMenu> #include <QTabBar> -#include "webengine/webprofile.h" #include <QWebEngineHistory> -#include "subwindow.h" -inline WebView *createViewFromInfo(TabWidget::TabInformation &tab, SubWindow *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; -} +const QLatin1String stylesheet("QTabBar::tab { width: 200px; }"); TabWidget::TabWidget(SubWindow *parent) : QTabWidget(parent) , m_parent(parent) { - setStyleSheet("QTabBar::tab { width: 200px; }"); + setStyleSheet(stylesheet); setTabsClosable(true); setTabBarAutoHide(true); @@ -80,29 +73,6 @@ TabWidget::~TabWidget() } } -int TabWidget::addTab(WebView *view) -{ - if(view == nullptr) { - return -1; - } - - const int idx = QTabWidget::addTab(view, view->title()); - connect(view, &WebView::titleChanged, [this, view](const QString &title) { - const int current_idx = indexOf(view); - if(current_idx != -1) { - setTabText(current_idx, title); - } - }); - connect(view, &WebView::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>(SubWindow::TabData{})); - return idx; -} - void TabWidget::removeTab(int index) { // deleting the widget automatically removes the tab? @@ -180,3 +150,12 @@ void TabWidget::mousePressEvent(QMouseEvent *event) QTabWidget::mousePressEvent(event); } + +WebView *TabWidget::createViewFromInfo(TabWidget::TabInformation &tab, SubWindow *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; +} |