Changeset - cc65dd8fc5fc
[Not reviewed]
default
0 7 2
Hasan Yavuz Ă–ZDERYA - 10 years ago 2016-02-28 09:21:55
hy@ozderya.net
added command name widget
9 files changed with 83 insertions and 2 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -67,48 +67,49 @@ if (WIN32)
 
else (WIN32)
 
  qt5_add_resources(RES_FILES misc/icons.qrc)
 
endif (WIN32)
 

	
 
add_executable(${PROGRAM_NAME} WIN32
 
  main.cpp
 
  mainwindow.cpp
 
  portcontrol.cpp
 
  plot.cpp
 
  zoomer.cpp
 
  hidabletabwidget.cpp
 
  framebuffer.cpp
 
  scalepicker.cpp
 
  scalezoomer.cpp
 
  portlist.cpp
 
  snapshot.cpp
 
  snapshotview.cpp
 
  snapshotmanager.cpp
 
  plotsnapshotoverlay.cpp
 
  commandpanel.cpp
 
  commandwidget.cpp
 
  commandedit.cpp
 
  dataformatpanel.cpp
 
  tooltipfilter.cpp
 
  sneakylineedit.cpp
 
  ${UI_FILES}
 
  ${RES_FILES}
 
  misc/windows_icon.rc
 
  )
 

	
 
# Use the Widgets module from Qt 5.
 
target_link_libraries(${PROGRAM_NAME} ${QWT_LIBRARY})
 
qt5_use_modules(${PROGRAM_NAME} Widgets SerialPort Svg)
 

	
 
# set compiler flags
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 

	
 
# Enable C++11 support, fail if not supported
 
include(CheckCXXCompilerFlag)
 
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
 
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
 
if(COMPILER_SUPPORTS_CXX11)
 
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 
elseif(COMPILER_SUPPORTS_CXX0X)
 
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
 
else()
 
  message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
 
endif()
 

	
commandpanel.cpp
Show inline comments
 
@@ -17,52 +17,55 @@
 
  along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "commandpanel.h"
 
#include "ui_commandpanel.h"
 

	
 
#include <QByteArray>
 
#include <QtDebug>
 

	
 
CommandPanel::CommandPanel(QSerialPort* port, QWidget *parent) :
 
    QWidget(parent),
 
    ui(new Ui::CommandPanel)
 
{
 
    serialPort = port;
 

	
 
    ui->setupUi(this);
 
    ui->scrollAreaWidgetContents->setLayout(new QVBoxLayout);
 

	
 
#ifdef Q_OS_WIN
 
    ui->pbNew->setIcon(QIcon(":/icons/list-add"));
 
#endif // Q_OS_WIN
 

	
 
    connect(ui->pbNew, &QPushButton::clicked, this, &CommandPanel::newCommand);
 

	
 
    command_name_counter = 0;
 
    newCommand(); // add an empty slot by default
 
}
 

	
 
CommandPanel::~CommandPanel()
 
{
 
    delete ui;
 
}
 

	
 
void CommandPanel::newCommand()
 
{
 
    auto command = new CommandWidget();
 
    command_name_counter++;
 
    command->setName(trUtf8("Command ") + QString::number(command_name_counter));
 
    ui->scrollAreaWidgetContents->layout()->addWidget(command);
 
    connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand);
 
}
 

	
 
void CommandPanel::sendCommand(QByteArray command)
 
{
 
    if (!serialPort->isOpen())
 
    {
 
        qCritical() << "Port is not open!";
 
        return;
 
    }
 

	
 
    if (serialPort->write(command) < 0)
 
    {
 
        qCritical() << "Send command failed!";
 
    }
 
}
commandpanel.h
Show inline comments
 
@@ -21,30 +21,32 @@
 
#define COMMANDPANEL_H
 

	
 
#include <QWidget>
 
#include <QSerialPort>
 
#include <QByteArray>
 

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

	
 
    unsigned command_name_counter;
 

	
 
private slots:
 
    void newCommand();
 
    void sendCommand(QByteArray command);
 
};
 

	
 
#endif // COMMANDPANEL_H
commandwidget.cpp
Show inline comments
 
