8000 cabana: add online-help by deanlee · Pull Request #27349 · commaai/openpilot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cabana: add online-help #27349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tools/cabana/binaryview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ BinaryView::BinaryView(QWidget *parent) : QTableView(parent) {
QObject::connect(UndoStack::instance(), &QUndoStack::indexChanged, this, &BinaryView::refresh);

addShortcuts();
setWhatsThis(R"(
<b>Binary View</b><br/>
<!-- TODO: add descprition here -->
Shortcuts:<br />
Delete Signal:
<span style="background-color:lightGray;color:gray"> x </span>,
<span style="background-color:lightGray;color:gray"> Backspace </span>,
<span style="background-color:lightGray;color:gray"> Delete</span><br />
Change endianness: <span style="background-color:lightGray;color:gray"> e </span><br />
Change singedness: <span style="background-color:lightGray;color:gray"> s </span><br />
Open chart:
<span style="background-color:lightGray;color:gray"> c </span>,
<span style="background-color:lightGray;color:gray"> p </span>,
<span style="background-color:lightGray;color:gray"> g </span><br />
)");
}

void BinaryView::addShortcuts() {
Expand Down
5 changes: 5 additions & 0 deletions tools/cabana/chartswidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ ChartsWidget::ChartsWidget(QWidget *parent) : QWidget(parent) {
docking = !docking;
updateToolBar();
});

setWhatsThis(tr(R"(
<b>Chart view</b><br />
<!-- TODO: add descprition here -->
)"));
}

void ChartsWidget::eventsMerged() {
Expand Down
5 changes: 3 additions & 2 deletions tools/cabana/detailwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,12 @@ WelcomeWidget::WelcomeWidget(QWidget *parent) : QWidget(parent) {
return hlayout;
};

auto lb = new QLabel(tr("<-Select a message to to view details"));
auto lb = new QLabel(tr("<-Select a message to view details"));
lb->setAlignment(Qt::AlignHCenter);
main_layout->addWidget(lb);
main_layout->addLayout(newShortcutRow("Pause", "Space"));
main_layout->addLayout(newShortcutRow("Help", "Alt + H"));
main_layout->addLayout(newShortcutRow("Help", "F1"));
main_layout->addLayout(newShortcutRow("WhatsThis", "Shift+F1"));
main_layout->addStretch(0);

setStyleSheet("QLabel{color:darkGray;}");
Expand Down
66 changes: 64 additions & 2 deletions tools/cabana/mainwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QResizeEvent>
#include <QShortcut>
#include <QTextDocument>
#include <QUndoView>
#include <QVBoxLayout>
#include <QWidgetAction>
Expand All @@ -20,7 +22,7 @@
static MainWindow *main_win = nullptr;
void qLogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
if (type == QtDebugMsg) std::cout << msg.toStdString() << std::endl;
if (main_win) emit main_win->showMessage(msg, 0);
if (main_win) emit main_win->showMessage(msg, 2000);
}

