diff --git a/commandpanel.cpp b/commandpanel.cpp --- a/commandpanel.cpp +++ b/commandpanel.cpp @@ -41,6 +41,7 @@ CommandPanel::CommandPanel(QSerialPort* connect(&_newCommandAction, &QAction::triggered, this, &CommandPanel::newCommand); _menu.addAction(&_newCommandAction); + _menu.addSeparator(); command_name_counter = 0; newCommand(); // add an empty slot by default @@ -59,6 +60,7 @@ void CommandPanel::newCommand() ui->scrollAreaWidgetContents->layout()->addWidget(command); command->setFocusToEdit(); connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand); + _menu.addAction(command->sendAction()); } void CommandPanel::sendCommand(QByteArray command) diff --git a/commandwidget.cpp b/commandwidget.cpp --- a/commandwidget.cpp +++ b/commandwidget.cpp @@ -27,7 +27,8 @@ CommandWidget::CommandWidget(QWidget *parent) : QWidget(parent), - ui(new Ui::CommandWidget) + ui(new Ui::CommandWidget), + _sendAction(this) { ui->setupUi(this); @@ -38,6 +39,11 @@ CommandWidget::CommandWidget(QWidget *pa connect(ui->pbDelete, &QPushButton::clicked, this, &CommandWidget::onDeleteClicked); connect(ui->pbSend, &QPushButton::clicked, this, &CommandWidget::onSendClicked); connect(ui->pbASCII, &QPushButton::toggled, this, &CommandWidget::onASCIIToggled); + connect(ui->leName, &QLineEdit::textChanged, [this](QString text) + { + this->_sendAction.setText(text); + }); + connect(&_sendAction, &QAction::triggered, this, &CommandWidget::onSendClicked); } CommandWidget::~CommandWidget() @@ -108,3 +114,8 @@ void CommandWidget::setFocusToEdit() { ui->leCommand->setFocus(Qt::OtherFocusReason); } + +QAction* CommandWidget::sendAction() +{ + return &_sendAction; +} diff --git a/commandwidget.h b/commandwidget.h --- a/commandwidget.h +++ b/commandwidget.h @@ -22,6 +22,7 @@ #include #include +#include namespace Ui { class CommandWidget; @@ -38,6 +39,7 @@ public: void setName(QString name); QString name(); void setFocusToEdit(); + QAction* sendAction(); signals: void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked @@ -50,6 +52,7 @@ signals: private: Ui::CommandWidget *ui; + QAction _sendAction; bool isASCIIMode(); // true: ascii mode, false hex mode