cabana: Make the close button on TabBar look consistent and adaptable to different templates. (#28065)

consistent and adaptable to different templates
pull/28109/head
Dean Lee 2 years ago committed by GitHub
parent 068ff038af
commit 4ed6412ee5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      tools/cabana/chart/chartswidget.cc
  2. 3
      tools/cabana/chart/chartswidget.h
  3. 3
      tools/cabana/detailwidget.cc
  4. 2
      tools/cabana/detailwidget.h
  5. 25
      tools/cabana/util.cc
  6. 11
      tools/cabana/util.h

@ -65,13 +65,12 @@ ChartsWidget::ChartsWidget(QWidget *parent) : align_timer(this), auto_scroll_tim
main_layout->addWidget(toolbar); main_layout->addWidget(toolbar);
// tabbar // tabbar
tabbar = new QTabBar(this); tabbar = new TabBar(this);
tabbar->setAutoHide(true); tabbar->setAutoHide(true);
tabbar->setExpanding(false); tabbar->setExpanding(false);
tabbar->setDrawBase(true); tabbar->setDrawBase(true);
tabbar->setAcceptDrops(true); tabbar->setAcceptDrops(true);
tabbar->setChangeCurrentOnDrag(true); tabbar->setChangeCurrentOnDrag(true);
tabbar->setTabsClosable(true);
tabbar->setUsesScrollButtons(true); tabbar->setUsesScrollButtons(true);
main_layout->addWidget(tabbar); main_layout->addWidget(tabbar);

@ -3,7 +3,6 @@
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QScrollArea> #include <QScrollArea>
#include <QTabBar>
#include <QTimer> #include <QTimer>
#include <QUndoCommand> #include <QUndoCommand>
#include <QUndoStack> #include <QUndoStack>
@ -95,7 +94,7 @@ private:
ToolButton *remove_all_btn; ToolButton *remove_all_btn;
QList<ChartView *> charts; QList<ChartView *> charts;
std::unordered_map<int, QList<ChartView *>> tab_charts; std::unordered_map<int, QList<ChartView *>> tab_charts;
QTabBar *tabbar; TabBar *tabbar;
ChartsContainer *charts_container; ChartsContainer *charts_container;
QScrollArea *charts_scroll; QScrollArea *charts_scroll;
uint32_t max_chart_range = 0; 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); main_layout->setContentsMargins(0, 0, 0, 0);
// tabbar // tabbar
tabbar = new QTabBar(this); tabbar = new TabBar(this);
tabbar->setTabsClosable(true);
tabbar->setUsesScrollButtons(true); tabbar->setUsesScrollButtons(true);
tabbar->setAutoHide(true); tabbar->setAutoHide(true);
tabbar->setContextMenuPolicy(Qt::CustomContextMenu); tabbar->setContextMenuPolicy(Qt::CustomContextMenu);

@ -41,7 +41,7 @@ private:
QLabel *time_label, *warning_icon, *warning_label; QLabel *time_label, *warning_icon, *warning_label;
ElidedLabel *name_label; ElidedLabel *name_label;
QWidget *warning_widget; QWidget *warning_widget;
QTabBar *tabbar; TabBar *tabbar;
QTabWidget *tab_widget; QTabWidget *tab_widget;
QToolButton *remove_btn; QToolButton *remove_btn;
LogsWidget *history_log; LogsWidget *history_log;

@ -131,6 +131,29 @@ void MessageBytesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
painter->setPen(old_pen); 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) { QColor getColor(const cabana::Signal *sig) {
float h = 19 * (float)sig->lsb / 64.0; float h = 19 * (float)sig->lsb / 64.0;
h = fmod(h, 1.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::ButtonText, QColor("#777777"));
new_palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor("#777777")); new_palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor("#777777"));
new_palette.setColor(QPalette::Disabled, QPalette::Text, 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")); new_palette.setColor(QPalette::Dark, QColor("#353535"));
} else { } else {
new_palette = style->standardPalette(); new_palette = style->standardPalette();

@ -122,4 +122,15 @@ private:
int theme; 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); int num_decimals(double num);

Loading…
Cancel
Save