# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2016-06-14 22:11:39 # Node ID cd8c3e8601e07bb222df0df174bc260d8adab295 # Parent 81e0159a3b23fddf9f0522a7019fc2c183a9577f focus on command panel when user tries to send an empty command from the menu diff --git a/src/commandpanel.cpp b/src/commandpanel.cpp --- a/src/commandpanel.cpp +++ b/src/commandpanel.cpp @@ -62,6 +62,7 @@ void CommandPanel::newCommand() ui->scrollAreaWidgetContents->layout()->addWidget(command); command->setFocusToEdit(); connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand); + connect(command, &CommandWidget::focusRequested, this, &CommandPanel::focusRequested); _menu.addAction(command->sendAction()); } diff --git a/src/commandpanel.h b/src/commandpanel.h --- a/src/commandpanel.h +++ b/src/commandpanel.h @@ -43,6 +43,10 @@ public: QMenu* menu(); QAction* newCommandAction(); +signals: + // emitted when user tries to send an empty command + void focusRequested(); + private: Ui::CommandPanel *ui; QSerialPort* serialPort; diff --git a/src/commandwidget.cpp b/src/commandwidget.cpp --- a/src/commandwidget.cpp +++ b/src/commandwidget.cpp @@ -64,6 +64,7 @@ void CommandWidget::onSendClicked() { qWarning() << "Enter a command to send!"; ui->leCommand->setFocus(Qt::OtherFocusReason); + emit focusRequested(); return; } diff --git a/src/commandwidget.h b/src/commandwidget.h --- a/src/commandwidget.h +++ b/src/commandwidget.h @@ -50,6 +50,9 @@ signals: // string containing hexadecimal characters only (not even spaces) void sendCommand(QByteArray command); + // emitted when user tries to send an empty command + void focusRequested(); + private: Ui::CommandWidget *ui; QAction _sendAction; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -70,6 +70,11 @@ MainWindow::MainWindow(QWidget *parent) this->ui->tabWidget->setCurrentWidget(&commandPanel); }); + connect(&commandPanel, &CommandPanel::focusRequested, [this]() + { + this->ui->tabWidget->setCurrentWidget(&commandPanel); + }); + setupAboutDialog(); // init view menu