Преглед изворни кода

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.
Timothy Flynn пре 1 година
родитељ
комит
f3053f1d01

BIN
Ladybird/Icons/new_tab.tvg


+ 4 - 5
Ladybird/Qt/BrowserWindow.cpp

@@ -78,10 +78,9 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> 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<URL::URL> 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);

+ 6 - 0
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 };

+ 2 - 0
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)

+ 1 - 0
Ladybird/Qt/ladybird.qrc

@@ -4,6 +4,7 @@
         <file>../Icons/back.tvg</file>
         <file>../Icons/close.tvg</file>
         <file>../Icons/forward.tvg</file>
+        <file>../Icons/new_tab.tvg</file>
         <file>../Icons/reload.tvg</file>
     </qresource>
 </RCC>