2024-04-03 01:24:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2024-04-03 01:38:01 +00:00
|
|
|
#include <AK/StdLibExtras.h>
|
2024-04-03 01:24:17 +00:00
|
|
|
#include <Ladybird/Qt/TabBar.h>
|
|
|
|
#include <QEvent>
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
|
|
namespace Ladybird {
|
|
|
|
|
2024-04-03 01:38:01 +00:00
|
|
|
QSize TabBar::tabSizeHint(int index) const
|
|
|
|
{
|
|
|
|
auto width = this->width() / count();
|
|
|
|
width = min(225, width);
|
2024-04-28 11:12:47 +00:00
|
|
|
width = max(128, width);
|
2024-04-03 01:38:01 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-04-03 01:24:17 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|