MainWindow::MainWindow() : QMainWindow() {
Expand All @@ -43,7 +45,7 @@ MainWindow::MainWindow() : QMainWindow() {
qRegisterMetaType<ReplyMsgType>("ReplyMsgType");
installMessageHandler([this](ReplyMsgType type, const std::string msg) {
// use queued connection to recv the log messages from replay.
emit showMessage(QString::fromStdString(msg), 3000);
emit showMessage(QString::fromStdString(msg), 2000);
});
installDownloadProgressHandler([this](uint64_t cur, uint64_t total, bool success) {
emit updateProgressBar(cur, total, success);
Expand Down Expand Up @@ -125,6 +127,7 @@ void MainWindow::createActions() {
tools_menu->addAction(tr("Find &Similar Bits"), this, &MainWindow::findSimilarBits);

QMenu *help_menu = menuBar()->addMenu(tr("&Help"));
help_menu->addAction(tr("Help"), this, &MainWindow::onlineHelp)->setShortcuts(QKeySequence::HelpContents);
help_menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
}

Expand Down Expand Up @@ -173,6 +176,7 @@ void MainWindow::createStatusBar() {
progress_bar->setTextVisible(true);
progress_bar->setFixedSize({230, 16});
progress_bar->setVisible(false);
statusBar()->addWidget(new QLabel(tr("For Help,Press F1")));
statusBar()->addPermanentWidget(progress_bar);
}

Expand Down Expand Up @@ -422,3 +426,61 @@ void MainWindow::findSimilarBits() {
QObject::connect(dlg, &FindSimilarBitsDlg::openMessage, messages_widget, &MessagesWidget::selectMessage);
dlg->show();
}

void MainWindow::onlineHelp() {
if (auto help = findChild<HelpOverlay*>()) {
help->close();
} else {
help = new HelpOverlay(this);
help->setGeometry(rect());
help->show();
help->raise();
}
}

// HelpOverlay
HelpOverlay::HelpOverlay(MainWindow *parent) : QWidget(parent) {
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_DeleteOnClose);
parent->installEventFilter(this);
}

void HelpOverlay::paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.fillRect(rect(), QColor(0, 0, 0, 50));
MainWindow *parent = (MainWindow *)parentWidget();
drawHelpForWidget(painter, parent->findChild<MessagesWidget *>());
drawHelpForWidget(painter, parent->findChild<BinaryView *>());
drawHelpForWidget(painter, parent->findChild<SignalView *>());
drawHelpForWidget(painter, parent->findChild<ChartsWidget *>());
drawHelpForWidget(painter, parent->findChild<VideoWidget *>());
}

void HelpOverlay::drawHelpForWidget(QPainter &painter, QWidget *w) {
if (w && w->isVisible() && !w->whatsThis().isEmpty()) {
QPoint pt = mapFromGlobal(w->mapToGlobal(w->rect().center()));
if (rect().contains(pt)) {
QTextDocument document;
document.setHtml(w->whatsThis());
QSize doc_size = document.size().toSize();
QPoint topleft = {pt.x() - doc_size.width() / 2, pt.y() - doc_size.height() / 2};
painter.translate(topleft);
painter.fillRect(QRect{{0, 0}, doc_size}, palette().toolTipBase());
document.drawContents(&painter);
painter.translate(-topleft);
}
}
}

bool HelpOverlay::eventFilter(QObject *obj, QEvent *event) {
if (obj == parentWidget() && event->type() == QEvent::Resize) {
QResizeEvent *resize_event = (QResizeEvent *)(event);
setGeometry(QRect{QPoint(0, 0), resize_event->size()});
}
return false;
}

void HelpOverlay::mouseReleaseEvent(QMouseEvent *event) {
close();
}
14 changes: 14 additions & 0 deletions tools/cabana/mainwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public slots:
void setOption();
void findSimilarBits();
void undoStackCleanChanged(bool clean);
void onlineHelp();

VideoWidget *video_widget = nullptr;
QDockWidget *video_dock;
Expand All @@ -69,4 +70,17 @@ public slots:
enum { MAX_RECENT_FILES = 15 };
QAction *recent_files_acts[MAX_RECENT_FILES] = {};
QMenu *open_recent_menu = nullptr;
friend class OnlineHelp;
};

class HelpOverlay : public QWidget {
Q_OBJECT
public:
HelpOverlay(MainWindow *parent);

protected:
void drawHelpForWidget(QPainter &painter, QWidget *w);
void paintEvent(QPaintEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
bool eventFilter(QObject *obj, QEvent *event) override;
};
9 changes: 9 additions & 0 deletions tools/cabana/messageswidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
});

updateSuppressedButtons();

setWhatsThis(tr(R"(
<b>Message View</b><br/>
<!-- TODO: add descprition here -->
Byte color: <br />
<span style="color:gray;">■ </span> constant changing<br />
<span style="color:blue;">■ </span> increasing<br />
<span style="color:red;">■ </span> decreasing <br />
)"));
}

void MessagesWidget::selectMessage(const MessageId &msg_id) {
Expand Down
5 changes: 5 additions & 0 deletions tools/cabana/signaledit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ SignalView::SignalView(ChartsWidget *charts, QWidget *parent) : charts(charts),
QObject::connect(model, &QAbstractItemModel::rowsInserted, this, &SignalView::rowsChanged);
QObject::connect(model, &QAbstractItemModel::rowsRemoved, this, &SignalView::rowsChanged);
QObject::connect(dbc(), &DBCManager::signalAdded, [this](uint32_t address, const Signal *sig) { expandSignal(sig); });

setWhatsThis(tr(R"(
<b>Signal view</b><br />
<!-- TODO: add descprition here -->
)"));
}

void SignalView::setMessage(const MessageId &id) {
Expand Down
7 changes: 7 additions & 0 deletions tools/cabana/videowidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ VideoWidget::VideoWidget(QWidget *parent) : QWidget(parent) {
QObject::connect(can, &AbstractStream::paused, this, &VideoWidget::updatePlayBtnState);
QObject::connect(can, &AbstractStream::resume, this, &VideoWidget::updatePlayBtnState);
updatePlayBtnState();

setWhatsThis(tr(R"(
<b>Video</b><br />
<!-- TODO: add descprition here -->
Shortcuts:<br />
Pause/Resume: <span style="background-color:lightGray;color:gray"> space </span></br>
)"));
}

QWidget *VideoWidget::createCameraWidget() {
Expand Down
0