Changeset - 3216cc699a63
[Not reviewed]
default
0 5 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2016-02-28 09:56:16
hy@ozderya.net
added "Commands" menu
5 files changed with 34 insertions and 1 deletions:
0 comments (0 inline, 0 general)
commandpanel.cpp
Show inline comments
 
@@ -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;
 
}
commandpanel.h
Show inline comments
 
@@ -23,6 +23,8 @@
 
#include <QWidget>
 
#include <QSerialPort>
 
#include <QByteArray>
 
#include <QMenu>
 
#include <QAction>
 

	
 
#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;
 

	
commandwidget.cpp
Show inline comments
 
@@ -103,3 +103,8 @@ QString CommandWidget::name()
 
{
 
    return ui->leName->text();
 
}
 

	
 
void CommandWidget::setFocusToEdit()
 
{
 
    ui->leCommand->setFocus(Qt::OtherFocusReason);
 
}
commandwidget.h
Show inline comments
 
@@ -37,6 +37,7 @@ public:
 

	
 
    void setName(QString name);
 
    QString name();
 
    void setFocusToEdit();
 

	
 
signals:
 
    void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked
mainwindow.cpp
Show inline comments
 
@@ -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();
 

	
0 comments (0 inline, 0 general)