@@ -72,24 +72,34 @@ void CommandWidget::onSendClicked()
 
        // check if nibbles are missing
 
        if (command.size() % 2 == 1)
 
        {
 
            qWarning() << "HEX command is missing a nibble at the end!";
 
            ui->leCommand->setFocus(Qt::OtherFocusReason);
 
            // highlight the byte that is missing a nibble (last byte obviously)
 
            int textSize = ui->leCommand->text().size();
 
            ui->leCommand->setSelection(textSize-1, textSize);
 
            return;
 
        }
 
        qDebug() << "Sending HEX:" << command;
 
        emit sendCommand(QByteArray::fromHex(command.toLatin1()));
 
    }
 
}
 

	
 
void CommandWidget::onASCIIToggled(bool checked)
 
{
 
    ui->leCommand->setMode(checked);
 
}
 

	
 
bool CommandWidget::isASCIIMode()
 
{
 
    return ui->pbASCII->isChecked();
 
}
 

	
 
void CommandWidget::setName(QString name)
 
{
 
    ui->leName->setText(name);
 
}
 

	
 
QString CommandWidget::name()
 
{
 
    return ui->leName->text();
 
}
commandwidget.h
Show inline comments
 
@@ -14,45 +14,48 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef COMMANDWIDGET_H
 
#define COMMANDWIDGET_H
 

	
 
#include <QWidget>
 
#include <QByteArray>
 

	
 
namespace Ui {
 
class CommandWidget;
 
}
 

	
 
class CommandWidget : public QWidget
 
{
 
    Q_OBJECT
 

	
 
public:
 
    explicit CommandWidget(QWidget *parent = 0);
 
    ~CommandWidget();
 

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

	
 
signals:
 
    void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked
 

	
 
    // 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);
 

	
 
private:
 
    Ui::CommandWidget *ui;
 

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

	
 
private slots:
 
    void onDeleteClicked();
 
    void onSendClicked();
 
    void onASCIIToggled(bool checked);
 
};
 

	
 
#endif // COMMANDWIDGET_H
commandwidget.ui
Show inline comments
 
@@ -27,48 +27,51 @@
 
    <number>0</number>
 
   </property>
 
   <item>
 
    <widget class="QToolButton" name="pbDelete">
 
     <property name="minimumSize">
 
      <size>
 
       <width>30</width>
 
       <height>0</height>
 
      </size>
 
     </property>
 
     <property name="text">
 
      <string/>
 
     </property>
 
     <property name="icon">
 
      <iconset theme="list-remove">
 
       <normaloff/>
 
      </iconset>
 
     </property>
 
     <property name="autoRaise">
 
      <bool>true</bool>
 
     </property>
 
    </widget>
 
   </item>
 
   <item>
 
    <widget class="SneakyLineEdit" name="leName"/>
 
   </item>
 
   <item>
 
    <widget class="CommandEdit" name="leCommand">
 
     <property name="sizePolicy">
 
      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
 
       <horstretch>0</horstretch>
 
       <verstretch>0</verstretch>
 
      </sizepolicy>
 
     </property>
 
     <property name="toolTip">
 
      <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter your command here.&lt;/p&gt;&lt;p&gt;In ASCII mode you can use backslash '\' to send some special characters. These are:&lt;br/&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;\n&lt;/span&gt; : Line Feed (new line)&lt;br/&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;\r&lt;/span&gt; : Carriage Return&lt;br/&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;\t&lt;/span&gt; : Tab&lt;/p&gt;&lt;p&gt;Be careful though, you cannot escape the backslash character itself!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
 
     </property>
 
     <property name="clearButtonEnabled">
 
      <bool>true</bool>
 
     </property>
 
    </widget>
 
   </item>
 
   <item>
 
    <widget class="QFrame" name="frame">
 
     <property name="sizePolicy">
 
      <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
 
       <horstretch>0</horstretch>
 
       <verstretch>0</verstretch>
 
      </sizepolicy>
 
     </property>
 
     <property name="frameShape">
 
@@ -146,28 +149,33 @@
 
     </layout>
 
    </widget>
 
   </item>
 
   <item>
 
    <widget class="QPushButton" name="pbSend">
 
     <property name="sizePolicy">
 
      <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
 
       <horstretch>0</horstretch>
 
       <verstretch>0</verstretch>
 
      </sizepolicy>
 
     </property>
 
     <property name="text">
 
      <string>Send</string>
 
     </property>
 
    </widget>
 
   </item>
 
  </layout>
 
 </widget>
 
 <customwidgets>
 
  <customwidget>
 
   <class>CommandEdit</class>
 
   <extends>QLineEdit</extends>
 
   <header>commandedit.h</header>
 
  </customwidget>
 
  <customwidget>
 
   <class>SneakyLineEdit</class>
 
   <extends>QLineEdit</extends>
 
   <header>sneakylineedit.h</header>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections/>
 
