Skip to content

Commit

Permalink
UI/QT: Move New Tab button in tab bar
Browse files Browse the repository at this point in the history
  • Loading branch information
lmutter committed Jul 14, 2024
1 parent 9ce727d commit aaccba8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Ladybird/Qt/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::Cook
, m_web_content_options(web_content_options)
, m_webdriver_content_ipc_path(webdriver_content_ipc_path)
, m_allow_popups(allow_popups)
, m_new_tab_button_toolbar(new QToolBar("New Tab", this))
{
setWindowIcon(app_icon());

Expand Down Expand Up @@ -661,6 +662,11 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> 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);
}
Expand All @@ -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)
return;

QSize tab_bar_size = m_tabs_container->tabBar()->sizeHint();
QRect new_rect;
new_rect.setX(qMax(tab_bar_size.width(), 225));
new_rect.setWidth(32);
new_rect.setHeight(32);

m_new_tab_button_toolbar->setGeometry(new_rect);
}

void BrowserWindow::debug_request(ByteString const& request, ByteString const& argument)
{
if (!m_current_tab)
Expand Down Expand Up @@ -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)
Expand All @@ -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();
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Ladybird/Qt/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public slots:
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 };
Expand Down Expand Up @@ -212,6 +214,7 @@ public slots:
StringView m_webdriver_content_ipc_path;

bool m_allow_popups { false };
QToolBar* m_new_tab_button_toolbar { nullptr };
};

}
1 change: 0 additions & 1 deletion Ladybird/Qt/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit aaccba8

Please sign in to comment.