From f3053f1d01e39ea243bad06c544eee0452e2312c Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 5 Apr 2024 07:21:48 -0400 Subject: [PATCH] Ladybird/Qt: Add a "new tab" button to the Qt chrome This adds a button on the right side of the location bar to create a new tab. Ideally, we would actually use QTabWidget::setCornerWidget to put this button in the tab bar. But it is surprisingly difficult to make that look nice on all platforms. Even if we ignore macOS, the CSS to make the button look right on KDE Plasma may not work well on Gnome. So for now, this location next to the location bar is horizontally the same that it would be in the tab bar at least. --- Ladybird/Icons/new_tab.tvg | Bin 0 -> 87 bytes Ladybird/Qt/BrowserWindow.cpp | 9 ++++----- Ladybird/Qt/BrowserWindow.h | 6 ++++++ Ladybird/Qt/Tab.cpp | 2 ++ Ladybird/Qt/ladybird.qrc | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 Ladybird/Icons/new_tab.tvg diff --git a/Ladybird/Icons/new_tab.tvg b/Ladybird/Icons/new_tab.tvg new file mode 100644 index 0000000000000000000000000000000000000000..6a0f18eba077999b6810aadca946776ee528afee GIT binary patch literal 87 zcmW;Eu?>JQ5JOQrmy(h}G7X3|*ecuHM)2k4S(Yrnm!+wR`bs+5r`2xjCSVOR?4ktf NuE1oC@Q7XD;0LDu57htw literal 0 HcmV?d00001 diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index 4726e6ffc1..2ed5e0f0ce 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -78,10 +78,9 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::Cook menu->addSeparator(); - auto* new_tab_action = new QAction("New &Tab", this); - new_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/new-tab.png"sv)); - new_tab_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::AddTab)); - menu->addAction(new_tab_action); + m_new_tab_action = new QAction("New &Tab", this); + m_new_tab_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::AddTab)); + menu->addAction(m_new_tab_action); auto* close_current_tab_action = new QAction("&Close Current Tab", this); close_current_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/close-tab.png"sv)); @@ -396,7 +395,7 @@ BrowserWindow::BrowserWindow(Vector const& initial_urls, WebView::Cook QObject::connect(about_action, &QAction::triggered, this, [this] { new_tab_from_url("about:version"sv, Web::HTML::ActivateTab::Yes); }); - QObject::connect(new_tab_action, &QAction::triggered, this, [this] { + QObject::connect(m_new_tab_action, &QAction::triggered, this, [this] { new_tab_from_url(ak_url_from_qstring(Settings::the()->new_tab_page()), Web::HTML::ActivateTab::Yes); }); QObject::connect(open_file_action, &QAction::triggered, this, &BrowserWindow::open_file); diff --git a/Ladybird/Qt/BrowserWindow.h b/Ladybird/Qt/BrowserWindow.h index e4caab42ba..36f47d6a87 100644 --- a/Ladybird/Qt/BrowserWindow.h +++ b/Ladybird/Qt/BrowserWindow.h @@ -51,6 +51,11 @@ public: return *m_reload_action; } + QAction& new_tab_action() + { + return *m_new_tab_action; + } + QAction& copy_selection_action() { return *m_copy_selection_action; @@ -148,6 +153,7 @@ private: QAction* m_go_back_action { nullptr }; QAction* m_go_forward_action { nullptr }; QAction* m_reload_action { nullptr }; + QAction* m_new_tab_action { nullptr }; QAction* m_copy_selection_action { nullptr }; QAction* m_paste_action { nullptr }; QAction* m_select_all_action { nullptr }; diff --git a/Ladybird/Qt/Tab.cpp b/Ladybird/Qt/Tab.cpp index 801f0f1765..a799b7d12b 100644 --- a/Ladybird/Qt/Tab.cpp +++ b/Ladybird/Qt/Tab.cpp @@ -79,6 +79,7 @@ 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->setIconSize({ 16, 16 }); // This is a little awkward, but without this Qt shrinks the button to the size of the icon. // Note: toolButtonStyle="0" -> ToolButtonIconOnly. @@ -870,6 +871,7 @@ void Tab::recreate_toolbar_icons() m_window->go_back_action().setIcon(create_tvg_icon_with_theme_colors("back", palette())); m_window->go_forward_action().setIcon(create_tvg_icon_with_theme_colors("forward", palette())); m_window->reload_action().setIcon(create_tvg_icon_with_theme_colors("reload", palette())); + m_window->new_tab_action().setIcon(create_tvg_icon_with_theme_colors("new_tab", palette())); } void Tab::show_inspector_window(InspectorTarget inspector_target) diff --git a/Ladybird/Qt/ladybird.qrc b/Ladybird/Qt/ladybird.qrc index b4c17459bf..a3c822fb01 100644 --- a/Ladybird/Qt/ladybird.qrc +++ b/Ladybird/Qt/ladybird.qrc @@ -4,6 +4,7 @@ ../Icons/back.tvg ../Icons/close.tvg ../Icons/forward.tvg + ../Icons/new_tab.tvg ../Icons/reload.tvg