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
 
@@ -79,24 +79,25 @@ add_executable(${PROGRAM_NAME} WIN32
 
  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")
 

	
commandpanel.cpp
Show inline comments
 
@@ -29,35 +29,38 @@ CommandPanel::CommandPanel(QSerialPort* 
 
{
 
    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;
 
    }
 

	
commandpanel.h
Show inline comments
 
@@ -33,18 +33,20 @@ 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
 
@@ -84,12 +84,22 @@ void CommandWidget::onSendClicked()
 
    }
 
}
 

	
 
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
 
@@ -26,24 +26,27 @@
 
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;
 

	
commandwidget.ui
Show inline comments
 
@@ -39,24 +39,27 @@
 
     </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>
 
@@ -158,16 +161,21 @@
 
      <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
 
@@ -42,46 +42,48 @@ SOURCES += main.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
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)