# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2016-02-28 09:56:16 # Node ID 3216cc699a63303d2bf0ef75627f593d7ea67f7c # Parent cc65dd8fc5fc8b76bc2410a6f1606aa88886a2a6 added "Commands" menu diff --git a/commandpanel.cpp b/commandpanel.cpp --- a/commandpanel.cpp +++ b/commandpanel.cpp @@ -25,7 +25,8 @@ CommandPanel::CommandPanel(QSerialPort* port, QWidget *parent) : QWidget(parent), - ui(new Ui::CommandPanel) + ui(new Ui::CommandPanel), + _menu(trUtf8("Commands")), _newCommandAction(trUtf8("New Command"), this) { serialPort = port; @@ -37,6 +38,9 @@ CommandPanel::CommandPanel(QSerialPort* #endif // Q_OS_WIN connect(ui->pbNew, &QPushButton::clicked, this, &CommandPanel::newCommand); + connect(&_newCommandAction, &QAction::triggered, this, &CommandPanel::newCommand); + + _menu.addAction(&_newCommandAction); command_name_counter = 0; newCommand(); // add an empty slot by default @@ -53,6 +57,7 @@ void CommandPanel::newCommand() command_name_counter++; command->setName(trUtf8("Command ") + QString::number(command_name_counter)); ui->scrollAreaWidgetContents->layout()->addWidget(command); + command->setFocusToEdit(); connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand); } @@ -69,3 +74,13 @@ void CommandPanel::sendCommand(QByteArra qCritical() << "Send command failed!"; } } + +QMenu* CommandPanel::menu() +{ + return &_menu; +} + +QAction* CommandPanel::newCommandAction() +{ + return &_newCommandAction; +} diff --git a/commandpanel.h b/commandpanel.h --- a/commandpanel.h +++ b/commandpanel.h @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "commandwidget.h" @@ -38,9 +40,14 @@ public: explicit CommandPanel(QSerialPort* port, QWidget *parent = 0); ~CommandPanel(); + QMenu* menu(); + QAction* newCommandAction(); + private: Ui::CommandPanel *ui; QSerialPort* serialPort; + QMenu _menu; + QAction _newCommandAction; unsigned command_name_counter; diff --git a/commandwidget.cpp b/commandwidget.cpp --- a/commandwidget.cpp +++ b/commandwidget.cpp @@ -103,3 +103,8 @@ QString CommandWidget::name() { return ui->leName->text(); } + +void CommandWidget::setFocusToEdit() +{ + ui->leCommand->setFocus(Qt::OtherFocusReason); +} diff --git a/commandwidget.h b/commandwidget.h --- a/commandwidget.h +++ b/commandwidget.h @@ -37,6 +37,7 @@ public: void setName(QString name); QString name(); + void setFocusToEdit(); signals: void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -67,6 +67,11 @@ MainWindow::MainWindow(QWidget *parent) ui->plotToolBar->addAction(snapshotMan.takeSnapshotAction()); ui->menuBar->insertMenu(ui->menuHelp->menuAction(), snapshotMan.menu()); + ui->menuBar->insertMenu(ui->menuHelp->menuAction(), commandPanel.menu()); + connect(commandPanel.newCommandAction(), &QAction::triggered, [this]() + { + this->ui->tabWidget->setCurrentWidget(&commandPanel); + }); setupAboutDialog();