ladybird/Ladybird/Qt/TabBar.cpp
Timothy Flynn d6c8218089 Ladybird/Qt: Show the tab bar by default
We currently only show the tab bar when we have more than one tab open.
This has caused confusion in the past, as it's a bit less obvious that
the browser supports tabs. For example:

https://hackaday.com/2023/10/10/jennys-daily-drivers-serenityos-and-in-particular-ladybird/
"it’s a single window with no tabs"
2024-04-03 20:56:04 +02:00

57 lines
1.2 KiB
C++

/*
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StdLibExtras.h>
#include <Ladybird/Qt/TabBar.h>
#include <QEvent>
#include <QPushButton>
namespace Ladybird {
QSize TabBar::tabSizeHint(int index) const
{
auto width = this->width() / count();
width = min(225, width);
width = max(64, width);
auto hint = QTabBar::tabSizeHint(index);
hint.setWidth(width);
return hint;
}
TabWidget::TabWidget(QWidget* parent)
: QTabWidget(parent)
{
// This must be called first, otherwise several of the options below have no effect.
setTabBar(new TabBar());
setDocumentMode(true);
setElideMode(Qt::TextElideMode::ElideRight);
setMovable(true);
setTabsClosable(true);
installEventFilter(parent);
}
TabBarButton::TabBarButton(QIcon const& icon, QWidget* parent)
: QPushButton(icon, {}, parent)
{
resize({ 20, 20 });
setFlat(true);
}
bool TabBarButton::event(QEvent* event)
{
if (event->type() == QEvent::Enter)
setFlat(false);
if (event->type() == QEvent::Leave)
setFlat(true);
return QPushButton::event(event);
}
}