</ui>
serialplot.pro
Show inline comments
 
@@ -30,64 +30,66 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += 
 
TARGET = serialplot
 
TEMPLATE = app
 

	
 
CONFIG += qwt
 

	
 

	
 
SOURCES += main.cpp\
 
        mainwindow.cpp \
 
    portcontrol.cpp \
 
    plot.cpp \
 
    zoomer.cpp \
 
    hidabletabwidget.cpp \
 
    framebuffer.cpp \
 
    scalepicker.cpp \
 
    scalezoomer.cpp \
 
    portlist.cpp \
 
    snapshotview.cpp \
 
    snapshotmanager.cpp \
 
    snapshot.cpp \
 
    plotsnapshotoverlay.cpp \
 
    commandpanel.cpp \
 
    commandwidget.cpp \
 
    commandedit.cpp \
 
    dataformatpanel.cpp \
 
    tooltipfilter.cpp
 
    tooltipfilter.cpp \
 
    sneakylineedit.cpp
 

	
 
HEADERS  += mainwindow.h \
 
    utils.h \
 
    portcontrol.h \
 
    floatswap.h \
 
    plot.h \
 
    zoomer.h \
 
    hidabletabwidget.h \
 
    framebuffer.h \
 
    scalepicker.h \
 
    scalezoomer.h \
 
    portlist.h \
 
    snapshotview.h \
 
    snapshotmanager.h \
 
    snapshot.h \
 
    plotsnapshotoverlay.h \
 
    commandpanel.h \
 
    commandwidget.h \
 
    commandedit.h \
 
    dataformatpanel.h \
 
    tooltipfilter.h
 
    tooltipfilter.h \
 
    sneakylineedit.h
 

	
 
FORMS    += mainwindow.ui \
 
    about_dialog.ui \
 
    portcontrol.ui \
 
    snapshotview.ui \
 
    commandpanel.ui \
 
    commandwidget.ui \
 
    dataformatpanel.ui
 

	
 
INCLUDEPATH += qmake/
 

	
 
CONFIG += c++11
 

	
 
RESOURCES += misc/icons.qrc
 

	
 
win32 {
 
    RESOURCES += misc/winicons.qrc
 
}
sneakylineedit.cpp
Show inline comments
 
new file 100644
 
#include "sneakylineedit.h"
 
#include <QFont>
 

	
 
SneakyLineEdit::SneakyLineEdit(QWidget *parent) :
 
    QLineEdit(parent)
 
{
 
    setFrame(false);
 
    setStyleSheet("QLineEdit{background-color: rgba(0,0,0,0);}");
 
    setToolTip(trUtf8("Click to edit"));    
 

	
 
    setBold(true);
 
}
 

	
 
void SneakyLineEdit::focusInEvent(QFocusEvent *event)
 
{
 
    setFrame(true);
 
    setBold(false);
 
    QLineEdit::focusInEvent(event);
 
}
 

	
 
void SneakyLineEdit::focusOutEvent(QFocusEvent *event)
 
{
 
    setFrame(false);
 
    setBold(true);
 
    QLineEdit::focusOutEvent(event);
 
}
 

	
 
void SneakyLineEdit::setBold(bool bold)
 
{
 
    QFont f(font());
 
    f.setBold(bold);
 
    setFont(f);
 
}
sneakylineedit.h
Show inline comments
 
new file 100644
 
#ifndef SNEAKYLINEEDIT_H
 
#define SNEAKYLINEEDIT_H
 

	
 
#include <QLineEdit>
 
#include <QFocusEvent>
 

	
 
class SneakyLineEdit : public QLineEdit
 
{
 
    Q_OBJECT
 
public:
 
    explicit SneakyLineEdit(QWidget *parent = 0);
 

	
 
private:
 
    void focusInEvent(QFocusEvent * event);
 
    void focusOutEvent(QFocusEvent * event);
 
    void setBold(bool bold);
 
};
 

	
 
#endif // SNEAKYLINEEDIT_H
0 comments (0 inline, 0 general)