Cabana: add tab context menu for 'close other tabs' (#26279)
close other tabs old-commit-hash: a622e523b2251472aa59b80eee60cae9fcb1e024
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFormLayout>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
@@ -22,6 +23,7 @@ DetailWidget::DetailWidget(QWidget *parent) : QWidget(parent) {
|
||||
tabbar->setDrawBase(false);
|
||||
tabbar->setUsesScrollButtons(true);
|
||||
tabbar->setAutoHide(true);
|
||||
tabbar->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
main_layout->addWidget(tabbar);
|
||||
|
||||
// message title
|
||||
@@ -79,22 +81,47 @@ DetailWidget::DetailWidget(QWidget *parent) : QWidget(parent) {
|
||||
QObject::connect(binary_view, &BinaryView::addSignal, this, &DetailWidget::addSignal);
|
||||
QObject::connect(can, &CANMessages::updated, this, &DetailWidget::updateState);
|
||||
QObject::connect(dbc(), &DBCManager::DBCFileChanged, [this]() { dbcMsgChanged(); });
|
||||
QObject::connect(tabbar, &QTabBar::currentChanged, [this](int index) { setMessage(messages[index]); });
|
||||
QObject::connect(tabbar, &QTabBar::tabCloseRequested, [=](int index) {
|
||||
messages.removeAt(index);
|
||||
tabbar->removeTab(index);
|
||||
setMessage(messages.isEmpty() ? "" : messages[0]);
|
||||
QObject::connect(tabbar, &QTabBar::customContextMenuRequested, this, &DetailWidget::showTabBarContextMenu);
|
||||
QObject::connect(tabbar, &QTabBar::currentChanged, [this](int index) {
|
||||
if (index != -1 && tabbar->tabText(index) != msg_id) {
|
||||
setMessage(tabbar->tabText(index));
|
||||
}
|
||||
});
|
||||
QObject::connect(tabbar, &QTabBar::tabCloseRequested, [=](int index) {
|
||||
if (tabbar->currentIndex() == index) {
|
||||
tabbar->setCurrentIndex(index == tabbar->count() - 1 ? index - 1 : index + 1);
|
||||
}
|
||||
tabbar->removeTab(index);
|
||||
});
|
||||
}
|
||||
|
||||
void DetailWidget::showTabBarContextMenu(const QPoint &pt) {
|
||||
int index = tabbar->tabAt(pt);
|
||||
if (index >= 0) {
|
||||
QMenu menu(this);
|
||||
menu.addAction(tr("Close Other Tabs"));
|
||||
if (menu.exec(tabbar->mapToGlobal(pt))) {
|
||||
for (int i = tabbar->count() - 1; i >= 0; --i) {
|
||||
if (i != index)
|
||||
tabbar->removeTab(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DetailWidget::setMessage(const QString &message_id) {
|
||||
if (message_id.isEmpty()) return;
|
||||
|
||||
int index = messages.indexOf(message_id);
|
||||
qWarning() << "setmessage" << message_id;
|
||||
int index = -1;
|
||||
for (int i = 0; i < tabbar->count(); ++i) {
|
||||
if (tabbar->tabText(i) == message_id) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == -1) {
|
||||
messages.push_back(message_id);
|
||||
tabbar->addTab(message_id);
|
||||
index = tabbar->count() - 1;
|
||||
index = tabbar->addTab(message_id);
|
||||
auto msg = dbc()->msg(message_id);
|
||||
tabbar->setTabToolTip(index, msg ? msg->name.c_str() : "untitled");
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ signals:
|
||||
void removeChart(const Signal *sig);
|
||||
|
||||
private:
|
||||
void showTabBarContextMenu(const QPoint &pt);
|
||||
void addSignal(int start_bit, int to);
|
||||
void resizeSignal(const Signal *sig, int from, int to);
|
||||
void saveSignal(const Signal *sig, const Signal &new_sig);
|
||||
@@ -53,7 +54,6 @@ private:
|
||||
QPushButton *edit_btn;
|
||||
QWidget *signals_container;
|
||||
QTabBar *tabbar;
|
||||
QStringList messages;
|
||||
HistoryLog *history_log;
|
||||
BinaryView *binary_view;
|
||||
ScrollArea *scroll;
|
||||
|
||||
Reference in New Issue
Block a user