Cabana: change the chart theme in setting (#26220)

* change the chart theme in setting

* change title colors

* cleanup
pull/26231/head
Dean Lee 3 years ago committed by GitHub
parent 995c74a994
commit ba570b963f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      tools/cabana/chartswidget.cc
  2. 5
      tools/cabana/chartswidget.h
  3. 8
      tools/cabana/settings.cc
  4. 3
      tools/cabana/settings.h

@ -200,33 +200,31 @@ ChartWidget::ChartWidget(const QString &id, const Signal *sig, QWidget *parent)
main_layout->setSpacing(0); main_layout->setSpacing(0);
main_layout->setContentsMargins(0, 0, 0, 0); main_layout->setContentsMargins(0, 0, 0, 0);
QWidget *header = new QWidget(this); header = new QWidget(this);
header->setStyleSheet("background-color:white");
QGridLayout *header_layout = new QGridLayout(header); QGridLayout *header_layout = new QGridLayout(header);
header_layout->setContentsMargins(11, 11, 11, 0); header_layout->setContentsMargins(11, 11, 11, 0);
msg_name_label = new QLabel(this); msg_name_label = new QLabel(this);
msg_name_label->setTextFormat(Qt::RichText); msg_name_label->setTextFormat(Qt::RichText);
header_layout->addWidget(msg_name_label, 0, 0, Qt::AlignLeft); header_layout->addWidget(msg_name_label, 0, 0, Qt::AlignLeft);
sig_name_label = new QLabel(this); sig_name_label = new QLabel(this);
sig_name_label->setStyleSheet("font-weight:bold");
header_layout->addWidget(sig_name_label, 0, 1, Qt::AlignCenter); //, 0, Qt::AlignCenter); header_layout->addWidget(sig_name_label, 0, 1, Qt::AlignCenter); //, 0, Qt::AlignCenter);
QPushButton *remove_btn = new QPushButton("", this); remove_btn = new QPushButton("", this);
remove_btn->setFixedSize(20, 20); remove_btn->setFixedSize(20, 20);
remove_btn->setToolTip(tr("Remove chart")); remove_btn->setToolTip(tr("Remove chart"));
header_layout->addWidget(remove_btn, 0, 2, Qt::AlignRight); header_layout->addWidget(remove_btn, 0, 2, Qt::AlignRight);
main_layout->addWidget(header); main_layout->addWidget(header);
chart_view = new ChartView(id, sig, this); chart_view = new ChartView(id, sig, this);
chart_view->setFixedHeight(settings.chart_height);
main_layout->addWidget(chart_view); main_layout->addWidget(chart_view);
main_layout->addStretch(); main_layout->addStretch();
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
updateTitle(); updateTitle();
updateFromSettings();
QObject::connect(remove_btn, &QPushButton::clicked, [=]() { emit remove(id, sig); }); QObject::connect(remove_btn, &QPushButton::clicked, [=]() { emit remove(id, sig); });
QObject::connect(&settings, &Settings::changed, [this]() { chart_view->setFixedHeight(settings.chart_height); }); QObject::connect(&settings, &Settings::changed, this, &ChartWidget::updateFromSettings);
} }
void ChartWidget::updateTitle() { void ChartWidget::updateTitle() {
@ -234,12 +232,22 @@ void ChartWidget::updateTitle() {
sig_name_label->setText(signal->name.c_str()); sig_name_label->setText(signal->name.c_str());
} }
void ChartWidget::updateFromSettings() {
header->setStyleSheet(settings.chart_theme == 0 ? "background-color:white" : "background-color:#23242c");
QString color_style = settings.chart_theme == 0 ? "color:black" : "color:white";
sig_name_label->setStyleSheet("font-weight:bold;" + color_style);
msg_name_label->setStyleSheet(color_style);
remove_btn->setStyleSheet(color_style);
chart_view->updateFromSettings();
}
// ChartView // ChartView
ChartView::ChartView(const QString &id, const Signal *sig, QWidget *parent) ChartView::ChartView(const QString &id, const Signal *sig, QWidget *parent)
: id(id), signal(sig), QChartView(nullptr, parent) { : id(id), signal(sig), QChartView(nullptr, parent) {
QLineSeries *series = new QLineSeries(); QLineSeries *series = new QLineSeries();
QChart *chart = new QChart(); QChart *chart = new QChart();
chart->setBackgroundRoundness(0);
chart->addSeries(series); chart->addSeries(series);
chart->createDefaultAxes(); chart->createDefaultAxes();
chart->legend()->hide(); chart->legend()->hide();
@ -254,7 +262,6 @@ ChartView::ChartView(const QString &id, const Signal *sig, QWidget *parent)
value_text->setBrush(Qt::gray); value_text->setBrush(Qt::gray);
line_marker = new QGraphicsLineItem(chart); line_marker = new QGraphicsLineItem(chart);
line_marker->setZValue(chart->zValue() + 10); line_marker->setZValue(chart->zValue() + 10);
line_marker->setPen(QPen(Qt::black, 2));
setChart(chart); setChart(chart);
@ -277,6 +284,12 @@ ChartView::ChartView(const QString &id, const Signal *sig, QWidget *parent)
}); });
} }
void ChartView::updateFromSettings() {
setFixedHeight(settings.chart_height);
chart()->setTheme(settings.chart_theme == 0 ? QChart::ChartThemeLight : QChart::QChart::ChartThemeDark);
line_marker->setPen(QPen(settings.chart_theme == 0 ? Qt::black : Qt::white, 2));
}
void ChartView::setRange(double min, double max, bool force_update) { void ChartView::setRange(double min, double max, bool force_update) {
auto axis_x = dynamic_cast<QValueAxis *>(chart()->axisX()); auto axis_x = dynamic_cast<QValueAxis *>(chart()->axisX());
if (force_update || (min != axis_x->min() || max != axis_x->max())) { if (force_update || (min != axis_x->min() || max != axis_x->max())) {

@ -23,6 +23,7 @@ public:
void updateSeries(const std::pair<double, double> &range); void updateSeries(const std::pair<double, double> &range);
void setRange(double min, double max, bool force_update = false); void setRange(double min, double max, bool force_update = false);
void updateLineMarker(double current_sec); void updateLineMarker(double current_sec);
void updateFromSettings();
signals: signals:
void zoomIn(double min, double max); void zoomIn(double min, double max);
@ -34,7 +35,6 @@ private:
void enterEvent(QEvent *event) override; void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override; void leaveEvent(QEvent *event) override;
void adjustChartMargins(); void adjustChartMargins();
void updateAxisY(); void updateAxisY();
QGraphicsLineItem *track_line; QGraphicsLineItem *track_line;
@ -51,6 +51,7 @@ Q_OBJECT
public: public:
ChartWidget(const QString &id, const Signal *sig, QWidget *parent); ChartWidget(const QString &id, const Signal *sig, QWidget *parent);
void updateTitle(); void updateTitle();
void updateFromSettings();
signals: signals:
void remove(const QString &msg_id, const Signal *sig); void remove(const QString &msg_id, const Signal *sig);
@ -58,8 +59,10 @@ signals:
public: public:
QString id; QString id;
const Signal *signal; const Signal *signal;
QWidget *header;
QLabel *msg_name_label; QLabel *msg_name_label;
QLabel *sig_name_label; QLabel *sig_name_label;
QPushButton *remove_btn;
ChartView *chart_view = nullptr; ChartView *chart_view = nullptr;
}; };

@ -17,6 +17,7 @@ void Settings::save() {
s.setValue("log_size", can_msg_log_size); s.setValue("log_size", can_msg_log_size);
s.setValue("cached_segment", cached_segment_limit); s.setValue("cached_segment", cached_segment_limit);
s.setValue("chart_height", chart_height); s.setValue("chart_height", chart_height);
s.setValue("chart_theme", chart_theme);
s.setValue("max_chart_x_range", max_chart_x_range); s.setValue("max_chart_x_range", max_chart_x_range);
emit changed(); emit changed();
} }
@ -27,6 +28,7 @@ void Settings::load() {
can_msg_log_size = s.value("log_size", 100).toInt(); can_msg_log_size = s.value("log_size", 100).toInt();
cached_segment_limit = s.value("cached_segment", 3).toInt(); cached_segment_limit = s.value("cached_segment", 3).toInt();
chart_height = s.value("chart_height", 200).toInt(); chart_height = s.value("chart_height", 200).toInt();
chart_theme = s.value("chart_theme", 0).toInt();
max_chart_x_range = s.value("max_chart_x_range", 3 * 60).toInt(); max_chart_x_range = s.value("max_chart_x_range", 3 * 60).toInt();
} }
@ -67,6 +69,11 @@ SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) {
chart_height->setValue(settings.chart_height); chart_height->setValue(settings.chart_height);
form_layout->addRow(tr("Chart's height"), chart_height); form_layout->addRow(tr("Chart's height"), chart_height);
chart_theme = new QComboBox();
chart_theme->addItems({"Light", "Dark"});
chart_theme->setCurrentIndex(settings.chart_theme == 1 ? 1 : 0);
form_layout->addRow(tr("Chart theme"), chart_theme);
main_layout->addLayout(form_layout); main_layout->addLayout(form_layout);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
@ -82,6 +89,7 @@ void SettingsDlg::save() {
settings.can_msg_log_size = log_size->value(); settings.can_msg_log_size = log_size->value();
settings.cached_segment_limit = cached_segment->value(); settings.cached_segment_limit = cached_segment->value();
settings.chart_height = chart_height->value(); settings.chart_height = chart_height->value();
settings.chart_theme = chart_theme->currentIndex();
settings.max_chart_x_range = max_chart_x_range->value() * 60; settings.max_chart_x_range = max_chart_x_range->value() * 60;
settings.save(); settings.save();
accept(); accept();

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <QComboBox>
#include <QDialog> #include <QDialog>
#include <QSpinBox> #include <QSpinBox>
@ -15,6 +16,7 @@ public:
int can_msg_log_size = 100; int can_msg_log_size = 100;
int cached_segment_limit = 3; int cached_segment_limit = 3;
int chart_height = 200; int chart_height = 200;
int chart_theme = 0;
int max_chart_x_range = 3 * 60; // 3 minutes int max_chart_x_range = 3 * 60; // 3 minutes
signals: signals:
@ -31,6 +33,7 @@ public:
QSpinBox *log_size ; QSpinBox *log_size ;
QSpinBox *cached_segment; QSpinBox *cached_segment;
QSpinBox *chart_height; QSpinBox *chart_height;
QComboBox *chart_theme;
QSpinBox *max_chart_x_range; QSpinBox *max_chart_x_range;
}; };

Loading…
Cancel
Save