diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index 4297691946e..66dd4b5c72a 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -72,6 +72,7 @@ public: BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab, Optional page_index) : m_tabs_container(new TabWidget(this)) + , m_new_tab_button_toolbar(new QToolBar("New Tab", m_tabs_container)) , m_cookie_jar(cookie_jar) , m_web_content_options(web_content_options) , m_webdriver_content_ipc_path(webdriver_content_ipc_path) @@ -661,6 +662,11 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::Cook } } + m_new_tab_button_toolbar->addAction(m_new_tab_action); + m_new_tab_button_toolbar->setMovable(false); + m_new_tab_button_toolbar->setStyleSheet("QToolBar { background: transparent; }"); + m_new_tab_button_toolbar->setIconSize(QSize(16, 16)); + setCentralWidget(m_tabs_container); setContextMenuPolicy(Qt::PreventContextMenu); } @@ -674,6 +680,20 @@ void BrowserWindow::set_current_tab(Tab* tab) } } +void BrowserWindow::update_new_tab_button() +{ + if (m_new_tab_button_toolbar == nullptr || m_tabs_container == nullptr || m_tabs_container->count() < 1) + return; + QSize tab_bar_size = m_tabs_container->tabBar()->sizeHint(); + int window_width = this->rect().width(); + QRect new_rect; + new_rect.setX(qMin(tab_bar_size.width(), window_width - 32)); + new_rect.setWidth(32); + new_rect.setHeight(32); + m_tabs_container->tabBar()->setMaximumWidth(window_width - 32); + m_new_tab_button_toolbar->setGeometry(new_rect); +} + void BrowserWindow::debug_request(ByteString const& request, ByteString const& argument) { if (!m_current_tab) @@ -814,6 +834,8 @@ void BrowserWindow::initialize_tab(Tab* tab) tab->set_navigator_compatibility_mode(navigator_compatibility_mode()); tab->set_enable_do_not_track(Settings::the()->enable_do_not_track()); tab->view().set_preferred_color_scheme(m_preferred_color_scheme); + + update_new_tab_button(); } void BrowserWindow::activate_tab(int index) @@ -827,6 +849,8 @@ void BrowserWindow::close_tab(int index) m_tabs_container->removeTab(index); tab->deleteLater(); + update_new_tab_button(); + if (m_tabs_container->count() == 0) close(); } @@ -1153,6 +1177,7 @@ void BrowserWindow::resizeEvent(QResizeEvent* event) for_each_tab([&](auto& tab) { tab.view().set_window_size({ frameSize().width() * m_device_pixel_ratio, frameSize().height() * m_device_pixel_ratio }); }); + update_new_tab_button(); } void BrowserWindow::moveEvent(QMoveEvent* event) diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index c3539410a0b..08f08378def 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -179,10 +179,14 @@ private: Web::CSS::PreferredColorScheme m_preferred_color_scheme; void set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme); + void update_new_tab_button(); + QTabWidget* m_tabs_container { nullptr }; Tab* m_current_tab { nullptr }; QMenu* m_zoom_menu { nullptr }; + QToolBar* m_new_tab_button_toolbar { nullptr }; + QMenu* m_hamburger_menu { nullptr }; QAction* m_go_back_action { nullptr }; diff --git a/Ladybird/Qt/Tab.cpp b/Ladybird/Qt/Tab.cpp index a3e0bf6583e..35a7d40eaef 100644 --- a/Ladybird/Qt/Tab.cpp +++ b/Ladybird/Qt/Tab.cpp @@ -90,7 +90,6 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St m_toolbar->addAction(&m_window->go_forward_action()); m_toolbar->addAction(&m_window->reload_action()); m_toolbar->addWidget(m_location_edit); - m_toolbar->addAction(&m_window->new_tab_action()); m_toolbar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); m_hamburger_button_action = m_toolbar->addWidget(m_hamburger_button); m_toolbar->setIconSize({ 16, 16 });