mirror of https://github.com/commaai/openpilot.git
cabana: Make the close button on TabBar look consistent and adaptable to different templates. (#28065)
consistent and adaptable to different templates
old-commit-hash: 4ed6412ee5
This commit is contained in:
parent
4f7d5b6b8f
commit
67d627d73c
|
@ -65,13 +65,12 @@ ChartsWidget::ChartsWidget(QWidget *parent) : align_timer(this), auto_scroll_tim
|
|||
main_layout->addWidget(toolbar);
|
||||
|
||||
// tabbar
|
||||
tabbar = new QTabBar(this);
|
||||
tabbar = new TabBar(this);
|
||||
tabbar->setAutoHide(true);
|
||||
tabbar->setExpanding(false);
|
||||
tabbar->setDrawBase(true);
|
||||
tabbar->setAcceptDrops(true);
|
||||
tabbar->setChangeCurrentOnDrag(true);
|
||||
tabbar->setTabsClosable(true);
|
||||
tabbar->setUsesScrollButtons(true);
|
||||
main_layout->addWidget(tabbar);
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QScrollArea>
|
||||
#include <QTabBar>
|
||||
#include <QTimer>
|
||||
#include <QUndoCommand>
|
||||
#include <QUndoStack>
|
||||
|
@ -95,7 +94,7 @@ private:
|
|||
ToolButton *remove_all_btn;
|
||||
QList<ChartView *> charts;
|
||||
std::unordered_map<int, QList<ChartView *>> tab_charts;
|
||||
QTabBar *tabbar;
|
||||
TabBar *tabbar;
|
||||
ChartsContainer *charts_container;
|
||||
QScrollArea *charts_scroll;
|
||||
uint32_t max_chart_range = 0;
|
||||
|
|
|
@ -13,8 +13,7 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
|||
main_layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// tabbar
|
||||
tabbar = new QTabBar(this);
|
||||
tabbar->setTabsClosable(true);
|
||||
tabbar = new TabBar(this);
|
||||
tabbar->setUsesScrollButtons(true);
|
||||
tabbar->setAutoHide(true);
|
||||
tabbar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
|
|
@ -41,7 +41,7 @@ private:
|
|||
QLabel *time_label, *warning_icon, *warning_label;
|
||||
ElidedLabel *name_label;
|
||||
QWidget *warning_widget;
|
||||
QTabBar *tabbar;
|
||||
TabBar *tabbar;
|
||||
QTabWidget *tab_widget;
|
||||
QToolButton *remove_btn;
|
||||
LogsWidget *history_log;
|
||||
|
|
|
@ -131,6 +131,29 @@ void MessageBytesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
|||
painter->setPen(old_pen);
|
||||
}
|
||||
|
||||
// TabBar
|
||||
|
||||
int TabBar::addTab(const QString &text) {
|
||||
int index = QTabBar::addTab(text);
|
||||
QToolButton *btn = new ToolButton("x", tr("Close Tab"));
|
||||
int width = style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, nullptr, btn);
|
||||
int height = style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, nullptr, btn);
|
||||
btn->setFixedSize({width, height});
|
||||
setTabButton(index, QTabBar::RightSide, btn);
|
||||
QObject::connect(btn, &QToolButton::clicked, this, &TabBar::closeTabClicked);
|
||||
return index;
|
||||
}
|
||||
|
||||
void TabBar::closeTabClicked() {
|
||||
QObject *object = sender();
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
if (tabButton(i, QTabBar::RightSide) == object) {
|
||||
emit tabCloseRequested(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QColor getColor(const cabana::Signal *sig) {
|
||||
float h = 19 * (float)sig->lsb / 64.0;
|
||||
h = fmod(h, 1.0);
|
||||
|
@ -191,7 +214,7 @@ void setTheme(int theme) {
|
|||
new_palette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor("#777777"));
|
||||
new_palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor("#777777"));
|
||||
new_palette.setColor(QPalette::Disabled, QPalette::Text, QColor("#777777"));;
|
||||
new_palette.setColor(QPalette::Light, QColor("#3c3f41"));
|
||||
new_palette.setColor(QPalette::Light, QColor("#777777"));
|
||||
new_palette.setColor(QPalette::Dark, QColor("#353535"));
|
||||
} else {
|
||||
new_palette = style->standardPalette();
|
||||
|
|
|
@ -122,4 +122,15 @@ private:
|
|||
int theme;
|
||||
};
|
||||
|
||||
class TabBar : public QTabBar {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TabBar(QWidget *parent) : QTabBar(parent) {}
|
||||
int addTab(const QString &text);
|
||||
|
||||
private:
|
||||
void closeTabClicked();
|
||||
};
|
||||
|
||||
int num_decimals(double num);
|
||||
|
|
Loading…
Reference in New Issue