diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index 08b1d7d1714..dbaee70985f 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -46,18 +46,12 @@ static QIcon const& app_icon() } BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path) - : m_cookie_jar(cookie_jar) + : m_tabs_container(new TabWidget(this)) + , m_cookie_jar(cookie_jar) , m_web_content_options(web_content_options) , m_webdriver_content_ipc_path(webdriver_content_ipc_path) { setWindowIcon(app_icon()); - m_tabs_container = new QTabWidget(this); - m_tabs_container->installEventFilter(this); - m_tabs_container->setElideMode(Qt::TextElideMode::ElideRight); - m_tabs_container->setMovable(true); - m_tabs_container->setTabsClosable(true); - m_tabs_container->setDocumentMode(true); - m_tabs_container->setTabBarAutoHide(true); // Listen for DPI changes m_device_pixel_ratio = devicePixelRatio(); diff --git a/Ladybird/Qt/TabBar.cpp b/Ladybird/Qt/TabBar.cpp index f8a70fcb5d9..5112370b92f 100644 --- a/Ladybird/Qt/TabBar.cpp +++ b/Ladybird/Qt/TabBar.cpp @@ -4,12 +4,39 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include namespace Ladybird { +QSize TabBar::tabSizeHint(int index) const +{ + auto width = this->width() / count(); + width = min(225, width); + width = max(64, width); + + auto hint = QTabBar::tabSizeHint(index); + hint.setWidth(width); + return hint; +} + +TabWidget::TabWidget(QWidget* parent) + : QTabWidget(parent) +{ + // This must be called first, otherwise several of the options below have no effect. + setTabBar(new TabBar()); + + setDocumentMode(true); + setElideMode(Qt::TextElideMode::ElideRight); + setMovable(true); + setTabBarAutoHide(true); + setTabsClosable(true); + + installEventFilter(parent); +} + TabBarButton::TabBarButton(QIcon const& icon, QWidget* parent) : QPushButton(icon, {}, parent) { diff --git a/Ladybird/Qt/TabBar.h b/Ladybird/Qt/TabBar.h index d28d0d32c56..07c9a15ee8c 100644 --- a/Ladybird/Qt/TabBar.h +++ b/Ladybird/Qt/TabBar.h @@ -7,6 +7,8 @@ #pragma once #include +#include +#include class QEvent; class QIcon; @@ -14,6 +16,20 @@ class QWidget; namespace Ladybird { +class TabBar : public QTabBar { + Q_OBJECT + +public: + virtual QSize tabSizeHint(int index) const override; +}; + +class TabWidget : public QTabWidget { + Q_OBJECT + +public: + explicit TabWidget(QWidget* parent = nullptr); +}; + class TabBarButton : public QPushButton { Q_OBJECT