Changeset - cd8c3e8601e0
[Not reviewed]
default
0 5 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2016-06-14 22:11:39
hy@ozderya.net
focus on command panel when user tries to send an empty command from the menu
5 files changed with 14 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/commandpanel.cpp
Show inline comments
 
@@ -59,12 +59,13 @@ void CommandPanel::newCommand()
 
    auto command = new CommandWidget();
 
    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);
 
    connect(command, &CommandWidget::focusRequested, this, &CommandPanel::focusRequested);
 
    _menu.addAction(command->sendAction());
 
}
 

	
 
void CommandPanel::sendCommand(QByteArray command)
 
{
 
    if (!serialPort->isOpen())
src/commandpanel.h
Show inline comments
 
@@ -40,12 +40,16 @@ public:
 
    explicit CommandPanel(QSerialPort* port, QWidget *parent = 0);
 
    ~CommandPanel();
 

	
 
    QMenu* menu();
 
    QAction* newCommandAction();
 

	
 
signals:
 
    // emitted when user tries to send an empty command
 
    void focusRequested();
 

	
 
private:
 
    Ui::CommandPanel *ui;
 
    QSerialPort* serialPort;
 
    QMenu _menu;
 
    QAction _newCommandAction;
 

	
src/commandwidget.cpp
Show inline comments
 
@@ -61,12 +61,13 @@ void CommandWidget::onSendClicked()
 
    auto command = ui->leCommand->text();
 

	
 
    if (command.isEmpty())
 
    {
 
        qWarning() << "Enter a command to send!";
 
        ui->leCommand->setFocus(Qt::OtherFocusReason);
 
        emit focusRequested();
 
        return;
 
    }
 

	
 
    if (isASCIIMode())
 
    {
 
        qDebug() << "Sending " << name() << ":" << command;
src/commandwidget.h
Show inline comments
 
@@ -47,12 +47,15 @@ signals:
 
    // emitted when send button is clicked
 
    //
 
    // in case of hex mode, command text should be a hexadecimal
 
    // 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;
 

	
 
    bool isASCIIMode(); // true: ascii mode, false hex mode
 

	
src/mainwindow.cpp
Show inline comments
 
@@ -67,12 +67,17 @@ MainWindow::MainWindow(QWidget *parent) 
 
    ui->menuBar->insertMenu(ui->menuHelp->menuAction(), commandPanel.menu());
 
    connect(commandPanel.newCommandAction(), &QAction::triggered, [this]()
 
            {
 
                this->ui->tabWidget->setCurrentWidget(&commandPanel);
 
            });
 

	
 
    connect(&commandPanel, &CommandPanel::focusRequested, [this]()
 
            {
 
                this->ui->tabWidget->setCurrentWidget(&commandPanel);
 
            });
 

	
 
    setupAboutDialog();
 

	
 
    // init view menu
 
    for (auto a : ui->plot->menuActions())
 
    {
 
        ui->menuView->addAction(a);
0 comments (0 inline, 0 general)