mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-13 21:32:14 +08:00
Cabana: make whole DetailWidget scrollable (#26340)
old-commit-hash: b25e56925c2453464f554bfab57b38f9487a9844
This commit is contained in:
@@ -20,15 +20,12 @@ BinaryView::BinaryView(QWidget *parent) : QTableView(parent) {
|
||||
setItemDelegate(delegate);
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
horizontalHeader()->hide();
|
||||
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setMouseTracking(true);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
|
||||
}
|
||||
|
||||
QSize BinaryView::sizeHint() const {
|
||||
QSize sz = QTableView::sizeHint();
|
||||
return {sz.width(), model->rowCount() <= 8 ? ((CELL_HEIGHT + 1) * model->rowCount() + 2) : sz.height()};
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
void BinaryView::highlight(const Signal *sig) {
|
||||
|
||||
@@ -61,7 +61,6 @@ public:
|
||||
void highlight(const Signal *sig);
|
||||
const Signal *hoveredSignal() const { return hovered_sig; }
|
||||
QSet<const Signal*> getOverlappingSignals() const;
|
||||
QSize sizeHint() const override;
|
||||
|
||||
signals:
|
||||
void signalHovered(const Signal *sig);
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include <QFormLayout>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "tools/cabana/canmessages.h"
|
||||
@@ -13,38 +15,26 @@
|
||||
// DetailWidget
|
||||
|
||||
DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(charts), QWidget(parent) {
|
||||
main_layout = new QHBoxLayout(this);
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout->setContentsMargins(0, 0, 0, 0);
|
||||
main_layout->setSpacing(0);
|
||||
|
||||
right_column = new QVBoxLayout();
|
||||
main_layout->addLayout(right_column);
|
||||
|
||||
binary_view_container = new QWidget(this);
|
||||
binary_view_container->setMinimumWidth(500);
|
||||
binary_view_container->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
QVBoxLayout *bin_layout = new QVBoxLayout(binary_view_container);
|
||||
bin_layout->setContentsMargins(0, 0, 0, 0);
|
||||
bin_layout->setSpacing(0);
|
||||
// tabbar
|
||||
// tabbar
|
||||
tabbar = new QTabBar(this);
|
||||
tabbar->setTabsClosable(true);
|
||||
tabbar->setDrawBase(false);
|
||||
tabbar->setUsesScrollButtons(true);
|
||||
tabbar->setAutoHide(true);
|
||||
tabbar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
bin_layout->addWidget(tabbar);
|
||||
main_layout->addWidget(tabbar);
|
||||
|
||||
TitleFrame *title_frame = new TitleFrame(this);
|
||||
QFrame *title_frame = new QFrame(this);
|
||||
QVBoxLayout *frame_layout = new QVBoxLayout(title_frame);
|
||||
title_frame->setFrameShape(QFrame::StyledPanel);
|
||||
title_frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
QVBoxLayout *frame_layout = new QVBoxLayout(title_frame);
|
||||
|
||||
// message title
|
||||
QHBoxLayout *title_layout = new QHBoxLayout();
|
||||
split_btn = new QPushButton("⬅", this);
|
||||
split_btn->setFixedSize(20, 20);
|
||||
split_btn->setToolTip(tr("Split to two columns"));
|
||||
title_layout->addWidget(split_btn);
|
||||
title_layout->addWidget(new QLabel("time:"));
|
||||
time_label = new QLabel(this);
|
||||
time_label->setStyleSheet("font-weight:bold");
|
||||
@@ -62,6 +52,7 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
||||
// warning
|
||||
warning_widget = new QWidget(this);
|
||||
QHBoxLayout *warning_hlayout = new QHBoxLayout(warning_widget);
|
||||
warning_hlayout->setContentsMargins(0, 0, 0, 0);
|
||||
QLabel *warning_icon = new QLabel(this);
|
||||
warning_icon->setPixmap(style()->standardPixmap(QStyle::SP_MessageBoxWarning));
|
||||
warning_hlayout->addWidget(warning_icon, 0, Qt::AlignTop);
|
||||
@@ -69,30 +60,33 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
||||
warning_hlayout->addWidget(warning_label, 1, Qt::AlignLeft);
|
||||
warning_widget->hide();
|
||||
frame_layout->addWidget(warning_widget);
|
||||
bin_layout->addWidget(title_frame);
|
||||
main_layout->addWidget(title_frame);
|
||||
|
||||
QWidget *container = new QWidget(this);
|
||||
QVBoxLayout *container_layout = new QVBoxLayout(container);
|
||||
container_layout->setSpacing(0);
|
||||
container_layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
scroll = new QScrollArea(this);
|
||||
scroll->setWidget(container);
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
main_layout->addWidget(scroll);
|
||||
|
||||
// binary view
|
||||
binary_view = new BinaryView(this);
|
||||
bin_layout->addWidget(binary_view);
|
||||
right_column->addWidget(binary_view_container);
|
||||
container_layout->addWidget(binary_view);
|
||||
|
||||
// signals
|
||||
signals_container = new QWidget(this);
|
||||
signals_container->setLayout(new QVBoxLayout);
|
||||
signals_container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
||||
|
||||
scroll = new ScrollArea(this);
|
||||
scroll->setWidget(signals_container);
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
right_column->addWidget(scroll);
|
||||
container_layout->addWidget(signals_container);
|
||||
|
||||
// history log
|
||||
history_log = new HistoryLog(this);
|
||||
right_column->addWidget(history_log);
|
||||
container_layout->addWidget(history_log);
|
||||
|
||||
QObject::connect(split_btn, &QPushButton::clicked, this, &DetailWidget::moveBinaryView);
|
||||
QObject::connect(title_frame, &TitleFrame::doubleClicked, this, &DetailWidget::moveBinaryView);
|
||||
QObject::connect(edit_btn, &QPushButton::clicked, this, &DetailWidget::editMsg);
|
||||
QObject::connect(binary_view, &BinaryView::resizeSignal, this, &DetailWidget::resizeSignal);
|
||||
QObject::connect(binary_view, &BinaryView::addSignal, this, &DetailWidget::addSignal);
|
||||
@@ -146,6 +140,8 @@ void DetailWidget::setMessage(const QString &message_id) {
|
||||
tabbar->setCurrentIndex(index);
|
||||
msg_id = message_id;
|
||||
dbcMsgChanged();
|
||||
|
||||
scroll->verticalScrollBar()->setValue(0);
|
||||
}
|
||||
|
||||
void DetailWidget::dbcMsgChanged(int show_form_idx) {
|
||||
@@ -201,27 +197,12 @@ void DetailWidget::updateState() {
|
||||
history_log->updateState();
|
||||
}
|
||||
|
||||
void DetailWidget::moveBinaryView() {
|
||||
if (binview_in_left_col) {
|
||||
right_column->insertWidget(0, binary_view_container);
|
||||
emit binaryViewMoved(true);
|
||||
} else {
|
||||
main_layout->insertWidget(0, binary_view_container);
|
||||
emit binaryViewMoved(false);
|
||||
}
|
||||
split_btn->setText(binview_in_left_col ? "⬅" : "➡");
|
||||
split_btn->setToolTip(binview_in_left_col ? tr("Split to two columns") : tr("Move back"));
|
||||
binary_view->updateGeometry();
|
||||
binview_in_left_col = !binview_in_left_col;
|
||||
}
|
||||
|
||||
void DetailWidget::showForm() {
|
||||
SignalEdit *sender = qobject_cast<SignalEdit *>(QObject::sender());
|
||||
for (auto f : signals_container->findChildren<SignalEdit *>()) {
|
||||
f->setFormVisible(f == sender && !f->isFormVisible());
|
||||
if (f == sender) {
|
||||
if (f == sender)
|
||||
QTimer::singleShot(0, [=]() { scroll->ensureWidgetVisible(f); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,19 +303,3 @@ EditMessageDialog::EditMessageDialog(const QString &msg_id, const QString &title
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
}
|
||||
|
||||
// ScrollArea
|
||||
|
||||
bool ScrollArea::eventFilter(QObject *obj, QEvent *ev) {
|
||||
if (obj == widget() && ev->type() == QEvent::Resize) {
|
||||
int height = widget()->height() + 4;
|
||||
setMinimumHeight(height > 480 ? 480 : height);
|
||||
setMaximumHeight(height);
|
||||
}
|
||||
return QScrollArea::eventFilter(obj, ev);
|
||||
}
|
||||
|
||||
void ScrollArea::setWidget(QWidget *w) {
|
||||
QScrollArea::setWidget(w);
|
||||
w->installEventFilter(this);
|
||||
}
|
||||
|
||||
@@ -2,22 +2,12 @@
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QTabBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "tools/cabana/binaryview.h"
|
||||
#include "tools/cabana/chartswidget.h"
|
||||
#include "tools/cabana/historylog.h"
|
||||
#include "tools/cabana/signaledit.h"
|
||||
|
||||
class TitleFrame : public QFrame {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TitleFrame(QWidget *parent) : QFrame(parent) {}
|
||||
void mouseDoubleClickEvent(QMouseEvent *e) { emit doubleClicked(); }
|
||||
signals:
|
||||
void doubleClicked();
|
||||
};
|
||||
|
||||
class EditMessageDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -28,15 +18,6 @@ public:
|
||||
QSpinBox *size_spin;
|
||||
};
|
||||
|
||||
class ScrollArea : public QScrollArea {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScrollArea(QWidget *parent) : QScrollArea(parent) {}
|
||||
bool eventFilter(QObject *obj, QEvent *ev) override;
|
||||
void setWidget(QWidget *w);
|
||||
};
|
||||
|
||||
class DetailWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -58,7 +39,6 @@ private:
|
||||
void editMsg();
|
||||
void showForm();
|
||||
void updateState();
|
||||
void moveBinaryView();
|
||||
|
||||
QString msg_id;
|
||||
QLabel *name_label, *time_label, *warning_label;
|
||||
@@ -66,13 +46,8 @@ private:
|
||||
QPushButton *edit_btn;
|
||||
QWidget *signals_container;
|
||||
QTabBar *tabbar;
|
||||
QHBoxLayout *main_layout;
|
||||
QVBoxLayout *right_column;
|
||||
bool binview_in_left_col = false;
|
||||
QWidget *binary_view_container;
|
||||
QPushButton *split_btn;
|
||||
HistoryLog *history_log;
|
||||
BinaryView *binary_view;
|
||||
ScrollArea *scroll;
|
||||
QScrollArea *scroll;
|
||||
ChartsWidget *charts;
|
||||
};
|
||||
|
||||
+10
-11
@@ -64,16 +64,15 @@ void HistoryLogModel::updateState() {
|
||||
}
|
||||
}
|
||||
|
||||
HistoryLog::HistoryLog(QWidget *parent) : QWidget(parent) {
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout->setContentsMargins(0, 0, 0, 0);
|
||||
HistoryLog::HistoryLog(QWidget *parent) : QTableView(parent) {
|
||||
model = new HistoryLogModel(this);
|
||||
table = new QTableView(this);
|
||||
table->setModel(model);
|
||||
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
table->setColumnWidth(0, 60);
|
||||
table->verticalHeader()->setVisible(false);
|
||||
table->setStyleSheet("QTableView::item { border:0px; padding-left:5px; padding-right:5px; }");
|
||||
main_layout->addWidget(table);
|
||||
setModel(model);
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
verticalHeader()->setVisible(false);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
|
||||
setStyleSheet("QTableView::item { border:0px; padding-left:5px; padding-right:5px; }");
|
||||
}
|
||||
|
||||
@@ -25,15 +25,13 @@ private:
|
||||
std::deque<CanData> messages;
|
||||
};
|
||||
|
||||
class HistoryLog : public QWidget {
|
||||
class HistoryLog : public QTableView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HistoryLog(QWidget *parent);
|
||||
void setMessage(const QString &message_id) { model->setMessage(message_id); }
|
||||
void updateState() { model->updateState(); }
|
||||
|
||||
private:
|
||||
QTableView *table;
|
||||
HistoryLogModel *model;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ void Settings::save() {
|
||||
void Settings::load() {
|
||||
QSettings s("settings", QSettings::IniFormat);
|
||||
fps = s.value("fps", 10).toInt();
|
||||
can_msg_log_size = s.value("log_size", 100).toInt();
|
||||
can_msg_log_size = s.value("log_size", 50).toInt();
|
||||
cached_segment_limit = s.value("cached_segment", 3).toInt();
|
||||
chart_height = s.value("chart_height", 200).toInt();
|
||||
chart_theme = s.value("chart_theme", 0).toInt();
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
void load();
|
||||
|
||||
int fps = 10;
|
||||
int can_msg_log_size = 100;
|
||||
int can_msg_log_size = 50;
|
||||
int cached_segment_limit = 3;
|
||||
int chart_height = 200;
|
||||
int chart_theme = 0;
|
||||
|
||||
Reference in New Issue
Block a user