mirror of https://github.com/commaai/openpilot.git
cabana: render light or dark icon based on system theme (#27155)
old-commit-hash: 0402e94927
This commit is contained in:
parent
d7ce6a56eb
commit
a1fb5b7e1f
|
@ -13,8 +13,6 @@
|
|||
#include <QToolTip>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
// ChartsWidget
|
||||
|
||||
ChartsWidget::ChartsWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
@ -24,7 +22,7 @@ ChartsWidget::ChartsWidget(QWidget *parent) : QWidget(parent) {
|
|||
QToolBar *toolbar = new QToolBar(tr("Charts"), this);
|
||||
toolbar->setIconSize({16, 16});
|
||||
|
||||
QAction *new_plot_btn = toolbar->addAction(bootstrapPixmap("file-plus"), "");
|
||||
QAction *new_plot_btn = toolbar->addAction(utils::icon("file-plus"), "");
|
||||
new_plot_btn->setToolTip(tr("New Plot"));
|
||||
toolbar->addWidget(title_label = new QLabel());
|
||||
title_label->setContentsMargins(0, 0, 12, 0);
|
||||
|
@ -46,9 +44,9 @@ ChartsWidget::ChartsWidget(QWidget *parent) : QWidget(parent) {
|
|||
range_slider->setPageStep(60); // 1 min
|
||||
toolbar->addWidget(range_slider);
|
||||
|
||||
reset_zoom_btn = toolbar->addAction(bootstrapPixmap("zoom-out"), "");
|
||||
reset_zoom_btn = toolbar->addAction(utils::icon("zoom-out"), "");
|
||||
reset_zoom_btn->setToolTip(tr("Reset zoom (drag on chart to zoom X-Axis)"));
|
||||
remove_all_btn = toolbar->addAction(bootstrapPixmap("x"), "");
|
||||
remove_all_btn = toolbar->addAction(utils::icon("x"), "");
|
||||
remove_all_btn->setToolTip(tr("Remove all charts"));
|
||||
dock_btn = toolbar->addAction("");
|
||||
main_layout->addWidget(toolbar);
|
||||
|
@ -170,7 +168,7 @@ void ChartsWidget::setMaxChartRange(int value) {
|
|||
void ChartsWidget::updateToolBar() {
|
||||
range_lb->setText(QString(" %1:%2 ").arg(max_chart_range / 60, 2, 10, QLatin1Char('0')).arg(max_chart_range % 60, 2, 10, QLatin1Char('0')));
|
||||
title_label->setText(tr("Charts: %1").arg(charts.size()));
|
||||
dock_btn->setIcon(bootstrapPixmap(docking ? "arrow-up-right" : "arrow-down-left"));
|
||||
dock_btn->setIcon(utils::icon(docking ? "arrow-up-right" : "arrow-down-left"));
|
||||
dock_btn->setToolTip(docking ? tr("Undock charts") : tr("Dock charts"));
|
||||
remove_all_btn->setEnabled(!charts.isEmpty());
|
||||
reset_zoom_btn->setEnabled(is_zoomed);
|
||||
|
@ -311,7 +309,7 @@ ChartView::ChartView(QWidget *parent) : QChartView(nullptr, parent) {
|
|||
chart->setMargins({20, 11, 11, 11});
|
||||
|
||||
QToolButton *remove_btn = new QToolButton();
|
||||
remove_btn->setIcon(bootstrapPixmap("x"));
|
||||
remove_btn->setIcon(utils::icon("x"));
|
||||
remove_btn->setAutoRaise(true);
|
||||
remove_btn->setToolTip(tr("Remove Chart"));
|
||||
close_btn_proxy = new QGraphicsProxyWidget(chart);
|
||||
|
@ -319,7 +317,7 @@ ChartView::ChartView(QWidget *parent) : QChartView(nullptr, parent) {
|
|||
close_btn_proxy->setZValue(chart->zValue() + 11);
|
||||
|
||||
QToolButton *manage_btn = new QToolButton();
|
||||
manage_btn->setIcon(bootstrapPixmap("gear"));
|
||||
manage_btn->setIcon(utils::icon("gear"));
|
||||
manage_btn->setAutoRaise(true);
|
||||
manage_btn->setToolTip(tr("Manage series"));
|
||||
manage_btn_proxy = new QGraphicsProxyWidget(chart);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <QMessageBox>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "tools/cabana/commands.h"
|
||||
#include "tools/cabana/dbcmanager.h"
|
||||
#include "tools/cabana/streams/abstractstream.h"
|
||||
|
@ -38,8 +37,8 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
|||
name_label->setAlignment(Qt::AlignCenter);
|
||||
name_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
toolbar->addWidget(name_label);
|
||||
toolbar->addAction(bootstrapPixmap("pencil"), "", this, &DetailWidget::editMsg)->setToolTip(tr("Edit Message"));
|
||||
remove_msg_act = toolbar->addAction(bootstrapPixmap("x-lg"), "", this, &DetailWidget::removeMsg);
|
||||
toolbar->addAction(utils::icon("pencil"), "", this, &DetailWidget::editMsg)->setToolTip(tr("Edit Message"));
|
||||
remove_msg_act = toolbar->addAction(utils::icon("x-lg"), "", this, &DetailWidget::removeMsg);
|
||||
remove_msg_act->setToolTip(tr("Remove Message"));
|
||||
main_layout->addWidget(toolbar);
|
||||
|
||||
|
@ -63,8 +62,8 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
|||
|
||||
tab_widget = new QTabWidget(this);
|
||||
tab_widget->setTabPosition(QTabWidget::South);
|
||||
tab_widget->addTab(splitter, bootstrapPixmap("file-earmark-ruled"), "&Msg");
|
||||
tab_widget->addTab(history_log = new LogsWidget(this), bootstrapPixmap("stopwatch"), "&Logs");
|
||||
tab_widget->addTab(splitter, utils::icon("file-earmark-ruled"), "&Msg");
|
||||
tab_widget->addTab(history_log = new LogsWidget(this), utils::icon("stopwatch"), "&Logs");
|
||||
main_layout->addWidget(tab_widget);
|
||||
|
||||
stacked_layout = new QStackedLayout(this);
|
||||
|
@ -148,7 +147,7 @@ void DetailWidget::refresh() {
|
|||
|
||||
if (!warnings.isEmpty()) {
|
||||
warning_label->setText(warnings.join('\n'));
|
||||
warning_icon->setPixmap(bootstrapPixmap(msg ? "exclamation-triangle" : "info-circle"));
|
||||
warning_icon->setPixmap(utils::icon(msg ? "exclamation-triangle" : "info-circle"));
|
||||
}
|
||||
warning_widget->setVisible(!warnings.isEmpty());
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
#include "tools/cabana/commands.h"
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
// SignalModel
|
||||
|
||||
SignalModel::SignalModel(QObject *parent) : root(new Item), QAbstractItemModel(parent) {
|
||||
|
@ -132,7 +130,7 @@ QVariant SignalModel::data(const QModelIndex &index, int role) const {
|
|||
if (item->type == Item::Endian) return item->sig->is_little_endian ? Qt::Checked : Qt::Unchecked;
|
||||
if (item->type == Item::Signed) return item->sig->is_signed ? Qt::Checked : Qt::Unchecked;
|
||||
} else if (role == Qt::DecorationRole && index.column() == 0 && item->type == Item::ExtraInfo) {
|
||||
return bootstrapPixmap(item->parent->extra_expanded ? "chevron-compact-down" : "chevron-compact-up");
|
||||
return utils::icon(item->parent->extra_expanded ? "chevron-compact-down" : "chevron-compact-up");
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
@ -331,7 +329,7 @@ SignalView::SignalView(ChartsWidget *charts, QWidget *parent) : charts(charts),
|
|||
hl->addWidget(filter_edit);
|
||||
hl->addStretch(1);
|
||||
auto collapse_btn = new QToolButton();
|
||||
collapse_btn->setIcon(bootstrapPixmap("dash-square"));
|
||||
collapse_btn->setIcon(utils::icon("dash-square"));
|
||||
collapse_btn->setIconSize({12, 12});
|
||||
collapse_btn->setAutoRaise(true);
|
||||
collapse_btn->setToolTip(tr("Collapse All"));
|
||||
|
@ -375,7 +373,7 @@ void SignalView::setMessage(const QString &id) {
|
|||
void SignalView::rowsChanged() {
|
||||
auto create_btn = [](const QString &id, const QString &tooltip) {
|
||||
auto btn = new QToolButton();
|
||||
btn->setIcon(bootstrapPixmap(id));
|
||||
btn->setIcon(utils::icon(id));
|
||||
btn->setToolTip(tooltip);
|
||||
btn->setAutoRaise(true);
|
||||
return btn;
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#include "tools/cabana/util.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFontDatabase>
|
||||
#include <QPainter>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
static QColor blend(QColor a, QColor b) {
|
||||
return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2, (a.blue() + b.blue()) / 2, (a.alpha() + b.alpha()) / 2);
|
||||
}
|
||||
|
@ -100,3 +103,17 @@ QValidator::State NameValidator::validate(QString &input, int &pos) const {
|
|||
input.replace(' ', '_');
|
||||
return QRegExpValidator::validate(input, pos);
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
QPixmap icon(const QString &id) {
|
||||
static bool dark_theme = QApplication::style()->standardPalette().color(QPalette::WindowText).value() >
|
||||
QApplication::style()->standardPalette().color(QPalette::Background).value();
|
||||
QPixmap pm = bootstrapPixmap(id);
|
||||
if (dark_theme) {
|
||||
QPainter p(&pm);
|
||||
p.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
p.fillRect(pm.rect(), Qt::lightGray);
|
||||
}
|
||||
return pm;
|
||||
}
|
||||
} // namespace utils
|
||||
|
|
|
@ -45,3 +45,7 @@ public:
|
|||
NameValidator(QObject *parent=nullptr);
|
||||
QValidator::State validate(QString &input, int &pos) const override;
|
||||
};
|
||||
|
||||
namespace utils {
|
||||
QPixmap icon(const QString &id);
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
|
||||
inline QString formatTime(int seconds) {
|
||||
return QDateTime::fromTime_t(seconds).toString(seconds > 60 * 60 ? "hh:mm:ss" : "mm:ss");
|
||||
}
|
||||
|
@ -130,7 +128,7 @@ void VideoWidget::updateState() {
|
|||
}
|
||||
|
||||
void VideoWidget::updatePlayBtnState() {
|
||||
play_btn->setIcon(bootstrapPixmap(can->isPaused() ? "play" : "pause"));
|
||||
play_btn->setIcon(utils::icon(can->isPaused() ? "play" : "pause"));
|
||||
play_btn->setToolTip(can->isPaused() ? tr("Play") : tr("Pause"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue