# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2015-10-04 16:08:55 # Node ID a90832d0c0ec9496c04c3d4ce765b16dec934021 # Parent a3aeb9c195e97dd29588948ae40b5b6f9503c3e9 added command panel diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ qt5_wrap_ui(UI_FILES portcontrol.ui about_dialog.ui snapshotview.ui + commandpanel.ui + commandwidget.ui ) qt5_add_resources(RES_FILES misc/icons.qrc) @@ -75,6 +77,8 @@ add_executable(${PROGRAM_NAME} WIN32 snapshotview.cpp snapshotmanager.cpp plotsnapshotoverlay.cpp + commandpanel.cpp + commandwidget.cpp ${UI_FILES} ${RES_FILES} misc/windows_icon.rc diff --git a/commandpanel.cpp b/commandpanel.cpp new file mode 100644 --- /dev/null +++ b/commandpanel.cpp @@ -0,0 +1,52 @@ +/* + Copyright © 2015 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#include "commandpanel.h" +#include "ui_commandpanel.h" + +#include + +CommandPanel::CommandPanel(QSerialPort* port, QWidget *parent) : + QWidget(parent), + ui(new Ui::CommandPanel) +{ + serialPort = port; + + ui->setupUi(this); + ui->scrollAreaWidgetContents->setLayout(new QVBoxLayout); + + connect(ui->pbNew, &QPushButton::clicked, this, &CommandPanel::newCommand); +} + +CommandPanel::~CommandPanel() +{ + delete ui; +} + +void CommandPanel::newCommand() +{ + auto command = new CommandWidget(); + ui->scrollAreaWidgetContents->layout()->addWidget(command); + connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand); +} + +void CommandPanel::sendCommand(QString command, bool ascii) +{ + qDebug() << "command:" << command; +} diff --git a/commandpanel.h b/commandpanel.h new file mode 100644 --- /dev/null +++ b/commandpanel.h @@ -0,0 +1,49 @@ +/* + Copyright © 2015 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#ifndef COMMANDPANEL_H +#define COMMANDPANEL_H + +#include +#include + +#include "commandwidget.h" + +namespace Ui { +class CommandPanel; +} + +class CommandPanel : public QWidget +{ + Q_OBJECT + +public: + explicit CommandPanel(QSerialPort* port, QWidget *parent = 0); + ~CommandPanel(); + +private: + Ui::CommandPanel *ui; + QSerialPort* serialPort; + +private slots: + void newCommand(); + void sendCommand(QString command, bool ascii); +}; + +#endif // COMMANDPANEL_H diff --git a/commandpanel.ui b/commandpanel.ui new file mode 100644 --- /dev/null +++ b/commandpanel.ui @@ -0,0 +1,63 @@ + + + CommandPanel + + + + 0 + 0 + 583 + 109 + + + + Form + + + false + + + + + + QFrame::StyledPanel + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 0 + 0 + 563 + 16 + + + + + 0 + 0 + + + + + + + + + New Command + + + + + + + + + + + diff --git a/commandwidget.cpp b/commandwidget.cpp new file mode 100644 --- /dev/null +++ b/commandwidget.cpp @@ -0,0 +1,46 @@ +/* + Copyright © 2015 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#include "commandwidget.h" +#include "ui_commandwidget.h" + +CommandWidget::CommandWidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::CommandWidget) +{ + ui->setupUi(this); + + connect(ui->pbDelete, &QPushButton::clicked, this, &CommandWidget::onDeleteClicked); + connect(ui->pbSend, &QPushButton::clicked, this, &CommandWidget::onSendClicked); +} + +CommandWidget::~CommandWidget() +{ + delete ui; +} + +void CommandWidget::onDeleteClicked() +{ + this->deleteLater(); +} + +void CommandWidget::onSendClicked() +{ + emit sendCommand(ui->leCommand->text(), ui->pbASCII->isChecked()); +} diff --git a/commandwidget.h b/commandwidget.h new file mode 100644 --- /dev/null +++ b/commandwidget.h @@ -0,0 +1,50 @@ +/* + Copyright © 2015 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#ifndef COMMANDWIDGET_H +#define COMMANDWIDGET_H + +#include +#include + +namespace Ui { +class CommandWidget; +} + +class CommandWidget : public QWidget +{ + Q_OBJECT + +public: + explicit CommandWidget(QWidget *parent = 0); + ~CommandWidget(); + +signals: + void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked + void sendCommand(QString command, bool ascii); // emitted when send button clicked + +private: + Ui::CommandWidget *ui; + +private slots: + void onDeleteClicked(); + void onSendClicked(); +}; + +#endif // COMMANDWIDGET_H diff --git a/commandwidget.ui b/commandwidget.ui new file mode 100644 --- /dev/null +++ b/commandwidget.ui @@ -0,0 +1,160 @@ + + + CommandWidget + + + + 0 + 0 + 433 + 34 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 30 + 0 + + + + + + + + + + + + true + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 40 + 0 + + + + ASCII + + + true + + + true + + + true + + + + + + + + 0 + 0 + + + + + 40 + 0 + + + + HEX + + + true + + + true + + + + + + + + + + + 0 + 0 + + + + Send + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -54,10 +54,12 @@ MainWindow::MainWindow(QWidget *parent) QMainWindow(parent), ui(new Ui::MainWindow), portControl(&serialPort), + commandPanel(&serialPort), snapshotMan(this, &channelBuffers) { ui->setupUi(this); ui->tabWidget->insertTab(0, &portControl, "Port"); + ui->tabWidget->insertTab(3, &commandPanel, "Commands"); ui->tabWidget->setCurrentIndex(0); addToolBar(portControl.toolBar()); diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -35,6 +35,7 @@ #include #include "portcontrol.h" +#include "commandpanel.h" #include "ui_about_dialog.h" #include "framebuffer.h" #include "snapshotmanager.h" @@ -100,6 +101,8 @@ private: unsigned int sampleCount; QTimer spsTimer; + CommandPanel commandPanel; + SnapshotManager snapshotMan; // demo diff --git a/serialplot.pro b/serialplot.pro --- a/serialplot.pro +++ b/serialplot.pro @@ -46,7 +46,9 @@ SOURCES += main.cpp\ snapshotview.cpp \ snapshotmanager.cpp \ snapshot.cpp \ - plotsnapshotoverlay.cpp + plotsnapshotoverlay.cpp \ + commandpanel.cpp \ + commandwidget.cpp HEADERS += mainwindow.h \ utils.h \ @@ -62,12 +64,16 @@ HEADERS += mainwindow.h \ snapshotview.h \ snapshotmanager.h \ snapshot.h \ - plotsnapshotoverlay.h + plotsnapshotoverlay.h \ + commandpanel.h \ + commandwidget.h FORMS += mainwindow.ui \ about_dialog.ui \ portcontrol.ui \ - snapshotview.ui + snapshotview.ui \ + commandpanel.ui \ + commandwidget.ui INCLUDEPATH += qmake/