Skip to content

Commit

Permalink
dim inactive messages
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Dec 20, 2024
1 parent 723ca95 commit 17ec655
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion tools/cabana/binaryview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void BinaryItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
painter->fillRect(option.rect, item->bg_color);
}
auto color_role = item->sigs.contains(bin_view->hovered_sig) ? QPalette::BrightText : QPalette::Text;
painter->setPen(option.palette.color(color_role));
painter->setPen(option.palette.color(bin_view->is_message_active ? QPalette::Normal : QPalette::Disabled, color_role));
}

if (item->sigs.size() > 1) {
Expand Down
7 changes: 6 additions & 1 deletion tools/cabana/binaryview.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ class BinaryView : public QTableView {
void setMessage(const MessageId &message_id);
void highlight(const cabana::Signal *sig);
QSet<const cabana::Signal*> getOverlappingSignals() const;
inline void updateState() { model->updateState(); }
void updateState() { model->updateState(); }
void paintEvent(QPaintEvent *event) override {
is_message_active = can->isMessageActive(model->msg_id);
QTableView::paintEvent(event);
}
QSize minimumSizeHint() const override;
void setHeatmapLiveMode(bool live) { model->heatmap_live_mode = live; updateState(); }

Expand All @@ -93,6 +97,7 @@ class BinaryView : public QTableView {
QModelIndex anchor_index;
BinaryViewModel *model;
BinaryItemDelegate *delegate;
bool is_message_active = false;
const cabana::Signal *resize_sig = nullptr;
const cabana::Signal *hovered_sig = nullptr;
friend class BinaryItemDelegate;
Expand Down
8 changes: 5 additions & 3 deletions tools/cabana/chart/chartswidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ChartsWidget::ChartsWidget(QWidget *parent) : QFrame(parent) {

range_lb_action = toolbar->addWidget(range_lb = new QLabel(this));
range_slider = new LogSlider(1000, Qt::Horizontal, this);
range_slider->setFixedWidth(150);
range_slider->setFixedWidth(150 * qApp->devicePixelRatio());
range_slider->setToolTip(tr("Set the chart range"));
range_slider->setRange(1, settings.max_cached_minutes * 60);
range_slider->setSingleStep(1);
Expand Down Expand Up @@ -256,7 +256,9 @@ void ChartsWidget::settingChanged() {
c->setTheme(theme);
}
}
range_slider->setRange(1, settings.max_cached_minutes * 60);
if (range_slider->maximum() != settings.max_cached_minutes * 60) {
range_slider->setRange(1, settings.max_cached_minutes * 60);
}
for (auto c : charts) {
c->setFixedHeight(settings.chart_height);
c->setSeriesType((SeriesType)settings.chart_series_type);
Expand Down Expand Up @@ -395,7 +397,7 @@ void ChartsWidget::doAutoScroll() {
}

QSize ChartsWidget::minimumSizeHint() const {
return QSize(CHART_MIN_WIDTH * 1.5, QWidget::minimumSizeHint().height());
return QSize(CHART_MIN_WIDTH * 1.5 * qApp->devicePixelRatio(), QWidget::minimumSizeHint().height());
}

void ChartsWidget::newChart() {
Expand Down
19 changes: 2 additions & 17 deletions tools/cabana/messageswidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@

#include "tools/cabana/commands.h"

static bool isMessageActive(const MessageId &id) {
if (id.source == INVALID_SOURCE) {
return false;
}
// Check if the message is active based on time difference and frequency
const auto &m = can->lastMessage(id);
float delta = can->currentSec() - m.ts;

if (m.freq < std::numeric_limits<double>::epsilon()) {
return delta < 1.5;
}

return delta < (5.0 / m.freq) + (1.0 / settings.fps);
}

MessagesWidget::MessagesWidget(QWidget *parent) : menu(new QMenu(this)), QWidget(parent) {
QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->setContentsMargins(0, 0, 0, 0);
Expand Down Expand Up @@ -335,7 +320,7 @@ bool MessageListModel::filterAndSort() {
std::vector<Item> items;
items.reserve(all_messages.size());
for (const auto &id : all_messages) {
if (show_inactive_messages || isMessageActive(id)) {
if (show_inactive_messages || can->isMessageActive(id)) {
auto msg = dbc()->msg(id);
Item item = {.id = id,
.name = msg ? msg->name : UNTITLED,
Expand Down Expand Up @@ -378,7 +363,7 @@ void MessageListModel::sort(int column, Qt::SortOrder order) {

void MessageView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
const auto &item = ((MessageListModel*)model())->items_[index.row()];
if (!isMessageActive(item.id)) {
if (!can->isMessageActive(item.id)) {
QStyleOptionViewItem custom_option = option;
custom_option.palette.setBrush(QPalette::Text, custom_option.palette.color(QPalette::Disabled, QPalette::Text));
auto color = QApplication::palette().color(QPalette::HighlightedText);
Expand Down
15 changes: 15 additions & 0 deletions tools/cabana/streams/abstractstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ const CanData &AbstractStream::lastMessage(const MessageId &id) const {
return it != last_msgs.end() ? it->second : empty_data;
}

bool AbstractStream::isMessageActive(const MessageId &id) const {
if (id.source == INVALID_SOURCE) {
return false;
}
// Check if the message is active based on time difference and frequency
const auto &m = lastMessage(id);
float delta = currentSec() - m.ts;

if (m.freq < std::numeric_limits<double>::epsilon()) {
return delta < 1.5;
}

return delta < (5.0 / m.freq) + (1.0 / settings.fps);
}

void AbstractStream::updateLastMsgsTo(double sec) {
std::lock_guard lk(mutex_);
current_sec_ = sec;
Expand Down
1 change: 1 addition & 0 deletions tools/cabana/streams/abstractstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class AbstractStream : public QObject {
inline double toSeconds(uint64_t mono_time) const { return std::max(0.0, (mono_time - beginMonoTime()) / 1e9); }

inline const std::unordered_map<MessageId, CanData> &lastMessages() const { return last_msgs; }
bool isMessageActive(const MessageId &id) const;
inline const MessageEventsMap &eventsMap() const { return events_; }
inline const std::vector<const CanEvent *> &allEvents() const { return all_events_; }
const CanData &lastMessage(const MessageId &id) const;
Expand Down

0 comments on commit 17ec655

Please sign in to comment.