mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 09:21:57 -05:00
UI/Qt: Move New Tab button in tab bar
(cherry picked from commit abddd0ac1b73407737981e283450a82cad79e877)
This commit is contained in:
parent
1e3bb7dbe1
commit
f5b850cbd6
3 changed files with 29 additions and 1 deletions
|
@ -72,6 +72,7 @@ public:
|
|||
|
||||
BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, WebView::CookieJar& cookie_jar, WebContentOptions const& web_content_options, StringView webdriver_content_ipc_path, bool allow_popups, Tab* parent_tab, Optional<u64> 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)
|
||||
|
@ -673,6 +674,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);
|
||||
}
|
||||
|
@ -686,6 +692,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)
|
||||
|
@ -833,6 +853,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)
|
||||
|
@ -846,6 +868,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();
|
||||
}
|
||||
|
@ -1172,6 +1196,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)
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Reference in a new issue